Exemple #1
0
 public static function remove_missing(array $items, com_meego_planet_feed $feed)
 {
     $urls = array_map('com_meego_planet_fetch::get_item_link', $items);
     array_walk(com_meego_planet_utils::get_items_for_feed($feed), function ($item) use($urls) {
         if (!in_array($item->url, $urls)) {
             $item->delete();
         }
     });
 }
Exemple #2
0
 public function inject_process(midgardmvc_core_request $request)
 {
     static $connected = false;
     if ($connected) {
         return;
     }
     // Subscribe to content changed signals from Midgard
     midgard_object_class::connect_default('com_meego_planet_feed', 'action-delete-hook', function ($feed) {
         array_walk(com_meego_planet_utils::get_items_for_feed($feed), function ($item) {
             $item->delete();
         });
     });
     $connected = true;
 }
Exemple #3
0
 public function get_items(array $args)
 {
     $this->data['title'] = sprintf('%s: Popular posts', $node = $this->request->get_node()->get_object()->title);
     midgardmvc_core::get_instance()->head->set_title($this->data['title']);
     $this->data['items'] = array_map('com_meego_planet_utils::prepare_item_for_display', com_meego_planet_utils::get_items(function ($q) {
         // Primarily order by calculated score tuned by age
         $q->add_order(new midgard_query_property('agedscore'), SORT_DESC);
         $q->set_limit(10);
     }));
     midgardmvc_core::get_instance()->head->add_link(array('rel' => 'alternate', 'type' => 'application/rss+xml', 'title' => $this->data['title'], 'href' => midgardmvc_core::get_instance()->dispatcher->generate_url('index_rss', array(), $this->request)));
     midgardmvc_core::get_instance()->head->enable_jquery();
     midgardmvc_core::get_instance()->head->enable_jquery_ui();
     midgardmvc_core::get_instance()->head->add_jsfile(MIDGARDMVC_STATIC_URL . '/com_meego_planet/vote.js');
     midgardmvc_core::get_instance()->head->add_jsfile(MIDGARDMVC_STATIC_URL . '/com_meego_planet/shorten.js');
 }
Exemple #4
0
 public function get_items(array $args)
 {
     $this->data['title'] = sprintf('%s: Latest posts', $node = $this->request->get_node()->get_object()->title);
     midgardmvc_core::get_instance()->head->set_title($this->data['title']);
     $this->data['items'] = array_map('com_meego_planet_utils::prepare_item_for_display', com_meego_planet_utils::get_items(function ($q) use($args) {
         // Order by publication date
         $q->add_order(new midgard_query_property('published'), SORT_DESC);
         // Handle paging
         com_meego_planet_utils::page_by_args($q, $args);
     }));
     midgardmvc_core::get_instance()->head->add_link(array('rel' => 'alternate', 'type' => 'application/rss+xml', 'title' => $this->data['title'], 'href' => midgardmvc_core::get_instance()->dispatcher->generate_url('latest_rss', array(), $this->request)));
     midgardmvc_core::get_instance()->head->enable_jquery();
     midgardmvc_core::get_instance()->head->enable_jquery_ui();
     midgardmvc_core::get_instance()->head->add_jsfile(MIDGARDMVC_STATIC_URL . '/com_meego_planet/vote.js');
     midgardmvc_core::get_instance()->head->add_jsfile(MIDGARDMVC_STATIC_URL . '/com_meego_planet/shorten.js');
 }
 public static function votes_against($url, $modifier = 1)
 {
     if (!class_exists('midgard_query_select')) {
         return self::prepare_return(0, $modifier);
     }
     try {
         $item = com_meego_planet_utils::get_item($url);
     } catch (Exception $e) {
         return self::prepare_return(0, $modifier);
     }
     $votes = com_meego_planet_votes::get($item);
     return self::prepare_return($votes['-1'], $modifier);
 }
Exemple #6
0
 public static function get_items_for_feed(com_meego_planet_feed $feed)
 {
     return com_meego_planet_utils::get_items(function ($q) use($feed) {
         $q->set_constraint(new midgard_query_constraint(new midgard_query_property('feed'), '=', new midgard_query_value($feed->id)));
     }, 'com_meego_planet_item');
 }
<?php

$filepath = ini_get('midgard.configuration_file');
$config = new midgard_config();
$config->read_file_at_path($filepath);
$mgd = midgard_connection::get_instance();
$mgd->open_config($config);
$basedir = dirname(__FILE__) . '/../..';
require "{$basedir}/midgardmvc_core/framework.php";
$mvc = midgardmvc_core::get_instance("{$basedir}/application.yml");
array_walk(com_meego_planet_utils::get_items(null, 'com_meego_planet_item_with_score'), function ($item) {
    $score = $item->score;
    $score += com_meego_planet_calculate::age($item->metadata->published);
    if (round($item->agedscore, 2) != round($score, 2)) {
        // FIXME: This is here until we can get QuerySelect out of read-only state
        $item = new com_meego_planet_item_with_score($item->guid);
        $transaction = new midgard_transaction();
        $transaction->begin();
        echo "Updating age score of {$item->title} to {$score}\n";
        $item->agedscore = $score;
        $item->update();
        $transaction->commit();
    }
});
Exemple #8
0
 public function get_item(array $args)
 {
     $this->item = com_meego_planet_utils::get_item($args['item']);
     $this->data['votes'] = com_meego_planet_votes::get($this->item);
 }