Exemple #1
0
 public static function registerJS($includeJS)
 {
     if (is_string($includeJS)) {
         $includeJS = [$includeJS];
     }
     if (!empty($includeJS)) {
         foreach ($includeJS as $js) {
             $jspath = realpath(Asset::resolveAlias($js));
             if (is_dir($jspath)) {
                 $path = Asset::publish($jspath);
                 $files = glob($jspath . "/*");
                 foreach ($files as $p) {
                     if (pathinfo($p, PATHINFO_EXTENSION) != "js") {
                         continue;
                     }
                     $p = str_replace($jspath, '', realpath($p));
                     Yii::app()->clientScript->registerScriptFile($path . str_replace("\\", "/", $p), CClientScript::POS_END);
                 }
             } else {
                 if (is_file($jspath)) {
                     Yii::app()->clientScript->registerScriptFile(Asset::publish($jspath), CClientScript::POS_END);
                 }
             }
         }
     }
 }
Exemple #2
0
 public static function registerCSS($includeCSS)
 {
     if (is_string($includeCSS)) {
         $includeCSS = [$includeCSS];
     }
     if (!empty($includeCSS)) {
         foreach ($includeCSS as $css) {
             $path = Asset::resolveAlias($css);
             if (is_file($path . ".css")) {
                 $file = $path . ".css";
                 if (strpos($file, Setting::getRootPath()) === 0) {
                     $file = substr($file, strlen(Setting::getRootPath()));
                     $file = Yii::app()->baseUrl . $file;
                 }
                 Yii::app()->clientScript->registerCssFile($file);
                 continue;
             }
             $csspath = realpath($path);
             if (is_dir($csspath)) {
                 $path = Asset::publish($csspath);
                 $files = glob($csspath . "/*");
                 foreach ($files as $p) {
                     if (pathinfo($p, PATHINFO_EXTENSION) != "css") {
                         continue;
                     }
                     $p = str_replace($csspath, '', realpath($p));
                     Yii::app()->clientScript->registerCssFile($path . str_replace("\\", "/", $p));
                 }
             } else {
                 if (is_file($csspath)) {
                     Yii::app()->clientScript->registerCssFile(Asset::publish($csspath));
                 }
             }
         }
     }
 }
Exemple #3
0
 public function renderEditorScript()
 {
     $html = [];
     $includeJS = $this->includeEditorJS();
     if (!empty($includeJS)) {
         foreach ($includeJS as $js) {
             $jspath = Asset::resolveAlias($js);
             if (!$jspath) {
                 $class = get_class($this);
                 $jspath = realpath(Yii::getPathOfAlias("application.components.ui.FormFields.{$class}") . '/' . $js);
             } else {
                 if (!is_dir($jspath)) {
                     $jspath = realpath($js);
                 }
             }
             if (is_dir($jspath)) {
                 $path = Asset::publish($jspath);
                 $files = glob($jspath . "/*");
                 foreach ($files as $p) {
                     if (pathinfo($p, PATHINFO_EXTENSION) != "js") {
                         continue;
                     }
                     $p = str_replace($jspath, '', realpath($p));
                     $html[] = $path . str_replace("\\", "/", $p);
                 }
             } else {
                 if (is_file($jspath)) {
                     $html[] = Asset::publish($jspath);
                 }
             }
         }
     }
     $includeCSS = $this->includeEditorCSS();
     if (!empty($includeCSS)) {
         foreach ($includeCSS as $css) {
             $csspath = Asset::resolveAlias($css);
             if (!$csspath) {
                 $class = get_class($this);
                 $csspath = realpath(Yii::getPathOfAlias("application.components.ui.FormFields.{$class}") . '/' . $css);
             } else {
                 $csspath = realpath($css);
             }
             if (is_dir($csspath)) {
                 $path = Asset::publish($csspath);
                 $files = glob($csspath . "/*");
                 foreach ($files as $p) {
                     if (pathinfo($p, PATHINFO_EXTENSION) != "css") {
                         continue;
                     }
                     $p = str_replace($csspath, '', realpath($p));
                     $html[] = $path . str_replace("\\", "/", $p);
                 }
             } else {
                 if (is_file($csspath)) {
                     $html[] = Asset::publish($csspath);
                 }
             }
         }
     }
     return $html;
 }
Exemple #4
0
 public static function getOptions($alias)
 {
     $path = Asset::resolveAlias($alias . ".php");
     ob_start();
     include $path;
     ob_get_clean();
     if (!isset($options)) {
         $options = ['mode' => 'normal'];
     }
     return $options;
 }