function setTitle() { $easyset = AKEasyset::getInstance(); $doc = JFactory::getDocument(); $config = JFactory::getConfig(); $siteName = $config->get('sitename'); $view = JRequest::getVar('view'); $title = $doc->getTitle(); // fix for YOOTheme $title = explode('|', $title); $title = $title[0]; if (AKHelper::isHome()) { $easyset->_siteTitle = $config->get('sitename'); } else { $separator = trim($easyset->params->get('titleSeparator')); $replace['{%SITE%}'] = $siteName; $replace['{%TITLE%}'] = $title; if ('category' == $view || 'categories' == $view) { $replace['{%CATEGORY%}'] = ''; } else { $replace['{%CATEGORY%}'] = $easyset->_catName; } $siteTitle = strtr($easyset->params->get('titleFix'), $replace); $siteTitle = explode('|', $siteTitle); foreach ($siteTitle as $k => $v) { if (!trim($v)) { unset($siteTitle[$k]); continue; } $siteTitle[$k] = trim($siteTitle[$k]); } $siteTitle = implode(" {$separator} ", $siteTitle); $easyset->_siteTitle = $siteTitle; } }
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 setScript() { $doc = JFactory::getDocument(); $body = JResponse::getBody(); $app = JFactory::getApplication(); $es = AKEasyset::getInstance(); if ($doc->getType() !== 'html') { return; } JHtml::_('behavior.framework', true); $doc->addScript(AK_ADMIN_JS_URL . '/easyset.js'); $doc->addScript(AK_JS_URL . '/easyset-custom.js'); $root = JURI::root(); $smoothScroll = $es->params->get('smoothScroll', 0); $smoothScroll = $smoothScroll ? 'true' : 'false'; $script = <<<SCRIPT \t<script type="text/javascript"> \t\tvar akoption = { \t\t\t\t"colorTable" \t: true , \t\t\t\t"opacityEffect" : true , \t\t\t\t"foldContent" \t: true , \t\t\t\t"fixingElement" : true , \t\t\t\t"smoothScroll"\t: {$smoothScroll} \t\t\t\t\t\t} ; \t\tvar akconfig = new Object(); \t\takconfig.root = '{$root}' ; \t\takconfig.host = 'http://'+location.host+'/' ; \t\t \t\tAsikartEasySet.init( akoption , akconfig ); \t</script> SCRIPT; $doc->addCustomTag($script); //include jQuery if ($es->params->get('includejQuery', 0) && $app->isSite()) { if (JDEBUG) { $doc->addScript(AK_ADMIN_JS_URL . '/jquery/jquery-1.7.2.js'); } else { $doc->addScript(AK_ADMIN_JS_URL . '/jquery/jquery-1.7.2.min.js'); } } // inculd bootstrap if ($es->params->get('includeBootstrap', 0) && $app->isSite()) { if (JDEBUG) { $doc->addStyleSheet(AK_ADMIN_CSS_URL . '/bootstrap/css/bootstrap.css'); $doc->addStyleSheet(AK_ADMIN_CSS_URL . '/bootstrap/css/bootstrap-responsive.css'); $doc->addScript(AK_ADMIN_CSS_URL . '/bootstrap/js/bootstrap.js'); } else { $doc->addStyleSheet(AK_ADMIN_CSS_URL . '/bootstrap/css/bootstrap.min.css'); $doc->addStyleSheet(AK_ADMIN_CSS_URL . '/bootstrap/css/bootstrap-responsive.min.css'); $doc->addScript(AK_ADMIN_CSS_URL . '/bootstrap/js/bootstrap.min.js'); } } }
function secure() { $app = JFactory::getApplication(); $user = JFactory::getUser(); $session = JFactory::getSession(); $es = AKEasyset::getInstance(); $mode = $es->params->get('adminSecure'); if (!$app->isAdmin() || !$mode || !$es->params->get('adminSecureCode') || !$user->get('guest') || $session->get('aksecure')) { return; } $logged = false; // http if ($mode == 'auth' || $mode == 'auth_user') { if (substr(php_sapi_name(), 0, 3) == 'cgi') { JError::raiseWarning(500, JText::_('Not Apache Handler')); return true; } if (!$session->get('tried_login')) { $_SERVER['PHP_AUTH_USER'] = null; $session->set('tried_login', true); } try { $username = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : null; $password = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : null; if ($mode == 'auth_user') { if (!$app->login(array('username' => $username, 'password' => $password), array('remember' => true))) { throw new Exception(); } $session->set('user', JFactory::getUser($username)); } else { if ($password != $es->params->get('adminSecureCode')) { throw new Exception(); } } $logged = true; } catch (Exception $e) { header('WWW-Authenticate: Basic realm="' . $app->getCfg('sitename') . '"'); header('HTTP/1.0 401 Unauthorized'); die; } } elseif ($mode == 'url') { $logged = isset($_GET[$es->params->get('adminSecureCode')]); if (!$logged) { $app->redirect(JURI::root()); } } if ($logged) { $session->set('aksecure', true); $session->set('tried_login', false); $app->redirect(JFactory::getURI()->toString()); } }
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 insertHeader() { $doc = JFactory::getDocument(); if ($doc->getType() !== 'html') { return; } $es = AKEasyset::getInstance(); $body = JResponse::getBody(); $body = explode('</head>', $body); $body[0] .= "\n" . $es->params->get('insertHeader', '') . "\n"; $body = implode('</head>', $body); JResponse::setBody($body); //$doc->addCustomTag( '<link rel="stylesheet" href="easyset/custom.css" type="text/css" />' ); }
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 customCode($position, $prepareContent = false, $article = null) { $es = AKEasyset::getInstance(); // generate code output $fileContent = $es->params->get($position, ''); $fileName = JPATH_ROOT . DS . 'tmp' . DS . 'inputcode' . DS . 'code' . DS . md5($position); $fileHash = md5($fileContent); if (!file_exists($fileName)) { JFile::write($fileName, $fileContent); } $tmpName = $fileName; $tmpContent = JFile::read($tmpName); $tmpHash = md5($tmpContent); if ($tmpHash !== $fileHash) { JFile::write($tmpName, $fileContent); } ob_start(); include $tmpName; $output = str_replace('$', '\\$', ob_get_contents()); //fixed joomla bug ob_end_clean(); // Inset the code to article if ($prepareContent) { if (!is_object($article)) { return; } switch ($position) { case 'insertArticleTop': if (JRequest::getVar('view', 'article') == 'article') { echo $output; } break; case 'insertContentTop': $article->text = $output . $article->text; break; default: return; break; } } else { return $output; } }
function insertContentTop() { $es = AKEasyset::getInstance(); $fileContent = $es->params->get('insertContentTop', ''); $fileName = JPATH_ROOT . DS . 'tmp' . DS . 'easyset' . DS . 'code' . DS . md5(__FUNCTION__); $fileHash = md5($fileContent); $tmpName = $fileName; $tmpContent = JFile::read($tmpName); $tmpHash = md5($tmpContent); if ($tmpHash !== $fileHash) { JFile::write($tmpName, $fileContent); } ob_start(); include $tmpName; $output = str_replace('$', '\\$', ob_get_contents()); //fixed joomla bug ob_end_clean(); return $output; }
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; }
function cacheManager() { $es = AKEasyset::getInstance(); $control_type = $es->params->get('cacheControlType', 'exclude'); $cache_menus = $es->params->get('CacheMenus', array()); $cache_queries = $es->params->get('CacheQueries', array()); $config = JFactory::getConfig(); $cache = null; $menus = JMenu::getInstance('site'); $uri = JFactory::getURI(); $bool = array(); /* // set Menu Itemid $route = str_replace( JURI::root(), '', $uri->toString()); $route = str_replace( '.html', '', $route); if( $route == '' || $route == 'index.php' ){ $actives = $menus->getItems( 'home' , 1 ); }else{ $actives = $menus->getItems( 'route' , $route ); } // detect cache enabled? // menus control foreach( $actives as $active ): if( in_array($active->id, $cache_menus) ){ $bool = true ; break ; } endforeach; */ $itemid = JRequest::getVar('Itemid'); if (in_array($itemid, $cache_menus)) { $bool[] = true; } // queries control $cache_queries = explode("\n", $cache_queries); //if( $bool == false ): foreach ($cache_queries as $q) { $q = explode('&', $q); $r = false; foreach ($q as $v) { $r = false; if (strpos($v, '!=')) { $v = explode('!=', $v); if (JRequest::getVar(trim($v[0])) == trim($v[1])) { break; } } else { $v = explode('=', $v); if (JRequest::getVar(trim($v[0])) != trim($v[1])) { break; } } $r = true; } $bool[] = $r ? true : false; } //endif ; $tmp = false; foreach ($bool as $v) { if ($v) { $tmp = true; break; } } $bool = $tmp; // detach cache plugin $dispatcher = JDispatcher::getInstance(); $observers = $dispatcher->get('_observers'); foreach ($observers as $observer) { if (get_class($observer) == 'plgSystemCache') { $cache = $observer; } } if ($control_type == 'include') { if ($bool == true) { $caching = 2; } else { $caching = 0; $dispatcher->detach($cache); } } else { if ($bool == true) { $caching = 0; $dispatcher->detach($cache); } else { $caching = 2; } } $config->set('caching', $caching); return $caching; }
public function __destruct() { // get some data $lang = JFactory::getLanguage(); $orphans = $lang->getOrphans(); $used = $lang->getUsed(); $es = AKEasyset::getInstance(); // get file $path = JPATH_ROOT . DS . $es->params->get('languageOrphanPath', 'logs/language.ini'); //'logs'.DS.'language.ini' ; $path = JPath::clean($path); $file = ''; if (JFile::exists($path)) { $file = JFile::read($path); } // set ini into registry, then convert to object $old = new JRegistry(); $old->loadString($file, 'INI', array('processSections' => 'true')); $old = $old->toObject(); //AK::show($old); // remove translated key foreach ((array) $old as $k => $v) { foreach ((array) $v as $k2 => $v2) { if (array_key_exists($k2, $used)) { unset($old->{$k}->{$k2}); if (!$old->{$k}) { unset($old->{$k}); } } } } //AK::show($old); // get orphan keys $obj = new JObject(); foreach ($orphans as $k => $v) { $key = explode('_', $k); $context = array_slice($key, 0, 2); $context = implode('_', $context); $lang = array_slice($key, 2); $lang = implode(' ', $lang); if (!$obj->get($context)) { $obj->set($context, new JObject()); } $obj->{$context}->set($k, $lang); } // merge ini and orphans $ini = $obj; foreach ((array) $old as $k => $v) { if (isset($ini->{$k})) { $ini->{$k} = (object) array_merge((array) $ini->{$k}, (array) $old->{$k}); } else { $ini->{$k} = $v; } $ini->{$k} = (array) $ini->{$k}; ksort($ini->{$k}); $ini->{$k} = (object) $ini->{$k}; } //AK::show($ini); // save to file $ini = new JRegistry($ini); $ini = $ini->toString('ini'); $ini = str_replace('_errors=""', '', $ini); $ini = str_replace('_errors=', '', $ini); //jimport('joomla.filesystem.path'); //JPath::setPermissions($path, 644, 755); //if(is_writable($path)) @JFile::write($path, $ini); }