Esempio n. 1
0
 public static function get_content_all($folder = null, $future = false, $past = true, $conditions = null, $skip_status = false, $parse = true, $since = null, $until = null, $location = null, $distance_from = null)
 {
     $content_type = Config::getContentType();
     $site_root = Config::getSiteRoot();
     $absolute_folder = Path::resolve($folder);
     $posts = self::get_file_list($absolute_folder);
     $list = array();
     // should we factor in location and distance?
     $measure_distance = !is_null($location) && !is_null($distance_from) && preg_match(Pattern::COORDINATES, $distance_from, $matches);
     if ($measure_distance) {
         $center_point = array($matches[1], $matches[2]);
     }
     foreach ($posts as $key => $post) {
         // starts with numeric value
         unset($list[$key]);
         if ((preg_match(Pattern::DATE, $key) || preg_match(Pattern::NUMERIC, $key)) && File::exists($post . ".{$content_type}")) {
             $data = Statamic::get_content_meta($key, $absolute_folder, false, $parse);
             $list[$key] = $data;
             $list[$key]['url'] = $folder ? $site_root . $folder . "/" . $key : $site_root . $key;
             $list[$key]['raw_url'] = $list[$key]['url'];
             // Clean the folder numbers out
             $list[$key]['url'] = Path::clean($list[$key]['url']);
             # Set status and "raw" slug
             if (substr($key, 0, 2) === "__") {
                 $list[$key]['status'] = 'draft';
                 $list[$key]['slug'] = substr($key, 2);
             } elseif (substr($key, 0, 1) === "_") {
                 $list[$key]['status'] = 'hidden';
                 $list[$key]['slug'] = substr($key, 1);
             } else {
                 $list[$key]['slug'] = $key;
             }
             $slug = $list[$key]['slug'];
             $date_entry = false;
             if (Config::getEntryTimestamps() && Slug::isDateTime($slug)) {
                 $datestamp = Slug::getTimestamp($key);
                 $date_entry = true;
                 # strip the date
                 $list[$key]['slug'] = preg_replace(Pattern::DATETIME, '', $slug);
                 $list[$key]['url'] = preg_replace(Pattern::DATETIME, '', $list[$key]['url']);
                 #override
                 $list[$key]['datestamp'] = $data['datestamp'];
                 $list[$key]['date'] = $data['date'];
             } elseif (Slug::isDate($slug)) {
                 $datestamp = Slug::getTimestamp($slug);
                 $date_entry = true;
                 # strip the date
                 // $list[$key]['slug'] = substr($key, 11);
                 $list[$key]['slug'] = preg_replace(Pattern::DATE, '', $slug);
                 $list[$key]['url'] = preg_replace(Pattern::DATE, '', $list[$key]['url']);
                 #override
                 $list[$key]['datestamp'] = $data['datestamp'];
                 $list[$key]['date'] = $data['date'];
             } else {
                 $list[$key]['slug'] = preg_replace(Pattern::NUMERIC, '', $slug);
                 $list[$key]['url'] = preg_replace(Pattern::NUMERIC, '', $list[$key]['url'], 1);
                 #override
             }
             $list[$key]['url'] = Path::tidy('/' . $list[$key]['url']);
             # fully qualified url
             $list[$key]['permalink'] = Path::tidy(Config::getSiteURL() . '/' . $list[$key]['url']);
             /* $content  = preg_replace('/<img(.*)src="(.*?)"(.*)\/?>/', '<img \/1 src="'.Statamic::get_asset_path(null).'/\2" /\3 />', $data['content']); */
             //$list[$key]['content'] = Statamic::transform_content($data['content']);
             // distance
             if (isset($list[$key][$location]['latitude']) && $list[$key][$location]['latitude'] && isset($list[$key][$location]['longitude']) && $list[$key][$location]['longitude']) {
                 $list[$key]['coordinates'] = $list[$key][$location]['latitude'] . "," . $list[$key][$location]['longitude'];
             }
             if ($measure_distance && is_array($center_point)) {
                 if (!isset($list[$key][$location]) || !is_array($list[$key][$location])) {
                     unset($list[$key]);
                 }
                 if (isset($list[$key][$location]['latitude']) && $list[$key][$location]['latitude'] && isset($list[$key][$location]['longitude']) && $list[$key][$location]['longitude']) {
                     $list[$key]['distance_km'] = Statamic_Helper::get_distance_in_km($center_point, array($list[$key][$location]['latitude'], $list[$key][$location]['longitude']));
                     $list[$key]['distance_mi'] = Statamic_Helper::convert_km_to_miles($list[$key]['distance_km']);
                 } else {
                     unset($list[$key]);
                 }
             }
             if (!$skip_status) {
                 if (isset($data['status']) && $data['status'] != 'live') {
                     unset($list[$key]);
                 }
             }
             // Remove future entries
             if ($date_entry && $future === false && $datestamp > time()) {
                 unset($list[$key]);
             }
             // Remove past entries
             if ($date_entry && $past === false && $datestamp < time()) {
                 unset($list[$key]);
             }
             // Remove entries before $since
             if ($date_entry && !is_null($since) && $datestamp < strtotime($since)) {
                 unset($list[$key]);
             }
             // Remove entries after $until
             if ($date_entry && !is_null($until) && $datestamp > strtotime($until)) {
                 unset($list[$key]);
             }
             if ($conditions) {
                 $keepers = array();
                 $conditions_array = explode(",", $conditions);
                 foreach ($conditions_array as $condition) {
                     $condition = trim($condition);
                     $inclusive = true;
                     list($condition_key, $condition_values) = explode(":", $condition);
                     # yay php!
                     $pos = strpos($condition_values, 'not ');
                     if ($pos === false) {
                     } else {
                         if ($pos == 0) {
                             $inclusive = false;
                             $condition_values = substr($condition_values, 4);
                         }
                     }
                     $condition_values = explode("|", $condition_values);
                     foreach ($condition_values as $k => $condition_value) {
                         $keep = false;
                         if (isset($list[$key][$condition_key])) {
                             if (is_array($list[$key][$condition_key])) {
                                 foreach ($list[$key][$condition_key] as $key2 => $value2) {
                                     #todo add regex driven taxonomy matching here
                                     if ($inclusive) {
                                         if (strtolower($value2['name']) == strtolower($condition_value)) {
                                             $keepers[$key] = $key;
                                             break;
                                         }
                                     } else {
                                         if (strtolower($value2['name']) != strtolower($condition_value)) {
                                             $keepers[$key] = $key;
                                         } else {
                                             // EXCLUDE!
                                             unset($keepers[$key]);
                                             break;
                                         }
                                     }
                                 }
                             } else {
                                 if ($list[$key][$condition_key] == $condition_value) {
                                     if ($inclusive) {
                                         $keepers[$key] = $key;
                                     } else {
                                         unset($keepers[$key]);
                                     }
                                 } else {
                                     if (!$inclusive) {
                                         $keepers[$key] = $key;
                                     }
                                 }
                             }
                         } else {
                             $keep = false;
                         }
                     }
                     if (!$keep && !in_array($key, $keepers)) {
                         unset($list[$key]);
                     }
                 }
             }
         }
     }
     return $list;
 }
