コード例 #1
0
ファイル: admin.php プロジェクト: indigo423/blog.no42.org
 public function processNotifications($notifications)
 {
     // Sort by date
     usort($notifications, function ($a, $b) {
         return strcmp($a->date, $b->date);
     });
     $notifications = array_reverse($notifications);
     // Make adminNicetimeFilter available
     require_once __DIR__ . '/../twig/AdminTwigExtension.php';
     $adminTwigExtension = new AdminTwigExtension();
     $filename = $this->grav['locator']->findResource('user://data/notifications/' . $this->grav['user']->username . YAML_EXT, true, true);
     $read_notifications = CompiledYamlFile::instance($filename)->content();
     $notifications_processed = [];
     foreach ($notifications as $key => $notification) {
         $is_valid = true;
         if (in_array($notification->id, $read_notifications)) {
             $notification->read = true;
         }
         if ($is_valid && isset($notification->permissions) && !$this->authorize($notification->permissions)) {
             $is_valid = false;
         }
         if ($is_valid && isset($notification->dependencies)) {
             foreach ($notification->dependencies as $dependency => $constraints) {
                 if ($dependency == 'grav') {
                     if (!Semver::satisfies(GRAV_VERSION, $constraints)) {
                         $is_valid = false;
                     }
                 } else {
                     $packages = array_merge($this->plugins()->toArray(), $this->themes()->toArray());
                     if (!isset($packages[$dependency])) {
                         $is_valid = false;
                     } else {
                         $version = $packages[$dependency]['version'];
                         if (!Semver::satisfies($version, $constraints)) {
                             $is_valid = false;
                         }
                     }
                 }
                 if (!$is_valid) {
                     break;
                 }
             }
         }
         if ($is_valid) {
             $notifications_processed[] = $notification;
         }
     }
     // Process notifications
     $notifications_processed = array_map(function ($notification) use($adminTwigExtension) {
         $notification->date = $adminTwigExtension->adminNicetimeFilter($notification->date);
         return $notification;
     }, $notifications_processed);
     return $notifications_processed;
 }
コード例 #2
0
 protected function taskGetNewsFeed()
 {
     $cache = $this->grav['cache'];
     if ($this->post['refresh'] == 'true') {
         $cache->delete('news-feed');
     }
     $feed_data = $cache->fetch('news-feed');
     if (!$feed_data) {
         try {
             $feed = $this->admin->getFeed();
             if (is_object($feed)) {
                 require_once __DIR__ . '/../twig/AdminTwigExtension.php';
                 $adminTwigExtension = new AdminTwigExtension();
                 $feed_items = $feed->getItems();
                 // Feed should only every contain 10, but just in case!
                 if (count($feed_items > 10)) {
                     $feed_items = array_slice($feed_items, 0, 10);
                 }
                 foreach ($feed_items as $item) {
                     $datetime = $adminTwigExtension->adminNicetimeFilter($item->getDate()->getTimestamp());
                     $feed_data[] = '<li><span class="date">' . $datetime . '</span> <a href="' . $item->getUrl() . '" target="_blank" title="' . str_replace('"', '″', $item->getTitle()) . '">' . $item->getTitle() . '</a></li>';
                 }
             }
             // cache for 1 hour
             $cache->save('news-feed', $feed_data, 60 * 60);
         } catch (\Exception $e) {
             $this->admin->json_response = ['status' => 'error', 'message' => $e->getMessage()];
             return;
         }
     }
     $this->admin->json_response = ['status' => 'success', 'feed_data' => $feed_data];
 }