diff options
Diffstat (limited to 'vendor/flexi/lib')
| -rw-r--r-- | vendor/flexi/lib/exceptions.php | 23 | ||||
| -rw-r--r-- | vendor/flexi/lib/flexi.php | 41 | ||||
| -rw-r--r-- | vendor/flexi/lib/helper/js_helper.php | 135 | ||||
| -rw-r--r-- | vendor/flexi/lib/helper/prototype_helper.php | 764 | ||||
| -rw-r--r-- | vendor/flexi/lib/helper/scriptaculous_helper.php | 142 | ||||
| -rw-r--r-- | vendor/flexi/lib/helper/tag_helper.php | 122 | ||||
| -rw-r--r-- | vendor/flexi/lib/helper/text_helper.php | 183 | ||||
| -rw-r--r-- | vendor/flexi/lib/js_template.php | 55 | ||||
| -rw-r--r-- | vendor/flexi/lib/mustache_template.php | 85 | ||||
| -rw-r--r-- | vendor/flexi/lib/php_template.php | 119 | ||||
| -rw-r--r-- | vendor/flexi/lib/template.php | 251 | ||||
| -rw-r--r-- | vendor/flexi/lib/template_factory.php | 281 |
12 files changed, 0 insertions, 2201 deletions
diff --git a/vendor/flexi/lib/exceptions.php b/vendor/flexi/lib/exceptions.php deleted file mode 100644 index befb789..0000000 --- a/vendor/flexi/lib/exceptions.php +++ /dev/null @@ -1,23 +0,0 @@ -<?php - -# Copyright (c) 2009 - Marcus Lunzenauer <mlunzena@uos.de> -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -class Flexi_TemplateNotFoundException extends Exception {} diff --git a/vendor/flexi/lib/flexi.php b/vendor/flexi/lib/flexi.php deleted file mode 100644 index ab94661..0000000 --- a/vendor/flexi/lib/flexi.php +++ /dev/null @@ -1,41 +0,0 @@ -<?php - -# Copyright (c) 2008 - Marcus Lunzenauer <mlunzena@uos.de> -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -define('FLEXI_VERSION', '0.5.0'); - -/** - * Bootstrapping file for flexi. Just include this to get going. - * - * @package flexi - */ - -require_once 'exceptions.php'; -require_once 'template.php'; -require_once 'template_factory.php'; -require_once 'php_template.php'; -require_once 'js_template.php'; - -require_once 'helper/js_helper.php'; -require_once 'helper/prototype_helper.php'; -require_once 'helper/scriptaculous_helper.php'; -require_once 'helper/tag_helper.php'; -require_once 'helper/text_helper.php'; diff --git a/vendor/flexi/lib/helper/js_helper.php b/vendor/flexi/lib/helper/js_helper.php deleted file mode 100644 index b641f4e..0000000 --- a/vendor/flexi/lib/helper/js_helper.php +++ /dev/null @@ -1,135 +0,0 @@ -<?php - -# Copyright (c) 2008 - Marcus Lunzenauer <mlunzena@uos.de> -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -/** - * Provides functionality for working with JavaScript in your views. - * - * @package flexi - * @subpackage helper - * - * @author Marcus Lunzenauer (mlunzena@uos.de) - * @author David Heinemeier Hansson - * @copyright (c) Authors - * @version $Id: js_helper.php 3437 2006-05-27 11:38:58Z mlunzena $ - */ - -class JsHelper { - - /** - * Returns a link that'll trigger a javascript function using the - * onclick handler and return false after the fact. - * - * Example: - * JsHelper::link_to_function('Greeting', "alert('Hello world!')"); - * - * @param type <description> - * @param type <description> - * @param type <description> - * - * @return type <description> - */ - function link_to_function($name, $function, $html = array()) { - $html['href'] = isset($html['href']) ? $html['href'] : '#'; - $html['onclick'] = $function.'; return false;'; - return TagHelper::content_tag('a', $name, $html); - } - - /** - * Returns a link that'll trigger a JavaScript function using the onclick - * handler. - * - * Examples: - * JsHelper::button_to_function("Greeting", "alert('Hello world!')"); - * - * @param type <description> - * @param type <description> - * @param type <description> - * - * @return type <description> - */ - function button_to_function($name, $function, $html_options = array()) { - - $html_options['type'] = 'button'; - $html_options['value'] = $name; - $html_options['onclick'] = sprintf('%s%s;', - isset($html_options['onclick']) ? $html_options['onclick'] . '; ' : '', - $function); - return TagHelper::tag('input', $html_options); - } - - /** - * Escape carrier returns and single and double quotes for Javascript - * segments. - * - * @param type <description> - * - * @return type <description> - */ - function escape_javascript($javascript = '') { - $pattern = array(); $replace = array(); - $pattern[] = '/\\\\/'; $replace[] = '\\\\\\'; - $pattern[] = '/<\//'; $replace[] = '<\\/'; - $pattern[] = "/\r\n/"; $replace[] = '\n'; - $pattern[] = "/\n/"; $replace[] = '\n'; - $pattern[] = "/\r/"; $replace[] = '\n'; - $pattern[] = '/"/'; $replace[] = '\\"'; - $pattern[] = "/'/"; $replace[] = "\\'"; - - $javascript = preg_replace($pattern, $replace, $javascript); - return $javascript; - } - - /** - * Returns a JavaScript tag with the '$content' inside. - * Example: - * JsHelper::javascript_tag("alert('All is good')"); - * => <script type="text/javascript">alert('All is good')</script> - * - * @param type <description> - * - * @return type <description> - */ - function javascript_tag($content) { - return TagHelper::content_tag('script', - JsHelper::js_cdata_section($content), - array('type' => 'text/javascript')); - } - - /** - * @ignore - */ - function js_cdata_section($content) { - return "\n//".TagHelper::cdata_section("\n$content\n//")."\n"; - } - - /** - * @ignore - */ - function options_for_javascript($opt) { - $opts = array(); - foreach ($opt as $key => $value) - $opts[] = "$key:$value"; - sort($opts); - - return '{'.join(', ', $opts).'}'; - } -} diff --git a/vendor/flexi/lib/helper/prototype_helper.php b/vendor/flexi/lib/helper/prototype_helper.php deleted file mode 100644 index 33f8821..0000000 --- a/vendor/flexi/lib/helper/prototype_helper.php +++ /dev/null @@ -1,764 +0,0 @@ -<?php - -# Copyright (c) 2008 - Marcus Lunzenauer <mlunzena@uos.de> -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -/** - * PrototypeHelper. - * - * - * @package flexi - * @subpackage helper - * - * @author Marcus Lunzenauer (mlunzena@uos.de) - * @author David Heinemeier Hansson - * @copyright (c) Authors - * @version $Id: prototype_helper.php 3437 2006-05-27 11:38:58Z mlunzena $ - */ - -class PrototypeHelper { - - /** - * Returns a link to a remote action defined by 'url' (using the 'url_for()' - * format) that's called in the background using XMLHttpRequest. The result of - * that request can then be inserted into a DOM object whose id can be - * specified with 'update'. - * - * Examples: - * link_to_remote('Delete this post', - * array('update' => 'posts', 'url' => 'destroy?id='.$id)) - * - * You can also specify a hash for 'update' to allow for - * easy redirection of output to an other DOM element if a server-side error - * occurs: - * - * Example: - * link_to_remote('Delete this post', - * array('update' => array('success' => 'posts', - * 'failure' => 'error'), - * 'url' => 'destroy?id='.$id)) - * - * Optionally, you can use the 'position' parameter to influence - * how the target DOM element is updated. It must be one of 'before', 'top', - * 'bottom', or 'after'. - * - * By default, these remote requests are processed asynchronous during - * which various JavaScript callbacks can be triggered (for progress - * indicators and the likes). All callbacks get access to the 'request' - * object, which holds the underlying XMLHttpRequest. - * - * The callbacks that may be specified are (in order): - * - * 'loading' Called when the remote document is being - * loaded with data by the browser. - * 'loaded' Called when the browser has finished loading - * the remote document. - * 'interactive' Called when the user can interact with the - * remote document, even though it has not - * finished loading. - * 'success' Called when the XMLHttpRequest is completed, - * and the HTTP status code is in the 2XX range. - * 'failure' Called when the XMLHttpRequest is completed, - * and the HTTP status code is not in the 2XX - * range. - * 'complete' Called when the XMLHttpRequest is complete - * (fires after success/failure if present). - * - * You can further refine 'success' and 'failure' by adding additional - * callbacks for specific status codes: - * - * Example: - * link_to_remote($word, array('url' => $rule, - * '404' => "alert('Not found...?')", - * 'failure' => "alert('HTTPError!')")) - * - * A status code callback overrides the success/failure handlers if present. - * - * If you for some reason or another need synchronous processing (that'll - * block the browser while the request is happening), you can specify - * 'type' => 'synchronous'. - * - * You can customize further browser side call logic by passing - * in JavaScript code snippets via some optional parameters. In - * their order of use these are: - * - * 'confirm' Adds confirmation dialog. - * 'condition' Perform remote request conditionally - * by this expression. Use this to - * describe browser-side conditions when - * request should not be initiated. - * 'before' Called before request is initiated. - * 'after' Called immediately after request was - * initiated and before 'loading'. - * 'submit' Specifies the DOM element ID that's used - * as the parent of the form elements. By - * default this is the current form, but - * it could just as well be the ID of a - * table row or any other DOM element. - * - * @param type <description> - * @param type <description> - * @param type <description> - * - * @return type <description> - */ - function link_to_remote($name, $options = array(), $html_options = array()) { - return JsHelper::link_to_function($name, - PrototypeHelper::remote_function($options), $html_options); - } - - /** - * Periodically calls the specified url ['url'] every ['frequency'] seconds - * (default is 10). Usually used to update a specified div ['update'] with the - * results of the remote call. The options for specifying the target with - * 'url' and defining callbacks is the same as 'link_to_remote()'. - * - * @param type <description> - * - * @return type <description> - */ - function periodically_call_remote($options = array()) { - $frequency = isset($options['frequency']) ? $options['frequency'] : 10; - $code = sprintf('new PeriodicalExecuter(function() {%s}, %d)', - PrototypeHelper::remote_function($options), $frequency); - return JsHelper::javascript_tag($code); - } - - /** - * Returns a form tag that will submit using XMLHttpRequest in the background - * instead of the regular reloading POST arrangement. Even though it's using - * JavaScript to serialize the form elements, the form submission will work - * just like a regular submission as viewed by the receiving side - * (all elements available in 'params'). The options for specifying the target - * with 'url' and defining callbacks are the same as 'link_to_remote()'. - * - * A "fall-through" target for browsers that don't do JavaScript can be - * specified with the 'action' and 'method' options on '$html_options'. - * - * Example: - * form_remote_tag(array( - * 'url' => 'tag_add', - * 'update' => 'question_tags', - * 'loading' => "Element.show('indicator'); tag.value = ''", - * 'complete' => "Element.hide('indicator');". - * visual_effect('highlight', 'question_tags'))) - * - * The hash passed as a second argument is equivalent to the options (2nd) - * argument in the form_tag() helper. - * - * @param type <description> - * - * @return type <description> - */ - function form_remote_tag($options = array(), $html_options = array()) { - - $options = TagHelper::_parse_attributes($options); - $html_options = TagHelper::_parse_attributes($html_options); - - $options['form'] = TRUE; - - $html_options['onsubmit'] = PrototypeHelper::remote_function($options). - '; return false;'; - $html_options['action'] = isset($html_options['action']) - ? $html_options['action'] - : $options['url']; - - $html_options['method'] = isset($html_options['method']) - ? $html_options['method'] - : 'post'; - - return TagHelper::tag('form', $html_options, TRUE); - } - - /** - * Returns a button input tag that will submit form using XMLHttpRequest in - * the background instead of regular reloading POST arrangement. The '$opt' - * argument is the same as in 'form_remote_tag()'. - * - * @param type <description> - * @param type <description> - * @param type <description> - * - * @return type <description> - */ - function submit_to_remote($name, $value, $options = array()) { - - if (!isset($options['with'])) - $options['with'] = 'Form.serialize(this.form)'; - - if (!isset($options['html'])) - $options['html'] = array(); - - $options['html']['type'] = 'button'; - $options['html']['onclick'] = PrototypeHelper::remote_function($options). - '; return false;'; - $options['html']['name'] = $name; - $options['html']['value'] = $value; - - return TagHelper::tag('input', $options['html']); - } - - /** - * Returns a Javascript function (or expression) that will update a DOM - * element '$element_id' according to the '$opt' passed. - * - * Possible '$opt' are: - * 'content' The content to use for updating. - * 'action' Valid options are 'update' (default), 'empty', 'remove' - * 'position' If the 'action' is 'update', you can optionally specify one of - * the following positions: 'before', 'top', 'bottom', 'after'. - * - * Example: - * update_element_function('products', - * array('position' => 'bottom', - * 'content' => "<p>New product!</p>")); - * - * - * This method can also be used in combination with remote method call - * where the result is evaluated afterwards to cause multiple updates on a - * page. - * - * @param type <description> - * @param type <description> - * - * @return type <description> - */ - function update_element_function($element_id, $options = array()) { - - $content = JsHelper::escape_javascript(isset($options['content']) - ? $options['content'] - : ''); - - $value = isset($options['action']) ? $options['action'] : 'update'; - - switch ($value) { - - case 'update': - $js_func = $options['position'] - ? sprintf("new Insertion.%s('%s','%s')", - TextHelper::camelize($options['position']), - $element_id, $content) - : "\$('$element_id').innerHTML = '$content'"; - break; - - case 'empty': - $js_func = "\$('$element_id').innerHTML = ''"; - break; - - case 'remove': - $js_func = "Element.remove('$element_id')"; - break; - - default: - trigger_error('Invalid action, choose one of update, remove, empty'); - exit; - } - - $js_func .= ";\n"; - - return isset($options['binding']) ? $js_func.$options['binding'] : $js_func; - } - - /** - * Returns 'eval(request.responseText)', which is the Javascript function that - * 'form_remote_tag()' can call in 'complete' to evaluate a multiple update - * return document using 'update_element_function()' calls. - * - * @return type <description> - */ - function evaluate_remote_response() { - return 'eval(request.responseText)'; - } - - /** - * Returns the javascript needed for a remote function. - * Takes the same arguments as 'link_to_remote()'. - * - * Example: - * <select id="options" onchange="<?= - * remote_function(array('update' => 'options', - * 'url' => '@update_options')) ?>"> - * <option value="0">Hello</option> - * <option value="1">World</option> - * </select> - * - * @param type <description> - * - * @return type <description> - */ - function remote_function($options) { - $javascript_options = PrototypeHelper::options_for_ajax($options); - - $update = ''; - if (isset($options['update']) && is_array($options['update'])) { - - $update = array(); - if (isset($options['update']['success'])) - $update[] = "success:'".$options['update']['success']."'"; - - if (isset($options['update']['failure'])) - $update[] = "failure:'".$options['update']['failure']."'"; - - $update = '{'.join(',', $update).'}'; - - } else if (isset($options['update'])) { - $update .= "'".$options['update']."'"; - } - - $function = sprintf("new Ajax.%s(%s'%s', %s)", - $update ? 'Updater' : 'Request', - $update ? "$update, " : '', - $options['url'], - $javascript_options); - - if (isset($options['before'])) - $function = $options['before'].'; '.$function; - - if (isset($options['after'])) - $function = $function.'; '.$options['after']; - - if (isset($options['condition'])) - $function = 'if ('.$options['condition'].') { '.$function.'; }'; - - if (isset($options['confirm'])) { - $function = "if (confirm('" . - JsHelper::escape_javascript($options['confirm']) . - "')) { $function; }"; - if (isset($options['cancel'])) - $function .= ' else { '.$options['cancel'].' }'; - } - - return $function; - } - - /** - * Observes the field with the DOM ID specified by '$field_id' and makes - * an AJAX call when its contents have changed. - * - * Required '$options' are: - * 'url' 'url_for()'-style options for the action to call - * when the field has changed. - * - * Additional options are: - * 'frequency' The frequency (in seconds) at which changes to - * this field will be detected. Not setting this - * option at all or to a value equal to or less than - * zero will use event based observation instead of - * time based observation. - * 'update' Specifies the DOM ID of the element whose - * innerHTML should be updated with the - * XMLHttpRequest response text. - * 'with' A JavaScript expression specifying the - * parameters for the XMLHttpRequest. This defaults - * to 'value', which in the evaluated context - * refers to the new field value. - * - * Additionally, you may specify any of the options documented in - * link_to_remote(). - * - * @param type <description> - * @param type <description> - * - * @return type <description> - */ - function observe_field($field_id, $options = array()) { - $name = isset($options['frequency']) && $options['frequency'] > 0 - ? 'Form.Element.Observer' - : 'Form.Element.EventObserver'; - return PrototypeHelper::build_observer($name, $field_id, $options); - } - - /** - * Like 'observe_field()', but operates on an entire form identified by the - * DOM ID '$form_id'. '$options' are the same as 'observe_field()', except - * the default value of the 'with' option evaluates to the - * serialized (request string) value of the form. - * - * @param type <description> - * @param type <description> - * - * @return type <description> - */ - function observe_form($form_id, $options = array()) { - $name = isset($options['frequency']) && $options['frequency'] > 0 - ? 'Form.Observer' - : 'Form.EventObserver'; - return PrototypeHelper::build_observer($name, $form_id, $options); - } - - /** - * @ignore - */ - function options_for_ajax($options) { - $js_opt = PrototypeHelper::build_callbacks($options); - - $js_opt['asynchronous'] = isset($options['type']) - ? $options['type'] != 'synchronous' : 'true'; - - if (isset($options['method'])) - $js_opt['method'] = PrototypeHelper::method_option_to_s($options['method']); - - if (isset($options['position'])) - $js_opt['insertion'] = 'Insertion.'.TextHelper::camelize($options['position']); - - $js_opt['evalScripts'] = !isset($options['script']) || - $options['script'] == '0' || - $options['script'] == 'false' - ? 'false' : 'true'; - - if (isset($options['form'])) - $js_opt['parameters'] = 'Form.serialize(this)'; - else if (isset($options['submit'])) - $js_opt['parameters'] = "Form.serialize(document.getElementById('{$options['submit']}'))"; - else if (isset($options['with'])) - $js_opt['parameters'] = $options['with']; - - return JsHelper::options_for_javascript($js_opt); - } - - /** - * @ignore - */ - function method_option_to_s($method) { - return is_string($method) && $method[0] == "'" ? $method : "'$method'"; - } - - /** - * @ignore - */ - function build_observer($klass, $name, $options = array()) { - if (!isset($options['with']) && $options['update']) - $options['with'] = 'value'; - - $callback = PrototypeHelper::remote_function($options); - - $javascript = 'new '.$klass.'("'.$name.'", '; - if (isset($options['frequency'])) - $javascript .= $options['frequency'].", "; - - $javascript .= 'function(element, value) {'; - $javascript .= $callback.'});'; - - return JsHelper::javascript_tag($javascript); - } - - /** - * @ignore - */ - function build_callbacks($options) { - $callbacks = array(); - foreach (PrototypeHelper::get_callbacks() as $callback) { - if (isset($options[$callback])) { - $name = 'on'.ucfirst($callback); - $code = $options[$callback]; - $callbacks[$name] = 'function(request, json){'.$code.'}'; - } - } - - return $callbacks; - } - - /** - * @ignore - */ - function get_callbacks() { - static $callbacks; - if (!$callbacks) - $callbacks = array_merge(range(100, 599), - array('uninitialized', 'loading', 'loaded', - 'interactive', 'complete', 'failure', - 'success')); - return $callbacks; - } - - /** - * @ignore - */ - function get_ajax_options() { - static $ajax_options; - if (!$ajax_options) - $ajax_options = array('before', 'after', 'condition', 'url', - 'asynchronous', 'method', 'insertion', 'position', - 'form', 'with', 'update', 'script') - + PrototypeHelper::get_callbacks(); - return $ajax_options; - } -} - -/** - * JavaScriptGenerator generates blocks of JavaScript code that allow you to - * change the content and presentation of multiple DOM elements. Use this in - * your Ajax response bodies, either in a <script> tag or as plain JavaScript - * sent with a Content-type of "text/javascript". - * - * @package flexi - * - * @author Marcus Lunzenauer (mlunzena@uos.de) - * @copyright (c) Authors - * @version $Id: prototype_helper.php 3437 2006-05-27 11:38:58Z mlunzena $ - */ - -class Flexi_JavascriptGenerator { - - /** - * internal variables - * @ignore - */ - var $lines = array(); - - /** - * @ignore - */ - function to_s() { - $javascript = implode("\n", $this->lines); - return "try {\n".$javascript."\n} catch (e) { ". - "alert('JS error:\\n\\n' + e.toString()); throw e }"; - } - -################################################################################ -# function [] -# function select -# function draggable -# function drop_receiving -# function sortable -################################################################################ - - /** - * Inserts HTML at the specified 'position' relative to the DOM element - * identified by the given 'id'. - * - * 'position' may be one of: - * - * 'top':: HTML is inserted inside the element, before the - * element's existing content. - * 'bottom':: HTML is inserted inside the element, after the - * element's existing content. - * 'before':: HTML is inserted immediately preceeding the element. - * 'after':: HTML is inserted immediately following the element. - * - * @param type <description> - * @param type <description> - * @param type <description> - * - * @return type <description> - */ - function insert_html($position, $id, $content) { - $insertion = TextHelper::camelize($position); - $this->call('new Insertion.'.$insertion, $id, $content); - } - - /** - * Replaces the inner HTML of the DOM element with the given 'id'. - * - * @param type <description> - * @param type <description> - * - * @return type <description> - */ - function replace_html($id, $content) { - $this->call('Element.update', $id, $content); - } - - /** - * Replaces the "outer HTML" (i.e., the entire element, not just its - * contents) of the DOM element with the given 'id'. - * - * @param type <description> - * @param type <description> - * - * @return void - */ - function replace($id, $content) { - $this->call('Element.replace', $id, $content); - } - - /** - * Removes the DOM elements with the given 'ids' from the page. - * - * @param type <description> - * - * @return void - */ - function remove($ids) { - $ids = func_get_args(); - $this->record($this->javascript_object_for($ids).".each(Element.remove)"); - } - - /** - * Shows hidden DOM elements with the given 'ids'. - * - * @param type <description> - * - * @return void - */ - function show($ids) { - $ids = func_get_args(); - array_unshift($ids, 'Element.show'); - call_user_func_array(array(&$this, 'call'), $ids); - } - - /** - * Hides the visible DOM elements with the given 'ids'. - * - * @param type <description> - * - * @return void - */ - function hide($ids) { - $ids = func_get_args(); - array_unshift($ids, 'Element.hide'); - call_user_func_array(array(&$this, 'call'), $ids); - } - - /** - * Toggles the visibility of the DOM elements with the given 'ids'. - * - * @param type <description> - * - * @return void - */ - function toggle($ids) { - $ids = func_get_args(); - array_unshift($ids, 'Element.toggle'); - call_user_func_array(array(&$this, 'call'), $ids); - } - - /** - * Displays an alert dialog with the given 'message'. - * - * @param string the given message. - * - * @return void - */ - function alert($message) { - $this->call('alert', $message); - } - - /** - * Redirects the browser to the given 'location'. - * - * @param type <description> - * - * @return void - */ - function redirect_to($location) { - $this->assign('window.location.href', $location); - } - - /** - * Calls the JavaScript 'function', optionally with the given 'arguments'. - * - * @param type <description> - * - * @return void - */ - function call($function) { - $arguments = func_get_args(); - array_shift($arguments); - $this->record($function.'('.$this->arguments_for_call($arguments).')'); - } - - /** - * Assigns the JavaScript 'variable' the given 'value'. - * - * @param type <description> - * @param type <description> - * - * @return void - */ - function assign($variable, $value) { - $this->record($variable.' = '.$this->javascript_object_for($value)); - } - - /** - * Writes raw JavaScript to the page. - * - * @param string the raw JavaScript - * - * @return void - */ - function append($javascript) { - $this->lines[] = $javascript; - } - - /** - * Executes the given javascript after a delay of 'seconds'. - * - * # TODO (mlunzena) this function has side effects and has to be explained or deleted - * - * @param type <description> - * - * @return void - */ - function delay($seconds = 1) { - static $in_delay = FALSE; - - if (!$in_delay) { - $in_delay = TRUE; - $this->record("setTimeout(function() {\n\n"); - } - - else { - $in_delay = FALSE; - $this->record(sprintf("\n}, %d)", $seconds * 1000)); - } - - return $in_delay; - } - - /** - * Starts a script.aculo.us visual effect. See - * ScriptaculousHelper for more information. - * - * @param type <description> - * @param type <description> - * @param type <description> - * - * @return void - */ - function visual_effect($name, $id = FALSE, $js_opt = array()) { - $this->record(ScriptaculousHelper::visual_effect($name, $id, $js_opt)); - } - - /** - * @ignore - */ - function record($line) { - $line = preg_replace('/\;$/', '', rtrim($line)) . ';'; - $this->append($line); - } - - /** - * @ignore - */ - function javascript_object_for($object) { - return json_encode($object); - } - - /** - * @ignore - */ - function arguments_for_call($arguments) { - $mapped = array(); - foreach ($arguments as $argument) - $mapped[] = $this->javascript_object_for($argument); - return join(',', $mapped); - } -} diff --git a/vendor/flexi/lib/helper/scriptaculous_helper.php b/vendor/flexi/lib/helper/scriptaculous_helper.php deleted file mode 100644 index 643ad24..0000000 --- a/vendor/flexi/lib/helper/scriptaculous_helper.php +++ /dev/null @@ -1,142 +0,0 @@ -<?php - -# Copyright (c) 2008 - Marcus Lunzenauer <mlunzena@uos.de> -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -/** - * ScriptaculousHelper. - * - * - * @package flexi - * @subpackage helper - * - * @author Marcus Lunzenauer (mlunzena@uos.de) - * @author David Heinemeier Hansson - * @copyright (c) Authors - * @version $Id: scriptaculous_helper.php 3437 2006-05-27 11:38:58Z mlunzena $ - */ - -class ScriptaculousHelper { - - /** - * Returns a JavaScript snippet to be used on the AJAX callbacks for starting - * visual effects. - * - * Example: - * ScriptaculousHelper::visual_effect('highlight', 'posts', - * array('duration' => 0.5 )); - * - * If no '$element_id' is given, it assumes "element" which should be a local - * variable in the generated JavaScript execution context. This can be used - * for example with drop_receiving_element(): - * - * ScriptaculousHelper::drop_receving_element(..., array(... - * 'loading' => ScriptaculousHelper::visual_effect('fade'))); - * - * This would fade the element that was dropped on the drop receiving element. - * - * You can change the behaviour with various options, see - * http://script.aculo.us for more documentation. - * - * @param type <description> - * @param type <description> - * @param type <description> - * - * @return string <description> - */ - function visual_effect($name, $element_id = FALSE, $js_opt = array()) { - - $element = $element_id ? "'$element_id'" : 'element'; - - switch ($name) { - case 'toggle_appear': - case 'toggle_blind': - case 'toggle_slide': - return sprintf("new Effect.toggle(%s, '%s', %s)", - $element, substr($name, 7), - JsHelper::options_for_javascript($js_opt)); - } - - return sprintf("new Effect.%s(%s, %s)", - TextHelper::camelize($name), - $element, JsHelper::options_for_javascript($js_opt)); - } - - - /** - * Makes the elements with the DOM ID specified by '$element_id' sortable - * by drag-and-drop and make an AJAX call whenever the sort order has - * changed. By default, the action called gets the serialized sortable - * element as parameters. - * - * Example: - * <php echo sortable_element($my_list, array( - * 'url' => '@order', - * )) ?> - * - * In the example, the action gets a '$my_list' array parameter - * containing the values of the ids of elements the sortable consists - * of, in the current order. - * - * You can change the behaviour with various options, see - * http://script.aculo.us for more documentation. - */ - function sortable_element($element_id, $options = array()) { - - if (!isset($options['with'])) - $options['with'] = "Sortable.serialize('$element_id')"; - - if (!isset($options['onUpdate'])) - $options['onUpdate'] = - sprintf('function(){%s}', PrototypeHelper::remote_function($options)); - - foreach (PrototypeHelper::get_ajax_options() as $key) - unset($options[$key]); - - foreach (array('tag', 'overlap', 'constraint', 'handle') as $option) - if (isset($options[$option])) - $options[$option] = "'{$options[$option]}'"; - - if (isset($options['containment'])) - $options['containment'] = self::array_or_string_for_javascript($options['containment']); - - if (isset($options['hoverclass'])) - $options['hoverclass'] = "'{$options['hoverclass']}'"; - - if (isset($options['only'])) - $options['only'] = self::array_or_string_for_javascript($options['only']); - - return JsHelper::javascript_tag( - sprintf("Sortable.create('%s', %s)", - $element_id, JsHelper::options_for_javascript($options))); - } - - - /** - * @ignore - */ - function array_or_string_for_javascript($option) { - if (is_array($option)) { - return "['".join("','", $option)."']"; - } else if ($option) { - return "'$option'"; - } - } -} diff --git a/vendor/flexi/lib/helper/tag_helper.php b/vendor/flexi/lib/helper/tag_helper.php deleted file mode 100644 index 673c5c1..0000000 --- a/vendor/flexi/lib/helper/tag_helper.php +++ /dev/null @@ -1,122 +0,0 @@ -<?php - -# Copyright (c) 2008 - Marcus Lunzenauer <mlunzena@uos.de> -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -/** - * TagHelper defines some base helpers to construct html tags. - * This is poor man’s Builder for the rare cases where you need to - * programmatically make tags but can’t use Builder. - * - * @package flexi - * @subpackage helper - * - * @author Marcus Lunzenauer (mlunzena@uos.de) - * @author Fabien Potencier <fabien.potencier@symfony-project.com> - * @author David Heinemeier Hansson - * @copyright (c) Authors - * @version $Id: tag_helper.php 3437 2006-05-27 11:38:58Z mlunzena $ - */ - -class TagHelper { - - /** - * Constructs an html tag. - * - * @param $name string tag name - * @param $options array tag options - * @param $open boolean true to leave tag open - * - * @return string - */ - function tag($name, $options = array(), $open = false) { - if (!$name) return ''; - return '<'.$name.TagHelper::_tag_options($options).($open ? '>' : ' />'); - } - - /** - * Helper function for content tags. - * - * @param type <description> - * @param type <description> - * @param type <description> - * - * @return type <description> - */ - function content_tag($name, $content = '', $options = array()) { - if (!$name) return ''; - return '<'.$name.TagHelper::_tag_options($options).'>'.$content.'</'.$name.'>'; - } - - /** - * Helper function for CDATA sections. - * - * @param type <description> - * - * @return type <description> - */ - function cdata_section($content) { - return '<![CDATA['.$content.']]>'; - } - - /** - * @ignore - */ - function _tag_options($options = array()) { - $options = TagHelper::_parse_attributes($options); - $html = ''; - foreach ($options as $key => $value) - $html .= ' '.$key.'="'.$value.'"'; - return $html; - } - - /** - * @ignore - */ - function _parse_attributes($string) { - return is_array($string) ? $string : TagHelper::string_to_array($string); - } - - /** - * <MethodDescription> - * - * @param string <description> - * - * @return array <description> - */ - function string_to_array($string) { - preg_match_all('/ - \s*(\w+) # key \\1 - \s*=\s* # = - (\'|")? # values may be included in \' or " \\2 - (.*?) # value \\3 - (?(2) \\2) # matching \' or " if needed \\4 - \s*(?: - (?=\w+\s*=) | \s*$ # followed by another key= or the end of the string - ) - /x', $string, $matches, PREG_SET_ORDER); - - $attributes = array(); - foreach ($matches as $val) - $attributes[$val[1]] = $val[3]; - - return $attributes; - } -} diff --git a/vendor/flexi/lib/helper/text_helper.php b/vendor/flexi/lib/helper/text_helper.php deleted file mode 100644 index c596727..0000000 --- a/vendor/flexi/lib/helper/text_helper.php +++ /dev/null @@ -1,183 +0,0 @@ -<?php - -# Copyright (c) 2008 - Marcus Lunzenauer <mlunzena@uos.de> -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -/** - * TextHelper. - * - * - * @package flexi - * @subpackage helper - * - * @author Marcus Lunzenauer (mlunzena@uos.de) - * @copyright (c) Authors - * @version $Id$ - */ - -class TextHelper { - - /** - * Holds the internal cycles. - * - * @ignore - */ - private static $cycles = array(); - - - /** - * Returns a camelized string from a lower case and underscored string by - * replacing slash with underscore and upper-casing each letter preceded - * by an underscore. - * - * @param string String to camelize. - * - * @return string Camelized string. - */ - function camelize($word) { - return str_replace(' ', '', - ucwords(str_replace(array('_', '/'), - array(' ', ' '), $word))); - } - - - /** - * Creates a Cycle object whose +__toString method cycles through elements of - * an array every time it is called. This can be used for example, to - * alternate classes for table rows: - * - * <? foreach ($items as $item) : ?> - * <tr class="<?= TextHelper::cycle('odd', 'even') ?>"> - * <td><?= item ?></td> - * </tr> - * <? endforeach ?> - * - * You can use named cycles to allow nesting in loops. Passing a single array - * as the only parameter with a <tt>name</tt> key will create a named cycle. - * You can manually reset a cycle by calling reset_cycle and passing the - * name of the cycle. - * - * <? foreach($items as $item) : ?> - * <tr class="<?= TextHelper::cycle(array("even", "odd", "name" => "row_class")) ?>"> - * <td> - * <? foreach ($item->values as $value) : ?> - * <span style="color:<?= TextHelper::cycle(array("red", "green", "blue", "name" => "colors")) : ?>"> - * <?= $value ?> - * </span> - * <? endforeach ?> - * <? TextHelper::reset_cycle("colors") ?> - * </td> - * </tr> - * <? endforeach ?> - */ - static function cycle($first_value) { - - $values = func_get_args(); - - - if (sizeof($values) == 1 && is_array($values[0])) { - $values = $values[0]; - $name = isset($values['name']) ? $values['name'] : 'default'; - unset($values['name']); - } - else { - $name = 'default'; - } - - $cycle = self::get_cycle($name); - if (is_null($cycle) || $cycle->values !== $values) { - $cycle = self::set_cycle($name, new TextHelperCycle($values)); - } - - return (string) $cycle; - } - - - /** - * Resets a cycle so that it starts from the first element the next time - * it is called. Pass in +name+ to reset a named cycle. - * - * @param string an optional name of a cycle - * - * @return void - */ - public static function reset_cycle($name = 'default') { - $cycle = self::get_cycle($name); - if (isset($cycle)) { - $cycle->reset(); - } - } - - - /** - * @ignore - */ - private static function get_cycle($name) { - return isset(self::$cycles[$name]) ? self::$cycles[$name] : NULL; - } - - /** - * @ignore - */ - private static function set_cycle($name, $cycle) { - return self::$cycles[$name] = $cycle; - } -} - - -/** - * This class holds an array of string and cycles through them. - * - * @package flexi - * @subpackage helper - * - * @author Marcus Lunzenauer (mlunzena@uos.de) - * @copyright (c) Authors - * @version $Id$ - */ - -class TextHelperCycle { - - - public $values; - - - function __construct($values) { - $this->values = (array) $values; - } - - - function cycle() { - $result = current($this->values); - if (next($this->values) === FALSE) - $this->reset(); - return $result; - } - - - function reset() { - reset($this->values); - } - - - function __toString() { - return $this->cycle(); - } -} diff --git a/vendor/flexi/lib/js_template.php b/vendor/flexi/lib/js_template.php deleted file mode 100644 index d2113a6..0000000 --- a/vendor/flexi/lib/js_template.php +++ /dev/null @@ -1,55 +0,0 @@ -<?php - -# Copyright (c) 2008 - Marcus Lunzenauer <mlunzena@uos.de> -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -/** - * A template engine that renders Javascript templates. - * - * @package flexi - * - * @author Marcus Lunzenauer (mlunzena@uos.de) - * @copyright (c) Authors - * @version $Id$ - */ - -class Flexi_JsTemplate extends Flexi_PhpTemplate { - - /** - * Parse, render and return the presentation. - * - * @return string A string representing the rendered presentation. - */ - function _render() { - - # put attributes into scope - extract($this->_attributes); - - # get generator object - $update_page = new Flexi_JavascriptGenerator(); - - # include template, parse it and remove output - ob_start(); - require $this->_template; - ob_end_clean(); - - return $update_page->to_s(); - } -} diff --git a/vendor/flexi/lib/mustache_template.php b/vendor/flexi/lib/mustache_template.php deleted file mode 100644 index 2051a2e..0000000 --- a/vendor/flexi/lib/mustache_template.php +++ /dev/null @@ -1,85 +0,0 @@ -<?php - -# Copyright (c) 2008 - Marcus Lunzenauer <mlunzena@uos.de> -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -require_once dirname(__FILE__) . '/../vendor/mustache.php/Mustache.php'; - -/** - * A template engine that uses PHP to render templates. - * - * @package flexi - * - * @author Marcus Lunzenauer (mlunzena@uos.de) - * @copyright (c) Authors - * @version $Id$ - */ - -class Flexi_MustacheTemplate extends Flexi_Template { - - /** - * Parse, render and return the presentation. - * - * @return string A string representing the rendered presentation. - */ - function _render() { - ${0} = new MyMustache($this); - $content_for_layout = ${0}->render(); - - // include layout, parse it and get output - if (isset($this->_layout)) { - $defined = get_defined_vars(); - unset($defined['this'], $defined['0']); - $content_for_layout = $this->_layout->render($defined); - } - - return $content_for_layout; - } - - function getPartial($tag_name) { - $file = dirname($this->_template) . '/' . $tag_name . '.mustache'; - var_dump($file); - if (file_exists($file)) { - return file_get_contents($file); - } - return ''; - } -} - -class MyMustache extends Mustache { - - public function __construct($flexi) { - parent::__construct(file_get_contents($flexi->_template), $flexi->_attributes); - $this->_flexi = $flexi; - } - - protected function _getPartial($tag_name) { - - if ($partial = $this->_flexi->getPartial($tag_name)) { - return $partial; - } - - if ($this->_throwsException(MustacheException::UNKNOWN_PARTIAL)) { - throw new MustacheException('Unknown partial: ' . $tag_name, MustacheException::UNKNOWN_PARTIAL); - } else { - return ''; - } - } -} diff --git a/vendor/flexi/lib/php_template.php b/vendor/flexi/lib/php_template.php deleted file mode 100644 index af808b4..0000000 --- a/vendor/flexi/lib/php_template.php +++ /dev/null @@ -1,119 +0,0 @@ -<?php - -# Copyright (c) 2008 - Marcus Lunzenauer <mlunzena@uos.de> -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -/** - * A template engine that uses PHP to render templates. - * - * @package flexi - * - * @author Marcus Lunzenauer (mlunzena@uos.de) - * @copyright (c) Authors - * @version $Id$ - */ - -class Flexi_PhpTemplate extends Flexi_Template { - - /** - * Parse, render and return the presentation. - * - * @return string A string representing the rendered presentation. - */ - function _render() { - - extract($this->_attributes); - - # include template, parse it and get output - ob_start(); - require $this->_template; - $content_for_layout = ob_get_clean(); - - - # include layout, parse it and get output - if (isset($this->_layout)) { - $defined = get_defined_vars(); - unset($defined['this']); - $content_for_layout = $this->_layout->render($defined); - } - - return $content_for_layout; - } - - - /** - * Parse, render and return the presentation of a partial template. - * - * @param string A name of a partial template. - * @param array An optional associative array of attributes and their - * associated values. - * - * @return string A string representing the rendered presentation. - */ - function render_partial($partial, $attributes = array()) { - return $this->_factory->render($partial, $attributes + $this->_attributes); - } - - - /** - * Renders a partial template with every member of a collection. This member - * can be accessed by a template variable with the same name as the name of - * the partial template. - * - * Example: - * - * # template entry.php contains: - * <li><?= $entry ?></li> - * - * - * $entries = array('lorem', 'ipsum'); - * $template->render_partial_collection('entry', $entries); - * - * # results in: - * <li>lorem</li> - * <li>ipsum</li> - * - * TODO (mlunzena) spacer and attributes must be described - * - * @param string A name of a partial template. - * @param array The collection to be rendered. - * @param string Optional a name of a partial template used as spacer. - * @param array An optional associative array of attributes and their - * associated values. - * - * @return string A string representing the rendered presentation. - */ - function render_partial_collection($partial, $collection, - $spacer = NULL, $attributes = array()) { - - $template = $this->_factory->open($partial); - $template->set_attributes($this->_attributes); - $template->set_attributes($attributes); - - $collected = array(); - $iterator_name = pathinfo($partial, PATHINFO_FILENAME); - foreach ($collection as $element) - $collected[] = $template->render(array($iterator_name => $element)); - - $spacer = isset($spacer) ? $this->render_partial($spacer, $attributes) : ''; - - return join($spacer, $collected); - } -} diff --git a/vendor/flexi/lib/template.php b/vendor/flexi/lib/template.php deleted file mode 100644 index b4d97e8..0000000 --- a/vendor/flexi/lib/template.php +++ /dev/null @@ -1,251 +0,0 @@ -<?php - -# Copyright (c) 2008 - Marcus Lunzenauer <mlunzena@uos.de> -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -/** - * Abstract template class representing the presentation layer of an action. - * Output can be customized by supplying attributes, which a template can - * manipulate and display. - * - * @package flexi - * - * @author Marcus Lunzenauer (mlunzena@uos.de) - * @copyright (c) Authors - * @version $Id$ - */ - -abstract class Flexi_Template { - - /** - * @ignore - */ - public $_attributes, $_factory, $_options, $_layout, $_template; - - - /** - * Constructor - * - * @param string the path of the template. - * @param Flexi_TemplateFactory the factory creating this template - * @param array optional array of options - * - * @return void - */ - function __construct($template, &$factory, $options = array()) { - - # set template - $this->_template = $template; - - # set factory - $this->_factory = $factory; - - # set options - $this->_options = $options; - - # init attributes - $this->clear_attributes(); - - # set layout - $this->set_layout(NULL); - } - - - /** - * __set() is a magic method run when writing data to inaccessible members. - * In this class it is used to set attributes for the template in a - * comfortable way. - * - * @see http://php.net/__set - * - * @param string the name of the member field - * @param mixed the value for the member field - * - * @return void - */ - function __set($name, $value) { - $this->set_attribute($name, $value); - } - - - /** - * __get() is a magic method utilized for reading data from inaccessible - * members. - * In this class it is used to get attributes for the template in a - * comfortable way. - * - * @see http://php.net/__set - * - * @param string the name of the member field - * - * @return mixed the value for the member field - */ - function __get($name) { - return $this->get_attribute($name); - } - - - /** - * __isset() is a magic method triggered by calling isset() or empty() on - * inaccessible members. - * In this class it is used to check for attributes for the template in a - * comfortable way. - * - * @see http://php.net/__set - * - * @param string the name of the member field - * - * @return bool TRUE if that attribute exists, FALSE otherwise - */ - function __isset($name) { - return isset($this->_attributes[$name]); - } - - - /** - * __unset() is a magic method invoked when unset() is used on inaccessible - * members. - * In this class it is used to check for attributes for the template in a - * comfortable way. - * - * @see http://php.net/__set - * - * @param string the name of the member field - * - * @return void - */ - function __unset($name) { - $this->clear_attribute($name); - } - - - /** - * Parse, render and return the presentation. - * - * @param array An optional associative array of attributes and their - * associated values. - * @param string A name of a layout template. - * - * @return string A string representing the rendered presentation. - */ - function render($attributes = null, $layout = null) { - - if (isset($layout)) { - $this->set_layout($layout); - } - - # merge attributes - $this->set_attributes($attributes); - - return $this->_render(); - } - - - /** - * Parse, render and return the presentation. - * - * @return string A string representing the rendered presentation. - */ - abstract function _render(); - - - /** - * Returns the value of an attribute. - * - * @param string An attribute name. - * @param mixed An attribute value. - * - * @return mixed An attribute value. - */ - function get_attribute($name) { - return isset($this->_attributes[$name]) ? $this->_attributes[$name] : NULL; - } - - - /** - * Set an array of attributes. - * - * @return array An associative array of attributes and their associated - * values. - */ - function get_attributes() { - return $this->_attributes; - } - - - /** - * Set an attribute. - * - * @param string An attribute name. - * @param mixed An attribute value. - * - * @return void - */ - function set_attribute($name, $value) { - $this->_attributes[$name] = $value; - } - - - /** - * Set an array of attributes. - * - * @param array An associative array of attributes and their associated - * values. - * - * @return void - */ - function set_attributes($attributes) { - $this->_attributes = (array)$attributes + (array)$this->_attributes; - } - - - /** - * Clear all attributes associated with this template. - * - * @return void - */ - function clear_attributes() { - $this->_attributes = array(); - } - - - /** - * Clear an attribute associated with this template. - * - * @param string The name of the attribute to be cleared. - * - * @return void - */ - function clear_attribute($name) { - unset($this->_attributes[$name]); - } - - - /** - * Set the template's layout. - * - * @param mixed A name of a layout template or a layout template. - * - * @return void - */ - function set_layout($layout) { - $this->_layout = $this->_factory->open($layout); - } -} diff --git a/vendor/flexi/lib/template_factory.php b/vendor/flexi/lib/template_factory.php deleted file mode 100644 index dfdc74e..0000000 --- a/vendor/flexi/lib/template_factory.php +++ /dev/null @@ -1,281 +0,0 @@ -<?php - -# Copyright (c) 2008 - Marcus Lunzenauer <mlunzena@uos.de> -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -/** - * Using this factory you can create new Template objects. - * - * @package flexi - * - * @author Marcus Lunzenauer (mlunzena@uos.de) - * @copyright (c) Authors - * @version $Id$ - */ - -class Flexi_TemplateFactory { - - - /** - * include path for templates - * - * @var string - */ - protected $path; - - - /** - * mapping of file extensions to supported template classes - * - * @var array - */ - protected $handlers = array( - 'php' => array('Flexi_PhpTemplate', array()), - 'pjs' => array('Flexi_JsTemplate', array()) - ); - - - /** - * Constructor of TemplateFactory. - * - * @param string the template include path - * - * @return void - */ - function __construct($path) { - $this->set_path($path); - } - - - /** - * Sets a new include path for the factory and returns the old one. - * - * @param string the new path - * - * @return string the old path - */ - function set_path($path) { - - $old_path = $this->get_path(); - - if (substr($path, -1) != '/') - $path .= '/'; - - $this->path = $path; - - return $old_path; - } - - - /** - * Returns the include path of the factory - * - * @return string the current include path - */ - function get_path() { - return $this->path; - } - - - /** - * Open a template of the given name using the factory method pattern. - * If a string was given, the path of the factory is searched for a matching - * template. - * If this string starts with a slash or with /\w+:\/\//, the string is - * interpreted as an absolute path. Otherwise the path of the factory will be - * prepended. - * After that the factory searches for a file extension in this string. If - * there is none, the directory where the template is supposed to live is - * searched for a file starting with the template string and a supported - * file extension. - * At last the factory instantiates a template object of the matching template - * class. - * - * Examples: - * - * $factory->open('/path/to/template') - * does not prepend the factory's path but searches for "template.*" in - * "/path/to" - * - * $factory->open('template') - * prepends the factory's path and searches there for "template.*" - * - * $factory->open('template.php') - * prepends the factory's path but does not search and instantiates a - * PHPTemplate instead - * - * This method returns it's parameter, if it is not a string. This - * functionality is useful for helper methods like #render_partial - * - * @throws Flexi_TemplateNotFoundException - * - * @param string A name of a template. - * - * @return mixed the factored object - * - * @throws Flexi_TemplateNotFoundException if the template could not be found - */ - function open($template) { - - # if it is not a string, this method behaves like identity - if (!is_string($template)) { - return $template; - } - - # get file - $file = $this->get_template_file($template); - - # retrieve handler - list($class, $options) = $this->get_template_handler($file); - - return new $class($file, $this, $options); - } - - - /** - * This method returns the absolute filename of the template - * - * @param string a template string - * - * @return string an absolute filename - * - * @throws Flexi_TemplateNotFoundException if the template could not be found - */ - function get_template_file($template0) { - - $template = $this->get_absolute_path($template0); - $extension = $this->get_extension($template); - - # extension defined, is there a matching template class? - if ($extension !== NULL) { - if (file_exists($template)) { - return $template; - } - } - - # no extension defined, find it - else { - $file = $this->find_template($template); - if ($file !== NULL) { - return $file; - } - } - - # falling through to throw exception - throw new Flexi_TemplateNotFoundException( - sprintf('Missing template "%s" in "%s".', $template0, $this->path)); - } - - - /** - * Matches an extension to a template handler. - * - * @param string the template - * - * @return array an array containing the class name and an array of - * options of the matched extension; - * or NULL if the extension did not match - */ - function get_template_handler($template) { - $extension = $this->get_extension($template); - return isset($this->handlers[$extension]) - ? $this->handlers[$extension] - : NULL; - } - - - /** - * Registers a handler for templates with a matching extension. - * - * @param string the extension of the templates to handle - * @param string the name of the already loaded class - * @param array optional; an array of options which is used - * when constructing a new instance - */ - function add_handler($extension, $class, $options = array()) - { - $this->handlers[$extension] = array($class, $options); - } - - - /** - * Returns the absolute path to the template. If the given argument starts - * with a slash or with a protocoll, this method just returns its arguments. - * - * @param string an incomplete template name - * - * @return string an absolute path to the incomplete template name - */ - function get_absolute_path($template) { - return preg_match('#^(/|\w+://)#', $template) - ? $template - : $this->get_path() . $template; - } - - - /** - * Find template given w/o extension. - * - * @param string the template's filename w/o extension - * - * @return mixed NULL if there no such file could be found, a string - * containing the complete file name otherwise - */ - function find_template($template) { - foreach ($this->handlers as $ext => $handler) { - $file = "$template.$ext"; - if (file_exists($file)) { - return $file; - } - } - return NULL; - } - - - /** - * Returns the file extension if there is one. - * - * @param string an possibly incomplete template file name - * - * @return mixed a string containing the file extension if there is one, - * NULL otherwise - */ - function get_extension($file) { - $matches = array(); - $matched = preg_match('/\.([^\/.]+)$/', $file, $matches); - return $matched ? $matches[1] : NULL; - } - - - /** - * Class method to parse, render and return the presentation of a - * template. - * - * @param string A name of a template. - * @param array An associative array of attributes and their associated - * values. - * @param string A name of a layout template. - * - * @return string A string representing the rendered presentation. - */ - function render($name, $attributes = null, $layout = null) { - return $this->open($name)->render($attributes, $layout); - } -} |
