Exemplo n.º 1
0
 /**
  * Add a css file to the page
  * @since 4.0
  * @param string $file The path of the css file relative to the addon folder
  * @param bool $combine Set to false to keep the file from being combined with other css files
  */
 public static function css($file, $combine = true)
 {
     global $page;
     $file = \gp\tool::WinPath($file);
     if ($combine) {
         $page->css_admin[] = self::$current['code_folder_part'] . '/' . ltrim($file, '/');
         return self::$current['code_folder_part'] . '/' . ltrim($file, '/');
     }
     //less file
     $ext = \gp\tool::Ext($file);
     if ($ext === 'less' || $ext === 'scss') {
         $full_path = self::$current['code_folder_full'] . '/' . ltrim($file, '/');
         $path = \gp\tool\Output\Css::Cache($full_path, $ext);
     } else {
         $path = self::$current['code_folder_part'] . '/' . ltrim($file, '/');
     }
     if ($path !== false) {
         $page->head .= "\n" . '<link rel="stylesheet" type="text/css" href="' . \gp\tool::GetDir($path) . '"/>';
     }
     return $path;
 }
Exemplo n.º 2
0
 /**
  * Prepare and output the css for the current page
  * @static
  */
 public static function GetHead_CSS($scripts)
 {
     global $page, $config, $dataDir;
     $scripts = self::GetHead_CDN('css', $scripts);
     if (isset($page->css_user) && is_array($page->css_user)) {
         $scripts = array_merge($scripts, $page->css_user);
     }
     // add theme css
     if (!empty($page->theme_name) && $page->get_theme_css === true) {
         $scripts = array_merge($scripts, self::LayoutStyleFiles());
     }
     //styles that need to override admin.css should be added to $page->css_admin;
     if (isset($page->css_admin) && is_array($page->css_admin)) {
         $scripts = array_merge($scripts, $page->css_admin);
     }
     //convert .scss & .less files to .css
     foreach ($scripts as $key => $script) {
         if (is_array($script)) {
             $file = $script['file'];
         } else {
             $file = $script;
         }
         $ext = \gp\tool::Ext($file);
         //less and scss
         if ($ext == 'less' || $ext == 'scss') {
             $scripts[$key] = \gp\tool\Output\Css::Cache($dataDir . $file, $ext);
         }
     }
     self::CombineFiles($scripts, 'css', $config['combinecss']);
 }
Exemplo n.º 3
0
 /**
  * Organize $scripts by type
  *
  */
 public static function OrganizeByType($scripts)
 {
     $return = array('js' => array(), 'css' => array());
     foreach ($scripts as $key => $script) {
         if (empty($script['file'])) {
             continue;
         }
         if (gpdebug && !empty($script['dev'])) {
             $script['file'] = $script['dev'];
         }
         if (empty($script['type'])) {
             $script['type'] = \gp\tool::Ext($script['file']);
         }
         if ($script['type'] == 'less' || $script['type'] == 'scss') {
             $script['type'] = 'css';
         }
         $return[$script['type']][$key] = $script;
     }
     return $return;
 }