Example #1
0
File: pi.nav.php Project: nob/joi
 public function count()
 {
     $url = $this->fetchParam('from', URL::getCurrent());
     $url = Path::resolve($url);
     $max_depth = $this->fetchParam('max_depth', 1, 'is_numeric');
     $tree = Statamic::get_content_tree($url, 1, $max_depth);
     if ($this->content != '') {
         return Parse::tagLoop($this->content, $tree);
     } else {
         return count($tree);
     }
 }
 private function order_set($page_order, $entry_folder)
 {
     $content_path = Config::getContentRoot();
     $entries = Statamic::get_content_tree('/' . $entry_folder, 3, 5, false, true);
     $result = array('linkage' => null, 'message' => 'Page order saved successfully!', 'status' => 'success');
     // Array to store the links of old data coupled with new data.
     // We return this to the view so we can use JS to update the pathing on the page.
     $links = array();
     // Loop over original folder structure and rename all folders to
     // reflect the new order.
     $entry_url = implode('/', explode('/', $page_order[0]->url, -1));
     $entry_url = str_replace(Config::getSiteRoot(), '', $entry_folder);
     foreach ($page_order as $page) {
         $page_url = str_replace(Config::getSiteRoot(), '/', $page->url);
         foreach ($entries as $entry) {
             // Store original folder data.
             $file_ext = pathinfo($entry['raw_url'], PATHINFO_EXTENSION);
             // used to generate the old pathing info.
             $old_slug = $entry['slug'];
             // Match on the URL to get the correct order result for this item.
             if ($page_url == $entry['url']) {
                 break;
             }
         }
         $slug = explode('/', $page->url);
         $slug = preg_replace("/^\\/(.+)/uis", "\$1", end($slug));
         $new_name = sprintf("%02d", $page->index + 1) . '.' . $slug;
         $old_name = $old_slug;
         $links[] = array('old' => $old_name, 'new' => $new_name);
         $folder_path = $content_path . "/" . $entry_folder . "/";
         // Generate pathing to pass to rename()
         $new_path = $folder_path . $new_name . '.' . $file_ext;
         $old_path = $folder_path . $old_name . '.' . $file_ext;
         if ($new_path !== $old_path) {
             // Check the old path actually exists and the new one doesn't.
             if (File::exists($old_path) && !File::exists($new_path)) {
                 rename($old_path, $new_path);
             } else {
                 $result['status'] = 'error';
                 $result['message'] = 'Aborting: Can\'t guarantee file integrity ' . 'for folders ' . $old_path . ' & ' . $new_path;
                 Log::error($result['message'], 'pagereorder_redux');
                 break;
             }
         }
     }
     if ($result['status'] !== 'error') {
         // No error, set links
         $result['linkage'] = $links;
     }
     return $result;
 }
