Пример #1
0
 /**
  * @ignore
  */
 public function __get($key)
 {
     $key = strtolower($key);
     switch ($key) {
         case 'name':
         case 'callback':
         case 'depends':
         case 'jsfile':
         case 'cssfile':
         case 'jsurl':
         case 'cssurl':
         case 'module':
         case 'js_nominify':
         case 'css_nominify':
             if (isset($this->_data[$key])) {
                 return $this->_data[$key];
             }
             break;
         case 'minify_js':
             return !$this->js_nominify;
         case 'minify_css':
             return !$this->css_nominify;
         default:
             stack_trace();
             die;
             throw new \CmsInvalidDataException($key . ' is not a valid member of a ' . __CLASS__ . ' object');
     }
 }
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# Or read it online: http://www.gnu.org/licenses/licenses.html#GPL
#
#-------------------------------------------------------------------------
#END_LICENSE
$this->CheckPermission('Modify Templates');
//Don't actually care.  Just force a login.
if (!isset($params['destmodule'])) {
    stack_trace();
    die('<br/>Destination module not set');
}
$module =& $this->GetModuleInstance($params['destmodule']);
if (!is_object($module)) {
    stack_trace();
    die('<br/>Could not find destination module');
}
if (isset($params['resettodefault']) && isset($params['prefname']) && isset($params['filename'])) {
    $fn = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . $module->GetName() . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $params['filename'];
    if (file_exists($fn)) {
        $template = @file_get_contents($fn);
        $module->SetTemplate($params['prefname'], $template);
        $module->RemovePreference($params['prefname']);
        // clear old cruft.
        audit('', $module->GetName(), 'Reset the default template for ' . $params['prefname']);
    }
} else {
    if (isset($params['submit']) && isset($params['prefname'])) {
        $module->SetTemplate($params['prefname'], $params['input_template']);
        $module->RemovePreference($params['prefname']);
Пример #3
0
 /**
  * A method to display a single input element for an object basic, or extended property.
  *
  * @abstract
  * @param string The property name
  * @param boolean Wether or not we are in add or edit mode.
  * @return array consisting of two elements.  A label, and the input element.
  */
 protected function display_single_element($one, $adding)
 {
     $gCms = cmsms();
     $config = $gCms->GetConfig();
     switch ($one) {
         case 'cachable':
             return array('<label for="in_cachable">' . lang('cachable') . ':</label>', '<input type="hidden" name="cachable" value="0"/><input id="in_cachable" class="pagecheckbox" type="checkbox" value="1" name="cachable"' . ($this->mCachable ? ' checked="checked"' : '') . ' />', lang('help_page_cachable'));
             break;
         case 'title':
             return array('<label for="in_title">*' . lang('title') . '</label>:', '<input type="text" id="in_title" name="title" value="' . cms_htmlentities($this->mName) . '" />');
             break;
         case 'menutext':
             return array('<label for="in_menutext">*' . lang('menutext') . '</label>:', '<input type="text" name="menutext" id="in_menutext" value="' . cms_htmlentities($this->mMenuText) . '" />');
             break;
         case 'parent':
             $contentops = $gCms->GetContentOperations();
             $tmp = $contentops->CreateHierarchyDropdown($this->mId, $this->mParentId, 'parent_id', 0, 1, 0, 1, get_site_preference('listcontent_showtitle', true));
             if (empty($tmp) && !check_permission(get_userid(), 'Manage All Content')) {
                 return array('', '<input type="hidden" name="parent_id" value="' . $this->mParentId . '" />');
             }
             if (!empty($tmp)) {
                 return array('<label for="parent_id">' . lang('parent') . '</label>:', $tmp);
             }
             break;
         case 'active':
             if (!$this->DefaultContent()) {
                 return array('<label for="id_active">' . lang('active') . '</label>:', '<input type="hidden" name="active" value="0"/><input class="pagecheckbox" type="checkbox" name="active" id="id_active" value="1"' . ($this->mActive ? ' checked="checked"' : '') . ' />');
             }
             break;
         case 'showinmenu':
             return array('<label for="showinmenu">' . lang('showinmenu') . '</label>:', '<input type="hidden" name="showinmenu" value="0"/><input class="pagecheckbox" type="checkbox" value="1" name="showinmenu" id="showinmenu"' . ($this->mShowInMenu ? ' checked="checked"' : '') . ' />');
             break;
         case 'target':
             $text = '<option value="---">' . lang('none') . '</option>';
             $text .= '<option value="_blank"' . ($this->GetPropertyValue('target') == '_blank' ? ' selected="selected"' : '') . '>_blank</option>';
             $text .= '<option value="_parent"' . ($this->GetPropertyValue('target') == '_parent' ? ' selected="selected"' : '') . '>_parent</option>';
             $text .= '<option value="_self"' . ($this->GetPropertyValue('target') == '_self' ? ' selected="selected"' : '') . '>_self</option>';
             $text .= '<option value="_top"' . ($this->GetPropertyValue('target') == '_top' ? ' selected="selected"' : '') . '>_top</option>';
             return array('<label for="target">' . lang('target') . '</label>:', '<select name="target" id="target">' . $text . '</select>', lang('info_target'));
             break;
         case 'alias':
             return array('<label for="alias">' . lang('pagealias') . '</label>:', '<input type="text" name="alias" id="alias" value="' . $this->mAlias . '" />', lang('help_page_alias'));
             break;
         case 'secure':
             $opt = '';
             if ($this->mSecure) {
                 $opt = ' checked="checked"';
             }
             $str = '<input type="hidden" name="secure" value="0"/>';
             $str .= '<input type="checkbox" name="secure" id="secure" value="1"' . $opt . '/>';
             return array('<label for="secure">' . lang('secure_page') . '</label>:', $str);
             break;
         case 'page_url':
             if (!$this->DefaultContent()) {
                 $str = '<input type="text" name="page_url" id="page_url" value="' . $this->mURL . '" size="50" maxlength="255"/>';
                 $prompt = '<label for="page_url">' . lang('page_url') . '</label>:';
                 if (get_site_preference('content_mandatory_urls', 0)) {
                     $prompt = '*' . $prompt;
                 }
                 return array($prompt, $str, lang('help_page_url'));
             }
             break;
         case 'image':
             $dir = cms_join_path($config['image_uploads_path'], get_site_preference('content_imagefield_path'));
             $data = $this->GetPropertyValue('image');
             $dropdown = create_file_dropdown('image', $dir, $data, 'jpg,jpeg,png,gif', '', true, '', 'thumb_', 1, 1);
             if (!$dropdown) {
                 return;
             }
             return array('<label for="image">' . lang('image') . '</label>:', $dropdown);
             break;
         case 'thumbnail':
             $dir = cms_join_path($config['image_uploads_path'], get_site_preference('content_thumbnailfield_path'));
             $data = $this->GetPropertyValue('thumbnail');
             $dropdown = create_file_dropdown('thumbnail', $dir, $data, 'jpg,jpeg,png,gif', '', true, '', 'thumb_', 0, 1);
             if (!$dropdown) {
                 return FALSE;
             }
             return array('<label for="thumbnail">' . lang('thumbnail') . '</label>:', $dropdown);
             break;
         case 'titleattribute':
             return array('<label for="titleattribute">' . lang('titleattribute') . '</label>:', '<input type="text" name="titleattribute" id="titleattribute" maxlength="255" size="80" value="' . cms_htmlentities($this->mTitleAttribute) . '" />');
             break;
         case 'accesskey':
             return array('<label for="accesskey">' . lang('accesskey') . '</label>:', '<input type="text" name="accesskey" id="accesskey" maxlength="5" value="' . cms_htmlentities($this->mAccessKey) . '" />');
             break;
         case 'tabindex':
             return array('<label for="tabindex">' . lang('tabindex') . '</label>:', '<input type="text" name="tabindex" id="tabindex" maxlength="5" value="' . cms_htmlentities($this->mTabIndex) . '" />');
             break;
         case 'extra1':
             return array('<label for="extra1">' . lang('extra1') . '</label>:', '<input type="text" name="extra1" id="extra1" maxlength="255" size="80" value="' . cms_htmlentities($this->GetPropertyValue('extra1')) . '" />');
             break;
         case 'extra2':
             return array('<label for="extra2">' . lang('extra2') . '</label>:', '<input type="text" name="extra2" id="extra2" maxlength="255" size="80" value="' . cms_htmlentities($this->GetPropertyValue('extra2')) . '" />');
             break;
         case 'extra3':
             return array('<label for="extra3">' . lang('extra3') . '</label>:', '<input type="text" name="extra3" id="extra3" maxlength="255" size="80" value="' . cms_htmlentities($this->GetPropertyValue('extra3')) . '" />');
             break;
         case 'owner':
             $showadmin = check_ownership(get_userid(), $this->Id());
             $userops = $gCms->GetUserOperations();
             if (!$adding && ($showadmin || check_permission(get_userid(), 'Manage All Content'))) {
                 return array('<label for="owner">' . lang('owner') . '</label>:', $userops->GenerateDropdown($this->Owner()));
             }
             break;
         case 'additionaleditors':
             // do owner/additional-editor stuff
             if ($adding || check_ownership(get_userid(), $this->Id()) || check_permission(get_userid(), 'Manage All Content')) {
                 return $this->ShowAdditionalEditors();
             }
             break;
         default:
             stack_trace();
             die('unknown property ' . $one);
     }
 }
Пример #4
0
 /**
  * Find a tree node given a specfied tag and value.
  *
  * @param string The tag name to search for
  * @param mixed  The tag value to search for
  * @return cms_tree or null on failure.
  */
 public function find_by_tag($tag_name, $value, $case_insensitive = false)
 {
     if ($this->_tags) {
         if ($case_insensitive) {
             if (isset($this->_tags[$tag_name]) && $this->_tags[$tag_name] == $value) {
                 return $this;
             }
         } else {
             if (is_object($this->_tags[$tag_name])) {
                 stack_trace();
                 die;
             }
             if (isset($this->_tags[$tag_name]) && strtolower($this->_tags[$tag_name]) == strtolower($value)) {
                 return $this;
             }
         }
     }
     if ($this->has_children()) {
         for ($i = 0; $i < count($this->_children); $i++) {
             $tmp = $this->_children[$i]->find_by_tag($tag_name, $value);
             if ($tmp) {
                 return $tmp;
             }
         }
     }
     $res = null;
     return $res;
 }
Пример #5
0
 public function offsetGet($key)
 {
     // hardcoded config vars
     // usually old values valid in past versions.
     switch ($key) {
         case 'use_adodb_lite':
         case 'use_hierarchy':
             // deprecated, backwards compat only
             return TRUE;
         case 'use_smarty_php_tags':
         case 'output_compression':
             // deprecated, backwards compat only
             return FALSE;
         case 'default_upload_permission':
             // deprecated, backwards compat only
             return '664';
         case 'assume_mod_rewrite':
             // deprecated, backwards compat only
             return $this['url_rewriting'] == 'mod_rewrite' ? true : false;
         case 'internal_pretty_urls':
             // deprecated, backwards compat only
             return $this['url_rewriting'] == 'internal' ? true : false;
     }
     // from the config file.
     if (isset($this->_data[$key])) {
         return $this->_data[$key];
     }
     // cached, calculated values.
     if (isset($this->_cache[$key])) {
         // this saves recursion and dynamic calculations all the time.
         return $this->_cache[$key];
     }
     // it's not explicitly specified in the config file, or cached.
     switch ($key) {
         case 'dbms':
         case 'db_hostname':
         case 'db_username':
         case 'db_password':
         case 'db_name':
             // these guys have to be set
             stack_trace();
             die('FATAL ERROR: Could not find database connection key ' . $key . ' in the config file');
             break;
         case 'persist_db_conn':
             return false;
         case 'set_names':
             return true;
         case 'set_db_timezone':
             return FALSE;
         case 'root_path':
             $out = dirname(dirname(dirname(__FILE__)));
             $this->_cache[$key] = $out;
             return $out;
         case 'root_url':
             $parts = parse_url($_SERVER['PHP_SELF']);
             $path = '';
             if (!empty($parts['path'])) {
                 $path = dirname($parts['path']);
                 if (endswith($path, 'install')) {
                     $path = substr($path, 0, strlen($path) - strlen('install') - 1);
                 } else {
                     if (endswith($path, $this->offsetGet('admin_dir'))) {
                         $path = substr($path, 0, strlen($path) - strlen($this->offsetGet('admin_dir')) - 1);
                     } else {
                         if (strstr($path, '/lib') !== FALSE) {
                             while (strstr($path, '/lib') !== FALSE) {
                                 $path = dirname($path);
                             }
                         }
                     }
                 }
                 while (endswith($path, DIRECTORY_SEPARATOR)) {
                     $path = substr($path, 0, strlen($path) - 1);
                 }
                 if (($pos = strpos($path, '/index.php')) !== FALSE) {
                     $path = substr($path, 0, $pos);
                 }
             }
             $prefix = 'http://';
             if (cmsms()->is_https_request()) {
                 $prefix = 'https://';
             }
             $str = $prefix . $_SERVER['HTTP_HOST'] . $path;
             $this->_cache[$key] = $str;
             return $str;
             break;
         case 'ssl_url':
             $this->_cache[$key] = str_replace('http://', 'https://', $this->offsetGet('root_url'));
             return $this->_cache[$key];
         case 'uploads_path':
             $this->_cache[$key] = cms_join_path($this->offsetGet('root_path'), 'uploads');
             return $this->_cache[$key];
         case 'uploads_url':
             $this->_cache[$key] = $this->offsetGet('root_url') . '/uploads';
             return $this->_cache[$key];
         case 'ssl_uploads_url':
             $this->_cache[$key] = str_replace('http://', 'https://', $this->offsetGet('uploads_url'));
             return $this->_cache[$key];
         case 'image_uploads_path':
             $this->_cache[$key] = cms_join_path($this->offsetGet('uploads_path'), 'images');
             return $this->_cache[$key];
         case 'image_uploads_url':
             $this->_cache[$key] = $this->offsetGet('uploads_url') . '/images';
             return $this->_cache[$key];
         case 'ssl_image_uploads_url':
             $this->_cache[$key] = str_replace('http://', 'https://', $this->offsetGet('image_uploads_url'));
             return $this->_cache[$key];
         case 'previews_path':
             return TMP_CACHE_LOCATION;
         case 'admin_dir':
             return 'admin';
         case 'debug':
             return false;
         case 'timezone':
             return '';
         case 'db_port':
             return '';
         case 'max_upload_size':
         case 'upload_max_filesize':
             return $this->get_upload_size();
         case 'auto_alias_content':
             return true;
         case 'url_rewriting':
             return 'none';
         case 'page_extension':
             return '';
         case 'query_var':
             return 'page';
         case 'image_manipulation_prog':
             return 'GD';
         case 'image_transform_lib_path':
             return 'WIN' === strtoupper(substr(PHP_OS, 0, 3)) ? 'C:/Program Files/VisualMagick/bin/' : '/usr/bin/ImageMagick/';
         case 'locale':
             return '';
         case 'default_encoding':
         case 'admin_encoding':
             return 'utf-8';
         case 'admin_path':
             return cms_join_path($this->offsetGet('root_path'), $this->offsetGet('admin_dir'));
         case 'admin_url':
             return $this->offsetGet('root_url') . '/' . $this->offsetGet('admin_dir');
         case 'ignore_lazy_load':
             return false;
         case 'css_path':
             return TMP_CACHE_LOCATION . '/';
         case 'css_url':
             return $this->offsetGet('root_url') . '/tmp/cache/';
         case 'ssl_css_url':
             return $this->offsetGet('ssl_url') . '/tmp/cache/';
         default:
             // not a mandatory key for the config.php file... and one we don't understand.
             return null;
     }
 }
Пример #6
0
 /**
  * Wrapper for the trigger_error method
  *
  * @ignore
  * @access private
  * @param string The error message
  * @param int    The error type E_USER_WARNING or E_USER_NOTICE
  * @return void
  */
 function trigger_error($error_msg, $error_type = E_USER_WARNING)
 {
     stack_trace();
     var_dump("Smarty error: {$error_msg}");
 }
Пример #7
0
 public function offsetGet($key)
 {
     if (isset($this->_data[$key])) {
         return $this->_data[$key];
     }
     if (isset($this->_cache[$key])) {
         // this saves recursion and dynamic calculations all the time.
         return $this->_cache[$key];
     }
     // it's not explicitly specified in the config file.
     $calculated_root_path = dirname(dirname(dirname(__FILE__)));
     switch ($key) {
         case 'dbms':
         case 'db_hostname':
         case 'db_username':
         case 'db_password':
         case 'db_name':
             // these guys have to be set
             stack_trace();
             die('FATAL ERROR: Could not find database connection key ' . $key . ' in the config file');
             break;
         case 'use_adodb_lite':
             return true;
         case 'persist_db_conn':
             return false;
         case 'set_names':
             return true;
         case 'root_path':
             return dirname(dirname(dirname(__FILE__)));
         case 'root_url':
             $parts = parse_url($_SERVER['REQUEST_URI']);
             $path = '';
             if (!empty($parts['path'])) {
                 $path = dirname($parts['path']);
                 if (endswith($path, 'install')) {
                     $path = substr($path, 0, strlen($path) - strlen('install') - 1);
                 }
             }
             // todo: here we could get the default content object and test if it's secure
             $str = 'http://' . $_SERVER['HTTP_HOST'] . $path;
             return $str;
             break;
         case 'ssl_url':
             $this->_cache[$key] = str_replace('http://', 'https://', $this->offsetGet('root_url'));
             return $this->_cache[$key];
         case 'uploads_path':
             $this->_cache[$key] = cms_join_path($this->offsetGet('root_path'), 'uploads');
             return $this->_cache[$key];
         case 'uploads_url':
             $this->_cache[$key] = $this->offsetGet('root_url') . '/uploads';
             return $this->_cache[$key];
         case 'ssl_uploads_url':
             $this->_cache[$key] = str_replace('http://', 'https://', $this->offsetGet('uploads_url'));
             return $this->_cache[$key];
         case 'image_uploads_path':
             $this->_cache[$key] = cms_join_path($this->offsetGet('uploads_path'), 'images');
             return $this->_cache[$key];
         case 'image_uploads_url':
             $this->_cache[$key] = $this->offsetGet('uploads_url') . '/images';
             return $this->_cache[$key];
         case 'previews_path':
             return TMP_CACHE_LOCATION;
         case 'admin_dir':
             return 'admin';
         case 'debug':
             return false;
         case 'process_whole_template':
             return false;
         case 'output_compression':
             return false;
         case 'timezone':
             return '';
         case 'db_port':
             return '';
         case 'max_upload_size':
         case 'upload_max_filesize':
             return $this->get_upload_size();
         case 'default_upload_permission':
             return '664';
         case 'use_smarty_php_tags':
             return false;
         case 'auto_alias_content':
             return true;
         case 'url_rewriting':
             return 'none';
         case 'page_extension':
             return '';
         case 'query_var':
             return 'page';
         case 'image_manipulation_prog':
             return 'GD';
         case 'image_transform_lib_path':
             return 'WIN' === strtoupper(substr(PHP_OS, 0, 3)) ? 'C:/Program Files/VisualMagick/bin/' : '/usr/bin/ImageMagick/';
         case 'locale':
             return '';
         case 'default_encoding':
         case 'admin_encoding':
             return 'utf-8';
         case 'wiki_url':
             return 'http://wiki.cmsmadesimple.org/index.php/User_Handbook/Admin_Panel';
         case 'admin_url':
             return $this->offsetGet('root_url') . '/' . $this->offsetGet('admin_dir');
         case 'ignore_lazy_load':
             return false;
         default:
             // not a mandatory key for the config.php file... and one we don't understand.
             return null;
     }
 }
Пример #8
0
/**
 * 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.
    global $gCms;
    global $lang;
    global $nls;
    $dir = cms_join_path($gCms->config['root_path'], $gCms->config['admin_dir'], 'lang');
    if (!isset($lang['admin'])) {
        cms_load_lang_realm('admin', $dir, 'admin.inc.php', 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;
    if (!isset($CMS_ADMIN_PAGE) && !isset($CMS_STYLESHEET) && !isset($CMS_INSTALL_PAGE)) {
        stack_trace();
        die;
        trigger_error('Attempt to load admin realm from non admin action');
        return '';
    }
    // todo:
    return lang_by_realm($name, 'admin', $params);
}
 public function get_user_info()
 {
     stack_trace();
     die('not implemented');
 }
 /**
  * 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;
     }
 }