Пример #1
0
 /**
  * Read a text which represents an email and splits it into fragments.
  *
  * @param string $text  A text.
  * @return array
  */
 public function read($text)
 {
     if (preg_match('/^(On(.+)wrote:)$/ms', $text, $matches)) {
         $text = str_replace($matches[1], str_replace("\n", ' ', $matches[1]), $text);
     }
     $lines = explode("\n", strrev($text));
     $fragment = null;
     $isQuoted = false;
     $foundVisible = false;
     foreach ($lines as $line) {
         $line = preg_replace("/\n\$/", '', ltrim($line));
         // isQuoted ?
         $isQuoted = preg_match('/(>+)$/', $line) ? true : false;
         if (null !== $fragment && empty($line)) {
             if (preg_match('/(--|__|\\w-$)|(^(\\w+\\s*){1,3} ym morf tneS$)/', $fragment->getLastLine())) {
                 $fragment->setIsSignature(true);
                 if (!$foundVisible) {
                     if ($fragment->isQuoted() || $fragment->isSignature() || $fragment->isEmpty()) {
                         $fragment->setIsHidden(true);
                     } else {
                         $foundVisible = true;
                     }
                 }
                 $this->fragments[] = $fragment;
                 $fragment = null;
             }
         }
         if (null !== $fragment && ($isQuoted === $fragment->isQuoted() || preg_match('/^:etorw.*nO$/', $line) || empty($line))) {
             $fragment->addLine($line);
         } else {
             if (null !== $fragment) {
                 if (!$foundVisible) {
                     if ($fragment->isQuoted() || $fragment->isSignature() || $fragment->isEmpty()) {
                         $fragment->setIsHidden(true);
                     } else {
                         $foundVisible = true;
                     }
                 }
                 $this->fragments[] = $fragment;
             }
             $fragment = null;
             $fragment = new Fragment($line, $isQuoted);
         }
     }
     if (null !== $fragment) {
         if (!$foundVisible) {
             if ($fragment->isQuoted() || $fragment->isSignature() || $fragment->isEmpty()) {
                 $fragment->setIsHidden(true);
             } else {
                 $foundVisible = true;
             }
         }
         $this->fragments[] = $fragment;
     }
     $this->fragments = array_reverse($this->fragments);
     return $this->fragments;
 }
Пример #2
0
 /**
  * default constructor
  */
 function Feature($language, $train, $tmp_dir, $output_dir, $fragments = null)
 {
     $this->language = $language;
     $this->train = $train;
     if (!$fragments) {
         $fragments = Fragment::select($language, $train);
     }
     $this->fragments = $fragments;
     $this->output_dir = $output_dir;
     $this->tmp_dir = $tmp_dir;
     $projects = $this->associated_projects();
     if (count($projects) == 1) {
         $this->feature_id = "org.eclipse.babel.nls_" . $projects[0]->id . "_" . $language->iso;
     } else {
         $this->feature_id = "org.eclipse.babel.nls_" . $language->iso;
     }
 }
Пример #3
0
 /**
  * 
  * @param Model_Page_Front $page
  * @param string $part
  * @param boolean $inherit
  * @param integer $cache_lifetime
  * @return void
  */
 public static function content(Model_Page_Front $page, $part = 'body', $inherit = FALSE, $cache_lifetime = NULL, array $tags = array())
 {
     if (self::exists($page, $part)) {
         $view = self::get($page->id(), $part);
         if ($cache_lifetime !== NULL and !Fragment::load($page->id() . $part . Request::current()->uri(), (int) $cache_lifetime)) {
             echo $view;
             Fragment::save_with_tags((int) $cache_lifetime, array('page_parts'));
         } else {
             if ($cache_lifetime === NULL) {
                 echo $view;
             }
         }
     } else {
         if ($inherit !== FALSE and $page->parent() instanceof Model_Page_Front) {
             self::content($page->parent(), $part, TRUE, $cache_lifetime);
         }
     }
 }
Пример #4
0
 /**
  * 
  * @param string $snippet_name
  * @param array $vars
  * @param integer $cache_lifetime
  * @param boolean $cache_by_uri
  * @param array $tags
  * @param boolean $i18n
  * @return void
  */
 public static function render($snippet_name, $vars = NULL, $cache_lifetime = NULL, $cache_by_uri = FALSE, array $tags = array(), $i18n = NULL)
 {
     $view = Snippet::get($snippet_name, $vars);
     if ($view === NULL) {
         return NULL;
     }
     $cache_key = self::_cache_key($snippet_name, $cache_by_uri);
     if (!in_array($snippet_name, $tags)) {
         $tags[] = $snippet_name;
     }
     if (Kohana::$caching === TRUE and $cache_lifetime !== NULL and !Fragment::load($cache_key, (int) $cache_lifetime, $i18n)) {
         echo $view;
         Fragment::save_with_tags((int) $cache_lifetime, $tags);
     } else {
         if ($cache_lifetime === NULL) {
             echo $view;
         }
     }
 }