Example #3
0
File: start.php Project: nob/joi
|
| This may be overwritten later, but let's go ahead and set the default
| layout file to start assembling our front-end view.
|
*/
Statamic_View::set_layout("layouts/default");
/*
|--------------------------------------------------------------------------
| Set Global Variables, Defaults, and Environments
|--------------------------------------------------------------------------
|
| Numerous tag variables, helpers, and other config-dependent options
| need to be loaded *before* the page is parsed.
|
*/
Statamic::setDefaultTags();
/*
|--------------------------------------------------------------------------
| Caching
|--------------------------------------------------------------------------
|
| Look for updated content to cache
|
*/
Cache::update();
/*
|--------------------------------------------------------------------------
| Load Admin Libraries
|--------------------------------------------------------------------------
|
| Admin has a few extra needs. Let's fetch those.
 public function member__forgot_password()
 {
     $globals = Statamic::loadAllConfigs();
     $username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING);
     $token = filter_input(INPUT_POST, 'token', FILTER_SANITIZE_STRING);
     $return = filter_input(INPUT_POST, 'return', FILTER_SANITIZE_STRING);
     $reset_return = filter_input(INPUT_POST, 'reset_return', FILTER_SANITIZE_STRING);
     $referrer = Request::getReferrer();
     // validate form token
     if (!$this->tokens->validate($token)) {
         $this->flash->set('forgot_password_error', 'Invalid token.');
         URL::redirect($referrer);
     }
     // bail if member doesn't exist
     if (!($member = Member::load($username))) {
         $this->flash->set('forgot_password_error', Localization::fetch('member_doesnt_exist'));
         URL::redirect($referrer);
     }
     // cache reset data
     $token = $this->tokens->create();
     $reset_data = array('username' => $username);
     if (isset($reset_return)) {
         $reset_data['return'] = $reset_return;
     }
     $this->cache->putYAML($token, $reset_data);
     // generate reset url
     $reset_url = URL::makeFull($this->fetchConfig('reset_password_url', str_replace(Config::getSiteURL(), '', $referrer)));
     $reset_url .= '?H=' . $token;
     // send email
     $attributes = array('from' => $this->fetchConfig('email_sender', Config::get('email_sender'), null, false, false), 'to' => $member->get('email'), 'subject' => $this->fetchConfig('reset_password_subject', 'Password Reset', null, false, false));
     if ($html_template = $this->fetchConfig('reset_password_html_email', false, null, false, false)) {
         $attributes['html'] = Theme::getTemplate($html_template);
     }
     if ($text_template = $this->fetchConfig('reset_password_text_email', false, null, false, false)) {
         $attributes['text'] = Theme::getTemplate($text_template);
     }
     foreach ($attributes as $key => $value) {
         $attributes[$key] = Parse::template($value, array('reset_url' => $reset_url), array('statamic_view', 'callback'), $globals);
     }
     Email::send($attributes);
     $this->flash->set('forgot_password_sent', true);
     // redirect
     URL::redirect($return);
 }
Example #5
0
    // legacy status
    } elseif (isset($data['status']) && $data['status'] != 'live' && $data['status'] != 'hidden' && !$app->config['logged_in']) {
        $data          = Content::get(Path::tidy(Config::getSiteRoot() . "/404"));
        $template_list = array('404');
        $visible       = false;
        $response_code = 404;
    }

    // mark milestone for debug panel
    Debug::markMilestone('status determined');

    // find next/previous
    if ($add_prev_next && $visible) {
        $folder = substr(preg_replace(Pattern::ORDER_KEY, "", substr($path, 0, (-1*strlen($page))-1)), 1);

        $relative     = Statamic::find_relative($current_url, $folder);
        $data['prev'] = $relative['prev'];
        $data['next'] = $relative['next'];
    }

    // grab data for this folder
    $folder_data = Content::get(Path::tidy('/' . Config::getSiteRoot() . '/' . dirname($current_url)));

    $fields_data = YAML::parseFile(Path::tidy(BASE_PATH . "/" . Config::getContentRoot() . dirname($current_url) . '/fields.yaml'));

    // Check for fallback template
    if ($content_found && empty($data['_template'])) {
        // check fields.yaml first
        if (array_get($fields_data, '_default_folder_template')) {
            $data['_template'] = $fields_data['_default_folder_template'];
        // fall back to the folder's page.md file
Example #6
0
 /**
  * Finds a given path on the server, adding in any ordering elements missing
  *
  * @param string  $path  Path to resolve
  * @return string
  */
 public static function resolve($path)
 {
     $content_root = Config::getContentRoot();
     $content_type = Config::getContentType();
     if (strpos($path, "/") === 0) {
         $parts = explode("/", substr($path, 1));
     } else {
         $parts = explode("/", $path);
     }
     $fixedpath = "/";
     foreach ($parts as $part) {
         if (!File::exists(Path::assemble($content_root, $path . '.' . $content_type)) && !is_dir(Path::assemble($content_root, $part))) {
             // check folders
             $list = Statamic::get_content_tree($fixedpath, 1, 1, FALSE, TRUE, FALSE);
             foreach ($list as $item) {
                 $t = basename($item['slug']);
                 if (Slug::isNumeric($t)) {
                     $nl = strlen(Slug::getOrderNumber($t)) + 1;
                     if (strlen($part) >= strlen($item['slug']) - $nl && Pattern::endsWith($item['slug'], $part)) {
                         $part = $item['slug'];
                         break;
                     }
                 } else {
                     if (Pattern::endsWith($item['slug'], $part)) {
                         if (strlen($part) >= strlen($t)) {
                             $part = $item['slug'];
                             break;
                         }
                     }
                 }
             }
             // check files
             $list = Statamic::get_file_list($fixedpath);
             foreach ($list as $key => $item) {
                 if (Pattern::endsWith($key, $part)) {
                     $t = basename($item);
                     $offset = 0;
                     if (Pattern::startsWith($key, '__')) {
                         $offset = 2;
                     } elseif (Pattern::startsWith($key, '_')) {
                         $offset = 1;
                     }
                     if (Config::getEntryTimestamps() && Slug::isDateTime($t)) {
                         if (strlen($part) >= strlen($key) - 16 - $offset) {
                             $part = $key;
                             break;
                         }
                     } elseif (Slug::isDate($t)) {
                         if (strlen($part) >= strlen($key) - 12 - $offset) {
                             $part = $key;
                             break;
                         }
                     } elseif (Slug::isNumeric($t)) {
                         $nl = strlen(Slug::getOrderNumber($key)) + 1;
                         if (strlen($part) >= strlen($key) - $nl - $offset) {
                             $part = $key;
                             break;
                         }
                     } else {
                         $t = basename($item);
                         if (strlen($part) >= strlen($t) - $offset) {
                             $part = $key;
                             break;
                         }
                     }
                 }
             }
         }
         if ($fixedpath != '/') {
             $fixedpath .= '/';
         }
         $fixedpath .= $part;
     }
     return $fixedpath;
 }
