/**
 * @deprecated
 * Больше не используется в системе
 */
function macros_content()
{
    static $res;
    if (!is_null($res)) {
        return $res;
    }
    $cmsController = cmsController::getInstance();
    $current_module = $cmsController->getCurrentModule();
    $current_method = $cmsController->getCurrentMethod();
    $previousValue = $cmsController->isContentMode;
    $cmsController->isContentMode = true;
    if ($module = $cmsController->getModule($current_module)) {
        $pid = $cmsController->getCurrentElementId();
        $permissions = permissionsCollection::getInstance();
        $templater = $cmsController->getCurrentTemplater();
        $isAdmin = $permissions->isAdmin();
        if ($pid) {
            list($r, $w) = $permissions->isAllowedObject($permissions->getUserId(), $pid);
            if ($r) {
                $is_element_allowed = true;
            } else {
                $is_element_allowed = false;
            }
        } else {
            $is_element_allowed = true;
        }
        if (system_is_allowed($current_module, $current_method) && $is_element_allowed) {
            if ($parsedContent = $cmsController->parsedContent) {
                return $parsedContent;
            }
            if ($cmsController->getCurrentMode() == "admin") {
                try {
                    if (!$templater->getIsInited()) {
                        $res = $module->cms_callMethod($current_method, NULL);
                    }
                } catch (publicException $e) {
                    $templater->setDataSet($e);
                    return $res = false;
                }
            } else {
                try {
                    $res = $module->cms_callMethod($current_method, NULL);
                } catch (publicException $e) {
                    $res = $e->getMessage();
                }
                $res = system_parse_short_calls($res);
                $res = str_replace("%content%", "%content ", $res);
                $res = templater::getInstance()->parseInput($res);
                $res = system_parse_short_calls($res);
            }
            if ($res !== false && is_array($res) == false) {
                if ($cmsController->getCurrentMode() != "admin" && stripos($res, "%cut%") !== false) {
                    if (array_key_exists("cut", $_REQUEST)) {
                        if ($_REQUEST['cut'] == "all") {
                            $_REQUEST['cut_pages'] = 0;
                            return str_ireplace("%cut%", "", $res);
                        }
                        $cut = (int) $_REQUEST['cut'];
                    } else {
                        $cut = 0;
                    }
                    $res_arr = spliti("%cut%", $res);
                    if ($cut > sizeof($res_arr) - 1) {
                        $cut = sizeof($res_arr) - 1;
                    }
                    if ($cut < 0) {
                        $cut = 0;
                    }
                    $_REQUEST['cut_pages'] = sizeof($res_arr);
                    $_REQUEST['cut_curr_page'] = $cut;
                    $res = $res_arr[$cut];
                }
                $cmsControllerInstance = $cmsController;
                $cmsControllerInstance->parsedContent = $res;
                $cmsController->isContentMode = $previousValue;
                return $res;
            } else {
                $cmsController->isContentMode = $previousValue;
                return $res = '<notice>%core_templater% %core_error_nullvalue%</notice>';
            }
        } else {
            if ($cmsController->getCurrentMode() == "admin" && $isAdmin) {
                if ($current_module == "content" && $current_method == "sitetree") {
                    $regedit = regedit::getInstance();
                    $modules = $regedit->getList("//modules");
                    foreach ($modules as $item) {
                        list($module) = $item;
                        if (system_is_allowed($module) && $module != 'content') {
                            $module_inst = $cmsController->getModule($module);
                            $url = $module_inst->pre_lang . "/admin/" . $module . "/";
                            $module_inst->redirect($url);
                        }
                    }
                }
            }
            if ($module = $cmsController->getModule("users")) {
                header("Status: 401 Unauthorized");
                $cmsController->setCurrentModule("users");
                $cmsController->setCurrentMethod("login");
                $cmsController->isContentMode = $previousValue;
                if ($isAdmin) {
                    $module = $cmsController->getModule($current_module);
                    if ($module->isMethodExists($current_method) == false) {
                        $url = $module_inst->pre_lang . "/admin/content/sitetree/";
                        $module->redirect($url);
                    }
                    if ($cmsController->getCurrentMode() == "admin") {
                        $e = new requreMoreAdminPermissionsException(getLabel("error-require-more-permissions"));
                        $templater->setDataSet($e);
                    }
                    return $res = "<p><warning>%core_error_nopermission%</warning></p>" . $module->login();
                } else {
                    if ($templater instanceof xslAdminTemplater && $templater->getParsed()) {
                        throw new requireAdminPermissionsException("No permissions");
                    }
                    return $res = $module->login();
                }
            }
            return $res = '<warning>%core_templater% %core_error_nullvalue% %core_error_nopermission%</warning>';
        }
    }
    $cmsController->isContentMode = $previousValue;
    return $res = '%core_templater% %core_error_unknown%';
}
Example #2
0
 /**
  * @desc Выводит содержимое публикации
  * @param int $postId Идентификатор публикации
  * @param string $template имя файла шаблона
  * @return string|array
  */
 public function postView($postId = false, $template = 'default')
 {
     $userId = cmsController::getInstance()->getModule('users')->user_id;
     if (!$postId) {
         $postId = ($tmp = getRequest('param0')) ? $tmp : $postId;
     }
     if ($postId === false) {
         $this->redirect(getServer('HTTP_REFERER'));
     }
     $postId = umiObjectProperty::filterInputString($postId);
     list($sTemplate) = self::loadTemplates('blogs20/' . $template, 'post_view');
     $oHierarchy = umiHierarchy::getInstance();
     $oPost = $oHierarchy->getElement($postId);
     if (!$oPost) {
         throw new publicException(getLabel('error-page-does-not-exist', null, $postId));
     }
     if ($oPost->getTypeId() != umiHierarchyTypesCollection::getInstance()->getTypeByName("blogs20", "post")->getId()) {
         throw new publicException("The id(#{$postId}) given is not an id of the blog's post");
     }
     if (!$oPost->getIsActive() && $oPost->getObject()->getOwnerId() != $userId) {
         $this->redirect('/blogs20/draughtsList/');
     }
     $oBlog = $oHierarchy->getElement($oPost->getRel());
     $sPostLink = $oHierarchy->getPathById($postId, true);
     $sBlogLink = $oHierarchy->getPathById($oBlog->getId(), true);
     $aParams = array();
     $aParams['name'] = $oPost->getName();
     $aParams['content'] = $this->prepareContent(system_parse_short_calls($oPost->getValue('content'), $postId));
     $aParams['pid'] = $postId;
     $aParams['bid'] = $oBlog->getId();
     $aParams['blog_title'] = $oBlog->getValue('title');
     $aParams['blog_name'] = $oBlog->getName();
     $aParams['post_link'] = $sPostLink;
     $aParams['blog_link'] = $sBlogLink;
     $aParams['author_id'] = $oPost->getObject()->getOwnerId();
     //		$aParams['publish_time'] = $oPost->getValue('publish_time')->getFormattedDate('U');
     $this->pushEditable("blogs20", "post", $postId);
     return self::parseTemplate($sTemplate, $aParams, $postId);
 }