Example #1
0
 /**
  * Get the feed
  *
  * @param  array               $feedHeaders
  * @param  string              $feedType
  * @param  int                 $feedLimit
  * @param  \Pop\Module\Manager $modules
  * @return Writer
  */
 public function getFeed($feedHeaders, $feedType, $feedLimit, \Pop\Module\Manager $modules)
 {
     $items = [];
     $feed = Table\Feed::findAll();
     foreach ($feed->rows() as $f) {
         if ($f->type == 'content') {
             if ($modules->isRegistered('phire-fields')) {
                 $item = \Phire\Fields\Model\FieldValue::getModelObject('Phire\\Content\\Model\\Content', ['id' => $f->id]);
             } else {
                 $item = new \Phire\Content\Model\Content();
                 $item->getById($f->id);
             }
             if ($item->status == 1 && count($item->roles) == 0) {
                 $items[] = $this->formatItem($item, 'content', $feedType);
             }
         } else {
             if ($f->type == 'media') {
                 if ($modules->isRegistered('phire-fields')) {
                     $item = \Phire\Fields\Model\FieldValue::getModelObject('Phire\\Media\\Model\\Media', ['id' => $f->id]);
                 } else {
                     $item = new \Phire\Media\Model\Media();
                     $item->getById($f->id);
                 }
                 $item->publish = $item->uploaded;
                 $items[] = $this->formatItem($item, 'media', $feedType);
             }
         }
     }
     usort($items, function ($a, $b) {
         $t1 = strtotime($a['publish']);
         $t2 = strtotime($b['publish']);
         return $t2 - $t1;
     });
     if ((int) $feedLimit > 0) {
         if (count($items) > (int) $feedLimit) {
             $items = array_slice($items, 0, (int) $feedLimit);
         }
     }
     $writer = new Writer($feedHeaders, $items);
     if ($feedType == 'atom') {
         $writer->setAtom();
     }
     return $writer;
 }
Example #2
0
 /**
  * Delete feed relationships
  *
  * @param  AbstractController $controller
  * @param  Application        $application
  * @return void
  */
 public static function delete(AbstractController $controller, Application $application)
 {
     if ($_POST) {
         if (isset($_POST['process_content']) && isset($_POST['content_process_action']) && $_POST['content_process_action'] == -3) {
             foreach ($_POST['process_content'] as $id) {
                 $feed = Table\Feed::findById([$id, 'content']);
                 if (isset($feed->id)) {
                     $feed->delete();
                 }
             }
         } else {
             if (isset($_POST['rm_media'])) {
                 foreach ($_POST['rm_media'] as $id) {
                     $feed = Table\Feed::findById([$id, 'media']);
                     if (isset($feed->id)) {
                         $feed->delete();
                     }
                 }
             }
         }
     }
 }