/** * @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"; } } }
/** * @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); }
/** * Creates temporary (variable) JavaScript file * * @param string $script * @param string $id * @param string $params * @param bool $adm * @return SPHeader */ public function &addJsVarFile($script, $id, $params, $adm = false) { $this->store(get_defined_vars(), __FUNCTION__); $checksum = md5(json_encode(get_defined_vars())); if (!isset($this->_checksums[__FUNCTION__][$checksum])) { $this->_checksums[__FUNCTION__][$checksum] = true; $varFile = SPLoader::translatePath("var.js.{$script}_{$id}", 'front', true, 'js'); if (!$varFile) { $file = SPLoader::JsFile($script, $adm, true, false); if ($file) { SPLoader::loadClass('base.fs.file'); $file = new SPFile($file); $fc =& $file->read(); foreach ($params as $k => $v) { $fc = str_replace("__{$k}__", $v, $fc); } $fc = str_replace('__CREATED__', date(SPFactory::config()->key('date.log_format', 'D M j G:i:s T Y')), $fc); $varFile = SPLoader::translatePath("var.js.{$script}_{$id}", 'front', false, 'js'); $file->saveAs($varFile); } else { Sobi::Error(__FUNCTION__, SPLang::e('CANNOT_LOAD_FILE_AT', $file), SPC::NOTICE, 0, __LINE__, __FILE__); } } if (Sobi::Cfg('cache.include_js_files', false) && !($adm || defined('SOBIPRO_ADM'))) { $this->_cache['js'][++$this->count] = $varFile; } else { $varFile = str_replace(SOBI_ROOT, SPFactory::config()->get('live_site'), $varFile); $varFile = str_replace('\\', '/', $varFile); $varFile = preg_replace('|(\\w)(//)(\\w)|', '$1/$3', $varFile); $varFile = "\n<script type=\"text/javascript\" src=\"{$varFile}\"></script>"; if (!in_array($varFile, $this->jsFiles)) { $this->jsFiles[++$this->count] = $varFile; } } } return $this; }
/** * Get all SharePoint Items (Folders/Files) * * @static * @access public * @param array $settings Instantiation settings * @return array */ public function getSPItems(array $settings = []) { $settings = array_replace_recursive($settings, ['folders' => ['extra' => []], 'files' => ['extra' => []]]); $folders = static::getSubFolders($this->site, $this->relativeUrl, $settings['folders']); $files = SPFile::getAll($this, $settings['files']['extra']); $this->items = array_merge($folders, $files); return $this->items; }