Example #1
0
function smarty_function_ctrl_button($params, Smarty_Internal_Template &$template)
{
    $adapter = ArrayAdapter::inst($params);
    $data = array();
    if ($adapter->has('states')) {
        $type = 'states';
        $data['states'] = explode(' ', $adapter->str('states'));
    } else {
        $data['hoverable'] = $adapter->bool('hoverable');
        $data['gray'] = $adapter->bool('gray');
        $data['popup'] = $adapter->bool('popup');
        $data['blank'] = $adapter->bool('blank');
        $data['title'] = $adapter->str('title');
        $data['href'] = $adapter->str('href');
        $data['action'] = $adapter->str('action');
        $data['class'] = $adapter->str('class');
        $data['name'] = $adapter->str(array('name', 'img', 'action'));
        $type = $adapter->str('type');
        $type = $type ? $type : 'button';
    }
    /* @var $buttonTpl Smarty_Internal_Template */
    $buttonTpl = $template->smarty->createTemplate("discussion/controls/{$type}.tpl");
    $buttonTpl->assign($data);
    $buttonTpl->display();
}
Example #2
0
function smarty_function_linkup_js($params, Smarty_Internal_Template &$smarty)
{
    $params = ArrayAdapter::inst($params);
    $dir = $params->str('dir');
    $name = $params->str('name');
    $di = DirManager::resources('scripts')->getDirItem($dir, $name, 'js');
    echo $di->isFile() ? PsHtml::linkJs($di) : '';
}
Example #3
0
function smarty_function_progress($params, Smarty_Internal_Template &$smarty)
{
    $PA = ArrayAdapter::inst($params);
    $params['total'] = $PA->int('total');
    $params['current'] = $PA->int('current');
    $params['title'] = $PA->has('title') ? $PA->str('title') : 'Прогресс';
    PSSmarty::template('common/progress.tpl', $params)->display();
}
function smarty_function_versein($params, Smarty_Internal_Template &$template)
{
    $params = ArrayAdapter::inst($params);
    $poetIdent = $params->str('poet');
    $verseIdent = $params->str('verse');
    $verse = PoetsManager::inst()->getVerse($poetIdent, $verseIdent);
    echo $verse->getContent();
}
Example #5
0
function smarty_function_video($params, Smarty_Internal_Template &$smarty)
{
    $params = ArrayAdapter::inst($params);
    MmediaManager::getInstance()->insertVideo($params->str('dir'), $params->str('name'));
    if (PostFetchingContext::getInstance()->isSetted()) {
        PostFetchingContext::getInstance()->setHasVideo();
    }
}
Example #6
0
function smarty_function_linkup_css($params, Smarty_Internal_Template &$smarty)
{
    $params = ArrayAdapter::inst($params);
    $dir = $params->str('dir');
    $name = $params->str('name');
    $media = $params->str('media');
    $di = DirManager::resources('css')->getDirItem($dir, $name, 'css');
    echo $di->isFile() ? PsHtml::linkCss($di, $media) : '';
}
Example #7
0
function smarty_function_versein($params, Smarty_Internal_Template &$template)
{
    $params = ArrayAdapter::inst($params);
    $poetIdent = $params->str('poet');
    $verseIdent = $params->str('verse');
    $verse = PoetsManager::inst()->getVerse($poetIdent, $verseIdent);
    echo $verse->getContent();
    FoldedContextWatcher::getInstance()->setDependsOnEntity($verse->getFoldedEntity());
}
Example #8
0
function smarty_block_verse($params, $content, Smarty_Internal_Template &$template)
{
    if (!$content) {
        return;
    }
    $params = ArrayAdapter::inst($params);
    $content = trim($content);
    $name = $params->str('name');
    $year = $params->str('year');
    $double = $params->bool('double');
    /*
     * Обработка содержимого
     */
    $verses = array();
    if ($double) {
        $versesTmp = array();
        $strings = explode("\n", $content);
        $verse = '';
        $break = 0;
        foreach ($strings as $str) {
            $str = trim($str);
            if (!$str) {
                if ($verse) {
                    $verse .= "\n";
                    ++$break;
                }
            } else {
                if ($break > 1) {
                    $versesTmp[] = $verse;
                    $verse = $str;
                } else {
                    $verse .= "\n{$str}";
                }
                $break = 0;
            }
        }
        if ($verse) {
            $versesTmp[] = $verse;
        }
        $double = count($versesTmp) > 1;
        if ($double) {
            for ($index = 0; $index < count($versesTmp); $index = $index + 2) {
                $v1 = nl2br(trim($versesTmp[$index]));
                $v2 = array_key_exists($index + 1, $versesTmp) ? nl2br(trim($versesTmp[$index + 1])) : '';
                $verses[] = array($v1, $v2);
            }
        }
    }
    /* @var $verseTpl Smarty_Internal_Template */
    $verseTpl = $template->smarty->createTemplate('common/verse.tpl');
    $verseTpl->assign('b_double', $double);
    $verseTpl->assign('c_name', $name);
    $verseTpl->assign('c_body', nl2br($content));
    $verseTpl->assign('verses', $verses);
    $verseTpl->assign('c_year', $year);
    $verseTpl->display();
}
Example #9
0
function smarty_block_hidden($params, $content, Smarty_Internal_Template &$template)
{
    if (!$content) {
        return;
    }
    $params = ArrayAdapter::inst($params);
    $name = $params->str(array('name', 'text'));
    $toggle = $params->bool('toggle');
    $content = trim($content);
    $tpl = $template->smarty->createTemplate('common/hidden_text.tpl');
    $tpl->assign('name', $name ? $name : 'показать');
    $tpl->assign('toggle', $toggle);
    $tpl->assign('body', $content);
    $tpl->display();
}
Example #10
0
 private function __construct($id)
 {
     $this->id = 1 * $id;
     $this->BEAN = MosaicImgBean::inst();
     $params = ArrayAdapter::inst($this->BEAN->getImgInfo($this->id));
     $this->width = $params->int('w');
     $this->height = $params->int('h');
     $this->cellsXcnt = $params->int('cx');
     $this->cellsYcnt = $params->int('cy');
     $this->cellWidth = $params->int('cw');
     $this->cellHeight = $params->int('ch');
     $this->cellsTotal = $this->cellsXcnt * $this->cellsYcnt;
     $this->LOGGER = PsLogger::inst(__CLASS__);
     $this->PROFILER = PsProfiler::inst(__CLASS__);
     $this->tryResyncImg();
 }
