Exemple #1
0
 /**
  * Helper method to be called on cron events to pull in the latest feeds for all the remote articles.
  */
 public static function CronRetrieveRemoteFeeds()
 {
     $blogs = BlogModel::Find(['type = remote']);
     foreach ($blogs as $blog) {
         /** @var $blog BlogModel */
         echo 'Retrieving remote feed for blog #' . $blog->get('id') . "...\n";
         try {
             $results = $blog->importFeed();
         } catch (Exception $e) {
             echo $e->getMessage();
             return false;
         }
         echo 'Added: ' . $results['added'] . "\n" . 'Updated: ' . $results['updated'] . "\n" . 'Skipped: ' . $results['skipped'] . "\n" . 'Deleted: ' . $results['deleted'] . "\n" . "\n" . $results['changelog'];
     }
     return true;
 }
 /**
  * The frontend listing page that displays all blog articles that are published across the system.
  */
 public function index()
 {
     $view = $this->getView();
     $request = $this->getPageRequest();
     $manager = \Core\user()->checkAccess('p:/blog/manage_all');
     // Get a list of all the blogs on the system.  I'll get the page object from each one and see if the current user has access
     // to each one.  Then I'll have a list of ids that the user can view.
     $parents = array();
     $editor = false;
     $page = null;
     $blogs = BlogModel::Find(null, null, null);
     foreach ($blogs as $blog) {
         /** @var BlogModel $blog */
         $page = $blog->getLink('Page');
         $editor = \Core\user()->checkAccess($blog->get('manage_articles_permission ')) || $manager;
         $viewer = \Core\user()->checkAccess($blog->get('access')) || $editor;
         if (!$viewer) {
             continue;
         }
         $parents[] = $blog->get('baseurl');
     }
     // Is the user a manager, but no blogs exist on the system?
     if ($manager && !sizeof($parents)) {
         Core::SetMessage('There are no blogs on the system currently, you can use the All Pages interface to create one.', 'tutorial');
         \core\redirect('/admin/pages');
     }
     $filters = new FilterForm();
     $filters->haspagination = true;
     $filters->setLimit(20);
     $filters->load($this->getPageRequest());
     $factory = new ModelFactory('PageModel');
     if (sizeof($parents)) {
         $factory->where('parenturl IN ' . implode(',', $parents));
     } else {
         // This is to prevent the system from trying to load all pages that have a parent of "".
         $factory->where('parenturl = -there-are-no-blogs-');
     }
     if ($request->getParameter('q')) {
         $query = $request->getParameter('q');
         $factory->where(\Core\Search\Helper::GetWhereClause($request->getParameter('q')));
     } else {
         $query = null;
     }
     $factory->order('published DESC');
     if (!$editor) {
         // Limit these to published articles.
         $factory->where('published_status = published');
         // And where the published date is >= now.
         $factory->where('published <= ' . CoreDateTime::Now('U', Time::TIMEZONE_GMT));
     }
     $filters->applyToFactory($factory);
     $articles = $factory->get();
     //var_dump($factory, $articles); die();
     $view->mode = View::MODE_PAGEORAJAX;
     $view->assign('articles', $articles);
     $view->assign('page', $page);
     $view->assign('filters', $filters);
     $view->assign('query', $query);
     if ($editor) {
         //$view->addControl('Add Blog Article', '/blog/article/create/' . $blog->get('id'), 'add');
     }
     if ($manager) {
         $view->addControl('Edit Blog Listing Page', '/blog/editindex', 'edit');
         $view->addControl('Create New Blog', '/blog/create', 'add');
         $view->addControl('All Articles', '/admin/pages/?filter[parenturl]=/blog/view/', 'tasks');
     }
 }