Exemplo n.º 1
0
function smarty_modifier_post_meta(PostContentProvider $postCP, $news = false)
{
    $post = $postCP->getPost();
    $postId = $post->getId();
    $type = $post->getPostType();
    $pp = Handlers::getInstance()->getPostsProcessorByPostType($type);
    $rp = Handlers::getInstance()->getRubricsProcessorByPostType($type, false);
    $trStateToggle = null;
    $rubHref = null;
    $commentsHref = null;
    $name = null;
    if ($news) {
        $name = $post->getName();
        $name = "<span class=\"name\">{$name}</span>";
    }
    if (!$news && $post->getPostType() == POST_TYPE_TRAINING && AuthManager::isAuthorized()) {
        $trStateToggle = '<a href="#' . $postId . '" title="Изменить состояние урока" class="toggle">Пройден</a>';
    }
    $rubHref = $rp ? $rp->rubricHref($post->getRubricId(), null, 'rubric') : null;
    //    if (!$news) {
    $commentsCnt = $post->getCommentsCount();
    $commentsHref = $pp->postHref($post, "Комментариев: {$commentsCnt}", 'comments', array('class' => 'commentcount'));
    //    }
    if ($name || $trStateToggle || $rubHref || $commentsHref) {
        echo '<div class="post_meta">';
        echo "{$name}&nbsp;{$trStateToggle} {$rubHref} {$commentsHref}";
        echo '</div>';
    }
}
 protected function registerPluginsImpl()
 {
     /* @var $manager FoldedResources */
     foreach (Handlers::getInstance()->getBubbles() as $manager) {
         $this->registerBlock($manager->getSmartyPrefix());
     }
 }
Exemplo n.º 3
0
 protected function processImpl(PostArrayAdapter $adapter, $button)
 {
     if (!$adapter->hasAllNoEmpty('folding', self::PARAM_NEW_FOLDING_IDENT)) {
         return 'Не переданы все необходимые параметры.';
     }
     $funique = $adapter->str('folding');
     $fident = check_condition($adapter->str(self::PARAM_NEW_FOLDING_IDENT), 'Пустой идентификатор фолдинга');
     $folding = Handlers::getInstance()->getFoldingByUnique($funique);
     $folding->assertNotExistsEntity($fident);
     switch ($button) {
         case self::BUTTON_SAVE_DB:
             $action = PS_ACTION_CREATE;
             $table = TableExporter::inst()->getTable($folding);
             //Проставим руками идентификатор фолдинга для колонки из базы
             $adapter->set($folding->getTableColumnIdent(), $fident);
             $rec = $table->fetchRowFromForm($adapter->getData(), $action);
             if (!is_array($rec)) {
                 //Данные для создания записи в БД не прошли валидацию
                 return $rec;
             }
             $table->saveRec($rec, $action);
             //createFoldingDbRec($folding, $ident);
         //createFoldingDbRec($folding, $ident);
         case self::BUTTON_SAVE:
             $folding->createEntity($fident);
             break;
     }
     return new AjaxSuccess(array('url' => AP_APFoldingEdit::urlFoldingEdit($folding->getFoldedEntity($fident))));
 }
Exemplo n.º 4
0
 public function doProcess(ArrayAdapter $params)
 {
     $postId = $params->int('postId');
     $postType = $params->str('postType');
     $this->postCP = Handlers::getInstance()->getPostsProcessorByPostType($postType)->getPostContentProvider($postId);
     check_condition(!!$this->postCP, "Not found post with id='{$postId}' for post type='{$postType}'");
 }