Example #11
0
 public final function init(ArrayAdapter $params)
 {
     //Стандартные параметры
     $this->name = $params->str('name', 'Акция');
     $this->isActive = $params->bool('active', true);
     $this->isByDate = $params->hasNoEmpty('to');
     if ($this->isByDate) {
         $this->secondsLeft = strtotime($params->str('to')) - time();
         $this->isActive = $this->isActive && $this->secondsLeft > 0;
     }
     //Параметры акции (только те, что начинаются с data_)
     $this->params = ArrayAdapter::inst($params->getByKeyPrefix('data_', true));
     //Полный идентификатор акции
     $this->stockIdent = $this->sign($this->params->getData());
     //Вызовем инициализацию класса-наследника
     $this->onInit($this->params);
 }
Example #12
0
function smarty_block_sortable($params, $content, Smarty_Internal_Template &$smarty)
{
    if (!$content) {
        return;
        //---
    }
    $params = ArrayAdapter::inst($params);
    $sep = $params->str('sep');
    $strings = explode("\n", trim($content));
    $res = array();
    foreach ($strings as $str) {
        if (isEmpty($str)) {
            continue;
        }
        $items = explode('||', $str);
        $res[] = array('l' => trim($items[0]), 'r' => trim($items[1]), 's' => $sep);
    }
    PSSmarty::template('common/sortable.tpl', array('strings' => $res))->display();
}
Example #13
0
 public function __construct($mandatory = true, $fileFormParam = FORM_PARAM_FILE)
 {
     if (!array_key_exists($fileFormParam, $_FILES)) {
         check_condition(!$mandatory, "Ключ [{$fileFormParam}] не найден в массиве файлов");
         return;
         //---
     }
     $this->params = ArrayAdapter::inst($_FILES[$fileFormParam]);
     $code = $this->params->int('error');
     if (!$mandatory && $code == UPLOAD_ERR_NO_FILE) {
         return;
         //---
     }
     check_condition($code == UPLOAD_ERR_OK, $this->getErrorDescription($code));
     $tmpName = $this->params->str('tmp_name');
     check_condition(is_uploaded_file($tmpName), 'Файл не является загруженным');
     $size = $this->params->int('size');
     check_condition($size > 0 && $size <= UPLOAD_MAX_FILE_SIZE, "Недопустимый размер загружаемого файла: {$size} байт.");
     $this->valid = true;
 }
