Ejemplo n.º 1
0
 public static function addCard(&$blog, $rawIntroText)
 {
     $cfg = EasyBlogHelper::getConfig();
     // @rule: Check if user really wants to append the opengraph tags on the headers.
     if (!$cfg->get('main_twitter_cards')) {
         return false;
     }
     // Get the absolute permalink for this blog item.
     $url = EasyBlogRouter::getRoutedURL('index.php?option=com_easyblog&view=entry&id=' . $blog->id, false, true);
     // Get the image of the blog post.
     $image = self::getImage($blog, $rawIntroText);
     // @task: Get Joomla's document object.
     $doc = JFactory::getDocument();
     // Add card definition.
     $doc->addCustomTag('<meta property="twitter:card" content="summary" />');
     $doc->addCustomTag('<meta property="twitter:url" content="' . $url . '" />');
     $doc->addCustomTag('<meta property="twitter:title" content="' . $blog->title . '" />');
     $text = EasyBlogHelper::stripEmbedTags($rawIntroText);
     $text = strip_tags($text);
     $text = str_ireplace("\r\n", "", $text);
     // Remove any " in the content as this would mess up the headers.
     $text = str_ireplace('"', '', $text);
     $maxLength = 137;
     if (!empty($maxLength)) {
         $text = JString::strlen($text) > $maxLength ? JString::substr($text, 0, $maxLength) . '...' : $text;
     }
     $text = EasyBlogStringHelper::escape($text);
     $doc->addCustomTag('<meta property="twitter:description" content="' . $text . '" />');
     if ($image) {
         $doc->addCustomTag('<meta property="twitter:image" content="' . $image . '"/> ');
     }
     return true;
 }
Ejemplo n.º 2
0
 function getName()
 {
     if ($this->id == 0) {
         return JText::_('COM_EASYBLOG_GUEST');
     }
     $config = EasyBlogHelper::getConfig();
     $displayname = $config->get('layout_nameformat');
     if (!$this->user) {
         $this->user = JFactory::getUser($this->id);
     }
     switch ($displayname) {
         case "name":
             $name = $this->user->name;
             break;
         case "username":
             $name = $this->user->username;
             break;
         case "nickname":
         default:
             $name = empty($this->nickname) ? $this->user->name : $this->nickname;
             break;
     }
     return EasyBlogStringHelper::escape($name);
 }
Ejemplo n.º 3
0
    public function googleone()
    {
        $config = EasyBlogHelper::getConfig();
        $document = JFactory::getDocument();
        $frontpage = $this->isFrontend;
        $pos = $this->position;
        $googleone = !$frontpage && $config->get('main_googleone') || $frontpage && $config->get('main_googleone_frontpage', $config->get('social_show_frontpage')) && $config->get('main_googleone');
        $socialFrontEnd = $config->get('main_googleone_frontpage', 0);
        $html = '';
        if ($googleone) {
            $size = $config->get('main_googleone_layout');
            $dataURL = $this->_getDataURL();
            $dataTitle = $this->_getDataTitle();
            $buttonSize = 'social-button-';
            switch ($size) {
                case 'tall':
                    $buttonSize .= 'large';
                    break;
                case 'medium':
                default:
                    $buttonSize .= 'small';
                    break;
            }
            // Add snippet info into headers
            $document = JFactory::getDocument();
            $meta = EasyBlogHelper::getTable('Meta', 'Table');
            $meta->loadByType(META_TYPE_POST, $this->blog->id);
            $document->addCustomTag('<meta itemprop="name" content="' . $this->blog->title . '" />');
            if (!empty($meta->description)) {
                $meta->description = EasyBlogStringHelper::escape($meta->description);
                // Remove JFBConnect codes.
                $pattern = '/\\{JFBCLike(.*)\\}/i';
                $meta->description = preg_replace($pattern, '', $meta->description);
                $document->addCustomTag('<meta itemprop="description" content="' . $meta->description . '" />');
            } else {
                $maxContentLen = 350;
                $text = strip_tags($this->blog->intro . $this->blog->content);
                $text = JString::strlen($text) > $maxContentLen ? JString::substr($text, 0, $maxContentLen) . '...' : $text;
                // Remove JFBConnect codes.
                $pattern = '/\\{JFBCLike(.*)\\}/i';
                $text = preg_replace($pattern, '', $text);
                $text = EasyBlogStringHelper::escape($text);
                $document->addCustomTag('<meta itemprop="description" content="' . $text . '" />');
            }
            $image = EasyBlogHelper::getFirstImage($this->blog->intro . $this->blog->content);
            if ($image !== false) {
                $document->addCustomTag('<meta itemprop="image" content="' . $image . '" />');
            }
            $placeholder = 'sb-' . rand();
            $html .= '<div class="social-button ' . $buttonSize . ' google-plusone"><span id="' . $placeholder . '"></span></div>';
            // TODO: Verify $socialFrontEnd, what is it used for.
            // if( ! $socialFrontEnd )
            // $googleHTML	.= '<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>';
            // $googleHTML	.= '<g:plusone size="' . $size . '" href="' . $dataURL . '"></g:plusone>';
            if ($this->isBottom) {
                $html = '<div class="socialbutton-vertical align' . $pos . '">' . $html . '</div>';
            }
            $html .= EasyBlogHelper::addScriptDeclarationBookmarklet('$("#' . $placeholder . '").bookmarklet("googlePlusOne", {
				href: "' . $dataURL . '",
				size: "' . $size . '"
			});');
        }
        return $html;
    }
