예제 #1
0
 /**
  * Return the pagination footer.
  *
  * @return  string   Pagination footer.
  *
  * @since   11.1
  */
 public function getListFooter()
 {
     $app = JFactory::getApplication();
     $list = array();
     $list['prefix'] = $this->prefix;
     $list['limit'] = $this->limit;
     $list['limitstart'] = $this->limitstart;
     $list['total'] = $this->total;
     $list['limitfield'] = $this->getLimitBox();
     $list['pagescounter'] = $this->getPagesCounter();
     $list['pageslinks'] = $this->getPagesLinks();
     // Plazart: detect if chrome pagination.php in template or in plugin
     $chromePath = PlazartPath::getPath('html/pagination.php');
     //$chromePath = JPATH_THEMES . '/' . $app->getTemplate() . '/html/pagination.php';
     if (file_exists($chromePath)) {
         include_once $chromePath;
         if (function_exists('pagination_list_footer')) {
             return pagination_list_footer($list);
         }
     }
     return $this->_list_footer($list);
 }
예제 #2
0
파일: path.php 프로젝트: Rus1an/plazart
 public static function updateUrl($css, $src)
 {
     self::$srcurl = $src;
     $css = preg_replace_callback('/@import\\s+([\'"])(.*?)[\'"]/', array('PlazartPath', 'replaceurl'), $css);
     $css = preg_replace_callback('/url\\(\\s*([^\\)\\s]+)\\s*\\)/', array('PlazartPath', 'replaceurl'), $css);
     return $css;
 }
예제 #3
0
파일: less.php 프로젝트: Rus1an/plazart
 public static function addStylesheet($lesspath)
 {
     // build less vars, once only
     static $vars_built = false;
     $plazartless = PlazartLess::getInstance();
     if (!$vars_built) {
         self::buildVars();
         $vars_built = true;
     }
     $app = JFactory::getApplication();
     $tpl = $app->getTemplate(true);
     $theme = $tpl->params->get('theme');
     $doc = JFactory::getDocument();
     if (defined('PLAZART_THEMER')) {
         // in Themer mode, using js to parse less for faster
         $doc->addStylesheet(JURI::base(true) . '/' . PlazartPath::cleanPath($lesspath), 'text/less');
         // Add lessjs to process lesscss
         $doc->addScript(PLAZART_URL . '/js/less-1.3.3.js');
     } else {
         // in development mode, using php to compile less for a better view of development
         if (preg_match('#(template(-responsive)?.less)#', $lesspath)) {
             // Development mode is on, try to include less file inside folder less/
             // get the less content
             $lessContent = JFile::read(JPATH_ROOT . '/' . $lesspath);
             $path = dirname($lesspath);
             // parse less content
             if (preg_match_all('#^\\s*@import\\s+"([^"]*)"#im', $lessContent, $matches)) {
                 foreach ($matches[1] as $url) {
                     if ($url == 'vars.less') {
                         continue;
                     }
                     $url = $path . '/' . $url;
                     // $doc->addStyleSheet(JURI::current().'?plazartaction=lessc&s='.PlazartPath::cleanPath($url));
                     //
                     $cssurl = $plazartless->buildCss(PlazartPath::cleanPath($url));
                     $doc->addStyleSheet($cssurl);
                 }
             }
         } else {
             // $doc->addStyleSheet(JURI::current().'?plazartaction=lessc&s='.PlazartPath::cleanPath($lesspath));
             //
             $cssurl = $plazartless->buildCss(PlazartPath::cleanPath($lesspath));
             $doc->addStyleSheet($cssurl);
         }
         // check and add theme less
         if ($theme && !preg_match('#bootstrap#', $lesspath)) {
             $themepath = str_replace('/less/', '/less/themes/' . $theme . '/', $lesspath);
             if (is_file(JPATH_ROOT . '/' . $themepath)) {
                 // $doc->addStyleSheet(JURI::current().'?plazartaction=lessc&s='.PlazartPath::cleanPath($themepath));
                 $cssurl = $plazartless->buildCss(PlazartPath::cleanPath($themepath));
                 $doc->addStyleSheet($cssurl);
             }
         }
     }
 }
