public function GetError() { $str = cms_utils::get_app_data('content_error'); return $str; }
/** * Loads a set of content objects into the cached tree. * * @param boolean $loadprops If true, load the properties of those content objects * @param boolean $onlyexpanded Not implemented * @param boolean $loadcontent If false, only create the nodes in the tree, * don't load the content objects * @return mixed The cached tree of content */ function &GetAllContentAsHierarchy($loadcontent = false) { debug_buffer('', 'starting tree'); $gCms = cmsms(); $db = $gCms->GetDb(); $tree = null; $cachefilename = TMP_CACHE_LOCATION . '/contentcache.php'; $loadedcache = false; if (file_exists($cachefilename)) { $last_modified = cms_utils::get_app_data('last_content_modification'); if ($last_modified <= 0) { } $query = 'SELECT modified_date FROM ' . cms_db_prefix() . 'content ORDER BY modified_date DESC'; $val = $db->GetOne($query); $last_modified = $db->UnixTimeStamp($val); cms_utils::set_app_data('last_content_modification', $last_modified); if ($last_modified > 0 && $last_modified < filemtime($cachefilename)) { debug_buffer('Content tree file needs loading'); $handle = fopen($cachefilename, "r"); $data = fread($handle, filesize($cachefilename)); fclose($handle); $tree = unserialize(substr($data, 16)); if (strtolower(get_class($tree)) == 'cms_content_tree') { $loadedcache = true; } else { $loadedcache = false; } } } if (!$loadedcache) { debug_buffer('', 'Start Loading Children into Tree'); $query = 'SELECT content_id,parent_id,content_alias FROM ' . cms_db_prefix() . 'content ORDER BY parent_id,item_order'; $nodes = $db->GetArray($query); $tree = cms_tree_operations::load_from_list($nodes); debug_buffer('', 'End Loading Children into Tree'); } if (!$loadedcache) { debug_buffer("Serializing..."); @file_put_contents($cachefilename, '<?php return; ?>' . serialize($tree)); } if ($loadcontent) { $this->LoadChildren(-1, true, true); } debug_buffer('', 'ending tree'); return $tree; }
/** * A replacement for the built in DoAction method * For CGExtensions derived modules some builtin smarty variables are created * module hints are handled, and input type=image values are corrected in input parameters. * * this method also handles setting the active tab, and displaying any messages or errors * set with the SetError or SetMessage methods. * * This method is called automatically by the system based on the incoming request, and the page template. * It should almost never be called manually. * * @see SetError() * @see SetMessage() * @see SetCurrentTab() * @see RedirectToTab() * @param string $name the action name * @param string $id The module action id * @param array $params The module parameters * @param int $returnid The page that will contain the HTML results. This is empty for admin requests. */ public function DoAction($name, $id, $params, $returnid = '') { if (!method_exists($this, 'set_action_id') && $this->GetName() != MOD_CGEXTENSIONS) { die('FATAL ERROR: A module derived from CGExtensions is not handling the set_action_id method'); } $this->set_action_id($id); // handle the stupid input type='image' problem. foreach ($params as $key => $value) { if (endswith($key, '_x')) { $base = substr($key, 0, strlen($key) - 2); if (isset($params[$base . '_y']) && !isset($params[$base])) { $params[$base] = $base; } } } // handle module hints $hints = cms_utils::get_app_data('__MODULE_HINT__' . $this->GetName()); if (is_array($hints)) { foreach ($hints as $key => $value) { if (isset($params[$key])) { continue; } $params[$key] = $value; } } /* if( !CmsApp::get_instance()->is_frontend_request() && $this->CheckPermission('Modify Modules') ) { // display module integrity stuff // only to people with appropriate permission, and only on admin requests // data is cached for one day (or until cache is cleared) $cge = \cms_utils::get_module(MOD_CGEXTENSIONS); $rec = \CGExtensions\internal\ModuleIntegrityTools::get_cached_status($this->GetName()); switch( $rec['status'] ) { case -1: // no checksum stuff // only display this once per day if( !\cge_utils::done_today('module_sig'.$this->GetName()) ) { $out = '<div class="cge_sig sig_error" title="'.$cge->Lang('info_vrfy_nodata').'"/>'; $out .= '<span>'.$rec['message'].'</span>'; $out .= '</div>'; $out .= '<div class="clearb"></div>'; echo $out; } break; case 0: // validation failed or some other error $out = '<div class="cge_sig sig_error" title="'.$cge->Lang('info_vrfy_failed').'"/>'; $out .= '<span>'.$rec['message'].'</span>'; $out .= '</div>'; $out .= '<div class="clearb"></div>'; echo $out; break; case 1: // it is all good, display the module signature. $out = '<div class="cge_sig" title="'.$cge->Lang('info_vrfy_signature').'"/>'; $out .= $cge->Lang('module_signature').':'; $out .= '<span>'.$rec['checksum'].'</span>'; $out .= '</div>'; $out .= '<div class="clearb"></div>'; echo $out; break; } } */ // redundant for cmsms 2.0 $smarty = null; if (version_compare(CMS_VERSION, '2.0.1') < 0) { $smarty = Smarty_CMS::get_instance(); } else { $smarty = $this->GetActionTemplateObject(); } $smarty->assign('actionid', $id); $smarty->assign('actionparams', $params); $smarty->assign('returnid', $returnid); $smarty->assign('mod', $this); $smarty->assign($this->GetName(), $this); cge_tmpdata::set('module', $this->GetName()); if ($returnid == '') { // admin action if (isset($params['cg_activetab'])) { $this->_current_tab = trim($params['cg_activetab']); unset($params['cg_activetab']); } if (isset($params['cg_error'])) { $this->_errormsg = explode(':err:', $params['cg_error']); unset($params['cg_error']); } if (isset($params['cg_message'])) { $this->_messages = explode(':msg:', $params['cg_message']); unset($params['cg_message']); } $this->DisplayErrors(); $this->DisplayMessages(); } parent::DoAction($name, $id, $params, $returnid); }
protected function fetch($name, &$source, &$mtime) { if (is_sitedown() && cmsms()->is_frontend_request()) { $source = ''; $mtime = time(); if ($this->_section == 'body') { header('HTTP/1.0 503 Service Unavailable'); header('Status: 503 Service Unavailable'); $source = get_site_preference('sitedownmessage'); } return; } if ($name == 'notemplate') { $source = '{content}'; $mtime = time(); // never cache... return; } else { if (startswith($name, 'appdata;')) { $name = substr($name, 8); $source = cms_utils::get_app_data($name); $mtime = time(); return; } } $source = ''; $mtime = null; $tpl = $this->get_template($name); if (!is_object($tpl)) { return; } // Get section, do magic. switch ($this->_section) { case 'top': $mtime = $tpl->modified_date; $pos1 = stripos($tpl->content, '<head'); $pos2 = stripos($tpl->content, '<header'); if ($pos1 === FALSE || $pos1 == $pos2) { return; } $source = substr($tpl->content, 0, $pos1); return; case 'head': $mtime = $tpl->modified_date; $pos1 = stripos($tpl->content, '<head'); $pos1a = stripos($tpl->content, '<header'); $pos2 = stripos($tpl->content, '</head>'); if ($pos1 === FALSE || $pos1 == $pos1a || $pos2 === FALSE) { return; } $source = substr($tpl->content, $pos1, $pos2 - $pos1 + 7); return; case 'body': $mtime = $tpl->modified_date; $pos = stripos($tpl->content, '</head>'); if ($pos !== FALSE) { $source = substr($tpl->content, $pos + 7); } else { $source = $tpl->content; } return; default: $source = $tpl->content; $mtime = $tpl->modified_date; return; } }
/** * A function to call a module as a smarty plugin * This method is used by the {cms_module} plugin, and internally when {ModuleName} is called * * @internal * @access private * @param array A hash of parameters * @param object The smarty object * @return string The module output */ function cms_module_plugin($params, &$template) { $smarty = $template->smarty; $mid_cache = cms_utils::get_app_data('mid_cache'); if (empty($mid_cache)) { $mid_cache = array(); } for ($i = 0; $i < 10; $i++) { $tmp = $i; foreach ($params as $key => $value) { $tmp .= $key . '=' . $value; } $id = 'm' . substr(md5($tmp), 0, 5); if (!isset($mid_cache[$id])) { $mid_cache[$id] = $id; break; } } cms_utils::set_app_data('mid_cache', $mid_cache); $returnid = ''; $content_obj = cmsms()->get_variable('content_obj'); if (isset($content_obj) && $content_obj->Id()) { $returnid = $content_obj->Id(); } //$params = array_merge($params, GetModuleParameters($id)); $modulename = ''; $action = 'default'; $inline = false; $checkid = ''; if (isset($params['module'])) { $modulename = $params['module']; } else { return '<!-- ERROR: module name not specified -->'; } if (isset($params['idprefix'])) { $id = trim($params['idprefix']); } if (isset($params['action']) && $params['action'] != '') { // action was set in the module tag $action = $params['action']; } if (isset($_REQUEST['id'])) { $checkid = $_REQUEST['id']; } else { if (isset($_REQUEST['mact'])) { // we're handling an action $ary = explode(',', cms_htmlentities($_REQUEST['mact']), 4); $mactmodulename = isset($ary[0]) ? $ary[0] : ''; if (!strcasecmp($mactmodulename, $params['module'])) { $checkid = isset($ary[1]) ? $ary[1] : ''; $mactaction = isset($ary[2]) ? $ary[2] : ''; } $mactinline = isset($ary[3]) && $ary[3] == 1 ? true : false; if ($checkid == $id) { // the action is for this instance of the module $inline = $mactinline; if ($inline == true) { // and we're inline (the results are supposed to replace // the tag, not {content} $action = $mactaction; $params = array_merge($params, GetModuleParameters($id)); } } } } if ($action == '') { $action = 'default'; } // probably not needed, but safe class_exists($modulename); $module = cms_utils::get_module($modulename); if ($module && $module->isPluginModule()) { @ob_start(); $result = $module->DoActionBase($action, $id, $params, $returnid); if ($result !== FALSE) { echo $result; } $modresult = @ob_get_contents(); @ob_end_clean(); if (isset($params['assign'])) { $smarty->assign(trim($params['assign']), $modresult); return; } return $modresult; } else { return "<!-- {$modulename} is not a plugin module -->\n"; } }
public static function cge_module_hint($params, $smarty) { if (!isset($params['module'])) { return; } $module = trim($params['module']); $modobj = cms_utils::get_module($module); if (!is_object($modobj)) { return; } $data = cms_utils::get_app_data('__MODULE_HINT__' . $module); if (!$data) { $data = array(); } // warning, no check here if the module understands the parameter. foreach ($params as $key => $value) { if ($key == 'module') { continue; } $data[$key] = $value; } cms_utils::set_app_data('__MODULE_HINT__' . $module, $data); }
/** * Generate dynamic config file * * @since 1.0 * @param boolean Frontend true/false * @param string Templateid * @param string A2 Languageid * @return string */ public static function GenerateConfig($frontend = false, $templateid = "", $languageid = "en") { $mod = cms_utils::get_module('MicroTiny'); // Check if we are in object instance if (!is_object($mod)) { return false; } // TODO: return static file if this fails, or something // Init $config = cms_utils::get_config(); $result = ""; $linker = ""; if ($frontend) { $mod->smarty->assign("isfrontend", true); } else { $mod->smarty->assign("isfrontend", false); $result .= self::GetCMSLinker(); $linker = "cmslinker,"; } if (count(self::$_textareas)) { $tmp = implode(',', self::$_textareas); self::$_textareas = array(); $mod->smarty->assign('textareas', $tmp); } if ($templateid <= 0) { $pageinfo = cmsms()->get_variable('pageinfo'); if (is_object($pageinfo)) { $templateid = $pageinfo->template_id; } else { $contentobj = cms_utils::get_app_data('editing_content'); if (is_object($contentobj)) { $templateid = $contentobj->TemplateId(); } else { $templateops = cmsms()->GetTemplateOperations(); $dflt_template = $templateops->LoadDefaultTemplate(); if (is_object($dflt_template)) { $templateid = $dflt_template->id; } } } } if ($templateid > 0) { $mod->smarty->assign('templateid', $templateid); } $urlext = ""; if (isset($_SESSION[CMS_USER_KEY])) { $urlext = CMS_SECURE_PARAM_NAME . '=' . $_SESSION[CMS_USER_KEY]; } $mod->smarty->assign("urlext", $urlext); //,pasteword,,|,undo,redo $image = ""; if ($mod->GetPreference("allowimages", 0) && !$frontend) { $image = ",image,|"; } $toolbar = "undo,|,bold,italic,underline,|,cut,copy,paste,pastetext,removeformat,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,|," . $linker . "link,unlink,|" . $image . ",formatselect"; //,separator,styleselect // handle css styles... newline OR comma separated (why, kinda dumb?) $tmp = $mod->GetPreference('css_styles'); $tmp = str_replace("\r\n", "\n", $tmp); $tmp = explode("\n", $tmp); $tmp2 = array(); foreach ($tmp as $one) { $one = trim($one); if (empty($one)) { continue; } $tmp3 = explode(',', $one); foreach ($tmp3 as $one2) { $tmp2[] = trim($one2); } } $tmp3 = array(); foreach ($tmp2 as $one) { $tmp4 = explode('=', trim($one), 2); if (count($tmp4) == 1) { $tmp3[$tmp4[0]] = $tmp4[0]; } else { $tmp3[$tmp4[0]] = $tmp4[1]; } } $css_styles = ''; foreach ($tmp3 as $key => $value) { $css_styles .= $key . '=' . $value . ';'; } $css_styles = substr($css_styles, 0, -1); if ($css_styles != '') { $toolbar .= ",separator,styleselect"; $mod->smarty->assign("css_styles", $css_styles); } // give the rest to smarty. $mod->smarty->assign('show_statusbar', $mod->GetPreference('show_statusbar', 0)); $mod->smarty->assign('allow_resize', $mod->GetPreference('allow_resize', 0)); $mod->smarty->assign('strip_background', $mod->GetPreference('strip_background', 1)); $mod->smarty->assign('force_blackonwhite', $mod->GetPreference('force_blackonwhite', 0)); $mod->smarty->assign("toolbar", $toolbar); $mod->smarty->assign("language", $languageid); $mod->smarty->assign("filepickertitle", $mod->Lang("filepickertitle")); $fpurl = $mod->create_url("", "filepicker"); $fpurl = str_replace("&", "&", $fpurl); $mod->smarty->assign("filepickerurl", $fpurl); $result .= $mod->ProcessTemplate('microtinyconfig.tpl'); return $result; }
function GetFieldInput($id, &$params, $returnid) { $gCms = cmsms(); $mod = $this->form_ptr->module_ptr; $cataloger = $mod->GetModuleInstance('Cataloger'); if (!$cataloger) { return $mod->Lang('error_cataloger_module_not_available'); } $tmp_attrs = $this->_get_cataloger_attribute_fields(); $lines = (int) $this->GetOption('lines', '5'); $nameregex = trim($this->GetOption('nameregex', '')); $tmp_attrs = array(); foreach ($tmp_attrs as $one) { $safeattr = strtolower(preg_replace('/\\W/', '', $one->attr)); $val = trim($this->GetOption('attr_' . $safeattr, '')); if (empty($val)) { continue; } $one->input = $val; $attrs[] = $one; } // put the hidden fields into smarty. $smarty_vars_set = cms_utils::get_app_data('fb_smarty_vars_set'); if (!empty($smarty_vars_set)) { $smarty = cmsms()->GetSmarty(); if (!$smarty) { return; } $theFields = $this->form_ptr->GetFields(); for ($i = 0; $i < count($theFields); $i++) { if ($theFields[$i]->GetFieldType() != 'HiddenField') { continue; } $smarty->assign('fld_' . $theFields[$i]->GetId(), $theFields[$i]->Value); if ($theFields[$i]->GetAlias() != '') { $smarty->assign($theFields[$i]->GetAlias(), $theFields[$i]->Value); } } cms_utils::set_app_data('fb_smarty_vars_set', 1); } // for each hierarchy item (from the root down) $hm = $gCms->GetHierarchyManager(); $allcontent = $hm->getFlatList(); $results = array(); foreach ($allcontent as $onepage) { $content = $onepage->GetContent(); // if it's not a cataloger item continue if ($content->Type() != 'catalogitem') { continue; } // if it's not active or shown in menu continue if (!$content->Active() || !$content->ShowInMenu()) { continue; } // if the nameregex string is not empty, and the name does not match the // regex, continue if (!empty($nameregex) && !preg_match('/' . $nameregex . '/', $content->Name())) { continue; } // for each attribute $passed = true; $attrs = array(); foreach ($attrs as $oneattr) { // parse the field value through smarty? $expr = $mod->ProcessTemplateFromData($oneattr->input); if (empty($expr)) { continue; } // no expression for this field. pass // get the value for this attribute for this content $currentval = $content->GetPropertyValue($oneattr->attr); if (empty($currentval)) { // no value for this field, but we have an expression // this catalog item fails. $passed = false; break; } list($type, $expr) = explode(':', $expr, 2); $type = trim($type); $expr = trim($expr); $res = false; switch (strtolower($type)) { case 'range': // for ranges: // grab min and max values list($minval, $maxval) = explode('to', $expr); $minval = trim($minval); $maxval = trim($maxval); // check for numeric if (!is_numeric($minval) || !is_numeric($maxval)) { // can't test ranges with non numeric values // so fail $passed = false; break; } if ($minval > $maxval) { $tmp = $minval; $minval = $maxval; $maxval = $tmp; } $res = $currentval >= $minval && $currentval <= $maxval; break; case 'multi': // for multi $tmp = explode('|', $expr); $res = in_array($currentval, $tmp); break; } if (!$res) { $passed = false; break; } } // foreach attr if ($passed) { $results[$content->Name()] = $content->Name(); } } // foreach content // All done, do we have something to display? if (count($results)) { $size = min($lines, count($results)); $size = min(50, $size); // maximum 50 lines, though this is probably big $val = array(); if ($this->Value !== false) { $val = $this->Value; if (!is_array($this->Value)) { $val = array($this->Value); } } $cssid = $this->GetCSSIdTag(); return $mod->CreateInputSelectList($id, 'fbrp__' . $this->Id . '[]', $results, $val, $size, $cssid); } return ''; // error }
/** * Loads a set of content objects into the cached tree. * * @param boolean $loadprops If true, load the properties of those content objects * @param boolean $onlyexpanded Not implemented * @param boolean $loadcontent If false, only create the nodes in the tree, * don't load the content objects * @return mixed The cached tree of content */ function &GetAllContentAsHierarchy($loadcontent = false) { debug_buffer('', 'starting tree'); $gCms = cmsms(); $db = $gCms->GetDb(); $tree = null; $cachefilename = TMP_CACHE_LOCATION . '/contentcache.php'; $loadedcache = false; if (file_exists($cachefilename)) { $last_modified = cms_utils::get_app_data('last_content_modification'); if (!$last_modified) { } $query = 'SELECT modified_date FROM ' . cms_db_prefix() . 'content ORDER BY modified_date DESC'; $val = $db->GetOne($query); $last_modified = $db->UnixTimeStamp($val); cms_utils::set_app_data('last_content_modification', $last_modified); if ($last_modified > 0 && $last_modified < filemtime($cachefilename)) { debug_buffer('file needs loading'); $handle = fopen($cachefilename, "r"); $data = fread($handle, filesize($cachefilename)); fclose($handle); $tree = unserialize(substr($data, 16)); if (strtolower(get_class($tree)) == 'cms_content_tree') { $loadedcache = true; } else { die('problem loading cache'); $loadedcache = false; } } } if (!$loadedcache) { $query = "SELECT id_hierarchy,content_alias FROM " . cms_db_prefix() . "content ORDER BY hierarchy"; $dbresult = $db->Execute($query); $nodes = array(); if ($dbresult && $dbresult->RecordCount() > 0) { while ($row = $dbresult->FetchRow()) { $nodes[] = $row['id_hierarchy'] . ',' . $row['content_alias']; } $dbresult->Close(); } debug_buffer('', 'Start Loading Children into Tree'); $tree = cms_tree_operations::load_from_list($nodes); debug_buffer('', 'End Loading Children into Tree'); } if (!$loadedcache) { debug_buffer("Serializing..."); @file_put_contents($cachefilename, '<?php return; ?>' . serialize($tree)); } if ($loadcontent) { $this->LoadChildren(-1, true, true); } debug_buffer('', 'ending tree'); return $tree; }
/** * A method to return the timestamp of a module database template * * @access private * @param string The name of the module template * @param int (returned) The file timestamp * @param object The smarty object * @return boolean */ function module_db_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj) { $db = cmsms()->GetDb(); $module_template_cache = cms_utils::get_app_data('module_template_cache'); if (isset($module_template_cache) && isset($module_template_cache[$tpl_name])) { $tpl_timestamp = $module_template_cache[$tpl_name]; return true; } $query = "SELECT module_name,template_name,modified_date \n FROM " . cms_db_prefix() . "module_templates"; $results = $db->GetArray($query); if (!count($results)) { return false; } if (empty($module_template_cache)) { $module_template_cache = array(); } foreach ($results as $row) { $key = $row['module_name'] . ';' . $row['template_name']; $val = $db->UnixTimeStamp($row['modified_date']); $module_template_cache[$key] = $val; } $tpl_timestamp = $module_template_cache[$tpl_name]; cms_utils::set_app_data('module_template_cache', $module_template_cache); return true; }
/** * Return a translated string for the default 'admin' realm. * This function is merely a wrapper around the lang_by_realm function * that assumes the realm is 'admin'. * * This method will throw a notice if it is called from a frontend request * * @param string The key to translate * @return string */ function lang() { // uses the default admin realm. $gCms = cmsms(); $nls =& $gCms->nls; $dir = cms_join_path($gCms->config['root_path'], $gCms->config['admin_dir'], 'lang'); $customdir = cms_join_path($gCms->config['root_path'], $gCms->config['admin_dir'], 'custom', 'lang'); cms_load_lang_realm('admin', $dir, 'admin.inc.php', 1, 1); cms_load_lang_realm('admin', $customdir, 'admin.inc.php', 1, 1, 1); $name = ''; $params = array(); $realm = 'admin'; if (func_num_args() > 0) { $name = func_get_arg(0); if (func_num_args() == 2 && is_array(func_get_arg(1))) { $params = func_get_arg(1); } else { if (func_num_args() > 1) { $params = array_slice(func_get_args(), 1); } } } else { return ''; } // quick test to see if we are on the frontend or admin. global $CMS_ADMIN_PAGE; global $CMS_STYLESHEET; global $CMS_INSTALL_PAGE; $flag = cms_utils::get_app_data('__allow_admin_realm__'); if (!isset($CMS_ADMIN_PAGE) && !isset($CMS_STYLESHEET) && !isset($CMS_INSTALL_PAGE) && !$flag) { trigger_error('Attempt to load admin realm from non admin action'); return ''; } // todo: return lang_by_realm($name, 'admin', $params); }