- <?php
- /**
- * This file is part of the TaniPHP Framework.
- * Copyright (C) 2005 by Dumitru Postoronca
- *
- * @package TaniPHP Helpers
- * @copyright Copyright © 2005, Dumitru Postoronca
- * @license http://www.opensource.org/licenses/lgpl-license.php
- */
-
- /**
- * HTML helper class
- *
- * @static
- * @package TaniPHP Helpers
- * @author Dumitru Postoronca
- */
- class HTML
- {
-
- /**
- * Will cycle thorough given array of values. Useful for nice table design.
- *
- * The following example will cycle the table row background making bluesh(#CCF) stripes
- * <code>
- * <?php foreach($i as $j) { ?>
- * <tr style="background-color: <?php echo HTML::cycle(array('#FFF', '#CCF'));?>">
- * <td><!-- show data --></td>
- * </tr>
- * <?php } ?>
- * </code>
- *
- * @static
- */
- function cycle($array)
- {
- static $i = 0;
- if($i >= count($array)) $i = 0;
- return $array[$i++];
- }
-
- /**
- * Will make a string more human-readable by replacing "_" with " ", and making words uppercase
- *
- * @static
- * @param string $word Word to "humanize"
- */
- function humanize($word)
- {
- $word = str_replace("_", " ", $word);
- return ucwords($word);
- }
-
- /**
- * Generates an URL according to config file
- *
- * @static
- * @param string $controller Controller to link to. Will use default controller if not set.
- * @param string $action Action to link to. Will use default action if not set.
- * @param array $params Associative array of parameters to pass by URL.
- */
- function getURL($controller = "", $action = "", $params=array())
- {
- if(empty($controller)) {
- $controller = Framework::getConfiguration('common', 'defaultController');
- }
-
- if(empty($action)) {
- $action = Framework::getConfiguration('common', 'defaultAction');
- }
-
- // generate url to controller/action pair using config file
- $url_pattern = Framework::getConfiguration("common", "url");
- $trans = array('{C}' => $controller, '{A}' => $action);
- $url = strtr($url_pattern, $trans);
-
- // append other parameters to url
- $url_param_pattern = Framework::getConfiguration('common', 'url_params');
- foreach($params as $param => $value) {
-
- $trans = array('{P}' => $param, '{V}' => urlencode($value));
-
- $url .= strtr($url_param_pattern, $trans);
-
- }
-
- return $url;
- }
-
- /**
- * Outputs an generated URL
- *
- * @static
- * @see getURL
- */
- function echoURL($controller = "", $action = "", $params = array())
- {
- echo HTML::getURL($controller, $action, $params);
- }
-
- /**
- * Loads a shared component into the view
- *
- * @static
- * @param string $file Component to load
- */
- function load($file)
- {
- if(file_exists(ROOT . 'views/shared/' . $file)) {
- include(ROOT . 'views/shared/' . $file);
- } else {
- Framework::croak("HTML::load - component file <i>$file</i> not found.");
- }
- }
-
- /**
- * Prints a edit/new form for the model instance passed as param
- *
- * @static
- * @see HTML::getForm()
- * @param object $model A model instance to generate form for
- */
- /*function printForm($model)
- {
- echo "<table>";
- $form = HTML::getForm($model);
- foreach ($form as $t) {
- echo '<tr class="' . HTML::cycle(array('color1', 'color2')) . '">' . "\n";
- echo "<td>${t['label']}</td>\n";
- echo "<td>\n";
- if(!isset($t['labels'])) {
- echo $t['tag'];
- } else {
- echo "<table>\n";
- $c = count($t['labels']);
- for($i = 0; $i < $c; $i++) {
- echo "<tr>\n";
- echo "<td>{$t['labels'][$i]}</td>\n";
- echo "<td>{$t['tags'][$i]}</td>\n";
- echo "</tr>\n";
- }
- echo "</table>\n";
- }
- echo "</td></tr>\n";
- }
- echo "</table>\n";
-
- }*/
-
- }
- ?>