コード例 #1
0
 public function index()
 {
     $between = $this->fetchParam('between', false, false, false, false);
     if ($between) {
         // Expanded mode lets you set the number of times a value is repeated
         $expanded_mode = strstr($between, ':');
         /*
         |--------------------------------------------------------------------------
         | Unique Hash
         |--------------------------------------------------------------------------
         |
         | Here we create a unique hash based on the parameters to provide 
         | users a method of using multiple switch tags in a single template
         |
         */
         $hash = md5(implode(",", $this->attributes));
         if (!isset(self::$container[$hash])) {
             // Instance counter
             self::$container[$hash] = 0;
         }
         $switch_vars = Helper::explodeOptions($between);
         // Expand those thangs!
         if ($expanded_mode) {
             $switch_vars = $this->expand($switch_vars);
         }
         $switch = $switch_vars[self::$container[$hash] % count($switch_vars)];
         // Iterate!
         self::$container[$hash]++;
         return $switch;
     }
     return null;
 }
コード例 #2
0
ファイル: pi.switch.php プロジェクト: nob/joi
 public function index()
 {
     $between = $this->fetchParam('between', false, false, false, false);
     if ($between) {
         # create unique instance key
         # using all parameters to allow a workaround
         # for duplicate switch tags
         $hash = md5(implode(",", $this->attributes));
         if (!isset(self::$container[$hash])) {
             # setup unique, per-instance counter
             self::$container[$hash] = 0;
         }
         $switch_vars = Helper::explodeOptions($between);
         $switch_count = count($switch_vars);
         $switch = $switch_vars[self::$container[$hash] % $switch_count];
         self::$container[$hash]++;
         return $switch;
     }
     return null;
 }
コード例 #3
0
ファイル: pi.nav.php プロジェクト: nob/joi
 public function index()
 {
     $from = $this->fetchParam('from', URL::getCurrent());
     $exclude = $this->fetchParam('exclude', false);
     $max_depth = $this->fetchParam('max_depth', 1, 'is_numeric');
     $include_entries = $this->fetchParam('include_entries', false, false, true);
     $folders_only = $this->fetchParam('folders_only', true, false, true);
     $include_content = $this->fetchParam('include_content', false, false, true);
     $url = Path::resolve($from);
     $tree = Statamic::get_content_tree($url, 1, $max_depth, $folders_only, $include_entries, true, $include_content);
     # exclude a pipe-delimited set of urls
     if ($exclude) {
         $exclude_items = Helper::explodeOptions($exclude);
         foreach ($tree as $key => $item) {
             if (in_array($item['url'], $exclude_items) || in_array(trim($item['url'], '/'), $exclude_items)) {
                 unset($tree[$key]);
             }
         }
     }
     if (count($tree) > 0) {
         return Parse::tagLoop($this->content, $tree);
     }
     return FALSE;
 }
コード例 #4
0
 public function password_form()
 {
     // fetch parameters
     $return = $this->fetch('return', filter_input(INPUT_GET, 'return', FILTER_SANITIZE_STRING), null, false, false);
     $attr = $this->fetchParam('attr', false);
     // set up data to be parsed into content
     $data = array('error' => $this->flash->get('error', ''), 'field_name' => 'password');
     // determine form attributes
     $attr_string = '';
     if ($attr) {
         $attributes_array = Helper::explodeOptions($attr, true);
         foreach ($attributes_array as $key => $value) {
             $attr_string .= ' ' . $key . '="' . $value . '"';
         }
     }
     // build the form
     $html = '<form action="' . Path::tidy(Config::getSiteRoot() . '/TRIGGER/protect/password') . '" method="post"' . $attr_string . '>';
     $html .= '<input type="hidden" name="return" value="' . $return . '">';
     $html .= '<input type="hidden" name="token" value="' . $this->tokens->create() . '">';
     $html .= Parse::template($this->content, $data);
     $html .= '</form>';
     // return the HTML
     return $html;
 }
