/** * @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); }