|
<?php |
|
|
|
/** |
|
* Temporary Tags for Text fields |
|
* |
|
* I need to push my site out ASAP, fast. I need this. |
|
* |
|
* @author Adam Kiss |
|
* @version 1.0 |
|
* @since 2012-09-20 |
|
* @license None. I don't care |
|
* |
|
* @link http://www.adamkiss.com |
|
*/ |
|
|
|
class TextformatterTempTags extends Textformatter implements Module { |
|
|
|
/*************************************************************************************************** |
|
MODULE INFO |
|
***************************************************************************************************/ |
|
|
|
public static function getModuleInfo() { |
|
return array( |
|
// basic information |
|
'title' => 'Temporary adamkiss.com tags', |
|
'version' => 100, |
|
// load information |
|
'singular' => true, |
|
'autoload' => false |
|
); |
|
} |
|
|
|
/*************************************************************************************************** |
|
VARIABLES |
|
***************************************************************************************************/ |
|
|
|
/** |
|
* Regexp for single tags |
|
*/ |
|
private $_rgx_tag = '/{{\s?([^}]*)\s?([^}]*)?\s?}}/'; |
|
|
|
/*************************************************************************************************** |
|
MODULE STUFF (SUBMODULES, RUNNER) |
|
***************************************************************************************************/ |
|
|
|
public function formatValue(Page $page, Field $field, &$value) { |
|
$value = $this->applyTags($str); |
|
} |
|
|
|
/*************************************************************************************************** |
|
DATA MANIPULATION & CACHE |
|
***************************************************************************************************/ |
|
|
|
|
|
private function applyTags( $text ) { |
|
//init |
|
$html = $text; |
|
|
|
$found = ''; $tagsFound = array(); |
|
|
|
preg_match_all($this->_rgx_tag, $html, $found, PREG_SET_ORDER); |
|
|
|
foreach ($found as $f){ |
|
try { |
|
$original = $f[0]; |
|
$parts = explode(' ', $f[1]); |
|
$tag = explode(':', array_shift($parts)); |
|
// $tag now should be array(0=>group, 1=>functions) |
|
|
|
$parameters = implode('', $parts); |
|
if (!empty($parameters)){ |
|
$params = new Selectors($parameters); |
|
}else{ |
|
$params = false; |
|
} |
|
|
|
//apply tag by group, function and send parameters |
|
$html = str_ireplace( |
|
$original, |
|
$this->{$tag[1]}($parameters), |
|
$html); |
|
} catch (Exception $e) { |
|
// |
|
} |
|
} |
|
|
|
return $html; |
|
} |
|
|
|
/*************************************************************************************************** |
|
TEMP TAGS |
|
***************************************************************************************************/ |
|
|
|
private function image($params){ |
|
// image |
|
} |
|
|
|
private function figure($params){ |
|
// figure |
|
} |
|
|
|
private function gist($params){ |
|
// this is simple, right? |
|
if ($params[0]->field === 'url') |
|
return "<script src=\"https://gist.github.com/{$params[0]->value}\"></script>"; |
|
} |
|
} |