Пример #1
0
 /**
  * @param $dir SPDirectoryIterator
  * @param $nodes string
  * @param $current int
  * @param $count
  * @param bool $package
  * @return void
  */
 private function travelTpl($dir, &$nodes, $current, &$count, $package = false)
 {
     $ls = Sobi::FixPath(Sobi::Cfg('img_folder_live') . '/tree');
     static $root = null;
     if (!$root) {
         $root = new SPFile(SOBI_PATH);
     }
     $exceptions = array('config.xml', 'config.json');
     foreach ($dir as $file) {
         $task = null;
         $fileName = $file->getFilename();
         if (in_array($fileName, $exceptions)) {
             continue;
         }
         if ($file->isDot()) {
             continue;
         }
         $count++;
         if ($file->isDir()) {
             if ($current == 0 || $package) {
                 if (strstr($file->getPathname(), $root->getPathname())) {
                     $filePath = str_replace($root->getPathname() . '/usr/templates/', null, $file->getPathname());
                 } else {
                     $filePath = 'cms:' . str_replace(SOBI_ROOT . '/', null, $file->getPathname());
                 }
                 $filePath = str_replace('/', '.', $filePath);
                 $insertTask = Sobi::Url(array('task' => 'template.info', 'template' => $filePath));
                 $nodes .= "spTpl.add( {$count}, {$current},'{$fileName}','', '', '', '{$ls}/imgfolder.gif', '{$ls}/imgfolder.gif' );\n";
                 if (!Sobi::Section()) {
                     $count2 = $count * -100;
                     $fileName = Sobi::Txt('TP.INFO');
                     $nodes .= "spTpl.add( {$count2}, {$count},'{$fileName}','{$insertTask}', '', '', '{$ls}/info.png' );\n";
                     if (file_exists($file->getPathname() . "/config.xml")) {
                         $fileName = Sobi::Txt('TP.SETTINGS');
                         $count2--;
                         $insertTask = Sobi::Url(array('task' => 'template.settings', 'template' => $filePath));
                         $nodes .= "spTpl.add( {$count2}, {$count},'{$fileName}','{$insertTask}', '', '', '{$ls}/settings.png' );\n";
                     }
                 }
             } else {
                 $nodes .= "spTpl.add( {$count}, {$current},'{$fileName}','');\n";
             }
             $this->travelTpl(new SPDirectoryIterator($file->getPathname()), $nodes, $count, $count);
         } else {
             $ext = SPFs::getExt($fileName);
             if (in_array($ext, array('htaccess', 'zip')) || $fileName == 'index.html') {
                 continue;
             }
             switch (strtolower($ext)) {
                 case 'php':
                     $ico = $ls . '/php.png';
                     break;
                 case 'xml':
                     $ico = $ls . '/xml.png';
                     break;
                 case 'xsl':
                     $ico = $ls . '/xsl.png';
                     break;
                 case 'css':
                     $ico = $ls . '/css.png';
                     break;
                 case 'jpg':
                 case 'jpeg':
                 case 'png':
                 case 'bmp':
                 case 'gif':
                     $ico = $ls . '/img.png';
                     $task = 'javascript:void(0);';
                     break;
                 case 'ini':
                     $ico = $ls . '/ini.png';
                     break;
                 case 'less':
                     $ico = $ls . '/less.png';
                     break;
                 case 'js':
                     $ico = $ls . '/js.png';
                     break;
                 default:
                     $ico = $ls . '/page.gif';
             }
             if (!$task) {
                 if (strstr($file->getPathname(), $root->getPathname())) {
                     $filePath = str_replace($root->getPathname() . '/usr/templates/', null, $file->getPathname());
                 } else {
                     $filePath = 'cms:' . str_replace(SOBI_ROOT . DS, null, $file->getPathname());
                 }
                 $filePath = str_replace('/', '.', $filePath);
                 if (Sobi::Section()) {
                     $task = Sobi::Url(array('task' => 'template.edit', 'file' => $filePath, 'sid' => Sobi::Section()));
                 } else {
                     $task = Sobi::Url(array('task' => 'template.edit', 'file' => $filePath));
                 }
             }
             $nodes .= "spTpl.add( {$count}, {$current},'{$fileName}','{$task}', '', '', '{$ico}' );\n";
         }
     }
 }
Пример #2
0
 /**
  * @param SPFile $file
  * @return string
  * */
 protected function functionDetails($file)
 {
     $xml = new DOMDocument();
     $xml->load($file->getPathname());
     $xpath = new DOMXPath($xml);
     $title = $xpath->query('/definition/header/title')->item(0)->attributes->getNamedItem('value')->nodeValue;
     $this->loadLanguage($xpath);
     return Sobi::Txt($title);
 }