コード例 #5
0
ファイル: pi.nav.php プロジェクト: zane-insight/WhiteLaceInn
 public function count()
 {
     // grab parameters
     $from = $this->fetchParam('from', URL::getCurrent());
     $exclude = $this->fetchParam('exclude', false);
     $max_depth = $this->fetchParam('max_depth', 1, 'is_numeric');
     $include_entries = $this->fetchParam('include_entries', false, false, true);
     $folders_only = $this->fetchParam('folders_only', true, false, true);
     $include_content = $this->fetchParam('include_content', false, false, true);
     $show_hidden = $this->fetchParam('show_hidden', false, null, true);
     // add in left-/ if not present
     if (substr($from, 0, 1) !== '/') {
         $from = '/' . $from;
     }
     // if this doesn't start with the site root, add the site root
     if (!Pattern::startsWith($from, Config::getSiteRoot())) {
         $from = Path::tidy(Config::getSiteRoot() . '/' . $from);
     }
     // standardize excludes
     if ($exclude && !is_array($exclude)) {
         $exclude = Helper::explodeOptions($exclude, array());
         foreach ($exclude as $key => $value) {
             $exclude[$key] = Path::tidy(Config::getSiteRoot() . '/' . $value);
         }
     }
     // option hash
     $hash = Helper::makeHash($from, $exclude, $max_depth, $include_entries, $folders_only, $include_content, $show_hidden);
     // load the content tree from cache
     if ($this->blink->exists($hash)) {
         $tree = $this->blink->get($hash);
     } else {
         $tree = ContentService::getContentTree($from, $max_depth, $folders_only, $include_entries, $show_hidden, $include_content, $exclude);
         $this->blink->set($hash, $tree);
     }
     if ($this->content) {
         return Parse::template($this->content, array('count' => count($tree)));
     } elseif (count($tree)) {
         return count($tree);
     }
     return '';
 }
コード例 #6
0
 public function login()
 {
     // deprecation warning
     $this->log->warn("Use of `login` is deprecated. Use `login_form` instead.");
     $site_root = Config::getSiteRoot();
     $return = $this->fetchParam('return', $site_root);
     /*
     |--------------------------------------------------------------------------
     | Form HTML
     |--------------------------------------------------------------------------
     |
     | The login form writes a hidden field to the form to set the return url.
     | Form attributes are accepted as colon/piped options:
     | Example: attr="class:form|id:contact-form"
     |
     | Note: The content of the tag pair is inserted back into the template
     |
     */
     $attributes_string = '';
     if ($attr = $this->fetchParam('attr', false)) {
         $attributes_array = Helper::explodeOptions($attr, true);
         foreach ($attributes_array as $key => $value) {
             $attributes_string .= " {$key}='{$value}'";
         }
     }
     $html = "<form method='post' action='" . Path::tidy($site_root . "/TRIGGER/member/login") . "' {$attributes_string}>";
     $html .= "<input type='hidden' name='return' value='{$return}' />";
     $html .= $this->content;
     $html .= "</form>";
     return $html;
 }
コード例 #7
0
 public function reset_password_form()
 {
     $data = array();
     $errors = array();
     // parse parameters and vars
     $attr_string = '';
     $site_root = Config::getSiteRoot();
     $logged_in_redirect = $this->fetchParam('logged_in_redirect', $this->fetchConfig('member_home', $site_root), null, false, false);
     $attr = $this->fetchParam('attr', false);
     $hash = filter_input(INPUT_GET, 'H', FILTER_SANITIZE_URL);
     // is user already logged in? forward as needed
     if (Auth::isLoggedIn()) {
         URL::redirect($logged_in_redirect, 302);
     }
     // no hash in URL?
     if (!$hash) {
         $errors[] = Localization::fetch('reset_password_url_invalid');
         $data['url_invalid'] = true;
     }
     if (count($errors) == 0) {
         // cache file doesn't exist or is too old
         if (!$this->cache->exists($hash) || $this->cache->getAge($hash) > $this->fetchConfig('reset_password_age_limit') * 60) {
             $errors[] = Localization::fetch('reset_password_url_expired');
             $data['expired'] = true;
         }
         // flash errors
         if ($flash_error = $this->flash->get('reset_password_error')) {
             $errors[] = $flash_error;
         }
     }
     // set up attributes
     if ($attr) {
         $attributes_array = Helper::explodeOptions($attr, true);
         foreach ($attributes_array as $key => $value) {
             $attr_string .= ' ' . $key . '="' . $value . '"';
         }
     }
     // errors
     $data['errors'] = $errors;
     // set up form HTML
     $html = '<form method="post" action="' . Path::tidy($site_root . "/TRIGGER/member/reset_password") . '" ' . $attr_string . '>';
     $html .= '<input type="hidden" name="token" value="' . $this->tokens->create() . '">';
     $html .= '<input type="hidden" name="hash" value="' . $hash . '">';
     $html .= Parse::template($this->content, $data);
     $html .= '</form>';
     // return that HTML
     return $html;
 }
