diff --git a/app/controllers/pages_controller.php b/app/controllers/pages_controller.php index 58cd38deb..9d5631514 100644 --- a/app/controllers/pages_controller.php +++ b/app/controllers/pages_controller.php @@ -1,4 +1,4 @@ -redirect('/'); diff --git a/app/views/errors/missing_controller.thtml b/app/views/errors/missing_controller.thtml index 7423fbbd5..85e5ab5b6 100644 --- a/app/views/errors/missing_controller.thtml +++ b/app/views/errors/missing_controller.thtml @@ -1,6 +1,6 @@

Missing controller

-

You are seeing this error because controller missing_controller;?> +

You are seeing this error because controller missingController;?> could not be found.

@@ -10,7 +10,7 @@ view file, a user-customizable error page for handling invalid controller dispat

-Fatal: Unable to load controller missing_controller;?> +Fatal: Unable to load controller missingController;?>

diff --git a/app/views/errors/missing_view.thtml b/app/views/errors/missing_view.thtml index 4324fb03e..77cd4e929 100644 --- a/app/views/errors/missing_view.thtml +++ b/app/views/errors/missing_view.thtml @@ -1,6 +1,6 @@

Missing view

-

You are seeing this error because the view missing_view;?> +

You are seeing this error because the view missingView;?> for action params['action'];?> in controller name);?> could not be found.

@@ -11,7 +11,7 @@ view file, a user-customizable error page for handling missing/invalid views dur

-Fatal: Unable to load view file missing_view;?> for +Fatal: Unable to load view file missingView;?> for action params['controller'];?>::params['action'];?>

