Ejemplo n.º 1
0
 /**
  * Dumps content elements
  */
 public function writeContent($packages)
 {
     $this->startElement('data');
     foreach ($packages as $package) {
         $mvc = midgardmvc_core::get_instance();
         $this->startElement('content');
         $this->writeAttribute('details', 'full');
         $this->writeElement('id', $package->packageid);
         $this->writeElement('name', $package->packagetitle);
         $this->writeElement('version', $package->packageversion);
         $this->writeElement('description', $package->packagedescription);
         $this->writeElement('summary', $package->packagesummary);
         $this->writeElement('homepage', $package->packagehomepageurl);
         $this->writeElement('created', $package->packagecreated);
         $this->writeElement('changed', $package->packagerevised);
         $this->writeElement('score', 20 * $package->statscachedratingvalue);
         $this->writeElement('x-filename', $package->packagefilename);
         $this->writeElement('x-license', $package->packagelicense);
         $this->writeElement('x-arch', $package->repoarch);
         $this->writeElement('x-project', $package->repoprojectname);
         $this->writeElement('x-repository', $package->reponame);
         $this->writeElement('x-os', $package->repoos);
         $this->writeElement('x-osversion', $package->repoosversion);
         $this->writeElement('x-ux', $package->repoosux);
         $this->writeElement('x-licenseid', $package->packagelicenseid);
         $this->writeElement('x-distributionid', $package->repoosversionid);
         $this->writeElement('x-dependencyid', $package->repoosuxid);
         $this->writeElement('x-obsname', $package->packageparent);
         if (isset($package->roles)) {
             $this->writeElement('x-roles', $package->roles);
         }
         if (isset($package->history)) {
             $this->writeElement('x-history', $package->history);
         }
         $user = com_meego_ocs_utils::get_current_user();
         if ($user) {
             if (com_meego_ocs_utils::user_has_voted($package->packageid, $user->person)) {
                 $this->writeElement('x-rated', 'true');
             } else {
                 $this->writeElement('x-rated', 'false');
             }
         }
         if (isset($package->testing) && $package->testing) {
             $this->writeElement('x-testing', true);
             $this->writeElement('x-qa-score', $package->packagescore);
             if (isset($package->qa)) {
                 $this->writeElement('x-qa', $package->qa);
             }
         }
         $dispatcher = midgardmvc_core::get_instance()->dispatcher;
         $counter = 0;
         $_downloadurl = '';
         //$package->packageinstallfileurl;
         foreach ($package->attachments as $attachment) {
             // check if attachment is YMP (ie. 1 click install file)
             if ($attachment->mimetype == "text/x-suse-ymp" && !strlen($_downloadurl)) {
                 $_downloadurl = com_meego_ocs_controllers_providers::generate_url($dispatcher->generate_url('attachmentserver_variant', array('guid' => $attachment->guid, 'variant' => '', 'filename' => $attachment->name), '/'));
             }
             // check if attachment MIME type is image something
             if ($attachment->mimetype == "image/png") {
                 $_icon_marker = 'icon.png';
                 $_screenshot_marker = 'screenshot.png';
                 // check if the name is *screenshot.png
                 if (strrpos($attachment->name, $_screenshot_marker) !== false) {
                     $counter++;
                     $_screenshoturl = com_meego_ocs_controllers_providers::generate_url($dispatcher->generate_url('attachmentserver_variant', array('guid' => $attachment->guid, 'variant' => 'prop480x300', 'filename' => $attachment->name), '/'));
                     $_smallscreenshoturl = com_meego_ocs_controllers_providers::generate_url($dispatcher->generate_url('attachmentserver_variant', array('guid' => $attachment->guid, 'variant' => 'thumbnail', 'filename' => $attachment->name), '/'));
                     $this->writeElement('previewpic' . $counter, $_screenshoturl);
                     $this->writeElement('smallpreviewpic' . $counter, $_smallscreenshoturl);
                     #if ($counter == 3)
                     #{
                     #    break;
                     #}
                 }
                 // check if the name is *icon.png and generate <icon> elements
                 if (strrpos($attachment->name, $_icon_marker) !== false) {
                     $_iconurl = com_meego_ocs_controllers_providers::generate_url($dispatcher->generate_url('attachmentserver_variant', array('guid' => $attachment->guid, 'variant' => 'icon', 'filename' => $attachment->name), '/'));
                     $iconwidth = $mvc->configuration->attachmentserver_variants['icon']['croppedThumbnail']['width'];
                     $iconheight = $mvc->configuration->attachmentserver_variants['icon']['croppedThumbnail']['height'];
                     $this->startElement('icon');
                     $this->writeAttribute('width', $iconwidth);
                     $this->writeAttribute('height', $iconheight);
                     $this->text($_iconurl);
                     $this->endElement();
                 }
             }
         }
         $this->writeElement('comments', $package->comments_count);
         if (isset($package->commentsurl)) {
             $this->writeElement('commentspage', $package->commentsurl);
         }
         $this->writeElement('downloadname1', $package->packagename);
         $this->writeElement('downloadlink1', $_downloadurl);
         $this->endElement();
         //content
     }
     $this->endElement();
     // data
 }
Ejemplo n.º 2
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);
 }