Example #7
0
 /**
  * Parse from mixed sources
  *
  * @param string  $file  a filename or string to retreive data from
  * @param bool    $type  if the type is known, you can pass it
  * @return array
  **/
 public static function mixed($file, $type = false)
 {
     if (!$type) {
         // resolve type
     }
     switch ($type) {
         case "md":
         case "markdown":
             return Statamic::yamlize_content($file);
         case "textile":
             return Statamic::yamlize_content($file);
         case "yaml":
             return self::yaml($file);
         case "json":
             return json_decode($file);
         default:
             return false;
     }
 }
Example #8
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;
 }
Example #9
0
        }
    }
    // save member
    $member->save();
    // REDIRECT
    $admin_app->flash('success', Localization::fetch('member_saved'));
    $url = CP_Helper::show_page('members') ? $admin_app->urlFor('members') : $admin_app->urlFor('pages');
    $admin_app->redirect($url);
});
// GET: MEMBER
// --------------------------------------------------------
$admin_app->get('/member', function () use($admin_app) {
    authenticateForRole('admin');
    doStatamicVersionCheck($admin_app);
    $data = array();
    if (!Statamic::are_users_writable()) {
        $url = $admin_app->urlFor('error') . "?code=users_not_writable";
        $admin_app->redirect($url);
    }
    $name = Session::getFlash('member_is_new', filter_input(INPUT_GET, 'name', FILTER_SANITIZE_STRING));
    $new = Session::getFlash('member_is_new', filter_input(INPUT_GET, 'new', FILTER_SANITIZE_NUMBER_INT));
    $original_name = $name;
    if ($new) {
        $data['status_message'] = Localization::fetch('creating_member');
    } else {
        $data = Member::getProfile($name, array('password'));
        $data['status_message'] = Localization::fetch('editing_member');
    }
    $data['fields'] = YAML::parse(Config::getConfigPath() . '/bundles/member/fields.yaml');
    $data['original_name'] = $original_name;
    $data['full_name'] = array_get($data, 'first_name', $name) . ' ' . array_get($data, 'last_name', '');
 /**
  * Initializes localization, overwriting any in-code defaults
  * 
  * @return void
  */
 public static function initialize()
 {
     // update publication states
     Statamic::$publication_states = array('live' => self::fetch('live'), 'hidden' => self::fetch('hidden'), 'draft' => self::fetch('draft'));
 }
|--------------------------------------------------------------------------
|
| "Autoload" the application dependencies and libraries
|
*/
require __DIR__ . '/_app/autoload.php';
/*
|--------------------------------------------------------------------------
| Load Configs
|--------------------------------------------------------------------------
|
| We need to load the configs here because we don't necessarily know
| the name of the admin folder.
|
*/
$config = Statamic::loadAllConfigs(true);
/*
|--------------------------------------------------------------------------
| Application Timezone
|--------------------------------------------------------------------------
|
| Many users are upgrading to PHP 5.3 for the first time. I know.
| We've gone ahead set the default timezone that will be used by the PHP
| date and date-time functions. This prevents some potentially
| frustrating errors for novice developers.
|
*/
date_default_timezone_set(Helper::pick($config['_timezone'], @date_default_timezone_get(), "UTC"));
/*
|--------------------------------------------------------------------------
| Start the Engine
Example #12
0
File: user.php Project: nob/joi
 public static function get_profile($username)
 {
     if (File::exists("_config/users/{$username}.yaml")) {
         $protected_fields = array_fill_keys(array('password', 'encrypted_password', 'salt'), NULL);
         $profile_content = file_get_contents("_config/users/{$username}.yaml");
         $profile_data = Statamic::yamlize_content($profile_content, 'biography');
         return array_diff_key($profile_data, $protected_fields);
     }
     return NULL;
 }