コード例 #8
0
ファイル: pi.raven.php プロジェクト: jalmelb/24hl2015
  /**
   * Raven form tag pair
   *
   * {{ raven:form }} {{ /raven:form }}
   *
   * @return string
   */
	public function form()
	{

		/*
		|--------------------------------------------------------------------------
		| Formset
		|--------------------------------------------------------------------------
		|
		| Raven really needs a formset to make it useful and secure. We may even
		| write a form decorator in the future to generate forms from formsets.
		|
		*/

		$formset      = $this->fetchParam('formset', false);
		$return       = $this->fetchParam('return', URL::getCurrent());
		$error_return = $this->fetchParam('error_return', URL::getCurrent());
		$multipart    = ($this->fetchParam('files', false)) ? "enctype='multipart/form-data'" : '';

		$old_values = array();

		// Fetch the content if in edit mode
		if ($edit = $this->fetchParam('edit')) {
			$old_values = Content::get($edit, false, false);

			// Throw exception if there's an invalid URL
			if (count($old_values) == 0) {
				throw new FatalException('Invalid URL for editing');
			}

			$entry_hash = Helper::encrypt($edit);
		}

		// Merge old values
		$old_values = array_merge($this->flash->get('old_values', array()), $old_values);

		// Sanitize data before returning it for display
		// $old_values = array_map_deep($old_values, 'htmlspecialchars');

		// Set old values to re-populate the form
		$data = array();
		array_set($data, 'value', $old_values);
		array_set($data, 'old_values', $old_values);

		/*
		|--------------------------------------------------------------------------
		| Form HTML
		|--------------------------------------------------------------------------
		|
		| Raven writes a few hidden fields to the form to help processing data go
		| more smoothly. Form attributes are accepted as colon/piped options:
		| Example: attr="class:form|id:contact-form"
		|
		| Note: The content of the tag pair is inserted back into the template
		|
		*/

		$form_id = $this->fetchParam('id', true);

		$attributes_string = '';

		if ($attr = $this->fetchParam('attr', false, null, false, false)) {
			$attributes_array = Helper::explodeOptions($attr, true);
			foreach ($attributes_array as $key => $value) {
				$attributes_string .= " {$key}='{$value}'";
			}
		}

		$html  = "<form method='post' {$multipart} {$attributes_string}>\n";
		$html .= "<input type='hidden' name='hidden[raven]' value='{$form_id}' />\n";
		$html .= "<input type='hidden' name='hidden[formset]' value='{$formset}' />\n";
		$html .= "<input type='hidden' name='hidden[return]' value='{$return}' />\n";
		$html .= "<input type='hidden' name='hidden[error_return]' value='{$error_return}' />\n";

		if ($edit) {
			$html .= "<input type='hidden' name='hidden[edit]' value='{$entry_hash}' />\n";
		}

		/*
		|--------------------------------------------------------------------------
		| Hook: Form Begin
		|--------------------------------------------------------------------------
		|
		| Occurs in the middle the form allowing additional fields to be added.
		| Has access to the current fieldset. Must return HTML.
		|
		*/

		$html .= Hook::run('raven', 'inside_form', 'cumulative', '');

		/*
		|--------------------------------------------------------------------------
		| Hook: Content Preparse
		|--------------------------------------------------------------------------
		|
		| Allows the modification of the tag data inside the form. Also has access
		| to the current formset.
		|
		*/

		$html .= Hook::run('raven', 'content_preparse', 'replace', $this->content, $this->content);

		$html .= "</form>";

		return Parse::template($html, $data, array('statamic_view', 'callback'), $this->context);

	}
