Beispiel #1
0
 /**
  * @todo: docs
  */
 public function get_search()
 {
     $query = $this->request->get_query();
     if (!isset($query['search'])) {
         $this->mvc->head->relocate('/');
     }
     if (!isset($query['os']) || !isset($query['version']) || !isset($query['ux'])) {
         $os = $this->mvc->configuration->default['os'];
         $version = $this->mvc->configuration->latest[$os]['version'];
         $ux = $this->mvc->configuration->latest[$os]['ux'];
         $search_url = rtrim($this->mvc->dispatcher->generate_url('search', array(), $this->request), '/');
         $search_url .= '?os=' . $os . '&version=' . $version . '&ux=' . $ux;
         $search_url .= '&search=' . $query['search'];
         $this->mvc->head->relocate($search_url);
     }
     $this->data['packages'] = array();
     $this->data['search'] = $query['search'];
     $apps = com_meego_packages_controllers_application::get_applications($query, false, 'top');
     if ($apps == 1) {
         $package = array_pop($this->data['packages']);
         // Relocate to the app directly
         $this->mvc->head->relocate($this->mvc->dispatcher->generate_url('apps_by_name', array('os' => $query['os'], 'version' => $query['version'], 'ux' => $query['ux'], 'basecategory' => $package['basecategoryname'], 'packagename' => $package['name']), $this->request));
     }
 }
 /**
  * Show a fancy list of basecategories but only for staging apps
  *
  * @param array args where the key
  *                                  'os' will contain the name of the OS
  *                                  'version' will contain the versionof the UX
  *                                  'ux' will contain the name of the UX
  *
  */
 public function get_staging_basecategories_by_ux(array $args)
 {
     $this->data['basecategories'] = array();
     // for now we will not use the UX at all
     $basecategories = self::load_basecategories();
     // do a quick saity check
     self::check_args($args);
     if (count($basecategories)) {
         foreach ($basecategories as $basecategory) {
             // set the url where to browse that category
             $basecategory->localurl = $this->get_url_browse_basecategory($args['os'], $args['version'], $args['ux'], $basecategory->name, 'staging');
             // count all apps that are in this category for that UX
             $basecategory->apps_counter = com_meego_packages_controllers_application::count_number_of_apps($args['os'], $args['version'], $basecategory->name, $args['ux'], 'staging');
             if (!$this->mvc->configuration->show_empty_categories && $basecategory->apps_counter == 0) {
                 continue;
             }
             // set the css class to be used to display this base category
             $basecategory->css = self::tidy_up($basecategory->name);
             // populate data
             $this->data['basecategories'][] = $basecategory;
         }
     }
 }