diff --git a/libs/controller.php b/libs/controller.php index 5331c651d..c2a25461a 100644 --- a/libs/controller.php +++ b/libs/controller.php @@ -84,10 +84,18 @@ class Controller extends Template * An array of names of models the particular controller wants to use. * * @var mixed A single name as a string or a list of names as an array. - * @access private + * @access protected */ var $uses = false; + /** + * An array of names of built-in helpers to include. + * + * @var mixed A single name as a string or a list of names as an array. + * @access protected + */ + var $helpers = array('html'); + /** * Constructor. * @@ -98,7 +106,9 @@ class Controller extends Template $r = null; if (!preg_match('/(.*)Controller/i', get_class($this), $r)) - die("Controller::__construct() : Can't get or parse my own class name, exiting."); + { + die("Controller::__construct() : Can't get or parse my own class name, exiting."); + } $this->name = strtolower($r[1]); $this->viewpath = Inflector::underscore($r[1]); @@ -134,22 +144,22 @@ class Controller extends Template parent::__construct(); } - function missing_controller() + function missingController() { $this->autoRender = false; - $this->render('../errors/missing_controller'); + $this->render('../errors/missingController'); } - function missing_action() + function missingAction() { $this->autoRender = false; - $this->render('../errors/missing_action'); + $this->render('../errors/missingAction'); } - function missing_view() + function missingView() { $this->autoRender = false; - $this->render('../errors/missing_view'); + $this->render('../errors/missingView'); } /** diff --git a/libs/dispatcher.php b/libs/dispatcher.php index 633cb833a..5f13c0954 100644 --- a/libs/dispatcher.php +++ b/libs/dispatcher.php @@ -1,326 +1,317 @@ - + // -// + Copyright: (c) 2005, Cake Authors/Developers + // -// + Author(s): Michal Tatarynowicz aka Pies + // -// + Larry E. Masters aka PhpNut + // -// + Kamil Dzielinski aka Brego + // -// +------------------------------------------------------------------+ // -// + Licensed under The MIT License + // -// + Redistributions of files must retain the above copyright notice. + // -// + See: http://www.opensource.org/licenses/mit-license.php + // -////////////////////////////////////////////////////////////////////////// - -/** - * Purpose: Dispatcher - * Dispatches the request, creating aproppriate models and controllers. - * - * @filesource - * @author Cake Authors/Developers - * @copyright Copyright (c) 2005, Cake Authors/Developers - * @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers - * @package cake - * @subpackage cake.libs - * @since Cake v 0.2.9 - * @version $Revision$ - * @modifiedby $LastChangedBy$ - * @lastmodified $Date$ - * @license http://www.opensource.org/licenses/mit-license.php The MIT License - */ - -/** - * Description: - * Dispatches the request, creating appropriate models and controllers. - */ - -define('DISPATCH_NO_CONTROLLER', 'missing_controller'); -define('DISPATCH_UNKNOWN_CONTROLLER', 'missing_controller'); -define('DISPATCH_NO_ACTION', 'missing_action'); -define('DISPATCH_UNKNOWN_ACTION', 'missing_action'); -define('DISPATCHER_UNKNOWN_VIEW', 'missing_view'); - -uses('error_messages', 'object', 'router', 'controller'); - -/** - * Dispatches the request, creating appropriate models and controllers. - * - * @package cake - * @subpackage cake.libs - * @since Cake v 0.2.9 - */ -class Dispatcher extends Object -{ - -/** - * Base URL - * - * @var unknown_type - */ - var $base = false; -/** - * Enter description here... - * - * @var array - */ - var $passed_args = array(); - -/** - * Constructor. - */ - function __construct () - { - $this->base = $this->baseUrl(); - parent::__construct(); - } - -/** - * Enter description here... - * - * @param string $url - * @return unknown - */ - function dispatch($url) - { - $params = $this->parseParams($url); - $result = $this->invoke($url); - - return $result === true? $params: array(); - } - -/** - * Enter description here... - * - * @param string $url - * @return unknown - */ - function invoke ($url) - { - global $_POST, $_GET, $_FILES, $_SESSION; - - $params = $this->parseParams($url); - $missing_controller = false; - $missing_action = false; - $missing_view = false; - - if (empty($params['controller'])) - { - $missing_controller = true; - } - else - { - $ctrl_name = Inflector::camelize($params['controller']); - $ctrl_class = $ctrl_name.'Controller'; - - if (!loadController($ctrl_name) || !class_exists($ctrl_class)) - { - $missing_controller = true; - } - } - - if ($missing_controller) - { - $ctrl_class = 'AppController'; - $controller = new $ctrl_class($this); - $params['action'] = 'missing_controller'; - $controller->missing_controller = $params['controller']; - } - else - { - // create controller - $controller = new $ctrl_class($this); - } - - // if action is not set, and the default Controller::index() method doesn't exist - if (empty($params['action'])) - { - if (method_exists($controller, 'index')) - { - $params['action'] = 'index'; - } - else - { - $missing_action = true; - } - } - - // if the requested action doesn't exist - if (!method_exists($controller, $params['action'])) - { - $missing_action = true; - } - - if ($missing_action) - { - $controller->missing_action = $params['action']; - $params['action'] = 'missing_action'; - } - - // initialize the controller - $controller->base = $this->base; - $controller->here = $this->base.'/'.$url; - $controller->params = $params; - $controller->action = $params['action']; - $controller->data = empty($params['data'])? null: $params['data']; - $controller->passed_args = empty($params['pass'])? null: $params['pass']; - - // EXECUTE THE REQUESTED ACTION - call_user_func_array(array(&$controller, $params['action']), empty($params['pass'])? null: $params['pass']); - - $isFatal = isset($controller->isFatal) ? $controller->isFatal : false; - - if ($isFatal) - { - switch($params['action']) - { - case 'missing_controller': - $this->errorUnknownController($url, $ctrl_name); - break; - - case 'missing_action': - $this->errorUnknownAction($url, $ctrl_class, $controller->missing_action); - break; - } - } - - if ($controller->autoRender) - { - $controller->render(); - } - - return true; - } - -/** - * Returns array of GET and POST parameters. GET parameters are taken from given URL. - * - * @param string $from_url - * @return array Parameters found in POST and GET. - */ - function parseParams ($from_url) - { - global $_POST, $_FILES; - - // load routes config - $Route = new Router(); - include CONFIGS.'routes.php'; - $params = $Route->parse ($from_url); - - // add submitted form data - $params['form'] = $_POST; - if (isset($_POST['data'])) - $params['data'] = $_POST['data']; - - foreach ($_FILES as $name => $data) - $params['form'][$name] = $data; - - return $params; - } - -/** - * Returns a base URL. - * - * @return string - */ - function baseUrl () - { - global $_SERVER; - - //non mod_rewrite use: - if (defined('BASE_URL')) return BASE_URL; - - $doc_root = $_SERVER['DOCUMENT_ROOT']; - $script_name = $_SERVER['PHP_SELF']; - - // if document root ends with 'public', it's probably correctly set - $r = null; - if (ereg('/^.*/public(\/)?$/', $doc_root)) - return preg_match('/^(.*)\/index\.php$/', $script_name, $r)? $r[1]: false; - else - // document root is probably not set to Cake 'public' dir - return preg_match('/^(.*)\/public\/index\.php$/', $script_name, $r)? $r[1]: false; - } - -/** - * Displays an error page (e.g. 404 Not found). - * - * @param int $code Error code (e.g. 404) - * @param string $name Name of the error message (e.g. Not found) - * @param string $message - */ - function error ($code, $name, $message) - { - $controller = new Controller ($this); - $controller->base = $this->base; - $controller->error($code, $name, $message); - } - -/** - * Convenience method to display a 404 page. - * - * @param unknown_type $url - * @param unknown_type $message - */ - function error404 ($url, $message) - { - $this->error('404', 'Not found', sprintf(ERROR_404, $url, $message)); - } - -/** - * If DEBUG is set, this displays a 404 error with the message that no controller is set. If DEBUG is not set, nothing happens. - * - * @param string $url - */ - function errorNoController ($url) - { - DEBUG? - trigger_error (ERROR_NO_CONTROLLER_SET, E_USER_ERROR): - $this->error404($url, "no controller set"); - exit; - } - -/** - * If DEBUG is set, this displays a 404 error with the message that the asked-for controller does not exist. If DEBUG is not set, nothing happens. - * - * @param string $url - * @param string $controller_class - */ - function errorUnknownController ($url, $controller_class) - { - DEBUG? - trigger_error (sprintf(ERROR_UNKNOWN_CONTROLLER, $controller_class), E_USER_ERROR): - $this->error404($url, "missing controller \"{$controller_class}\""); - exit; - } - -/** - * If DEBUG is set, this displays a 404 error with the message that no action is set. If DEBUG is not set, nothing happens. - * - * @param string $url - */ - function errorNoAction ($url) - { - DEBUG? - trigger_error (ERROR_NO_ACTION_SET, E_USER_ERROR): - $this->error404(sprintf(ERROR_404, $url, "no action set")); - exit; - } - -/** - * If DEBUG is set, this displays a 404 error with the message that no such action exists. If DEBUG is not set, nothing happens. - * - * @param string $url - * @param string $controller_class - * @param string $action - */ - function errorUnknownAction ($url,$controller_class, $action) - { - DEBUG? - trigger_error (sprintf(ERROR_NO_ACTION, $action, $controller_class), E_USER_ERROR): - $this->error404($url, "missing controller \"{$controller_class}\""); - exit; - } -} - -?> + + // +// + Copyright: (c) 2005, Cake Authors/Developers + // +// + Author(s): Michal Tatarynowicz aka Pies + // +// + Larry E. Masters aka PhpNut + // +// + Kamil Dzielinski aka Brego + // +// +------------------------------------------------------------------+ // +// + Licensed under The MIT License + // +// + Redistributions of files must retain the above copyright notice. + // +// + See: http://www.opensource.org/licenses/mit-license.php + // +////////////////////////////////////////////////////////////////////////// + +/** + * Purpose: Dispatcher + * Dispatches the request, creating aproppriate models and controllers. + * + * @filesource + * @author Cake Authors/Developers + * @copyright Copyright (c) 2005, Cake Authors/Developers + * @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers + * @package cake + * @subpackage cake.libs + * @since Cake v 0.2.9 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + */ + +define('DISPATCH_NO_CONTROLLER', 'missingController'); +define('DISPATCH_UNKNOWN_CONTROLLER', 'missingController'); +define('DISPATCH_NO_ACTION', 'missingAction'); +define('DISPATCH_UNKNOWN_ACTION', 'missingAction'); +define('DISPATCHER_UNKNOWN_VIEW', 'missingView'); + +uses('error_messages', 'object', 'router', 'controller'); + +/** + * Dispatches the request, creating appropriate models and controllers. + * + * @package cake + * @subpackage cake.libs + * @since Cake v 0.2.9 + */ +class Dispatcher extends Object +{ + /** + * Base URL + * @var string + */ + var $base = false; + + /** + * Fetches base url. + */ + function __construct() + { + $this->base = $this->baseUrl(); + parent::__construct(); + } + + /** + * Dispatches the request (action). + * + * @param string $url + * @return array + */ + function dispatch($url) + { + $params = $this->parseParams($url); + $result = $this->invoke($url); + + return $result === true? $params: array(); + } + + /** + * Enter description here... + * + * @param string $url + * @return unknown + */ + function invoke($url) + { + global $_POST, $_GET, $_FILES, $_SESSION; + + $params = $this->parseParams($url); + $missingController = false; + $missingAction = false; + $missingView = false; + + if (empty($params['controller'])) + { + $missingController = true; + } + else + { + $ctrlName = Inflector::camelize($params['controller']); + $ctrlClass = $ctrlName.'Controller'; + + if (!loadController($ctrlName) || !class_exists($ctrlClass)) + { + $missingController = true; + } + } + + if ($missingController) + { + $ctrlClass = 'AppController'; + $controller = new $ctrlClass($this); + $params['action'] = 'missingController'; + $controller->missingController = $params['controller']; + } + else + { + // create controller + $controller = new $ctrlClass($this); + } + + // if action is not set, and the default Controller::index() method doesn't exist + if (empty($params['action'])) + { + if (method_exists($controller, 'index')) + { + $params['action'] = 'index'; + } + else + { + $missingAction = true; + } + } + + // if the requested action doesn't exist + if (!method_exists($controller, $params['action'])) + { + $missingAction = true; + } + + if ($missingAction) + { + $controller->missingAction = $params['action']; + $params['action'] = 'missingAction'; + } + + // initialize the controller + $controller->base = $this->base; + $controller->here = $this->base.'/'.$url; + $controller->params = $params; + $controller->action = $params['action']; + $controller->data = empty($params['data'])? null: $params['data']; + //$controller->passed_args = empty($params['pass'])? null: $params['pass']; + + // EXECUTE THE REQUESTED ACTION + call_user_func_array(array(&$controller, $params['action']), empty($params['pass'])? null: $params['pass']); + + $isFatal = isset($controller->isFatal) ? $controller->isFatal : false; + + if ($isFatal) + { + switch($params['action']) + { + case 'missingController': + $this->errorUnknownController($url, $ctrlName); + break; + + case 'missingAction': + $this->errorUnknownAction($url, $ctrlClass, $controller->missingAction); + break; + } + } + + if ($controller->autoRender) + { + $controller->render(); + } + + return true; + } + + /** + * Returns array of GET and POST parameters. GET parameters are taken from given URL. + * + * @param string $from_url + * @return array Parameters found in POST and GET. + */ + function parseParams($from_url) + { + global $_POST, $_FILES; + + // load routes config + $Route = new Router(); + include CONFIGS.'routes.php'; + $params = $Route->parse ($from_url); + + // add submitted form data + $params['form'] = $_POST; + if (isset($_POST['data'])) + { + $params['data'] = $_POST['data']; + } + + foreach ($_FILES as $name => $data) + { + $params['form'][$name] = $data; + } + + return $params; + } + + /** + * Returns a base URL. + * + * @return string + */ + function baseUrl() + { + global $_SERVER; + + //non mod_rewrite use: + if (defined('BASE_URL')) return BASE_URL; + + $doc_root = $_SERVER['DOCUMENT_ROOT']; + $script_name = $_SERVER['PHP_SELF']; + + // if document root ends with 'public', it's probably correctly set + $r = null; + if (ereg('/^.*/public(\/)?$/', $doc_root)) + return preg_match('/^(.*)\/index\.php$/', $script_name, $r)? $r[1]: false; + else + // document root is probably not set to Cake 'public' dir + return preg_match('/^(.*)\/public\/index\.php$/', $script_name, $r)? $r[1]: false; + } + + /** + * Displays an error page (e.g. 404 Not found). + * + * @param int $code Error code (e.g. 404) + * @param string $name Name of the error message (e.g. Not found) + * @param string $message + */ + function error ($code, $name, $message) + { + $controller = new Controller ($this); + $controller->base = $this->base; + $controller->error($code, $name, $message); + } + + /** + * Convenience method to display a 404 page. + * + * @param unknown_type $url + * @param unknown_type $message + */ + function error404 ($url, $message) + { + $this->error('404', 'Not found', sprintf(ERROR_404, $url, $message)); + } + + /** + * If DEBUG is set, this displays a 404 error with the message that no controller is set. If DEBUG is not set, nothing happens. + * + * @param string $url + */ + function errorNoController ($url) + { + DEBUG? + trigger_error (ERROR_NO_CONTROLLER_SET, E_USER_ERROR): + $this->error404($url, "no controller set"); + exit; + } + + /** + * If DEBUG is set, this displays a 404 error with the message that the asked-for controller does not exist. If DEBUG is not set, nothing happens. + * + * @param string $url + * @param string $controller_class + */ + function errorUnknownController ($url, $controller_class) + { + DEBUG? + trigger_error (sprintf(ERROR_UNKNOWN_CONTROLLER, $controller_class), E_USER_ERROR): + $this->error404($url, "missing controller \"{$controller_class}\""); + exit; + } + + /** + * If DEBUG is set, this displays a 404 error with the message that no action is set. If DEBUG is not set, nothing happens. + * + * @param string $url + */ + function errorNoAction ($url) + { + DEBUG? + trigger_error (ERROR_NO_ACTION_SET, E_USER_ERROR): + $this->error404(sprintf(ERROR_404, $url, "no action set")); + exit; + } + + /** + * If DEBUG is set, this displays a 404 error with the message that no such action exists. If DEBUG is not set, nothing happens. + * + * @param string $url + * @param string $controller_class + * @param string $action + */ + function errorUnknownAction ($url,$controller_class, $action) + { + DEBUG? + trigger_error (sprintf(ERROR_NO_ACTION, $action, $controller_class), E_USER_ERROR): + $this->error404($url, "missing controller \"{$controller_class}\""); + exit; + } +} + +?> diff --git a/libs/helpers/ajax.php b/libs/helpers/ajax.php new file mode 100644 index 000000000..2d3b07ce4 --- /dev/null +++ b/libs/helpers/ajax.php @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/libs/helpers/html.php b/libs/helpers/html.php new file mode 100644 index 000000000..c03456b44 --- /dev/null +++ b/libs/helpers/html.php @@ -0,0 +1,576 @@ + + // +// + Copyright: (c) 2005, Cake Authors/Developers + // +// + Author(s): Michal Tatarynowicz aka Pies + // +// + Larry E. Masters aka PhpNut + // +// + Kamil Dzielinski aka Brego + // +// +------------------------------------------------------------------+ // +// + Licensed under The MIT License + // +// + Redistributions of files must retain the above copyright notice. + // +// + See: http://www.opensource.org/licenses/mit-license.php + // +////////////////////////////////////////////////////////////////////////// + +/** + * Purpose: Dispatcher + * Dispatches the request, creating aproppriate models and controllers. + * + * @filesource + * @author Cake Authors/Developers + * @copyright Copyright (c) 2005, Cake Authors/Developers + * @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers + * @package cake + * @subpackage cake.libs + * @since Cake v 0.2.9 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + */ + +class HtmlHelper +{ + /** + * Returns given string trimmed to given length, adding an ending (default: "..") if necessary. + * + * @param string $string String to trim + * @param integer $length Length of returned string, excluding ellipsis + * @param string $ending Ending to be appended after trimmed string + * @return string Trimmed string + */ + function trim($string, $length, $ending='..') + { + return substr($string, 0, $length).(strlen($string)>$length? $ending: null); + } + + /** + * Returns an URL for a combination of controller and action. + * + * @param string $url + * @return string Full constructed URL as a string. + */ + function url($url=null) + { + global $controller; + + if (empty($url)) + { + return $controller->here; + } + elseif ($url[0] == '/') + { + $out = $controller->base . $url; + } + else + { + $out = $controller->base . '/' . strtolower($controller->params['controller']) . '/' . $url; + } + + return ereg_replace('&([^a])', '&\1', $out); + } + + /** + * Returns a space-separated string with items of the $options array. + * + * @param array $options Array of HTML options. + * @param string $insert_before + * @param unknown_type $insert_after + * @return string + */ + function parseHtmlOptions($options, $exclude=null, $insert_before=' ', $insert_after=null) + { + if (!is_array($exclude)) $exclude = array(); + + if (is_array($options)) + { + $out = array(); + foreach ($options as $k=>$v) + { + if (!in_array($k, $exclude)) + { + $out[] = "{$k}=\"{$v}\""; + } + } + $out = join(' ', $out); + return $out? $insert_before.$out.$insert_after: null; + } + else + { + return $options? $insert_before.$options.$insert_after: null; + } + } + + /** + * Returns an HTML link to $url for given $title, optionally using $html_options and $confirm_message (for "flash"). + * + * @param string $title The content of the A tag. + * @param string $url + * @param array $html_options Array of HTML options. + * @param string $confirm_message Message to be shown in "flash". + * @return string + */ + function linkTo($title, $url, $html_options=null, $confirm_message=false) + { + $confirm_message? $html_options['onClick'] = "return confirm('{$confirm_message}')": null; + return sprintf(TAG_LINK, $this->url($url), $this->parseHtmlOptions($html_options), $title); + } + + /** + * Returns an external HTML link to $url for given $title, optionally using $html_options. + * The ereg_replace is to replace the '&' in the URL into & for XHTML purity. + * + * @param string $title + * @param string $url + * @param array $html_options + * @return string + */ + function linkOut($title, $url=null, $html_options=null) + { + $url = $url? $url: $title; + return sprintf(TAG_LINK, ereg_replace('&([^a])', '&\1', $url), $this->parseHtmlOptions($html_options), $title); + } + + /** + * Returns an HTML FORM element. + * + * @param string $target URL for the FORM's ACTION attribute. + * @param string $type FORM type (POST/GET). + * @param array $html_options + * @return string An formatted opening FORM tag. + */ + function formTag($target=null, $type='post', $html_options=null) + { + $html_options['action'] = $this->UrlFor($target); + $html_options['method'] = $type=='get'? 'get': 'post'; + $type == 'file'? $html_options['enctype'] = 'multipart/form-data': null; + + return sprintf(TAG_FORM, $this->parseHtmlOptions($html_options, null, '')); + } + + /** + * Returns a generic HTML tag (no content). + * + * Examples: + * * tag("br") =>
+ * * tag("input", array("type" => "text")) => + * + * @param string $name Name of HTML element + * @param array $options HTML options + * @param bool $open Is the tag open or closed? (defaults to closed "/>") + * @return string The formatted HTML tag + */ + function tag($name, $options=null, $open=false) + { + $tag = "<$name ". $this->parseHtmlOptions($options); + $tag .= $open? ">" : " />"; + return $tag; + } + + /** + * Returns a generic HTML tag with content. + * + * Examples: + * * content_tag("p", "Hello world!") =>

Hello world!

+ * * content_tag("div", content_tag("p", "Hello world!"), array("class" => "strong")) => + *

Hello world!

+ * + * @param string $name Name of HTML element + * @param array $options HTML options + * @param bool $open Is the tag open or closed? (defaults to closed "/>") + * @return string The formatted HTML tag + */ + function contentTag($name, $content, $options=null) + { + return "<$name ". $this->parseHtmlOptions($options). ">$content"; + } + + /** + * Returns a formatted SUBMIT button for HTML FORMs. + * + * @param string $caption Text on SUBMIT button + * @param array $html_options HTML options + * @return string The formatted SUBMIT button + */ + function submitTag($caption='Submit', $html_options=null) + { + $html_options['value'] = $caption; + return sprintf(TAG_SUBMIT, $this->parseHtmlOptions($html_options, null, '', ' ')); + } + + /** + * Returns a formatted INPUT tag for HTML FORMs. + * + * @param string $tag_name Name attribute for INPUT element + * @param int $size Size attribute for INPUT element + * @param array $html_options + * @return string The formatted INPUT element + */ + function inputTag($tag_name, $size=20, $html_options=null) + { + $html_options['size'] = $size; + $html_options['value'] = isset($html_options['value'])? $html_options['value']: $this->tagValue($tag_name); + $this->tagIsInvalid($tag_name)? $html_options['class'] = 'form_error': null; + return sprintf(TAG_INPUT, $tag_name, $this->parseHtmlOptions($html_options, null, '', ' ')); + } + + /** + * Returns an INPUT element with type="password". + * + * @param string $tag_name + * @param int $size + * @param array $html_options + * @return string + */ + function passwordTag($tag_name, $size=20, $html_options=null) + { + $html_options['size'] = $size; + empty($html_options['value'])? $html_options['value'] = $this->tagValue($tag_name): null; + return sprintf(TAG_PASSWORD, $tag_name, $this->parseHtmlOptions($html_options, null, '', ' ')); + } + + /** + * Returns an INPUT element with type="hidden". + * + * @param string $tag_name + * @param string $value + * @param array $html_options + * @return string + */ + function hiddenTag($tag_name, $value=null, $html_options=null) + { + $html_options['value'] = $value? $value: $this->tagValue($tag_name); + return sprintf(TAG_HIDDEN, $tag_name, $this->parseHtmlOptions($html_options, null, '', ' ')); + } + + /** + * Returns an INPUT element with type="file". + * + * @param string $tag_name + * @param array $html_options + * @return string + */ + function fileTag($tag_name, $html_options=null) + { + return sprintf(TAG_FILE, $tag_name, $this->parseHtmlOptions($html_options, null, '', ' ')); + } + + /** + * Returns a TEXTAREA element. + * + * @param string $tag_name + * @param int $cols + * @param int $rows + * @param array $html_options + * @return string + */ + function areaTag($tag_name, $cols=60, $rows=10, $html_options=null) + { + $value = empty($html_options['value'])? $this->tagValue($tag_name): empty($html_options['value']); + $html_options['cols'] = $cols; + $html_options['rows'] = $rows; + return sprintf(TAG_AREA, $tag_name, $this->parseHtmlOptions($html_options, null, ' '), $value); + } + + /** + * Returns an INPUT element with type="checkbox". Checkedness is to be passed as string "checked" with the key "checked" in the $html_options array. + * + * @param string $tag_name + * @param string $title + * @param array $html_options + * @return string + */ + function checkboxTag($tag_name, $title=null, $html_options=null) + { + $this->tagValue($tag_name)? $html_options['checked'] = 'checked': null; + $title = $title? $title: ucfirst($tag_name); + return sprintf(TAG_CHECKBOX, $tag_name, $tag_name, $tag_name, $this->parseHtmlOptions($html_options, null, '', ' '), $title); + } + + /** + * Returns a set of radio buttons. + * + * @param string $tag_name + * @param array $options Array of options to select from + * @param string $inbetween String to separate options. See PHP's implode() function + * @param array $html_options + * @return string + */ + function radioTags($tag_name, $options, $inbetween=null, $html_options=null) + { + $value = isset($html_options['value'])? $html_options['value']: $this->tagValue($tag_name); + $out = array(); + foreach ($options as $opt_value=>$opt_title) + { + $options_here = array('value' => $opt_value); + $opt_value==$value? $options_here['checked'] = 'checked': null; + $parsed_options = $this->parseHtmlOptions(array_merge($html_options, $options_here), null, '', ' '); + $individual_tag_name = "{$tag_name}_{$opt_value}"; + $out[] = sprintf(TAG_RADIOS, $individual_tag_name, $tag_name, $individual_tag_name, $parsed_options, $opt_title); + } + + $out = join($inbetween, $out); + return $out? $out: null; + } + + /** + * Returns a SELECT element, + * + * @param string $tag_name Name attribute of the SELECT + * @param array $option_elements Array of the OPTION elements (as 'value'=>'Text' pairs) to be used in the SELECT element + * @param array $select_attr Array of HTML options for the opening SELECT element + * @param array $option_attr Array of HTML options for the enclosed OPTION elements + * @return string Formatted SELECT element + */ + function selectTag($tag_name, $option_elements, $selected=null, $select_attr=null, $option_attr=null) + { + if (!is_array($option_elements) || !count($option_elements)) + return null; + + $select[] = sprintf(TAG_SELECT_START, $tag_name, $this->parseHtmlOptions($select_attr)); + $select[] = sprintf(TAG_SELECT_EMPTY, $this->parseHtmlOptions($option_attr)); + + foreach ($option_elements as $name=>$title) + { + $options_here = $option_attr; + + if ($selected == $name) + $options_here['selected'] = 'selected'; + + $select[] = sprintf(TAG_SELECT_OPTION, $name, $this->parseHtmlOptions($options_here), $title); + } + + $select[] = sprintf(TAG_SELECT_END); + + return implode("\n", $select); + } + + /** + * Returns a formatted IMG element. + * + * @param string $path Path to the image file + * @param string $alt ALT attribute for the IMG tag + * @param array $html_options + * @return string Formatted IMG tag + */ + function imageTag($path, $alt=null, $html_options=null) + { + $url = $this->base.IMAGES_URL.$path; + return sprintf(TAG_IMAGE, $url, $alt, $this->parseHtmlOptions($html_options, null, '', ' ')); + } + + /** + * Returns a mailto: link. + * + * @param string $title Title of the link, or the e-mail address (if the same) + * @param string $email E-mail address if different from title + * @param array $options + * @return string Formatted A tag + */ + function linkEmail($title, $email=null, $options=null) + { + // if no $email, then title contains the email. + if (empty($email)) $email = $title; + + $match = array(); + + // does the address contain extra attributes? + preg_match('!^(.*)(\?.*)$!', $email, $match); + + // plaintext + if (empty($options['encode']) || !empty($match[2])) + { + return sprintf(TAG_MAILTO, $email, $this->parseHtmlOptions($options), $title); + } + // encoded to avoid spiders + else + { + $email_encoded = null; + for ($ii=0; $ii < strlen($email); $ii++) + { + if(preg_match('!\w!',$email[$ii])) + { + $email_encoded .= '%' . bin2hex($email[$ii]); + } + else + { + $email_encoded .= $email[$ii]; + } + } + + $title_encoded = null; + for ($ii=0; $ii < strlen($title); $ii++) + { + $title_encoded .= preg_match('/^[A-Za-z0-9]$/', $title[$ii])? '&#x' . bin2hex($title[$ii]).';': $title[$ii]; + } + + return sprintf(TAG_MAILTO, $email_encoded, $this->parseHtmlOptions($options, array('encode')), $title_encoded); + } + } + + /** + * Returns a LINK element for CSS stylesheets. + * + * @param string $path Path to CSS file + * @param string $rel Rel attribute. Defaults to "stylesheet". + * @param array $html_options + * @return string Formatted LINK element. + */ + function cssTag($path, $rel='stylesheet', $html_options=null) + { + $url = "{$this->base}/".(COMPRESS_CSS? 'c': '')."css/{$path}.css"; + return sprintf(TAG_CSS, $rel, $url, $this->parseHtmlOptions($html_options, null, '', ' ')); + } + + /** + * Returns a charset meta-tag + * + * @param string $charset + * @return string + */ + function charsetTag($charset) + { + return sprintf(TAG_CHARSET, $charset); + } + + /** + * Returns a JavaScript script tag. + * + * @param string $script The JavaScript to be wrapped in SCRIPT tags. + * @return string The full SCRIPT element, with the JavaScript inside it. + */ + function javascriptTag($script) + { + return sprintf(TAG_JAVASCRIPT, $script); + } + + /** + * Returns a JavaScript include tag + * + * @param string $url URL to JavaScript file. + * @return string + */ + function javascriptIncludeTag($url) + { + return sprintf(TAG_JAVASCRIPT_INCLUDE, $this->base.$url); + } + + /** + * Returns a row of formatted and named TABLE headers. + * + * @param array $names + * @param array $tr_options + * @param array $th_options + * @return string + */ + function tableHeaders($names, $tr_options=null, $th_options=null) + { + $out = array(); + foreach ($names as $arg) + { + $out[] = sprintf(TAG_TABLE_HEADER, $this->parseHtmlOptions($th_options), $arg); + } + + return sprintf(TAG_TABLE_HEADERS, $this->parseHtmlOptions($tr_options), join(' ', $out)); + } + + /** + * Returns a formatted string of table rows (TR's with TD's in them). + * + * @param array $data Array of table data + * @param array $tr_options HTML options for TR elements + * @param array $td_options HTML options for TD elements + * @return string + */ + function tableCells($data, $odd_tr_options=null, $even_tr_options=null) + { + if (empty($data[0]) || !is_array($data[0])) + { + $data = array($data); + } + + $count=0; + foreach ($data as $line) + { + $count++; + $cells_out = array(); + foreach ($line as $cell) + { + $cells_out[] = sprintf(TAG_TABLE_CELL, null, $cell); + } + + $options = $this->parseHtmlOptions($count%2? $odd_tr_options: $even_tr_options); + $out[] = sprintf(TAG_TABLE_ROW, $options, join(' ', $cells_out)); + } + + return join("\n", $out); + } + + /** + * Generates a nested
    (unordered list) tree from an array + * + * @param array $data + * @param array $htmlOptions + * @param string $bodyKey + * @param childrenKey $bodyKey + * @return string + */ + function guiListTree($data, $htmlOptions=null, $bodyKey='body', $childrenKey='children') + { + $out = "parseHtmlOptions($htmlOptions).">\n"; + + foreach ($data as $item) + { + $out .= "
  • {$item[$bodyKey]}
  • \n"; + if (isset($item[$childrenKey]) && is_array($item[$childrenKey]) && count($item[$childrenKey])) + { + $out .= $this->guiListTree($item[$childrenKey], $htmlOptions, $bodyKey, $childrenKey); + } + } + + $out .= "
\n"; + + return $out; + } + + /** + * Adds $name and $link to the breadcrumbs array. + * + * @param string $name Text for link + * @param string $link URL for link + */ + function addCrumb($name, $link) + { + $this->_crumbs[] = array ($name, $link); + } + + /** + * Returns the breadcrumb trail as a sequence of »-separated links. + * + * @param string $separator Text to separate crumbs. + * @return string Formatted -separated list of breadcrumb links. Returns NULL if $this->_crumbs is empty. + */ + function getCrumbs($separator = '»') + { + + if (count($this->_crumbs)) + { + + $out = array("base}\">START"); + foreach ($this->_crumbs as $crumb) + { + $out[] = "base}{$crumb[1]}\">{$crumb[0]}"; + } + + return join($separator, $out); + } + else + { + return null; + } + } + +} + +?> \ No newline at end of file diff --git a/libs/object.php b/libs/object.php index d2e1ae285..a95fe725a 100644 --- a/libs/object.php +++ b/libs/object.php @@ -1,112 +1,113 @@ - + // -// + Copyright: (c) 2005, Cake Authors/Developers + // -// + Author(s): Michal Tatarynowicz aka Pies + // -// + Larry E. Masters aka PhpNut + // -// + Kamil Dzielinski aka Brego + // -// +------------------------------------------------------------------+ // -// + Licensed under The MIT License + // -// + Redistributions of files must retain the above copyright notice. + // -// + See: http://www.opensource.org/licenses/mit-license.php + // -////////////////////////////////////////////////////////////////////////// - -/** - * Purpose: Object - * Allows for __construct to be used in PHP4. - * - * @filesource - * @author Cake Authors/Developers - * @copyright Copyright (c) 2005, Cake Authors/Developers - * @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers - * @package cake - * @subpackage cake.libs - * @since Cake v 0.2.9 - * @version $Revision$ - * @modifiedby $LastChangedBy$ - * @lastmodified $Date$ - * @license http://www.opensource.org/licenses/mit-license.php The MIT License - */ - -uses('log'); - -/** - * Enter description here... - * - * @package cake - * @subpackage cake.libs - * @since Cake v 0.2.9 - */ -class Object -{ - - /** - * Database connection, if available. - * - * @var DBO - */ - var $db = null; - -/** - * A hack to support __construct() on PHP 4 - * Hint: descendant classes have no PHP4 class_name() constructors, - * so this constructor gets called first and calls the top-layer __construct() - * which (if present) should call parent::__construct() - * - * @return Object - */ - function Object() - { - global $DB; - - $this->db =& $DB; - $args = func_get_args(); - register_shutdown_function(array(&$this, '__destruct')); - call_user_func_array(array(&$this, '__construct'), $args); - } - -/** - * Class constructor, overridden in descendant classes. - */ - function __construct() { - } - -/** - * Class destructor, overridden in descendant classes. - */ - function __destruct() { - } - -/** - * Object-to-string conversion. - * Each class can override it as necessary. - * - * @return string This name of this class - */ - function toString () { - return get_class($this); - } - -/** - * API for logging events. - * - * @param string $msg Log message - * @param int $type Error type constant. Defined in /libs/log.php. - */ - function log ($msg, $type=LOG_ERROR) { - if (!$this->_log) - $this->_log = new Log (); - - switch ($type) { - case LOG_DEBUG: - return $this->_log->write('debug', $msg); - default: - return $this->_log->write('error', $msg); - } - } - -} - + + // +// + Copyright: (c) 2005, Cake Authors/Developers + // +// + Author(s): Michal Tatarynowicz aka Pies + // +// + Larry E. Masters aka PhpNut + // +// + Kamil Dzielinski aka Brego + // +// +------------------------------------------------------------------+ // +// + Licensed under The MIT License + // +// + Redistributions of files must retain the above copyright notice. + // +// + See: http://www.opensource.org/licenses/mit-license.php + // +////////////////////////////////////////////////////////////////////////// + +/** + * Purpose: Object + * Allows for __construct to be used in PHP4. + * + * @filesource + * @author Cake Authors/Developers + * @copyright Copyright (c) 2005, Cake Authors/Developers + * @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers + * @package cake + * @subpackage cake.libs + * @since Cake v 0.2.9 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + */ + +uses('log'); + +/** + * Object class, allowing __construct and __destruct. + * + * @package cake + * @subpackage cake.libs + * @since Cake v 0.2.9 + */ +class Object +{ + /** + * Database connection, if available. + * + * @var DBO + */ + var $db = null; + + /** + * A hack to support __construct() on PHP 4 + * Hint: descendant classes have no PHP4 class_name() constructors, + * so this constructor gets called first and calls the top-layer __construct() + * which (if present) should call parent::__construct() + * + * @return Object + */ + function Object() + { + global $DB; + + $this->db =& $DB; + $args = func_get_args(); + register_shutdown_function(array(&$this, '__destruct')); + call_user_func_array(array(&$this, '__construct'), $args); + } + + /** + * Class constructor, overridden in descendant classes. + */ + function __construct() {} + + /** + * Class destructor, overridden in descendant classes. + */ + function __destruct() {} + + /** + * Object-to-string conversion. + * Each class can override it as necessary. + * + * @return string This name of this class + */ + function toString() + { + return get_class($this); + } + + /** + * API for logging events. + * + * @param string $msg Log message + * @param int $type Error type constant. Defined in /libs/log.php. + */ + function log ($msg, $type=LOG_ERROR) + { + if (!$this->_log) + { + $this->_log = new Log (); + } + + switch ($type) + { + case LOG_DEBUG: + return $this->_log->write('debug', $msg); + default: + return $this->_log->write('error', $msg); + } + } +} + ?> \ No newline at end of file diff --git a/libs/template.php b/libs/template.php index 76d51db14..33dec8702 100644 --- a/libs/template.php +++ b/libs/template.php @@ -80,7 +80,7 @@ class Template extends Object * @var array * @access private */ - var $_view_vars = array(); + var $_viewVars = array(); /** * Enter description here... @@ -103,7 +103,7 @@ class Template extends Object * * @param string $layout */ - function setLayout ($layout) + function setLayout($layout) { $this->layout = $layout; } @@ -125,7 +125,7 @@ class Template extends Object * * @param string $pageTitle Text for the title */ - function setTitle ($pageTitle) + function setTitle($pageTitle) { $this->pageTitle = $pageTitle; } @@ -140,9 +140,9 @@ class Template extends Object foreach ($data as $name => $value) { if ($name == 'title') - $this->setTitle ($value); + $this->setTitle($value); else - $this->_view_vars[$name] = $value; + $this->_viewVars[$name] = $value; } } @@ -153,7 +153,7 @@ class Template extends Object * @param string $url URL fragment * @param int $time Display time, in seconds */ - function flash ($message, $url, $time=1) + function flash($message, $url, $time=1) { $this->autoRender = false; $this->autoLayout = false; @@ -173,7 +173,7 @@ class Template extends Object * @param string $layout * @param string $file Custom filename for view */ - function render ($action=null, $layout=null, $file=null) + function render($action=null, $layout=null, $file=null) { if (isset($this->hasRendered) && $this->hasRendered) { @@ -191,60 +191,59 @@ class Template extends Object //$isFatal = isset($this->isFatal) ? $this->isFatal : false; - $view_fn = $file? $file: $this->_getViewFn($action); + $viewFn = $file? $file: $this->_getViewFn($action); - if (!is_file($view_fn)) + if (!is_file($viewFn)) { if (strtolower(get_class($this)) == 'template') { - return array('action' => $action, 'layout' => $layout, 'view_fn' => $view_fn); + return array('action' => $action, 'layout' => $layout, 'viewFn' => $viewFn); } - // check to see if the missing view is due to a custom missing_action - if (strpos($action, 'missing_action') !== false) + // check to see if the missing view is due to a custom missingAction + if (strpos($action, 'missingAction') !== false) { - $error_action = 'missing_action'; + $errorAction = 'missingAction'; } else { - $error_action = 'missing_view'; + $errorAction = 'missingView'; } - // check for controller-level view handler foreach(array($this->name, 'errors') as $view_dir) { - $missing_view_fn = VIEWS.$view_dir.DS.$error_action.'.thtml'; - $missing_view_exists = is_file($missing_view_fn); - if ($missing_view_exists) + $missingViewFn = VIEWS.$view_dir.DS.Inflector::underscore($errorAction).'.thtml'; + $missingViewExists = is_file($missingViewFn); + if ($missingViewExists) { break; } } - if (strpos($action, 'missing_view') === false) + if (strpos($action, 'missingView') === false) { $controller = $this; - $controller->missing_view = $view_fn; - $controller->action = $action; - call_user_func_array(array(&$controller, 'missing_view'), empty($params['pass'])? null: $params['pass']); + $controller->missingView = $viewFn; + $controller->action = $action; + call_user_func_array(array(&$controller, 'missingView'), empty($params['pass'])? null: $params['pass']); $isFatal = isset($this->isFatal) ? $this->isFatal : false; if (!$isFatal) { - $view_fn = $missing_view_fn; + $viewFn = $missingViewFn; } } else { - $missing_view_exists = false; + $missingViewExists = false; } - if (!$missing_view_exists || $isFatal) + if (!$missingViewExists || $isFatal) { - // app/errors/missing_view.thtml view is missing! + // app/view/errors/missing_view.thtml view is missing! if (DEBUG) { - trigger_error (sprintf(ERROR_NO_VIEW, $action, $view_fn), E_USER_ERROR); + trigger_error(sprintf(ERROR_NO_VIEW, $action, $viewFn), E_USER_ERROR); } else { @@ -255,9 +254,9 @@ class Template extends Object } } - if ($view_fn && !$this->hasRendered) + if ($viewFn && !$this->hasRendered) { - $out = $this->_render($view_fn, $this->_view_vars, 0); + $out = $this->_render($viewFn, $this->_viewVars, 0); if ($out !== false) { if ($this->layout && $this->autoLayout) @@ -270,8 +269,8 @@ class Template extends Object } else { - $out = $this->_render($view_fn, $this->_view_vars, false); - trigger_error (sprintf(ERROR_IN_VIEW, $view_fn, $out), E_USER_ERROR); + $out = $this->_render($viewFn, $this->_viewVars, false); + trigger_error(sprintf(ERROR_IN_VIEW, $viewFn, $out), E_USER_ERROR); } return true; @@ -284,11 +283,11 @@ class Template extends Object * @param string $content_for_layout Content to render in a view * @return string Rendered output */ - function renderLayout ($content_for_layout) + function renderLayout($content_for_layout) { $layout_fn = $this->_getLayoutFn(); - $data_for_layout = array_merge($this->_view_vars, array( + $data_for_layout = array_merge($this->_viewVars, array( 'title_for_layout'=>$this->pageTitle !== false? $this->pageTitle: Inflector::humanize($this->viewpath), 'content_for_layout'=>$content_for_layout)); @@ -297,7 +296,7 @@ class Template extends Object if ($out === false) { $out = $this->_render($layout_fn, $data_for_layout, false); - trigger_error (sprintf(ERROR_IN_LAYOUT, $layout_fn, $out), E_USER_ERROR); + trigger_error(sprintf(ERROR_IN_LAYOUT, $layout_fn, $out), E_USER_ERROR); return false; } else { @@ -305,7 +304,7 @@ class Template extends Object } } else { - trigger_error (sprintf(ERROR_NO_LAYOUT, $this->layout, $layout_fn), E_USER_ERROR); + trigger_error(sprintf(ERROR_NO_LAYOUT, $this->layout, $layout_fn), E_USER_ERROR); return false; } } @@ -317,14 +316,14 @@ class Template extends Object * @param array $params Array of data for rendered view * @return string Rendered output */ - function renderElement ($name, $params=array()) + function renderElement($name, $params=array()) { $fn = ELEMENTS.$name.'.thtml'; if (!file_exists($fn)) return "(Error rendering {$name})"; - return $this->_render($fn, array_merge($this->_view_vars, $params)); + return $this->_render($fn, array_merge($this->_viewVars, $params)); } /** @@ -345,20 +344,49 @@ class Template extends Object */ function _getViewFn($action) { - return VIEWS.$this->viewpath.DS."{$action}.thtml"; + $action = Inflector::underscore($action); + $viewFn = VIEWS.$this->viewpath.DS."{$action}.thtml"; + $viewPath = explode(DS, $viewFn); + + $i = array_search('..', $viewPath); + + unset($viewPath[$i-1]); + unset($viewPath[$i]); + + return '/'.implode('/', $viewPath); } /** * Renders and returns output for given view filename with its * array of data. * - * @param string $___view_fn Filename of the view + * @param string $___viewFn Filename of the view * @param array $___data_for_view Data to include in rendered view - * @param boolean $___play_safe If set to false, the include() of the $__view_fn is done without suppressing output of errors + * @param boolean $___play_safe If set to false, the include() of the $__viewFn is done without suppressing output of errors * @return string Rendered output */ - function _render($___view_fn, $___data_for_view, $___play_safe = true) + function _render($___viewFn, $___data_for_view, $___play_safe = true) { + /** + * Fetching helpers + */ + if ($this->helpers !== false) + { + foreach ($this->helpers as $helper) + { + $helperFn = LIBS.'helpers'.DS.Inflector::underscore($helper).'.php'; + $helperCn = ucfirst($helper).'Helper'; + if (is_file($helperFn)) + { + require_once $helperFn; + if(class_exists($helperCn)===true); + { + ${$helper} = new $helperCn; + } + } + } + } + extract($___data_for_view, EXTR_SKIP); # load all view variables /** * Local template variables. @@ -375,13 +403,17 @@ class Template extends Object /** * Include the template. */ - $___play_safe? @include($___view_fn): include($___view_fn); + $___play_safe? @include($___viewFn): include($___viewFn); $out = ob_get_clean(); return $out; } + + /////////////////////////////////////////////////////////////////////////// + + /** * Returns given string trimmed to given length, adding an elipsis '..' if necessary. * @@ -389,7 +421,7 @@ class Template extends Object * @param int $length Length of returned string, excluding ellipsis * @return string Trimmed string */ - function trimTo ($string, $length) + function trimTo($string, $length) { return substr($string, 0, $length).(strlen($string)>$length? '..': null); } @@ -400,7 +432,7 @@ class Template extends Object * @param string $url * @return string Full constructed URL as a string. */ - function urlFor ($url=null) + function urlFor($url=null) { if (empty($url)) { @@ -426,7 +458,7 @@ class Template extends Object * @param unknown_type $insert_after * @return string */ - function parseHtmlOptions ($options, $exclude=null, $insert_before=' ', $insert_after=null) + function parseHtmlOptions($options, $exclude=null, $insert_before=' ', $insert_after=null) { if (!is_array($exclude)) $exclude = array(); @@ -458,7 +490,7 @@ class Template extends Object * @param string $confirm_message Message to be shown in "flash". * @return string */ - function linkTo ($title, $url, $html_options=null, $confirm_message=false) + function linkTo($title, $url, $html_options=null, $confirm_message=false) { $confirm_message? $html_options['onClick'] = "return confirm('{$confirm_message}')": null; return sprintf(TAG_LINK, $this->UrlFor($url), $this->parseHtmlOptions($html_options), $title); @@ -473,7 +505,7 @@ class Template extends Object * @param array $html_options * @return string */ - function linkOut ($title, $url=null, $html_options=null) + function linkOut($title, $url=null, $html_options=null) { $url = $url? $url: $title; return sprintf(TAG_LINK, ereg_replace('&([^a])', '&\1', $url), $this->parseHtmlOptions($html_options), $title); @@ -487,7 +519,7 @@ class Template extends Object * @param array $html_options * @return string An formatted opening FORM tag. */ - function formTag ($target=null, $type='post', $html_options=null) + function formTag($target=null, $type='post', $html_options=null) { $html_options['action'] = $this->UrlFor($target); $html_options['method'] = $type=='get'? 'get': 'post'; @@ -540,7 +572,7 @@ class Template extends Object * @param array $html_options HTML options * @return string The formatted SUBMIT button */ - function submitTag ($caption='Submit', $html_options=null) + function submitTag($caption='Submit', $html_options=null) { $html_options['value'] = $caption; return sprintf(TAG_SUBMIT, $this->parseHtmlOptions($html_options, null, '', ' ')); @@ -554,7 +586,7 @@ class Template extends Object * @param array $html_options * @return string The formatted INPUT element */ - function inputTag ($tag_name, $size=20, $html_options=null) + function inputTag($tag_name, $size=20, $html_options=null) { $html_options['size'] = $size; $html_options['value'] = isset($html_options['value'])? $html_options['value']: $this->tagValue($tag_name); @@ -570,7 +602,7 @@ class Template extends Object * @param array $html_options * @return string */ - function passwordTag ($tag_name, $size=20, $html_options=null) + function passwordTag($tag_name, $size=20, $html_options=null) { $html_options['size'] = $size; empty($html_options['value'])? $html_options['value'] = $this->tagValue($tag_name): null; @@ -585,7 +617,7 @@ class Template extends Object * @param array $html_options * @return string */ - function hiddenTag ($tag_name, $value=null, $html_options=null) + function hiddenTag($tag_name, $value=null, $html_options=null) { $html_options['value'] = $value? $value: $this->tagValue($tag_name); return sprintf(TAG_HIDDEN, $tag_name, $this->parseHtmlOptions($html_options, null, '', ' ')); @@ -598,7 +630,7 @@ class Template extends Object * @param array $html_options * @return string */ - function fileTag ($tag_name, $html_options=null) + function fileTag($tag_name, $html_options=null) { return sprintf(TAG_FILE, $tag_name, $this->parseHtmlOptions($html_options, null, '', ' ')); } @@ -612,7 +644,7 @@ class Template extends Object * @param array $html_options * @return string */ - function areaTag ($tag_name, $cols=60, $rows=10, $html_options=null) + function areaTag($tag_name, $cols=60, $rows=10, $html_options=null) { $value = empty($html_options['value'])? $this->tagValue($tag_name): empty($html_options['value']); $html_options['cols'] = $cols; @@ -628,7 +660,7 @@ class Template extends Object * @param array $html_options * @return string */ - function checkboxTag ($tag_name, $title=null, $html_options=null) + function checkboxTag($tag_name, $title=null, $html_options=null) { $this->tagValue($tag_name)? $html_options['checked'] = 'checked': null; $title = $title? $title: ucfirst($tag_name); @@ -644,7 +676,7 @@ class Template extends Object * @param array $html_options * @return string */ - function radioTags ($tag_name, $options, $inbetween=null, $html_options=null) + function radioTags($tag_name, $options, $inbetween=null, $html_options=null) { $value = isset($html_options['value'])? $html_options['value']: $this->tagValue($tag_name); $out = array(); @@ -670,7 +702,7 @@ class Template extends Object * @param array $option_attr Array of HTML options for the enclosed OPTION elements * @return string Formatted SELECT element */ - function selectTag ($tag_name, $option_elements, $selected=null, $select_attr=null, $option_attr=null) + function selectTag($tag_name, $option_elements, $selected=null, $select_attr=null, $option_attr=null) { if (!is_array($option_elements) || !count($option_elements)) return null; @@ -701,7 +733,7 @@ class Template extends Object * @param array $html_options * @return string Formatted IMG tag */ - function imageTag ($path, $alt=null, $html_options=null) + function imageTag($path, $alt=null, $html_options=null) { $url = $this->base.IMAGES_URL.$path; return sprintf(TAG_IMAGE, $url, $alt, $this->parseHtmlOptions($html_options, null, '', ' ')); @@ -764,7 +796,7 @@ class Template extends Object * @param array $html_options * @return string Formatted LINK element. */ - function cssTag ($path, $rel='stylesheet', $html_options=null) + function cssTag($path, $rel='stylesheet', $html_options=null) { $url = "{$this->base}/".(COMPRESS_CSS? 'c': '')."css/{$path}.css"; return sprintf(TAG_CSS, $rel, $url, $this->parseHtmlOptions($html_options, null, '', ' ')); @@ -776,7 +808,7 @@ class Template extends Object * @param string $charset * @return string */ - function charsetTag ($charset) + function charsetTag($charset) { return sprintf(TAG_CHARSET, $charset); } @@ -787,7 +819,7 @@ class Template extends Object * @param string $script The JavaScript to be wrapped in SCRIPT tags. * @return string The full SCRIPT element, with the JavaScript inside it. */ - function javascriptTag ($script) + function javascriptTag($script) { return sprintf(TAG_JAVASCRIPT, $script); } @@ -798,7 +830,7 @@ class Template extends Object * @param string $url URL to JavaScript file. * @return string */ - function javascriptIncludeTag ($url) + function javascriptIncludeTag($url) { return sprintf(TAG_JAVASCRIPT_INCLUDE, $this->base.$url); } @@ -811,7 +843,7 @@ class Template extends Object * @param array $th_options * @return string */ - function tableHeaders ($names, $tr_options=null, $th_options=null) + function tableHeaders($names, $tr_options=null, $th_options=null) { $out = array(); foreach ($names as $arg) @@ -830,7 +862,7 @@ class Template extends Object * @param array $td_options HTML options for TD elements * @return string */ - function tableCells ($data, $odd_tr_options=null, $even_tr_options=null) + function tableCells($data, $odd_tr_options=null, $even_tr_options=null) { if (empty($data[0]) || !is_array($data[0])) { @@ -863,7 +895,7 @@ class Template extends Object * @param childrenKey $bodyKey * @return string */ - function guiListTree ($data, $htmlOptions=null, $bodyKey='body', $childrenKey='children') + function guiListTree($data, $htmlOptions=null, $bodyKey='body', $childrenKey='children') { $out = "parseHtmlOptions($htmlOptions).">\n"; @@ -887,7 +919,7 @@ class Template extends Object * @param string $name Text for link * @param string $link URL for link */ - function addCrumb ($name, $link) + function addCrumb($name, $link) { $this->_crumbs[] = array ($name, $link); } @@ -898,7 +930,7 @@ class Template extends Object * @param string $separator Text to separate crumbs. * @return string Formatted -separated list of breadcrumb links. Returns NULL if $this->_crumbs is empty. */ - function getCrumbs ($separator = '&raqo;') + function getCrumbs($separator = '»') { if (count($this->_crumbs)) @@ -918,6 +950,10 @@ class Template extends Object } } + + /////////////////////////////////////////////////////////////////////////// + + /** * Returns link to javascript function * @@ -935,7 +971,7 @@ class Template extends Object * @param array $html_options html options for link * @return string html code for link to javascript function */ - function linkToFunction ($title, $func, $html_options=null) + function linkToFunction($title, $func, $html_options=null) { $html_options['onClick'] = "$func; return false;"; return $this->linkTo($title, '#', $html_options); @@ -1003,7 +1039,7 @@ class Template extends Object * @param array $html_options options for link * @return string html code for link to remote action */ - function linkToRemote ($title, $options=null, $html_options=null) + function linkToRemote($title, $options=null, $html_options=null) { return $this->linkToFunction($title, $this->remoteFunction($options), $html_options); } @@ -1019,7 +1055,7 @@ class Template extends Object * @param array $options options for javascript * @return string html code for link to remote action */ - function remoteFunction ($options=null) + function remoteFunction($options=null) { $javascript_options = $this->__optionsForAjax($options); $func = isset($options['update']) @@ -1055,7 +1091,7 @@ class Template extends Object * @param string $javascript string that might have javascript elements * @return string escaped string */ - function escapeJavascript ($javascript) + function escapeJavascript($javascript) { $javascript = str_replace(array("\r\n","\n","\r"),'\n', $javascript); $javascript = str_replace(array('"', "'"), array('\"', "\\'"), $javascript); @@ -1072,7 +1108,7 @@ class Template extends Object * @param array $options callback options * @return string javascript code */ - function periodicallyCallRemote ($options=null) + function periodicallyCallRemote($options=null) { $frequency = (isset($options['frequency']))? $options['frequency'] : 10; $code = "new PeriodicalExecuter(function() {" . $this->remote_function($options) . "}, $frequency)"; @@ -1090,7 +1126,7 @@ class Template extends Object * @param array $options callback options * @return string javascript code */ - function formRemoteTag ($options=null) + function formRemoteTag($options=null) { $options['form'] = true; $options['html']['onsubmit']=$this->remoteFunction($options) . "; return false;"; @@ -1108,7 +1144,7 @@ class Template extends Object * @param array $options callback options * @return string ajaxed input button */ - function submitToRemote ($name, $value, $options = null) + function submitToRemote($name, $value, $options = null) { $options['with'] = 'Form.serialize(this.form)'; $options['html']['type'] = 'button'; @@ -1126,7 +1162,7 @@ class Template extends Object */ function defineJavascriptFunctions() { - return $this->javascriptIncludeTag('/js/vendors.php?file=prototype.js'); + return $this->javascriptIncludeTag(DS.'js'.DS.'vendors.php?file=prototype.js'); } /** @@ -1157,7 +1193,7 @@ class Template extends Object * @param array $options ajax options * @return string ajax script */ - function observeField ($field_id, $options = null) + function observeField($field_id, $options = null) { if (!isset($options['with'])) { @@ -1178,7 +1214,7 @@ class Template extends Object * @param array $options ajax options * @return string ajax script */ - function observeForm ($field_id, $options = null) + function observeForm($field_id, $options = null) { //i think this is a rails bug... should be set if (!isset($options['with'])) @@ -1194,7 +1230,7 @@ class Template extends Object * Javascript helper function (private). * */ - function __optionsForAjax ($options) + function __optionsForAjax($options) { $js_options = $this->__buildCallbacks($options); $js_options['asynchronous'] = 'true'; @@ -1234,12 +1270,12 @@ class Template extends Object } - function __methodOptionToString ($method) + function __methodOptionToString($method) { return (is_string($method) && !$method[0]=="'")? $method : "'$method'"; } - function __buildObserver ($klass, $name, $options=null) + function __buildObserver($klass, $name, $options=null) { if(!isset($options['with']) && isset($options['update'])) { diff --git a/libs/view.php b/libs/view.php new file mode 100644 index 000000000..f0393b455 --- /dev/null +++ b/libs/view.php @@ -0,0 +1,34 @@ + + // +// + Copyright: (c) 2005, Cake Authors/Developers + // +// + Author(s): Michal Tatarynowicz aka Pies + // +// + Larry E. Masters aka PhpNut + // +// + Kamil Dzielinski aka Brego + // +// +------------------------------------------------------------------+ // +// + Licensed under The MIT License + // +// + Redistributions of files must retain the above copyright notice. + // +// + See: http://www.opensource.org/licenses/mit-license.php + // +////////////////////////////////////////////////////////////////////////// + +/** + * Purpose: Dispatcher + * Dispatches the request, creating aproppriate models and controllers. + * + * @filesource + * @author Cake Authors/Developers + * @copyright Copyright (c) 2005, Cake Authors/Developers + * @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers + * @package cake + * @subpackage cake.libs + * @since Cake v 0.2.9 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + */ + + + +?> \ No newline at end of file diff --git a/public/index.php b/public/index.php index 604c23020..9e7888d9e 100644 --- a/public/index.php +++ b/public/index.php @@ -38,49 +38,51 @@ session_start(); * Get Cake's root directory */ if (!defined('DS')) - define ('DS', DIRECTORY_SEPARATOR); +{ + define('DS', DIRECTORY_SEPARATOR); +} if (!defined('ROOT')) - define ('ROOT', dirname(dirname(__FILE__)).DS); +{ + define('ROOT', dirname(dirname(__FILE__)).DS); +} if (strpos($url, 'ccss/') === 0) { - include(ROOT.'public'.DS.'css.php'); + include ROOT.'public'.DS.'css.php'; die; } /** - * Configuration, directory layout and standard libraries - */ -require_once (ROOT.'config/core.php'); -require_once (ROOT.'config/paths.php'); -require_once (ROOT.'libs/basics.php'); -require_once (ROOT.'libs/log.php'); -require_once (ROOT.'libs/object.php'); -require_once (ROOT.'libs/narray.php'); -require_once (ROOT.'libs/inflector.php'); + * Configuration, directory layout and standard libraries + */ +require_once ROOT.'config/core.php'; +require_once ROOT.'config/paths.php'; +require_once ROOT.'libs/basics.php'; +require_once ROOT.'libs/log.php'; +require_once ROOT.'libs/object.php'; +require_once ROOT.'libs/narray.php'; +require_once ROOT.'libs/inflector.php'; DEBUG? error_reporting(E_ALL): error_reporting(0); $TIME_START = getMicrotime(); -uses('folder'); -uses('dispatcher'); -uses('dbo_factory'); +uses('folder', 'dispatcher', 'dbo_factory'); -config ('tags', 'database'); +config('tags', 'database'); if (class_exists('DATABASE_CONFIG')) { $DB = DboFactory::make('devel'); - loadModels (); + loadModels(); } -## RUN THE SCRIPT +//RUN THE SCRIPT $DISPATCHER = new Dispatcher (); $DISPATCHER->dispatch($url); -## CLEANUP +//CLEANUP if (DEBUG) echo ""; ?> \ No newline at end of file diff --git a/tests/libs/controller.php b/tests/libs/controller.php index 64ca5365d..b930542a4 100644 --- a/tests/libs/controller.php +++ b/tests/libs/controller.php @@ -262,7 +262,7 @@ class ControllerTest extends UnitTestCase { $this->controller->addCrumb('Foo', '/bar/foo'); $result = $this->controller->getCrumbs(); - $expected = 'START » Foo'; + $expected = 'START»Foo'; $this->assertEqual($result, $expected); } } diff --git a/tests/libs/folder.php b/tests/libs/folder.php index 938604ad1..08692d565 100644 --- a/tests/libs/folder.php +++ b/tests/libs/folder.php @@ -19,16 +19,24 @@ class FolderTest extends UnitTestCase function setUp() { $this->testDir = ROOT.'tmp'.DS.'tests'; - - touch($this->testDir.DS.'.htaccess'); - if (!is_dir($this->testDir.DS.'dir1')) - mkdir($this->testDir.DS.'dir1'); - touch($this->testDir.DS.'dir1'.DS.'test1.php'); - if (!is_dir($this->testDir.DS.'dir2')) - mkdir($this->testDir.DS.'dir2'); + touch($this->testDir.DS.'.htaccess'); + chmod($this->testDir.DS.'.htaccess', 0777); + if (!is_dir($this->testDir.DS.'dir1')) + { + mkdir($this->testDir.DS.'dir1', 0777); + } + touch($this->testDir.DS.'dir1'.DS.'test1.php'); + chmod($this->testDir.DS.'dir1'.DS.'test1.php', 0777); + + if (!is_dir($this->testDir.DS.'dir2')) + { + mkdir($this->testDir.DS.'dir2', 0777); + } touch($this->testDir.DS.'dir2'.DS.'test2.php'); - + chmod($this->testDir.DS.'dir2'.DS.'test2.php', 0777); + + $this->folder = new Folder($this->testDir); } @@ -37,16 +45,13 @@ class FolderTest extends UnitTestCase // here function tearDown() { - unset($this->folder); - unlink($this->testDir.DS.'.htaccess'); unlink($this->testDir.DS.'dir1'.DS.'test1.php'); - if (is_dir($this->testDir.DS.'dir1')) - rmdir($this->testDir.DS.'dir1'); unlink($this->testDir.DS.'dir2'.DS.'test2.php'); - if (is_dir($this->testDir.DS.'dir2')) - rmdir($this->testDir.DS.'dir2'); - + + rmdir($this->testDir.DS.'dir1'); + rmdir($this->testDir.DS.'dir2'); + unset($this->folder); } @@ -55,8 +60,8 @@ class FolderTest extends UnitTestCase { $result = $this->folder->ls(); $expected = array ( - array('.svn', 'dir1', 'dir2'), - array('.htaccess') + array('.svn', 'dir1', 'dir2'), + array('.htaccess') ); $this->assertEqual($result, $expected, "List directories and files from test dir"); @@ -78,7 +83,7 @@ class FolderTest extends UnitTestCase //THIS ONE IS HACKED... why do i need to give a full path to this method? $this->folder->cd($this->testDir.DS.'dir1'); $result = $this->folder->pwd(); - + $this->assertEqual($result, Folder::addPathElement($this->testDir, 'dir1'), 'Change directory to dir1'); } @@ -86,7 +91,7 @@ class FolderTest extends UnitTestCase { $result = $this->folder->findRecursive('.*\.php'); $expected = array(Folder::addPathElement($this->folder->pwd().DS.'dir1', 'test1.php'), Folder::addPathElement($this->folder->pwd().DS.'dir2', 'test2.php')); - + $this->assertEqual($result, $expected, 'Find .php files'); }