Example #14
0
function smarty_block_partition($params, $content, Smarty_Internal_Template &$smarty)
{
    if (!$content) {
        return;
    }
    $type = PostFetchingContext::getInstance()->getFoldedEntity()->getFolding()->getFoldingSubType();
    $aa = ArrayAdapter::inst(explode(':', $content));
    $MAKROS = $aa->str(0);
    $VALUE = $aa->str(1);
    switch ($type) {
        case POST_TYPE_TRAINING:
            //УПРАЖНЕНИЯ
            switch ($MAKROS) {
                case 'PLAN':
                    echo '<h3>План урока:</h3>';
                    break;
                case 'VIDEO':
                    echo '<h3>Видео урок:</h3>';
                    break;
                case 'CONSPECT':
                    echo '<h3>Конспект занятия:</h3>';
                    break;
                case 'TASKS':
                    if (!$VALUE) {
                        echo '<h3>Контрольные вопросы и задачи:</h3>';
                    } else {
                        echo "<h3 class=\"section\">{$VALUE}</h4>";
                    }
                    break;
                case 'FINAL':
                    echo '<h3>Заключение:</h3>';
                    break;
                default:
                    echo "<h3>{$content}</h3>";
                    break;
            }
            break;
        default:
            check_condition(false, __FUNCTION__ . ' function cannot be used with post type ' . $type);
    }
}
Example #15
0
function smarty_block_table($params, $content, Smarty_Internal_Template &$smarty)
{
    if (!$content) {
        return;
        //---
    }
    $params = ArrayAdapter::inst($params);
    $strings = explode("\n", trim($content));
    $res = array();
    foreach ($strings as $str) {
        $items = explode('||', $str);
        if (isEmpty($items)) {
            continue;
        }
        $processed = array();
        foreach ($items as $item) {
            $processed[] = explode('::', trim($item));
        }
        $res[] = $processed;
    }
    PSSmarty::template('common/table.tpl', array('items' => $res, 'class' => $params->str('class')))->display();
}
Example #16
0
function smarty_function_chis_rebus($params, Smarty_Internal_Template &$smarty)
{
    $params = ArrayAdapter::inst($params);
    /*
     * Текст ребуса
     */
    $rebus = $params->str('text');
    if ($rebus) {
        return "<div class=\"ps-math-rebus-holder\">{$rebus}</div>";
    }
    $rebus = $params->str('ans');
    if ($rebus) {
        $answers = PsMathRebus::inst()->rebusAnswers($rebus);
        if (is_array($answers)) {
            foreach ($answers as $ans) {
                echo "<div class=\"ps-math-rebus-holder\">{$ans}</div> ";
            }
        } else {
            return PsHtml::spanErr($answers);
        }
    }
}
Example #17
0
function smarty_function_html_input($params, Smarty_Internal_Template &$smarty)
{
    $adapter = ArrayAdapter::inst($params);
    $fieldId = $adapter->get('id');
    $label = $adapter->get('label');
    $value = $adapter->get('val');
    $inputType = $adapter->str('type');
    $help = $adapter->str('help');
    $RQ = PostArrayAdapter::inst();
    $attrs = array();
    switch ($inputType) {
        case 'hidden':
            echo PsHtml::hidden($fieldId, $value);
            break;
        case 'text':
            echo PsHtmlForm::text($label, $fieldId, $RQ->str($fieldId, $value), $attrs, $help);
            break;
        case 'datetime':
            $attrs['class'][] = 'ps-datetime-picker';
            echo PsHtmlForm::text($label, $fieldId, $RQ->str($fieldId, $value), $attrs, $help);
            break;
        case 'pass':
            echo PsHtmlForm::password($label, $fieldId, $RQ->str($fieldId));
            break;
        case 'file':
            $label = $adapter->get('label', 'Файл');
            $fieldId = $fieldId ? $fieldId : FORM_PARAM_FILE;
            echo PsHtmlForm::file($label, $fieldId, $help);
            break;
        case 'user':
            $label = $adapter->get('label', 'Ваше имя');
            if (AuthManager::isAuthorized()) {
                echo PsHtmlForm::textInfo($label, PsUser::inst()->getName());
            } else {
                $fieldId = $fieldId ? $fieldId : FORM_PARAM_NAME;
                echo PsHtmlForm::text($label, $fieldId, $RQ->str($fieldId), $attrs, $help);
            }
            break;
        case 'textarea':
            $label = $adapter->get('label', 'Текст сообщения');
            $fieldId = $fieldId ? $fieldId : FORM_PARAM_COMMENT;
            $value = $value ? $value : $RQ->str($fieldId, $value);
            $maxlen = $adapter->str(array('maxlen', 'maxlength'));
            $manual = $adapter->bool('manual');
            $codemirror = $adapter->str('codemirror');
            echo PsHtmlForm::textarea($label, $fieldId, $value, $maxlen, $manual, $codemirror, $attrs, $help);
            break;
        case 'submit':
            $buttons[] = $label ? $label : 'Отправить';
            for ($idx = 0; $idx <= 10; $idx++) {
                $button = $adapter->get("label{$idx}");
                if ($button) {
                    $buttons[] = $button;
                }
            }
            $canReset = $adapter->bool('reset');
            echo PsHtmlForm::submit($buttons, $canReset);
            break;
        case 'yesno':
            $fieldId = $fieldId ? $fieldId : 'yesno';
            $options[] = PsHtml::comboOption(0, 'Нет');
            $options[] = PsHtml::comboOption(1, 'Да');
            echo PsHtmlForm::select($label, $fieldId, $attrs, $options, 0);
            break;
        case 'sex':
            $value = $value ? $value : $RQ->int($fieldId);
            $options[] = PsHtml::comboOption(SEX_GIRL, 'Женский');
            $options[] = PsHtml::comboOption(SEX_BOY, 'Мужской');
            echo PsHtmlForm::select($label, $fieldId, $attrs, $options, $value);
            break;
        case 'posttype':
            $label = $label ? $label : 'Тип поста';
            $fieldId = $fieldId ? $fieldId : FORM_PARAM_POST_TYPE;
            $options = array();
            /* @var $pr PostsProcessor */
            foreach (Handlers::getInstance()->getPostsProcessors() as $type => $pr) {
                $title = $pr->postTitle();
                $options[] = PsHtml::comboOption($type, "{$title} ({$type})");
            }
            echo PsHtmlForm::select($label, $fieldId, $attrs, $options);
            break;
        case 'select':
            echo PsHtmlForm::select($label, $fieldId, $attrs, $adapter->arr('options'), $adapter->str('curVal'), $adapter->bool('hasEmpty'), $help);
            break;
        case 'timezone':
            $label = $label ? $label : 'Выберите временную зону';
            $tzSelect = PsTimeZone::inst()->zonesSelectHtml();
            echo PsHtmlForm::field($label, $tzSelect, $help);
            break;
        default:
            raise_error("Unsupported html input type: [{$inputType}]");
    }
}
 /**
  * Основной метод
  */
 protected function do_block($tagName, $params, $content, Smarty_Internal_Template $smarty)
 {
     if ($content) {
         return $this->insert($tagName, ArrayAdapter::inst($params), trim($content));
     }
 }
 protected function do_function($tagName, $params, Smarty_Internal_Template $smarty)
 {
     $this->insert($tagName, ArrayAdapter::inst($params), null);
 }
