Joomla! Discussion Forums



It is currently Tue Nov 24, 2009 2:58 pm (All times are UTC )

 





Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: gAvatar
Posted: Mon May 11, 2009 1:42 am 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Sat Mar 07, 2009 2:05 am
Posts: 48
Eu instalei o plugin gAvatar para exibir avatares nos artigos, mas ele exibe em todos os locais e gostaria de exibi-lo apenas em uma determinada seção.

Aqui está o link do plugin e o código: http://extensions.joomla.org/extensions ... 19/details

Code:
<?php defined( '_JEXEC' ) or die( 'Direct Access to this location is not allowed.' );

// gAvatar 0.3
// by geminorum.ir
// 9:21 PM 3/6/2009
// 3:02 AM 3/28/2009

jimport( 'joomla.plugin.plugin' );

class plgContentgAvatar extends JPlugin
{
   function plgContentgAvatar( &$subject, $params )
   {
      parent::__construct( $subject, $params );

      $plugin =& JPluginHelper::getPlugin('content', 'gavatar');
      $this->_params = new JParameter( $plugin->params );
      $this->_gauthor = (($this->_params->get('integrated_with') == 'gauthor' && JPluginHelper::isEnabled('content', 'gauthor')) ? true : false );
      //$this->_gauthor = true;
      $this->_cb = (($this->_params->get('integrated_with') == 'cb' && JComponentHelper::isEnabled('com_comprofiler', true)) ? true : false );
      //$this->_cb = true;
     
      $this->_addstyle = (($this->_params->get( 'add_style', '1') == '1') ? true : false );
     
      $this->_debug = false;
   }