Ejemplo n.º 4
0
 public static function setMeta($id, $type, $defaultViewDesc = '')
 {
     $config = EasyBlogHelper::getConfig();
     $db = EasyBlogHelper::db();
     $query = 'SELECT id, keywords, description, indexing FROM ' . $db->nameQuote('#__easyblog_meta') . ' WHERE content_id = ' . $db->Quote($id) . ' and type = ' . $db->Quote($type);
     $db->setQuery($query);
     $result = $db->loadObject();
     if (!$result) {
         $result = new stdClass();
     }
     // If the category was created without any meta, we need to automatically fill in the description
     if ($type == META_TYPE_CATEGORY && !$result) {
         $category = EasyBlogHelper::getTable('Category');
         $category->load($id);
         JFactory::getDocument()->setMetadata('description', strip_tags($category->description));
     }
     //auto fill meta keywords if the option is enable and the user did not set his own meta keywords.
     if ($type == META_TYPE_POST && ($config->get('main_meta_autofillkeywords') && empty($result->keywords) || $config->get('main_meta_autofilldescription'))) {
         $keywords = array();
         //set category into the meta keyword.
         $post = EasyBlogHelper::getTable('Blog', 'Table');
         $post->load($id);
         $post->intro = EasyBlogHelper::getHelper('Videos')->processVideos($post->intro, true);
         $post->content = EasyBlogHelper::getHelper('Videos')->processVideos($post->content, true);
         $category = EasyBlogHelper::getTable('Category', 'Table');
         $category->load($post->category_id);
         $keywords[] = $category->title;
         if ($config->get('main_meta_autofillkeywords') && empty($result->keywords)) {
             //set tags into the meta keyword.
             $modelPT = self::getModel('PostTag');
             $blogTags = $modelPT->getBlogTags($id);
             if (!empty($blogTags)) {
                 foreach ($blogTags as $tag) {
                     $keywords[] = $tag->title;
                 }
             }
             $result->keywords = implode(',', $keywords);
         }
         if ($config->get('main_meta_autofilldescription') && empty($result->description)) {
             $content = !empty($post->intro) ? strip_tags($post->intro) : strip_tags($post->content);
             $content = str_ireplace("\r\n", "", $content);
             $content = str_ireplace("&nbsp;", " ", $content);
             $content = trim($content);
             // @rule: Set description into meta headers
             $result->description = JString::substr($content, 0, $config->get('main_meta_autofilldescription_length'));
             $result->description = EasyBlogStringHelper::escape($result->description);
         }
         // Remove JFBConnect codes.
         if (isset($result->description)) {
             $pattern = '/\\{JFBCLike(.*)\\}/i';
             $result->description = preg_replace($pattern, '', $result->description);
         }
     }
     // check if the descriptin or keysword still empty or not. if yes, try to get from joomla menu.
     if (empty($result->description) && empty($result->keywords)) {
         $menu = JFactory::getApplication()->getMenu();
         $item = $menu->getActive();
         if (is_object($item)) {
             $params = EasyBlogHelper::getRegistry($item->params);
             $description = $params->get('menu-meta_description', '');
             $keywords = $params->get('menu-meta_keywords', '');
             if (!(empty($description) && empty($keywords))) {
                 $result = new stdClass();
                 $result->description = EasyBlogStringHelper::escape($description);
                 $result->keywords = $keywords;
             }
         }
     }
     if (!empty($result)) {
         $document = JFactory::getDocument();
         if (!empty($result->keywords)) {
             $document->setMetadata('keywords', $result->keywords);
         }
         if (!empty($result->description)) {
             $document->setMetadata('description', $result->description);
         } else {
             if (!empty($defaultViewDesc)) {
                 //get joomla default description.
                 $joomlaDesc = EasyBlogHelper::getJConfig()->get('MetaDesc');
                 $metaDesc = $defaultViewDesc . ' - ' . $joomlaDesc;
                 $metaDesc = EasyBlogStringHelper::escape($metaDesc);
                 $document->setMetadata('description', $metaDesc);
             }
         }
         // @task: Set the noindex if necessary.
         if (isset($result->indexing) && !$result->indexing) {
             $document->setMetadata('robots', 'noindex,follow');
         }
     }
 }