コード例 #9
0
 public function index()
 {
     /*
     |--------------------------------------------------------------------------
     | Check for image
     |--------------------------------------------------------------------------
     |
     | Transform just needs the path to an image to get started. If it exists,
     | the fun begins.
     |
     */
     $image_src = $this->fetchParam('src', null, false, false, false);
     // Set full system path
     $image_path = Path::standardize(Path::fromAsset($image_src));
     // Check if image exists before doing anything.
     if (!File::isImage($image_path)) {
         Log::error("Could not find requested image to transform: " . $image_path, "core", "Transform");
         return;
     }
     /*
     |--------------------------------------------------------------------------
     | Resizing and cropping options
     |--------------------------------------------------------------------------
     |
     | The first transformations we want to run is for size to reduce the
     | memory usage for future effects.
     |
     */
     $width = $this->fetchParam('width', null, 'is_numeric');
     $height = $this->fetchParam('height', null, 'is_numeric');
     // resize specific
     $ratio = $this->fetchParam('ratio', true, false, true);
     $upsize = $this->fetchParam('upsize', true, false, true);
     // crop specific
     $pos_x = $this->fetchParam('pos_x', 0, 'is_numeric');
     $pos_y = $this->fetchParam('pos_y', 0, 'is_numeric');
     $quality = $this->fetchParam('quality', '75', 'is_numeric');
     /*
     |--------------------------------------------------------------------------
     | Action
     |--------------------------------------------------------------------------
     |
     | Available actions: resize, crop, and guess.
     |
     | "Guess" will find the best fitting aspect ratio of your given width and
     | height on the current image automatically, cut it out and resize it to
     | the given dimension.
     |
     */
     $action = $this->fetchParam('action', 'resize');
     /*
     |--------------------------------------------------------------------------
     | Extra bits
     |--------------------------------------------------------------------------
     |
     | Delicious and probably rarely used options.
     |
     */
     $angle = $this->fetchParam('rotate', false);
     $flip_side = $this->fetchParam('flip', false);
     $blur = $this->fetchParam('blur', false, 'is_numeric');
     $pixelate = $this->fetchParam('pixelate', false, 'is_numeric');
     $greyscale = $this->fetchParam(array('greyscale', 'grayscale'), false, false, true);
     /*
     |--------------------------------------------------------------------------
     | Assemble filename and check for duplicate
     |--------------------------------------------------------------------------
     |
     | We need to make sure we don't already have this image created, so we
     | defer any action until we've processed the parameters, which create
     | a unique filename.
     |
     */
     // Late modified time of original image
     $last_modified = File::getLastModified($image_path);
     // Find .jpg, .png, etc
     $extension = File::getExtension($image_path);
     // Filename with the extension removed so we can append our unique filename flags
     $stripped_image_path = str_replace('.' . $extension, '', $image_path);
     // The possible filename flags
     $parameter_flags = array('width' => $width, 'height' => $height, 'quality' => $quality, 'rotate' => $angle, 'flip' => $flip_side, 'pos_x' => $pos_x, 'pos_y' => $pos_y, 'blur' => $blur, 'pixelate' => $pixelate, 'greyscale' => $greyscale, 'modified' => $last_modified);
     // Start with a 1 character action flag
     $file_breadcrumbs = '-' . $action[0];
     foreach ($parameter_flags as $param => $value) {
         if ($value) {
             $flag = is_bool($value) ? '' : $value;
             // don't show boolean flags
             $file_breadcrumbs .= '-' . $param[0] . $flag;
         }
     }
     // Allow converting filetypes (jpg, png, gif)
     $extension = $this->fetchParam('type', $extension);
     // Allow saving in a different directory
     $destination = $this->fetchParam('destination', Config::get('transform_destination', false), false, false, false);
     if ($destination) {
         $destination = Path::tidy(BASE_PATH . '/' . $destination);
         // Method checks to see if folder exists before creating it
         Folder::make($destination);
         $stripped_image_path = Path::tidy($destination . '/' . basename($stripped_image_path));
     }
     // Reassembled filename with all flags filtered and delimited
     $new_image_path = $stripped_image_path . $file_breadcrumbs . '.' . $extension;
     // Check if we've already built this image before
     if (File::exists($new_image_path)) {
         return Path::toAsset($new_image_path);
     }
     /*
     |--------------------------------------------------------------------------
     | Create Image
     |--------------------------------------------------------------------------
     |
     | Transform just needs the path to an image to get started. The image is
     | created in memory so we can start manipulating it.
     |
     */
     $image = Image::make($image_path);
     /*
     |--------------------------------------------------------------------------
     | Perform Actions
     |--------------------------------------------------------------------------
     |
     | This is fresh transformation. Time to work the magic!
     |
     */
     if ($action === 'resize' && ($width || $height)) {
         $image->resize($width, $height, $ratio, $upsize);
     }
     if ($action === 'crop' && $width && $height) {
         $image->crop($width, $height, $pos_x, $pos_y);
     }
     if ($action === 'smart') {
         $image->grab($width, $height);
     }
     $resize = $this->fetchParam('resize', null);
     if ($resize) {
         $resize_options = Helper::explodeOptions($resize, true);
         $image->resize(array_get($resize_options, 'width'), array_get($resize_options, 'height'), array_get($resize_options, 'ratio', true), array_get($resize_options, 'upsize', true));
     }
     $crop = $this->fetchParam('crop', null);
     if ($crop) {
         $crop_options = Helper::explodeOptions($crop, true);
         $image->crop(array_get($crop_options, 'width'), array_get($crop_options, 'height'), array_get($crop_options, 'x'), array_get($crop_options, 'y'));
     }
     if ($angle) {
         $image->rotate($angle);
     }
     if ($flip_side === 'h' || $flip_side === 'v') {
         $image->flip($flip_side);
     }
     if ($greyscale) {
         $image->greyscale();
     }
     if ($blur) {
         $image->blur($blur);
     }
     if ($pixelate) {
         $image->pixelate($pixelate);
     }
     /*
     |--------------------------------------------------------------------------
     | Save
     |--------------------------------------------------------------------------
     |
     | Get out of dodge!
     |
     */
     try {
         $image->save($new_image_path, $quality);
     } catch (Exception $e) {
         Log::fatal('Could not write new images. Try checking your file permissions.', 'core', 'Transform');
         throw new Exception('Could not write new images. Try checking your file permissions.');
     }
     return File::cleanURL($new_image_path);
 }
