/** * translateAlias * * @return void */ public static function translateAlias() { $easyset = \Ezset::getInstance(); $input = \JFactory::getApplication()->input; // Set translate language $SourceLan = $easyset->params->get('originLan'); $ResultLan = $easyset->params->get('tranLan', 'en'); // Get query $jform = $input->post->getRaw('jform', array()); if (!isset($jform) || !isset($jform['alias']) || !isset($jform['title'])) { return; } $alias = $jform['alias']; $title = $jform['title']; $titleTmp = explode('::', $jform['title']); if (!empty($titleTmp[1])) { $title = $titleTmp[0]; $alias = \JFilterOutput::stringURLSafe($titleTmp[1]); } if ('' == (string) trim($alias)) { $alias = LanguageHelper::translate($title, $SourceLan, $ResultLan); $alias = trim($alias); $alias = \JFilterOutput::stringURLSafe($alias); $alias = strtr($alias, static::$replace); $alias = trim($alias, '-'); } $jform['alias'] = $alias; $jform['title'] = $title; $input = \JFactory::getApplication()->input; $input->post->set('jform', $jform, 'method', true); $input->request->set('jform', $jform); }
/** * setOpenGraph * * @param string $context * @param object $article * * @return void */ public static function setOpenGraph($context, $article) { $es = \Ezset::getInstance(); $input = \JFactory::getApplication()->input; $view = $input->get('view'); if (empty($article->id)) { return; } if (!$es->params->get('ogGetInnerPageImage', 1)) { return; } if ('article' == $view) { $images = new \JRegistry($article->images); $ignoreFirst = false; $imgs = array(); $img = $images->get('image_fulltext', $images->get('image_intro')); if ($img) { $imgs[] = $img; } if ($imgs) { $ignoreFirst = true; } $dom = new Dom(); // If first image = main image, delete this paragraph. $dom->load($article->text); $images = $dom->find('img'); foreach ($images as $image) { if ($ignoreFirst) { continue; } $imgs[] = $image->src; } if (!$imgs && isset($article->catid)) { $cat = \JTable::getInstance('category'); $cat->load($article->catid); $cat->params = new \JRegistry($cat->params); $imgs[] = $cat->params->get('image'); } if (!$imgs && !$es->params->get('ogDefaultImageOnlyFrontPage', 1)) { $imgs[] = UriHelper::pathAddHost($es->params->get('ogDefaultImage')); } $es->data->ogImages = $imgs; } elseif ('category' == $view) { if (static::$once) { $cat = \JTable::getInstance('category'); $cat->load($input->get('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 = UriHelper::pathAddHost($es->data->ogImage); } static::$once = 0; } }
/** * adminBlock * * @return void * * @throws \RuntimeException */ public static function adminBlock() { $app = \JFactory::getApplication(); $user = \JFactory::getUser(); $session = \JFactory::getSession(); $es = \Ezset::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') { $app->enqueueMessage('Not Apache handler, fallback to default login method.', 'warning'); return; } 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; // Workaround to simulate system lang input $_REQUEST['lang'] = ''; 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="This operation must login."'); header('HTTP/1.0 401 Unauthorized'); die; } } elseif ($mode == 'url') { $logged = isset($_GET[$es->params->get('adminSecureCode')]); if (!$logged) { $app->redirect(\JURI::root()); exit; } } if ($logged) { $session->set('aksecure', true); $session->set('tried_login', false); $app->redirect(\JUri::getInstance()->toString()); exit; } }
/** * autoThumb * * @param string $context * @param object $article * @param \JRegistry $params * * @return void */ public static function autoThumb($context, $article, $params = null) { \JHtmlBehavior::modal(); $minimal = 30; $es = \Ezset::getInstance(); include_once EZSET_ROOT . '/lib/dom/simple_html_dom.php'; $html = str_get_html($article->text); $imgs = $html->find('img'); foreach ($imgs as $img) { $classes = explode(' ', $img->class); $imgUrl = UriHelper::pathAddHost($img->src); // Has class nothumb, skip to next. if (in_array('nothumb', $classes)) { continue; } // If is anchor already, skip to next. if ($img->parent->tag == 'a') { continue; } // If img tag has no width and height attrs, skip. if (!$img->width && !$img->height) { continue; } // If not localhost image, skip. if (!strpos('-' . $imgUrl, \JURI::root()) && $es->params->get('onlyLocalhostThumb', 1)) { continue; } // Get img path and size $imgPath = \JPath::clean(str_replace(\JURI::root(), JPATH_ROOT . '/', $imgUrl)); $size = getimagesize($imgPath); // Manul size $imgW = $img->width; $imgH = $img->height; // Original size $oriW = $size[0]; $oriH = $size[1]; // If too small, skip. if ($oriW <= $minimal || $oriH <= $minimal) { continue; } // If large ten origin, skip. if ($oriW <= $imgW || $oriW <= $imgW) { continue; } // Get thumb url $thumb = new \Windwalker\Image\Thumb(); $img->src = $thumb->resize($imgUrl, $imgW, $imgH); $imgtext = $img->outertext; $imgtext = \JHtml::link($imgUrl, $imgtext, array('class' => 'modal')); $img->outertext = $imgtext; $classes = null; } $article->text = $html->save(); }
/** * authenticate * * @return bool * * @throws \Exception */ public static function authenticate() { $es = \Ezset::getInstance(); $input = \JFactory::getApplication()->input; $key = $es->params->get('watcherPublicKey'); if (!$key) { return false; } $token = $input->get('access_token'); if (!$token) { return false; } if (static::genPublicKey($token) === $key) { return true; } return false; }
public static function ipBlock() { $ezset = \Ezset::getInstance(); $blockType = $ezset->params->get('ipBlock', 0); if (!$blockType) { return; } $clients = $ezset->params->get('ipBlockClient'); if ($ezset->app->isSite() && !in_array('site', $clients)) { return; } if ($ezset->app->isAdmin() && !in_array('administrator', $clients)) { return; } $ips = $ezset->params->get('ipBlockList'); $ips = explode("\n", $ips); $ips = array_map('trim', $ips); $ips = static::addLocalhost($ips); $block = false; $currentIps = array(ArrayHelper::getValue($_SERVER, 'HTTP_CLIENT_IP'), ArrayHelper::getValue($_SERVER, 'HTTP_X_FORWARDED_FOR'), ArrayHelper::getValue($_SERVER, 'REMOTE_ADDR')); if (array_intersect($ips, $currentIps)) { if ($blockType == 'deny') { $block = true; } } else { if ($blockType == 'allow') { $block = true; } } $input = \JFactory::getApplication()->input; if ($ezset->app->isAdmin()) { if (isset($_GET[$ezset->params->get('adminSecureCode')]) || $input->get('task') == 'login' && $input->get('option') == 'com_login') { $block = false; } } if (!\JFactory::getUser()->guest && $ezset->app->isAdmin()) { $block = false; } if ($block) { header('HTTP/1.1 404'); die; } }
/** * likeButton * * @param string $context * @param object $article * * @return void */ public static function likeButton($context, $article) { $context = explode('.', $context); if ($context[0] != 'com_content') { return; } $input = \JFactory::getApplication()->input; $uri = \JUri::getInstance(); // Force http to make like button always use same link. $uri->setScheme('http'); // Set Route $link = JContentHelper::getArticleLink("{$article->id}:{$article->alias}", $article->catid, false); $link = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port')) . \JRoute::_($link); // Set like $es = \Ezset::getInstance(); $position = $es->params->get('fbLikePosition', 1); $like = with(new FileLayout('ezset.article.facebook.like'))->render(array('uri' => $link)); if ($input->get('view') == 'featured' || $input->get('layout') == 'blog') { if ($es->params->get('fbLikeOnBlog', 0)) { $article->introtext = $like . $article->introtext; } } elseif ($input->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; } } }
/** * register * * @return void */ public static function register() { /** @var $doc \JDocumentHtml */ $doc = \JFactory::getDocument(); $es = \Ezset::getInstance(); $input = \JFactory::getApplication()->input; if ($doc->getType() !== 'html') { return; } $uri = \JUri::getInstance(); $root = $uri::root(); $base = $uri::base(); $host = $uri->toString(array('scheme', 'host')) . '/'; if ($smoothScroll = $es->params->get('smoothScroll', 0)) { \JHtmlBehavior::framework(true); } $smoothScroll = $smoothScroll ? 'true' : 'false'; $confirmLeave = $es->params->get('confirmLeave', 0) && UriChecker::isArticleEdit() ? 'true' : 'false'; $logoLink = \JFactory::getApplication()->isAdmin() ? 'true' : 'false'; $script = <<<SCRIPT <script type="text/javascript"> \tvar ezsetOption = { \t\tsmoothScroll: {$smoothScroll}, \t\tconfirmLeave: {$confirmLeave}, \t\tlogoLink: {$logoLink} \t}; \tvar ezsetConfig = { \t\troot : '{$root}', \t\tbase : '{$base}', \t\thost : '{$host}' \t}; \tEzset.init(ezsetOption, ezsetConfig); </script> SCRIPT; $doc->addCustomTag($script); $doc->addScript(\JUri::root(true) . '/plugins/system/ezset/asset/js/ezset.js'); $doc->addScript(\JUri::root(true) . '/ezset/js/ezset-custom.js'); }
/** * execute * * @return void */ public static function execute() { $app = \JFactory::getApplication(); $input = $app->input; $option = $input->get('option'); if ($option) { return; } if ($app->isSite() && !\Ezset::isHome()) { return; } $cmd = $input->getCmd('cmd'); if ($cmd) { $cmd = str_replace('.', '/', $cmd); $file = EZSET_FRONT . '/cmd/' . $cmd . '.php'; if (!file_exists($file)) { $file = EZSET_ROOT . '/cmd/' . $cmd . '.php'; } if (file_exists($file)) { include $file; } jexit(); } }
* @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; JHtml::addIncludePath(JPATH_COMPONENT . '/helpers'); // Create shortcuts to some parameters. $params = $this->item->params; $images = json_decode($this->item->images); $urls = json_decode($this->item->urls); $canEdit = $params->get('access-edit'); $user = JFactory::getUser(); $info = $params->get('info_block_position', 0); JHtml::_('behavior.caption'); $columnClass = ' col-md-offset-2 col-md-8'; if (class_exists('Ezset') && strpos($this->pageclass_sfx, 'work') !== false) { $ezset = Ezset::getInstance(); $ezset->data->headingContent = JHtmlContent::prepare($this->item->introtext); } if (strpos($this->pageclass_sfx, 'fullwidth') !== false) { $columnClass = ''; } ?> <div class="item-page-outer row"> <div class="item-page<?php echo $this->pageclass_sfx; echo $columnClass; ?> " itemscope itemtype="http://schema.org/Article"> <meta itemprop="inLanguage" content="<?php echo $this->item->language === '*' ? JFactory::getConfig()->get('language') : $this->item->language; ?>
/** * clearView * * @param string $context * @param object $article * @param \JRegistry $params * * @return void */ public static function clearView($context, $article, $params = null) { $input = \JFactory::getApplication()->input; if ($input->get('layout') != 'blog' && $input->get('view') != 'featured') { return; } $es = \Ezset::getInstance(); $html = new Dom(); $imgW = $es->params->get('blogViewImgWidth', 150); $maxChar = $es->params->get('blogViewMaxChar', 250); $default = $es->params->get('blogViewImgDefault'); $crop = (bool) $es->params->get('blogViewImgCrop', true); $allowTags = $es->params->get('blogViewTagsAllow'); $doc = \JFactory::getDocument(); $text = $article->introtext; $mainImg = null; if ($doc->getType() != 'html') { return; } $thumb = new \Windwalker\Image\Thumb(); if ($default) { $thumb->setDefaultImage($default); } // Clean Tags if ($es->params->get('blogViewClearly', 0)) { // If first image = main image, delete this paragraph. $html = $html->load($text); /** @var \PHPHtmlParser\Dom\Collection|\PHPHtmlParser\Dom\HtmlNode[] $imgs */ $imgs = $html->find('img'); if ($imgs->count()) { $mainImg = $imgs[0]->src; // Is img in p tag? /** @var \PHPHtmlParser\Dom\HtmlNode $p */ $p = $imgs[0]->getParent(); // If image has anchor, get parent. if ($p->getTag() != 'p') { $p = $p->getParent(); } // remove first img $p->setInnerHtml(str_replace($p->firstChild()->outerHtml(), '', $p->innerHtml())); if (!trim($p->innerHtml())) { $p->setOuterHtml(''); } $text = (string) $html; } if ($es->params->get('blogViewCleanTags', 0)) { $text = strip_tags($text, $allowTags); if (!$allowTags) { $text = StringHelper::substr($text, 0, $maxChar); } } } // Handle Image if ($crop) { $imageUrl = $thumb->resize($mainImg, $imgW, $imgW, $crop); } else { $imageUrl = $thumb->resize($mainImg, $imgW, 999); } // Article Link $link = JContentHelper::getArticleLink($article->id, $article->catid, 0); $data = array('link' => $link, 'image_width' => $imgW, 'image_url' => $imageUrl, 'article' => $article, 'text' => $text); // Set layout $layout = with(new FileLayout('ezset.article.blog.clearview'))->render($data); $article->introtext = $layout; }
/** * setTitle * * @return void */ public static function setTitle() { $input = \JFactory::getApplication()->input; $ezset = \Ezset::getInstance(); $doc = \JFactory::getDocument(); $config = \JFactory::getConfig(); $siteName = $config->get('sitename'); $view = $input->get('view'); $title = $doc->getTitle(); // Fix for YOOTheme $title = explode('|', $title); $title = $title[0]; $ezset->data->originTitle = $title; if (\Ezset::isHome()) { $ezset->data->siteTitle = $config->get('sitename'); } else { $separator = trim($ezset->params->get('titleSeparator')); $replace['{%SITE%}'] = $siteName; $replace['{%TITLE%}'] = $title; if ('category' == $view || 'categories' == $view) { $replace['{%CATEGORY%}'] = ''; } else { $replace['{%CATEGORY%}'] = $ezset->data->catName; } $siteTitle = strtr($ezset->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); $ezset->data->siteTitle = $siteTitle; } }
/** * Class destructor. */ public function __destruct() { // Get some data $lang = \JFactory::getLanguage(); $orphans = $lang->getOrphans(); $used = $lang->getUsed(); $es = \Ezset::getInstance(); // Get file $path = JPATH_ROOT . '/' . $es->params->get('languageOrphanPath', 'logs/language.ini'); $path = \JPath::clean($path); $file = ''; if (\JFile::exists($path)) { $file = file_get_contents($path); } // Set ini into registry, then convert to object $old = new \JRegistry(); $old->loadString($file, 'INI', array('processSections' => 'true')); $old = $old->toObject(); // 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}); } } } } // 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}; } // Save to file $ini = new \JRegistry($ini); $ini = $ini->toString('ini'); $ini = str_replace('_errors=""', '', $ini); $ini = str_replace('_errors=', '', $ini); @\JFile::write($path, $ini); }
/** * customCode * * @param string $position * @param boolean $prepareContent * @param object $article * * @return mixed */ public static function customCode($position, $prepareContent = false, $article = null) { $es = \Ezset::getInstance(); $input = \JFactory::getApplication()->input; // Generate code output $fileContent = $es->params->get($position, ''); $fileName = JPATH_ROOT . '/tmp/inputcode/code/' . md5($position); $fileHash = md5($fileContent); if (!file_exists($fileName)) { \JFile::write($fileName, $fileContent); } $tmpName = $fileName; $tmpContent = file_get_contents($tmpName); $tmpHash = md5($tmpContent); if ($tmpHash !== $fileHash) { \JFile::write($tmpName, $fileContent); } ob_start(); include $tmpName; // Fixed joomla bug $output = str_replace('$', '\\$', ob_get_contents()); ob_end_clean(); // Inset the code to article if ($prepareContent) { if (!is_object($article)) { return ''; } switch ($position) { case 'insertArticleTop': if ($input->get('view', 'article') == 'article') { echo $output; } break; case 'insertContentTop': $article->text = $output . $article->text; break; default: return ''; break; } } else { return $output; } }
/** * favicon * * @return void * * @throws \Exception */ public static function favicon() { $app = \JFactory::getApplication(); $es = \Ezset::getInstance(); if ($app->isSite()) { $favicon = $es->params->get('faviconSite'); } else { $favicon = $es->params->get('faviconAdmin'); } if (!$favicon) { return; } /** @var \JDocumentHTML $doc */ $doc = \JFactory::getDocument(); if ($doc->getType() != 'html') { return; } foreach ($doc->_links as $key => $link) { if ($link['relation'] == 'shortcut icon') { unset($doc->_links[$key]); continue; } if (substr($key, -4) == '.ico') { unset($doc->_links[$key]); continue; } } $doc->addFavicon(\JUri::root(true) . '/' . $favicon); }
/** * Detach whole page cache plugin in specific page. * * @return int */ public static function manage() { $es = \Ezset::getInstance(); $input = \JFactory::getApplication()->input; $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; $bool = array(); $itemid = $input->get('Itemid'); if (in_array($itemid, $cache_menus)) { $bool[] = true; } // Queries control $cache_queries = explode("\n", $cache_queries); foreach ($cache_queries as $q) { $q = explode('&', $q); $r = false; foreach ($q as $v) { $r = false; // Equals if (strpos($v, '!=')) { $v = explode('!=', $v); if ($input->get(trim($v[0])) == trim($v[1])) { break; } } else { $v = explode('=', $v); if ($input->get(trim($v[0])) != trim($v[1])) { break; } } $r = true; } $bool[] = $r ? true : false; } $tmp = false; foreach ($bool as $v) { if ($v) { $tmp = true; break; } } $bool = $tmp; // Determine cache plugin $dispatcher = \JEventDispatcher::getInstance(); $observers = $dispatcher->get('_observers'); foreach ($observers as $observer) { if (get_class($observer) == 'PlgSystemCache') { $cache = $observer; } } // Let's detach cache plugin 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; }