function autoThumbnail($context, $article, $params = null) { JHtml::_('behavior.modal'); $minimal = 30; $es = AKEasyset::getInstance(); $es->getFunction('dom.simple_html_dom'); $html = str_get_html($article->text); $imgs = $html->find('img'); foreach ($imgs as $img) { $classes = explode(' ', $img->class); $imgUrl = AK::_('uri.pathAddHost', $img->src); if (in_array('nothumb', $classes)) { continue; } // Has class nothumb, skip to next. if ($img->parent->tag == 'a') { continue; } // If is anchor already, skip to next. if (!$img->width && !$img->height) { continue; } // If img tag has no width and height attrs, skip. if (!strpos('-' . $imgUrl, JURI::root()) && $es->params->get('onlyLocalhostThumb', 1)) { continue; } // If not localhost image, skip. // get img path and size $imgPath = JPath::clean(str_replace(JURI::root(), JPATH_ROOT . DS, $imgUrl)); $size = getimagesize($imgPath); // manul size $imgW = $img->width; $imgH = $img->height; // original size $oriW = $size[0]; $oriH = $size[1]; if ($oriW <= $minimal || $oriH <= $minimal) { continue; } // if too small, skip. if ($oriW <= $imgW || $oriW <= $imgW) { continue; } // If large ten origin, skip. $img->src = AK::_('thumb.resize', $imgUrl, $imgW, $imgH, 0); // get thumb url $imgtext = $img->outertext; $imgtext = <<<ANCHOR \t\t<a class="modal" href="{$imgUrl}">{$imgtext}</a> ANCHOR; $img->outertext = $imgtext; $classes = null; } $article->text = $html->save(); }
function addFbLikeButton($context, $article) { $context; $context = explode('.', $context); if ($context[0] != 'com_content') { return; } // set Route $uri = AK::_('jcontent.getArticleLink', "{$article->id}:{$article->alias}", $article->catid, 1); // set like $es = AKEasyset::getInstance(); $position = $es->params->get('fbLikePosition', 1); $like = <<<LIKE \t<div class="asikart-fb-like"> \t\t<div id="fb-root"></div> \t\t<script>(function(d, s, id) { \t\t var js, fjs = d.getElementsByTagName(s)[0]; \t\t if (d.getElementById(id)) {return;} \t\t js = d.createElement(s); js.id = id; \t\t js.src = "//connect.facebook.net/zh_TW/all.js#xfbml=1"; \t\t fjs.parentNode.insertBefore(js, fjs); \t\t}(document, 'script', 'facebook-jssdk'));</script> \t\t \t\t<fb:like href="{$uri}" send="false" show_faces="false"></fb:like> \t</div> LIKE; $get = JRequest::get(); if (JRequest::getVar('view') == 'featured' || JRequest::getVar('layout') == 'blog') { if ($es->params->get('fbLikeOnBlog', 0)) { $article->introtext = $like . $article->introtext; } } elseif ($get['view'] == 'article') { switch ($position) { // After Title case 1: $article->text = $like . $article->text; break; // After Content // After Content case 2: $article->text = $article->text . $like; break; // Both // Both case 3: $article->text = $like . $article->text . $like; break; } } }
function setOpenGraph($context, $article, $es) { $view = JRequest::getVar('view'); if (empty($article->id)) { return; } if ('article' == $view) { $images = new JRegistry($article->images); $img = $images->get('image_fulltext', $images->get('image_intro')); if (!$img) { $es = AKEasyset::getInstance(); $es->getFunction('dom.simple_html_dom'); // If first image = main image, delete this paragraph. $html = str_get_html($article->text); $imgs = $html->find('img'); if (!empty($imgs[0])) { $img = $imgs[0]->src; } } $cat = JTable::getInstance('category'); $cat->load($article->catid); $cat->params = new JRegistry($cat->params); $catimg = $cat->params->get('image'); if (isset($img)) { $es->ogImage = $img; } elseif ($catimg) { $es->ogImage = AK::_('uri.pathAddHost', $catimg); } else { if (!$es->params->get('ogDefaultImageOnlyFrontPage', 1)) { $es->ogImage = AK::_('uri.pathAddHost', $es->params->get('ogDefaultImage')); } } } elseif ('category' == $view) { static $once = 1; if ($once) { $cat = JTable::getInstance('category'); $cat->load(JRequest::getVar('id')); $cat->params = new JRegistry($cat->params); $img = $cat->params->get('image'); if ($img) { $es->ogImage = $img; } elseif (!$es->params->get('ogDefaultImageOnlyFrontPage', 1)) { $es->ogImage = $es->params->get('ogDefaultImage'); } $es->ogImage = AK::_('uri.pathAddHost', $es->ogImage); } $once = 0; } }
function blogViewClearly($context, $article, $params = null) { if (JRequest::getVar('layout') != 'blog' && JRequest::getVar('view') != 'featured') { return; } $es = AKEasyset::getInstance(); $imgW = $es->params->get('blogViewImgWidth', 150); $maxChar = $es->params->get('blogViewMaxChar', 250); $crop = $es->params->get('blogViewImgCrop', 1); $allowTags = $es->params->get('blogViewTagsAllow'); $doc = JFactory::getDocument(); $text = $article->introtext; $mainImg = null; if ($doc->getType() != 'html') { return; } // Clean Tags if ($es->params->get('blogViewCleanTags', 1)) { $es->getFunction('dom.simple_html_dom'); // If first image = main image, delete this paragraph. $html = str_get_html($text); $imgs = $html->find('img'); if ($imgs) { $mainImg = $imgs[0]->src; $p = $imgs[0]->parent(); // is img in p tag? if ($p->tag != 'p') { $p = $p->parent(); } // if image has anchor, get parent. $imgtext = $p->children[0]->outertext; $p->innertext = str_replace($imgtext, '', $p->innertext); if (!trim($p->innertext)) { $p->outertext = ''; } $text = $html->save(); $text = strip_tags($text, $allowTags); if (!$allowTags) { $text = JString::substr($text, 0, $maxChar); } } } // Handle Image if ($crop) { $imageUrl = AK::_('thumb.resize', $mainImg, $imgW, $imgW, $crop); } else { $imageUrl = AK::_('thumb.resize', $mainImg, $imgW, 999, 0); } // Article Link $link = AK::_('jcontent.getArticleLink', $article->id, $article->catid, 0); // Set layout $layout = <<<LAYOUT \t\t<div class="ak_blog_layout"> \t\t\t<div class="ak_blog_img_wrap fltlft float-left"> \t\t\t\t<a class="ak_blog_img_link" href="{$link}"> \t\t\t\t\t<img class="ak_blog_img" src="{$imageUrl}" alt="{$article->title}" width="{$imgW}px" /> \t\t\t\t</a> \t\t\t</div> \t\t\t<div class="ak_blog_intro"> \t\t\t\t{$text} \t\t\t</div> \t\t\t<div class="clr clearfix"></div> \t\t</div> LAYOUT; $article->introtext = $layout; }
$url = $xml->addChild('url'); $url->addChild('loc', $link); $url->addChild('lastmod', $modified); $url->addChild('changefreq', 'weekly'); $url->addChild('priority', '0.7'); $exists_links[] = $link; } // build content map $where = AK::_('query.publishingItems', '', 'state'); $q = $db->getQuery(true); $q->select("*")->from("#__content")->where($where)->order('id DESC'); $db->setQuery($q); $contents = $db->loadObjectList(); foreach ($contents as $content) { // get category link $link = AK::_('jcontent.getArticleLink', $content->id, $content->catid, true); if (in_array($link, $exists_links)) { continue; } // set some data $modified = $content->modified != '0000-00-00 00:00:00' ? $content->modified : $content->created; $modified = JFactory::getDate($modified, JFactory::getConfig()->get('offset')); $modified = $modified->format('Y-m-d'); // set xml data $url = $xml->addChild('url'); $url->addChild('loc', $link); $url->addChild('lastmod', $modified); $url->addChild('changefreq', 'weekly'); $url->addChild('priority', '0.6'); $exists_links[] = $link; }
/** * Map API Response Filter Fields * * @param $filter_fields array Filter fields array. * @param $name string Class name. * * @return array Merged filter fields. */ public static function mergeAPIFilterFields($filter_fields, $name) { $map = (array) AK::_('system.getConfig', 'keyMap.' . $name); $map = array_keys($map); $filter_fields = array_merge($filter_fields, $map); return $filter_fields; }
function setDocument($easyset) { if ($easyset->app->isAdmin()) { return; } $doc = JFactory::getDocument(); if ($doc->getType() != 'html') { return; } $config = JFactory::getConfig(); $siteName = $config->get('sitename'); if ($easyset->params->get('getMeta')) { if (AKHelper::isHome()) { $doc->setDescription($config->get('MetaDesc')); } else { $doc->setDescription($easyset->_metaDesc); } } // SEO Title $easyset->getFunction('seo.setTitle'); if ($easyset->params->get('titleFix') && $easyset->_siteTitle) { $doc->setTitle($easyset->_siteTitle); } //set Generator if ($easyset->params->get('generator')) { $doc->setGenerator($easyset->params->get('generator')); } // set Open Graph if ($easyset->params->get('openGraph', 1)) { $meta = array(); // og:image if (AK::isHome()) { if ($easyset->params->get('ogDefaultImage')) { $meta[] = '<meta property="og:image" content="' . AK::_('uri.pathAddHost', $easyset->params->get('ogDefaultImage')) . '"/>'; } } elseif ($easyset->ogImage) { $meta[] = '<meta property="og:image" content="' . $easyset->ogImage . '"/>'; } // others $url = $doc->getBase() ? $doc->getBase() : AK::_('uri.current', true); $admin_id = $easyset->params->get('ogAdminId'); $page_id = $easyset->params->get('ogPageId'); $app_id = $easyset->params->get('ogAppId'); $meta[] = '<meta property="og:title" content="' . $doc->getTitle() . '"/>'; $meta[] = '<meta property="og:site_name" content="' . $siteName . '"/>'; $meta[] = '<meta property="og:description" content="' . $easyset->_metaDesc . '"/>'; $meta[] = '<meta property="og:url" content="' . $url . '"/>'; // admin, page, user ids if ($admin_id) { $meta[] = '<meta property="fb:admins" content="' . $admin_id . '"/>'; } if ($page_id) { $meta[] = '<meta property="fb:page_id" content="' . $page_id . '"/>'; } if ($app_id) { $meta[] = '<meta property="fb:app_id" content="' . $app_id . '"/>'; } foreach ($meta as $v) { $doc->addCustomTag($v); } } }