/** * Gets a single page * * @access public * @param mixed $id ID or fast_url of the page (int/string) * @param string $language Page language * @return mixed Array of the page information or Jaws_Error on failure */ function GetPage($id, $language = '') { $spTable = Jaws_ORM::getInstance()->table('static_pages as sp'); $spTable->select('sp.page_id:integer', 'sp.group_id:integer', 'spt.translation_id:integer', 'spt.language', 'spt.title', 'sp.fast_url', 'spt.published:boolean', 'sp.show_title:boolean', 'spt.content', 'spt.user:integer', 'spt.meta_keywords', 'spt.meta_description', 'spt.updated'); $spTable->join('static_pages_translation as spt', 'sp.page_id', 'spt.base_id'); if (empty($language)) { $spTable->where('spt.language', array('sp.base_language', 'expr')); } else { $spTable->where('spt.language', $language); } if (is_numeric($id)) { $spTable->and()->where('sp.page_id', $id); } else { $spTable->and()->where('sp.fast_url', $id); } $page = $spTable->fetchRow(); if (!empty($page)) { $page['tags'] = ''; if (Jaws_Gadget::IsGadgetInstalled('Tags')) { $model = Jaws_Gadget::getInstance('Tags')->model->loadAdmin('Tags'); $tags = $model->GetReferenceTags('StaticPage', 'page', $page['translation_id']); $page['tags'] = implode(',', array_filter($tags)); } } return $page; }
/** * Displays admin menu bar according to selected action * * @access public * @param string $action_selected selected action * @return string XHTML template content */ function MenuBar($action_selected) { $actions = array('Summary', 'NewEntry', 'ListEntries', 'ManageComments', 'ManageTrackbacks', 'ManageCategories', 'AdditionalSettings'); if (!in_array($action_selected, $actions)) { $action_selected = 'ListEntries'; } $menubar = new Jaws_Widgets_Menubar(); $menubar->AddOption('Summary', _t('BLOG_SUMMARY'), BASE_SCRIPT . '?gadget=Blog&action=Summary', 'images/stock/new.png'); if ($this->gadget->GetPermission('AddEntries')) { $menubar->AddOption('NewEntry', _t('BLOG_NEW_ENTRY'), BASE_SCRIPT . '?gadget=Blog&action=NewEntry', 'images/stock/new.png'); } $menubar->AddOption('ListEntries', _t('BLOG_LIST_ENTRIES'), BASE_SCRIPT . '?gadget=Blog&action=ListEntries', 'images/stock/edit.png'); if (Jaws_Gadget::IsGadgetInstalled('Comments') && $this->gadget->GetPermission('ManageComments')) { $menubar->AddOption('ManageComments', _t('BLOG_MANAGE_COMMENTS'), BASE_SCRIPT . '?gadget=Blog&action=ManageComments', 'images/stock/stock-comments.png'); } if ($this->gadget->GetPermission('ManageTrackbacks')) { $menubar->AddOption('ManageTrackbacks', _t('BLOG_MANAGE_TRACKBACKS'), BASE_SCRIPT . '?gadget=Blog&action=ManageTrackbacks', 'images/stock/stock-comments.png'); } if ($this->gadget->GetPermission('ManageCategories')) { $menubar->AddOption('ManageCategories', _t('BLOG_CATEGORIES'), BASE_SCRIPT . '?gadget=Blog&action=ManageCategories', 'images/stock/edit.png'); } if ($this->gadget->GetPermission('Settings')) { $menubar->AddOption('AdditionalSettings', _t('BLOG_SETTINGS'), BASE_SCRIPT . '?gadget=Blog&action=AdditionalSettings', 'images/stock/properties.png'); } $menubar->Activate($action_selected); return $menubar->Get(); }
/** * Shouts a call to the listener object that will act immediately. * * @access public * @param string $shouter Shouter class|gadget name * @param string $event Event name * @param mixed $params Event param(s) * @param string $gadget If set, returns listener result of this gadget * @param bool $broadcast Broadcast event to all listeners * @return mixed True if successfully, otherwise returns Jaws_Error */ function Shout($shouter, $event, $params = array(), $gadget = '', $broadcast = true) { $listeners = $this->GetEventListeners($event); if (Jaws_Error::IsError($listeners)) { return $listeners; } $result = null; foreach ($listeners as $listener) { // check event broadcasting if (!$broadcast && $listener['gadget'] !== $gadget) { continue; } if (Jaws_Gadget::IsGadgetInstalled($listener['gadget'])) { $objGadget = Jaws_Gadget::getInstance($listener['gadget']); if (Jaws_Error::IsError($objGadget)) { continue; } $objEvent = $objGadget->event->load($event); if (Jaws_Error::IsError($objEvent)) { continue; } $response = $objEvent->Execute($shouter, $params); // return listener result if ($gadget == $listener['gadget']) { $result = $response; } } } return $result; }
/** * Displays blog comments manager * * @access public * @return string XHTML template content */ function ManageComments() { $this->gadget->CheckPermission('ManageComments'); if (!Jaws_Gadget::IsGadgetInstalled('Comments')) { Jaws_Header::Location(BASE_SCRIPT . '?gadget=Blog'); } $cHTML = Jaws_Gadget::getInstance('Comments')->action->loadAdmin('Comments'); return $cHTML->Comments($this->gadget->name, $this->MenuBar('ManageComments')); }
/** * 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; }
/** * Does any actions required to finish the stage, such as DB queries. * * @access public * @return bool|Jaws_Error Either true on success, or a Jaws_Error * containing the reason for failure. */ function Run() { // Connect to database require_once JAWS_PATH . 'include/Jaws/DB.php'; $objDatabase = Jaws_DB::getInstance('default', $_SESSION['upgrade']['Database']); if (Jaws_Error::IsError($objDatabase)) { _log(JAWS_LOG_DEBUG, "There was a problem connecting to the database, please check the details and try again"); return new Jaws_Error(_t('UPGRADE_DB_RESPONSE_CONNECT_FAILED'), 0, JAWS_ERROR_WARNING); } // upgrade core database schema $old_schema = JAWS_PATH . 'upgrade/Resources/schema/0.9.0.xml'; $new_schema = JAWS_PATH . 'upgrade/Resources/schema/schema.xml'; if (!file_exists($old_schema)) { return new Jaws_Error(_t('GLOBAL_ERROR_SQLFILE_NOT_EXISTS', '0.9.0.xml'), 0, JAWS_ERROR_ERROR); } if (!file_exists($new_schema)) { return new Jaws_Error(_t('GLOBAL_ERROR_SQLFILE_NOT_EXISTS', 'schema.xml'), 0, JAWS_ERROR_ERROR); } _log(JAWS_LOG_DEBUG, "Upgrading core schema"); $result = Jaws_DB::getInstance()->installSchema($new_schema, '', $old_schema); if (Jaws_Error::isError($result)) { _log(JAWS_LOG_ERROR, $result->getMessage()); if ($result->getCode() !== MDB2_ERROR_ALREADY_EXISTS) { return new Jaws_Error($result->getMessage(), 0, JAWS_ERROR_ERROR); } } // Create application include_once JAWS_PATH . 'include/Jaws.php'; $GLOBALS['app'] = jaws(); $GLOBALS['app']->Registry->Init(); // Upgrading core gadgets $gadgets = array('UrlMapper', 'Settings', 'ControlPanel', 'Policy', 'Layout', 'Users', 'Comments'); foreach ($gadgets as $gadget) { $objGadget = Jaws_Gadget::getInstance($gadget); if (Jaws_Error::IsError($objGadget)) { _log(JAWS_LOG_DEBUG, "There was a problem loading core gadget: " . $gadget); return $objGadget; } $installer = $objGadget->installer->load(); if (Jaws_Error::IsError($installer)) { _log(JAWS_LOG_DEBUG, "There was a problem loading installer of core gadget: {$gadget}"); return $installer; } if (Jaws_Gadget::IsGadgetInstalled($gadget)) { $result = $installer->UpgradeGadget(); } else { continue; //$result = $installer->InstallGadget(); } if (Jaws_Error::IsError($result)) { _log(JAWS_LOG_DEBUG, "There was a problem installing/upgrading core gadget: {$gadget}"); return $result; } } return true; }
/** * The preg_replace call back function * * @access private * @param string $data Matched strings from preg_replace_callback * @return string Block content or blank text */ function Prepare($data) { $blockID = isset($data[1]) ? $data[1] : ''; if (Jaws_Gadget::IsGadgetInstalled('Blocks') && !empty($blockID)) { $objBlocks = Jaws_Gadget::getInstance('Blocks')->action->load('Block'); $result = $objBlocks->Block($blockID); if (!Jaws_Error::isError($result)) { return $result; } } return ''; }
/** * Displays a list of blog entries ordered by date * * @access public * @return string XHTML template content */ function Archive() { $tpl = $this->gadget->template->load('Archive.html'); $model = $this->gadget->model->load('Posts'); $archiveEntries = $model->GetEntriesAsArchive(); $auxMonth = ''; $this->SetTitle(_t('BLOG_ARCHIVE')); $tpl->SetBlock('archive'); $tpl->SetVariable('title', _t('BLOG_ARCHIVE')); if (!Jaws_Error::IsError($archiveEntries)) { $date = Jaws_Date::getInstance(); foreach ($archiveEntries as $entry) { $currentMonth = $date->Format($entry['publishtime'], 'MN'); if ($currentMonth != $auxMonth) { if ($auxMonth != '') { $tpl->ParseBlock('archive/month'); } $tpl->SetBlock('archive/month'); $year = $date->Format($entry['publishtime'], 'Y'); $tpl->SetVariable('month', $currentMonth); $tpl->SetVariable('year', $year); $auxMonth = $currentMonth; } $tpl->SetBlock('archive/month/record'); $tpl->SetVariable('id', $entry['id']); $tpl->SetVariable('date', $date->Format($entry['publishtime'])); $tpl->SetVariable('date-monthname', $currentMonth); $tpl->SetVariable('date-month', $date->Format($entry['publishtime'], 'm')); $tpl->SetVariable('date-day', $date->Format($entry['publishtime'], 'd')); $tpl->SetVariable('date-year', $year); $tpl->SetVariable('date-time', $date->Format($entry['publishtime'], 'g:ia')); $tpl->SetVariable('title', $entry['title']); $comments = _t('BLOG_NO_COMMENT'); if (Jaws_Gadget::IsGadgetInstalled('Comments')) { $cModel = Jaws_Gadget::getInstance('Comments')->model->load('Comments'); $commentsCount = $cModel->GetCommentsCount('Blog', 'Post', $entry['id'], '', Comments_Info::COMMENTS_STATUS_APPROVED); if (!empty($commentsCount)) { $comments = _t('BLOG_HAS_N_COMMENTS', $entry['comments']); } } $tpl->SetVariable('comments', $comments); $id = !empty($entry['fast_url']) ? $entry['fast_url'] : $entry['id']; $url = $this->gadget->urlMap('SingleView', array('id' => $id)); $tpl->SetVariable('view-link', $url); $tpl->ParseBlock('archive/month/record'); } $tpl->ParseBlock('archive/month'); } $tpl->ParseBlock('archive'); return $tpl->Get('archive'); }
/** * Displays admin menu bar according to selected action * * @access public * @param string $action selected action * @return string XHTML template content */ function MenuBar($action) { $actions = array('Directory', 'Comments'); if (!in_array($action, $actions)) { $action = 'Directory'; } $menubar = new Jaws_Widgets_Menubar(); $menubar->AddOption('Directory', _t('DIRECTORY_TITLE'), BASE_SCRIPT . '?gadget=Directory&action=Directory', 'images/stock/folder.png'); if (Jaws_Gadget::IsGadgetInstalled('Comments') && $this->gadget->GetPermission('ManageComments')) { $menubar->AddOption('Comments', _t('DIRECTORY_FILE_COMMENTS'), BASE_SCRIPT . '?gadget=Directory&action=ManageComments', 'images/stock/stock-comments.png'); } $menubar->Activate($action); return $menubar->Get(); }
/** * Get information about a link * * @access public * @param int $id The links id * @return mixed An array contains link information and Jaws_Error on error */ function GetLink($id) { $objORM = Jaws_ORM::getInstance()->table('linkdump_links'); $objORM->select('id:integer', 'gid:integer', 'title', 'description', 'url', 'fast_url', 'createtime', 'updatetime', 'clicks:integer', 'rank:integer'); $objORM->where(is_numeric($id) ? 'id' : 'fast_url', $id); $link = $objORM->fetchRow(); if (Jaws_Error::IsError($link)) { return $link; } if (Jaws_Gadget::IsGadgetInstalled('Tags')) { if (!empty($link)) { $model = Jaws_Gadget::getInstance('Tags')->model->loadAdmin('Tags'); $tags = $model->GetReferenceTags('LinkDump', 'link', $id); $link['tags'] = array_filter($tags); } } return $link; }
/** * Get summary of the blog * * @access public * @return array An array that has the summary of blog entries */ function GetSummary() { $model = $this->gadget->model->load('DatePosts'); $summary = $model->GetPostsDateLimitation(); // Avg. entries per week if (isset($summary['min_date'])) { $dfirst = strtotime($summary['min_date']); $dlast = strtotime($summary['max_date']); $weekfirst = date('W', $dfirst); $yearfirst = date('Y', $dfirst); $weeklast = date('W', $dlast); $yearlast = date('Y', $dlast); if ($yearlast > $yearfirst) { // Ok ok, we assume 53 weeks per year... $nweeks = 54 - $weekfirst + 53 * ($yearlast - 1 - $yearfirst) + $weeklast; } else { $nweeks = $weeklast - $weekfirst; } if ($nweeks != 0) { $avg = round($summary['qty_posts'] / $nweeks); } else { $avg = $summary['qty_posts']; } $summary['AvgEntriesPerWeek'] = $avg; } else { $summary['min_date'] = null; $summary['max_date'] = null; $summary['AvgEntriesPerWeek'] = null; } if (Jaws_Gadget::IsGadgetInstalled('Comments')) { $cModel = Jaws_Gadget::getInstance('Comments')->model->load('Comments'); // total comments $summary['CommentsQty'] = $cModel->GetCommentsCount($this->gadget->name); // recent comments $comments = $cModel->GetComments($this->gadget->name, '', '', '', array(), 10); if (Jaws_Error::IsError($comments)) { return $comments; } foreach ($comments as $r) { $summary['Comments'][] = array('id' => $r['id'], 'name' => $r['name'], 'insert_time' => $r['insert_time']); } } return $summary; }
/** * Gets the translation(by translation ID) of a page * * @access public * @param int $id Translation ID * @return mixed Array translation information or Jaws_Error on failure */ function GetPageTranslation($id) { $sptTable = Jaws_ORM::getInstance()->table('static_pages_translation'); $sptTable->select('translation_id:integer', 'base_id:integer', 'title', 'content', 'language', 'meta_keywords', 'meta_description', 'user:integer', 'published:boolean', 'updated')->where('translation_id', $id); $row = $sptTable->fetchRow(); if (Jaws_Error::IsError($row)) { return new Jaws_Error(_t('STATICPAGE_ERROR_TRANSLATION_NOT_EXISTS')); } if (isset($row['translation_id'])) { if (!empty($row)) { if (Jaws_Gadget::IsGadgetInstalled('Tags')) { $model = Jaws_Gadget::getInstance('Tags')->model->loadAdmin('Tags'); $tags = $model->GetReferenceTags('StaticPage', 'page', $row['translation_id']); $row['tags'] = implode(',', array_filter($tags)); } } return $row; } return new Jaws_Error(_t('STATICPAGE_ERROR_TRANSLATION_NOT_EXISTS')); }
/** * Overrides, Parses the text * * @access public * @param string $html HTML to be parsed * @return string Parsed content */ function ParseText($html) { if (file_exists(JAWS_PATH . 'gadgets/Phoo/Model.php') && Jaws_Gadget::IsGadgetInstalled('Phoo')) { $howMany = preg_match_all("#\\[phoo album=\"(.*?)\" picture=\"(.*?)\" title=\"(.*?)\" class=\"(.*?)\" size=\"(.*?)\" linked=\"(.*?)\"\\]#si", $html, $matches); $new_html = $html; $url = $GLOBALS['app']->getSiteURL(); $objPhoo = Jaws_Gadget::getInstance('Phoo')->model->load('Photos'); for ($i = 0; $i < $howMany; $i++) { $albumid = $matches[1][$i]; $imageid = $matches[2][$i]; $title = $matches[3][$i]; $clase = $matches[4][$i]; $size = $matches[5][$i]; $linked = $matches[6][$i]; $image = $objPhoo->GetImageEntry($imageid); if (!Jaws_Error::IsError($image) && !empty($image)) { if (strtoupper($size) == 'THUMB') { $img_file = JAWS_DATA . 'phoo/' . $image['thumb']; $img_url = $GLOBALS['app']->getDataURL('phoo/' . $image['thumb']); } elseif (strtoupper($size) == 'MEDIUM') { $img_file = JAWS_DATA . 'phoo/' . $image['medium']; $img_url = $GLOBALS['app']->getDataURL('phoo/' . $image['medium']); } else { $img_file = JAWS_DATA . 'phoo/' . $image['image']; $img_url = $GLOBALS['app']->getDataURL('phoo/' . $image['image']); } $imgData = Jaws_Image::getimagesize($img_file); if (strtoupper($linked) == 'YES') { $img_lnk = $GLOBALS['app']->Map->GetURLFor('Phoo', 'ViewImage', array('id' => $imageid, 'albumid' => $albumid)); $new_text = '<a href="' . $img_lnk . '" ><img src="' . $img_url . '" title="' . $title . '" alt="' . $title . '" class="' . $clase . '" height="' . $imgData['height'] . '" width="' . $imgData['width'] . '"/></a>'; } else { $new_text = '<img src="' . $img_url . '" title="' . $title . '" alt="' . $title . '" class="' . $clase . '" height="' . $imgData['height'] . '" width="' . $imgData['width'] . '" />'; } $textToReplace = "#\\[phoo album=\"" . $albumid . "\" picture=\"" . $imageid . "\" title=\"" . $title . "\" class=\"" . $clase . "\" size=\"" . $size . "\" linked=\"" . $linked . "\"\\]#"; $new_html = preg_replace($textToReplace, $new_text, $new_html); } } return $new_html; } return $html; }
/** * Overrides, Parses the text * * @access public * @param string $html HTML to be parsed * @return string Parsed content */ function ParseText($html) { if (!Jaws_Gadget::IsGadgetInstalled('Glossary') || !$this->NeedParsing($html)) { return $html; } $glossyModel = Jaws_Gadget::getInstance('Glossary')->model->load('Term'); $howMany = preg_match_all('#\\[term\\](.*?)\\[/term\\]#si', $html, $matches); for ($i = 0; $i < $howMany; $i++) { $match_text = $matches[1][$i]; //How many? if ($term = $glossyModel->GetTermByTerm(strip_tags($match_text))) { $new_text = "<acronym title=\"" . str_replace(array('[term]', '[/term]'), '', strip_tags($term['description'])) . "\">{$match_text}</acronym>"; $url = $GLOBALS['app']->Map->GetURLFor('Glossary', 'ViewTerm', array('term' => empty($term['fast_url']) ? $term['id'] : $term['fast_url'])); $new_text = "<a href=\"{$url}\">{$new_text}</a>"; } else { $new_text = $match_text; } $html = str_replace('[term]' . $match_text . '[/term]', $new_text, $html); } return $html; }
/** * Does any actions required to finish the stage, such as DB queries. * * @access public * @return bool|Jaws_Error Either true on success, or a Jaws_Error * containing the reason for failure. */ function Run() { // Connect to database require_once JAWS_PATH . 'include/Jaws/DB.php'; $objDatabase = Jaws_DB::getInstance('default', $_SESSION['upgrade']['Database']); if (Jaws_Error::IsError($objDatabase)) { _log(JAWS_LOG_DEBUG, "There was a problem connecting to the database, please check the details and try again"); return new Jaws_Error(_t('UPGRADE_DB_RESPONSE_CONNECT_FAILED'), 0, JAWS_ERROR_WARNING); } // Create application include_once JAWS_PATH . 'include/Jaws.php'; $GLOBALS['app'] = jaws(); $GLOBALS['app']->Registry->Init(); // Upgrading core gadgets $gadgets = array('Settings', 'Layout', 'Users'); foreach ($gadgets as $gadget) { $objGadget = Jaws_Gadget::getInstance($gadget); if (Jaws_Error::IsError($objGadget)) { _log(JAWS_LOG_DEBUG, "There was a problem loading core gadget: " . $gadget); return $objGadget; } $installer = $objGadget->installer->load(); if (Jaws_Error::IsError($installer)) { _log(JAWS_LOG_DEBUG, "There was a problem loading installer of core gadget: {$gadget}"); return $installer; } if (Jaws_Gadget::IsGadgetInstalled($gadget)) { $result = $installer->UpgradeGadget(); } else { continue; //$result = $installer->InstallGadget(); } if (Jaws_Error::IsError($result)) { _log(JAWS_LOG_DEBUG, "There was a problem installing/upgrading core gadget: {$gadget}"); return $result; } } return true; }
/** * Displays a menu bar for the control panel gadget. * * @access protected * @param string $action_selected The item to display as selected. * @return string XHTML template content for menubar */ function MenuBar($action_selected) { $actions = array('Photos', 'Groups', 'ManageComments', 'AdditionalSettings', 'Import'); if (!in_array($action_selected, $actions)) { $action_selected = 'Photos'; } $menubar = new Jaws_Widgets_Menubar(); $menubar->AddOption('Photos', _t('PHOO_PHOTOS'), BASE_SCRIPT . '?gadget=Phoo', STOCK_IMAGE); if ($this->gadget->GetPermission('Groups')) { $menubar->AddOption('Groups', _t('GLOBAL_GROUPS'), BASE_SCRIPT . '?gadget=Phoo&action=Groups', 'gadgets/Phoo/Resources/images/groups_mini.png'); } if (Jaws_Gadget::IsGadgetInstalled('Comments') && $this->gadget->GetPermission('ManageComments')) { $menubar->AddOption('ManageComments', _t('PHOO_COMMENTS'), BASE_SCRIPT . '?gadget=Phoo&action=ManageComments', 'images/stock/stock-comments.png'); } if ($this->gadget->GetPermission('Settings')) { $menubar->AddOption('AdditionalSettings', _t('PHOO_ADDITIONAL_SETTINGS'), BASE_SCRIPT . '?gadget=Phoo&action=AdditionalSettings', 'images/stock/properties.png'); } if ($this->gadget->GetPermission('Import')) { $menubar->AddOption('Import', _t('PHOO_IMPORT'), BASE_SCRIPT . '?gadget=Phoo&action=Import', STOCK_IMAGE); } $menubar->Activate($action_selected); return $menubar->Get(); }
/** * Overrides, Parses the text * * @access public * @param string $html HTML to be parsed * @return string Parsed content */ function ParseText($html) { if (file_exists(JAWS_PATH . 'gadgets/Friends/Model.php') && Jaws_Gadget::IsGadgetInstalled('Friends')) { $howMany = preg_match_all('#\\[friend\\](.*?)\\[/friend\\]#si', $html, $matches); $objFriends = Jaws_Gadget::getInstance('Friends')->model->load('Friends'); for ($i = 0; $i < $howMany; $i++) { $match_text = $matches[1][$i]; //How many? $friend = $objFriends->GetFriendByName($match_text); if (!Jaws_Error::IsError($friend)) { $new_text = "<a href=\"" . $friend['url'] . "\" rel=\"friend\">" . $match_text . "</a>"; } else { $new_text = $match_text; } $pattern = '#\\[friend\\]' . $match_text . '\\[/friend\\]#si'; $html = preg_replace($pattern, $new_text, $html); } } else { //FIXME: Simon says we need another regexp here $html = str_replace('[friend]', '', $html); $html = str_replace('[/friend]', '', $html); } return $html; }
/** * Builds an individual page * * @access public * @param string $base_action Determines the map to be used (Page/Pages) * @return string XHTML content */ function Page($pid = null, $base_action = 'Page') { $post = jaws()->request->fetch(array('gid', 'pid', 'language'), 'get'); $post['gid'] = Jaws_XSS::defilter($post['gid']); $post['pid'] = empty($pid) ? Jaws_XSS::defilter($post['pid']) : $pid; $pModel = $this->gadget->model->load('Page'); $gModel = $this->gadget->model->load('Group'); $tModel = $this->gadget->model->load('Translation'); if ($base_action == 'Pages') { $group = $gModel->GetGroup($post['gid']); if (Jaws_Error::IsError($group) || empty($group)) { return Jaws_HTTPError::Get(404); } } $page_id = empty($post['pid']) ? $this->gadget->registry->fetch('default_page') : $post['pid']; $page_language = $post['language']; if (empty($page_language)) { // if page language not set try to load language traslation of page that same as site language $page_language = $GLOBALS['app']->GetLanguage(); if (!$tModel->TranslationExists($page_id, $page_language)) { $page_language = null; } } $page = $pModel->GetPage($page_id, $page_language); if (Jaws_Error::IsError($page) || empty($page) || !$page['published']) { return Jaws_HTTPError::Get(404); } if (!$this->gadget->GetPermission('AccessGroup', $page['group_id'])) { return Jaws_HTTPError::Get(403); } //add static page language to meta language tag $this->AddToMetaLanguages($page_language); $tpl = $this->gadget->template->load('StaticPage.html'); $tpl->SetBlock('page'); if (!$page['published'] && !$GLOBALS['app']->Session->IsSuperAdmin() && $page['user'] !== (int) $GLOBALS['app']->Session->GetAttribute('user')) { $this->SetTitle(_t('STATICPAGE_TITLE_NOT_FOUND')); $tpl->SetVariable('content', _t('STATICPAGE_CONTENT_NOT_FOUND')); $tpl->SetBlock('page/title'); $tpl->SetVariable('title', _t('STATICPAGE_TITLE_NOT_FOUND')); $tpl->ParseBlock('page/title'); } else { $this->SetTitle($page['title']); $this->AddToMetaKeywords($page['meta_keywords']); $this->SetDescription($page['meta_description']); $text = $this->gadget->ParseText($page['content']); $tpl->SetVariable('content', $text, false); if ($page['show_title']) { $tpl->SetBlock('page/title'); $tpl->SetVariable('title', $page['title']); $tpl->ParseBlock('page/title'); } if ($this->gadget->registry->fetch('multilanguage') == 'yes') { $translations = $tModel->GetTranslationsOfPage($page['page_id'], true); if (!Jaws_Error::isError($translations) && count($translations) > 1) { $tpl->SetBlock('page/translations'); $tpl->SetVariable('avail_trans', _t('STATICPAGE_AVAIL_TRANSLATIONS')); foreach ($translations as $trans) { //if ($page['language'] == $trans['language']) continue; $tpl->SetBlock('page/translations/language'); $tpl->SetVariable('lang', $trans['language']); if ($base_action == 'Pages') { $param = array('gid' => !empty($group['fast_url']) ? $group['fast_url'] : $group['id'], 'pid' => !empty($page['fast_url']) ? $page['fast_url'] : $page['page_id'], 'language' => $trans['language']); $tpl->SetVariable('url', $this->gadget->urlMap('Pages', $param)); } else { $param = array('pid' => !empty($page['fast_url']) ? $page['fast_url'] : $page['page_id'], 'language' => $trans['language']); $tpl->SetVariable('url', $this->gadget->urlMap('Page', $param)); } $tpl->ParseBlock('page/translations/language'); } $tpl->ParseBlock('page/translations'); } } } // Show Tags if (Jaws_Gadget::IsGadgetInstalled('Tags')) { $tagsHTML = Jaws_Gadget::getInstance('Tags')->action->load('Tags'); $tagsHTML->loadReferenceTags('StaticPage', 'page', $page['translation_id'], $tpl, 'page'); } $tpl->ParseBlock('page'); return $tpl->Get(); }
/** * Build the XHTML * * @access public * @return string XHTML content */ function buildXHTML() { $label = $this->_Label->GetValue(); if (!empty($label)) { $this->_Container->PackStart($this->_Label); } $this->_Container->PackStart($this->TextArea); $this->_Container->SetWidth($this->_Width); $this->_XHTML .= $this->_Container->Get(); $extraPlugins = array(); $pluginDir = JAWS_PATH . 'libraries/ckeditor/plugins/'; if (is_dir($pluginDir)) { $dirs = scandir($pluginDir); foreach ($dirs as $dir) { if ($dir[0] != '.' && is_dir($pluginDir . $dir)) { if (!in_array($dir, $this->_DefaultPlugins)) { $extraPlugins[] = $dir; } } } } $tpl = new Jaws_Template(); $tpl->Load('CKEditor.html', 'include/Jaws/Resources'); $block = JAWS_SCRIPT == 'admin' ? 'ckeditor_backend' : 'ckeditor_frontend'; $tpl->SetBlock($block); $tpl->SetVariable('name', $this->_Name); $tpl->SetVariable('baseUrl', Jaws_Utils::getBaseURL('/', true)); $tpl->SetVariable('contentsLangDirection', $this->_Direction); $tpl->SetVariable('language', $this->_Language); $tpl->SetVariable('AutoDetectLanguage', 'false'); $tpl->SetVariable('autoParagraph', 'false'); $tpl->SetVariable('height', $this->_Height); $tpl->SetVariable('skin', $this->_Skin); $tpl->SetVariable('theme', $this->_Theme); $tpl->SetVariable('readOnly', $this->_IsEnabled ? 'false' : 'true'); $tpl->SetVariable('resize_enabled', $this->_IsResizable ? 'true' : 'false'); $tpl->SetVariable('toolbar', json_encode($this->toolbars)); if (!empty($extraPlugins)) { $tpl->SetBlock("{$block}/extra"); $tpl->SetVariable('extraPlugins', implode(',', $extraPlugins)); $tpl->ParseBlock("{$block}/extra"); } // removed plugins $tpl->SetVariable('removePlugins', $this->_RemovePlugins); // direction if ('rtl' == $this->_Direction) { $tpl->SetVariable('contentsCss', 'gadgets/ControlPanel/Resources/ckeditor.rtl.css'); } else { $tpl->SetVariable('contentsCss', 'gadgets/ControlPanel/Resources/ckeditor.css'); } // FileBrowser if (Jaws_Gadget::IsGadgetInstalled('FileBrowser')) { $tpl->SetBlock("{$block}/filebrowser"); $tpl->SetVariable('filebrowserBrowseUrl', BASE_SCRIPT . '?gadget=FileBrowser&action=BrowseFile'); $tpl->SetVariable('filebrowserFlashBrowseUrl', BASE_SCRIPT . '?gadget=FileBrowser&action=BrowseFile'); $tpl->ParseBlock("{$block}/filebrowser"); } // Phoo if (Jaws_Gadget::IsGadgetInstalled('Phoo')) { $tpl->SetBlock("{$block}/phoo"); $tpl->SetVariable('filebrowserImageBrowseUrl', BASE_SCRIPT . '?gadget=Phoo&action=BrowsePhoo'); $tpl->ParseBlock("{$block}/phoo"); } // Directory if (Jaws_Gadget::IsGadgetInstalled('Directory')) { $tpl->SetBlock("{$block}/directory"); $tpl->SetVariable('filebrowserFlashBrowseUrl', BASE_SCRIPT . '?gadget=Directory&action=Browse'); $tpl->ParseBlock("{$block}/directory"); } $tpl->ParseBlock($block); $this->_XHTML .= $tpl->Get(); }
/** * Builds a pre-filled form * * @access private * @param string $title Page title * @param string $fast_url Fast URL * @param string $meta_keys Meta keywords * @param string $meta_desc Meta description * @param string $tags Tags (comma separated) * @param string $content Page content * @param bool $published Whether 'published' is checked or not * @param bool $show_title Whether 'show_title' is checked or not * @param string $language Page language * @param int $id Page ID * @param int $gid Group ID * @param string $action The action to perform on page submit * @param string $mode The mode we are using (base by default or translation) * @return string XHTML form */ function CreateForm($title, $fast_url, $meta_keys, $meta_desc, $tags, $content, $published, $show_title, $language, $id, $gid, $action, $mode = 'base') { $this->AjaxMe('script.js'); $tpl = $this->gadget->template->loadAdmin('StaticPage.html'); $tpl->SetBlock('pageform'); $m_action = jaws()->request->fetch('action', 'get'); $tpl->SetVariable('menubar', $this->MenuBar($m_action)); $pageform =& Piwi::CreateWidget('Form', BASE_SCRIPT, 'post'); $pageform->Add(Piwi::CreateWidget('HiddenEntry', 'gadget', 'StaticPage')); $pageform->Add(Piwi::CreateWidget('HiddenEntry', 'action', $action)); if ($action == 'SaveEditTranslation') { $pageform->Add(Piwi::CreateWidget('HiddenEntry', 'trans_id', $id)); } else { $pageform->Add(Piwi::CreateWidget('HiddenEntry', 'page', $id)); } $vBox =& Piwi::CreateWidget('VBox'); $vBox->SetId('page_options'); $vBox->SetStyle('display:inline;'); $titleentry =& Piwi::CreateWidget('Entry', 'title', $title); $titleentry->SetTitle(_t('GLOBAL_TITLE')); $vBox->Add($titleentry); // Group if ($mode == 'base') { $model = $this->gadget->model->load('Group'); $groups = $model->GetGroups(); $combo =& Piwi::CreateWidget('Combo', 'group_id'); foreach ($groups as $group) { if (!$this->gadget->GetPermission('AccessGroup', $group['id'])) { continue; } $combo->AddOption($group['title'], $group['id']); } $combo->SetTitle(_t('STATICPAGE_GROUP')); $combo->SetDefault($gid); $vBox->Add($combo); } // Status $published = $published === true ? 1 : 0; $statCombo =& Piwi::CreateWidget('Combo', 'published'); $statCombo->AddOption(_t('STATICPAGE_DRAFT'), '0'); $statCombo->AddOption(_t('STATICPAGE_PUBLISHED'), '1'); $statCombo->SetDefault($published); $statCombo->setTitle(_t('STATICPAGE_STATUS')); $vBox->Add($statCombo); if ($mode == 'base') { //show title $show_title = $show_title == true ? 1 : 0; $titleShowCombo =& Piwi::CreateWidget('Combo', 'show_title'); $titleShowCombo->AddOption(_t('GLOBAL_YES'), '1'); $titleShowCombo->AddOption(_t('GLOBAL_NO'), '0'); $titleShowCombo->SetDefault($show_title); $titleShowCombo->setTitle(_t('STATICPAGE_SHOW_TITLE')); $vBox->Add($titleShowCombo); } $language = empty($language) ? $this->gadget->registry->fetch('site_language', 'Settings') : $language; $languageCombo =& Piwi::CreateWidget('Combo', 'language'); //Load the Settings AdminModel to get a list of all available languages $languages = Jaws_Utils::GetLanguagesList(); foreach ($languages as $langCode => $langName) { $languageCombo->AddOption($langName, $langCode); } $languageCombo->SetDefault($language); $languageCombo->setTitle(_t('STATICPAGE_PAGE_LANGUAGE')); $vBox->Add($languageCombo); // Advanced Options $btnAdvanced =& Piwi::CreateWidget('Button', 'btn_advanced', _t('STATICPAGE_ADVANCED_OPTIONS')); $btnAdvanced->AddEvent(ON_CLICK, "javascript:\$('#advanced_options').show(); \$(this).hide();"); $advBox =& Piwi::CreateWidget('VBox'); $advBox->SetId('advanced_options'); $advBox->SetStyle('display:none;'); // Fast URL if ($mode == 'base') { $fasturlentry =& Piwi::CreateWidget('Entry', 'fast_url', $fast_url); $fasturlentry->SetTitle(_t('STATICPAGE_FASTURL')); $fasturlentry->SetStyle('direction:ltr;'); $advBox->Add($fasturlentry); } // Meta Keywords $metaKeysEntry =& Piwi::CreateWidget('Entry', 'meta_keys', $meta_keys); $metaKeysEntry->SetTitle(_t('GLOBAL_META_KEYWORDS')); $advBox->Add($metaKeysEntry); // Meta Description $metaDescEntry =& Piwi::CreateWidget('Entry', 'meta_desc', $meta_desc); $metaDescEntry->SetTitle(_t('GLOBAL_META_DESCRIPTION')); $advBox->Add($metaDescEntry); // Tags if (Jaws_Gadget::IsGadgetInstalled('Tags')) { $tagsEntry =& Piwi::CreateWidget('Entry', 'tags', $tags); $tagsEntry->SetTitle(_t('GLOBAL_TAGS')); $advBox->Add($tagsEntry); } // Auto Draft if ($mode == 'base') { $autodraft = '<script type="text/javascript" language="javascript">setTimeout(\'startAutoDrafting();\', 1200000);</script>'; $tpl->SetVariable('autodraft', $autodraft); } $pageform->Add($vBox); $pageform->Add($advBox); $pageform->Add($btnAdvanced); // Editor $editor =& $GLOBALS['app']->LoadEditor('StaticPage', 'content', $content, false); $editor->TextArea->SetRows(12); $editor->TextArea->SetStyle('width:100%;'); $pageform->Add($editor); if ($mode == 'base') { if ($action == 'AddPage') { $submit =& Piwi::CreateWidget('Button', 'newpage', _t('STATICPAGE_ADD_PAGE'), STOCK_SAVE); } else { $submit =& Piwi::CreateWidget('Button', 'editpage', _t('STATICPAGE_UPDATE_PAGE'), STOCK_SAVE); $btnDelete =& Piwi::CreateWidget('Button', 'delpage', _t('GLOBAL_DELETE'), STOCK_DELETE); $btnDelete->AddEvent(ON_CLICK, "javascript:deletePage({$id}, true);"); } } else { if ($action == 'AddTranslation') { $submit =& Piwi::CreateWidget('Button', 'newpagetrans', _t('STATICPAGE_ADD_TRANSLATION'), STOCK_SAVE); } else { $submit =& Piwi::CreateWidget('Button', 'editpagetrans', _t('STATICPAGE_UPDATE_TRANSLATION'), STOCK_SAVE); $btnDelete =& Piwi::CreateWidget('Button', 'delpagetrans', _t('GLOBAL_DELETE'), STOCK_DELETE); $btnDelete->AddEvent(ON_CLICK, "javascript:deleteTranslation({$id}, true);"); } } $submit->SetSubmit(); $cancel =& Piwi::CreateWidget('Button', 'cancel', _t('GLOBAL_CANCEL'), STOCK_CANCEL); ///FIXME use the proper url stuff $cancel->AddEvent(ON_CLICK, "javascript:window.location = '" . BASE_SCRIPT . '?gadget=StaticPage' . "';"); $preview =& Piwi::CreateWidget('Button', 'preview', _t('GLOBAL_PREVIEW'), STOCK_PRINT_PREVIEW); $preview->AddEvent(ON_CLICK, 'javascript:parseText(this.form);'); $buttonbox =& Piwi::CreateWidget('HBox'); $buttonbox->SetClass('actions'); $buttonbox->SetStyle(_t('GLOBAL_LANG_DIRECTION') == 'rtl' ? 'float: left;' : 'float: right;'); $buttonbox->PackStart($preview); $buttonbox->PackStart($cancel); if (isset($btnDelete) && $this->gadget->GetPermission('DeletePage')) { $buttonbox->PackStart($btnDelete); } $buttonbox->PackStart($submit); $pageform->Add($buttonbox); $tpl->setVariable('preview_header', _t('GLOBAL_PREVIEW')); $tpl->SetVariable('form', $pageform->Get()); $tpl->SetVariable('confirmPageDelete', _t('GLOBAL_CONFIRM_DELETE', _t('STATICPAGE_PAGE'))); $tpl->ParseBlock('pageform'); return $tpl->Get(); }
/** * Delete link * * @access public * @param int $lid Link's id * @param string $gid Group ID * @param int $rank * @return mixed True on success on Jaws_Error otherwise */ function DeleteLink($lid, $gid = '', $rank = 0) { $objORM = Jaws_ORM::getInstance(); $res = $objORM->delete()->table('linkdump_links')->where('id', $lid)->exec(); if (Jaws_Error::IsError($res)) { $GLOBALS['app']->Session->PushLastResponse(_t('LINKDUMP_LINKS_DELETE_ERROR'), RESPONSE_ERROR); return $res; } $this->MoveLink($lid, $gid, $gid, 0xfff, $rank); if (Jaws_Gadget::IsGadgetInstalled('Tags')) { $model = Jaws_Gadget::getInstance('Tags')->model->loadAdmin('Tags'); $res = $model->DeleteReferenceTags('LinkDump', 'link', $lid); if (Jaws_Error::IsError($res)) { $GLOBALS['app']->Session->PushLastResponse(_t('LINKDUMP_LINKS_DELETE_ERROR'), RESPONSE_ERROR); return $res; } } $this->InvalidateFeed($gid); $GLOBALS['app']->Session->PushLastResponse(_t('LINKDUMP_LINKS_DELETED'), RESPONSE_NOTICE); return true; }
/** * Delete a group * * @access public * @param int $gid group ID * @return bool True if query was successful and false on error */ function DeleteGroup($gid) { if ($gid == 1) { $GLOBALS['app']->Session->PushLastResponse(_t('LINKDUMP_GROUPS_NOT_DELETABLE'), RESPONSE_ERROR); return false; } $model = $this->gadget->model->load('Groups'); $group = $model->GetGroup($gid); if (Jaws_Error::IsError($group)) { $GLOBALS['app']->Session->PushLastResponse(_t('GLOBAL_ERROR_QUERY_FAILED'), RESPONSE_ERROR); return false; } if (!isset($group['id'])) { $GLOBALS['app']->Session->PushLastResponse(_t('LINKDUMP_GROUPS_NOT_EXISTS'), RESPONSE_ERROR); return false; } if (Jaws_Gadget::IsGadgetInstalled('Tags')) { $links = $model->GetGroupLinks($gid); $model = Jaws_Gadget::getInstance('Tags')->model->loadAdmin('Tags'); foreach ($links as $link) { $res = $model->DeleteReferenceTags('LinkDump', 'link', $link['id']); if (Jaws_Error::IsError($res)) { $GLOBALS['app']->Session->PushLastResponse(_t('GLOBAL_ERROR_QUERY_FAILED'), RESPONSE_ERROR); return false; } } } $objORM = Jaws_ORM::getInstance()->table('linkdump_links'); $res = $objORM->delete()->where('gid', $gid)->exec(); if (Jaws_Error::IsError($res)) { $GLOBALS['app']->Session->PushLastResponse(_t('GLOBAL_ERROR_QUERY_FAILED'), RESPONSE_ERROR); return false; } $res = $objORM->delete()->table('linkdump_groups')->where('id', $gid)->exec(); if (Jaws_Error::IsError($res)) { $GLOBALS['app']->Session->PushLastResponse(_t('GLOBAL_ERROR_QUERY_FAILED'), RESPONSE_ERROR); return false; } $GLOBALS['app']->Session->PushLastResponse(_t('LINKDUMP_GROUPS_DELETED', $gid), RESPONSE_NOTICE); return true; }
/** * Calls default action * * @access public * @return string XHTML template content */ function DefaultAction() { $gadgetsections = array(); $cmpModel = Jaws_Gadget::getInstance('Components')->model->load('Gadgets'); $gadgets = $cmpModel->GetGadgetsList(null, true, true); unset($gadgets['ControlPanel']); foreach ($gadgets as $gadget => $gInfo) { if ($this->gadget->GetPermission('default_admin', '', $gadget)) { $section = $gInfo['section']; if (!isset($gadgetsections[$section])) { $gadgetsections[$section] = array(); } $gadgetsections[$section][] = array('name' => $gadget, 'tname' => $gInfo['title'], 'desc' => $gInfo['description']); } } if ($this->gadget->registry->fetch('show_viewsite', 'Settings') == 'true') { $gadgetsections['general'][] = array('name' => 'Index', 'tname' => _t('GLOBAL_VIEW_SITE'), 'desc' => _t('GLOBAL_VIEW_SITE')); } // Load the template $tpl = $this->gadget->template->loadAdmin('ControlPanel.html'); $this->AjaxMe('script.js'); foreach ($gadgetsections as $section => $gadgets) { $tpl->SetBlock('main'); $tpl->SetVariable('title', _t('GLOBAL_GI_' . strtoupper($section))); foreach ($gadgets as $gadget) { $tpl->SetBlock('main/item'); $tpl->SetVariable('name', $gadget['tname']); $tpl->SetVariable('desc', $gadget['desc']); if ($gadget['name'] === 'Index') { $tpl->SetVariable('icon', Jaws::CheckImage('gadgets/ControlPanel/Resources/images/view_site.png')); $tpl->SetVariable('url', $GLOBALS['app']->getSiteURL('/')); } else { $tpl->SetVariable('icon', Jaws::CheckImage('gadgets/' . $gadget['name'] . '/Resources/images/logo.png')); $tpl->SetVariable('url', BASE_SCRIPT . '?gadget=' . $gadget['name']); } $tpl->ParseBlock('main/item'); } $tpl->ParseBlock('main'); } if ($this->gadget->GetPermission('default_admin', '', 'Components')) { //Count non-installed gadgets $noninstalled = $cmpModel->GetGadgetsList(null, false); if (count($noninstalled) > 0) { $tpl->SetBlock('notifybox'); $tpl->SetVariable('title', _t('COMPONENTS_GADGETS_NOTINSTALLED')); foreach ($noninstalled as $key => $gadget) { $tpl->SetBlock('notifybox/item'); $gadgetCompleteDesc = $gadget['title'] . ' - ' . $gadget['description']; $icon = Jaws::CheckImage('gadgets/' . $key . '/Resources/images/logo.png'); $tpl->SetVariable('title', $gadgetCompleteDesc); $tpl->SetVariable('name', $gadget['title']); $tpl->SetVariable('icon', $icon); $tpl->SetVariable('url', BASE_SCRIPT . '?gadget=Components&action=InstallGadget&comp=' . $key); $tpl->SetVariable('install', _t('COMPONENTS_INSTALL')); $tpl->ParseBlock('notifybox/item'); } $tpl->ParseBlock('notifybox'); } //Count out date gadgets $nonupdated = $cmpModel->GetGadgetsList(null, true, false); if (count($nonupdated) > 0) { $tpl->SetBlock('notifybox'); $tpl->SetVariable('title', _t('COMPONENTS_GADGETS_OUTDATED')); foreach ($nonupdated as $key => $gadget) { $tpl->SetBlock('notifybox/item'); $gadgetCompleteDesc = $gadget['title'] . ' - ' . $gadget['description']; $icon = Jaws::CheckImage('gadgets/' . $key . '/Resources/images/logo.png'); $tpl->SetVariable('title', $gadgetCompleteDesc); $tpl->SetVariable('name', $gadget['title']); $tpl->SetVariable('icon', $icon); $tpl->SetVariable('url', BASE_SCRIPT . '?gadget=Components&action=UpgradeGadget&comp=' . $key); $tpl->SetVariable('install', _t('COMPONENTS_UPDATE')); $tpl->ParseBlock('notifybox/item'); } $tpl->ParseBlock('notifybox'); } } // login history if (Jaws_Gadget::IsGadgetInstalled('Logs')) { $logModel = Jaws_Gadget::getInstance('Logs')->model->load('Logs'); $logs = $logModel->GetLogs(array('gadget' => 'Users', 'action' => 'Login', 'user' => $GLOBALS['app']->Session->GetAttribute('user')), 10); if (!Jaws_Error::IsError($logs) && !empty($logs)) { $tpl->SetBlock('login_history'); $date = Jaws_Date::getInstance(); $tpl->SetVariable('title', _t('LOGS_LOGIN_HISTORY')); foreach ($logs as $log) { $tpl->SetBlock('login_history/item'); $tpl->SetVariable('ip', long2ip($log['ip'])); $tpl->SetVariable('agent', $log['agent']); $tpl->SetVariable('status_code', $log['status']); $tpl->SetVariable('status_title', _t('GLOBAL_HTTP_ERROR_TITLE_' . $log['status'])); $tpl->SetVariable('icon', 'images/stock/' . ($log['status'] == 200 ? 'info.png' : 'stop.png')); $tpl->SetVariable('date', $date->Format($log['insert_time'], 'd MN Y H:i')); $tpl->ParseBlock('login_history/item'); } $tpl->ParseBlock('login_history'); } } $last_checking = unserialize($this->gadget->registry->fetch('update_last_checking')); $do_checking = time() - $last_checking['time'] > 86400; // lesser do checking if need check $do_checking = $do_checking && mt_rand(1, 10) == mt_rand(1, 10); $tpl->SetBlock('versionbox'); $tpl->SetVariable('do_checking', (int) $do_checking); $tpl->SetVariable('jaws_version', JAWS_VERSION); $tpl->SetVariable('latest_jaws_version', $last_checking['version']); $tpl->SetVariable('lbl_latest_jaws_version', _t('CONTROLPANEL_LATEST_JAWS_VERSION')); $tpl->ParseBlock('versionbox'); return $tpl->Get(); }
/** * 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(); }
/** * Get an entry * * @access public * @param int $id ID of the Entry * @param bool $published If it is true then get the entry only if it is published * @return mixed Properties of the entry(an array) and Jaws_Error on error */ function GetEntry($id, $published = false) { // super admins can get/show drafted entries $published = (bool) $published && !$GLOBALS['app']->Session->IsSuperAdmin(); $blogTable = Jaws_ORM::getInstance()->table('blog'); $blogTable->select('blog.id:integer', 'blog.user_id:integer', 'username', 'email', 'nickname', 'blog.title', 'summary', 'text', 'fast_url', 'meta_keywords', 'meta_description', 'trackbacks', 'published:boolean', 'image', 'blog.publishtime', 'blog.updatetime', 'comments:integer', 'clicks:integer', 'allow_comments:boolean')->join('users', 'blog.user_id', 'users.id', 'left'); if (is_numeric($id)) { $blogTable->where('blog.id', $id); } else { $blogTable->where('blog.fast_url', $id); } if ($published) { // entry's author can get/show drafted entries $now = Jaws_DB::getInstance()->date(); $user = (int) $GLOBALS['app']->Session->GetAttribute('user'); $blogTable->and()->openWhere('blog.user_id', $user)->or(); $blogTable->openWhere('published', $published)->and()->closewhere('blog.publishtime', $now, '<='); $blogTable->closeWhere(); } $row = $blogTable->fetchRow(); if (Jaws_Error::IsError($row)) { return new Jaws_Error(_t('BLOG_ERROR_GETTING_ENTRY')); } $entry = array(); if (!empty($row)) { $model = $this->gadget->model->load('Categories'); $entry = $row; $entry['avatar_source'] = Jaws_Gravatar::GetGravatar($row['email']); $entry['categories'] = $model->GetCategoriesInEntry($row['id']); if (empty($entry['categories'])) { $entry['categories'][] = array('id' => 0, 'name' => _t('BLOG_UNCATEGORIZED'), 'fast_url' => ''); } $entry['tags'] = array(); if (Jaws_Gadget::IsGadgetInstalled('Tags')) { $model = Jaws_Gadget::getInstance('Tags')->model->loadAdmin('Tags'); $tags = $model->GetReferenceTags('Blog', 'post', $row['id']); $entry['tags'] = array_filter($tags); } } return $entry; }
/** * Updates file * * @access public * @return array Response array */ function UpdateFile() { try { // Validate data $data = jaws()->request->fetch(array('id', 'title', 'description', 'parent', 'hidden', 'user_filename', 'host_filename', 'filetype', 'filesize')); if (empty($data['title'])) { throw new Exception(_t('DIRECTORY_ERROR_INCOMPLETE_DATA')); } $data['title'] = Jaws_XSS::defilter($data['title']); $data['description'] = Jaws_XSS::defilter($data['description']); $model = $this->gadget->model->loadAdmin('Files'); // Validate file $id = (int) $data['id']; $file = $model->GetFile($id); if (Jaws_Error::IsError($file)) { throw new Exception($file->getMessage()); } // Upload file $path = $GLOBALS['app']->getDataURL('directory'); if (!is_dir($path)) { if (!Jaws_Utils::mkdir($path, 2)) { throw new Exception('DIRECTORY_ERROR_FILE_UPLOAD'); } } $res = Jaws_Utils::UploadFiles($_FILES, $path, '', null); if (Jaws_Error::IsError($res)) { throw new Exception($res->getMessage()); } else { if ($res !== false) { $data['host_filename'] = $res['file'][0]['host_filename']; $data['user_filename'] = $res['file'][0]['user_filename']; $data['filetype'] = $res['file'][0]['host_filetype']; $data['filesize'] = $res['file'][0]['host_filesize']; } else { if ($data['host_filename'] === ':nochange:') { unset($data['host_filename']); } else { if (empty($data['host_filename'])) { throw new Exception(_t('DIRECTORY_ERROR_FILE_UPLOAD')); } else { $filename = Jaws_Utils::upload_tmp_dir() . '/' . $data['host_filename']; if (file_exists($filename)) { $target = $path . '/' . $data['host_filename']; $res = Jaws_Utils::rename($filename, $target, false); if ($res === false) { throw new Exception(_t('DIRECTORY_ERROR_FILE_UPLOAD')); } $data['host_filename'] = basename($res); } else { throw new Exception(_t('DIRECTORY_ERROR_FILE_UPLOAD')); } } } } } // Update file in database unset($data['user']); $data['updatetime'] = time(); $data['hidden'] = $data['hidden'] ? true : false; $model = $this->gadget->model->loadAdmin('Files'); $res = $model->Update($id, $data); if (Jaws_Error::IsError($res)) { throw new Exception(_t('DIRECTORY_ERROR_FILE_UPDATE')); } // Update Tags if (Jaws_Gadget::IsGadgetInstalled('Tags')) { $tags = jaws()->request->fetch('tags'); $tModel = Jaws_Gadget::getInstance('Tags')->model->loadAdmin('Tags'); $tModel->UpdateReferenceTags('Directory', 'file', $id, !$data['hidden'], time(), $tags); } } catch (Exception $e) { return $GLOBALS['app']->Session->GetResponse($e->getMessage(), RESPONSE_ERROR); } return $GLOBALS['app']->Session->GetResponse(_t('DIRECTORY_NOTICE_FILE_UPDATED'), RESPONSE_NOTICE); }
/** * Deletes the translation * * @access public * @param int $id Translation ID * @return mixed True on success or Jaws_Error on failure */ function DeleteTranslation($id) { $params = array(); $params['id'] = $id; if (!$this->gadget->GetPermission('ModifyOthersPages')) { $translation = $this->GetPageTranslation($id); if (Jaws_Error::isError($translation)) { $GLOBALS['app']->Session->PushLastResponse(_t('STATICPAGE_ERROR_TRANSLATION_NOT_EXISTS'), RESPONSE_ERROR); return new Jaws_Error(_t('STATICPAGE_ERROR_TRANSLATION_NOT_EXISTS')); } if ($GLOBALS['app']->Session->GetAttribute('user') != $translation['user']) { $GLOBALS['app']->Session->PushLastResponse(_t('STATICPAGE_ERROR_TRANSLATION_NOT_DELETED'), RESPONSE_ERROR); return new Jaws_Error(_t('STATICPAGE_ERROR_TRANSLATION_NOT_DELETED')); } } $sptTable = Jaws_ORM::getInstance()->table('static_pages_translation'); $result = $sptTable->delete()->where('translation_id', $id)->exec(); if (Jaws_Error::IsError($result)) { $GLOBALS['app']->Session->PushLastResponse(_t('STATICPAGE_ERROR_TRANSLATION_NOT_DELETED'), RESPONSE_ERROR); return new Jaws_Error(_t('STATICPAGE_ERROR_TRANSLATION_NOT_DELETED')); } if (Jaws_Gadget::IsGadgetInstalled('Tags')) { $model = Jaws_Gadget::getInstance('Tags')->model->loadAdmin('Tags'); $res = $model->DeleteReferenceTags('StaticPage', 'page', $id); if (Jaws_Error::IsError($res)) { $GLOBALS['app']->Session->PushLastResponse(_t('STATICPAGE_ERROR_TAG_NOT_DELETED'), RESPONSE_ERROR); return $res; } } $GLOBALS['app']->Session->PushLastResponse(_t('STATICPAGE_TRANSLATION_DELETED'), RESPONSE_NOTICE); return true; }
/** * Build the XHTML * * @access public * @return void */ function buildXHTML() { static $alreadyLoaded; $alreadyLoaded = isset($alreadyLoaded) ? true : false; $plugins = array(); $lang = $GLOBALS['app']->GetLanguage(); $pluginDir = JAWS_PATH . 'libraries/tinymce/plugins/'; if (is_dir($pluginDir)) { $dirs = scandir($pluginDir); foreach ($dirs as $dir) { if ($dir[0] != '.' && is_dir($pluginDir . $dir)) { $plugins[] = $dir; } } } $plugins = implode(',', $plugins); $label = $this->_Label->GetValue(); if (!empty($label)) { $this->_Container->PackStart($this->_Label); } $this->_Container->PackStart($this->TextArea); $this->_Container->SetWidth($this->_Width); $this->_XHTML .= $this->_Container->Get(); $ibrowser = ''; if (Jaws_Gadget::IsGadgetInstalled('Phoo')) { $ibrowser = $GLOBALS['app']->getSiteURL() . '/' . BASE_SCRIPT . '?gadget=Phoo&action=BrowsePhoo'; } $fbrowser = ''; if (Jaws_Gadget::IsGadgetInstalled('FileBrowser')) { $fbrowser = $GLOBALS['app']->getSiteURL() . '/' . BASE_SCRIPT . '?gadget=FileBrowser&action=BrowseFile'; } $mbrowser = ''; if (Jaws_Gadget::IsGadgetInstalled('Directory')) { $mbrowser = $GLOBALS['app']->getSiteURL() . '/' . BASE_SCRIPT . '?gadget=Directory&action=Browse'; } if (JAWS_SCRIPT == 'admin') { $plugins = str_replace(',bbcode,', ',', $plugins); $block = 'tinymce_backend'; } else { $block = 'tinymce_frontend'; } $tpl = new Jaws_Template(); $tpl->Load('TinyMCE.html', 'include/Jaws/Resources'); $tpl->SetBlock($block); $tpl->SetVariable('ibrowser', $ibrowser); $tpl->SetVariable('fbrowser', $fbrowser); $tpl->SetVariable('mbrowser', !empty($mbrowser) ? $mbrowser : $fbrowser); $tpl->SetVariable('mode', $this->_Mode); $tpl->SetVariable('lang', $lang); $tpl->SetVariable('theme', $this->_Theme); $tpl->SetVariable('plugins', $plugins); // set toolbars $index = 0; foreach ($this->toolbars as $key => $toolbar) { $tpl->SetBlock("{$block}/toolbar"); $index = $key + 1; $tpl->SetVariable('theme', $this->_Theme); $tpl->SetVariable('key', $index); $tpl->SetVariable('toolbar', $toolbar); $tpl->ParseBlock("{$block}/toolbar"); } $index = $index + 1; $tpl->SetVariable('key', $index); $tpl->SetVariable('browsers', implode($this->_Browsers, ',')); $tpl->SetVariable('dir', _t('GLOBAL_LANG_DIRECTION')); $tpl->SetVariable('valid_elements', $this->_ExtendedValidElements); $tpl->SetVariable('invalid_elements', $this->_InvalidElements); $tpl->SetVariable('class', $this->_Class); $tpl->ParseBlock($block); $this->_XHTML .= $tpl->Get(); }
/** * Deletes the page and all of its translations * * @access public * @param int $id Page ID * @return mixed True on success or Jaws_Error on failure */ function DeletePage($id) { if (!$this->gadget->GetPermission('ModifyOthersPages')) { $user = $GLOBALS['app']->Session->GetAttribute('user'); $sptTable = Jaws_ORM::getInstance()->table('static_pages_translation'); $sptTable->select('count(base_id)')->where('base_id', $id)->and()->where('user', $user, '<>'); $result = $sptTable->fetchOne(); if (Jaws_Error::IsError($result) || $result > 0) { // FIXME: need new language statement $GLOBALS['app']->Session->PushLastResponse(_t('STATICPAGE_ERROR_PAGE_NOT_DELETED'), RESPONSE_ERROR); return new Jaws_Error(_t('STATICPAGE_ERROR_PAGE_NOT_DELETED')); } } // Delete Page Translation Tags if (Jaws_Gadget::IsGadgetInstalled('Tags')) { $sptTable = Jaws_ORM::getInstance()->table('static_pages_translation'); $tIds = $sptTable->select('translation_id:integer')->where('base_id', $id)->fetchColumn(); $model = Jaws_Gadget::getInstance('Tags')->model->loadAdmin('Tags'); $res = $model->DeleteReferenceTags('StaticPage', 'page', $tIds); if (Jaws_Error::IsError($res)) { $GLOBALS['app']->Session->PushLastResponse(_t('STATICPAGE_ERROR_TAG_NOT_DELETED'), RESPONSE_ERROR); return $res; } } $sptTable = Jaws_ORM::getInstance()->table('static_pages_translation'); $result = $sptTable->delete()->where('base_id', $id)->exec(); if (Jaws_Error::IsError($result)) { $GLOBALS['app']->Session->PushLastResponse(_t('GLOBAL_ERROR_QUERY_FAILED'), RESPONSE_ERROR); return new Jaws_Error(_t('GLOBAL_ERROR_QUERY_FAILED')); } $spTable = Jaws_ORM::getInstance()->table('static_pages'); $result = $spTable->delete()->where('page_id', $id)->exec(); if (Jaws_Error::IsError($result)) { $GLOBALS['app']->Session->PushLastResponse(_t('STATICPAGE_ERROR_PAGE_NOT_DELETED'), RESPONSE_ERROR); return new Jaws_Error(_t('STATICPAGE_ERROR_PAGE_NOT_DELETED')); } $GLOBALS['app']->Session->PushLastResponse(_t('STATICPAGE_PAGE_DELETED'), RESPONSE_NOTICE); return true; }
/** * Deletes passed file(s)/directorie(s) * * @access public * @return mixed Response array */ function Delete() { $id_set = jaws()->request->fetch('id_set'); $id_set = explode(',', $id_set); if (empty($id_set)) { return $GLOBALS['app']->Session->GetResponse(_t('DIRECTORY_ERROR_DELETE'), RESPONSE_ERROR); } $model = $this->gadget->model->loadAdmin('Files'); $user = (int) $GLOBALS['app']->Session->GetAttribute('user'); $fault = false; foreach ($id_set as $id) { // Validate file $file = $model->GetFile($id); if (Jaws_Error::IsError($file)) { $fault = true; continue; } // Delete file/directory $res = $model->Delete($file); if (Jaws_Error::IsError($res)) { $fault = true; } // Delete tags if (Jaws_Gadget::IsGadgetInstalled('Tags')) { $tModel = Jaws_Gadget::getInstance('Tags')->model->loadAdmin('Tags'); $tModel->DeleteReferenceTags('Directory', 'file', $id); } } if ($fault === true) { return $GLOBALS['app']->Session->GetResponse(_t('DIRECTORY_WARNING_DELETE'), RESPONSE_WARNING); } else { return $GLOBALS['app']->Session->GetResponse(_t('DIRECTORY_NOTICE_ITEMS_DELETED'), RESPONSE_NOTICE); } }