예제 #4
0
파일: minify.php 프로젝트: Rus1an/plazart
 /**
  * @param   $tpl  template object
  * @return  bool  optimize success or not
  */
 public static function optimizecss($tpl)
 {
     $outputpath = JPATH_ROOT . '/' . $tpl->getParam('plazart-assets', 'plazart-assets') . '/css';
     $outputurl = JURI::root(true) . '/' . $tpl->getParam('plazart-assets', 'plazart-assets') . '/css';
     if (!JFile::exists($outputpath)) {
         JFolder::create($outputpath);
         @chmod($outputpath, 0755);
     }
     if (!is_writeable($outputpath)) {
         return false;
     }
     //prepare config
     self::prepare($tpl);
     $doc = JFactory::getDocument();
     //======================= Group css ================= //
     $mediagroup = array();
     $cssgroups = array();
     $stylesheets = array();
     $ielimit = 4095;
     $selcounts = 0;
     $regex = '/\\{.+?\\}|,/s';
     //selector counter
     $csspath = '';
     // group css into media
     $mediagroup['all'] = array();
     $mediagroup['screen'] = array();
     foreach ($doc->_styleSheets as $url => $stylesheet) {
         $media = $stylesheet['media'] ? $stylesheet['media'] : 'all';
         if (empty($mediagroup[$media])) {
             $mediagroup[$media] = array();
         }
         $mediagroup[$media][$url] = $stylesheet;
     }
     foreach ($mediagroup as $media => $group) {
         $stylesheets = array();
         // empty - begin a new group
         foreach ($group as $url => $stylesheet) {
             $url = self::fixUrl($url);
             if ($stylesheet['mime'] == 'text/css' && ($csspath = self::cssPath($url))) {
                 $stylesheet['path'] = $csspath;
                 $stylesheet['data'] = file_get_contents($csspath);
                 $selcount = preg_match_all($regex, $stylesheet['data'], $matched);
                 if (!$selcount) {
                     $selcount = 1;
                     //just for sure
                 }
                 //if we found an @import rule or reach IE limit css selector count, break into the new group
                 if (preg_match('#@import\\s+.+#', $stylesheet['data']) || $selcounts + $selcount >= $ielimit) {
                     if (count($stylesheets)) {
                         $cssgroup = array();
                         $groupname = array();
                         foreach ($stylesheets as $gurl => $gsheet) {
                             $cssgroup[$gurl] = $gsheet;
                             $groupname[] = $gurl;
                         }
                         $cssgroup['groupname'] = implode('', $groupname);
                         $cssgroup['media'] = $media;
                         $cssgroups[] = $cssgroup;
                     }
                     $stylesheets = array($url => $stylesheet);
                     // empty - begin a new group
                     $selcounts = $selcount;
                 } else {
                     $stylesheets[$url] = $stylesheet;
                     $selcounts += $selcount;
                 }
             } else {
                 // first get all the stylsheets up to this point, and get them into
                 // the items array
                 if (count($stylesheets)) {
                     $cssgroup = array();
                     $groupname = array();
                     foreach ($stylesheets as $gurl => $gsheet) {
                         $cssgroup[$gurl] = $gsheet;
                         $groupname[] = $gurl;
                     }
                     $cssgroup['groupname'] = implode('', $groupname);
                     $cssgroup['media'] = $media;
                     $cssgroups[] = $cssgroup;
                 }
                 //mark ignore current stylesheet
                 $cssgroup = array($url => $stylesheet, 'ignore' => true);
                 $cssgroups[] = $cssgroup;
                 $stylesheets = array();
                 // empty - begin a new group
             }
         }
         if (count($stylesheets)) {
             $cssgroup = array();
             $groupname = array();
             foreach ($stylesheets as $gurl => $gsheet) {
                 $cssgroup[$gurl] = $gsheet;
                 $groupname[] = $gurl;
             }
             $cssgroup['groupname'] = implode('', $groupname);
             $cssgroup['media'] = $media;
             $cssgroups[] = $cssgroup;
         }
     }
     //======================= Group css ================= //
     $output = array();
     foreach ($cssgroups as $cssgroup) {
         if (isset($cssgroup['ignore'])) {
             unset($cssgroup['ignore']);
             unset($cssgroup['groupname']);
             unset($cssgroup['media']);
             foreach ($cssgroup as $furl => $fsheet) {
                 $output[$furl] = $fsheet;
             }
         } else {
             $media = $cssgroup['media'];
             $groupname = 'css-' . substr(md5($cssgroup['groupname']), 0, 5) . '.css';
             $groupfile = $outputpath . '/' . $groupname;
             $grouptime = JFile::exists($groupfile) ? @filemtime($groupfile) : -1;
             $rebuild = $grouptime < 0;
             //filemtime == -1 => rebuild
             unset($cssgroup['groupname']);
             unset($cssgroup['media']);
             foreach ($cssgroup as $furl => $fsheet) {
                 if (!$rebuild && @filemtime($fsheet['path']) > $grouptime) {
                     $rebuild = true;
                 }
             }
             if ($rebuild) {
                 $cssdata = array();
                 foreach ($cssgroup as $furl => $fsheet) {
                     $cssdata[] = "\n\n/*===============================";
                     $cssdata[] = $furl;
                     $cssdata[] = "================================================================================*/";
                     $cssmin = self::minifyCss($fsheet['data']);
                     $cssmin = PlazartPath::updateUrl($cssmin, PlazartPath::relativePath($outputurl, dirname($furl)));
                     $cssdata[] = $cssmin;
                 }
                 $cssdata = implode("\n", $cssdata);
                 if (!JFile::write($groupfile, $cssdata)) {
                     // cannot write file, ignore minify
                     return false;
                 }
                 $grouptime = @filemtime($groupfile);
                 @chmod($groupfile, 0644);
             }
             $output[$outputurl . '/' . $groupname . '?t=' . $grouptime % 1000] = array('mime' => 'text/css', 'media' => $media == 'all' ? NULL : $media, 'attribs' => array());
         }
     }
     //apply the change make change
     $doc->_styleSheets = $output;
 }
