Location: PHPKode > scripts > Avatar Tools > views/articles.php
<?php
/**
 * @version		$Id: coolfeed.php 100 2012-04-14 17:42:51Z hide@address.com $
 * @copyright	JoomAvatar.com
 * @author		Nguyen Quang Trung
 * @link		http://joomavatar.com
 * @license		License GNU General Public License version 2 or later http://www.gnu.org/licenses/gpl-2.0.html
 * @package		Avatar Dream Framework Template
 * @facebook 	http://www.facebook.com/pages/JoomAvatar/120705031368683
 * @twitter	    https://twitter.com/#!/JoomAvatar
 * @support 	http://joomavatar.com/forum/
 */

// no direct access
defined('_JEXEC') or die; 
?>
<script type="text/javascript">
	jQuery.noConflict();
	
	(function($) 
	{ 
			$(document).ready( function()
			{	
				var searchRequest;
				
				$('#avatar-tool-article-search').keyup(function()
				{
					if (searchRequest !== undefined) {
						searchRequest.abort();
					}
					
					searchRequest = $.ajax({
					  	url: "index.php?option=avatar-tool&controller=ajax&task=searchArticles",
					  	type: "POST",
					  	data: $("#avatar-tool-form-articles").serialize(),
					  	dataType: "json",
					});	
					
					searchRequest.done(function(data) 
					{
						var items = $('#avatar-tool-articles-search-results');
						var html = '';
						
					  	data.each(function (el, index)
					  	{
					  		index++;
					  		if (el.state == '1') {
					  			publish = 'article-publish';
					  		} else {
					  			publish = 'article-unpublish';
					  		}
					  		
					  		var featured = '';
					  		
					  		if (el.featured == 1) {
					  			featured = 'article-featured'
					  		}
					  		
					  		html += '<li class="item ' + publish + ' '+ featured +'">';
					  		html += '<form id="article-'+ el.id +'">';
					  		html += '<input type="hidden" name="id" value="'+ el.id +'">';
					  		html += '<h3 class="title avatar-tool-title">' + index + ' - <span>' + el.title + '</span></h3>';
					  		html += '<input class="avatar-tool-input-title" type="text" name="title" value="'+ $.addslashes(el.title)  +'">';
					  		html += '<strong><?php echo JText::_('AVATAR_TOOL_ALIAS', true); ?></strong> <span class="title avatar-tool-alias">' + el.alias + '</span>';
				  			html += '<input class="avatar-tool-input-alias" type="text" name="alias" value="'+ $.addslashes(el.alias)  +'">';
					  		html += '<div class="details">';
					  		
					  		html += '<span class="action click"><strong><?php echo JText::_('AVATAR_TOOL_PUBLISH', true); ?></strong> <span class="publish state'+ el.state +'"></span></span>';
					  		html += '<span class="action click"><strong><?php echo JText::_('AVATAR_TOOL_FEATURED', true); ?></strong> <span class="featured featured'+ el.featured +'"></span></span>';
					  		html += '<span class="action click"><strong><?php echo JText::_('AVATAR_TOOL_ACCESS', true); ?></strong> <span class="text access">'+ el.access_level +'</span></span>';
					  		html += '<span class="action click"><strong><?php echo JText::_('AVATAR_TOOL_AUTHOR', true); ?></strong> <span class="text author">'+ el.author +'</span></span>';
					  		html += '<span class="action click"><strong><?php echo JText::_('AVATAR_TOOL_CATEGORY', true); ?></strong> <span class="text category">'+ el.category +'</span></span>';
					  		
					  		var languageOpts = $.parseJSON('<?php echo json_encode(JHtml::_('contentlanguage.existing')); ?>');
					  		
					  		html += '<span class="action language"><strong><?php echo JText::_('AVATAR_TOOL_LANGUAGE', true); ?></strong> '+ AvatarTools.HTML.menus.selectboxLanguage(el.language, languageOpts) +'</span>';
					  		html += '<span class="action hits"><strong><?php echo JText::_('AVATAR_TOOL_HITS', true); ?></strong> <span class="text">'+ el.hits +'</span></span>';
					  		html += '<span style="clear:both;"></span>';
					  		html += '</div>';
					  		html += '<div style="clear: both;"><span class="avatar-tool-button button-edit"><?php echo JText::_('AVATAR_TOOL_ARTICLES_QUICK_EDIT', true); ?></span><span class="avatar-tool-button button-full-edit"><a href="index.php?option=com_content&task=article.edit&id='+ el.id +'"><?php echo JText::_('AVATAR_TOOL_ARTICLES_FULL_EDIT', true); ?></a></span></div>';
					  		
					  		html += '<div class="info-edit">';
					  		
					  		html += '<p class="label"><?php echo JText::_('JFIELD_META_KEYWORDS_LABEL', true); ?></p>';
							html +=	'<p class="description"><?php echo JText::_('JFIELD_META_KEYWORDS_DESC', true) ?></p>';
							html += '<textarea name="metakey" class="meta-keywords">'+ el.metakey +'</textarea>';
							
							html += '<p class="label"><?php echo JText::_('JFIELD_META_DESCRIPTION_LABEL', true); ?></p>';
							html +=	'<p class="description"><?php echo JText::_('JFIELD_META_DESCRIPTION_DESC', true) ?></p>';
					  		html += '<textarea name="metadesc" class="meta-desc">'+ el.metadesc +'</textarea>';
					  		
					  		html += '<p class="label"><?php echo JText::_('AVATAR_TOOL_MENU_ROBOTS', true); ?></p>';
							
							var textRobots = {
								userGlobal : '<?php echo JText::_('AVATAR_TOOL_MENU_ROBOTS_USER_GLOBAL', true); ?>',
								indexFollow : '<?php echo JText::_('AVATAR_TOOL_MENU_ROBOTS_INDEX_FOLLOW', true); ?>',
								noIndexFollow : '<?php echo JText::_('AVATAR_TOOL_MENU_ROBOTS_NOINDEX_FOLLOW', true); ?>',
								indexNoFollow : '<?php echo JText::_('AVATAR_TOOL_MENU_ROBOTS_INDEX_NOFOLLOW', true); ?>',
								noIndexNoFollow : '<?php echo JText::_('AVATAR_TOOL_MENU_ROBOTS_NOINDEX_NOFOLLOW', true); ?>',
							}
							
							if (el.metadata) 
							{
								try {
									el.metadata = $.parseJSON(el.metadata);
								
							  		html += AvatarTools.HTML.menus.selectboxRobots(el.metadata.robots, textRobots, {name: 'metadata[robots]'});
							  		
							  		html += '<p class="label"><?php echo JText::_('AVATAR_TOOL_META_AUTHOR', true); ?></p>';
									html += '<input type="text" name="metadata[author]" value="'+ $.addslashes(el.metadata.author) +'"/>';
							  		
							  		html += '<p class="label"><?php echo JText::_('AVATAR_TOOL_META_CONTENT_RIGHTS', true); ?></p>';
									html += '<input type="text" name="metadata[rights]" value="'+ $.addslashes(el.metadata.rights) +'"/>';	
								} catch (er) {}
							}
					  		
					  		html += '<hr/><div class="buttons"><span class="avatar-tool-button button-cancel"><?php echo JText::_('AVATAR_TOOL_BUTTON_CANCEL', true); ?></span><span class="avatar-tool-button button-update"><?php echo JText::_('AVATAR_TOOL_BUTTON_UPDATE', true); ?></span></div>'
					  		
					  		html += '</div>'
					  		
					  		html += '</form>';
					  		html += '</li>';
					  	})
					  	
					  	items.html(html);
					  	var articlesForms = $('#avatar-tool-articles-search-results form');
					  	
					  	var titles 	= $('#avatar-tool-articles-search-results .avatar-tool-title');
					  	var inputTitles = $('#avatar-tool-articles-search-results .avatar-tool-input-title');
						var alias 	= $('#avatar-tool-articles-search-results .avatar-tool-alias');
				  		var inputAlias = $('#avatar-tool-articles-search-results .avatar-tool-input-alias');
				  	
					  	titles.each(function(index)
					  	{
					  		var el = $(this);
					  		el.click(function(){
					  			el.css('display', 'none');
					  			$(inputTitles[index]).css('display', 'block');
					  		});
					  	});
					  	
					  	inputTitles.each(function(index)
					  	{
					  		var el = $(this);
					  		el.change(function()
					  		{
					  			if (el.val() != '') 
					  			{
					  				$('span', $(titles[index])).html(el.val());
						  			el.css('display', 'none');
						  			$(titles[index]).css('display', 'block');
						  			
						  			request = $.ajax({
									  	url: "index.php?option=avatar-tool&controller=ajax&task=articleUpdateTitle",
									  	type: "POST",
									  	data: $('#' + articlesForms[index].get('id')).serialize(),
									  	dataType: "json",
									});	
					  			}
					  		});
					  	});
					  	
					  	alias.each(function(index)
					  	{
					  		var el = $(this);
					  		el.click(function(){
					  			el.css('display', 'none');
					  			$(inputAlias[index]).css('display', 'inline-block');
					  		});
					  	});
					  	
					  	inputAlias.each(function(index)
					  	{
					  		var el = $(this);
					  		el.change(function()
					  		{
					  			if (el.val() != '') 
					  			{
					  				$(alias[index]).html(el.val());
						  			el.css('display', 'none');
						  			$(alias[index]).css('display', 'inline-block');
						  			
						  			request = $.ajax({
									  	url: "index.php?option=avatar-tool&controller=ajax&task=articleUpdateTitle",
									  	type: "POST",
									  	data: $('#' + articlesForms[index].get('id')).serialize(),
									  	dataType: "json",
									});	
					  			}
					  		});
					  	});
					  	
					  	$('#avatar-tool-articles-search-results .button-edit').each(function(index){
					  		
					  		var infos = $('#avatar-tool-articles-search-results .info-edit');
					  		var buttonCancels 	= $('#avatar-tool-articles-search-results .button-cancel');
					  		var buttonUpdates 	= $('#avatar-tool-articles-search-results .button-update');
					  		
					  		$(this).click(function() 
					  		{
					  			var editButton = $(this);
					  			editButton.css('display', 'none');
					  			$(infos[index]).css('display', 'block');
					  			
					  			$(buttonCancels[index]).click(function(){
					  				editButton.css('display', 'inline-block');
					  				$(infos[index]).css('display', 'none');
					  			});	
					  			
					  			$(buttonUpdates[index]).click(function()
					  			{
					  				searchRequest = $.ajax({
									  	url: "index.php?option=avatar-tool&controller=ajax&task=updateArticle",
									  	type: "POST",
									  	data: $('#' + articlesForms[index].get('id')).serialize(),
									  	dataType: "json",
									});	
									editButton.css('display', 'inline-block');
									$(infos[index]).css('display', 'none');
					  			});
					  		});
					  	});
					  	
					  	var buttonPublishs 	= $('#avatar-tool-articles-search-results .details .publish');
				  		var buttonFeatureds = $('#avatar-tool-articles-search-results .details .featured');
					  	
					  	buttonPublishs.each(function(index)
					  	{
					  		$(this).click(function()
				  			{
				  				var el = $(this);
				  				var state = 0;
				  				
				  				if (el.hasClass('state1')) {
				  					el.removeClass('state1').addClass('state0');
				  					state = 0;
				  				} else if (el.hasClass('state0')) {
				  					el.removeClass('state0').addClass('state1');
				  					state = 1;
				  				};
				  			
				  				searchRequest = $.ajax({
								  	url: "index.php?option=avatar-tool&controller=ajax&task=articlePublish",
								  	type: "POST",
								  	data: $('#' + articlesForms[index].get('id')).serialize() + '&state=' + state,
								  	dataType: "json",
								});	
				  			});
					  	})
					  	
					  	buttonFeatureds.each(function(index)
					  	{
					  		$(this).click(function()
				  			{
				  				var el = $(this);
				  				var featured = 0;
				  				
				  				if (el.hasClass('featured1')) {
				  					el.removeClass('featured1').addClass('featured0');
				  					featured = 0;
				  				} else if (el.hasClass('featured0')) {
				  					el.removeClass('featured0').addClass('featured1');
				  					featured = 1;
				  				};
				  			
				  				searchRequest = $.ajax({
								  	url: "index.php?option=avatar-tool&controller=ajax&task=articleFeatured",
								  	type: "POST",
								  	data: $('#' + articlesForms[index].get('id')).serialize() + '&featured=' + featured,
								  	dataType: "json",
								});	
				  			});
					  	})
					  	
					  	var buttonAccess = $('#avatar-tool-articles-search-results .details .access');
						
					  	buttonAccess.each(function(index)
					  	{
					  		var access = $(this);
					  		access.click(function()
					  		{
					  			$('#avatar-tool-subview-access').dialog({
					  				zIndex: 900,
					  				open: function(event, ui)
					  				{
					  					request = $.ajax({
										  	url: "index.php?option=avatar-tool&controller=ajax&task=accessGet",
										  	type: "GET",
										  	dataType: "json",
										});	
										
										request.done(function(data)
										{
											if ($.isArray(data)) 
											{
												var html = '';
												data.each(function(index)
												{
													html += '<p class="avatar-tool-button button-tag">' + $(index)[0].title;
													html += '<input type="hidden" name="access" value="'+ $(index)[0].id +'"></p>';
												});
												
												html += '<p style="clear: both;"></p>'
												
												$('#avatar-tool-subview-access').html(html);
												
												$('#avatar-tool-subview-access .button-tag').each(function(el){
													$(this).draggable({
														revert: true,
														stack: "#avatar-tool-subview-access .button-tag",
														helper:'clone',
  														appendTo: 'body',
  														zIndex: 910,
  														start: function(){
  															$('#avatar-tool-articles-search-results .details .access').each(function(index){
  																$(this).css('background','#137BAF');
  															});
  														},
  														stop: function(){
  															$('#avatar-tool-articles-search-results .details .access').each(function(index){
  																$(this).css('background','');
  															});
  														}
												    });
													
												});
											}
										})
					  				}
					  			});
					  		});
					  		
					  		access.droppable(
					  		{
					  			accept: "#avatar-tool-subview-access .button-tag",
								drop: function(event, ui) 
								{ 
							   		$(this).html(ui.draggable.html());
							   		 
							   		request = $.ajax({
									  	url: "index.php?option=avatar-tool&controller=ajax&task=accessUpdate",
									  	type: "POST",
									  	data: $('#' + articlesForms[index].get('id')).serialize(),
									  	dataType: "json",
									});	
								}
							});
					  	});
					  	
					  	var buttonCategories = $('#avatar-tool-articles-search-results .details .category');
						
					  	buttonCategories.each(function(index)
					  	{
					  		var category = $(this);
					  		category.click(function()
					  		{
					  			$('#avatar-tool-subview-categories').dialog({
					  				zIndex: 900,
					  				open: function(event, ui)
					  				{
					  					request = $.ajax({
										  	url: "index.php?option=avatar-tool&controller=ajax&task=categoriesGet",
										  	type: "GET",
										  	dataType: "json",
										});	
										
										request.done(function(data)
										{
											if ($.isArray(data)) 
											{
												var html = '';
												data.each(function(index)
												{
													html += '<p class="avatar-tool-button button-category">' + $(index)[0].title;;
													html += '<input type="hidden" name="catid" value="'+ $.addslashes($(index)[0].id) +'"></p>';
												});
												
												html += '<p style="clear: both;"></p>'
												
												$('#avatar-tool-subview-categories').html(html);
												
												$('#avatar-tool-subview-categories .button-category').each(function(el){
													$(this).draggable({
														revert: true,
														stack: "#avatar-tool-subview-categories .button-category",
														helper:'clone',
  														appendTo: 'body',
  														zIndex: 910,
  														start: function(){
  															$('#avatar-tool-articles-search-results .details .category').each(function(index){
  																$(this).css('background','#137BAF');
  															});
  														},
  														stop: function(){
  															$('#avatar-tool-articles-search-results .details .category').each(function(index){
  																$(this).css('background','');
  															});
  														}
												    });
													
												});
											}
										})
					  				}
					  			});
					  		});
					  		
					  		category.droppable(
					  		{
					  			accept: "#avatar-tool-subview-categories .button-category",
								drop: function(event, ui) 
								{ 
							   		$(this).html(ui.draggable.html());
							   		
							   		request = $.ajax({
									  	url: "index.php?option=avatar-tool&controller=ajax&task=categoriesUpdate",
									  	type: "POST",
									  	data: $('#' + articlesForms[index].get('id')).serialize(),
									  	dataType: "json",
									});
								}
							});
					  		
					  	});
					  	
					  	var buttonAuthors = $('#avatar-tool-articles-search-results .details .author');
						
					  	buttonAuthors.each(function(index)
					  	{
					  		var author = $(this);
					  		author.click(function()
					  		{
					  			$('#avatar-tool-subview-users').dialog({
					  				zIndex: 900,
					  				open: function(event, ui)
					  				{
					  					request = $.ajax({
										  	url: "index.php?option=avatar-tool&controller=ajax&task=usersGet",
										  	type: "GET",
										  	dataType: "json",
										});	
										
										request.done(function(data)
										{
											if ($.isArray(data)) 
											{
												var html = '';
												data.each(function(index)
												{
													html += '<p class="avatar-tool-button button-tag">' + $(index)[0].name;
													html += '<input type="hidden" name="created_by" value="'+ $.addslashes($(index)[0].id) +'"></p>';
												});
												
												html += '<p style="clear: both;"></p>'
												
												$('#avatar-tool-subview-users').html(html);
												
												$('#avatar-tool-subview-users .button-tag').each(function(el){
													$(this).draggable({
														revert: true,
														stack: "#avatar-tool-subview-users .button-tag",
														helper:'clone',
  														appendTo: 'body',
  														zIndex: 910,
  														start: function(){
  															$('#avatar-tool-articles-search-results .details .author').each(function(index){
  																$(this).css('background','#137BAF');
  															});
  														},
  														stop: function(){
  															$('#avatar-tool-articles-search-results .details .author').each(function(index){
  																$(this).css('background','');
  															});
  														}
												    });
													
												});
											}
										})
					  				}
					  			});
					  		});
					  		
					  		author.droppable(
					  		{
					  			accept: "#avatar-tool-subview-users .button-tag",
								drop: function(event, ui) 
								{ 
							   		$(this).html(ui.draggable.html());
							   		
							   		request = $.ajax({
									  	url: "index.php?option=avatar-tool&controller=ajax&task=usersUpdate",
									  	type: "POST",
									  	data: $('#' + articlesForms[index].get('id')).serialize(),
									  	dataType: "json",
									});
								}
							});
					  	});
					  	
					  	var buttonLanguages = $('#avatar-tool-articles-search-results .details .language select');
			  		
				  		buttonLanguages.each(function(index)
					  	{
					  		$(this).change(function()
				  			{
				  				request = $.ajax({
								  	url: "index.php?option=avatar-tool&controller=ajax&task=articleUpdateLanguage",
								  	type: "POST",
								  	data: $('#' + articlesForms[index].get('id')).serialize(),
								  	dataType: "json",
								});	
				  			});
					  	})
					});
				});
				
			});
			
	})(jQuery);
	
	