Esempio n. 2
0
File: pages.php Progetto: nob/joi
function display_folder($app, $folder, $base = "")
{
    ?>
  <ul class="subpages">
  <?php 
    foreach ($folder as $page) {
        ?>
  <li class="page">
    <div class="page-wrapper">
      <div class="page-primary">

      <!-- PAGE TITLE -->
        <?php 
        if ($page['type'] == 'file') {
            ?>
          <a href="<?php 
            print $app->urlFor('publish') . "?path={$base}/{$page['slug']}";
            ?>
"><span class="page-title"><?php 
            print isset($page['title']) ? $page['title'] : Statamic_Helper::prettify($page['slug']);
            ?>
</span></a>
        <?php 
        } else {
            ?>
          <a href="<?php 
            print $app->urlFor('publish') . "?path={$page['file_path']}";
            ?>
"><span class="page-title"><?php 
            print isset($page['title']) ? $page['title'] : Statamic_Helper::prettify($page['slug']);
            ?>
</span></a>

        <?php 
        }
        ?>

      <!-- ENTRIES -->
      <?php 
        if (isset($page['has_entries']) && $page['has_entries']) {
            ?>
        <div class="control-entries">
          <span class="ss-icon">textfile</span>
          <span class="muted"><?php 
            echo Localization::fetch('entries');
            ?>
:</span>
          <a href="<?php 
            print $app->urlFor('entries') . "?path={$base}/{$page['slug']}";
            ?>
">
            <?php 
            echo Localization::fetch('list');
            ?>
          </a>
          <span class="muted">or</span>
          <a href="<?php 
            print $app->urlFor('publish') . "?path={$base}/{$page['slug']}&new=true";
            ?>
">
            <?php 
            echo Localization::fetch('create');
            ?>
          </a>
        </div>
      <?php 
        }
        ?>
      </div>

      <!-- SLUG & VIEW PAGE LINK -->
      <div class="page-extras">

        <div class="page-view">
          <a href="<?php 
        print $page['url'];
        ?>
" class="tip" title="View Page">
            <span class="ss-icon">link</span>
          </a>
        </div>

        <?php 
        if ($page['type'] != 'file') {
            ?>
        <div class="page-add"><a href="#" data-path="<?php 
            print $page['raw_url'];
            ?>
" data-title="<?php 
            print $page['title'];
            ?>
" class="tip add-page-btn" title="<?php 
            echo Localization::fetch('new_child_page');
            ?>
"><span class="ss-icon">addfile</span></a></div>
        <?php 
        }
        ?>

        <?php 
        if (Config::get('_enable_delete_page', true)) {
            ?>
        <div class="page-delete">
          <a class="confirm" href="<?php 
            print $app->urlFor('delete_page') . '?path=' . $page['raw_url'] . '&type=' . $page['type'];
            ?>
" class="tip" title="<?php 
            echo Localization::fetch('delete_page');
            ?>
" data-confirm-message="Are you sure you wish to delete this page?">
            <span class="ss-icon">delete</span>
          </a>
        </div>
        <?php 
        }
        ?>

        <div class="slug-preview">
          <?php 
        print isset($page['url']) ? $page['url'] : $base . ' /' . $page['slug'];
        ?>
        </div>

      </div>

    </div>
    <?php 
        if (isset($page['children']) && sizeof($page['children']) > 0) {
            display_folder($app, $page['children'], $base . "/" . $page['slug']);
        }
        ?>

  </li>
  <?php 
    }
    ?>
  </ul>
  <?php 
}