コード例 #1
0
 public function __call($method, $arguments)
 {
     $extensions = array(".html", ".md", ".markdown", ".textile");
     $html = null;
     foreach ($extensions as $extension) {
         $full_src = Path::assemble(BASE_PATH, Config::getCurrentThemePath(), 'partials', ltrim($method . $extension, '/'));
         if (File::exists($full_src)) {
             // Merge additional variables passed as parameters
             Statamic_View::$_dataStore = $arguments + Statamic_View::$_dataStore;
             if ($this->fetchParam('use_context', false, false, true, false)) {
                 $html = Parse::contextualTemplate(File::get($full_src), Statamic_View::$_dataStore, $this->context, 'Statamic_View::callback');
             } else {
                 $html = Parse::template(File::get($full_src), Statamic_View::$_dataStore, 'Statamic_View::callback');
             }
             // parse contents if needed
             if ($extension == ".md" || $extension == ".markdown") {
                 $html = Parse::markdown($html);
             } elseif ($extension == ".textile") {
                 $html = Parse::textile($html);
             }
         }
     }
     if (Config::get('enable_smartypants', TRUE)) {
         $html = Parse::smartypants($html);
     }
     return $html;
 }
 public function words()
 {
     $limit = $this->fetchParam('limit', NULL);
     $ending = $this->fetchParam('ending', '...', null, false, false);
     $this->content = Parse::contextualTemplate($this->content, array(), $this->context);
     $words = preg_split("/[\n\r\t ]+/", $this->content, $limit + 1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_OFFSET_CAPTURE);
     if (count($words) > $limit) {
         end($words);
         $last_word = prev($words);
         $this->content = substr($this->content, 0, $last_word[1] + strlen($last_word[0])) . $ending;
     }
     return $this->content;
 }
コード例 #3
0
 public function index()
 {
     // if disabled, do nothing
     if (!$this->core->isEnabled()) {
         return Parse::contextualTemplate($this->content, array(), $this->context);
     }
     // grab and prepare parameters
     $key = $this->fetchParam('key', null, null, false, false);
     $age = time() - Date::resolve('-' . $this->fetch(array('for', 'default_cache_length'), '12 hours', null, false, false));
     $hash = $this->fetch(array('scope', 'default_scope'), 'site') === 'page' ? Helper::makeHash(URL::getCurrent(), $this->content) : Helper::makeHash($this->content);
     $path = 'troves/' . $hash;
     // deal with keys
     if ($key) {
         // split on pipes
         $keys = explode('|', $key);
         // loop through keys, storing this hash to this key
         foreach ($keys as $key) {
             $key_path = 'keys/' . trim($key);
             // get existing keys
             $hashes = $this->cache->getYAML($key_path, array());
             $new_hashes = array();
             // check that the hashes are all still valid
             foreach ($hashes as $new_hash) {
                 if ($this->cache->exists('troves/' . $new_hash)) {
                     $new_hashes[] = $new_hash;
                 }
             }
             // add this one
             $new_hashes[] = $hash;
             // append new ones
             $this->cache->putYAML($key_path, array_unique($new_hashes));
         }
     }
     // check for pre-existing cache
     if (!$this->cache->exists($path) || $this->cache->getAge($path) > $age) {
         // cache doesn't exist or has expired, so parse this contextually...
         $html = Parse::contextualTemplate($this->content, array(), $this->context);
         // ...and store the HTML
         $this->cache->put($path, $html);
     }
     // garbage collection
     $this->core->collectGarbage();
     // return what we know
     return $this->cache->get($path);
 }
コード例 #4
0
 public function partial()
 {
     $start = time();
     $src = $this->fetchParam('src', null, null, false, false);
     $extensions = array(".html", ".md", ".markdown", ".textile");
     $html = null;
     // measurement
     $hash = Debug::markStart('partials', $src, $start);
     Debug::increment('partials', $src);
     if ($src) {
         foreach ($extensions as $extension) {
             $full_src = Path::assemble(BASE_PATH, $this->theme_root, 'partials', ltrim($src . $extension, '/'));
             if (File::exists($full_src)) {
                 Statamic_View::$_dataStore = $this->attributes + Statamic_View::$_dataStore;
                 if ($this->fetchParam('use_context', false, false, true, false)) {
                     // to use context, we only want to pass the attributes as
                     // the current data, as those will override into the context
                     // set of data; if we were to include all of ::$_dataStore,
                     // we run into the issue where all of the global-level variables
                     // are overriding variables in context, when the variables in
                     // context are more accurate scope-wise at this point in the parse
                     $html = Parse::contextualTemplate(file_get_contents($full_src), $this->attributes, $this->context, array('statamic_view', 'callback'), true);
                 } else {
                     $html = Parse::template(file_get_contents($full_src), Statamic_View::$_dataStore);
                 }
                 // parse contents if needed
                 if ($extension == ".md" || $extension == ".markdown") {
                     $html = Parse::markdown($html);
                 } elseif ($extension == ".textile") {
                     $html = Parse::textile($html);
                 }
             }
         }
         if (Config::get('enable_smartypants', TRUE)) {
             $html = Parse::smartypants($html);
         }
     }
     Debug::markEnd($hash);
     return $html;
 }
