Beispiel #1
0
function smarty_block_tool($params, $content, Smarty_Internal_Template &$template)
{
    $ctxtParams = SmartyBlockContext::getInstance()->registerBlock($content, __FUNCTION__);
    if (!$content) {
        return;
    }
    $hasToolBody = !isEmptyInArray(SmartyBlockContext::HAS_TOOL_BODY, $ctxtParams);
    $id = value_Array('id', $params);
    $name = value_Array('name', $params);
    $img = value_Array('img', $params);
    $ident = value_Array('ident', $params);
    /*
     * Вычислим - показывать утилиту как ссылку или нет.
     * Такое возможно в двух случаях: у утилиты есть контент или мы насильно её делаем
     * ссылкой, чтобы "рулить" руками.
     */
    $asHref = $hasToolBody;
    $toolTpl = $template->smarty->createTemplate('common/tool.tpl');
    $toolTpl->assign('id', $id ? 'tool_' . $id : '');
    $toolTpl->assign('name', $name);
    $toolTpl->assign('img', $img);
    $toolTpl->assign('ident', $ident);
    $toolTpl->assign('as_href', $asHref);
    $toolTpl->assign('c_body', $content);
    $toolTpl->display();
}
Beispiel #2
0
    private function saveImg($gallery, array $img, $order)
    {
        check_condition($gallery, 'Не задано название галереи');
        $file = check_condition(array_get_value('file', $img), 'Не задан путь к картинке');
        $this->update('
INSERT INTO ps_gallery_images 
(v_dir, v_file, b_show, b_web, v_name, v_descr, n_order) 
VALUES 
(?, ?, ?, ?, ?, ?, ?)', array($gallery, $file, !isEmptyInArray('show', $img), !isEmptyInArray('web', $img), $img['name'], $img['descr'], $order));
    }
Beispiel #3
0
function smarty_block_feed($params, $content, Smarty_Internal_Template &$smarty)
{
    if (!$content) {
        return;
    }
    $text = trim($content);
    $text = $text == '.' ? null : $text;
    $blank = !isEmptyInArray('blank', $params);
    $http = !isEmptyInArray('http', $params);
    return '<b>Напишите мне</b>';
}
Beispiel #4
0
function smarty_block_feed($params, $content, Smarty_Internal_Template &$smarty)
{
    if (!$content) {
        return;
    }
    $text = trim($content);
    $text = $text == '.' ? null : $text;
    $blank = !isEmptyInArray('blank', $params);
    $http = !isEmptyInArray('http', $params);
    return FeedbackManager::inst()->writeToUsHref($text, $blank, $http);
}
function smarty_function_showcases_list($params, Smarty_Internal_Template &$template)
{
    $type = value_Array('type', $params);
    $postsProcessor = Handlers::getInstance()->getPostsProcessorByPostType($type);
    $posts_ids = array_key_exists('posts_ids', $params) ? $params['posts_ids'] : $postsProcessor->getPagePostsIds();
    /* @var $showcasesTpl Smarty_Internal_Template */
    $showcasesTpl = $template->smarty->createTemplate('common/showcases_list.tpl');
    $showcasesTpl->assign('posts_ids', is_array($posts_ids) ? $posts_ids : array());
    $showcasesTpl->assign('full_view', !isEmptyInArray('full_view', $params));
    $showcasesTpl->assign('type', $type);
    $showcasesTpl->display();
}
Beispiel #6
0
function smarty_block_ans($params, $content, Smarty_Internal_Template &$smarty)
{
    if ($content === null) {
        return;
    }
    $parent = SmartyBlockContext::getInstance()->getParentBlockSetVirtualCtxt(array('answers', 'ex', 'task', 'question'), __FUNCTION__, true);
    if ($parent == 'answers') {
        $correct = !isEmptyInArray('correct', $params);
        SmartyBlockContext::getInstance()->addParam(SmartyBlockContext::MULTIPLE_ANSWERS, array($content, $correct));
    } else {
        SmartyBlockContext::getInstance()->setParam('c_ans', $content);
    }
    SmartyBlockContext::getInstance()->dropVirtualContext();
}
Beispiel #7
0
function smarty_block_post_href($params, $content, Smarty_Internal_Template &$smarty)
{
    if (isEmpty($content)) {
        return;
    }
    /*
     * text - текст ссылки
     * Также может быть вставлен произвольный текст
     */
    $text = trim($content);
    $text = $text == '.' ? null : $text;
    /* @var $post Post */
    $post = value_Array('post', $params);
    $post = $post instanceof PostContentProvider ? $post->getPost() : $post;
    $sub = value_Array('sub', $params);
    $blank = !isEmptyInArray('blank', $params);
    $handler = null;
    if ($post) {
        $handler = Handlers::getInstance()->getPostsProcessorByPostType($post->getPostType());
    } else {
        $id = value_Array(array('id', 'post_id'), $params);
        $ident = value_Array(array('ident', 'post_ident'), $params);
        check_condition($id || $ident, 'Не переданы уникальный код или идентификатор поста.');
        $handler = Handlers::getInstance()->getPostsProcessorByPostType($params['type']);
        $post = $id ? $handler->getPost($id, true) : $handler->getPostByIdent($ident, true);
    }
    /*
     * Выкидываем служебные ключи, а остальное - возвращаем
     */
    unset($params['sub']);
    unset($params['blank']);
    unset($params['post']);
    unset($params['type']);
    unset($params['id']);
    unset($params['post_id']);
    unset($params['ident']);
    unset($params['post_ident']);
    echo $handler->postHref($post, $text, $sub, $params, $blank);
}
Beispiel #8
0
function smarty_block_page_href($params, $content, Smarty_Internal_Template &$smarty)
{
    if (isEmpty($content)) {
        return;
    }
    $code = value_Array('code', $params);
    $code = $code ? $code : BASE_PAGE_INDEX;
    $sub = value_Array('sub', $params);
    $title = value_Array('title', $params);
    $classes = value_Array('class', $params);
    $blank = !isEmptyInArray('blank', $params);
    $http = !isEmptyInArray('http', $params);
    $urlParams = array();
    foreach ($params as $key => $val) {
        if (starts_with($key, 'p_')) {
            $urlParams[substr($key, 2)] = $val;
        }
    }
    $content = trim($content);
    $content = $content == '.' ? null : $content;
    return WebPage::inst($code)->getHref($content, $blank, $classes, $http, $urlParams, $sub, $title);
}
Beispiel #9
0
function smarty_function_showcase($params, Smarty_Internal_Template &$template)
{
    /*
     * type - тип поста
     */
    $type = Handlers::getInstance()->extractPostType($params['type']);
    /*
     * full_view - полный или "обрезанный вид"
     */
    $full_view = !isEmptyInArray('full_view', $params);
    /*
     * mag_mode - режим вставки в журнал
     */
    $mag_mode = !isEmptyInArray('mag_mode', $params);
    /*
     * post_id - уникальный код поста в базе
     * post_ident - идентификатор поста, чаще всего - название шаблона
     *
     * Один из параметров обязательно должен присутствовать.
     */
    $post_id = value_Array('post_id', $params);
    $post_ident = value_Array('post_ident', $params);
    check_condition($post_id || $post_ident, 'Не переданы уникальный код или идентификатор поста.');
    $handler = Handlers::getInstance()->getPostsProcessorByPostType($type);
    /* @var $postCP PostContentProvider */
    $postCP = $post_id ? $handler->getPostContentProvider($post_id) : $handler->getPostContentProviderByIdent($post_ident);
    if (!$postCP) {
        return PsHtml::spanErr($post_id ? 'Не найден ' . $handler->postTitle() . ' с кодом \'' . $post_id . '\'' : 'Не найден ' . $handler->postTitle() . ' с идентификатором \'' . $post_ident . '\'');
    }
    /* @var $postShowcaseTpls Smarty_Internal_Template */
    $postShowcaseTpls = $template->smarty->createTemplate("{$type}/post_showcase.tpl");
    $postShowcaseTpls->assign('cp', $postCP);
    $postShowcaseTpls->assign('full_view', $full_view);
    $postShowcaseTpls->assign('mag_mode', $mag_mode);
    $postShowcaseTpls->display();
}
Beispiel #10
0
function smarty_block_p($params, $content, Smarty_Internal_Template &$smarty)
{
    if (isEmpty($content)) {
        return;
    }
    $styles = array();
    $align = value_Array('al', $params);
    switch ($align) {
        case 'l':
            $styles['text-align'] = 'left';
            break;
        case 'c':
            $styles['text-align'] = 'center';
            break;
        case 'r':
            $styles['text-align'] = 'right';
            break;
    }
    $bold = !isEmptyInArray('bold', $params);
    if ($bold) {
        $styles['font-weight'] = 'bold';
    }
    return PsHtml::p(array('style' => $styles), $content);
}
Beispiel #11
0
 public function getComment()
 {
     return isEmptyInArray('comment', $this->data) ? null : $this->data['comment'];
 }
Beispiel #12
0
    public function getProgramms()
    {
        //todo извлекать одним запросом.
        $programms = $this->getArray('
SELECT g.id_gym_programm AS id_prog,
       g.name AS prog_name,
       g.description AS prog_descr,
       e.id_gym_programm_exercise AS id_prog_ex,
       e.id_gym_ex,
       if(e.name is null, ex.name, e.name) AS ex_name,
       e.description AS ex_descr,
       s.value as set_val
  FROM gym_programm g,
             gym_programm_exercises e
          LEFT JOIN
             gym_exercises ex
          ON ex.id_gym_ex = e.id_gym_ex
       LEFT JOIN
          gym_sets s
       ON s.id_gym_programm_exercise = e.id_gym_programm_exercise
 WHERE g.id_gym_programm = e.id_gym_programm
ORDER BY g.id_gym_programm ASC, e.n_order ASC, s.n_order ASC');
        $progData = array();
        $curProg = null;
        foreach ($programms as $prog) {
            $progId = (int) $prog['id_prog'];
            if (!$curProg || $curProg->getId() != $progId) {
                $curProg = new GymProgramm(array_sift_out($prog, array('id_prog' => 'id', 'prog_name' => 'name', 'prog_descr' => 'comment')));
                $progData[] = $curProg;
            }
            $progExId = (int) $prog['id_prog_ex'];
            $ex = $curProg->getExercise($progExId);
            if (!$ex) {
                $ex = new GymProgrammEx(array_sift_out($prog, array('id_gym_ex' => 'id', 'ex_name' => 'name', 'ex_descr' => 'comment')));
                $curProg->addExercise($progExId, $ex);
            }
            if (!isEmptyInArray('set_val', $prog)) {
                $ex->addSet($prog['set_val']);
            }
        }
        return $progData;
    }