Exemple #1
0
 /**
  * Include JavaScript code or file
  * @param string $value Code or file path
  * @param string $type  Whether to include as "code" or a "file"
  * @param string $match Optional regex, will include if the URL matches
  * @return Plugin
  */
 protected final function _addJs($value, $type = "code", $match = null)
 {
     if ($type == "file") {
         \Helper\Plugin::instance()->addJsFile($value, $match);
     } else {
         \Helper\Plugin::instance()->addJsCode($value, $match);
     }
     return $this;
 }
Exemple #2
0
 public function testJsCode()
 {
     $helper = \Helper\Plugin::instance();
     // Add JS code block
     $helper->addJsCode("'test';", "/^\\/test1/");
     // Get JS code block list
     $result1 = $helper->getJsCode("/test1");
     $result2 = $helper->getJsCode("/test2");
     $expected = array("'test';");
     $this->assertEquals($result1, $expected);
     $this->assertNotEquals($result2, $expected);
 }
Exemple #3
0
 /**
  * Convert Textile or Markdown to HTML, adding hashtags
  * @param  string $str
  * @param  array  $options
  * @param  int    $ttl
  * @return string
  */
 public function parseText($str, $options = array(), $ttl = null)
 {
     if ($options === null) {
         $options = array();
     }
     $options = $options + \Base::instance()->get("parse");
     // Check for cached value if $ttl is set
     if ($ttl !== null) {
         $cache = \Cache::instance();
         $hash = sha1($str . json_encode($options));
         // Return value if cached
         if (($str = $cache->get("{$hash}.tex")) !== false) {
             return $str;
         }
     }
     // Pass to any plugin hooks
     $str = \Helper\Plugin::instance()->callHook("text.parse.before", $str);
     // Run through the parsers based on $options
     if ($options["ids"]) {
         $str = $this->_parseIds($str);
     }
     if ($options["hashtags"]) {
         $str = $this->_parseHashtags($str);
     }
     if ($options["markdown"]) {
         $str = $this->_parseMarkdown($str);
     }
     if ($options["textile"]) {
         if ($options["markdown"]) {
             // Yes, this is hacky. Please open an issue on GitHub if you
             // know of a better way of supporting Markdown and Textile :)
             $str = html_entity_decode($str);
             $str = preg_replace('/^<p>|<\\/p>$/m', "\n", $str);
         }
         $str = $this->_parseTextile($str);
     }
     if ($options["emoticons"]) {
         $str = $this->_parseEmoticons($str);
     }
     if ($options["urls"]) {
         $str = $this->_parseUrls($str);
     }
     // Pass to any plugin hooks
     $str = \Helper\Plugin::instance()->callHook("text.parse.after", $str);
     // Cache the value if $ttl is set
     if ($ttl !== null) {
         $cache->set("{$hash}.tex", $str, $ttl);
     }
     return $str;
 }
Exemple #4
0
 /**
  * Save model, triggering plugin hooks and setting created_date
  * @return mixed
  */
 function save()
 {
     // Ensure created_date is set if possible
     if (!$this->query && array_key_exists("created_date", $this->fields) && !$this->get("created_date")) {
         $this->set("created_date", date("Y-m-d H:i:s"));
     }
     // Call before_save hooks
     $hookName = str_replace("\\", "/", strtolower(get_class($this)));
     \Helper\Plugin::instance()->callHook("model.before_save", $this);
     \Helper\Plugin::instance()->callHook($hookName . ".before_save", $this);
     // Save object
     $result = parent::save();
     // Call after save hooks
     \Helper\Plugin::instance()->callHook("model.after_save", $this);
     \Helper\Plugin::instance()->callHook($hookName . ".after_save", $this);
     return $result;
 }