Ejemplo n.º 5
0
 function escape($val)
 {
     return EasyBlogStringHelper::escape($val);
 }
Ejemplo n.º 6
0
 public static function addOpenGraphTags(&$blog, $rawIntroText = '')
 {
     $cfg = EasyBlogHelper::getConfig();
     // @rule: Check if user really wants to append the opengraph tags on the headers.
     if (!$cfg->get('main_facebook_opengraph')) {
         return false;
     }
     // Get the absolute permalink for this blog item.
     $url = EasyBlogRouter::getRoutedURL('index.php?option=com_easyblog&view=entry&id=' . $blog->id, false, true);
     // Get the image of the blog post.
     $image = self::getImage($blog, $rawIntroText);
     // @task: Get Joomla's document object.
     $doc = JFactory::getDocument();
     // Add the blog image.
     $doc->addCustomTag('<meta property="og:image" content="' . $image . '"/> ');
     if ($cfg->get('main_facebook_like')) {
         $doc->addCustomTag('<meta property="fb:app_id" content="' . $cfg->get('main_facebook_like_appid') . '"/> ');
         $doc->addCustomTag('<meta property="fb:admins" content="' . $cfg->get('main_facebook_like_admin') . '"/>');
     }
     $meta = EasyBlogHelper::getTable('Meta', 'Table');
     $meta->loadByType(META_TYPE_POST, $blog->id);
     $doc->addCustomTag('<meta property="og:title" content="' . $blog->title . '" />');
     // @task: Add description of the blog.
     if (!empty($meta->description)) {
         $meta->description = EasyBlogStringHelper::escape($meta->description);
         $doc->addCustomTag('<meta property="og:description" content="' . $meta->description . '" />');
     } else {
         $maxLength = $cfg->get('integrations_facebook_blogs_length');
         $text = EasyBlogHelper::stripEmbedTags($rawIntroText);
         $text = strip_tags($text);
         $text = str_ireplace("\r\n", "", $text);
         // Remove any " in the content as this would mess up the headers.
         $text = str_ireplace('"', '', $text);
         if (!empty($maxLength)) {
             $text = JString::strlen($text) > $maxLength ? JString::substr($text, 0, $maxLength) . '...' : $text;
         }
         $text = EasyBlogStringHelper::escape($text);
         $doc->addCustomTag('<meta property="og:description" content="' . $text . '" />');
     }
     $doc->addCustomTag('<meta property="og:type" content="article" />');
     $doc->addCustomTag('<meta property="og:url" content="' . $url . '" />');
     return true;
 }