/** * Constructor of the class * * @param blogInfo A valid BlogInfo object representing the blog to which this View belongs * @param templateName A template name * @param cachingEnabled either SMARTY_VIEW_CACHE_ENABLED, SMARTY_VIEW_CACHED_DISABLED, SMARTY_VIEW_CACHE_CHECK. * If left as SMARTY_VIEW_CACHE_CHECK, the blog settings will checked to determine whether caching is enabled * or not. * @param data Data that will be used to generate a unique id for the cached view (it will be ignored * if caching is not enabled) */ function SmartyView($blogInfo, $templateName, $cachingEnabled = SMARTY_VIEW_CACHE_CHECK, $data = array()) { // parent constructor $this->View(); if ($cachingEnabled == SMARTY_VIEW_CACHE_CHECK) { // detect whether caching should be enabled or not $config =& Config::getConfig(); $cachingEnabled = $config->getValue("template_cache_enabled"); } // whether caching is enabled or not $this->_cachingEnabled = $cachingEnabled; // save the blogInfo object $this->_blogInfo = $blogInfo; // name of the tepmlate $this->_templateName = $templateName; // get the right CachedTemplate or Template object $blogSettings = $this->_blogInfo->getSettings(); $ts = new TemplateService(); if ($this->isCachingEnabled()) { // get a CachedTemplate object $this->_template = $ts->CachedTemplate($this->_templateName, $blogSettings->getValue('template'), $this->_blogInfo); // data used to calculate the view id $this->_data = $data; // and generate the right cache id for it $this->_data["blogId"] = $blogInfo->getId(); $this->_viewId = $this->generateCacheId(); } else { $this->_template = $ts->Template($this->_templateName, $blogSettings->getValue('template'), $this->_blogInfo); } }
function render() { parent::render(); $templateService = new TemplateService(); $template = $templateService->Template($this->_templateName, "admin/xml"); $template->assign($this->_params->getAsArray()); print $template->fetch(); }
function generateTemplate() { $templateService = new TemplateService(); $this->_template = $templateService->customTemplate($this->_templateName, "summary/rss", true); // by default, these compiled files would be saved and cached to tmp/summary/rss but that's too // many folders so we'll overwrite the default settings set by TemplateService::customTemplate() // and save the files to tmp/summary/ with the other summary pages $config =& Config::getConfig(); $templateTmpFolder = $config->getValue("temp_folder") . '/summary'; $this->_template->cache_dir = $templateTmpFolder; $this->_template->compile_dir = $templateTmpFolder; }
function renderBodyTemplate($templateid, $templateFolder) { // create a new template service $ts = new TemplateService(); $messageTemplate = $ts->Template($templateid, $templateFolder); $messageTemplate->assign("username", $this->username); $messageTemplate->assign("activeCode", $this->activeCode); $messageTemplate->assign("activeLink", $this->activeLink); // FIXME: use which locale? $locale =& Locales::getLocale(); $messageTemplate->assign("locale", $locale); // render and return the contents return $messageTemplate->fetch(); }
function render() { // load the locale $this->_getLocale(); // set the view character set based on the locale $this->setCharset($this->_locale->getCharset()); parent::render(); $templateService = new TemplateService(); $template = $templateService->customTemplate($this->_templateName, "summary"); $this->_params->setValue("version", new Version()); $this->_params->setValue("locale", $this->_locale); $template->assign($this->_params->getAsArray()); print $template->fetch(); }
/** * Renders the view. It simply gets all the parameters we've been adding to it * and puts them in the context of the template renderer so that they can be accessed * as normal parameters from within the template */ function render() { parent::render(); // to find the template we need, we can use the TemplateService $ts = new TemplateService(); $template = $ts->AdminTemplate(ADMINLOGIN_TEMPLATE); // load the default locale $config =& Config::getConfig(); $locale =& Locales::getLocale($config->getValue("default_locale")); $this->setValue("locale", $locale); // assign all the values $template->assign($this->_params->getAsArray()); // and send the results print $template->fetch(); }
function RssView($blogInfo, $profile, $data = array()) { $this->BlogView($blogInfo, "", SMARTY_VIEW_CACHE_CHECK, $data); $ts = new TemplateSetStorage(); if (!$ts->templateExists($this->_profile, 'rss')) { // if not, then we will use the default one $this->_profile = RSS_VIEW_DEFAULT_PROFILE; } // we need to overwrite the $this->_template object with the Template object of our choice... $this->_profile = $profile; $templateService = new TemplateService(); $this->_template = $templateService->CachedTemplate($this->_profile, 'rss', $this->_blogInfo); // set the correct content type $this->setContentType('text/xml'); }
/** * Renders the view. It simply gets all the parameters we've been adding to it * and puts them in the context of the template renderer so that they can be accessed * as normal parameters from within the template */ function render() { // set the view character set based on the default locale $config =& Config::getConfig(); $locale =& Locales::getLocale($config->getValue("default_locale")); $this->setCharset($locale->getCharset()); parent::render(); // to find the template we need, we can use the TemplateService $ts = new TemplateService(); $template = $ts->AdminTemplate("dashboard"); $this->setValue("locale", $locale); // assign all the values $template->assign($this->_params->getAsArray()); // and send the results print $template->fetch(); }
function render() { // set the view character set based on the default locale $config =& Config::getConfig(); $locale =& Locales::getLocale($config->getValue("default_locale")); $this->setValue('version', Version::getVersion()); $this->setCharset($locale->getCharset()); parent::render(); // load the contents into the template context $ts = new TemplateService(); $template = $ts->Template(ADMINSIMPLEMESSAGE_TEMPLATE, "admin"); $this->setValue("locale", $locale); // and pass the values to the template $template->assign($this->_params->getAsArray()); // finally, send the results print $template->fetch(); }
/** * sends the email with the request * @private */ function sendResetEmail($userInfo, $url) { // prepare the template $templateService = new TemplateService(); $template = $templateService->Template("resetpasswordemail", "summary"); $template->assign("locale", $this->_locale); $template->assign("reseturl", $url); // render it and keep its contents $emailBody = $template->fetch(); $message = new EmailMessage(); $config =& Config::getConfig(); $message->setFrom($config->getValue("post_notification_source_address")); $message->addTo($userInfo->getEmail()); $message->setSubject("pLog Password Reset Request"); $message->setBody($emailBody); $service = new EmailService(); return $service->sendMessage($message); }
/** * Renders the template at templates/misc/email_notifier.template */ function renderMessageTemplate($article, $blogInfo) { // create a new template service $ts = new TemplateService(); $messageTemplate = $ts->Template(EMAILNOTIFIER_TEMPLATE, "misc"); // add these two useful objects $rg =& RequestGenerator::getRequestGenerator($blogInfo); // disable the xhtml mode, as some email clients cannot deal with it $rg->setXHTML(false); $messageTemplate->assign("url", $rg); $messageTemplate->assign("post", $article); // render and return the contents return $messageTemplate->fetch(); }
<?php require_once 'includes/config.php'; require_once 'includes/classes/template_service.php'; session_start(); $tpl = new TemplateService(); $tpl->display('index.php');
/** * Change the module used as an entry-point for Oasis skin and use custom class for rendering edit page * * Keep global and user nav only. * * @author macbre */ function setupEditPage(Article $editedArticle, $fullScreen = true, $class = false) { wfProfileIn(__METHOD__); $user = $this->app->wg->User; // don't render edit area when we're in read only mode if ($this->app->runFunction('wfReadOnly')) { // set correct page title $this->out->setPageTitle($this->app->runFunction('wfMsg', 'editing', $this->app->getGlobal('wgTitle')->getPrefixedText())); return false; } // use "reskined" edit page layout $this->fullScreen = $fullScreen; if ($fullScreen) { // set Oasis entry-point Wikia::setVar('OasisEntryControllerName', 'EditPageLayout'); } // macbre: load YUI on edit page (it's always loaded using $.loadYUI) // PLB has problems with $.loadYUI not working correctly in Firefox (callback is fired to early) /* $srcs = F::build('AssetsManager',array(),'getInstance')->getGroupCommonURL('yui'); $wgJsMimeType = $this->app->wg->JsMimeType; foreach($srcs as $src) { $this->out->addScript("<script type=\"{$wgJsMimeType}\" src=\"{$src}\"></script>"); } */ $this->out->addModules('wikia.yui'); // Disable custom JS while loading the edit page on MediaWiki JS pages and user subpages (BugID: 41449) if ($editedArticle->getTitle()->getNamespace() === NS_MEDIAWIKI && substr($editedArticle->getTitle()->getText(), -3) === '.js' || $editedArticle->getTitle()->getNamespace() === NS_USER && preg_match('/^' . preg_quote($user->getName(), '/') . '\\/.*\\.js$/', $editedArticle->getTitle()->getText())) { $this->out->disallowUserJs(); } // initialize custom edit page $this->editPage = new EditPageLayout($editedArticle); $editedTitle = $this->editPage->getEditedTitle(); $formCustomHandler = $this->editPage->getCustomFormHandler(); $this->addJsVariable('wgIsEditPage', true); $this->addJsVariable('wgEditedTitle', $editedTitle->getPrefixedText()); $this->addJsVariable('wgEditPageClass', $class ? $class : 'SpecialCustomEditPage'); $this->addJsVariable('wgEditPageHandler', !is_null($formCustomHandler) ? $formCustomHandler->getLocalUrl('wpTitle=$1') : $this->app->getGlobal('wgScript') . '?action=ajax&rs=EditPageLayoutAjax&title=$1'); $this->addJsVariable('wgEditPagePopularTemplates', TemplateService::getPromotedTemplates()); $this->addJsVariable('wgEditPageIsWidePage', $this->isWidePage()); if ($user->isLoggedIn()) { global $wgRTEDisablePreferencesChange; $wgRTEDisablePreferencesChange = true; $this->addJsVariable('wgEditPageWideSourceMode', (bool) $user->getOption('editwidth')); unset($wgRTEDisablePreferencesChange); } $this->addJsVariableRef('wgEditPageFormType', $this->editPage->formtype); $this->addJsVariableRef('wgEditPageIsConflict', $this->editPage->isConflict); $this->addJsVariable('wgEditPageIsReadOnly', $this->editPage->isReadOnlyPage()); $this->addJsVariableRef('wgEditPageHasEditPermissionError', $this->editPage->mHasPermissionError); $this->addJsVariableRef('wgEditPageSection', $this->editPage->section); // data for license module (BugId:6967) $titleLicensing = GlobalTitle::newFromText('Community_Central:Licensing', null, 177); $this->addJsVariable('wgEditPageLicensingUrl', $titleLicensing->getFullUrl()); $this->addJsVariable('wgRightsText', $this->app->wg->RightsText); // copyright warning for notifications (BugId:7951) $this->addJsVariable('wgCopywarn', $this->editPage->getCopyrightNotice()); // extra hooks for edit page $this->app->registerHook('MakeGlobalVariablesScript', 'EditPageLayoutHelper', 'onMakeGlobalVariablesScript', array(), false, $this); $this->app->registerHook('SkinGetPageClasses', 'EditPageLayoutHelper', 'onSkinGetPageClasses', array(), false, $this); WF::setInstance('EditPageLayoutHelper', $this); $this->editPage->setHelper($this); wfProfileOut(__METHOD__); return $this->editPage; }
/** * Grabbing list of most included templates * (moved to TemplateService) */ public static function getHotTemplates() { return TemplateService::getHotTemplates(); }
/** * Change the module used as an entry-point for Oasis skin and use custom class for rendering edit page * * Keep global and user nav only. * * @author macbre */ function setupEditPage(Article $editedArticle, $fullScreen = true, $class = false) { global $wgHooks; wfProfileIn(__METHOD__); $user = $this->app->wg->User; // don't render edit area when we're in read only mode if (wfReadOnly()) { // set correct page title $this->out->setPageTitle(wfMessage('editing', $this->app->getGlobal('wgTitle')->getPrefixedText())->escaped()); wfProfileOut(__METHOD__); return false; } // use "reskined" edit page layout $this->fullScreen = $fullScreen; if ($fullScreen) { // set Oasis entry-point Wikia::setVar('OasisEntryControllerName', 'EditPageLayout'); } // Disable custom JS while loading the edit page on MediaWiki JS pages and user subpages (BugID: 41449) $editedArticleTitle = $editedArticle->getTitle(); $editedArticleTitleNS = $editedArticleTitle->getNamespace(); $editedArticleTitleText = $editedArticleTitle->getText(); if ($editedArticleTitleNS === NS_MEDIAWIKI && substr($editedArticleTitleText, -3) === '.js' || $editedArticleTitleNS === NS_USER && preg_match('/^' . preg_quote($user->getName(), '/') . '\\/.*\\.js$/', $editedArticleTitleText)) { $this->out->disallowUserJs(); } // Add variables for pages to edit code (css, js, lua) if ($this->isCodeSyntaxHighlightingEnabled($editedArticleTitle)) { $this->prepareVarsForCodePage($editedArticleTitle); } // initialize custom edit page $this->editPage = new EditPageLayout($editedArticle); $editedTitle = $this->editPage->getEditedTitle(); $formCustomHandler = $this->editPage->getCustomFormHandler(); $this->addJsVariable('wgIsEditPage', true); $this->addJsVariable('wgEditedTitle', $editedTitle->getPrefixedText()); $this->addJsVariable('wgEditPageClass', $class ? $class : 'SpecialCustomEditPage'); $this->addJsVariable('wgEditPageHandler', !is_null($formCustomHandler) ? $formCustomHandler->getLocalUrl('wpTitle=$1') : $this->app->getGlobal('wgScript') . '?action=ajax&rs=EditPageLayoutAjax&title=$1'); $this->addJsVariable('wgEditPagePopularTemplates', TemplateService::getPromotedTemplates()); $this->addJsVariable('wgEditPageIsWidePage', $this->isWidePage()); $this->addJsVariable('wgIsDarkTheme', SassUtil::isThemeDark()); if ($user->isLoggedIn()) { global $wgRTEDisablePreferencesChange; $wgRTEDisablePreferencesChange = true; $this->addJsVariable('wgEditPageWideSourceMode', (bool) $user->getGlobalPreference('editwidth')); unset($wgRTEDisablePreferencesChange); } $this->addJsVariableRef('wgEditPageFormType', $this->editPage->formtype); $this->addJsVariableRef('wgEditPageIsConflict', $this->editPage->isConflict); $this->addJsVariable('wgEditPageIsReadOnly', $this->editPage->isReadOnlyPage()); $this->addJsVariableRef('wgEditPageHasEditPermissionError', $this->editPage->mHasPermissionError); $this->addJsVariableRef('wgEditPageSection', $this->editPage->section); // data for license module (BugId:6967) $titleLicensing = GlobalTitle::newFromText('Community_Central:Licensing', null, 177); $this->addJsVariable('wgEditPageLicensingUrl', $titleLicensing->getFullUrl()); $this->addJsVariable('wgRightsText', $this->app->wg->RightsText); // copyright warning for notifications (BugId:7951) $this->addJsVariable('wgCopywarn', $this->editPage->getCopyrightNotice()); // extra hooks for edit page $wgHooks['MakeGlobalVariablesScript'][] = 'EditPageLayoutHooks::onMakeGlobalVariablesScript'; $wgHooks['SkinGetPageClasses'][] = 'EditPageLayoutHooks::onSkinGetPageClasses'; $this->helper = self::getInstance(); wfProfileOut(__METHOD__); return $this->editPage; }
function filter() { // get some info $blogInfo = $this->_pipelineRequest->getBlogInfo(); $request = $this->_pipelineRequest->getHttpRequest(); $session = HttpVars::getSession(); // get the article id from the request, since if it is available, then we know // that we have to ask for the password before we can let users watch it $articleId = $request->getValue("articleId"); // If we use custom url mode, the article id is not available, we need to use // - articleName // - userId // - categoryId // - date // and $articles->getBlogArticleByTitle() to find the value if ($articleId == "") { $articleName = $request->getValue("articleName"); $categoryId = $request->getValue("postCategoryId", -1); $categoryName = $request->getValue("postCategoryName"); $userId = $request->getValue("userId", -1); $userName = $request->getValue("userName"); $date = $request->getValue("Date", -1); // If userName available, use it to find userId if ($userName) { $users =& new Users(); $user = $users->getUserInfoFromUsername($userName); if (!$user) { $result = new PipelineResult(true); return $result; } // if there was a user, use his/her id $userId = $user->getId(); } // If categoryName available, use it to find categoryId if ($categoryName) { $categories =& new ArticleCategories(); $category = $categories->getCategoryByName($categoryName, $blogInfo->getId()); if (!$category) { $result = new PipelineResult(true); return $result; } // if there was a user, use his/her id $categoryId = $category->getId(); } // fetch the article // the article identifier can be either its internal id number or its mangled topic $articles =& new Articles(); $article = $articles->getBlogArticleByTitle($articleName, $blogInfo->getId(), false, $date, $categoryId, $userId, POST_STATUS_PUBLISHED); if ($article) { $articleId = $article->getId(); } else { $result = new PipelineResult(true); return $result; } } // check if the article should be protected or not $secretItems = new SecretItems(); if ($secretItems->articleIsSecret($articleId)) { // if so, first check if the password does not already exist in the session $itemPassword = $request->getValue("itemPassword"); // do we already have this information in the session? $sessionKey = "article_" . $articleId . "_auth"; if ($session["{$sessionKey}"] != "") { // check if the information is correct if ($secretItems->authenticateItemHash($articleId, $session["{$sessionKey}"])) { // if all correct, go ahead! $result = new PipelineResult(true); return $result; } } // if not, check if we are authenticating now... if ($itemPassword != "") { // authenticate using the given password if (!$secretItems->authenticateItem($articleId, $itemPassword)) { $result = new PipelineResult(false, 500, "Better luck next time!"); } else { // if the user authenticated correctly, then put the information in the session _debug("authenticated correctly!"); $session = HttpVars::getSession(); $session["{$sessionKey}"] = md5($itemPassword); $result = new PipelineResult(true); HttpVars::setSession($session); } } else { $ts = new TemplateService(); $t = $ts->PluginTemplate("secret", "passwordform"); $t->assign("locale", $blogInfo->getLocale()); $t->assign("params", $request->getAsArray()); $t->assign("articleId", $articleId); $t->assign("url", RequestGenerator::getRequestGenerator($blogInfo)); $message = $t->fetch(); $result = new PipelineResult(false, 500, $message); } return $result; } // if everything went fine, we can say so by returning // a positive PipelineResult object $result = new PipelineResult(true); return $result; }
/** +---------------------------------------------------------- * TagLib库解析 +---------------------------------------------------------- * @access public +---------------------------------------------------------- * @param string $tagLib 要解析的标签库 * @param string $content 要解析的模板内容 * @param boolen $hide 是否隐藏标签库前缀 +---------------------------------------------------------- * @return string +---------------------------------------------------------- */ public function parseTagLib($tagLib, &$content, $hide = false) { $begin = $this->config['taglib_begin']; $end = $this->config['taglib_end']; $fileName = SITE_PATH . '/addons/plugins/Tags/TPTag.class.php'; require_cache($fileName); $tLib = new TPTag($tagLib); if ($tLib->valid()) { //如果标签库有效则取出支持标签列表 $tagList = $tLib->getTagList(); //遍历标签列表进行模板标签解析 foreach ($tagList as $tag) { self::$nowTags = $tag; // 实际要解析的标签名称 $startTag = $tag['name']; // 检查可嵌套标签以及嵌套级别 if ($tag['nested'] && $this->config['tag_level'] > 1) { $level = $this->config['tag_level']; } else { $level = 1; } $endTag = $startTag; if (false !== stripos($content, C('TAGLIB_BEGIN') . $startTag)) { if (empty($tag['attribute'])) { // 无属性标签 if ($tag['content'] != 'empty') { for ($i = 0; $i < $level; $i++) { $content = preg_replace('/' . $begin . $startTag . '(\\s*?)' . $end . '(.*?)' . $begin . '\\/' . $endTag . '(\\s*?)' . $end . '/eis', "\$this->parseXmlTag('" . $tagLib . "','" . $tag['name'] . "','\\1','\\2')", $content); } } else { $content = preg_replace('/' . $begin . $startTag . '(\\s*?)\\/(\\s*?)' . $end . '/eis', "\$this->parseXmlTag('" . $tagLib . "','" . $tag['name'] . "','\\1','')", $content); } } elseif ($tag['content'] != 'empty') { //闭合标签解析 for ($i = 0; $i < $level; $i++) { $content = preg_replace('/' . $begin . $startTag . '\\s(.*?)' . $end . '(.+?)' . $begin . '\\/' . $endTag . '(\\s*?)' . $end . '/eis', "\$this->parseXmlTag('" . $tagLib . "','" . $tag['name'] . "','\\1','\\2')", $content); } } else { //开放标签解析 // 开始标签必须有一个空格 $content = preg_replace('/' . $begin . $startTag . '\\s(.*?)\\/(\\s*?)' . $end . '/eis', "\$this->parseXmlTag('" . $tagLib . "','" . $tag['name'] . "','\\1','')", $content); } } self::$nowTags = array(); } } }
} else { $project = new ProjectMapper(); $project_id = $project->getFirstProjectId(); } $tpl = new TemplateService(); $tpl->todo_list = TodoMapper::getTodoList($project_id); $tpl->project_id = $project_id; echo $tpl->display('todo_list.php'); break; case 'update_list': $list = $_POST['listContainer']; TodoMapper::updateTodoList($list); break; case 'get_item': $item_id = str_replace('item_', '', $_GET['id']); $tpl = new TemplateService(); $tpl->todo = TodoMapper::getTodo($item_id); echo $tpl->display('todo.php'); break; case 'set_item': $output = TodoMapper::setTodo($_POST['value'], $_GET['project_id'], $_GET['id']); echo utf8_decode($output); break; case 'set_item_text': $value = $_POST['value']; $project_id = $_GET['project_id']; $id = $_GET['id']; $output = TodoMapper::setTodoText($value, $project_id, $id); echo utf8_decode($output); break; case 'insert_item':
function generateTemplate() { $templateService = new TemplateService(); $this->_template = $templateService->customTemplate($this->_templateName, "summary", true); }