Exemplo n.º 5
0
 protected function executeImpl(ArrayAdapter $params)
 {
     $unique = $params->str(DiscussionController::JS_DATA_UNIQUE);
     $upDown = $params->bool(DiscussionController::JS_DATA_UPDOWN);
     $entity = $params->str(DiscussionController::JS_DATA_THREAD);
     $theme = $params->str(self::JS_PARAM_THEME);
     $comment = $params->str(self::JS_PARAM_COMMENT);
     $parentId = $params->int(self::JS_PARAM_PARENT_ID);
     $controller = Handlers::getInstance()->getDiscussionController($unique);
     //Валидируем тему
     if (!$parentId && $controller->getDiscussionSettings()->isThemed()) {
         if (!$theme) {
             return 'Введите тему';
         }
         $error = UserInputValidator::validateShortText($theme);
         if ($error) {
             return $error;
         }
         $theme = UserInputTools::safeShortText($theme);
     }
     //Валидируем комментарий
     if (!$comment) {
         return 'Введите комментарий';
     }
     $error = UserInputValidator::validateLongText($comment);
     if ($error) {
         return $error;
     }
     $comment = UserInputTools::safeLongText($comment);
     $msgObj = $controller->saveMessage($entity, $parentId, $comment, $theme, PsUser::inst());
     if (!$msgObj instanceof DiscussionMsg) {
         return 'Ошибка добавления сообщения';
     }
     return new AjaxSuccess($controller->buildLeaf($msgObj));
 }
Exemplo n.º 6
0
 public function doProcess(ArrayAdapter $params)
 {
     $postId = $params->int('postId');
     $postType = $params->str('postType');
     $pp = Handlers::getInstance()->getPostsProcessorByPostType($postType);
     $this->postCP = $pp->getPostContentProvider($postId);
 }
Exemplo n.º 7
0
 public function execute()
 {
     //1. ПРОВЕРИМ ВСЕ ФОЛДИНГИ, НЕТ ЛИ ИЗМЕНЁННЫХ СУЩНОСТЕЙ
     /* @var $folding FoldedResources */
     foreach (Handlers::getInstance()->getFoldings() as $folding) {
         $folding->checkAllEntitiesChanged();
     }
 }
Exemplo n.º 8
0
function smarty_modifier_rubric_title(RubricContentProvider $rubricCP)
{
    $rubric = $rubricCP->getRubric();
    $rp = Handlers::getInstance()->getRubricsProcessorByPostType($rubric->getPostType());
    $title = $rp->rubricTitle();
    $name = $rubric->getName();
    echo "<h4>{$title}: <span>{$name}</span></h4>";
}
Exemplo n.º 9
0
 protected function processImpl(PostArrayAdapter $adapter, $button)
 {
     $entity = Handlers::getInstance()->getFoldedEntityByUnique($adapter->str('fentity'));
     $tpl = $entity->getFolding()->getInfoTpl($entity->getIdent(), $adapter->str('ftpl'));
     $content = $adapter->str('tpl');
     $tpl->getDirItem()->writeLineToFile($content, true);
     return new AjaxSuccess();
 }
Exemplo n.º 10
0
/**
 * Управление постом
 */