   function onBeforeDisplayContent( &$article, &$params, $limitstart )
   {
      if (!$params) return '';
      $isModule = (int) $params->get( 'item_title', -1);
      if ($isModule > -1 ) return ''; //TODO : Check for newsflash title
     
      $view = JRequest::getCmd('view');
      if ($view == 'article') {
         $this->_size = $this->_params->get('size_full', '80'); //80
      } else {
         $this->_size = $this->_params->get('size_other', '60'); //60
      }
     
      $html = '';

      $page_link = $this->_params->get('page_link', '1');
      $show_author = true;
      if ($this->_gauthor) {
         $gauthor =& JPluginHelper::getPlugin('content', 'gauthor');
         $gauthor_params = new JParameter( $gauthor->params );
         if ($gauthor_params->get('authors_section') == $article->sectionid) {
            if ($gauthor_params->get( 'link_on_section', '0') == '0') $show_author = false;
            if ($view == 'article') $this->_size = $this->_params->get('size_gauthor', '100'); //100
         }
      }
     
     
      $avatar = $this->getAvatar($article);

      //for compatibility with gAuthor
      $article->created_by_alias = $avatar['alias'];

     
      switch ($this->_params->get('display_mode', '0')){
         default:
         case '0': {
            $header = array();
           
            $header['avatar'] = '<img src="'.$avatar['src'].'" style="width:'.$this->_size.'px; height:'.$this->_size.'px;" alt="'.JText::_('Avatar').'"/>';
            if ($page_link == '1' && $avatar['page']) $header['avatar'] = '<a href="'.$avatar['page'].'">'.$header['avatar'].'</a>';
            $header['suffix'] = $params->get('pageclass_sfx');
           
            if ($params->get('show_create_date')) {
               $header['date'] = JHTML::_('date', $article->created, JText::_('DATE_FORMAT_LC2'));
               $params->set('show_create_date', '0');
            } else {
               $header['date'] = false;
            }
           
            if ($params->get('show_author') && ($article->author != "") && $show_author) {
               $header['author'] = JText::sprintf('WRITTEN BY', ($article->created_by_alias ? $article->created_by_alias : $article->author));
               $params->set('show_author', '0');
            } else {
               $header['author'] = false;
            }
           
            if ($params->get('show_title')) {
               if ($params->get('link_titles') && $article->readmore_link != '') {
                  $header['title'] = '<a href="'.$article->readmore_link.'" class="contentpagetitle'.$header['suffix'].'" >'.$article->title.'</a>';
               } else {
                  $header['title'] = htmlspecialchars($article->title, ENT_QUOTES, 'UTF-8');
               }
               $params->set('show_title', '0');
            } else {
               $header['title'] = false;
            }
           
            if ($params->get('show_pdf_icon')) {
               $header['pdf'] = JHTML::_('icon.pdf', $article, $params, true);
               $params->set('show_pdf_icon', '0');
            } else {
               $header['pdf'] = false;
            }

            if ($params->get('show_print_icon')) {
               $header['print'] = JHTML::_('icon.print_popup', $article, $params, true);
               $params->set('show_print_icon', '0');
            } else {
               $header['print'] = false;
            }
            if ($params->get('show_email_icon')) {
               $header['email'] = JHTML::_('icon.email', $article, $params, true);
               $params->set('show_email_icon', '0');
            } else {
               $header['email'] = false;
            }

            if ($params->get('show_section') && $article->sectionid && isset($article->section)) {
               if ($params->get('link_section')) {
                  $header['section'] = '<a href="'.JRoute::_(ContentHelperRoute::getSectionRoute($article->sectionid)).'">'.$article->section.'</a>';
               } else {
                  $header['section'] = $article->section;
               }
               $params->set('show_section', '0');
            } else {
               $header['section'] = false;
            }
           
            if ($params->get('show_category') && $article->catid) {
               if ($params->get('link_category')) {
                  $header['cat'] = '<a href="'.JRoute::_(ContentHelperRoute::getCategoryRoute($article->catslug, $article->sectionid)).'">'.$article->category.'</a>';
               } else {
                  $header['cat'] =    $article->category;
               }
               $params->set('show_category', '0');
            } else {
               $header['cat'] = false;
            }
           
            $html = $this->drawArticleHeaderTable($header);
            if ($this->_addstyle) JHTML::stylesheet('avatar.html.css', 'plugins/content/gavatar/');
         }break;

         case '1': {
            $html = '<img class="avatar_'.$this->_params->get('float', 'right').'"'
                  . ' src="'.$avatar['src'].'"'
                  . ' alt="'.JText::_('Avatar').'"'
                  . ' style="width:'.$this->_size.'px; height:'.$this->_size.'px;"'
                  . ' />';
            if ($page_link == '1' && $avatar['page']) $html = '<a href="'.$avatar['page'].'">'.$html.'</a>';
            if ($this->_addstyle) JHTML::stylesheet('avatar.float.css', 'plugins/content/gavatar/');
            $article->text = $html.$article->text;
            $html = '';
         }break;
         
         case '2': {
            //$html = '<img class="avatar_'.$this->_params->get('float', 'right').'"'
            $html = '<img class="avatar"'
                  . ' src="'.$avatar['src'].'"'
                  . ' alt="'.JText::_('Avatar').'"'
                  . ' style="width:'.$this->_size.'px; height:'.$this->_size.'px;"'
                  . ' />';
            if ($page_link == '1' && $avatar['page']) $html = '<a href="'.$avatar['page'].'">'.$html.'</a>';
            //if ($this->_addstyle) JHTML::stylesheet('avatar.template.css', 'plugins/content/gavatar/');
            $article->avatar = $html;
            $html = '';
         }break;
      }

      if ($this->_debug){
         $article->text .='<br /><h4>gAvatar Debug</h4>'
                     .'<br />src:'.$avatar['src']
                     .'<br />username:'.$avatar['username']
                     .'<br />email:'.$avatar['email']
                     .'<br />page:'.$avatar['page']
                     .'<br />alias:'.$article->created_by_alias
                     .'<br />size:'.$this->_size
                     .'<br />';
      }
      return $html;
   }