Пример #5
0
 /**
  * Delete a cached fragment.
  *
  *     Fragment::delete($key);
  *
  * @param   string  $name   fragment name
  * @param   boolean $i18n   multilingual fragment support
  * @return  void
  */
 public static function delete($name, $i18n = NULL)
 {
     // Invalid the cache
     Kohana::cache(Fragment::_cache_key($name, $i18n), NULL, -3600);
 }
Пример #6
0
 /**
  * Delete a cached fragment.
  *
  *     Fragment::delete($key);
  *
  * @param   string  $name   fragment name
  * @param   boolean $i18n   multilingual fragment support
  * @return  void
  */
 public static function delete($name, $i18n = NULL)
 {
     // Invalid the cache
     Cache::instance()->delete(Fragment::_cache_key($name, $i18n));
 }
Пример #7
0
 private function delete_album_fragment($id)
 {
     try {
         Fragment::delete("album_{$id}");
     } catch (Exception $e) {
     }
 }
Пример #8
0
<?php

// Displayed feeds are cached for 5 minutes
if (!Fragment::load('feed:' . $feed . ':' . $limit, Date::MINUTE * 5)) {
    // Parse the feed
    $items = Feed::parse($feed, $limit);
    // Set the "link" and "title" variable names
    isset($link) or $link = 'link';
    isset($title) or $title = 'title';
    foreach ($items as $item) {
        // Clean the title so no one can inject anything
        $clean = html::chars($item[$title]);
        // Shorten it to 50 characters, but don't cut words in half, add 2 so that if the 51st char is a space, it will grab the 52nd character, and the word its attached to, so that the strrpos below works.
        $short = Text::limit_chars($clean, 52, false, true);
        // If the string is longer than 50 chars, cut off the leftover workd from limit_chars, and append '...'
        if (strlen($short) > 50) {
            $short = substr($short, 0, strrpos($short, ' ')) . '&#8230;';
        }
        // At this point, $short is at MAX 51 characters (50 characters of the string + "..."), usually less, because its rare for the words to line up exactly with the 50th character.
        echo '<li>' . HTML::anchor($item[$link], $short, array('title' => $clean)) . '</li>';
    }
    Fragment::save();
}
Пример #9
0
 public static function cached_fragment($name, $lifetime = NULL, $i18n = NULL)
 {
     if (isset(static::$_cache_buffers[$name]) && static::$_cache_buffers[$name] === TRUE) {
         $buffer_id = array_pop(static::$_cache_buffer_pull);
         unset(static::$_cache_buffers[$name]);
         Fragment::save();
         return FALSE;
     }
     static::$_cache_buffers[$name] = TRUE;
     static::$_cache_buffer_pull[] = $name;
     if (NULL != $lifetime) {
         $lifetime *= 60;
     }
     if (Fragment::load($name, $lifetime, $i18n)) {
         $buffer_id = array_pop(static::$_cache_buffer_pull);
         unset(static::$_cache_buffers[$name]);
         return FALSE;
     }
     return TRUE;
 }
Пример #10
0
 /**
  * Splits the given text into a list of Fragments.  This is roughly done by
  * reversing the text and parsing from the bottom to the top.  This way we
  * can check for 'On <date>, <author> wrote:' lines above quoted blocks.
  *
  * @param string $text A email body.
  * @param string $encoding Optional encoding to be used when parsing the text.
  * @return array A list of parsed Fragments.
  */
 public static function read($text, $encoding = null)
 {
     // Resets everything before starting
     self::$_foundVisible = false;
     self::$_fragments = array();
     self::$_fragment = null;
     self::$_encoding = $encoding;
     // Check for multi-line reply headers. Some clients break up
     // the "On DATE, NAME <EMAIL> wrote:" line into multiple lines.
     $text = preg_replace_callback('/^(On.*wrote:)$/msU', function ($matches) {
         return str_replace("\n", ' ', $matches[1]);
     }, $text);
     // Normalize line breaks.
     $text = str_replace("\r\n", "\n", $text);
     // The text is reversed initially due to the way we check for hidden fragments.
     $text = Fragment::reverse($text, self::$_encoding);
     // Strip any extra new lines or spaces from start.
     $text = rtrim($text);
     // Split into lines.
     $lines = preg_split("/\n/", $text);
     // Scan each line of the email content.
     foreach ($lines as $line) {
         self::_scanLine($line);
     }
     // Free variables
     unset($text, $lines);
     // Finish up the final fragment. Finishing a fragment will detect any
     // attributes (hidden, signature, reply), and join each line into a string.
     self::_finishFragment();
     // Now that parsing is done, reverse the order.
     self::$_fragments = array_reverse(self::$_fragments);
     return self::$_fragments;
 }