function smarty_modifier_post_header_controls($post)
{
    $post = $post instanceof PostContentProvider ? $post->getPost() : $post;
    $pp = Handlers::getInstance()->getPostsProcessorByPostType($post->getPostType());
    /*
     * Собираем кнопки управления
     */
    $buttons = array();
    $hintClasses = 'hint--top hint--info hint--rounded';
    //Печать поста
    $attrs = array();
    $title = 'Версия для печати';
    $attrs['href'] = '#print';
    $attrs['title'] = $title;
    $attrs['data'] = array('hint' => $title);
    $attrs['class'] = $hintClasses;
    $content = CssSpritesManager::getDirSprite(CssSpritesManager::DIR_ICO, 'print', true);
    $buttons[] = PsHtml::a($attrs, $content);
    //Оригинальный вид поста
    if (PsDefines::isReplaceFormulesWithImages()) {
        $attrs = array();
        $title = 'Просмотр ' . ps_strtolower($pp->postTitle(null, 2)) . ' без замены формул на картинки';
        $attrs['href'] = '#originalView';
        $attrs['title'] = $title;
        $attrs['data'] = array('hint' => $title);
        $attrs['class'] = $hintClasses;
        $content = CssSpritesManager::getDirSprite(CssSpritesManager::DIR_ICO, 'formula', true);
        $buttons[] = PsHtml::a($attrs, $content);
    }
    //Быстрый просмотр постов (перелистывание)
    $attrs = array();
    $title = 'Предыдущий/следующий ' . ps_strtolower($pp->postTitle(null, 1));
    $attrs['href'] = '#prevNextView';
    $attrs['title'] = $title;
    $attrs['data'] = array('hint' => $title);
    $attrs['class'] = $hintClasses;
    $content = CssSpritesManager::getDirSprite(CssSpritesManager::DIR_ICO, 'prev_next', true);
    $buttons[] = PsHtml::a($attrs, $content);
    //Предыдущий пост
    $prevPost = $pp->getPrevPost($post->getId(), false);
    if ($prevPost) {
        $attrs = array();
        $attrs['data']['hint'] = $pp->postTitle($prevPost);
        $attrs['class'] = $hintClasses;
        $content = CssSpritesManager::getDirSprite(CssSpritesManager::DIR_ICO, 'prev_s', true);
        $buttons[] = $pp->postHref($prevPost, $content, null, $attrs);
    }
    //Следующий пост
    $nextPost = $pp->getNextPost($post->getId(), false);
    if ($nextPost) {
        $attrs = array();
        $attrs['data']['hint'] = $pp->postTitle($nextPost);
        $attrs['class'] = $hintClasses;
        $content = CssSpritesManager::getDirSprite(CssSpritesManager::DIR_ICO, 'next_s', true);
        $buttons[] = $pp->postHref($nextPost, $content, null, $attrs);
    }
    return PsHtml::div(array('class' => PsConstJs::POST_HEAD_CONTROLS), implode(' ', $buttons));
}
Exemplo n.º 11
0
 protected function getPlugins()
 {
     $result = array();
     /* @var $manager FoldedResources */
     foreach (Handlers::getInstance()->getBubbles() as $manager) {
         $this->registerPluginImpl($result, $manager->getSmartyPrefix());
     }
     return $result;
 }
Exemplo n.º 12
0
 function __construct(Rubric $rubric = null)
 {
     $this->rubric = $rubric;
     $this->isRubric = !!$rubric;
     if ($this->isRubric) {
         $this->rp = Handlers::getInstance()->getRubricsProcessorByPostType($rubric->getPostType());
         $this->suffix = ' в ' . ps_strtolower($this->rp->rubricTitle(null, 6));
     }
 }
Exemplo n.º 13
0
 private function getAllComments()
 {
     $formules = array();
     /* @var $proc PostsProcessor */
     foreach (Handlers::getInstance()->getPostsProcessors() as $proc) {
         $formules = array_merge($formules, $proc->getCommentsFormules());
     }
     return $formules;
 }
Exemplo n.º 14
0
 /**
  * Метод пытается выдать очки пользователю на основе запроса к ajax {@link GivePointsCommon}
  */
 public function givePointsByRequest(PsUser $user, ArrayAdapter $request)
 {
     $fentity = Handlers::getInstance()->getFoldedEntityByUnique($request->str('fentity'));
     $class = $fentity->getClassInst();
     PsUtil::assertInstanceOf($class, 'PointsGiverRequest');
     $request->remove('fentity');
     $ctxt = new GivePointsContext($user->getId(), $fentity->getDbCode());
     $class->givePointsByRequest($ctxt, $request);
     return $this->checkGivePointsContext($user, $ctxt);
 }
Exemplo n.º 15
0
 protected function doFinalize($CONTENT)
 {
     //1. Менеджеры, которые могут финализировать страницы, производят это
     /* @var $folding PageFinalizerFolding */
     foreach (Handlers::getInstance()->getPageFinaliseFoldings() as $folding) {
         $CONTENT = $folding->finalizePageContent($CONTENT);
     }
     //2. BubbledFolding добавляют свои ресурсы для быстрого открытия подсказок
     return $CONTENT . $this->getBubbles($CONTENT);
 }
Exemplo n.º 16
0
 protected function preload($mident, array $params)
 {
     /* @var $pp PostsProcessor */
     foreach (Handlers::getInstance()->getPostsProcessors() as $pp) {
         $folding = $pp->getFolding();
         foreach ($folding->getAccessibleDbIdents() as $ident) {
             $this->posts[] = $folding->getUnique($ident);
         }
     }
 }