예제 #5
0
파일: template.php 프로젝트: Rus1an/plazart
 /**
  * Add some other condition assets (css, javascript)
  */
 function addExtraAssets()
 {
     $base = JURI::base(true);
     $regurl = '#(http|https)://([a-zA-Z0-9.]|%[0-9A-Za-z]|/|:[0-9]?)*#iu';
     foreach (array(PLAZART_PATH, PLAZART_TEMPLATE_PATH) as $bpath) {
         //full path
         $afile = $bpath . '/etc/assets.xml';
         if (is_file($afile)) {
             //load xml
             $axml = JFactory::getXML($afile);
             //parse stylesheets first if exist
             if ($axml) {
                 foreach ($axml as $node => $nodevalue) {
                     //ignore others node
                     if ($node == 'stylesheets' || $node == 'scripts') {
                         foreach ($nodevalue->file as $file) {
                             $compatible = $file['compatible'];
                             if ($compatible) {
                                 $parts = explode(' ', $compatible);
                                 $operator = '=';
                                 //exact equal to
                                 $operand = $parts[1];
                                 if (count($parts) == 2) {
                                     $operator = $parts[0];
                                     $operand = $parts[1];
                                 }
                                 //compare with Joomla version
                                 if (!version_compare(JVERSION, $operand, $operator)) {
                                     continue;
                                 }
                             }
                             $url = (string) $file;
                             if (substr($url, 0, 2) == '//') {
                                 //external link
                             } else {
                                 if ($url[0] == '/') {
                                     //absolute link from based folder
                                     $url = is_file(JPATH_ROOT . $url) ? $base . $url : false;
                                 } else {
                                     if (!preg_match($regurl, $url)) {
                                         //not match a full url -> sure internal link
                                         $url = PlazartPath::getUrl($url);
                                         // so get it
                                     }
                                 }
                             }
                             if ($url) {
                                 if ($node == 'stylesheets') {
                                     $this->addStylesheet($url);
                                 } else {
                                     $this->addScript($url);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }