protected function registerPluginsImpl()
 {
     $pluginType = strtolower(cut_string_end(cut_string_start(get_called_class(), 'Smarty'), 's'));
     foreach (PsUtil::getClassMethods(get_called_class(), true, true, null, true) as $tagName) {
         $this->register($tagName, $pluginType);
     }
 }
Ejemplo n.º 2
0
 public function getProps()
 {
     if (is_array($this->props)) {
         return $this->props;
     }
     $this->props = array();
     if (!$this->di->isFile()) {
         return $this->props;
     }
     $prop = null;
     $content = array();
     foreach ($this->di->getFileLines() as $line) {
         $line = trim($line);
         if (!$line) {
             continue;
         }
         if (starts_with($line, '[') && ends_with($line, ']')) {
             //Нашли свойство. Приверим, а нет ли информации о предыдущем свойстве
             if ($prop) {
                 $this->props[$prop] = trim(implode("\n", $content));
                 $content = array();
             }
             $prop = trim(cut_string_end(cut_string_start($line, '['), ']'));
             continue;
         }
         if (!$prop) {
             continue;
         }
         $content[] = $line;
     }
     if ($prop) {
         $this->props[$prop] = trim(implode("\n", $content));
     }
     return $this->props;
 }
Ejemplo n.º 3
0
 protected function getPlugins()
 {
     $type = strtolower(cut_string_end(cut_string_start($this->CLASS, 'Smarty'), 's'));
     $result = array();
     foreach (PsUtil::getClassMethods($this->CLASS, true, true, null, true) as $method) {
         $result[$method] = $type;
     }
     return $result;
 }
Ejemplo n.º 4
0
 /**
  * Название файла конфига
  */
 public static function getConfigName()
 {
     $class = self::getClass();
     if (array_key_exists($class, self::$CLASS2FILE)) {
         return self::$CLASS2FILE[$class];
     }
     if ($class == __CLASS__) {
         PsUtil::raise('Illegal to call {}::{}', __CLASS__, __FUNCTION__);
     }
     return self::$CLASS2FILE[$class] = cut_string_end(strtolower($class), 'ini') . '.ini';
 }
Ejemplo n.º 5
0
function saveResult2Html($tplName, $params = null, $__DIR__ = __DIR__, $htmlName = 'results.html', $title = null)
{
    $tplName = ensure_file_ext($tplName, 'tpl');
    $pageClass = cut_string_end($tplName, '.tpl');
    $body = PSSmarty::template("hometools/{$tplName}", $params)->fetch();
    $pageParams['title'] = $title == null ? 'Результаты' : $title;
    $pageParams['body'] = $body;
    $pageParams['class'] = $pageClass;
    $html = PSSmarty::template('hometools/page_pattern.tpl', $pageParams)->fetch();
    $htmlName = ensure_file_ext($htmlName, 'html');
    DirItem::inst($__DIR__, $htmlName)->writeToFile($html, true);
}
Ejemplo n.º 6
0
 /**
  * Основной метод, возвращающий путь к классу
  */
 public function getClassPath($className)
 {
     $className = cut_string_end($className, '.php');
     $this->LOGGER->info('');
     $this->LOGGER->info("Searching path for class [{$className}].");
     $path = $this->getClassPathImpl($className);
     $this->LOGGER->info("Path [{$path}] returned.");
     return $path;
 }
Ejemplo n.º 7
0
 /**
  * Метод рекурсивно собирает все классы в директории.
  * 
  * @param string $dirAbsPath - путь к директории
  * @param array $classes - карта [PsUtil] => [C:/www/postupayu.ru/www/kitcore/utils/PsUtil.php]
  * @param bool $skipDirClasses - пропускать ли классы в корневой директории.
  * Флаг позволит не подключать классы, лежащие в корне kitcore,
  * так как их мы подключим сами (Globals, Defines, PsCoreIncluder)
  */
 public static function loadClassPath($dirAbsPath, array &$classes, $skipDirClasses)
 {
     if (!is_dir($dirAbsPath)) {
         return;
         //---
     }
     $dir = openDir($dirAbsPath);
     while ($file = readdir($dir)) {
         if (!is_valid_file_name($file)) {
             continue;
         }
         $isphp = ends_with($file, '.php');
         if ($isphp && $skipDirClasses) {
             continue;
         }
         $path = next_level_dir($dirAbsPath, $file);
         if ($isphp) {
             $classes[cut_string_end($file, '.php')] = $path;
         } else {
             self::loadClassPath($path, $classes, false);
         }
     }
     closedir($dir);
 }
