Example #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
 }
Example #2
0
 /**
  * Process vote posts
  */
 public function post_vote(array $args)
 {
     $auth = false;
     $ocs = new com_meego_ocs_OCSWriter();
     if ($this->user) {
         $auth = true;
     } else {
         // Voting requires authentication
         $auth = com_meego_ocs_utils::authenticate($args);
     }
     if ($auth) {
         $primary = new com_meego_package();
         $primary->get_by_id((int) $args['contentid']);
         if (!$primary->guid) {
             $this->mvc->log(__CLASS__, 'Package with id:  (with id:' . $args['contentid'] . ') can not be found', 'info');
             $ocs->writeError('Content not found', 101);
         } else {
             $voted = false;
             // the multiple voting is configurable, pls check the config file
             if (!$this->mvc->configuration->allow_multiple_voting) {
                 // if not allowed then check if the user has voted already
                 if (com_meego_ocs_utils::user_has_voted($primary->id, $this->user->person)) {
                     $this->mvc->log(__CLASS__, "{$this->user}->login has already voted for {$primary->name} (with id: {$primary->id}) and multiple votings are disabled", 'info');
                     $ocs->writeError('Multiple voting not allowed and user has already voted this object.', 103);
                 }
             }
             if (!$ocs->error) {
                 $rating = new com_meego_ratings_rating();
                 $rating->to = $primary->guid;
                 $vote = $_POST['vote'];
                 // incoming votes are ranging between 0 and 100
                 // our internal scale is different: 0 - 5
                 $vote = round($vote / 20);
                 if ($vote > $this->mvc->configuration->maxrate) {
                     $vote = $this->mvc->configuration->maxrate;
                 }
                 $rating->rating = $vote;
                 // for votes only we have no comments
                 $rating->comment = 0;
                 if (!$rating->create()) {
                     $this->mvc->log(__CLASS__, 'Failed to create rating object. User: '******', application: ' . $primary->name . ' (with id: ' . $primary->id . ')', 'info');
                     throw new midgardmvc_exception_notfound("Could not create rating object");
                 }
                 $args = array('to' => $rating->to);
                 com_meego_ratings_caching_controllers_rating::calculate_average($args);
                 $ocs->writeMeta(0);
                 $this->mvc->log(__CLASS__, 'Rating (' . $rating->rating . ') submitted by ' . $this->user->login . ' for ' . $primary->name . ' (with id: ' . $primary->id . ')', 'info');
                 // create activity object
                 $verb = 'rate';
                 $summary = 'The user rated an application via OCS.';
                 $res = midgardmvc_account_controllers_activity::create_activity($rating->metadata->creator, $verb, $rating->to, $summary, 'Apps', $rating->metadata->created);
             }
         }
     } else {
         // extend the OCS spec with a custom status code
         $this->mvc->log(__CLASS__, 'Attempt to vote by anonymous. No luck.', 'info');
         $ocs->writeError('Voting requires authentication. Please login first.', 102);
     }
     $ocs->endDocument();
     self::output_xml($ocs);
 }