Example #20
0
function smarty_function_gallery($params, Smarty_Internal_Template &$smarty)
{
    $params = ArrayAdapter::inst($params);
    $gallery = $params->str(array('dir', 'name'));
    echo PsGallery::inst($gallery)->getGalleryBox($params->bool('lazy'));
}
Example #21
0
 public function getFoldedEntityPreview($ident)
 {
     return array('info' => '', 'content' => $this->getPageContent($ident, ArrayAdapter::inst())->getContent());
 }
Example #22
0
function smarty_function_stock($params, Smarty_Internal_Template &$template)
{
    echo StockManager::inst()->registerStock(ArrayAdapter::inst($params));
}
Example #23
0
 /**
  * 
  * @return ArrayAdapter
  */
 public function copy()
 {
     return ArrayAdapter::inst($this, false);
 }
Example #24
0
 /**
  * Предварительная обработка страницы - самое время выполнить сабмит формы, редирект и остальные подобные вещи
  */
 private final function preProcess(array $buildParams = array())
 {
     ExceptionHandler::registerPretty();
     //Проверим и сменим состояние
     $this->changeState(self::STATE_NOT_INITED, self::STATE_STARTED);
     $BUILDER_CTXT = PageBuilderContext::getInstance();
     //Стартуем контекст
     $BUILDER_CTXT->setContext(__CLASS__);
     $this->PROFILER->start(__FUNCTION__);
     try {
         //Вызываем предварительную обработку страницы
         return $this->preProcessImpl($BUILDER_CTXT, RequestArrayAdapter::inst(), ArrayAdapter::inst($buildParams));
     } catch (Exception $ex) {
         $this->PROFILER->stop(false);
         throw $ex;
     }
 }
