/**
* Use this to parse your backend page
*
* You will get the template located in /View/Template/{CMD}.html
* You can access Cx class using $this->cx
* To show messages, use \Message class
*
* @param \Cx\Core\Html\Sigma $template Template for current CMD
* @param array $cmd CMD separated by slashes
*/
public function parsePage(\Cx\Core\Html\Sigma $template, array $cmd)
{
$uploader = new Uploader();
$uploader->setFinishedCallback('\\Cx\\Core_Modules\\Uploader\\Model\\DefaultUploadCallback');
$uploader->setCallback('gallery.uploader');
$template->setVariable('UPLOADER_CODE', $uploader->getXHtml('Open Uploader 1'));
$uploader2 = new Uploader();
$uploader2->setUploadLimit(1);
$uploader2->setFinishedCallback('\\Cx\\Core_Modules\\Uploader\\Model\\DefaultUploadCallback');
$uploader2->setCallback('gallery.uploader2');
$uploader2->setType(Uploader::UPLOADER_TYPE_INLINE);
$template->setVariable('UPLOADER_CODE2', $uploader2->getXHtml('Open Uploader 2'));
$configurations = array(array(), array('startview' => 'sitestructure', 'views' => 'sitestructure'), array('views' => 'uploader'), array('views' => 'sitestructure'), array('views' => 'filebrowser'), array('startmediatype' => 'gallery'), array('mediatypes' => 'gallery, files'), array('multipleselect' => true), array('data-cx-Mb-Cb-Js-modalopened' => 'testfunction'));
foreach ($configurations as $configuration) {
$mediaBrowser = new MediaBrowser();
$mediaBrowser->setOptions($configuration);
$mediaBrowser->setCallback('gallery.fancyCallback');
$template->setVariable('MEDIABROWSER_CODE', $mediaBrowser->getXHtml('MediaBrowser'));
$template->setVariable('MEDIABROWSER_OPTIONS', var_export($configuration, true));
$template->setVariable('MEDIABROWSER_CODE_RAW', htmlspecialchars($mediaBrowser->getXHtml('MediaBrowser')));
$template->parse('mediabrowser_demo');
}
$template->setVariable('MEDIABROWSER_FOLDER_WIDGET', new \Cx\Core_Modules\MediaBrowser\Model\Entity\FolderWidget($this->cx->getWebsiteImagesContentPath()));
$template->setVariable('MEDIABROWSER_FOLDER_WIDGET_VIEW_MODE', new \Cx\Core_Modules\MediaBrowser\Model\Entity\FolderWidget($this->cx->getWebsiteImagesContentPath(), true));
}
/**
* Use this to parse your backend page
*
* You will get the template located in /View/Template/{CMD}.html
* You can access Cx class using $this->cx
* To show messages, use \Message class
*
* @param \Cx\Core\Html\Sigma $template Template for current CMD
* @param array $cmd CMD separated by slashes
*/
public function parsePage(\Cx\Core\Html\Sigma $template, array $cmd)
{
$uploader = new Uploader();
$uploader->setFinishedCallback('\\Cx\\Core_Modules\\Uploader\\Model\\DefaultUploadCallback');
$uploader->setCallback('gallery.uploader');
$template->setVariable('UPLOADER_CODE', $uploader->getXHtml('Open Uploader 1'));
$uploader2 = new Uploader();
$uploader2->setFinishedCallback('\\Cx\\Core_Modules\\Uploader\\Model\\DefaultUploadCallback');
$uploader2->setCallback('gallery.uploader2');
$uploader2->setType(Uploader::UPLOADER_TYPE_INLINE);
$template->setVariable('UPLOADER_CODE2', $uploader2->getXHtml('Open Uploader 2'));
$mediaBrowser = new MediaBrowser();
$mediaBrowser->setCallback('gallery.fancyCallback');
$template->setVariable('MEDIABROWSER_CODE1', $mediaBrowser->getXHtml('MediaBrowser'));
$template->setVariable('MEDIABROWSER_CODE1_RAW', htmlspecialchars($mediaBrowser->getXHtml('MediaBrowser')));
$template->setVariable('MEDIABROWSER_FOLDER_WIDGET', new \Cx\Core_Modules\MediaBrowser\Model\Entity\FolderWidget($this->cx->getWebsiteImagesContentPath()));
$template->setVariable('MEDIABROWSER_FOLDER_WIDGET_VIEW_MODE', new \Cx\Core_Modules\MediaBrowser\Model\Entity\FolderWidget($this->cx->getWebsiteImagesContentPath(), true));
}
/**
* Use this to parse your backend page
*
* You will get the template located in /View/Template/{CMD}.html
* You can access Cx class using $this->cx
* To show messages, use \Message class
* @param \Cx\Core\Html\Sigma $template Template for current CMD
* @param array $cmd CMD separated by slashes
*/
public function parsePage(\Cx\Core\Html\Sigma $template, array $cmd)
{
global $_ARRAYLANG, $objInit;
$objTpl = new \Cx\Core\Html\Sigma($this->getDirectory(true) . '/View/Template/Backend');
//merge language
$langData = $objInit->loadLanguageData('Pdf');
$_ARRAYLANG = array_merge($_ARRAYLANG, $langData);
$objTpl->setGlobalVariable($_ARRAYLANG);
$objTpl->loadTemplatefile('Default.html');
// Not an entity, parse overview or settings
switch (current($cmd)) {
default:
// Parse entity view generation pages
$entityClassName = $this->getNamespace() . '\\Model\\Entity\\PdfTemplate';
$this->parseEntityClassPage($objTpl, $entityClassName, 'PdfTemplate');
if ($objTpl->blockExists('overview')) {
$objTpl->touchBlock('overview');
}
break;
}
\JS::registerCSS(substr($this->getDirectory(false, true) . '/View/Style/Backend.css', 1));
$template->setVariable(array('CONTENT_TITLE' => $_ARRAYLANG['TXT_CORE_MODULE_PDF'], 'ADMIN_CONTENT' => $objTpl->get()));
}
/**
* Do something before main template gets parsed
*
* @param \Cx\Core\Html\Sigma $template The main template
*/
public function preFinalize(\Cx\Core\Html\Sigma $template)
{
if ($this->cx->getMode() != \Cx\Core\Core\Controller\Cx::MODE_FRONTEND) {
return;
}
// make all language data of Access component globally available
$template->setVariable(\Env::get('init')->getComponentSpecificLanguageData($this->getName()));
}
/**
* Parsing the related News
*
* @global object $objDatabase
* @global type $_ARRAYLANG
*
* @param Object $objTpl Template Object
* @param Interger $newsId News Id
* @param Interger $langId Language id
* @param type $blockName Block Name
* @param type $limit Limit
*
* @return null
*/
public function parseRelatedNews(\Cx\Core\Html\Sigma $objTpl, $newsId = null, $langId = null, $blockName = 'related_news', $limit = 0)
{
global $_ARRAYLANG, $objDatabase;
if (empty($newsId) || !$objTpl->blockExists($blockName)) {
return;
}
//Getting the related news ids
$relatedNewsIds = $this->getRelatedNews($newsId);
$defaultLangId = \FWLanguage::getDefaultLangId();
//Getting the related news details for the given languages
$relatedNewsDetails = $this->getRelatedNewsDetails($relatedNewsIds, array($langId, $defaultLangId));
if (!empty($relatedNewsDetails)) {
$defaultImage = \Cx\Core\Core\Controller\Cx::instanciate()->getCodeBaseCoreModulePath() . '/News/View/Media/default_news_image.png';
$currentCount = 1;
foreach ($relatedNewsIds as $relatedNewsId) {
//If the limit is reached then the loop is stopped
if (!empty($limit) && $currentCount > $limit) {
break;
}
/*
* Checking the related news is available in the current
* acitve front-end language if not available then the default
* language details are getting used
* Comment/Uncomment the following line if this condition
* is required
*/
//$currentRelatedDetails = isset($relatedNewsDetails[$relatedNewsId][$langId])
// ? $relatedNewsDetails[$relatedNewsId][$langId]
// : $relatedNewsDetails[$relatedNewsId][$defaultLangId];
/*
* Checking the related news is available in the current
* acitve front-end language if not available then the related
* News not listed Comment/Uncomment the following
* line if this condition is required
*/
$currentRelatedDetails = isset($relatedNewsDetails[$relatedNewsId][$langId]) ? $relatedNewsDetails[$relatedNewsId][$langId] : false;
if (!$currentRelatedDetails) {
continue;
}
++$currentCount;
$categories = $this->getCategoriesByNewsId($relatedNewsId);
$newsUrl = empty($currentRelatedDetails['redirect']) ? empty($currentRelatedDetails['newscontent']) ? '' : \Cx\Core\Routing\Url::fromModuleAndCmd('news', $this->findCmdById('details', array_keys($categories)), FRONTEND_LANG_ID, array('newsid' => $relatedNewsId)) : $currentRelatedDetails['redirect'];
$newstitle = $currentRelatedDetails['title'];
$htmlLink = self::parseLink($newsUrl, $newstitle, contrexx_raw2xhtml('[' . $_ARRAYLANG['TXT_NEWS_MORE'] . '...]'));
$htmlLinkTitle = self::parseLink($newsUrl, $newstitle, contrexx_raw2xhtml($newstitle));
// in case that the message is a stub,
// we shall just display the news title instead of a html-a-tag
// with no href target
if (empty($htmlLinkTitle)) {
$htmlLinkTitle = contrexx_raw2xhtml($newstitle);
}
$imagePath = !empty($currentRelatedDetails['teaser_image_path']) ? $currentRelatedDetails['teaser_image_path'] : $defaultImage;
$imageThumbPath = !empty($currentRelatedDetails['teaser_image_thumbnail_path']) ? $currentRelatedDetails['teaser_image_thumbnail_path'] : $defaultImage;
$this->parseImageBlock($objTpl, $imagePath, $newstitle, $newsUrl, 'related_news_image');
$this->parseImageBlock($objTpl, $imageThumbPath, $newstitle, $newsUrl, 'related_news_image_thumb');
$author = \FWUser::getParsedUserTitle($currentRelatedDetails['author_id'], $currentRelatedDetails['author']);
$publisher = \FWUser::getParsedUserTitle($currentRelatedDetails['publisher_id'], $currentRelatedDetails['publisher']);
$objSubResult = $objDatabase->Execute('
SELECT count(`id`) AS `countComments`
FROM `' . DBPREFIX . 'module_news_comments`
WHERE `newsid` = ' . $relatedNewsId);
$objTpl->setVariable(array('NEWS_RELATED_NEWS_ID' => contrexx_raw2xhtml($relatedNewsId), 'NEWS_RELATED_NEWS_URL' => contrexx_raw2xhtml($newsUrl), 'NEWS_RELATED_NEWS_LINK' => $htmlLink, 'NEWS_RELATED_NEWS_TITLE' => contrexx_raw2xhtml($currentRelatedDetails['title']), 'NEWS_RELATED_NEWS_TITLE_SHORT' => strlen($currentRelatedDetails['title']) > 35 ? substr(strip_tags($currentRelatedDetails['title']), 0, 35) . '...' : strip_tags($currentRelatedDetails['title']), 'NEWS_RELATED_NEWS_TITLE_LINK' => $htmlLinkTitle, 'NEWS_RELATED_NEWS_TEXT' => $currentRelatedDetails['text'], 'NEWS_RELATED_NEWS_TEXT_SHORT' => strlen($currentRelatedDetails['text']) > 250 ? substr(strip_tags($currentRelatedDetails['text']), 0, 247) . '...' : strip_tags($currentRelatedDetails['text']), 'NEWS_RELATED_NEWS_TEASER_TEXT' => nl2br($currentRelatedDetails['teaser_text']), 'NEWS_RELATED_NEWS_AUTHOR' => contrexx_raw2xhtml($author), 'NEWS_RELATED_NEWS_PUBLISHER' => contrexx_raw2xhtml($publisher), 'NEWS_RELATED_NEWS_CATEGORY_NAMES' => implode(', ', contrexx_raw2xhtml($categories)), 'NEWS_RELATED_NEWS_LONG_DATE' => date(ASCMS_DATE_FORMAT, $currentRelatedDetails['newsdate']), 'NEWS_RELATED_NEWS_DATE' => date(ASCMS_DATE_FORMAT_DATE, $currentRelatedDetails['newsdate']), 'NEWS_RELATED_NEWS_TIME' => date(ASCMS_DATE_FORMAT_TIME, $currentRelatedDetails['newsdate']), 'NEWS_RELATED_NEWS_COUNT_COMMENTS' => $currentRelatedDetails['commentactive'] && $this->arrSettings['news_comments_activated'] ? contrexx_raw2xhtml($objSubResult->fields['countComments'] . ' ' . $_ARRAYLANG['TXT_NEWS_COMMENTS']) : ''));
if (!$objSubResult->fields['countComments'] || !$this->arrSettings['news_comments_activated']) {
if ($objTpl->blockExists('related_news_comments_count')) {
$objTpl->hideBlock('related_news_comments_count');
}
}
if ($this->arrSettings['news_use_teaser_text'] != '1' && $objTpl->blockExists('news_use_teaser_text')) {
$objTpl->hideBlock('news_use_teaser_text');
}
$objTpl->parse($blockName);
}
if ($objTpl->blockExists('related_news_block')) {
$objTpl->setVariable('TXT_NEWS_RELATED_NEWS', $_ARRAYLANG['TXT_NEWS_RELATED_NEWS']);
$objTpl->touchBlock('related_news_block');
}
}
}
/**
* Adds an external settings view to the current template
*
* The content must contain the full view, including the surrounding form
* tags and submit button.
* Note that these are always appended on the right end of the tab list.
* @param \Cx\Core\Html\Sigma $objTemplateLocal Template object
* @param string $tab_name The tab name to add
* @param string $content The external content
* @return boolean True on success
*/
static function show_external(&$objTemplateLocal, $tab_name, $content)
{
if (empty($objTemplateLocal) || !$objTemplateLocal->blockExists('core_setting_row')) {
$objTemplateLocal = new \Cx\Core\Html\Sigma(\Env::get('cx')->getCodeBaseDocumentRootPath() . '/core/Setting/View/Template/Generic');
if (!$objTemplateLocal->loadTemplateFile('Form.html')) {
die("Failed to load template Form.html");
}
}
$active_tab = isset($_REQUEST['active_tab']) ? $_REQUEST['active_tab'] : 1;
// The tabindex must be set in the form name in any case
$objTemplateLocal->setGlobalVariable(array('CORE_SETTING_TAB_INDEX' => self::$tab_index, 'CORE_SETTING_EXTERNAL' => $content));
// Set up the tab, if any
if (!empty($tab_name)) {
$objTemplateLocal->setGlobalVariable(array('CORE_SETTING_TAB_NAME' => $tab_name, 'CORE_SETTING_TAB_INDEX' => self::$tab_index, 'CORE_SETTING_TAB_CLASS' => self::$tab_index == $active_tab ? 'active' : '', 'CORE_SETTING_TAB_DISPLAY' => self::$tab_index++ == $active_tab ? 'block' : 'none', 'CORE_SETTING_CURRENT_TAB' => 'tab-' . $active_tab));
$objTemplateLocal->touchBlock('core_setting_tab_row');
$objTemplateLocal->parse('core_setting_tab_row');
$objTemplateLocal->touchBlock('core_setting_tab_div_external');
$objTemplateLocal->parse('core_setting_tab_div_external');
}
return true;
}
/**
* Render the option in the frontend.
*
* @param Sigma $template
*/
public function renderTheme($template)
{
$template->setVariable('TEMPLATE_EDITOR_' . strtoupper($this->name), $this->activeChoice);
}
请发表评论