function index() { $conn = Db::get_connection(); if (isset($_GET['software_name'])) { $software_factory = new Software(); $softwares = $software_factory->find_all(array('where_clause' => "`name` = '{$conn->escape($_GET['software_name'])}' AND (`name` != 'guidatv' OR `type` = 'macosx')", 'limit' => 1)); if (count($softwares) > 0) { $this->software = $softwares[0]; $this->software->has_many('software_releases'); // Sort releases $releases = $this->software->software_releases; usort($releases, array($releases[0], 'sort_releases')); $this->software->release = $releases[0]; $this->software->release->has_many('software_artifacts'); // Horrible hack to enable per-software caching. $_REQUEST['id'] = $this->software->id; } } else { if (isset($_GET['id'])) { $this->software = new Software(); $this->software->find_by_id($_GET['id']); $this->software->has_many('software_releases'); // Sort releases $releases = $this->software->software_releases; usort($releases, array($releases[0], 'sort_releases')); $this->software->release = $releases[0]; $this->software->release->has_many('software_artifacts'); } else { $this->render_error(); } } Db::close_connection($conn); }
/** * @fn update_versiontracker_ratings * @short Action method that updates the VersionTracker ratings for software products. */ public function update_versiontracker_ratings() { $conn = Db::get_connection(); error_reporting(E_ALL | E_STRICT); $sw = new Software(); $softwares = $sw->find_all(); foreach ($softwares as $software) { $software->has_one('version_tracker_entries'); if ($software->version_tracker_entry && $software->version_tracker_entry->vt_id != 0) { $vt = new VTRatingsParser($software->version_tracker_entry->vt_id); $vt->parse(); $software->version_tracker_entry->rating = $vt->rating; $software->version_tracker_entry->save(); } } $this->render(NULL); Db::close_connection($conn); }
/** * @fn _init_software * @short Private method that initializes repetitive members of software product page actions. */ private function _init_software() { $conn = Db::get_connection(); if (isset($_REQUEST['software_name'])) { $software_factory = new Software(); $softwares = $software_factory->find_all(array('where_clause' => '`name` = \'' . $conn->escape($_REQUEST['software_name']) . '\' AND `type` = \'' . $conn->escape($_REQUEST['software_type']) . '\'', 'limit' => 1)); if (count($softwares) > 0) { $this->software = $softwares[0]; } else { $softwares = $software_factory->find_by_query('SELECT `softwares`.`id` ' . 'FROM `softwares` ' . 'LEFT JOIN `software_typos` ON `softwares`.`id` = `software_typos`.`software_id` ' . 'WHERE `software_typos`.`typo` = \'' . $conn->escape($_REQUEST['software_name']) . '\' ' . 'LIMIT 1'); if (count($softwares) > 0) { $this->software = $softwares[0]; header(sprintf('Location: http://%s%s', $_SERVER['HTTP_HOST'], $this->software->url_to_detail($_REQUEST['subview']))); exit; } else { HTTP::error(404); } } $_REQUEST['id'] = $this->software->id; } else { if (isset($_GET['id'])) { $this->software = new Software(); if ($this->software->find_by_id($_GET['id']) === FALSE) { $this->flash(l('No such software product!'), 'error'); $this->redirect_to(array('action' => 'index')); } } else { HTTP::error(404); } } $this->software->has_many('software_releases', array('where_clause' => '`released` = \'1\'')); $releases = $this->software->software_releases; usort($releases, array($releases[0], 'sort_releases')); $this->release = $releases[0]; $this->software->software_releases = $releases; Db::close_connection($conn); }
/** * @fn software_downloads * @short Action method that shows statistics on software downloads grouped by * software product. */ public function software_downloads() { $software_factory = new Software(); $this->softwares = $software_factory->find_all(array('order_by' => '`title` DESC')); }