Пример #11
0
 /**
  * Get the contents of a fragment cache.
  *
  * @param  string   $key
  * @param  Closure  $callback
  */
 public static function sear($key, Closure $callback)
 {
     return Cache::sear($key, function () use($callback) {
         return Fragment::execute($callback);
     });
 }
Пример #12
0
 /**
  * Removes a single Fragment from RDF Store by deleting all triples describing the Fragment URI
  * WARNING: As far as triples extracted from the RDFa representation of a given fragment are concerned,
  *          this method only removes the following:
  *			1) fragmentURI loomp:contains sommeURI .
  *			2) all triples: someURI someProperty someOtherURI  or   someURI someProperty someLiteral
  *		    If there are other triples further describing someOtherURI they will not be removed, becuase this
  * 		    requires the analysis of the entire RDF graph, i.e. the paths from someOtherURI to other fragmentURIs.
  *		    At this point I do not have sufficient test data to play with. --> future work
  *
  * @param Fragment	$fragment	Fragment Object
  */
 private function _removeFragment($fragment)
 {
     $it = $this->rdfModel->find(new Resource($fragment->getUri()), LOOMP::CONTAINS(), NULL)->getStatementIterator();
     $this->_removeResWithAllProps($fragment->getUri());
     // remove all triples describing a given resource which is not contained in any other fragment
     while ($it->hasNext()) {
         $s = $it->next();
         $obj = $s->getObject();
         if ($this->rdfModel->findCount(NULL, LOOMP::CONTAINS(), $obj) == 0) {
             $this->_removeResWithAllProps($obj->getURI());
         }
     }
 }
Пример #13
0
 /**
  * Рендер виджета во Frontend
  * 
  * Отключение комментариев для блока
  * 
  *		Block::run('block_name', array('comments' => FALSE));
  * 
  * Отключение кеширования виджетов в блоке
  * 
  *		Block::run('block_name', array('caching' => FALSE));
  * 
  * @param array $params Дополнительные параметры
  */
 public function render(array $params = array())
 {
     // Проверка прав на видимость виджета
     if (!empty($this->roles)) {
         if (Auth::is_logged_in()) {
             if (!Auth::has_permissions($this->roles, FALSE)) {
                 return;
             }
         } else {
             return;
         }
     }
     if (Kohana::$profiling === TRUE) {
         $benchmark = Profiler::start('Widget render', $this->name);
     }
     $this->_fetch_template();
     $this->set_params($params);
     $allow_omments = (bool) Arr::get($this->template_params, 'comments', TRUE);
     $caching = (bool) Arr::get($this->template_params, 'caching', $this->caching);
     if ($this->block == 'PRE' or $this->block == 'POST') {
         $allow_omments = FALSE;
     }
     if (Kohana::$caching === FALSE or $caching === FALSE) {
         $this->caching = FALSE;
     }
     if (Arr::get($this->template_params, 'return') === TRUE) {
         return $this->_fetch_render();
     }
     if ($allow_omments) {
         echo "<!--{Widget: {$this->name}}-->";
     }
     if ($this->caching === TRUE and !Fragment::load($this->get_cache_id(), $this->cache_lifetime, TRUE)) {
         echo $this->_fetch_render();
         Fragment::save_with_tags($this->cache_lifetime, $this->cache_tags);
     } else {
         if (!$this->caching) {
             echo $this->_fetch_render();
         }
     }
     if ($allow_omments) {
         echo "<!--{/Widget: {$this->name}}-->";
     }
     if (isset($benchmark)) {
         Profiler::stop($benchmark);
     }
 }
Пример #14
0
 /**
  * Update fragment
  * @param integer $id
  * @param array   $data
  */
 public function update($id, $data)
 {
     // First validate the input
     if ($this->validation->passes($data)) {
         // Set the data
         $fragment = Fragment::find($id);
         $fragment->fill(array('title' => array_get($data, 'title'), 'body' => array_get($data, 'body')));
         // Slug
         if ($slug = array_get($data, 'slug') and $slug != $fragment->slug) {
             $fragment->slug = Str::slug($slug);
         }
         return $fragment->save();
     }
     // Set errors
     $this->errors = $this->validation->errors();
     return false;
 }