function cms_autoloader($classname) { //if( $classname != 'Smarty_CMS' && $classname != 'Smarty_Parser' && startswith($classname,'Smarty') ) return; $config = cmsms()->GetConfig(); // standard classes $fn = cms_join_path($config['root_path'], 'lib', 'classes', "class.{$classname}.php"); if (file_exists($fn)) { __cms_load($fn); return; } $lowercase = strtolower($classname); $fn = cms_join_path($config['root_path'], 'lib', 'classes', "class.{$lowercase}.inc.php"); if (file_exists($fn) && $classname != 'Content') { __cms_load($fn); return; } // standard interfaces $fn = cms_join_path($config['root_path'], 'lib', 'classes', "interface.{$classname}.php"); if (file_exists($fn)) { __cms_load($fn); return; } global $CMS_LAZYLOAD_MODULES; global $CMS_INSTALL_PAGE; if (!isset($CMS_LAZYLOAD_MODULES) || isset($CMS_INSTALL_PAGE)) { return; } // standard content types $fn = cms_join_path($config['root_path'], 'lib', 'classes', 'contenttypes', "{$classname}.inc.php"); if (file_exists($fn)) { __cms_load($fn); return; } // module loaded content types $contentops = ContentOperations::get_instance(); if ($contentops) { // why would this ever NOT be true.. dunno, but hey. $types = $contentops->ListContentTypes(); if (in_array(strtolower($classname), array_keys($types))) { $contentops->LoadContentType(strtolower($classname)); return; } } $fn = $config['root_path'] . "/modules/{$classname}/{$classname}.module.php"; if (file_exists($fn)) { __cms_load($fn); return; } $list = ModuleOperations::get_instance()->GetLoadedModules(); if (is_array($list) && count($list)) { foreach (array_keys($list) as $modname) { $fn = $config['root_path'] . "/modules/{$modname}/lib/class.{$classname}.php"; if (file_exists($fn)) { __cms_load($fn); return; } } } // module classes }
public static function &get_instance() { if (!is_object(self::$_instance)) { self::$_instance = new ContentOperations(); } return self::$_instance; }
private function _get_returnid() { if (!isset($this->_meta['returnid'])) { $mod = cms_utils::get_module('News'); $tmp = $mod->GetPreference('detail_returnid', -1); if ($tmp <= 0) { $tmp = ContentOperations::get_instance()->GetDefaultContent(); } $this->_meta['returnid'] = $tmp; } return $this->_meta['returnid']; }
/** * Get a list of matching records. * This method returns an array of hashes. Each row in the resultset * will have val,title,label,selected,disabled members. * * A consumer of this output can then parse these records and build a * suitable option list for a dropdown. * * @see content_list_builder::get_options() * @return array */ public function get_content_list() { // initialize our start level $root = $tree = cmsms()->GetHierarchyManager(); $this->_start_level = 0; if ($this->parent > 0) { $tree = $root->find_by_tag('id', $this->parent); if (!$tree) { throw new \CmsInvalidDataException('Page with id ' . $this->parent . ' not found'); } $this->_start_level = $tree->get_level() + 1; } // now that we have our paramters, start building our tree. $out = array(); $allcontent = \ContentOperations::get_instance()->GetAllContent(FALSE); $out = array(); if (!$tree->has_children()) { return; } $children = $tree->get_children(); foreach ($children as $child) { $this->_walk_nodes($child, $out); } if (!count($out)) { return; } return $out; }
/** * Get a handle to the CMS ContentOperations object. If it does not yet * exist, this method will instantiate it. To disambiguate, this is a globally-available * object with methods for dealing with Content -- it should not to be confused with * the GlobalContentOperations object. * * @final * @see ContentOperations * @return ContentOperations handle to the ContentOperations object */ public function &GetContentOperations() { return ContentOperations::get_instance(); }
/** * A convenience function to create a url to a certain CMS page * * @param mixed $pageid A frontend page id or alias. * @return string */ function CreateContentURL($pageid) { die('this is still used'); $config = cms_config::get_instance(); $contentops = ContentOperations::get_instance(); $alias = $contentops->GetPageAliasFromID($pageid); $text = ''; if ($config["assume_mod_rewrite"]) { // mod_rewrite if ($alias == false) { return '<!-- ERROR: could not get an alias for pageid=' . $pageid . '-->'; } else { $text .= $config["root_url"] . "/" . $alias . (isset($config['page_extension']) ? $config['page_extension'] : '.shtml'); } } else { $text .= $config["root_url"] . "/index.php?" . $config["query_var"] . "=" . $pageid; return $text; } }
} // outer if !$error } else { if (isset($params['preview'])) { // save data for preview. unset($params['apply']); unset($params['preview']); unset($params['submit']); unset($params['cancel']); unset($params['ajsx']); $tmpfname = tempnam(TMP_CACHE_LOCATION, $this->GetName() . '_preview'); file_put_contents($tmpfname, serialize($params)); $detail_returnid = $this->GetPreference('detail_returnid', -1); if ($detail_returnid <= 0) { // now get the default content id. $detail_returnid = ContentOperations::get_instance()->GetDefaultContent(); } if (isset($params['previewpage']) && (int) $params['previewpage'] > 0) { $detail_returnid = (int) $params['previewpage']; } $_SESSION['news_preview'] = array('fname' => basename($tmpfname), 'checksum' => md5_file($tmpfname)); $tparms = array('preview' => md5(serialize($_SESSION['news_preview']))); if (isset($params['detailtemplate'])) { $tparms['detailtemplate'] = trim($params['detailtemplate']); } $url = $this->create_url('_preview_', 'detail', $detail_returnid, $tparms, TRUE); $response = '<?xml version="1.0"?>'; $response .= '<EditArticle>'; if (isset($error) && $error != '') { $response .= '<Response>Error</Response>'; $response .= '<Details><![CDATA[' . $error . ']]></Details>';
/** * Save or update the content * * @todo This function should return something (or throw an exception) */ function Save() { Events::SendEvent('Core', 'ContentEditPre', array('content' => &$this)); if (!is_array($this->_props)) { debug_buffer('save is loading properties'); $this->_load_properties(); } if (-1 < $this->mId) { $this->Update(); } else { $this->Insert(); } $contentops = ContentOperations::get_instance()->SetAllHierarchyPositions(); Events::SendEvent('Core', 'ContentEditPost', array('content' => &$this)); }
/** * Returns the content id given a valid hierarchical position. * * @param string $position The position to query * @return integer The resulting id. false if not found. */ function GetPageIDFromHierarchy($position) { global $gCms; $db =& $gCms->GetDb(); $query = "SELECT content_id FROM " . cms_db_prefix() . "content WHERE hierarchy = ?"; $row = $db->GetRow($query, array(ContentOperations::CreateUnfriendlyHierarchyPosition($position))); if (!$row) { return false; } return $row['content_id']; }
public static function get_sibling($dir, $assign = '', $alias = '') { $gCms = CmsApp::get_instance(); $smarty = $gCms->GetSmarty(); $contentops = ContentOperations::get_instance(); if (empty($alias)) { $alias = $smarty->get_template_vars('page_alias'); } // @todo: could use the tree here (find the node, get it's parent, the parent's childs are the sibling) $content = $contentops->LoadContentFromAlias($alias); if (!is_object($content)) { return false; } // get the last item out of the hierarchy // and rebuild $query = 'SELECT content_alias FROM ' . cms_db_prefix() . 'content WHERE parent_id = ? AND item_order %s ? AND active = 1 ORDER BY item_order %s LIMIT 1'; switch (strtolower($dir)) { case '-1': case 'prev': $thechar = '<'; $order = 'DESC'; break; default: $thechar = '>'; $order = 'ASC'; break; } $db = $gCms->GetDb(); $res = $db->GetOne(sprintf($query, $thechar, $order), array($content->ParentId(), $content->ItemOrder())); if (!empty($assign)) { $smarty->assign(trim($assign), $res); return; } return $res; }
/** * Get a link definition for the provided dataref. * * @return LinkDefinition */ public function get_linkdefinition() { if (!is_a($this->_dataref, '\\CGExtensions\\LinkDefinition\\DataRef')) { throw new \RuntimeException('Data passed to ' . __CLASS__ . ' is not a DataRef'); } $key2 = $this->_dataref->key2; $key3 = $this->_dataref->key3; if ((int) $key2 > 0) { $key3 = $key2; $key2 = 'page'; } switch (strtolower($key2)) { case 'page': // get the content object specified by key3 $key3 = (int) $key3; if ($key3 < 1) { throw new \RuntimeException('Invalid Core DataRef key3 does not represent a valid page id'); } $content = \ContentOperations::get_instance()->LoadContentFromId($key3); if (!is_object($content)) { throw new \RuntimeException('Could not find content object specified in DataRef object'); } // now, if this is a frontend request, obviously we should just export the proper URL for this content object if (cmsms()->is_frontend_request()) { if (!$content->HasUsableLink()) { throw new \RuntimeException('Cannot create a LinkDefinition to a content type that has no usable link'); } if (!$content->Active()) { throw new \RuntimeException('Cannot create a LinkDefinition to a content page that is inactive'); } $linkdefn = new LinkDefinition(); $linkdefn->href = $content->GetURL(); $linkdefn->text = $content->Name(); $linkdefn->title = $content->TitleAttribute(); return $linkdefn; } else { // if it is an admin request we do not need to check if the page is active, or has a usable link // but we may need to know if the apge is editable by this user (do this later) if (version_compare(CMS_VERSION, '1.99') < 0) { // 1.x uses admin/editcontent.php?content_id=## $config = cmsms()->GetConfig(); $linkdefn = new LinkDefn(); $linkdefn->href = $config['admin_url'] . '/editcontent.php?content_id=' . $content->Id(); $linkdefn->text = $content->GetName(); return $linkdefn; } else { // 2.x uses CmsContentManager, there is no abstracted method to get the edit url. // so we get the content manager module // and us it's create url method with the admin_editcontent action, and a content_id param $mod = \cms_utils::get_module('CMSContentManager'); $linkdefn = new LinkDefn(); $linkdefn->href = $mod->create_url('m1_', 'admin_editcontent', '', array('content_id' => $key3)); $linkedfn->text = $content->GetName(); return $linkdefn; } } break; case 'stylesheet': case 'template': stack_trace(); die('incomplete'); break; default: throw new \RuntimeException(__CLASS__ . ' does not know how to handle core datarefs where key2 is ' . $key2); break; } }