/** * Returns an array with the results of a search * * @access public * @param string $pSql Prepared search(WHERE) SQL * @return array An array of entries that matches a certain pattern */ function Execute($pSql = '') { $params = array(); $sql = ' SELECT [id],[name], [title], [description], [meta_keywords], [meta_description] FROM [[tags]] '; if ($GLOBALS['app']->Session->Logged()) { $params['user'] = $GLOBALS['app']->Session->GetAttribute('user'); $wStr = '([user]=0 OR [user]={user})'; } else { $wStr = '[user]=0'; } $sql .= ' WHERE ' . $wStr; $sql .= ' AND ' . $pSql; $sql .= ' ORDER BY [id] desc'; $types = array('integer', 'text', 'text', 'text', 'text', 'text'); $result = Jaws_DB::getInstance()->queryAll($sql, $params, $types); if (Jaws_Error::IsError($result)) { return array(); } $tags = array(); foreach ($result as $t) { $tag = array(); $tag['title'] = $t['title']; $url = $this->gadget->urlMap('ViewTag', array('tag' => $t['name'])); $tag['url'] = $url; $tag['image'] = 'gadgets/Tags/Resources/images/logo.png'; $tag['snippet'] = $t['description']; $tag['date'] = null; $tags[$t['id']] = $tag; } return $tags; }
/** * Retrieve banners that can be visible * * @access public * @param int $gid group ID * @param int $random * @return mixed An array of available banners or False on error */ function GetEnableBanners($gid = 0, $random = 0) { $bannersTable = Jaws_ORM::getInstance()->table('banners'); $bannersTable->select('id:integer', 'title', 'url', 'banner', 'template'); $bannersTable->where('published', true)->and()->where('random', $random)->and(); $bannersTable->openWhere('views_limitation', 0)->or(); $bannersTable->closeWhere('views', $bannersTable->expr('views_limitation'), '<')->and(); $bannersTable->openWhere('clicks_limitation', 0)->or(); $bannersTable->closeWhere('clicks', $bannersTable->expr('clicks_limitation'), '<')->and(); $bannersTable->openWhere('start_time', '', 'is null')->or(); $bannersTable->closeWhere('start_time', Jaws_DB::getInstance()->date(), '<=')->and(); $bannersTable->openWhere('stop_time', '', 'is null')->or(); $bannersTable->closeWhere('stop_time', Jaws_DB::getInstance()->date(), '>='); if ($gid == 0) { $bannersTable->orderBy('id asc'); } else { $bannersTable->and()->where('gid', $gid); $bannersTable->orderBy('id asc'); } $res = $bannersTable->fetchAll(); if (Jaws_Error::IsError($res)) { return false; } return $res; }
/** * Returns an array with the results of a search * * @access public * @param string $pSql Prepared search(WHERE) SQL * @return array An array of entries that matches a certain pattern */ function Execute($pSql = '') { $sql = ' SELECT [id], [title], [description], [user_filename], [update_time] FROM [[directory]] WHERE [hidden] = {hidden} '; $sql .= ' AND ' . $pSql; $sql .= ' ORDER BY id desc'; $params = array(); $params['hidden'] = false; $types = array('text', 'text', 'text', 'integer'); $result = Jaws_DB::getInstance()->queryAll($sql, $params, $types); if (Jaws_Error::IsError($result)) { return array(); } $date = Jaws_Date::getInstance(); $files = array(); foreach ($result as $p) { $file = array(); $file['title'] = $p['title']; $file['url'] = $this->gadget->urlMap('Directory', array('id' => $p['id'])); $file['image'] = 'gadgets/Directory/Resources/images/logo.png'; $file['snippet'] = $p['description']; $file['date'] = $p['update_time']; $stamp = $p['update_time']; $files[$stamp] = $file; } return $files; }
/** * Returns an array with the results of a search * * @access public * @param string $pSql Prepared search (WHERE) SQL * @return array An array of entries that matches a certain pattern */ function Execute($pSql = '') { // TODO: must be converted to Jaws_ORM $sql = ' SELECT [id], [title], [contents], [updatetime] FROM [[blocks]] '; $sql .= ' WHERE ' . $pSql; $sql .= ' ORDER BY [createtime] desc'; $result = Jaws_DB::getInstance()->queryAll($sql); if (Jaws_Error::IsError($result)) { return array(); } $date = Jaws_Date::getInstance(); $blocks = array(); foreach ($result as $r) { $block = array(); $block['title'] = $r['title']; $block['url'] = $this->gadget->urlMap('Block', array('id' => $r['id'])); $block['image'] = 'gadgets/Blocks/Resources/images/logo.png'; $block['snippet'] = $r['contents']; $block['date'] = $date->ToISO($r['updatetime']); $blocks[] = $block; } return $blocks; }
/** * Adds a new term * * @acess public * @param string $term Term * @param string $fast_url * @param string $desc Term's description * @return mixed Returns true if term was added or Jaws_Error on error */ function NewTerm($term, $fast_url, $desc) { $fast_url = empty($fast_url) ? $term : $fast_url; $fast_url = $this->GetRealFastUrl($fast_url, 'glossary'); $now = Jaws_DB::getInstance()->date(); $params['term'] = $term; $params['fast_url'] = $fast_url; $params['description'] = $desc; $params['createtime'] = $now; $params['updatetime'] = $now; $glossaryTable = Jaws_ORM::getInstance()->table('glossary'); $result = $glossaryTable->insert($params)->exec(); if (Jaws_Error::IsError($result)) { $GLOBALS['app']->Session->PushLastResponse(_t('GLOSSARY_ERROR_TERM_NOT_CREATED'), RESPONSE_ERROR); return new Jaws_Error(_t('GLOSSARY_ERROR_TERM_NOT_CREATED')); } $GLOBALS['app']->Session->PushLastResponse(_t('GLOSSARY_TERM_ADDED'), RESPONSE_NOTICE); $glossaryTable = Jaws_ORM::getInstance()->table('glossary'); $row = $glossaryTable->select('id:integer')->where('createtime', $now)->fetchRow(); if (Jaws_Error::IsError($row)) { $GLOBALS['app']->Session->PushLastResponse(_t('GLOSSARY_ERROR_TERM_NOT_CREATED'), RESPONSE_ERROR); return new Jaws_Error(_t('GLOSSARY_ERROR_TERM_NOT_CREATED')); } if (isset($row['id'])) { return $row['id']; } return false; }
/** * Returns an array with the results of a search * * @access public * @param string $pSql Prepared search (WHERE) SQL * @return mixed An array of entries that matches a certain pattern or False on error */ function Execute($pSql = '') { $sql = ' SELECT [id], [term], [description], [createtime] FROM [[glossary]] '; $sql .= ' WHERE ' . $pSql; $sql .= " ORDER BY [createtime] desc"; $result = Jaws_DB::getInstance()->queryAll($sql); if (Jaws_Error::IsError($result)) { return false; } $date = Jaws_Date::getInstance(); $entries = array(); foreach ($result as $r) { $entry = array(); $entry['title'] = $r['term']; $entry['url'] = $this->gadget->urlMap('ViewTerm', array('term' => $r['id'])); $entry['image'] = 'gadgets/Glossary/Resources/images/logo.png'; $entry['snippet'] = $r['description']; $entry['date'] = $date->ToISO($r['createtime']); $stamp = str_replace(array('-', ':', ' '), '', $r['createtime']); $entries[$stamp] = $entry; } return $entries; }
/** * Create a new trackback * * @access public * @param int $parent_id ID of the entry * @param string $url URL of the trackback * @param string $title Title of the trackback * @param string $excerpt The Excerpt * @param string $blog_name The name of the Blog * @param string $ip The sender ip address * @return mixed True if trackback was successfully added, if not, returns Jaws_Error */ function NewTrackback($parent_id, $url, $title, $excerpt, $blog_name, $ip) { if ($this->gadget->registry->fetch('trackback') == 'true') { $model = $this->gadget->model->load('Posts'); if (!$model->DoesEntryExists($parent_id)) { return new Jaws_Error(_t('BLOG_ERROR_DOES_NOT_EXISTS')); } // lets only load it if it's actually needed $now = Jaws_DB::getInstance()->date(); $trackbackTable = Jaws_ORM::getInstance()->table('blog_trackback'); $trackbackTable->select('id:integer')->where('parent_id', $parent_id); $id = $trackbackTable->and()->where('url', strip_tags($url))->fetchOne(); $trackData['title'] = strip_tags($title); $trackData['excerpt'] = strip_tags($excerpt); $trackData['blog_name'] = strip_tags($blog_name); $trackData['updatetime'] = $now; $trackbackTable = Jaws_ORM::getInstance()->table('blog_trackback'); if (!Jaws_Error::IsError($id) && !empty($id)) { $trackbackTable->update($trackData)->where('id', $id); } else { $trackData['parent_id'] = $parent_id; $trackData['url'] = strip_tags($url); $trackData['ip'] = $ip; $trackData['status'] = $this->gadget->registry->fetch('trackback_status'); $trackData['createtime'] = $now; $trackbackTable->insert($trackData); } $result = $trackbackTable->exec(); if (Jaws_Error::IsError($result)) { return new Jaws_Error(_t('BLOG_ERROR_TRACKBACK_NOT_ADDED')); } return true; } return true; }
/** * Returns an array with the results of a search * * @access public * @param string $pSql Prepared search (WHERE) SQL * @return array An array of entries that matches a certain pattern */ function Execute($pSql = '') { $params = array('active' => true); $sql = ' SELECT [category], [question], [answer], [faq_position], [updatetime] FROM [[faq]] WHERE [published] = {active} '; $sql .= ' AND ' . $pSql; $sql .= ' ORDER BY [createtime] desc'; $result = Jaws_DB::getInstance()->queryAll($sql, $params); if (Jaws_Error::IsError($result)) { return array(); } $questions = array(); $date = Jaws_Date::getInstance(); foreach ($result as $r) { $question = array(); $question['title'] = $r['question']; $question['url'] = $this->gadget->urlMap('ViewCategory', array('id' => $r['category'])) . '#Question' . $r['faq_position']; $question['image'] = 'gadgets/Faq/Resources/images/logo.png'; $question['snippet'] = $r['answer']; $question['date'] = $date->ToISO($r['updatetime']); $questions[] = $question; } return $questions; }
/** * Returns downloadable backup file * * @access public * @return void */ function Backup() { $this->gadget->CheckPermission('Backup'); $tmpDir = sys_get_temp_dir(); $domain = preg_replace("/^(www.)|(:{$_SERVER['SERVER_PORT']})\$|[^a-z0-9\\-\\.]/", '', strtolower($_SERVER['HTTP_HOST'])); $nameArchive = $domain . '-' . date('Y-m-d') . '.tar.gz'; $pathArchive = $tmpDir . DIRECTORY_SEPARATOR . $nameArchive; //Dump database data $dbFileName = 'dbdump.xml'; $dbFilePath = $tmpDir . DIRECTORY_SEPARATOR . $dbFileName; Jaws_DB::getInstance()->Dump($dbFilePath); $files = array(); require_once PEAR_PATH . 'File/Archive.php'; $files[] = File_Archive::read(JAWS_DATA); $files[] = File_Archive::read($dbFilePath, $dbFileName); File_Archive::extract($files, File_Archive::toArchive($pathArchive, File_Archive::toFiles())); Jaws_Utils::Delete($dbFilePath); // browser must download file from server instead of cache header("Expires: 0"); header("Pragma: public"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); // force download dialog header("Content-Type: application/force-download"); // set data type, size and filename header("Content-Disposition: attachment; filename=\"{$nameArchive}\""); header("Content-Transfer-Encoding: binary"); header('Content-Length: ' . @filesize($pathArchive)); @readfile($pathArchive); Jaws_Utils::Delete($pathArchive); }
/** * Returns an array with the results of a search * * @access public * @param string $pSql Prepared search (WHERE) SQL * @return array An array of entries that matches a certain pattern */ function Execute($pSql = '') { $sql = ' SELECT [id], [title], [url], [description], [updatetime] FROM [[linkdump_links]] '; $sql .= ' WHERE ' . $pSql; $sql .= ' ORDER BY [createtime] desc'; $result = Jaws_DB::getInstance()->queryAll($sql); if (Jaws_Error::IsError($result)) { return array(); } $date = Jaws_Date::getInstance(); $links = array(); foreach ($result as $r) { $link = array(); $link['title'] = $r['title']; $link['url'] = $this->gadget->urlMap('Link', array('id' => $r['id'])); $link['outer'] = true; $link['image'] = 'gadgets/LinkDump/Resources/images/logo.png'; $link['snippet'] = $r['description']; $link['date'] = $date->ToISO($r['updatetime']); $links[] = $link; } return $links; }
/** * Sends email to user * * @access public * @param string $name Name * @param string $email Email address * @param string $company * @param string $url * @param string $tel * @param string $fax * @param string $mobile * @param string $address * @param string $rcipient Rcipient ID * @param string $subject Subject of message * @param string $attachment Attachment filename * @param string $message Message content * @return bool True on Success or False on Failure */ function InsertContact($name, $email, $company, $url, $tel, $fax, $mobile, $address, $recipient, $subject, $attachment, $message) { $now = Jaws_DB::getInstance()->date(); $data = array(); $data['[user]'] = $GLOBALS['app']->Session->GetAttribute('user'); $data['ip'] = $_SERVER['REMOTE_ADDR']; $data['name'] = $name; $data['email'] = $email; $data['company'] = $company; $data['url'] = $url; $data['tel'] = $tel; $data['fax'] = $fax; $data['mobile'] = $mobile; $data['address'] = $address; $data['recipient'] = (int) $recipient; $data['subject'] = $subject; $data['attachment'] = $attachment; $data['msg_txt'] = $message; $data['reply'] = ''; $data['reply_sent'] = 0; $data['createtime'] = $now; $data['updatetime'] = $now; $cntctTable = Jaws_ORM::getInstance()->table('contacts'); $result = $cntctTable->insert($data)->exec(); if (Jaws_Error::IsError($result)) { return false; } $GLOBALS['app']->Session->SetCookie('visitor_name', $name, 60 * 24 * 150); $GLOBALS['app']->Session->SetCookie('visitor_email', $email, 60 * 24 * 150); $GLOBALS['app']->Session->SetCookie('visitor_url', $url, 60 * 24 * 150); return $result; }
/** * Returns an array of the search results * * @access public * @param string $pSql Prepared search(WHERE) SQL * @return array Array of entries match a certain pattern */ function Execute($pSql = '') { $sql = ' SELECT [id], [title], [quotation], [updatetime] FROM [[quotes]] WHERE [published] = {published} '; $sql .= ' AND ' . $pSql; $sql .= ' ORDER BY [id] desc'; $params = array(); $params['published'] = true; $result = Jaws_DB::getInstance()->queryAll($sql, $params); if (Jaws_Error::IsError($result)) { return array(); } $date = Jaws_Date::getInstance(); $quotations = array(); foreach ($result as $r) { $quotation = array(); $quotation['title'] = $r['title']; $quotation['url'] = $this->gadget->urlMap('ViewQuote', array('id' => $r['id'])); $quotation['image'] = 'gadgets/Quotes/Resources/images/logo.png'; $quotation['snippet'] = $r['quotation']; $quotation['date'] = $date->ToISO($r['updatetime']); $quotations[] = $quotation; } return $quotations; }
/** * Updates a category entry * * @access public * @param int $cid Category ID * @param string $name Category name * @param string $description Category description * @param string $fast_url Category fast url * @param string $meta_keywords Meta keywords of the category * @param string $meta_desc Meta description of the category * @return mixed True on success, Jaws_Error on failure */ function UpdateCategory($cid, $name, $description, $fast_url, $meta_keywords, $meta_desc) { if (!$this->gadget->GetPermission('CategoryManage', $cid)) { $GLOBALS['app']->Session->PushLastResponse(_t('GLOBAL_ERROR_ACCESS_DENIED'), RESPONSE_ERROR); return false; } $fast_url = empty($fast_url) ? $name : $fast_url; $fast_url = $this->GetRealFastUrl($fast_url, 'blog_category', false); $params['name'] = $name; $params['description'] = $description; $params['fast_url'] = $fast_url; $params['meta_keywords'] = $meta_keywords; $params['meta_description'] = $meta_desc; $params['updatetime'] = Jaws_DB::getInstance()->date(); $catTable = Jaws_ORM::getInstance()->table('blog_category'); $result = $catTable->update($params)->where('id', $cid)->exec(); if (Jaws_Error::IsError($result)) { $GLOBALS['app']->Session->PushLastResponse(_t('BLOG_ERROR_CATEGORY_NOT_UPDATED'), RESPONSE_ERROR); return new Jaws_Error(_t('BLOG_ERROR_CATEGORY_NOT_UPDATED')); } if ($this->gadget->registry->fetch('generate_category_xml') == 'true') { $model = $this->gadget->model->load('Feeds'); $catAtom = $model->GetCategoryAtomStruct($cid); $model->MakeCategoryAtom($cid, $catAtom, true); $model->MakeCategoryRSS($cid, $catAtom, true); } $GLOBALS['app']->Session->PushLastResponse(_t('BLOG_CATEGORY_UPDATED'), RESPONSE_NOTICE); return true; }
/** * Update a question * * @access public * @param string $id Number of the question * @param array $data Question data * @return mixed True if question is succesfully updated, Jaws_Error if not */ function UpdateQuestion($id, $data) { $fast_url = empty($data['fast_url']) ? $data['question'] : $data['fast_url']; $data['fast_url'] = $this->GetRealFastUrl($fast_url, 'faq'); $data['updatetime'] = Jaws_DB::getInstance()->date(); $faqTable = Jaws_ORM::getInstance()->table('faq'); return $faqTable->update($data)->where('id', $id)->exec(); }
/** * Uninstalls the gadget * * @access public * @return mixed True on Success or Jaws_Error on Failure */ function Uninstall() { $result = Jaws_DB::getInstance()->dropTable('filebrowser'); if (Jaws_Error::IsError($result)) { $errMsg = _t('GLOBAL_ERROR_GADGET_NOT_UNINSTALLED', $this->gadget->title); return new Jaws_Error($errMsg); } return true; }
/** * Returns an array with the results of a search * * @access public * @param string $pSql Prepared search (WHERE) SQL * @return array An array of entries that matches a certain pattern */ function Execute($pSql = '') { $params = array('published' => true); $sql = ' SELECT [id], [title], [fast_url], [summary], [text], [categories], [createtime], [updatetime] FROM [[blog]] WHERE [published] = {published} AND [createtime] <= {now} '; $sql .= ' AND ' . $pSql; $sql .= ' ORDER BY [createtime] desc'; $params['now'] = Jaws_DB::getInstance()->date(); $params['published'] = true; $result = Jaws_DB::getInstance()->queryAll($sql, $params); if (Jaws_Error::IsError($result)) { return array(); } $date = Jaws_Date::getInstance(); $entries = array(); foreach ($result as $key => $r) { $permission = true; foreach (explode(",", $r['categories']) as $cat) { if (!$this->gadget->GetPermission('CategoryAccess', $cat)) { $permission = false; } } if (!$permission) { continue; } $entry = array(); $entry['title'] = $r['title']; if (empty($r['fast_url'])) { $url = $this->gadget->urlMap('SingleView', array('id' => $r['id'])); } else { $url = $this->gadget->urlMap('SingleView', array('id' => $r['fast_url'])); } $entry['url'] = $url; //FIXME: Will be great if we can get the first image in "text" $entry['image'] = 'gadgets/Blog/Resources/images/logo.png'; $entry['snippet'] = empty($r['summary']) ? $r['text'] : $r['summary']; $entry['date'] = $date->ToISO($r['createtime']); $stamp = str_replace(array('-', ':', ' '), '', $r['createtime']); $entries[$stamp] = $entry; } return $entries; }
/** * 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; }
/** * Uninstalls the gadget * * @access public * @return mixed True on success and Jaws_Error otherwise */ function Uninstall() { $tables = array('blog', 'blog_trackback', 'blog_category', 'blog_entrycat'); foreach ($tables as $table) { $result = Jaws_DB::getInstance()->dropTable($table); if (Jaws_Error::IsError($result)) { $errMsg = _t('GLOBAL_ERROR_GADGET_NOT_UNINSTALLED', $this->gadget->title); return new Jaws_Error($errMsg); } } return true; }
/** * Uninstalls the gadget * * @access public * @return mixed True on Success and Jaws_Error on Failure */ function Uninstall() { $tables = array('address_book', 'address_group', 'address_book_group'); foreach ($tables as $table) { $result = Jaws_DB::getInstance()->dropTable($table); if (Jaws_Error::IsError($result)) { $errMsg = _t('GLOBAL_ERROR_GADGET_NOT_UNINSTALLED', $this->gadget->title); return new Jaws_Error($errMsg); } } return true; }
/** * Uninstalls the gadget * * @access public * @return mixed True on success and Jaws_Error otherwise */ function Uninstall() { $tables = array('pm_message_attachment', 'pm_messages', 'pm_attachments'); foreach ($tables as $table) { $result = Jaws_DB::getInstance()->dropTable($table); if (Jaws_Error::IsError($result)) { $errMsg = _t('GLOBAL_ERROR_GADGET_NOT_UNINSTALLED', $this->gadget->title); return new Jaws_Error($errMsg); } } return true; }
/** * Gets the last visible poll * * @access public * @return mixed An array with the last visible and returns Jaws_Error or false on error */ function GetLastPoll() { $now = Jaws_DB::getInstance()->date(); $table = Jaws_ORM::getInstance()->table('poll'); $table->select('id', 'gid', 'question', 'select_type', 'poll_type', 'result_view', 'start_time', 'stop_time', 'visible'); $table->where('visible', 1)->and(); $table->openWhere()->where('start_time', '', 'is null')->or(); $table->where('start_time', $now, '>=')->closeWhere()->and(); $table->openWhere()->where('stop_time', '', 'is null')->or(); $table->where('stop_time', $now, '<=')->closeWhere(); return $table->orderBy('id')->fetchRow(); }
/** * Builds the upgrader page. * * @access public * @return string A block of valid XHTML to display the status of old/current jaws versions */ function Display() { include_once JAWS_PATH . 'include/Jaws/DB.php'; $objDatabase = Jaws_DB::getInstance('default', $_SESSION['upgrade']['Database']); require_once JAWS_PATH . 'include/Jaws.php'; $GLOBALS['app'] = jaws(); if (!isset($_SESSION['upgrade']['InstalledVersion'])) { $_SESSION['upgrade']['InstalledVersion'] = $GLOBALS['app']->Registry->Init(); } $GLOBALS['app']->loadPreferences(array('language' => $_SESSION['upgrade']['language']), false); $supportedversions = array(array('version' => '1.2.0', 'stage' => '9'), array('version' => '1.1.1', 'stage' => '8'), array('version' => '1.1.0', 'stage' => '7'), array('version' => '1.0.0', 'stage' => '6'), array('version' => '0.9.3', 'stage' => null), array('version' => '0.9.2', 'stage' => null), array('version' => '0.9.1', 'stage' => null), array('version' => '0.9.0', 'stage' => null)); _log(JAWS_LOG_DEBUG, "Checking/Reporting previous missed installations"); $tpl = new Jaws_Template(false, false); $tpl->Load('display.html', 'stages/Report/templates'); $tpl->SetBlock('Report'); $tpl->setVariable('lbl_info', _t('UPGRADE_REPORT_INFO', JAWS_VERSION)); $tpl->setVariable('lbl_message', _t('UPGRADE_REPORT_MESSAGE')); $tpl->SetVariable('next', _t('GLOBAL_NEXT')); $versions_to_upgrade = 0; $_SESSION['upgrade']['stagedVersions'] = array(); foreach ($supportedversions as $supported) { $tpl->SetBlock('Report/versions'); $tpl->SetBlock('Report/versions/version'); $tpl->SetVariable('description', $supported['version']); $_SESSION['upgrade']['versions'][$supported['version']] = array('version' => $supported['version'], 'stage' => $supported['stage'], 'file' => isset($supported['file']) ? $supported['file'] : '', 'script' => isset($supported['script']) ? $supported['script'] : ''); if (version_compare($supported['version'], $_SESSION['upgrade']['InstalledVersion'], '<=')) { if ($supported['version'] == JAWS_VERSION) { $tpl->SetVariable('status', _t('UPGRADE_REPORT_NO_NEED_CURRENT')); _log(JAWS_LOG_DEBUG, $supported['version'] . " does not requires upgrade(is current)"); } else { $tpl->SetVariable('status', _t('UPGRADE_REPORT_NO_NEED')); _log(JAWS_LOG_DEBUG, $supported['version'] . " does not requires upgrade"); } $_SESSION['upgrade']['versions'][$supported['version']]['status'] = true; } else { $tpl->SetVariable('status', _t('UPGRADE_REPORT_NEED')); $_SESSION['upgrade']['versions'][$supported['version']]['status'] = false; $versions_to_upgrade++; _log(JAWS_LOG_DEBUG, $supported['version'] . " requires upgrade"); $_SESSION['upgrade']['versions'][$supported['version']]['status'] = false; } if (!is_null($supported['stage'])) { $_SESSION['upgrade']['stagedVersions'][] = $supported['version']; } $tpl->ParseBlock('Report/versions/version'); $tpl->ParseBlock('Report/versions'); } $_SESSION['upgrade']['versions_to_upgrade'] = $versions_to_upgrade; arsort($_SESSION['upgrade']['versions']); krsort($_SESSION['upgrade']['stagedVersions']); $tpl->ParseBlock('Report'); return $tpl->Get(); }
/** * Gets database server information * * @access public * @param int $iType Type of information * @return string Database server information */ function GetDBServerInfo($iType = 0) { static $dbInfo; if (!isset($dbInfo)) { $dbInfo = Jaws_DB::getInstance()->getDatabaseInfo(); } switch ($iType) { case 0: return $dbInfo['driver'] . '/' . (empty($dbInfo['version']) ? '-' : $dbInfo['version']); case 1: return $dbInfo['host'] . '/' . (empty($dbInfo['port']) ? '-' : $dbInfo['port']) . '/' . $dbInfo['name'] . '/' . (empty($dbInfo['prefix']) ? '-' : $dbInfo['prefix']); } }
/** * Get number of author's pages * * @access public * @param string $user username * @return int number of pages */ function GetAuthorNumberOfPages($user) { $blogTable = Jaws_ORM::getInstance()->table('blog'); $blogTable->select('count(blog.id)'); $blogTable->join('users', 'blog.user_id', 'users.id', 'left'); $blogTable->where('published', true)->and()->where('publishtime', Jaws_DB::getInstance()->date(), '<='); if (is_numeric($user)) { $blogTable->and()->where('users.id', $user); } else { $blogTable->and()->where('users.username', $user); } $howmany = $blogTable->fetchOne(); return Jaws_Error::IsError($howmany) ? 0 : $howmany; }
/** * Retrieve poll groups * * @access public * @param int $limit limit groups * @param int $offset offset groups * @return mixed An array of available poll groups and Jaws_Error on error */ function GetPollGroups($limit = 0, $offset = null) { if (!empty($limit)) { $res = Jaws_DB::getInstance()->setLimit($limit, $offset); if (Jaws_Error::IsError($res)) { return new Jaws_Error($res->getMessage()); } } $table = Jaws_ORM::getInstance()->table('poll_groups'); $table->select('id', 'title', 'visible')->orderBy('id asc'); $result = $table->fetchAll(); if (Jaws_Error::IsError($result)) { return new Jaws_Error($result->getMessage()); } return $result; }
/** * Returns an array with the results of a search * * @access public * @param string $pSql Prepared search (WHERE) SQL * @return array An array of entries that matches a certain pattern */ function Execute($pSql = '') { if (!$this->gadget->GetPermission('OutputAccess')) { return array(); } if ($GLOBALS['app']->Registry->fetch('frontend_avail', 'FileBrowser') != 'true') { return array(); } // TODO: must be converted to Jaws_ORM $sql = ' SELECT [id], [filename], [title], [description], [fast_url], [path], [updatetime] FROM [[filebrowser]] '; $sql .= ' WHERE ' . $pSql; $sql .= ' ORDER BY [updatetime] desc'; $files = Jaws_DB::getInstance()->queryAll($sql); if (Jaws_Error::IsError($files)) { return array(); } $fModel = $this->gadget->model->load('Files'); $date = Jaws_Date::getInstance(); $result = array(); foreach ($files as $file) { $item = array(); $item['title'] = $file['title']; $filepath = ltrim($file['path'] . '/' . $file['filename'], '/'); if (is_dir($fModel->GetFileBrowserRootDir() . $filepath)) { $item['url'] = $this->gadget->urlMap('Display', array('path' => $filepath)); $item['image'] = 'images/mimetypes/folder.png'; } else { $fid = empty($file['fast_url']) ? $file['id'] : $file['fast_url']; $item['url'] = $this->gadget->urlMap('FileInfo', array('id' => $fid)); $filetype = ltrim(strrchr($file['filename'], '.'), '.'); $fileicon = $fModel->getExtImage($filetype); if (is_file(JAWS_PATH . 'images/' . $fileicon)) { $item['image'] = 'images/' . $fileicon; } else { $item['image'] = 'images/mimetypes/unknown.png'; } } $item['snippet'] = $file['description']; $item['date'] = $date->ToISO($file['updatetime']); $result[] = $item; } return $result; }
/** * Add/Update file or directory information * * @access public * @param string $path File|Directory path * @param string $file File|Directory name * @param string $title * @param string $description * @param string $fast_url * @param string $oldname * @return mixed A list of properties of files and directories of a certain path and Jaws_Error on failure */ function UpdateDBFileInfo($path, $file, $title, $description, $fast_url, $oldname = '') { $path = trim($path, '/'); $path = str_replace('..', '', $path); $title = empty($title) ? $file : $title; $fast_url = empty($fast_url) ? $title : $fast_url; $params['path'] = $path; $params['filename'] = $file; $params['title'] = $title; $params['description'] = $description; $params['updatetime'] = Jaws_DB::getInstance()->date(); $oldname = empty($oldname) ? $params['filename'] : $oldname; $fModel = $this->gadget->model->load('Files'); $dbFile = $fModel->DBFileInfo($path, $oldname); if (Jaws_Error::IsError($dbFile)) { $GLOBALS['app']->Session->PushLastResponse(_t('GLOBAL_ERROR_QUERY_FAILED'), RESPONSE_ERROR); return false; } if (!empty($dbFile) && array_key_exists('id', $dbFile)) { // Update $fast_url = $this->GetRealFastUrl($fast_url, 'filebrowser', false); $params['fast_url'] = $fast_url; $table = Jaws_ORM::getInstance()->table('filebrowser'); $res = $table->update($params)->where('path', $path)->and()->where('filename', $oldname)->exec(); if (Jaws_Error::IsError($res)) { $GLOBALS['app']->Session->PushLastResponse(_t('GLOBAL_ERROR_QUERY_FAILED'), RESPONSE_ERROR); return false; } $GLOBALS['app']->Session->PushLastResponse(_t('FILEBROWSER_FILE_UPDATED', $file), RESPONSE_NOTICE); } else { //Insert $fast_url = $this->GetRealFastUrl($fast_url, 'filebrowser'); $params['fast_url'] = $fast_url; unset($params['oldname']); $fileTable = Jaws_ORM::getInstance()->table('filebrowser'); $res = $fileTable->insert($params)->exec(); if (Jaws_Error::IsError($res)) { $GLOBALS['app']->Session->PushLastResponse(_t('GLOBAL_ERROR_QUERY_FAILED'), RESPONSE_ERROR); return false; } if (empty($path) && is_dir($fModel->GetFileBrowserRootDir() . '/' . $file)) { $this->gadget->acl->insert('OutputAccess', $res, true); } $GLOBALS['app']->Session->PushLastResponse(_t('FILEBROWSER_FILE_ADDED', $file), RESPONSE_NOTICE); } return true; }
/** * Update a category * * @access public * @param int $id Category ID * @param string $category Category name * @param string $fast_url Fast URL * @param string $description Category description * @return mixed True if category is succesfully updated, Jaws_Error if not */ function UpdateCategory($id, $category, $fast_url, $description) { $fast_url = empty($fast_url) ? $category : $fast_url; $fast_url = $this->GetRealFastUrl($fast_url, 'faq_category', false); $params['category'] = $category; $params['fast_url'] = $fast_url; $params['description'] = $description; $params['updatetime'] = Jaws_DB::getInstance()->date(); $table = Jaws_ORM::getInstance()->table('faq_category'); $result = $table->update($params)->where('id', $id)->exec(); if (Jaws_Error::IsError($result)) { $GLOBALS['app']->Session->PushLastResponse(_t('FAQ_ERROR_CATEGORY_NOT_UPDATED'), RESPONSE_ERROR); return new Jaws_Error(_t('FAQ_ERROR_CATEGORY_NOT_UPDATED')); } $GLOBALS['app']->Session->PushLastResponse(_t('FAQ_CATEGORY_UPDATED'), RESPONSE_NOTICE); return true; }
/** * Update Block * * @access public * @param int $id Block ID * @param string $title Block title * @param string $contents Block contents * @param bool $display_title True if we want to display block title * @param int $user User ID * @return mixed True if query is successful, if not, returns Jaws_Error on any error */ function UpdateBlock($id, $title, $contents, $display_title, $user) { $data = array(); $data['title'] = $title; $data['contents'] = $contents; $data['display_title'] = $display_title ? true : false; $data['modified_by'] = $user; $data['updatetime'] = Jaws_DB::getInstance()->date(); $blocksTable = Jaws_ORM::getInstance()->table('blocks'); $result = $blocksTable->update($data)->where('id', (int) $id)->exec(); if (Jaws_Error::IsError($result)) { $GLOBALS['app']->Session->PushLastResponse(_t('BLOCKS_ERROR_NOT_UPDATED'), RESPONSE_ERROR); return new Jaws_Error(_t('BLOCKS_ERROR_NOT_UPDATED')); } $GLOBALS['app']->Session->PushLastResponse(_t('BLOCKS_UPDATED', $title), RESPONSE_NOTICE); return true; }
/** * Update a question * * @access public * @param string $id Number of the question * @param string $question The question * @param string $fast_url Fast URL * @param string $answer The answer of the question * @param int $category Category id * @param bool $active Question status * @return mixed True if question is succesfully updated, Jaws_Error if not */ function UpdateQuestion($id, $question, $fast_url, $answer, $category, $active) { $fast_url = empty($fast_url) ? $question : $fast_url; $fast_url = $this->GetRealFastUrl($fast_url, 'faq', false); $params['question'] = $question; $params['fast_url'] = $fast_url; $params['answer'] = $answer; $params['category'] = $category; $params['published'] = $active; $params['updatetime'] = Jaws_DB::getInstance()->date(); $faqTable = Jaws_ORM::getInstance()->table('faq'); $result = $faqTable->update($params)->where('id', $id)->exec(); if (Jaws_Error::IsError($result)) { $GLOBALS['app']->Session->PushLastResponse(_t('FAQ_ERROR_QUESTION_NOT_UPDATED'), RESPONSE_ERROR); return new Jaws_Error(_t('FAQ_ERROR_QUESTION_NOT_UPDATED')); } $GLOBALS['app']->Session->PushLastResponse(_t('FAQ_QUESTION_UPDATED'), RESPONSE_NOTICE); return true; }