/** * Fetches list of plugins, installed or not installed * * @access public * @param bool $installed accepts true/false/null * @return array List of plugins */ function GetPluginsList($installed = null) { //TODO: implementing cache for this method static $pluginsList; if (!isset($pluginsList)) { $pluginsList = array(); $pDir = JAWS_PATH . 'plugins' . DIRECTORY_SEPARATOR; if (!is_dir($pDir)) { Jaws_Error::Fatal('The plugins directory does not exists!', __FILE__, __LINE__); } $installed_plugins = $GLOBALS['app']->Registry->fetch('plugins_installed_items'); $plugins = scandir($pDir); foreach ($plugins as $plugin) { if ($plugin[0] == '.' || !is_dir($pDir . $plugin)) { continue; } $objPlugin = $GLOBALS['app']->LoadPlugin($plugin); if (Jaws_Error::IsError($objPlugin)) { continue; } $pluginsList[$plugin] = array('name' => $objPlugin->name, 'title' => $objPlugin->title, 'description' => $objPlugin->description, 'installed' => strpos($installed_plugins, ",{$plugin},") !== false); } } $resList = array(); foreach ($pluginsList as $name => $plugin) { if (is_null($installed) || $plugin['installed'] == $installed) { $resList[$name] = $plugin; } } return $resList; }
/** * Fetches list of gadgets, installed/not installed, core/none core, has layout/has not, ... * * @access public * @param bool $core_gadget accepts true/false/null * @param bool $installed accepts true/false/null * @param bool $updated accepts true/false/null * @param bool $has_html accepts true/false/null * @return array List of gadgets */ function GetGadgetsList($core_gadget = null, $installed = null, $updated = null, $has_html = null) { //TODO: implementing cache for this method static $gadgetsList; if (!isset($gadgetsList)) { $gadgetsList = array(); $gDir = JAWS_PATH . 'gadgets' . DIRECTORY_SEPARATOR; if (!is_dir($gDir)) { Jaws_Error::Fatal('The gadgets directory does not exists!', __FILE__, __LINE__); } $installed_gadgets = $GLOBALS['app']->Registry->fetch('gadgets_installed_items'); $installed_gadgets = array_filter(explode(',', $installed_gadgets)); $disabled_gadgets = $GLOBALS['app']->Registry->fetch('gadgets_disabled_items'); $gadgets = scandir($gDir); foreach ($gadgets as $gadget) { if ($gadget[0] == '.' || !is_dir($gDir . $gadget)) { continue; } if (!$this->gadget->GetPermission(JAWS_SCRIPT == 'index' ? 'default' : 'default_admin', '', false, $gadget)) { continue; } $objGadget = Jaws_Gadget::getInstance($gadget); if (Jaws_Error::IsError($objGadget)) { continue; } $gInstalled = Jaws_Gadget::IsGadgetInstalled($gadget); if ($gInstalled) { $gUpdated = Jaws_Gadget::IsGadgetUpdated($gadget); } else { $gUpdated = true; } $index = urlencode($objGadget->title) . $gadget; $section = strtolower($objGadget->GetSection()); switch ($section) { case 'general': $order = str_pad(array_search($gadget, $installed_gadgets), 2, '0', STR_PAD_LEFT); $index = '0' . $section . $order . $index; break; case 'gadgets': $index = '2' . $section . $index; break; default: $index = '1' . $section . $index; break; } $gadgetsList[$index] = array('section' => $section, 'name' => $gadget, 'title' => $objGadget->title, 'core_gadget' => $objGadget->_IsCore, 'description' => $objGadget->description, 'version' => $objGadget->version, 'installed' => (bool) $gInstalled, 'updated' => (bool) $gUpdated, 'disabled' => strpos($disabled_gadgets, ",{$gadget},") !== false, 'has_html' => $objGadget->default_action ? true : false); } ksort($gadgetsList); } $resList = array(); foreach ($gadgetsList as $gadget) { if ((is_null($core_gadget) || $gadget['core_gadget'] == $core_gadget) && (is_null($installed) || $gadget['installed'] == $installed) && (is_null($updated) || $gadget['updated'] == $updated) && (is_null($has_html) || $gadget['has_html'] == $has_html)) { $resList[$gadget['name']] = $gadget; } } return $resList; }
/** * Adds layout element * * @access public * @return XHTML template content */ function AddLayoutElement() { $layout = jaws()->request->fetch('layout', 'get'); $layout = empty($layout) ? 'Layout' : $layout; // check permissions if ($layout == 'Index.Dashboard') { $GLOBALS['app']->Session->CheckPermission('Users', 'ManageDashboard'); } else { $GLOBALS['app']->Session->CheckPermission('Users', 'ManageLayout'); } $tpl = $this->gadget->template->load('AddGadget.html'); $tpl->SetBlock('template'); $direction = _t('GLOBAL_LANG_DIRECTION'); $dir = $direction == 'rtl' ? '.' . $direction : ''; $brow = $GLOBALS['app']->GetBrowserFlag(); $brow = empty($brow) ? '' : '.' . $brow; $base_url = $GLOBALS['app']->GetSiteURL('/'); $tpl->SetVariable('BASE_URL', $base_url); $tpl->SetVariable('.dir', $dir); $tpl->SetVariable('.browser', $brow); $tpl->SetVariable('base_script', BASE_SCRIPT); $tpl->SetVariable('gadgets', _t('LAYOUT_GADGETS')); $tpl->SetVariable('actions', _t('LAYOUT_ACTIONS')); $tpl->SetVariable('no_actions_msg', _t('LAYOUT_NO_GADGET_ACTIONS')); $addButton =& Piwi::CreateWidget('Button', 'add', _t('LAYOUT_NEW'), STOCK_ADD); $addButton->AddEvent(ON_CLICK, "getAction();"); $tpl->SetVariable('add_button', $addButton->Get()); $section = jaws()->request->fetch('section', 'post'); if (is_null($section)) { $section = jaws()->request->fetch('section', 'get'); $section = !is_null($section) ? $section : ''; } $tpl->SetVariable('section', $section); $cmpModel = Jaws_Gadget::getInstance('Components')->model->load('Gadgets'); $gadget_list = $cmpModel->GetGadgetsList(null, true, true, true); //Hold.. if we dont have a selected gadget?.. like no gadgets? if (count($gadget_list) <= 0) { Jaws_Error::Fatal('You don\'t have any installed gadgets, please enable/install one and then come back', __FILE__, __LINE__); } reset($gadget_list); $first = current($gadget_list); $tpl->SetVariable('first', $first['name']); $tpl->SetBlock('template/working_notification'); $tpl->SetVariable('loading-message', _t('GLOBAL_LOADING')); $tpl->ParseBlock('template/working_notification'); foreach ($gadget_list as $gadget) { $tpl->SetBlock('template/gadget'); $tpl->SetVariable('id', $gadget['name']); $tpl->SetVariable('icon', 'gadgets/' . $gadget['name'] . '/Resources/images/logo.png'); $tpl->SetVariable('gadget', $gadget['title']); $tpl->SetVariable('desc', $gadget['description']); $tpl->ParseBlock('template/gadget'); } $tpl->ParseBlock('template'); return $tpl->Get(); }
/** * Get root dir * * @access public * @return string The root directory */ function GetFileBrowserRootDir() { static $root_dir; if (!isset($root_dir)) { $root_dir = trim($this->gadget->registry->fetch('root_dir')); $root_dir = JAWS_DATA . trim($root_dir, "\\/"); $root_dir = str_replace('..', '', $root_dir); require_once PEAR_PATH . 'File/Util.php'; $root_dir = File_Util::realpath($root_dir) . '/'; if (!File_Util::pathInRoot($root_dir, JAWS_DATA)) { Jaws_Error::Fatal(_t('FILEBROWSER_ERROR_DIRECTORY_DOES_NOT_EXISTS'), __FILE__, __LINE__); } } return $root_dir; }
/** * Loads the data from the DB * * @access public * @return string Jaws version */ function Init() { $tblReg = Jaws_ORM::getInstance()->table('registry'); $tblReg->select('component', 'key_name', 'key_value', 'custom:boolean'); $result = $tblReg->where('user', 0)->fetchAll('', JAWS_ERROR_NOTICE); if (Jaws_Error::IsError($result)) { if ($result->getCode() == MDB2_ERROR_NOSUCHFIELD) { // get 0.9.x jaws version $result = $tblReg->select('key_value')->where('key_name', 'version')->and()->where('component', '')->fetchOne(); if (!Jaws_Error::IsError($result)) { return $result; } } Jaws_Error::Fatal($result->getMessage()); } foreach ($result as $regrec) { $this->regkeys[$regrec['component']][$regrec['key_name']] = $regrec['key_value']; if ($regrec['custom']) { $this->customs[$regrec['component']][$regrec['key_name']] = $regrec['key_value']; } } return @$this->regkeys['']['version']; }
/** * Loads a stage based on an array of information. * The array should be like this: * name => 'Human Readable Name of Stage' * file => 'stage' * * file should be the file the stage's class is stored * in, without the .php extension. * * @access public * @param array Information on the stage being loaded. * @param boolean If the function should return the instance for the stage * * @return object|bool|Jaws_Error */ function LoadStage($stage, $instance = true) { $file = 'stages/' . $stage['file'] . '.php'; if (!file_exists($file)) { Jaws_Error::Fatal('The ' . $stage['name'] . " stage couldn't be loaded, because " . $stage['file'] . ".php doesn't exist.", __FILE__, __LINE__); } if ($instance) { include_once $file; $classname = 'Upgrader_' . $stage['file']; $classExists = version_compare(PHP_VERSION, '5.0', '>=') ? class_exists($classname, false) : class_exists($classname); if ($classExists) { if (isset($stage['options'])) { $stage = new $classname($stage['options']); } else { $stage = new $classname(); } return $stage; } Jaws_Error::Fatal("The " . $stage['name'] . " stage couldn't be loaded, because the class " . $stage['file'] . " couldn't be found.", __FILE__, __LINE__); } $this->Stages[] = $stage; return true; }
/** * Returns the items that should be displayed in the layout * * @access public * @return array Items according to BASE_SCRIPT */ function GetLayoutItems() { if (JAWS_SCRIPT == 'index') { $layoutModel = Jaws_Gadget::getInstance('Layout')->model->load('Layout'); if (Jaws_Error::isError($layoutModel)) { Jaws_Error::Fatal("Can't load layout model"); } return $layoutModel->GetLayoutItems($GLOBALS['app']->Session->GetAttribute('layout'), $this->IndexLayout, true); } $items = array(); $items[] = array('id' => null, 'gadget' => '[REQUESTEDGADGET]', 'gadget_action' => '[REQUESTEDACTION]', 'display_when' => '*', 'section' => 'main', 'layout_position' => 0); return $items; }
if ($objAction->getAttribute($ReqAction, 'internal') && !$GLOBALS['app']->Session->extraCheck()) { $ReqError = '403'; } // set requested gadget $GLOBALS['app']->mainGadget = $ReqGadget; } else { $ReqError = '404'; } } // if action not a global action and site is protected, so request redirected to login page if ($AccessToWebsiteDenied && (empty($ReqGadget) || !$objAction->getAttribute($ReqAction, 'global'))) { $ReqGadget = 'Users'; $ReqAction = 'LoginBox'; $objAction = Jaws_Gadget::getInstance($ReqGadget)->action->load(); if (Jaws_Error::IsError($objAction)) { Jaws_Error::Fatal("Error loading gadget: {$ReqGadget}"); } $ReqError = ''; // set requested gadget $GLOBALS['app']->mainGadget = $ReqGadget; } } else { $ReqError = empty($ReqError) ? '404' : $ReqError; $ReqGadget = null; $ReqAction = null; } // set requested in front-end first/home page $GLOBALS['app']->mainIndex = $IsIndex; // Init layout... $GLOBALS['app']->InstanceLayout(); $GLOBALS['app']->Layout->Load();
/** * Displays an editor to edit an existing blog entry or preview it before saving changes * * @access public * @param string $action "preview" or empty(optional, empty by default) * @param int $id * @return string XHTML template content */ function EditEntry($action = '', $id = null) { $names = array('id', 'action'); $get = jaws()->request->fetch($names, 'get'); $names = array('allow_comments', 'edit_advanced'); $post = jaws()->request->fetch($names, 'post'); $id = !is_null($id) ? $id : $get['id']; $pModel = $this->gadget->model->load('Posts'); $cModel = $this->gadget->model->load('Categories'); $entry = $pModel->GetEntry($id); if (Jaws_Error::IsError($entry)) { Jaws_Error::Fatal('Post not found', __FILE__, __LINE__); } if ($GLOBALS['app']->Session->GetAttribute('user') != $entry['user_id']) { $this->gadget->CheckPermission('ModifyOthersEntries'); } $this->AjaxMe('script.js'); $tpl = $this->gadget->template->loadAdmin('Entry.html'); $tpl->SetBlock('edit_entry'); $tpl->SetVariable('base_script', BASE_SCRIPT); // Header $action = isset($get['action']) ? $get['action'] : null; $tpl->SetVariable('menubar', $this->MenuBar($action)); // Title $tpl->SetVariable('title', _t('GLOBAL_TITLE')); $tpl->SetVariable('action', 'EditEntry'); $tpl->SetVariable('id', $id); $titleEntry =& Piwi::CreateWidget('Entry', 'title', $entry['title']); $titleEntry->SetStyle('width: 750px'); $tpl->SetVariable('title_field', $titleEntry->Get()); // Image $imageUrl = $GLOBALS['app']->getSiteURL('/gadgets/Blog/Resources/images/no-image.gif'); if (!empty($entry['image'])) { $imageUrl = $GLOBALS['app']->getDataURL() . 'blog/images/' . $entry['image']; } $blogImage =& Piwi::CreateWidget('Image', $imageUrl); $blogImage->SetID('blog_image'); $tpl->SetVariable('blog_image', $blogImage->Get()); $imageFile =& Piwi::CreateWidget('FileEntry', 'image_file', ''); $imageFile->SetID('image_file'); $imageFile->SetSize(1); $imageFile->SetStyle('width:110px; padding:0;'); $imageFile->AddEvent(ON_CHANGE, 'previewImage(this);'); $tpl->SetVariable('upload_image', $imageFile->Get()); $button =& Piwi::CreateWidget('Button', 'btn_upload', '', STOCK_ADD); $tpl->SetVariable('btn_upload', $button->Get()); $button =& Piwi::CreateWidget('Button', 'btn_remove', '', STOCK_DELETE); $button->AddEvent(ON_CLICK, 'removeImage()'); $tpl->SetVariable('btn_remove', $button->Get()); // Category $catChecks =& Piwi::CreateWidget('CheckButtons', 'categories', 'vertical'); $categories = $cModel->GetCategories(); if (!Jaws_Error::IsError($categories)) { foreach ($categories as $a) { if ($this->gadget->GetPermission('CategoryManage', $a['id'])) { $catChecks->AddOption($a['name'], $a['id']); } } } $catDefault = array(); if (!Jaws_Error::isError($entry['categories'])) { foreach ($entry['categories'] as $cat) { if (!$this->gadget->GetPermission('CategoryManage', $cat['id'])) { return Jaws_HTTPError::Get(403); } $catDefault[] = $cat['id']; } } $catChecks->SetDefault($catDefault); $catChecks->SetColumns(3); $tpl->SetVariable('category', _t('GLOBAL_CATEGORY')); $tpl->SetVariable('category_field', $catChecks->Get()); // for compatibility with old versions $more_pos = Jaws_UTF8::strpos($entry['text'], '[more]'); if ($more_pos !== false) { $entry['summary'] = Jaws_UTF8::substr($entry['text'], 0, $more_pos); $entry['text'] = Jaws_UTF8::str_replace('[more]', '', $entry['text']); } // Summary $tpl->SetVariable('lbl_summary', _t('BLOG_ENTRY_SUMMARY')); $summary =& $GLOBALS['app']->LoadEditor('Blog', 'summary_block', $entry['summary'], false); $summary->setId('summary_block'); $summary->TextArea->SetRows(8); $summary->TextArea->SetStyle('width: 750px;'); $summary->SetWidth('96%'); $tpl->SetVariable('summary', $summary->Get()); // Body $tpl->SetVariable('text', _t('BLOG_BODY')); $editor =& $GLOBALS['app']->LoadEditor('Blog', 'text_block', $entry['text'], false); $editor->setId('text_block'); $editor->TextArea->SetRows(12); $editor->TextArea->SetStyle('width: 100%;'); $editor->SetWidth('96%'); $tpl->SetVariable('editor', $editor->Get()); // Allow Comments if (isset($post['allow_comments'])) { $allow = true; } else { if (isset($entry['allow_comments']) && $entry['allow_comments'] === true) { $allow = true; } else { $allow = false; } } $comments =& Piwi::CreateWidget('CheckButtons', 'allow_comments'); $comments->AddOption(_t('BLOG_ALLOW_COMMENTS'), 'comments', 'allow_comments', $allow); $tpl->SetVariable('allow_comments_field', $comments->Get()); // Status $tpl->SetVariable('status', _t('GLOBAL_STATUS')); $entry['published'] = $entry['published'] === true ? 1 : 0; $statData = $entry['published']; $statCombo =& Piwi::CreateWidget('Combo', 'published'); $statCombo->AddOption(_t('BLOG_DRAFT'), '0'); $statCombo->AddOption(_t('BLOG_PUBLISHED'), '1'); $statCombo->SetDefault($statData); if (!$this->gadget->GetPermission('PublishEntries')) { $statCombo->SetEnabled(false); } $tpl->SetVariable('status_field', $statCombo->Get()); // Save $tpl->SetVariable('missing_title', _t('BLOG_MISSING_TITLE')); $saveButton =& Piwi::CreateWidget('Button', 'save', _t('BLOG_UPDATE'), STOCK_SAVE); $saveButton->SetSubmit(); $tpl->SetVariable('save_button', $saveButton->Get()); // Preview // TODO: We need a different stock icon for this. $previewButton =& Piwi::CreateWidget('Button', 'preview', _t('GLOBAL_PREVIEW'), STOCK_PRINT_PREVIEW); $previewButton->SetID('preview_button'); $previewButton->AddEvent(ON_CLICK, "javascript: parseText(this.form);"); $tpl->SetVariable('preview_button', $previewButton->Get()); $tpl->SetBlock('edit_entry/advanced'); $advancedDefault = false; if (isset($post['edit_advanced'])) { $advancedDefault = true; $tpl->SetVariable('advanced_style', 'display: inline;'); } else { $tpl->SetVariable('advanced_style', 'display: none;'); } $editAdvancedchk =& Piwi::CreateWidget('CheckButtons', 'edit_advanced'); $editAdvancedchk->SetID('advanced_toggle'); $editAdvancedchk->AddOption(_t('BLOG_ADVANCED_MODE'), 'advanced', false, $advancedDefault); $editAdvancedchk->AddEvent(ON_CLICK, 'toggleAdvanced(this.checked);'); $tpl->SetVariable('advanced_field', $editAdvancedchk->Get()); $tpl->SetVariable('timestamp_label', _t('BLOG_EDIT_TIMESTAMP')); $tsChk =& Piwi::CreateWidget('CheckButtons', 'edit_timestamp'); $tsChk->AddOption('', 'yes', 'edit_timestamp', false); $tsChk->AddEvent(ON_CLICK, 'toggleUpdate(this.checked);'); $tpl->SetVariable('timestamp_check', $tsChk->Get()); $objDate = Jaws_Date::getInstance(); $pubTime = $objDate->Format($entry['publishtime'], 'Y-m-d H:i:s'); $pubdate =& Piwi::CreateWidget('DatePicker', 'pubdate', $pubTime); $pubdate->SetId('pubdate'); $pubdate->showTimePicker(true); $pubdate->setDateFormat('%Y-%m-%d %H:%M:%S'); $pubdate->setLanguageCode($this->gadget->registry->fetch('admin_language', 'Settings')); $pubdate->setCalType($this->gadget->registry->fetch('calendar', 'Settings')); $tpl->SetVariable('pubdate', $pubdate->Get()); $tpl->SetVariable('fasturl', _t('BLOG_FASTURL')); $fastUrlData = $entry['fast_url']; $fastUrlEntry =& Piwi::CreateWidget('Entry', 'fasturl', $fastUrlData); $fastUrlEntry->SetId('fasturl'); $fastUrlEntry->SetStyle('width: 100%'); $tpl->SetVariable('fasturl_field', $fastUrlEntry->Get()); $tpl->SetVariable('meta_keywords_label', _t('GLOBAL_META_KEYWORDS')); $metaKeywords =& Piwi::CreateWidget('Entry', 'meta_keywords', $entry['meta_keywords']); $metaKeywords->SetStyle('width: 100%;'); $tpl->SetVariable('meta_keywords', $metaKeywords->Get()); $tpl->SetVariable('meta_desc_label', _t('GLOBAL_META_DESCRIPTION')); $metaDesc =& Piwi::CreateWidget('Entry', 'meta_desc', $entry['meta_description']); $metaDesc->SetStyle('width: 100%;'); $tpl->SetVariable('meta_desc', $metaDesc->Get()); if (Jaws_Gadget::IsGadgetInstalled('Tags')) { $tpl->SetBlock('edit_entry/advanced/tags'); $tpl->SetVariable('tags_label', _t('GLOBAL_TAGS')); $postTags = implode(', ', $entry['tags']); $tags =& Piwi::CreateWidget('Entry', 'tags', $postTags); $tags->SetStyle('width: 100%;'); $tpl->SetVariable('tags', $tags->Get()); $tpl->ParseBlock('edit_entry/advanced/tags'); } // Trackback if ($this->gadget->registry->fetch('trackback') == 'true') { $tpl->SetBlock('edit_entry/advanced/trackback'); $tpl->SetVariable('trackback_to', _t('BLOG_TRACKBACK')); $tb =& Piwi::CreateWidget('TextArea', 'trackback_to', $entry['trackbacks']); $tb->SetId('trackback_to'); $tb->SetRows(4); $tb->SetColumns(30); // TODO: Remove this nasty hack, and replace it with some padding in the template. $tb->SetStyle('width: 99%; direction: ltr; white-space: nowrap;'); $tpl->SetVariable('trackbackTextArea', $tb->Get()); $tpl->ParseBlock('edit_entry/advanced/trackback'); } $tpl->ParseBlock('edit_entry/advanced'); $tpl->ParseBlock('edit_entry'); return $tpl->Get(); }
if (!defined('JAWS_WIKI_FORMAT')) { define('JAWS_WIKI_FORMAT', '{url}/{lang}/{lower-type}/{page}'); } if (!defined('COMPRESS_LEVEL')) { define('COMPRESS_LEVEL', 4); } // Lets support older PHP versions so we can use spanking new functions require JAWS_PATH . 'include/Jaws/PHPFunctions.php'; // lets setup the include_path set_include_path('.' . PATH_SEPARATOR . JAWS_PATH . 'libraries/pear'); // Create application $GLOBALS['app'] = jaws(); // get an instance of Jaws_DB $objDatabase = Jaws_DB::getInstance('default', $db); if (Jaws_Error::IsError($objDatabase)) { Jaws_Error::Fatal($objDatabase->getMessage()); } $db_jaws_version = $GLOBALS['app']->Registry->Init(); if ($db_jaws_version != JAWS_VERSION) { if (strrstr(JAWS_VERSION, '.', true) != strrstr($db_jaws_version, '.', true)) { //require_once JAWS_PATH . 'upgrade/JawsUpgrader.php'; //require_once JAWS_PATH . 'upgrade/JawsUpgraderStage.php'; //require_once JAWS_PATH . 'upgrade/stages/111To120.php'; //$objStage = new Upgrader_111To120; //$result = $objStage->Run(); //if (Jaws_Error::IsError($result)) { Jaws_Header::Location('upgrade/index.php'); //} } $GLOBALS['app']->Registry->update('version', JAWS_VERSION); }
/** * Loads a template from a file * * @access public * @param string $fname File name * @param string $fpath File path * @param bool $return Return content? * @return mixed Template content or void(based on $return parameter) */ function Load($fname, $fpath = '', $return = false) { $filePath = rtrim($fpath, '/'); $fileExtn = strrchr($fname, '.'); $fileName = substr($fname, 0, -strlen($fileExtn)); // load from theme? if ($this->loadFromTheme) { $layout = empty($filePath) ? '' : $this->layout; if (file_exists($this->theme['path'] . $layout . $filePath . '/' . $fname)) { $filePath = $this->theme['path'] . $layout . $filePath; } else { $filePath = JAWS_PATH . $filePath; } } $prefix = ''; if ($this->loadRTLDirection || is_null($this->loadRTLDirection) && function_exists('_t') && _t('GLOBAL_LANG_DIRECTION') == 'rtl') { $prefix = '.rtl'; } $tplFile = $filePath . '/' . $fileName . $prefix . $fileExtn; $tplExists = file_exists($tplFile); if (!$tplExists && !empty($prefix)) { $tplFile = $filePath . '/' . $fileName . $fileExtn; $tplExists = file_exists($tplFile); } if (!$tplExists) { Jaws_Error::Fatal('Template ' . $tplFile . ' doesn\'t exists'); } $content = @file_get_contents($tplFile); if (empty($content)) { Jaws_Error::Fatal('There was a problem while reading the template file: ' . $tplFile); } if (preg_match_all("#<!-- INCLUDE (.*) -->#i", $content, $includes, PREG_SET_ORDER)) { foreach ($includes as $key => $include) { @(list($incl_fname, $incl_fpath) = preg_split('#\\s#', $include[1])); if (empty($incl_fpath)) { $incl_fpath = $fpath; } $replacement = $this->Load($incl_fname, $incl_fpath, true); $content = str_replace($include[0], $replacement, $content); } } if ($return) { return $content; } $this->loadFromString($content); }
if (Jaws_Error::IsError($objAction)) { Jaws_Error::Fatal("Error loading gadget: {$ReqGadget}"); } $ReqAction = empty($ReqAction) ? $objAction->gadget->default_admin_action : $ReqAction; // set requested gadget/action $GLOBALS['app']->mainGadget = $ReqGadget; $GLOBALS['app']->mainAction = $ReqAction; // Init layout $GLOBALS['app']->InstanceLayout(); // check referrer host if (!$GLOBALS['app']->Session->extraCheck()) { $ReqResult = Jaws_HTTPError::Get(403); } else { $ReqResult = $objAction->Execute($ReqAction); if (Jaws_Error::IsError($ReqResult)) { Jaws_Error::Fatal($ReqResult->getMessage()); } } $IsReqActionStandAlone = $objAction->IsStandAloneAdmin($ReqAction); if (!$IsReqActionStandAlone) { // Load ControlPanel header $GLOBALS['app']->Layout->LoadControlPanelHead(); $GLOBALS['app']->Layout->Populate($ReqResult); $GLOBALS['app']->Layout->AddHeadLink('gadgets/' . $ReqGadget . '/Resources/style.css?' . $objAction->gadget->version, 'stylesheet', 'text/css'); $GLOBALS['app']->Layout->LoadControlPanel($ReqGadget); $ReqResult = $GLOBALS['app']->Layout->Get(); } terminate($ReqResult); } Jaws_Error::Fatal('Invalid requested gadget');
/** * insert new session * * @access public * @return mixed Session ID if success, otherwise Jaws_Error or false */ function insert() { $max_active_sessions = (int) $GLOBALS['app']->Registry->fetch('max_active_sessions', 'Policy'); if (!empty($max_active_sessions)) { $activeSessions = $this->GetSessionsCount(true); if ($activeSessions >= $max_active_sessions) { // remove expired session $this->DeleteExpiredSessions(); $GLOBALS['app']->Session->Logout(); Jaws_Error::Fatal(_t('GLOBAL_HTTP_ERROR_CONTENT_503_OVERLOAD'), 0, 503); } } // agent $agent = substr(Jaws_XSS::filter($_SERVER['HTTP_USER_AGENT']), 0, 252); // ip $ip = 0; if (preg_match('/\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b/', $_SERVER['REMOTE_ADDR'])) { $ip = ip2long($_SERVER['REMOTE_ADDR']); $ip = $ip < 0 ? $ip + 0xffffffff + 1 : $ip; } // referrer $referrer = Jaws_Utils::getHostReferrer(); $sessTable = Jaws_ORM::getInstance()->table('session', '', 'sid'); if (!empty($GLOBALS['app']->Session->_Attributes)) { //A new session, we insert it to the DB $updatetime = time(); $user = $GLOBALS['app']->Session->GetAttribute('user'); $serialized = serialize($GLOBALS['app']->Session->_Attributes); $sessTable->insert(array('user' => $user, 'type' => JAWS_APPTYPE, 'longevity' => $GLOBALS['app']->Session->GetAttribute('longevity'), 'data' => $serialized, 'referrer' => md5($referrer), 'checksum' => md5($user . $serialized), 'ip' => $ip, 'agent' => $agent, 'createtime' => $updatetime, 'updatetime' => $updatetime)); $result = $sessTable->exec(); if (!Jaws_Error::IsError($result)) { return $result; } } return false; }
/** * Returns the items that should be displayed in the layout * * @access public * @return array Items according to BASE_SCRIPT */ function GetLayoutItems() { if (JAWS_SCRIPT == 'index') { $layoutModel = Jaws_Gadget::getInstance('Layout')->model->load('Layout'); if (Jaws_Error::isError($layoutModel)) { Jaws_Error::Fatal("Can't load layout model"); } return $layoutModel->GetLayoutItems($this->layout, true); } $items = array(); $items[] = array('id' => null, 'gadget' => '[REQUESTEDGADGET]', 'action' => '[REQUESTEDACTION]', 'params' => '', 'filename' => '', 'when' => '*', 'section' => 'main', 'position' => 0); return $items; }
/** * Initializes the Jaws URL Mapping * * @access public * @param string $request_uri Requested URL * @return bool True on success, or False on failure */ function Init($request_uri = '') { $urlMapper = Jaws_Gadget::getInstance('UrlMapper'); if (Jaws_Error::isError($urlMapper)) { Jaws_Error::Fatal($urlMapper->getMessage()); } $this->_MapsModel = Jaws_Gadget::getInstance('UrlMapper')->model->load('Maps'); if (Jaws_Error::isError($this->_MapsModel)) { Jaws_Error::Fatal($this->_MapsModel->getMessage()); } $this->_AliasesModel = Jaws_Gadget::getInstance('UrlMapper')->model->load('Aliases'); if (Jaws_Error::isError($this->_AliasesModel)) { Jaws_Error::Fatal($this->_AliasesModel->getMessage()); } // fetch all registry keys $regKeys = $urlMapper->registry->fetchAll(); $extension = $regKeys['map_extensions']; $this->_enabled = $regKeys['map_enabled'] == 'true'; $this->_use_rewrite = $regKeys['map_use_rewrite'] == 'true'; $this->_use_aliases = $regKeys['map_use_aliases'] == 'true'; $this->_custom_precedence = $regKeys['map_custom_precedence'] == 'true'; $this->_restrict_multimap = $regKeys['map_restrict_multimap'] == 'true'; if (!empty($extension) && $extension[0] != '.') { $extension = '.' . $extension; } $this->_extension = $extension; if (empty($request_uri)) { // ?\d+$ for force browsers to update cached file e.g. (?12345) $this->_request_uri = preg_replace(array('/^index\\.php[\\/|\\?]?/iu', '/\\?\\d+$/u'), '', Jaws_Utils::getRequestURL()); } elseif (strpos($request_uri, 'http') !== false) { //prepare it manually if (false !== ($strPos = stripos($request_uri, BASE_SCRIPT))) { $strPos = $strPos + strlen(BASE_SCRIPT); $this->_request_uri = substr($request_uri, $strPos); } } else { $this->_request_uri = $request_uri; } // fetch apptype $params = explode('/', $this->_request_uri); if (false !== ($apptype_key = array_search('apptype', $params))) { jaws()->request->update('apptype', $params[$apptype_key + 1], 'get'); unset($params[$apptype_key], $params[$apptype_key + 1]); } // decode url parts $this->_request_uri = implode('/', array_map('rawurldecode', $params)); //Moment.. first check if we are running on aliases_mode if ($this->_use_aliases && ($realURI = $this->_AliasesModel->GetAliasPath($this->_request_uri))) { $this->_request_uri = str_ireplace(BASE_SCRIPT, '', $realURI); } // load maps if ($this->_enabled) { $maps = $this->_MapsModel->GetMaps(); if (Jaws_Error::IsError($maps)) { return false; } foreach ($maps as $map) { $this->_actions_maps[$map['gadget']][$map['action']][] = $map['map']; $this->_maps[$map['gadget']][$map['map']] = array('params' => null, 'action' => $map['action'], 'map' => $map['map'], 'regexp' => $map['regexp'], 'extension' => $map['extension'], 'regexp_vars' => array_keys(unserialize($map['vars_regexps'])), 'custom_map' => $map['custom_map'], 'custom_regexp' => $map['custom_regexp']); } } return true; }