コード例 #5
0
ファイル: pi.raven.php プロジェクト: jalmelb/24hl2015
	/**
	 * Allows you to output data from the submission
	 *
	 * @return string
	 **/
	public function submission()
	{
		if ( ! $this->flash->exists('submission')) {
			return;
		}

		return Parse::contextualTemplate($this->content, $this->flash->get('submission'), $this->context);
	}
コード例 #6
0
ファイル: parse.php プロジェクト: Bferreira5/Theme-Example
 /**
  * Parses a tag loop, replacing template variables with each array in a list of arrays
  *
  * @param string  $content  Template for replacing
  * @param array  $data  Array of arrays containing values
  * @param bool  $supplement  Supplement each loop with contextual information?
  * @param array  $context  Contextual data to add into loop
  * @return string
  */
 public static function tagLoop($content, $data, $supplement = false, $context = array())
 {
     $output = '';
     if ($supplement) {
         // loop through each record of $data
         $i = 1;
         $count = count($data);
         foreach ($data as $item) {
             $item['first'] = $i === 1;
             $item['last'] = $i === $count;
             $item['index'] = $i;
             $item['zero_index'] = $i - 1;
             $item['total_results'] = $count;
             $output .= Parse::contextualTemplate($content, $item, $context);
             $i++;
         }
     } else {
         foreach ($data as $item) {
             $output .= Parse::contextualTemplate($content, $item, $context, array('statamic_view', 'callback'));
         }
     }
     return $output;
 }
コード例 #7
0
 public function generateModal($files, $destination)
 {
     $vars = array('server_files' => $files, 'destination' => $destination, 'secure_destination' => urlencode(Helper::encrypt($destination)), 'cp_url' => URL::assemble(Config::getSiteRoot(), Config::get('admin_path') . '.php'), 'default_thumbnail' => $this->defaultFileThumbnail(), 'allow_delete' => (bool) Config::get('allow_file_field_deletions'));
     $template = File::get($this->getAddonLocation() . 'views/modal.html');
     return Parse::contextualTemplate($template, $vars, Config::getAll());
 }
コード例 #8
0
ファイル: hooks.raven.php プロジェクト: Synergy23/RealEstate
 /**
  * Send a notification/response email
  *
  * @param array $submission Array of submitted values
  * @param array $email Array of email config values
  * @param array $config Array of config values
  */
 private function send($submission, $email, $config)
 {
     $attributes = array_intersect_key($email, array_flip(Email::$allowed));
     if (array_get($email, 'automagic') || array_get($email, 'automatic')) {
         $automagic_email = $this->buildAutomagicEmail($submission);
         $attributes['html'] = $automagic_email['html'];
         $attributes['text'] = $automagic_email['text'];
     }
     if ($html_template = array_get($email, 'html_template', false)) {
         $attributes['html'] = Theme::getTemplate($html_template);
     }
     if ($text_template = array_get($email, 'text_template', false)) {
         $attributes['text'] = Theme::getTemplate($text_template);
     }
     /*
     |--------------------------------------------------------------------------
     | Parse all fields
     |--------------------------------------------------------------------------
     |
     | All email settings are parsed with the form data, allowing you, for
     | example, to send an email to a submitted email address.
     |
     |
     */
     $globals = Config::getAll();
     array_walk_recursive($attributes, function (&$value, $key) use($submission, $globals) {
         $value = Parse::contextualTemplate($value, $submission, $globals);
     });
     $attributes['email_handler'] = array_get($config, 'email_handler', null);
     $attributes['email_handler_key'] = array_get($config, 'email_handler_key', null);
     $attributes['smtp'] = array_get($config, 'smtp', null);
     Email::send($attributes);
 }
コード例 #9
0
ファイル: pi.killwhite.php プロジェクト: jeffreyDcreative/gkp
 function index()
 {
     $content = Parse::contextualTemplate($this->content, array(), $this->context);
     return trim(preg_replace('/\\s+/', ' ', $content), " \t\n");
 }
コード例 #10
0
 private function getMessage()
 {
     $this->what = $this->fetchParam('what', 'log', null, false, false);
     $this->specifically = $this->fetchParam('specifically', 'message', null, false, false);
     $this->message = Parse::contextualTemplate(trim($this->fetchParam('message', $this->content, null, false, false)), array(), $this->context);
 }