コード例 #10
0
ファイル: plugin.php プロジェクト: nob/joi
 /**
  * Explodes options into an array
  *
  * @deprecated  Use $this->explodeOptions instead
  *
  * @param string  $string  String to explode
  * @param bool $keyed  Are options keyed?
  * @return array
  */
 public function explode_options($string, $keyed = FALSE)
 {
     $this->log->warn('Use of $this->explode_options() is deprecated. Use Helper::explodeOptions() instead.');
     return Helper::explodeOptions($string, $keyed);
 }
コード例 #11
0
ファイル: pi.get_files.php プロジェクト: nob/joi
 public function index()
 {
     /*
     |--------------------------------------------------------------------------
     | Paramers
     |--------------------------------------------------------------------------
     |
     | Match overrides Extension. Exclusion applies in both cases.
     |
     */
     $match = $this->fetchParam('match', false);
     $exclude = $this->fetchParam('exclude', false);
     $extension = $this->fetchParam('extension', false);
     $in = $this->fetchParam('in', false);
     $not_in = $this->fetchParam('not_in', false);
     $file_size = $this->fetchParam('file_size', false);
     $file_date = $this->fetchParam('file_date', false);
     $depth = $this->fetchParam('depth', false);
     if ($file_size) {
         $file_size = Helper::explodeOptions($file_size);
     }
     if ($extension) {
         $extension = Helper::explodeOptions($extension);
     }
     /*
     |--------------------------------------------------------------------------
     | Finder
     |--------------------------------------------------------------------------
     |
     | Get_Files implements most of the Symfony Finder component as a clean
     | tag wrapper mapped to matched filenames.
     |
     */
     $finder = new Finder();
     $finder->in($in);
     // Finder doesn't respect multiple glob options,
     // so this will need to wait until later.
     //
     // $match = str_replace('{{', '{', $match);
     // $match = str_replace('}}', '}', $match);
     /*
     |--------------------------------------------------------------------------
     | Name
     |--------------------------------------------------------------------------
     |
     | Match is the "native" Finder name() method, which is supposed to
     | implement string, glob, and regex. The glob support is only partial,
     | so "extension" is a looped *single* glob rule iterator.
     |
     */
     if ($match) {
         $finder->name($match);
     } elseif ($extension) {
         foreach ($extension as $ext) {
             $finder->name("*.{$ext}");
         }
     }
     /*
     |--------------------------------------------------------------------------
     | Exclude
     |--------------------------------------------------------------------------
     |
     | Exclude directories from matching. Remapped to "not in" to allow more
     | intuitive differentiation between filename and directory matching.
     |
     */
     if ($not_in) {
         $finder->exclude($not_in);
     }
     /*
     |--------------------------------------------------------------------------
     | Not Name
     |--------------------------------------------------------------------------
     |
     | Exclude files matching a given pattern: string, regex, or glob.
     |
     */
     if ($exclude) {
         $finder->notName($exclude);
     }
     /*
     |--------------------------------------------------------------------------
     | File Size
     |--------------------------------------------------------------------------
     |
     | Restrict files by size. Can be chained and allows comparison operators.
     |
     */
     if ($file_size) {
         foreach ($file_size as $size) {
             $finder->size($size);
         }
     }
     /*
     |--------------------------------------------------------------------------
     | File Date
     |--------------------------------------------------------------------------
     |
     | Restrict files by last modified date. Can use comparison operators, and
     | since/after is aliased to >, and until/before to <.
     |
     */
     if ($file_date) {
         $finder->date($file_date);
     }
     /*
     |--------------------------------------------------------------------------
     | Depth
     |--------------------------------------------------------------------------
     |
     | Recursively traverse directories, starting at 0.
     |
     */
     if ($depth) {
         $finder->depth($depth);
     }
     $matches = $finder->files();
     /*
     |--------------------------------------------------------------------------
     | Return and Parse
     |--------------------------------------------------------------------------
     |
     | This tag returns the matched filenames mapped to {{ file }}.
     |
     */
     $files = array();
     foreach ($matches as $file) {
         $files[] = array('file' => '/' . $in . '/' . $file->getRelativePathname());
         // $files[] = YAML::parse($file->getContents());
     }
     return Parse::tagLoop($this->content, $files);
 }