Exemplo n.º 17
0
 protected function executeImpl(ArrayAdapter $params)
 {
     $id = $params->int('id');
     $uts = $params->int('date');
     $show = $params->bool('show');
     $type = $params->str('type');
     $pp = Handlers::getInstance()->getPostsProcessorByPostType($type);
     AdminPostsBean::inst()->updateState($pp->dbBean(), $id, $uts, $show);
     return new AjaxSuccess();
 }
Exemplo n.º 18
0
 public function getUserPostCommentsCnt($userId)
 {
     $total = 0;
     /* @var $cp CommentsProcessor */
     foreach (Handlers::getInstance()->getCommentProcessors() as $cp) {
         $cnt = $cp->getUserCommentsAnswersCnt($userId);
         $total += $cnt;
     }
     return $total;
 }
Exemplo n.º 19
0
 /**
  * Основной метод
  */
 protected function getPlugins()
 {
     $result = array();
     /* @var $manager FoldedResources */
     foreach (Handlers::getInstance()->getPanelProviders() as $manager) {
         $prefix = $manager->getSmartyPrefix();
         $result[$prefix . self::MODIFIER_SUFFIX] = Smarty::PLUGIN_MODIFIER;
         //Модификатор
     }
     return $result;
 }
Exemplo n.º 20
0
 protected function executeImpl(ArrayAdapter $params)
 {
     $ftype = $params->str('ftype');
     $fsubtype = $params->str('fsubtype');
     $fident = $params->str('fident');
     $zip = Handlers::getInstance()->getFolding($ftype, $fsubtype)->export2zip($fident);
     if (!$zip->isFile()) {
         return 'Не удалось создать архив';
     }
     return new AjaxSuccess($zip->getRelPath());
 }
Exemplo n.º 21
0
 public function buildContent()
 {
     $PARAMS['uts_php'] = time();
     $PARAMS['uts_db'] = UtilsBean::inst()->getDbUnixTimeStamp();
     $posts = array();
     /* @var $pp PostsProcessor */
     foreach (Handlers::getInstance()->getPostsProcessors() as $pp) {
         $posts[$pp->postsTitle()] = AdminPostsBean::inst()->getAllPosts($pp->dbBean());
     }
     $PARAMS['data'] = $posts;
     echo $this->getFoldedEntity()->fetchTpl($PARAMS);
 }
Exemplo n.º 22
0
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();
}
Exemplo n.º 23
0
 protected function executeImpl(ArrayAdapter $params)
 {
     $name = $params->str('name');
     $type = $params->str('type');
     $ident = $params->str('ident');
     $rubId = $params->int('rubId');
     check_condition($name, 'Name is empty');
     $pp = Handlers::getInstance()->getPostsProcessorByPostType($type);
     $pp->getFolding()->assertExistsEntity($ident);
     AdminPostsBean::inst()->registerPost($pp->dbBean(), $ident, $name, $rubId);
     return new AjaxSuccess();
 }
Exemplo n.º 24
0
 /**
  * Меод должен вернуть все возможные маппинги.
  * Нужно для показа в админке
  */
 protected final function allMappings()
 {
     $mappings = array();
     foreach (Handlers::getInstance()->getRubricsProcessors() as $postType => $rp) {
         $mappings[] = self::RUBRIC_2_SCCONTROLLERS($postType);
     }
     foreach (Handlers::getInstance()->getPostsProcessors() as $postType => $pp) {
         $mappings[] = self::RECOMMENDED_POSTS($postType);
     }
     $mappings[] = self::CACHE_FOLDINGS();
     $mappings[] = self::CACHE_DBENTITYS();
     return $mappings;
 }
Exemplo n.º 25
0
 protected function processImpl(PostArrayAdapter $adapter, $button)
 {
     $clear = $adapter->bool(FORM_PARAM_YES_NO);
     $folding = Handlers::getInstance()->getFoldingByUnique($adapter->str('folding'));
     $uploadedZip = SimpleUploader::inst()->saveUploadedFile();
     try {
         $fentity = $folding->imporFromZip($uploadedZip, $clear);
     } catch (Exception $ex) {
         $uploadedZip->remove();
         throw $ex;
     }
     return new AjaxSuccess(array('url' => AP_APFoldingEdit::url($fentity)));
 }