   function getAvatar(&$article)
   {
     
      $avatar_path = $this->_params->get('avatar_path', 'images/avatars');
      $avatar_mode = $this->_params->get('avatar_mode', '1');

      //$default_img_tag = JHTML::_('image.site', 'avatar.png', 'plugins/content/gavatar/', NULL, '', $author_text, array('title'=>$author_text, 'class'=>'avatar_'.$this->_float));
      $default_img_src = JHTML::_('image.site', 'avatar.png', 'plugins/content/gavatar/', NULL, '', null, null, false);

      $avatar = array();
      $avatar_file = false;
      if ($this->_gauthor){
         //JPluginHelper::importPlugin( 'content' );
         $dispatcher =& JDispatcher::getInstance();
         
         $results = $dispatcher->trigger('getAuthors', array($article,'gavatar'));
         $avatar['alias'] = $results[0]['alias'];
         $avatar['username'] = $results[0]['author']['username'];
         $avatar['email'] = $results[0]['author']['email'];
         $avatar['page'] = $results[0]['author']['url'];
      } else if ($this->_cb){
         $avatar_file = $this->getCBAvatar($article->created_by);
         $avatar['alias'] = $article->created_by_alias;
         $avatar['username'] = $this->getUsername($article->created_by);
         $avatar['email'] = $this->getUserEmail($article->created_by);
         $avatar['page'] = JRoute::_('index.php?option=com_comprofiler&task=userProfile&user='.$article->created_by);
      } else {
         $avatar['alias'] = $article->created_by_alias;
         $avatar['username'] = $this->getUsername($article->created_by);
         $avatar['email'] = $this->getUserEmail($article->created_by);
         //TODO : Link to contact page
         $avatar['page'] = false;
         
      }

      switch ($avatar_mode)
      {
         case '0':{
            $avatar['src'] = ($avatar['email'] ? $this->getGravatar($avatar['email'], $default_img_src, $this->_size) : $default_img_src);
         } break;
         default:
         case '1':{
            $avatar_local = JPath::find(JPath::clean($avatar_path), $avatar['username'].'.png');
            $avatar['src'] = ($avatar_file ? $avatar_file : ($avatar_local ? JURI::base().$avatar_path.'/'.$avatar['username'].'.png' : ($avatar['email'] ? $this->getGravatar($avatar['email'], $default_img_src, $this->_size) : $default_img_src)));
         } break;
         case '2':{
            $avatar_local = JPath::find(JPath::clean($avatar_path), $avatar['username'].'.png');
            $avatar['src'] = ($avatar_file ? $avatar_file : ($avatar_local ? JURI::base().$avatar_path.'/'.$avatar['username'].'.png' : $default_img_src));
         }break;
      }   
      return $avatar;
   }
   
   function drawArticleHeaderTable($header)
   {
      $result = '';
      $result .= '<table class="avatar_header" style="width:100%; border:none;"><tr><td rowspan="5" class="avatar">'.$header['avatar'].'</td><td style="width:100%;"><tr class="avatar_article">';
   
      if ($header['title']) $result .='<td class="contentheading'.$header['suffix'].'" >'.$header['title'].'</td>';
      if ($header['pdf']) $result .= '<td align="right" class="buttonheading">'.$header['pdf'].'</td>';
      if ($header['print']) $result .= '<td align="right" class="buttonheading">'.$header['print'].'</td>';
      if ($header['email']) $result .= '<td align="right" class="buttonheading">'.$header['email'].'</td>';
      $result .= '</tr>';
     
      if ($header['section'] || $header['cat']) $result .= '<tr><td>';
      if ($header['section']) $result .= '<span class="content_section" >'.$header['section'].'</span>';
      if ($header['section'] && $header['cat']) $result .= ' - ';
      if ($header['cat']) $result .= '<span class="content_category" >'.$header['cat'].'</span>';
      if ($header['section'] || $header['cat']) $result .= '</td></tr>';
     
      if ($header['date']) $result .= '<tr><td class="createdate" >'.$header['date'].'</td></tr>';
      if ($header['author']) $result .= '<tr><td><span class="small">'.$header['author'].'</span></td></tr>';

      $result .= '</td></tr></table>';
     
      return $result;
   }
   
   function getGravatar($email, $default = '',$size = 80)
   {
      if ($email == false) return $default;
      //return $default;
      return 'http://www.gravatar.com/avatar.php?gravatar_id='.md5($email)
      .'&default='.urlencode($default)
      .'&size='.$size;
   }

   function getUserEmail($id)
   {
      $db = & JFactory::getDBO();
      $query = 'SELECT email FROM #__users WHERE id = ' . $db->Quote( $id );
      $db->setQuery($query, 0, 1);
      return $db->loadResult();
   }
   
   function getUsername($id)
   {
      $db = & JFactory::getDBO();
      $query = 'SELECT username FROM #__users WHERE id = ' . $db->Quote( $id );
      $db->setQuery($query, 0, 1);
      return $db->loadResult();
   }
   
   function getCBAvatar($id)
   {
      $db = & JFactory::getDBO();
      $query = 'SELECT avatar FROM #__comprofiler WHERE user_id = '.$id;
      $db->setQuery($query, 0, 1);
      $avatar = $db->loadResult();
      if($avatar && file_exists(JPATH_BASE.DS.'images'.DS.'comprofiler'.DS.$avatar)){
         return JURI::Base().'images/comprofiler/'.$avatar;
      }
      return false;
   }
}


Top
  E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

Quick reply

 



Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group