Example #1
0
 /**
  * Lists pages
  *
  * @param {User} $user
  * @param {string} $id friendly id of site (e.g. site-name)
  * @return Response
  */
 public static function listAll($user, $site)
 {
     $arr = array();
     // get base path for the site
     $json_file = app()->basePath() . '/public/sites/' . $site->id . '/data/pages.json';
     if (file_exists($json_file)) {
         // list the contents of the json file
         $json = file_get_contents($json_file);
         $arr = json_decode($json, true);
     } else {
         // refresh the JSON file
         $arr = Page::refreshJSON($user, $site);
     }
     // append .html for non-friendly URLs
     if (env('FRIENDLY_URLS') === false) {
         foreach ($arr as &$page) {
             $page['url'] = $page['url'] . '.html';
         }
     }
     // sort by last modified date
     usort($arr, function ($a, $b) {
         $ts1 = strtotime($a['lastModifiedDate']);
         $ts2 = strtotime($b['lastModifiedDate']);
         return $ts2 - $ts1;
     });
     return $arr;
 }