Example #25
0
function smarty_block_psplugin($params, $content, Smarty_Internal_Template &$smarty)
{
    $params = ArrayAdapter::inst($params);
    $ident = $params->str(GET_PARAM_PLUGIN_IDENT);
    echo PluginsManager::inst()->buildFromTag($ident, $content, $params);
}
Example #26
0
 /**
  * Предпросмотр страницы при редактировании
  */
 public function getFoldedEntityPreview($ident)
 {
     $page = $this->getPage($ident);
     $page->doProcess(ArrayAdapter::inst());
     return array('info' => $page->getTitle(), 'content' => $this->getPopupPageContent($page));
 }
Example #27
0
 public function getFoldedEntityPreview($ident)
 {
     $plugin = $this->getPlugin($ident);
     PluginFetchingContext::getInstance()->setContext($plugin->getIdent());
     $return = $this->buildImpl($plugin, 'token1 token2 token3', ArrayAdapter::inst());
     PluginFetchingContext::getInstance()->dropContext();
     return array('info' => $plugin->getName(), 'content' => $return);
 }
Example #28
0
 /** @return GetArrayAdapter */
 public static function inst()
 {
     return parent::inst($_GET, true);
 }
Example #29
0
 private function uploadFileImpl(DirItem $source, FILEAdapter $file = null, $userId = null, array $params = array())
 {
     $userId = $this->checkUserId($userId);
     $this->LOGGER->info("Processing file upload for user [{$userId}], source {$source}.");
     $aa = ArrayAdapter::inst($params);
     $uploaded = $file ? $source : null;
     $originalName = $file ? $file->getOriginalName() : $source->getName();
     $dbMsg = null;
     try {
         $this->LOGGER->info('Calling onBeforeSave...');
         $dbMsg = $this->onBeforeSave($source, $userId, $aa);
         $this->LOGGER->info("\tDone!");
     } catch (Exception $ex) {
         $this->LOGGER->info('Error occurred in onBeforeSave method: ' . $ex->getMessage());
         $this->LOGGER->info('Source file will be deleted ? {}.', var_export(!!$uploaded, true));
         if ($uploaded) {
             $uploaded->remove();
         }
         throw $ex;
     }
     if ($uploaded) {
         //Это уже и так загруженный файл
         $this->LOGGER->info('Source file is uploaded file');
     } else {
         $this->LOGGER->info('Move source file to uploads dir');
         $uploaded = $this->makeTmpDirItem();
         $source->copyTo($uploaded);
     }
     if ($this->LOGGER->isEnabled()) {
         $this->LOGGER->info("\tUploaded file: {$uploaded}");
         $this->LOGGER->info("\tOriginal name: [{$originalName}]");
         $this->LOGGER->info("\tMime: [{$uploaded->getMime()}]");
         $this->LOGGER->info("\tParams: " . array_to_string($params, false));
     }
     $uploadId = null;
     if ($this->isStoreToDb()) {
         $this->LOGGER->info("Saving upload file into database. DbMsg: '{$dbMsg}'.");
         try {
             $uploadId = UploadsBean::inst()->saveFileUpload($this->DBTYPE, $uploaded->getAbsPath(), $originalName, $uploaded->getMime(), $userId, $dbMsg);
             //Почистим кеш, вдруг мы запрашивали информацию по данному файлу
             $this->CACHE->remove($uploadId);
             $this->LOGGER->info("\tFile successfully saved, uploadId = {$uploadId}.");
         } catch (Exception $ex) {
             $this->LOGGER->info('Error occured while saving file to DB: ' . $ex->getMessage());
             $this->LOGGER->info('Deleting upload file...');
             $uploaded->remove();
             $uploaded = null;
             throw $ex;
         }
         $uploaded->setData('id', $uploadId);
     }
     try {
         $this->LOGGER->info('Calling onAfterSave...');
         $this->onAfterSave($uploaded, $userId, $aa);
         $this->LOGGER->info("\tDone!");
     } catch (Exception $ex) {
         $this->LOGGER->info('Error occured in onAfterSave method: ' . $ex->getMessage());
         if (is_inumeric($uploadId)) {
             $this->LOGGER->info('Deleting db record...');
             UploadsBean::inst()->clearFileUpload($uploadId);
             $uploadId = null;
         }
         $this->LOGGER->info('Deleting upload file...');
         $uploaded->remove();
         $uploaded = null;
         throw $ex;
     }
     /*
      * Если класс работает автономно и не работает с базой, то файл нужно удалить.
      */
     if ($this->isAutonomous() && !$this->isStoreToDb()) {
         $this->LOGGER->info('Class is auto clean, deleting uploaded file...');
         $uploaded->remove();
         $uploaded = null;
     }
     $this->LOGGER->info('');
     return $uploaded;
 }
Example #30
0
 /**
  * Возвращает представление для bubble
  */
 public function getBubble($ident)
 {
     $libItem = $this->getLibItemDb($ident, false);
     if (!$libItem) {
         return null;
     }
     $tlItem = $this->convertLibItemDb2TimeLineItem($libItem, ArrayAdapter::inst());
     $PARAMS['i'] = new LibBubbleItem($libItem, $tlItem);
     return PSSmarty::template('lib/bubble.tpl', $PARAMS)->fetch();
 }