Exemplo n.º 26
0
 protected function executeImpl(ArrayAdapter $params)
 {
     $libType = $params->str('fsubtype');
     $libManager = Handlers::getInstance()->getLibManager($libType);
     $models = $params->arr('models');
     foreach ($models as $model) {
         $model['grup'] = $libType;
         $item = new LibItemDb($model);
         check_condition($item->getIdent(), 'Не передан идентификатор сущности');
         $libManager->saveLibItem($item, AdminLibBean::inst());
     }
     return new AjaxSuccess();
 }
Exemplo n.º 27
0
 protected function getWindowTplSmartyParams()
 {
     $posts = array();
     /* @var $processor PostsProcessor */
     foreach (Handlers::getInstance()->getPostsProcessors() as $processor) {
         /* @var $post Post */
         foreach ($processor->getPosts() as $post) {
             $posts[IdHelper::ident($post)] = array('name' => $processor->postTitle($post), 'url' => $processor->postUrl($post), 'cover' => $processor->getCoverDi($post->getIdent(), '64x64')->getRelPath());
         }
     }
     $params['posts'] = $posts;
     return $params;
 }
Exemplo n.º 28
0
 /** @return NavigationItem */
 private static function byPost(Post $post, $postAnonsName = 'Навигация')
 {
     $pp = Handlers::getInstance()->getPostsProcessorByPostType($post->getPostType());
     $item = self::byHref($pp->postHref($post), $postAnonsName);
     $anons = $pp->getPostContentProvider($post->getId())->getPostParams()->getAnons();
     $item->setPostData($post, $pp);
     if (empty($anons)) {
         return $item;
     }
     $item->setExtraData('chanons');
     foreach ($anons as $num => $name) {
         $item->addChild(self::byHref($pp->postHref($post, $name, "p{$num}")));
     }
     return $item;
 }
Exemplo n.º 29
0
 protected function executeImpl(ArrayAdapter $params)
 {
     $action = $params->str('action');
     $unique = $params->str('unique');
     $folding = Handlers::getInstance()->getFoldingByUnique($unique);
     $res = 'OK';
     switch ($action) {
         case 'save_list':
             $list = $params->str('list');
             $data = $params->arr('data');
             $folding->saveList($list, $data);
             break;
         default:
             return 'Неизвестное действие: ' . $action;
     }
     return new AjaxSuccess($res);
 }
Exemplo n.º 30
0
 /**
  * Метод строит список постов, в которых появились новые комментарии, и показывает их администратору.
  * 
  * Выпуск №1 (3)
  * Архимед (7)
  */
 public function getPostsWithUncheckedCommentsHtml()
 {
     $adminId = AuthManager::getUserId();
     $result = array();
     /* @var $pp PostsProcessor */
     foreach (Handlers::getInstance()->getPostsProcessors() as $pp) {
         $bean = $pp->dbBean();
         $table = $bean->getPostsTable();
         $table_comments = $bean->getCommentsTable();
         $query = "SELECT p.id_post, (SELECT count(*)\n             FROM {$table_comments} c\n            WHERE     c.id_post = p.id_post\n                  AND c.b_deleted = 0\n                  AND c.b_confirmed = 0\n                  AND c.id_user <> ?) as comments_count\n  FROM v_{$table} p\n WHERE EXISTS\n          (SELECT *\n             FROM {$table_comments} c\n            WHERE     c.id_post = p.id_post\n                  AND c.b_deleted = 0\n                  AND c.b_confirmed = 0\n                  AND c.id_user <> ?)";
         $posts = $this->getArray($query, array($adminId, $adminId));
         foreach ($posts as $post) {
             $result[] = '<li>' . $pp->postHref($post['id_post'], null, 'comments') . ' (' . $post['comments_count'] . ')</li>';
         }
     }
     return '<ul>' . implode('', $result) . '</ul>';
 }