示例#1
0
 /**
  * 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();
 }
 /**
  * Get a page and save it as file.
  *
  * @param   string $url    A url to request.
  * @param   string $path   A system path with file name to save it.
  * @param   array  $option An option array to override CURL OPT.
  *
  * @return  Object Object with success or fail information.
  */
 public static function download($url, $path = null, $option = array())
 {
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.folder');
     jimport('joomla.filesystem.path');
     $url = new \JUri($url);
     $path = \JPath::clean($path);
     // $folder_path = JPATH_ROOT.DS.'files'.DS.$url->task_id ;
     if (substr($path, -1) == DIRECTORY_SEPARATOR) {
         $file_name = basename($url);
         $file_path = $path . $file_name;
         $folder_path = $path;
     } else {
         $file_path = $path;
         $folder_path = str_replace(basename($path), '', $file_path);
     }
     \JPath::setPermissions($folder_path, 644, 755);
     if (!\is_dir($folder_path)) {
         \JFolder::create($folder_path);
     }
     $fp = fopen($file_path, 'w+');
     $ch = curl_init();
     $options = array(CURLOPT_URL => UriHelper::safe($url), CURLOPT_RETURNTRANSFER => true, CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.163 Safari/535.1", CURLOPT_FOLLOWLOCATION => !ini_get('open_basedir') ? true : false, CURLOPT_FILE => $fp, CURLOPT_SSL_VERIFYPEER => false);
     // Merge option
     foreach ($option as $key => $opt) {
         if (isset($option[$key])) {
             $options[$key] = $option[$key];
         }
     }
     curl_setopt_array($ch, $options);
     curl_exec($ch);
     $errno = curl_errno($ch);
     $errmsg = curl_error($ch);
     curl_close($ch);
     fclose($fp);
     if ($errno) {
         $return = new Object();
         $return->set('errorCode', $errno);
         $return->set('errorMsg', $errmsg);
         return $return;
     } else {
         $return = new Object();
         $return->set('filePath', $file_path);
         return $return;
     }
 }
示例#3
0
    if (!$menu->link) {
        continue;
    }
    if (in_array($menu->type, array('alias', 'url'))) {
        continue;
    }
    // Fix URI bugs
    $uri = new JUri($menu->link);
    $uri->setVar('Itemid', $menu->id);
    if ($app->get('sef')) {
        $uri->setVar('layout', null);
    }
    $link = JRoute::_($uri->toString());
    $host = str_replace('http://' . $_SERVER['HTTP_HOST'], '', JUri::root());
    $link = str_replace($host, '', $link);
    $link = UriHelper::pathAddHost($link);
    // Set xml data
    $sitemap->addItem($link, '0.8', 'weekly', $date);
    $linkCache[] = $link;
}
// Build category map
$query = $db->getQuery(true);
$query->select("*")->from("#__categories")->where("id != 1")->where("published = 1")->where("access = 1")->where("extension = 'com_content'");
if ($locale) {
    $query->where($query->format('language IN (%q, %q)', $locale, '*'));
}
$db->setQuery($query);
$cats = $db->loadObjectList();
foreach ($cats as $cat) {
    // Get category link
    $link = ArticleHelper::getCategoryLink($cat->id);
 /**
  * Set a URL for browser redirection.
  *
  * @param   string $url     URL to redirect to.
  * @param   string $message Message to display on redirect. Optional, defaults to value set internally by controller, if any.
  * @param   string $type    Message type. Optional, defaults to 'message' or the type set by a previous call to setMessage.
  *
  * @return  void
  */
 public function redirect($url = null, $message = null, $type = Message::MESSAGE_GREEN)
 {
     if ($this->input->get('hmvc') || !$this->input->get('redirect', true)) {
         return;
     }
     if ($this->input->get('return') && $this->allowReturn) {
         $url = UriHelper::base64('decode', $this->input->get('return'));
     }
     if (!$url && ($redirect = $this->getRedirect(true))) {
         list($url, $message, $type) = $redirect;
     }
     if ($url) {
         $this->addMessage($message, $type);
         $this->app->redirect($url);
     }
 }
示例#5
0
<?php

/** @var JApplicationWebClient $client */
$client = JFactory::getApplication()->client;
$invalidIE = JApplicationWebClient::IE === $client->browser && $client->browserVersion <= 9;
$isHome = \Windwalker\Helper\UriHelper::isHome();
?>

<?php 
if ($invalidIE && $isHome) {
    ?>
<style>
	#do-not-use-old-ie
	{
		text-align: center;
	}
	#do-not-use-old-ie .pull-left
	{
		line-height: 1.5em;
		padding: 0 8px;
	}
</style>

<div id="do-not-use-old-ie" class="modal fade">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-body">
				<p>
					為確保你瀏覽順暢,建議你使用以下的瀏覽器
				</p>
示例#6
0
 /**
  * register
  *
  * @return  void
  */
 public static function register()
 {
     $easyset = \Ezset::getInstance();
     $doc = \JFactory::getDocument();
     if ($easyset->app->isAdmin() || $doc->getType() != 'html') {
         return;
     }
     /** @var $params \JRegistry */
     $params = $easyset->params;
     $config = \JFactory::getConfig();
     $siteName = $config->get('sitename');
     $metaDesc = '';
     if ($params->get('getMeta')) {
         if ($easyset->data->metaDesc) {
             $doc->setDescription($easyset->data->metaDesc);
         }
     }
     // SEO Title
     $easyset->call(array('Seo\\ContentSeo', 'setTitle'));
     if ($params->get('titleFix') && $easyset->data->siteTitle) {
         $doc->setTitle($easyset->data->siteTitle);
     }
     // Set Generator
     if ($generator = $params->get('generator')) {
         $doc->setGenerator($generator);
     }
     // Set Open Graph
     if ($params->get('openGraph', 1)) {
         $meta = array();
         // Og:image
         if (\Ezset::isHome()) {
             if ($params->get('ogDefaultImage')) {
                 $meta[] = '<meta property="og:image" content="' . UriHelper::pathAddHost($params->get('ogDefaultImage')) . '"/>';
             }
         } elseif ($easyset->data->ogImages) {
             $count = $params->get('ogGetInnerPageImageCount', 1);
             foreach ($easyset->data->ogImages as $k => $image) {
                 if ($k + 1 > $count) {
                     break;
                 }
                 $meta[] = '<meta property="og:image" content="' . UriHelper::pathAddHost($image) . '"/>';
             }
         }
         // Others
         $url = $doc->getBase() ?: \JUri::base();
         $admin_id = $params->get('ogAdminId');
         $page_id = $params->get('ogPageId');
         $app_id = $params->get('ogAppId');
         $title = $params->get('ogOnlyTitle', 1) && !\Ezset::isHome() ? $easyset->data->originTitle : $doc->getTitle();
         $meta[] = '<meta property="og:title" content="' . $title . '"/>';
         $meta[] = '<meta property="og:site_name" content="' . $siteName . '"/>';
         if ($metaDesc) {
             $meta[] = '<meta property="og:description" content="' . $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) {
             /** @var $doc \JDocumentHtml */
             $doc->addCustomTag($v);
         }
     }
 }
 /**
  * The method to test UriHelper::pathAddHost.
  *
  * @param string $expected
  * @param string $path
  *
  * @return void
  *
  * @dataProvider pathDataProvider
  * @covers       Windwalker\Helper\UriHelper::pathAddHost
  * @group        pathAddHost
  */
 public function testPathAddHost($expected, $path)
 {
     $this->assertSame($expected, UriHelper::pathAddHost($path));
 }
 /**
  * Set a URL for browser redirection.
  *
  * @param   string $url  URL to redirect to.
  * @param   string $msg  Message to display on redirect. Optional, defaults to value set internally by controller, if any.
  * @param   string $type Message type. Optional, defaults to 'message' or the type set by a previous call to setMessage.
  *
  * @return  void
  */
 public function redirect($url, $msg = null, $type = 'message')
 {
     $this->setMessage($msg, $type);
     if ($this->input->get('hmvc') || !$this->input->get('redirect', true)) {
         return;
     }
     if ($this->input->get('return') && $this->allowReturn) {
         $url = UriHelper::base64('decode', $this->input->get('return'));
     }
     $this->app->redirect($url);
 }
示例#9
0
 /**
  * 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;
     }
 }