コード例 #12
0
 public static function get_content_list($folder = null, $limit = null, $offset = 0, $future = false, $past = true, $sort_by = 'date', $sort_dir = 'desc', $conditions = null, $switch = null, $skip_status = false, $parse = true, $since = null, $until = null, $location = null, $distance_from = null)
 {
     $folder_list = Helper::explodeOptions($folder);
     $list = array();
     foreach ($folder_list as $list_item) {
         $results = self::get_content_all($list_item, $future, $past, $conditions, $skip_status, $parse, $since, $until, $location, $distance_from);
         // if $location was set, filter out results that don't work
         if (!is_null($location)) {
             foreach ($results as $result => $variables) {
                 try {
                     foreach ($variables as $key => $value) {
                         // checks for $location variables, and that it has a latitude and longitude within it
                         if (strtolower($location) == strtolower($key)) {
                             if (!is_array($value) || !isset($value['latitude']) || !$value['latitude'] || !isset($value['longitude']) || !$value['longitude']) {
                                 throw new Exception("nope");
                             }
                         }
                     }
                 } catch (Exception $e) {
                     unset($results[$result]);
                 }
             }
         }
         $list = $list + $results;
     }
     // default sort is by date
     if ($sort_by == 'date') {
         uasort($list, 'statamic_sort_by_datetime');
     } elseif ($sort_by == 'title') {
         uasort($list, "statamic_sort_by_title");
     } elseif ($sort_by == 'random') {
         shuffle($list);
     } elseif ($sort_by == 'numeric' || $sort_by == 'number') {
         uasort($list, function ($a, $b) {
             return Helper::compareValues($a['numeric'], $b['numeric']);
         });
     } elseif ($sort_by == 'distance' && !is_null($location) && !is_null($distance_from) && preg_match(Pattern::COORDINATES, trim($distance_from))) {
         uasort($list, "statamic_sort_by_distance");
     } elseif ($sort_by != 'date') {
         # sort by any other field
         uasort($list, function ($a, $b) use($sort_by) {
             if (isset($a[$sort_by]) && isset($b[$sort_by])) {
                 return strcmp($b[$sort_by], $a[$sort_by]);
             }
         });
     }
     // default sort is asc
     if ($sort_dir == 'desc') {
         $list = array_reverse($list);
     }
     // handle offset/limit
     if ($offset > 0) {
         $list = array_splice($list, $offset);
     }
     if ($limit) {
         $list = array_splice($list, 0, $limit);
     }
     if ($switch) {
         $switch_vars = explode('|', $switch);
         $switch_count = count($switch_vars);
         $count = 1;
         foreach ($list as $key => $post) {
             $list[$key]['switch'] = $switch_vars[($count - 1) % $switch_count];
             $count++;
         }
     }
     return $list;
 }
 public function index()
 {
     /*
     |--------------------------------------------------------------------------
     | Paramers
     |--------------------------------------------------------------------------
     |
     | Match overrides Extension. Exclusion applies in both cases.
     |
     */
     $match = $this->fetchParam('match', false);
     $exclude = $this->fetchParam('exclude', false);
     $extension = $this->fetchParam(array('extension', 'type'), false);
     $in = $this->fetchParam(array('in', 'folder', 'from'), false);
     $not_in = $this->fetchParam('not_in', false);
     $file_size = $this->fetchParam('file_size', false);
     $file_date = $this->fetchParam('file_date', false);
     $depth = $this->fetchParam('depth', false);
     $sort_by = $this->fetchParam(array('sort_by', 'order_by'), false);
     $sort_dir = $this->fetchParam(array('sort_dir', 'sort_direction'), 'asc');
     $limit = $this->fetchParam('limit', false);
     if ($in) {
         $in = Helper::explodeOptions($in);
     }
     if ($not_in) {
         $not_in = Helper::explodeOptions($not_in);
     }
     if ($file_size) {
         $file_size = Helper::explodeOptions($file_size);
     }
     if ($extension) {
         $extension = Helper::explodeOptions($extension);
     }
     /*
     |--------------------------------------------------------------------------
     | Finder
     |--------------------------------------------------------------------------
     |
     | Get_Files implements most of the Symfony Finder component as a clean
     | tag wrapper mapped to matched filenames.
     |
     */
     $finder = new Finder();
     if ($in) {
         foreach ($in as $location) {
             $finder->in(Path::fromAsset($location));
         }
     }
     /*
     |--------------------------------------------------------------------------
     | Name
     |--------------------------------------------------------------------------
     |
     | Match is the "native" Finder name() method, which is supposed to
     | implement string, glob, and regex. The glob support is only partial,
     | so "extension" is a looped *single* glob rule iterator.
     |
     */
     if ($match) {
         $finder->name($match);
     } elseif ($extension) {
         foreach ($extension as $ext) {
             $finder->name("*.{$ext}");
         }
     }
     /*
     |--------------------------------------------------------------------------
     | Exclude
     |--------------------------------------------------------------------------
     |
     | Exclude directories from matching. Remapped to "not in" to allow more
     | intuitive differentiation between filename and directory matching.
     |
     */
     if ($not_in) {
         foreach ($not_in as $location) {
             $finder->exclude($location);
         }
     }
     /*
     |--------------------------------------------------------------------------
     | Not Name
     |--------------------------------------------------------------------------
     |
     | Exclude files matching a given pattern: string, regex, or glob.
     | By default we don't allow looking for PHP files. Be smart.
     |
     */
     if ($this->fetchParam('allow_php', false) !== TRUE) {
         $finder->notName("*.php");
     }
     if ($exclude) {
         $finder->notName($exclude);
     }
     /*
     |--------------------------------------------------------------------------
     | File Size
     |--------------------------------------------------------------------------
     |
     | Restrict files by size. Can be chained and allows comparison operators.
     |
     */
     if ($file_size) {
         foreach ($file_size as $size) {
             $finder->size($size);
         }
     }
     /*
     |--------------------------------------------------------------------------
     | File Date
     |--------------------------------------------------------------------------
     |
     | Restrict files by last modified date. Can use comparison operators, and
     | since/after is aliased to >, and until/before to <.
     |
     */
     if ($file_date) {
         $finder->date($file_date);
     }
     /*
     |--------------------------------------------------------------------------
     | Depth
     |--------------------------------------------------------------------------
     |
     | Recursively traverse directories, starting at 0.
     |
     */
     if ($depth) {
         $finder->depth($depth);
     }
     /*
     |--------------------------------------------------------------------------
     | Sort By
     |--------------------------------------------------------------------------
     |
     | Sort by name, file, or type
     |
     */
     if ($sort_by) {
         if ($sort_by === 'file' || $sort_by === 'name') {
             $finder->sortByName();
         } elseif ($sort_by === 'type') {
             $finder->sortByType();
         }
     }
     /*
     |--------------------------------------------------------------------------
     | Assemble File Array
     |--------------------------------------------------------------------------
     |
     | Select the important bits of data on the list of files.
     |
     */
     $matches = $finder->files()->followLinks();
     $files = array();
     foreach ($matches as $file) {
         $files[] = array('extension' => $file->getExtension(), 'filename' => $file->getFilename(), 'file' => Path::toAsset($file->getPathname()), 'name' => Path::toAsset($file->getPathname()), 'size' => File::getHumanSize($file->getSize()), 'size_bytes' => $file->getSize(), 'size_kilobytes' => number_format($file->getSize() / 1024, 2), 'size_megabytes' => number_format($file->getSize() / 1048576, 2), 'size_gigabytes' => number_format($file->getSize() / 1073741824, 2), 'is_image' => File::isImage($file->getPathname()));
     }
     /*
     |--------------------------------------------------------------------------
     | Sort Direction
     |--------------------------------------------------------------------------
     |
     | Set the sort direction, defaulting to "asc" (ascending)
     |
     */
     if ($sort_dir === 'desc') {
         $files = array_reverse($files);
     }
     /*
     |--------------------------------------------------------------------------
     | Randomizing
     |--------------------------------------------------------------------------
     |
     | You can't sort randomly using Symfony finder, so we'll do it manually.
     |
     */
     if ($sort_by === 'random') {
         shuffle($files);
     }
     /*
     |--------------------------------------------------------------------------
     | Limit Files
     |--------------------------------------------------------------------------
     |
     | Limit the number of files returned. Needs to be run after sort_dir to 
     | ensure consistency.
     |
     */
     if ($limit) {
         $files = array_slice($files, 0, $limit);
     }
     return Parse::tagLoop($this->content, $files, true, $this->context);
 }
コード例 #14
0
ファイル: helper.php プロジェクト: nob/joi
 public static function explode_options($string, $keyed = FALSE)
 {
     Log::warn("Use of Statamic_Helper::explode_options() is deprecated. Use Helper::explodeOptions() instead.", "core", "Statamic_Helper");
     return Helper::explodeOptions($string, $keyed);
 }
コード例 #15
0
 function cleanFoldersList($folder_params)
 {
     $folder_params_array = Helper::explodeOptions($folder_params, false);
     foreach ($folder_params_array as $part) {
         $folders[] = '/_content' . Path::resolve($part) . '/';
     }
     return $folders;
 }