Ejemplo n.º 8
0
 private function getImages(ArrayAdapter $params, $FNAME)
 {
     $dir = $params->str('dir');
     $name = $params->get('name');
     //НЕПОСРЕДСТВЕННО КАРТИНКА
     if ($name instanceof DirItem) {
         return $name;
     }
     /*
      * FOLDING
      */
     $FCW = FoldedContextWatcher::getInstance();
     $folding = null;
     $ident = $params->get('ident');
     //Тип фолдинга. Он может быть передан либо в параметре 'group', либо по префиксу смарти-функции, например: postimg (post-название типа фолдинга).
     $foldingType = $params->get('group');
     $foldingType = $foldingType ? $foldingType : (starts_with($FNAME, 'img') ? null : array_get_value(0, explode('img', $FNAME)));
     //Подтип фолдинга, например: is - подтип фолдингов для фолдингов с типом post (выпуск журнала среди всех постов).
     $foldingSubType = $params->get('type');
     if ($params->has('post')) {
         /* @var $post AbstractPost */
         $post = $params->get('post');
         $ident = $post->getIdent();
         $folding = Handlers::getInstance()->getPostsProcessorByPostType($post->getPostType())->getFolding();
     } else {
         if ($foldingType) {
             $hasSubtype = FoldedStorage::isFoldingHasSubtype($foldingType);
             if ($hasSubtype && !$foldingSubType) {
                 //У фолдинга есть подтип, но в параметрах он не передан - определим фолдинг по контексту
                 $folding = $FCW->getFoldedEntityEnsureType($foldingType)->getFolding();
             } else {
                 $folding = FoldedStorageInsts::byTypeStype($foldingType, $foldingSubType);
             }
         } else {
             if ($foldingSubType) {
                 //Если передан только тип, то считаем, что имеется ввиду фолдинг поста
                 $folding = Handlers::getInstance()->getPostsProcessorByPostType($foldingSubType)->getFolding();
             }
         }
     }
     if ($folding && !$ident) {
         //У нас есть фолдинг, но нет идентификатора сущности - определим её из контекста
         $ident = $FCW->getFoldedEntityEnsureType($folding->getFoldingType())->getIdent();
     }
     if (!$dir && !$name && $ident && $folding) {
         /*
          * Не передано название картинки, но передан идентификатор сущности - показываем cover.
          * TODO - подумать, возможно имеет смысл сделать возможность показывать любую картинку в заданном размере.
          */
         return $folding->getCover($ident, $params->str('dim'));
     }
     /*
      * Берём путь "как есть", если: 
      * 1. Передан специальный параметр asis
      * 2. Передана dir, и она начинается с '/'
      * 3. Не передана dir, но при этом name начинается с '/'
      * 4. dir или name указывают на адрес в интернете
      */
     $asis = $params->bool('asis') || starts_with($dir, DIR_SEPARATOR) || !$dir && starts_with($name, DIR_SEPARATOR) || PsUrl::isHttp($dir) || PsUrl::isHttp($name);
     if ($asis) {
         if (!$dir) {
             return $name;
         }
         if (starts_with($name, DIR_SEPARATOR)) {
             return cut_string_end($dir, DIR_SEPARATOR) . $name;
         }
         return ($name ? ensure_ends_with($dir, DIR_SEPARATOR) : $dir) . $name;
     }
     /** @var DirManager */
     $DM = null;
     /*
      * Теперь определим DirManager. Мы его можем взять:
      */
     if ($folding) {
         //1. Из ресурсов фолдинга
         $DM = $folding->getResourcesDm($ident, 'src');
     } else {
         //2. Обычный resources->images, если фолдинг не установлен
         $DM = DirManager::images();
     }
     /*
      * Определим список показываемых картинок по атрибуту $name. Пример тега:
      * {postimg type='tr' ident='matrix' name='mao.gif mu.png mu.png'}
      * Просто разделим значение атрибута $name по точкам и пробелам и склеим в названия картинок.
      */
     $NAMES = preg_split("/[. ]/", $name);
     $DI = $DM ? $DM->getDirItem($dir, $name) : DirItem::inst($dir, $name);
     if (count($NAMES) % 2 != 0 || $DI->isImg()) {
         //Указано что-то непонятное - не чётное кол-во составных элементов
         return $DI;
     }
     $IMAGES = array();
     for ($i = 0; $i < count($NAMES); $i += 2) {
         $imgName = $NAMES[$i] . '.' . $NAMES[$i + 1];
         $IMAGES[] = $DM ? $DM->getDirItem($dir, $imgName) : DirItem::inst($dir, $imgName);
     }
     return $IMAGES;
 }
Ejemplo n.º 9
0
 protected function do_modifier($tagName, $panelName)
 {
     $smartyPrefix = cut_string_end($tagName, self::MODIFIER_SUFFIX);
     echo Handlers::getInstance()->getFoldingBySmartyPrefix($smartyPrefix)->includePanel($panelName);
 }
Ejemplo n.º 10
0
function unique_from_path($dirs1, $dirs2 = null, $dirs3 = null, $dirs4 = null)
{
    return str_replace(DIR_SEPARATOR, '-', cut_string_start(cut_string_end(next_level_dir(func_get_args()), DIR_SEPARATOR), DIR_SEPARATOR));
}
Ejemplo n.º 11
0
 /**
  * Основной метод, возвращающий содержимое списка.
  * Пользователь получит все сущности из списка, к которым у него есть доступ.
  * 
  * @param string $list - название списка
  * @return array идентификаторы из списка
  */
 private function getListContent($list)
 {
     if (!array_key_exists($list, $this->LINES)) {
         //Инициализируем хранилища
         $this->LINES[$list] = array();
         //Загрузим строки
         $lines = $this->getListDi($list)->getTextFileAdapter()->getLines();
         foreach ($lines as $line) {
             $marked = ends_with($line, '+');
             $line = $marked ? cut_string_end($line, '+') : $line;
             if ($this->hasAccess($line) && $this->isIncludeToList($line, $list)) {
                 $this->LINES[$list][$line] = $marked;
             }
         }
     }
     return $this->LINES[$list];
 }
Ejemplo n.º 12
0
 /**
  * Метод возвращает содержимое php файла, удаляя открывающий и закрывающий php теги
  */
 public function getFileContentsNoTags()
 {
     return trim(cut_string_end(cut_string_start($this->getDi()->getFileContents(), '<?php'), '?>'));
 }