</script>
<div class="avatar-view" id="avatar-view-articles">
	<form id="avatar-tool-form-articles" name="avatar-tool-form-articles">
		<ul class="list-item">
			<li class="item">
				<p class="label"><?php echo JText::_('AVATAR_TOOL_ARTICLES_SEARCH'); ?></p>
				<p class="description"><?php echo JText::_('AVATAR_TOOL_ARTICLES_SEARCH_DESC') ?></p>
				<input id="avatar-tool-article-search" size="50" name="search"/>	
				<p class="description"><?php echo JText::_('AVATAR_TOOL_ARTICLES_SEARCH_OPTIONS_DESC') ?></p>
				<input type="text" name="search-options[limit]" value="100" size="5"/> <?php echo JText::_('AVATAR_TOOL_LIMIT'); ?> &nbsp;&nbsp;
				<input type="checkbox" name="search-options[]" value="articles-fulltext" /> <?php echo JText::_('AVATAR_TOOL_ARTICLE_FULLTEXT'); ?> &nbsp;&nbsp;
				<input type="checkbox" name="search-options[]" value="articles-popular" /> <?php echo JText::_('AVATAR_TOOL_ARTICLE_POPULAR'); ?> &nbsp;&nbsp;
				<br/><br/>
				<span class="avatar-tool-button" onclick="AvatarTools.articles.reset('#avatar-tool-articles-search-results li');" > <?php echo JText::_('AVATAR_TOOL_ARTICLE_RESET'); ?></span> &nbsp;&nbsp;
				<span class="avatar-tool-button" onclick="AvatarTools.articles.fillter('article-featured', '#avatar-tool-articles-search-results li');" > <?php echo JText::_('AVATAR_TOOL_ARTICLE_FEATURED'); ?></span> &nbsp;&nbsp;
				<span class="avatar-tool-button" onclick="AvatarTools.articles.fillter('article-publish', '#avatar-tool-articles-search-results li');" > <?php echo JText::_('AVATAR_TOOL_ARTICLE_PUBLISH'); ?></span> &nbsp;&nbsp;
				<span class="avatar-tool-button" onclick="AvatarTools.articles.fillter('article-unpublish', '#avatar-tool-articles-search-results li');" > <?php echo JText::_('AVATAR_TOOL_ARTICLE_UNPUBLISH'); ?></span> &nbsp;&nbsp;
			</li>
		</ul>	
	</form>
	
	<ul id="avatar-tool-articles-search-results" class="list-item">
		
	</ul>	
</div>
Return current item: Avatar Tools