function smarty_block_task($params, $content, Smarty_Internal_Template &$template) { $ctxtParams = SmartyBlockContext::getInstance()->registerBlock($content, __FUNCTION__); if (!$content) { return; //--- } /* @var $taskTpl Smarty_Internal_Template */ $taskTpl = PSSmarty::template('common/task.tpl', $ctxtParams); $from = value_Array(array('from', 'c_from'), $params); $taskTpl->assign('from', $from); $taskTpl->assign('body', $content); $isSubTask = SmartyBlockContext::getInstance()->hasParentBlock('tasks'); $taskTpl->assign('sub_task', $isSubTask); $taskNum = null; if (!$isSubTask) { $taskNumber = null; //Допускается вывод задач не в контексте $ctxt = FoldedContextWatcher::getInstance()->getTasksNumeratorContext(false); if ($ctxt) { $taskNumber = $ctxt->getNextTaskNumber(); } $taskNum = $taskNumber ? "Задача № {$taskNumber}" : null; } $taskTpl->assign('task_num', $taskNum); $taskTpl->display(); }
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(); }
function smarty_function_doc_href($params, Smarty_Internal_Template &$smarty) { $doc = value_Array('doc', $params); $text = value_Array('text', $params); $title = value_Array('title', $params); echo "<a href=\"/resources/docs/{$doc}\" title=\"{$title}\" target=\"_blank\">{$text}</a>"; }
function smarty_function_binom($params, Smarty_Internal_Template &$smarty) { $n = value_Array('n', $params); $n = $n === null ? 'n' : $n; $m = value_Array('m', $params); $m = $m === null ? 'm' : $m; echo '<span class="binon_holder"> <table class="binom"><tbody><tr><td class="lbr" rowspan="2"></td><td>' . $n . '</td><td class="rbr" rowspan="2"></td></tr><tr><td>' . $m . '</td></tr></tbody></table></span>'; }
function smarty_function_insert_id($params, Smarty_Internal_Template &$smarty) { $item = value_Array('item', $params); if ($item) { $ident = IdHelper::ident($item); echo "id=\"{$ident}\""; } }
function smarty_function_chis_rebus_task($params, Smarty_Internal_Template &$template) { /* @var $crtTpl Smarty_Internal_Template */ $crtTpl = $template->smarty->createTemplate('common/chis_rebus_task.tpl'); $crtTpl->assign('rebus_txt', value_Array('text', $params)); $crtTpl->assign('reset', value_Array('reset', $params)); $crtTpl->display(); }
function smarty_block_joke($params, $content, Smarty_Internal_Template &$template) { if (!$content) { return; } /* @var $jokeTpl Smarty_Internal_Template */ $jokeTpl = $template->smarty->createTemplate('common/joke.tpl'); $jokeTpl->assign('text', trim($content)); $jokeTpl->assign('from', value_Array('from', $params)); $jokeTpl->display(); }
/** * Метод каждое сообщение из стека оборачивает в див с отступом, соответствующим номеру сообщения. * 0# C:\www\postupayu.ru\www\src\common\content\ContentHelper.php (39) * 1# C:\www\postupayu.ru\www\resources\folded\pagebuilders\basic\basic.php (53) * 2# C:\www\postupayu.ru\www\src\common\folded\pagebuilders\AbstractPageBuilder.php (55) */ private static function formatTraceMessagesFile(Exception $ex) { $stack = ''; foreach (self::extendTrace($ex) as $num => $stackItem) { $file = value_Array(array('file', 'class'), $stackItem); $line = value_Array('line', $stackItem); $stack .= pad_left('', $num * 2, ' ') . "{$num}# {$file} ({$line})"; $stack .= "\n"; } return $stack; }
function smarty_function_sprite($params, Smarty_Internal_Template &$smarty) { /* * Название картинки */ $name = value_Array('name', $params); $group = value_Array(array('gr', 'group'), $params); $group = $group ? $group : CssSpritesManager::DIR_ICO; $withGray = array_key_exists('nc', $params); echo CssSpritesManager::getDirSprite($group, $name, $withGray); }
function smarty_block_answers($params, $content, Smarty_Internal_Template &$smarty) { $ctxtParams = SmartyBlockContext::getInstance()->registerBlock($content, __FUNCTION__); if (!$content) { return; } $answers = value_Array(SmartyBlockContext::MULTIPLE_ANSWERS, $ctxtParams); if ($answers) { PSSmarty::template('common/answers.tpl', array('answers' => $answers))->display(); } }
function smarty_function_form($params, Smarty_Internal_Template &$smarty) { $formId = value_Array('form_id', $params); $hiddens = array(); foreach ($params as $key => $value) { if ($key == 'form_id') { continue; } $hiddens[$key] = $value; } PSForm::inst()->getForm($formId)->display($hiddens); }
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(); }
function smarty_block_al($params, $content, Smarty_Internal_Template &$smarty) { if (!$content) { return; } $id = value_Array('id', $params); $id = IdHelper::localId($id); $title = value_Array('title', $params); $class = value_Array('class', $params); $class = $class ? "class='{$class}'" : ''; $content = trim($content); echo "<a href='#{$id}' title='{$title}' {$class}>{$content}</a>"; }
function smarty_block_part($params, $content, Smarty_Internal_Template &$smarty) { if (!$content) { return; } $post = PostFetchingContext::getInstance()->getPost(); $postType = $post->getPostType(); $content = trim($content); $descr = value_Array(array('desc', 'descr'), $params); switch ($postType) { case POST_TYPE_ISSUE: //ЖУРНАЛ if ($content == 'EDITOR') { $postId = MagManager::ident2id($post->getIdent()); echo "<h4 class=\"ps-post-head section\"><span>Выпуск {$postId}.</span> Редакторская колонка</h4>"; } else { switch ($content) { case 'WHOIS': $content = 'Кто это?'; break; case 'TASKS': PostFetchingContext::getInstance()->resetTasksNumber(); $content = 'Задачки на подумать'; break; case 'TASKS_A': $content = 'Ответы на задачи предыдущего номера'; break; case 'CITATA': $content = 'Цитата номера'; break; case 'VERSE': $content = "Стихи, {$descr}"; break; case 'HUMOR': $content = 'Студенческий юмор'; break; } $curNum = PostFetchingContext::getInstance()->addAnons($content); echo "<h4 id=\"p{$curNum}\" class=\"section\"><span>Часть#{$curNum}.</span> {$content}</h4>"; } break; case POST_TYPE_TRAINING: //УПРАЖНЕНИЯ $curNum = PostFetchingContext::getInstance()->addAnons($content); echo "<h5 id=\"p{$curNum}\" class=\"paragraph\">{$curNum}. {$content}</h5>"; break; default: check_condition(false, __FUNCTION__ . ' function cannot be used with post type ' . $postType); } }
function smarty_block_toolbody($params, $content, Smarty_Internal_Template &$template) { if (!$content) { return; } SmartyBlockContext::getInstance()->getParentBlockSetVirtualCtxt('tool', __FUNCTION__, true); SmartyBlockContext::getInstance()->setParam(SmartyBlockContext::HAS_TOOL_BODY, true); SmartyBlockContext::getInstance()->dropVirtualContext(); $toolName = value_Array('name', $params); if ($toolName) { /* @var $toolBodyContentTpl Smarty_Internal_Template */ $toolBodyContentTpl = $template->smarty->createTemplate("tools/{$toolName}.tpl"); $content = $toolBodyContentTpl->fetch(); } echo "<div class=\"tool_body\">{$content}</div>"; }
function smarty_block_citata($params, $content, Smarty_Internal_Template &$template) { $ctxtParams = SmartyBlockContext::getInstance()->registerBlock($content, __FUNCTION__); if (!$content) { return; } $citatas = SmartyBlockContext::getInstance()->hasParentBlock('citatas'); $from = value_Array('c_from', $ctxtParams); $from = $from ? $from : value_Array('from', $params); /* @var $citataTpl Smarty_Internal_Template */ $citataTpl = $template->smarty->createTemplate('common/citata.tpl'); $citataTpl->assign('child', $citatas); $citataTpl->assign('body', trim($content)); $citataTpl->assign('from', $from); $citataTpl->display(); }
function smarty_block_th($params, $content, Smarty_Internal_Template &$smarty) { $ctxtParams = SmartyBlockContext::getInstance()->registerBlock($content, __FUNCTION__); if (!$content) { return; //--- } $thId = trim(value_Array(array('id', 'num'), $params)); $num = PostFetchingContext::getInstance()->getNextThNum($thId, true); $elId = $thId ? PostFetchingContext::getInstance()->getThElId($thId) : null; $tpl = PSSmarty::template('common/theorem.tpl'); $tpl->assign('id', $elId); $tpl->assign('num', $num); $tpl->assign('c_body', $content); $tpl->assign($ctxtParams); $tpl->display(); }
function smarty_block_exercise($params, $content, Smarty_Internal_Template &$template) { if (isEmpty($content)) { return; } $id = value_Array('id', $params); /* @var $ex GymEx */ $ex = GymManager::getInstance()->getExercise($id); $content = trim($content); $name = value_Array('name', $params); $name = $name ? $name : ($ex ? $ex->getName() : ''); $class = $ex ? GymManager::getInstance()->getClass($ex) : ''; $exTemplate = $template->smarty->createTemplate('gym/exercise.tpl'); $exTemplate->assign('c_id', IdHelper::gymExId($id)); $exTemplate->assign('c_name', $name); $exTemplate->assign('c_class', $class); $exTemplate->assign('c_body', $content); $exTemplate->display(); }
function smarty_block_hinfo($params, $content, Smarty_Internal_Template &$template) { if (!$content) { return; } $content = trim($content); $name = value_Array('name', $params); $start = value_Array('start', $params); $end = value_Array('end', $params); $id = value_Array('id', $params); $dates = DatesTools::inst()->toString(DatesTools::TS_MONTH_FULL, $start, $end); /* @var $hinfoTpl Smarty_Internal_Template */ $hinfoTpl = $template->smarty->createTemplate('common/human_info.tpl'); $hinfoTpl->assign('c_id', $id); $hinfoTpl->assign('c_name', $name); $hinfoTpl->assign('c_date', $dates); $hinfoTpl->assign('c_body', $content); $hinfoTpl->display(); }
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); }
function smarty_block_f($params, $content, Smarty_Internal_Template &$template) { if (isEmpty($content)) { return; //--- } /* * Если это не TeX формула \[\], то это текстовая формула и её надо обработать. */ if (!TexTools::isBlockFormula($content)) { $content = TextFormulesProcessor::processBlockFormula($content); } /* * Проверим, задан ли идентификатор для формулы. * Если задан - пронумеруем её, т.к. на неё будут ссылаться. */ $formulaId = trim(value_Array(array('id', 'num'), $params)); if (!$formulaId) { return $content; } return FoldedContextWatcher::getInstance()->getFormulaNumeratorContext()->wrapFormulaBox($formulaId, $content); }
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); }
function smarty_block_ex($params, $content, Smarty_Internal_Template &$template) { $ctxtParams = SmartyBlockContext::getInstance()->registerBlock($content, __FUNCTION__); if (!$content) { return; //--- } $ctxt = PostFetchingContext::getInstance(); if (array_key_exists('reset', $params)) { $ctxt->resetExamplesNum(); } $exId = trim(value_Array(array('id', 'num'), $params)); $num = $ctxt->getExampleNum($exId, true); $elId = $exId ? $ctxt->getExampleElId($exId) : null; /* @var $exampleTpl Smarty_Internal_Template */ $exampleTpl = PSSmarty::template('common/example.tpl'); $exampleTpl->assign('id', $elId); $exampleTpl->assign('num', $num); $exampleTpl->assign('c_body', $content); $exampleTpl->assign($ctxtParams); $exampleTpl->display(); }
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(); }
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); }
public function getMappedParam($key, $mapKey, $default = null) { return value_Array($mapKey, $this->getParam($key), $default); }
public function get($key, $default = null) { return value_Array($key, $this->data, $default); }
/** * Вернётся true, если хоть одно значение будет пустым */ function isEmptyInArray($keys, array $array) { return isEmpty(value_Array($keys, $array)); }
public function fullMonth($m) { return value_Array(3, $this->monthDecodes($m)); }
public function getExercise($exId) { $data = $this->getExercises(); return value_Array((int) $exId, $data); }