Beispiel #3
0
 /**
  * Some template hack
  */
 public function inject_template(midgardmvc_core_request $request)
 {
     $this->mvc = midgardmvc_core::get_instance();
     if (!$this->connected) {
         self::get_connected();
     }
     if (!$this->mvc->configuration->exists('default')) {
         // workaround to avoid an exception while templating
         return true;
     }
     $this->request = $request;
     $route = $this->request->get_route();
     if ($route->id == "apps_index") {
         $route->template_aliases['topbar'] = 'cmp-welcome-text';
     } else {
         $route->template_aliases['topbar'] = 'cmp-menubar';
     }
     // login link with redirect specified
     $request->set_data_item('redirect_link', $this->mvc->context->get_request(0)->get_path());
     // placeholder for a link to list staging apps
     $request->set_data_item('staging_link', false);
     // set if user is admin
     $request->set_data_item('admin', false);
     // admins get a link to category management UI
     $request->set_data_item('category_admin_url', false);
     // flag to show newest and hottest blocks
     $request->set_data_item('bottomblocks', false);
     if ($this->mvc->authentication->is_user()) {
         if ($this->mvc->authentication->get_user()->is_admin()) {
             $request->set_data_item('admin', true);
             $category_admin_url = $this->mvc->dispatcher->generate_url('basecategories_admin_index', array(), $request);
             $request->set_data_item('category_admin_url', $category_admin_url);
         }
     }
     $matched = $route->get_matched();
     if (!$matched && $route->id == 'search') {
         // if we have a search we may be lucky and get a nicely set matched array
         $matched = $this->request->get_query();
     }
     if (is_array($matched) && array_key_exists('os', $matched) && array_key_exists('version', $matched) && array_key_exists('ux', $matched)) {
         $os = $matched['os'];
         $ux = $matched['ux'];
         $redirect = false;
         $decoded = '';
         if (array_key_exists('basecategory', $matched)) {
             $decoded = rawurldecode($matched['basecategory']);
             $matched['basecategory'] = $decoded;
             if (array_key_exists($decoded, $this->mvc->configuration->basecategory_css_map)) {
                 $matched['basecategory_css'] = $this->mvc->configuration->basecategory_css_map[$decoded];
             } else {
                 $matched['basecategory_css'] = strtolower($decoded);
             }
         } else {
             $matched['basecategory'] = false;
             $matched['basecategory_css'] = '';
         }
         if (!array_key_exists($matched['os'], $this->mvc->configuration->os_map)) {
             $redirect = true;
             $os = $this->mvc->configuration->default['os'];
         }
         // if the matched UX is not configured then we shout out loud
         if (!array_key_exists($matched['ux'], $this->mvc->configuration->os_ux[$os])) {
             $redirect = true;
             $ux = $this->mvc->configuration->latest[$os]['ux'];
         }
         $matched['prettyversion'] = $matched['version'];
         if (array_key_exists('versions', $this->mvc->configuration->os_map[$matched['os']])) {
             if (array_key_exists($matched['version'], $this->mvc->configuration->os_map[$matched['os']]['versions'])) {
                 $matched['prettyversion'] = $this->mvc->configuration->os_map[$matched['os']]['versions'][$matched['version']];
             }
         }
         if ($redirect) {
             //throw new midgardmvc_exception_notfound("Please pick a valid UX, " . $matched['ux'] . " does not exist.", 404);
             com_meego_packages_controllers_basecategory::redirect($os, $matched['version'], $ux);
         }
         // gather available UXes for the popups
         // @todo: this piece of code is only needed for some of the routes
         // so we should not run it when not needed
         $uxes = array();
         $versions = array();
         $repositories = com_meego_packages_controllers_application::get_top_project_repos();
         $latest = $this->mvc->configuration->latest;
         foreach ($repositories as $repository) {
             if (array_key_exists($repository->repoos, $latest) && $repository->repoosversion == $latest[$repository->repoos]['version']) {
                 if (!strlen($repository->repoosux)) {
                     // No UX means a core or universal repo, so we populate all UXes
                     foreach ($this->mvc->configuration->os_ux[$repository->repoos] as $configured_ux => $configured_ux_title) {
                         $uxes[$repository->repoos . $configured_ux] = com_meego_packages_controllers_application::populate_repo_ux($repository, $configured_ux);
                     }
                 } else {
                     $uxes[$repository->repoos . $repository->repoosux] = com_meego_packages_controllers_application::populate_repo_ux($repository);
                 }
             }
             if ($matched['os'] == $repository->repoos) {
                 // all versions of the matched, current UX
                 if ($repository->repoosux == '' || $repository->repoosux == 'universal' || $repository->repoosux == $matched['ux'] && !array_key_exists($repository->repoosversion, $versions)) {
                     $prettyversion = $repository->repoosversion;
                     if (array_key_exists('versions', $this->mvc->configuration->os_map[$repository->repoos])) {
                         if (array_key_exists($repository->repoosversion, $this->mvc->configuration->os_map[$repository->repoos]['versions'])) {
                             $prettyversion = $this->mvc->configuration->os_map[$repository->repoos]['versions'][$repository->repoosversion];
                         }
                     }
                     $_repo = com_meego_packages_controllers_application::populate_repo_ux($repository, $matched['ux']);
                     $versions[$repository->repoosversion] = array('version' => $repository->repoosversion, 'url' => $_repo['url'], 'prettyversion' => $prettyversion);
                 }
             }
             // if we are not serving a staging_ route then
             // check if the repo's project has a staging project configured
             if ($route->id == "basecategories_os_version_ux" && substr($route->id, 0, 8) != 'staging_' && $repository->repoos == $os && $this->mvc->configuration->top_projects[$repository->projectname]['staging']) {
                 //echo "call count of apps\n"; ob_flush();
                 $cnt = com_meego_packages_controllers_application::count_number_of_apps($repository->repoos, $repository->repoosversion, 0, $matched['ux'], 'staging');
                 if ($cnt) {
                     $workflows = com_meego_packages_controllers_workflow::get_open_workflows_for_osux($repository->repoos, $repository->repoosversion, $matched['ux']);
                     if (count($workflows)) {
                         // if there is at least 1 workflow then we set and show the link in the templates
                         $link = $this->mvc->dispatcher->generate_url('staging_basecategories_os_version_ux', array('os' => $os, 'version' => (string) $repository->repoosversion, 'ux' => $matched['ux']), 'com_meego_packages');
                         $request->set_data_item('staging_link', $link);
                     }
                 }
             }
         }
         krsort($uxes);
         ksort($versions);
         $request->set_data_item('uxes', $uxes);
         $request->set_data_item('versions', $versions);
     }
     // in case there is no matched stuff from the request we will use the defaults configured
     if (!is_array($matched)) {
         $matched = array();
     }
     if (is_array($matched) && (!array_key_exists('os', $matched) || !array_key_exists('version', $matched) || !array_key_exists('prettyversion', $matched) || !array_key_exists('ux', $matched))) {
         $default_os = $this->mvc->configuration->default['os'];
         $matched = array_merge($matched, $this->mvc->configuration->latest[$default_os]);
         $matched['os'] = $this->mvc->configuration->default['os'];
         $matched['prettyversion'] = $matched['version'];
         if (array_key_exists('versions', $this->mvc->configuration->os_map[$matched['os']])) {
             if (array_key_exists($matched['version'], $this->mvc->configuration->os_map[$matched['os']]['versions'])) {
                 $matched['prettyversion'] = $this->mvc->configuration->os_map[$matched['os']]['versions'][$matched['version']];
             }
         }
         $this->part = 'packages';
     }
     // Add the CSS and JS files needed by Packages
     $this->add_head_elements();
     $matched['configured_ux'] = ucwords($this->mvc->configuration->os_ux[$matched['os']][$matched['ux']]);
     if (array_key_exists('client', $this->mvc->configuration->os_ux[$matched['os']])) {
         $matched['appsclient'] = $this->mvc->configuration->os_ux[$matched['os']]['client'];
     } else {
         $matched['appsclient'] = false;
     }
     $request->set_data_item('matched', $matched);
     if (count($matched)) {
         // if we have matched then show the newest and hottest blocks
         $request->set_data_item('bottomblocks', true);
     }
     $request->set_data_item('submit_app_url', $this->mvc->configuration->submit_app_url);
     // don't show newest and hottest blocks if any of these were requested explicitly
     if ($route->id == "newest_apps" || $route->id == "hottest_apps") {
         $request->set_data_item('bottomblocks', false);
     }
     $request->set_data_item('staging_area', false);
     if (substr($route->id, 0, 8) == 'staging_') {
         $request->set_data_item('staging_area', true);
         $request->set_data_item('staging_back_link', false);
         $request->set_data_item('community_qa_url', $this->mvc->configuration->community_qa_url);
         $link = false;
         if (substr($route->id, 0, 28) == 'staging_apps_by_basecategory') {
             $link = $this->mvc->dispatcher->generate_url('staging_basecategories_os_version_ux', array('os' => $matched['os'], 'version' => (string) $matched['version'], 'ux' => $matched['ux']), 'com_meego_packages');
         }
         if (substr($route->id, 0, 21) == 'staging_apps_by_name') {
             $link = '..';
         }
         if ($link) {
             $request->set_data_item('staging_back_link', $link);
         }
     }
 }
Beispiel #4
0
 /**
  * The main method to return list of packages
  *
  * @param array HTTP GET arguments
  */
 public function get_data(array $args)
 {
     $constraints = array();
     $query = $this->request->get_query();
     $storage = new midgard_query_storage('com_meego_package_details');
     $q = new midgard_query_select($storage);
     $qc = new midgard_query_constraint_group('OR');
     // filter all hidden packages
     $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('packagehidden'), '=', new midgard_query_value(1)));
     // filter packages by their names
     foreach ($this->mvc->configuration->sql_package_filters as $filter) {
         $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('packagename'), 'LIKE', new midgard_query_value($filter)));
         $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('packagetitle'), 'LIKE', new midgard_query_value($filter)));
     }
     $q->set_constraint($qc);
     $q->execute();
     $filtered = array();
     foreach ($q->list_objects() as $package) {
         $filtered[] = $package->packageid;
     }
     if (count($filtered)) {
         $constraints[] = new midgard_query_constraint(new midgard_query_property('packageid'), 'NOT IN', new midgard_query_value($filtered));
     }
     if (count($query)) {
         if (array_key_exists('search', $query) && strlen($query['search'])) {
             $cnstr1 = new midgard_query_constraint(new midgard_query_property('packagename'), 'LIKE', new midgard_query_value('%' . $query['search'] . '%'));
             $cnstr2 = new midgard_query_constraint(new midgard_query_property('packagetitle'), 'LIKE', new midgard_query_value('%' . $query['search'] . '%'));
             $group_constraint = new midgard_query_constraint_group("OR", $cnstr1, $cnstr2);
             $constraints[] = $group_constraint;
         }
         if (array_key_exists('categories', $query) && strlen($query['categories'])) {
             $constraints[] = new midgard_query_constraint(new midgard_query_property('basecategory'), 'IN', new midgard_query_value(explode('x', $query['categories'])));
         }
         if (array_key_exists('license', $query) && strlen($query['license'])) {
             $constraints[] = new midgard_query_constraint(new midgard_query_property('packagelicenseid'), 'IN', new midgard_query_value(explode(',', $query['license'])));
         }
         if (array_key_exists('distribution', $query) && strlen($query['distribution'])) {
             $constraints[] = new midgard_query_constraint(new midgard_query_property('repoosversionid'), 'IN', new midgard_query_value(explode(',', $query['distribution'])));
         }
         if (array_key_exists('dependency', $query) && strlen($query['dependency'])) {
             $constraints[] = new midgard_query_constraint(new midgard_query_property('repoosuxid'), 'IN', new midgard_query_value(explode(',', $query['dependency'])));
         }
         if (array_key_exists('sortmode', $query) && strlen($query['sortmode'])) {
             switch ($query['sortmode']) {
                 case 'new':
                     $q->add_order(new midgard_query_property('packagecreated'), SORT_DESC);
                     break;
                 case 'high':
                     $q->add_order(new midgard_query_property('statscachedratingvalue'), SORT_DESC);
                     //sort by name too
                     $q->add_order(new midgard_query_property('packagetitle'), SORT_ASC);
                     break;
                 case 'down':
                     //sort by name too
                     $q->add_order(new midgard_query_property('statscachedratingvalue'), SORT_ASC);
                 case 'alpha':
                 default:
                     $q->add_order(new midgard_query_property('packagetitle'), SORT_ASC);
                     break;
             }
         }
     }
     if (isset($args['id'])) {
         $constraints[] = new midgard_query_constraint(new midgard_query_property('packageid'), '=', new midgard_query_value($args['id']));
     }
     $qc = null;
     if (count($constraints) > 1) {
         $qc = new midgard_query_constraint_group('AND');
         foreach ($constraints as $constraint) {
             $qc->add_constraint($constraint);
         }
     } else {
         if (isset($constraints[0])) {
             $qc = $constraints[0];
         }
     }
     if (is_object($qc)) {
         $q->set_constraint($qc);
     }
     // 1st execute to get the total number of records
     // required by OCS
     $q->execute();
     $total = $q->get_results_count();
     if (array_key_exists('pagesize', $query) && strlen($query['pagesize'])) {
         $this->pagesize = $query['pagesize'];
     }
     $q->set_limit($this->pagesize);
     $page = 0;
     if (array_key_exists('page', $query) && strlen($query['page'])) {
         $page = $query['page'];
     }
     $offset = $page * $this->pagesize;
     $q->set_offset($offset);
     if ($offset > $total) {
         $offset = $total - $this->pagesize;
     }
     // 2nd execute to limit pagesize
     $q->execute();
     $ocs = new com_meego_ocs_OCSWriter();
     if ($total > 0) {
         $packageids = array();
         $localpackages = array();
         $packages = $q->list_objects();
         $done = array();
         foreach ($packages as $package) {
             if (in_array($package->packageid, $packageids)) {
                 // mimic distinct (Midgard Ratatoskr does not support it on SQL level)
                 --$total;
                 continue;
             }
             // set a special flag if the package is from a testing repository
             $package->testing = false;
             foreach ($this->mvc->configuration->top_projects as $top_project) {
                 if ($top_project['staging'] == $package->repoprojectname) {
                     $package->testing = true;
                 }
             }
             $package->comments_count = 0;
             // get number of comments
             $comments_qs = new midgard_query_storage('com_meego_comments_comment');
             $comments_q = new midgard_query_select($comments_qs);
             $comments_q->set_constraint(new midgard_query_constraint(new midgard_query_property('to'), '=', new midgard_query_value($package->packageguid)));
             $comments_q->execute();
             $package->comments_count = $comments_q->get_results_count();
             // get attachments
             $origpackage = new com_meego_package($package->packageguid);
             $package->attachments = $origpackage->list_attachments();
             unset($origpackage);
             // get the voters (who rated the package)
             $package->ratings = '';
             $ratings = com_meego_packages_controllers_application::prepare_ratings($package->packagename, true);
             if (count($ratings['ratings'])) {
                 foreach ($ratings['ratings'] as $rating) {
                     $ratings_[] = array('user' => $rating->user, 'version' => $rating->version, 'rate' => $rating->rating, 'date' => $rating->date);
                 }
                 $package->ratings = serialize($ratings_);
             }
             // some attributes returned only if an exact package is queried
             if (isset($args['id'])) {
                 // generate the URL of the package instance
                 $path = midgardmvc_core::get_instance()->dispatcher->generate_url('package_instance', array('package' => $package->packagename, 'version' => $package->packageversion, 'project' => $package->repoprojectname, 'repository' => $package->reponame, 'arch' => $package->repoarch), '/');
                 $package->commentsurl = com_meego_ocs_controllers_providers::generate_url($path);
                 // get the roles
                 $package->roles = null;
                 $roles = com_meego_packages_controllers_application::get_roles($package->packageguid);
                 if (count($roles)) {
                     $package->roles = serialize($roles);
                 }
                 // get the forms
                 $package->qa = null;
                 $forms = com_meego_packages_utils::get_stripped_forms_for_package($package);
                 if (count($forms)) {
                     $package->qa = serialize($forms);
                 }
             }
             if ($package->packagename != '') {
                 //get history
                 $args = array('os' => $package->repoos, 'version' => $package->repoosversion, 'ux' => $package->repoosux, 'packagename' => $package->packagename);
                 if (!isset($done[$package->packagename])) {
                     $packagehistory = com_meego_packages_controllers_application::get_lightweight_history($args);
                     if (count($packagehistory)) {
                         $package->history = serialize($packagehistory);
                         $done[$package->packagename] = $package->history;
                         //die;
                     }
                 } else {
                     // just copy the history
                     $package->history = $done[$package->packagename];
                 }
             }
             $localpackages[] = $package;
             $packageids[] = $package->packageid;
         }
         // write the xml content
         $ocs->writeMeta($total, $this->pagesize);
         $ocs->writeContent(array_values($localpackages));
         unset($done, $packageids, $localpackages);
     } else {
         // item not found
         $ocs->writeMeta($total, $this->pagesize, 'content not found', 'failed', 101);
         $ocs->writeEmptyData();
     }
     $ocs->endDocument();
     self::output_xml($ocs);
 }