From 55da45ec777890ef8658fed9dfe45e68d69ccb29 Mon Sep 17 00:00:00 2001 From: phpnut Date: Thu, 30 Jun 2005 02:09:47 +0000 Subject: [PATCH] setting proper mime-type on files in the trunk git-svn-id: https://svn.cakephp.org/repo/trunk/cake@292 3807eeeb-6ff5-0310-8944-8be069107fe0 --- app/app_controller.php | 48 +- app/app_model.php | 48 +- config/paths.php | 328 ++++++------ config/tags.php | 278 +++++------ libs/bake.php | 1050 +++++++++++++++++++-------------------- libs/cache.php | 298 +++++------ libs/error_messages.php | 222 ++++----- libs/flay.php | 640 ++++++++++++------------ libs/folder.php | 508 +++++++++---------- libs/inflector.php | 448 ++++++++--------- libs/legacy.php | 154 +++--- libs/router.php | 344 ++++++------- libs/validators.php | 104 ++-- public/css/default.css | 220 ++++---- 14 files changed, 2345 insertions(+), 2345 deletions(-) diff --git a/app/app_controller.php b/app/app_controller.php index 2b0da0a2a..7c568e252 100644 --- a/app/app_controller.php +++ b/app/app_controller.php @@ -1,25 +1,25 @@ - + // -// + Copyright: (c) 2005, Cake Authors/Developers + // -// +------------------------------------------------------------------+ // -// + Licensed under The MIT License + // -////////////////////////////////////////////////////////////////////////// - -/** - * This file is application-wide controller file. You can put all - * application-wide controller-related methods here. - * - * Add your application-wide methods in the class below, your controllers - * will inherit them. - * - * @package cake - * @subpackage cake.app - */ - -class AppController extends Controller { -} - + + // +// + Copyright: (c) 2005, Cake Authors/Developers + // +// +------------------------------------------------------------------+ // +// + Licensed under The MIT License + // +////////////////////////////////////////////////////////////////////////// + +/** + * This file is application-wide controller file. You can put all + * application-wide controller-related methods here. + * + * Add your application-wide methods in the class below, your controllers + * will inherit them. + * + * @package cake + * @subpackage cake.app + */ + +class AppController extends Controller { +} + ?> \ No newline at end of file diff --git a/app/app_model.php b/app/app_model.php index 1fab0c903..48c31eb81 100644 --- a/app/app_model.php +++ b/app/app_model.php @@ -1,25 +1,25 @@ - + // -// + Copyright: (c) 2005, Cake Authors/Developers + // -// +------------------------------------------------------------------+ // -// + Licensed under The MIT License + // -////////////////////////////////////////////////////////////////////////// - -/** - * This file is application-wide model file. You can put all - * application-wide model-related methods here. - * - * Add your application-wide methods in the class below, your models - * will inherit them. - * - * @package cake - * @subpackage cake.app - */ - -class AppModel extends Model { -} - + + // +// + Copyright: (c) 2005, Cake Authors/Developers + // +// +------------------------------------------------------------------+ // +// + Licensed under The MIT License + // +////////////////////////////////////////////////////////////////////////// + +/** + * This file is application-wide model file. You can put all + * application-wide model-related methods here. + * + * Add your application-wide methods in the class below, your models + * will inherit them. + * + * @package cake + * @subpackage cake.app + */ + +class AppModel extends Model { +} + ?> \ No newline at end of file diff --git a/config/paths.php b/config/paths.php index 7fecf40d9..0863f9d22 100644 --- a/config/paths.php +++ b/config/paths.php @@ -1,164 +1,164 @@ - + // -// + Copyright: (c) 2005, Cake Authors/Developers + // -// +------------------------------------------------------------------+ // -// + Licensed under The MIT License + // -////////////////////////////////////////////////////////////////////////// - -/** - * In this file you set paths to different directories used by Cake. - * - * @package cake - * @subpackage cake.config - */ - -/** - * If the index.php file is used instead of an .htaccess file - * or if the user can not set the web root to use the public - * directory we will define ROOT there, otherwise we set it - * here. - */ -if(!defined('ROOT')) -{ - define ('ROOT', '../'); -} - -/** - * Path to the application's directory. - */ -define ('APP', ROOT.'app'.DS); - -/** - * Path to the application's models directory. - */ -define ('MODELS', APP.'models'.DS); - -/** - * Path to the application's controllers directory. - */ -define ('CONTROLLERS', APP.'controllers'.DS); - -/** - * Path to the application's helpers directory. - */ -define ('HELPERS', APP.'helpers'.DS); - -/** - * Path to the application's views directory. - */ -define ('VIEWS', APP.'views'.DS); - -/** - * Path to the application's view's layouts directory. - */ -define ('LAYOUTS', APP.'views'.DS.'layouts'.DS); - -/** - * Path to the application's view's elements directory. - * It's supposed to hold pieces of PHP/HTML that are used on multiple pages - * and are not linked to a particular layout (like polls, footers and so on). - */ -define ('ELEMENTS', APP.'views'.DS.'elements'.DS); - -/** - * Path to the configuration files directory. - */ -define ('CONFIGS', ROOT.'config'.DS); - -/** - * Path to the libs directory. - */ -define ('LIBS', ROOT.'libs'.DS); - -/** - * Path to the logs directory. - */ -define ('LOGS', ROOT.'logs'.DS); - -/** - * Path to the modules directory. - */ -define ('MODULES', ROOT.'modules'.DS); - -/** - * Path to the public directory. - */ -define ('WWW_ROOT', ROOT.'public'.DS); - -/** - * Path to the public directory. - */ -define ('CSS', WWW_ROOT.'css'.DS); - -/** - * Path to the scripts direcotry. - */ -define('SCRIPTS', ROOT.'scripts'.DS); - -/** - * Path to the tests directory. - */ -define ('TESTS', ROOT.'tests'.DS); - -/** - * Path to the controller test directory. - */ -define ('CONTROLLER_TESTS',TESTS.'app'.DS.'controllers'.DS); - -/** - * Path to the helpers test directory. - */ -define ('HELPER_TESTS', TESTS.'app'.DS.'helpers'.DS); - -/** - * Path to the models' test directory. - */ -define ('MODEL_TESTS', TESTS.'app'.DS.'models'.DS); - -/** - * Path to the lib test directory. - */ -define ('LIB_TESTS', TESTS.'libs'.DS); - -/** - * Path to the temporary files directory. - */ -define ('TMP', ROOT.'tmp'.DS); - -/** - * Path to the cache files directory. It can be shared between hosts in a multi-server setup. - */ -define('CACHE', TMP.'cache'.DS); - -/** - * Path to the vendors directory. - */ -define ('VENDORS', ROOT.'vendors'.DS); - -/** - * Path to the Pear directory - * The purporse is to make it easy porting Pear libs into Cake - * without setting the include_path PHP variable. - */ -define ('PEAR', VENDORS.'Pear'.DS); - - -/** - * Full url prefix - */ -define('FULL_BASE_URL', 'http://'.$_SERVER['HTTP_HOST']); - -/** - * Web path to the public images directory. - */ -define ('IMAGES_URL', '/img/'); - -/** - * Web path to the CSS files directory. - */ -define ('CSS_URL', '/css/'); - -?> + + // +// + Copyright: (c) 2005, Cake Authors/Developers + // +// +------------------------------------------------------------------+ // +// + Licensed under The MIT License + // +////////////////////////////////////////////////////////////////////////// + +/** + * In this file you set paths to different directories used by Cake. + * + * @package cake + * @subpackage cake.config + */ + +/** + * If the index.php file is used instead of an .htaccess file + * or if the user can not set the web root to use the public + * directory we will define ROOT there, otherwise we set it + * here. + */ +if(!defined('ROOT')) +{ + define ('ROOT', '../'); +} + +/** + * Path to the application's directory. + */ +define ('APP', ROOT.'app'.DS); + +/** + * Path to the application's models directory. + */ +define ('MODELS', APP.'models'.DS); + +/** + * Path to the application's controllers directory. + */ +define ('CONTROLLERS', APP.'controllers'.DS); + +/** + * Path to the application's helpers directory. + */ +define ('HELPERS', APP.'helpers'.DS); + +/** + * Path to the application's views directory. + */ +define ('VIEWS', APP.'views'.DS); + +/** + * Path to the application's view's layouts directory. + */ +define ('LAYOUTS', APP.'views'.DS.'layouts'.DS); + +/** + * Path to the application's view's elements directory. + * It's supposed to hold pieces of PHP/HTML that are used on multiple pages + * and are not linked to a particular layout (like polls, footers and so on). + */ +define ('ELEMENTS', APP.'views'.DS.'elements'.DS); + +/** + * Path to the configuration files directory. + */ +define ('CONFIGS', ROOT.'config'.DS); + +/** + * Path to the libs directory. + */ +define ('LIBS', ROOT.'libs'.DS); + +/** + * Path to the logs directory. + */ +define ('LOGS', ROOT.'logs'.DS); + +/** + * Path to the modules directory. + */ +define ('MODULES', ROOT.'modules'.DS); + +/** + * Path to the public directory. + */ +define ('WWW_ROOT', ROOT.'public'.DS); + +/** + * Path to the public directory. + */ +define ('CSS', WWW_ROOT.'css'.DS); + +/** + * Path to the scripts direcotry. + */ +define('SCRIPTS', ROOT.'scripts'.DS); + +/** + * Path to the tests directory. + */ +define ('TESTS', ROOT.'tests'.DS); + +/** + * Path to the controller test directory. + */ +define ('CONTROLLER_TESTS',TESTS.'app'.DS.'controllers'.DS); + +/** + * Path to the helpers test directory. + */ +define ('HELPER_TESTS', TESTS.'app'.DS.'helpers'.DS); + +/** + * Path to the models' test directory. + */ +define ('MODEL_TESTS', TESTS.'app'.DS.'models'.DS); + +/** + * Path to the lib test directory. + */ +define ('LIB_TESTS', TESTS.'libs'.DS); + +/** + * Path to the temporary files directory. + */ +define ('TMP', ROOT.'tmp'.DS); + +/** + * Path to the cache files directory. It can be shared between hosts in a multi-server setup. + */ +define('CACHE', TMP.'cache'.DS); + +/** + * Path to the vendors directory. + */ +define ('VENDORS', ROOT.'vendors'.DS); + +/** + * Path to the Pear directory + * The purporse is to make it easy porting Pear libs into Cake + * without setting the include_path PHP variable. + */ +define ('PEAR', VENDORS.'Pear'.DS); + + +/** + * Full url prefix + */ +define('FULL_BASE_URL', 'http://'.$_SERVER['HTTP_HOST']); + +/** + * Web path to the public images directory. + */ +define ('IMAGES_URL', '/img/'); + +/** + * Web path to the CSS files directory. + */ +define ('CSS_URL', '/css/'); + +?> diff --git a/config/tags.php b/config/tags.php index 749bb7205..02d26463a 100644 --- a/config/tags.php +++ b/config/tags.php @@ -1,139 +1,139 @@ - + // -// + Copyright: (c) 2005, Cake Authors/Developers + // -// +------------------------------------------------------------------+ // -// + Licensed under The MIT License + // -////////////////////////////////////////////////////////////////////////// - -/** - * In this file, you can set up 'templates' for every tag generated by the tag - * generator. - * - * @package cake - * @subpackage cake.config - */ - -/** - * Tag template for a link. - */ -define('TAG_LINK', '%s'); - -/** - * Tag template for a mailto: link. - */ -define('TAG_MAILTO', '%s'); - -/** - * Tag template for opening form tag. - */ -define('TAG_FORM', '
'); - -/** - * Tag template for an input type='text' tag. - */ -define('TAG_INPUT', ''); - -/** - * Tag template for an input type='hidden' tag. - */ -define('TAG_HIDDEN', ''); - -/** - * Tag template for a textarea tag. - */ -define('TAG_AREA', ''); - -/** - * Tag template for a input type='checkbox ' tag. - */ -define('TAG_CHECKBOX', ''); - -/** - * Tag template for a input type='radio' tag. - */ -define('TAG_RADIOS', ''); - -/** - * Tag template for a select opening tag. - */ -define('TAG_SELECT_START', ''); - -/** - * Tag template for a password tag. - */ -define('TAG_PASSWORD', ''); - -/** - * Tag template for a file input tag. - */ -define('TAG_FILE', ''); - -/** - * Tag template for a submit button tag. - */ -define('TAG_SUBMIT', ''); - -/** - * Tag template for an image tag. - */ -define('TAG_IMAGE', '%s'); - -/** - * Tag template for a table header tag. - */ -define('TAG_TABLE_HEADER', '%s'); - -/** - * Tag template for table headers row tag. - */ -define('TAG_TABLE_HEADERS','%s'); - -/** - * Tag template for a table cell tag. - */ -define('TAG_TABLE_CELL', '%s'); - -/** - * Tag template for a table row tag. - */ -define('TAG_TABLE_ROW', '%s'); - -/** - * Tag template for a CSS link tag. - */ -define('TAG_CSS', ''); - -/** - * Tag template for a charset meta-tag. - */ -define('TAG_CHARSET', ''); - -/** - * Tag template for inline JavaScript. - */ -define('TAG_JAVASCRIPT', ''); - -/** - * Tag template for included JavaScript. - */ -define('TAG_JAVASCRIPT_INCLUDE', ''); - -?> + + // +// + Copyright: (c) 2005, Cake Authors/Developers + // +// +------------------------------------------------------------------+ // +// + Licensed under The MIT License + // +////////////////////////////////////////////////////////////////////////// + +/** + * In this file, you can set up 'templates' for every tag generated by the tag + * generator. + * + * @package cake + * @subpackage cake.config + */ + +/** + * Tag template for a link. + */ +define('TAG_LINK', '%s'); + +/** + * Tag template for a mailto: link. + */ +define('TAG_MAILTO', '%s'); + +/** + * Tag template for opening form tag. + */ +define('TAG_FORM', ''); + +/** + * Tag template for an input type='text' tag. + */ +define('TAG_INPUT', ''); + +/** + * Tag template for an input type='hidden' tag. + */ +define('TAG_HIDDEN', ''); + +/** + * Tag template for a textarea tag. + */ +define('TAG_AREA', ''); + +/** + * Tag template for a input type='checkbox ' tag. + */ +define('TAG_CHECKBOX', ''); + +/** + * Tag template for a input type='radio' tag. + */ +define('TAG_RADIOS', ''); + +/** + * Tag template for a select opening tag. + */ +define('TAG_SELECT_START', ''); + +/** + * Tag template for a password tag. + */ +define('TAG_PASSWORD', ''); + +/** + * Tag template for a file input tag. + */ +define('TAG_FILE', ''); + +/** + * Tag template for a submit button tag. + */ +define('TAG_SUBMIT', ''); + +/** + * Tag template for an image tag. + */ +define('TAG_IMAGE', '%s'); + +/** + * Tag template for a table header tag. + */ +define('TAG_TABLE_HEADER', '%s'); + +/** + * Tag template for table headers row tag. + */ +define('TAG_TABLE_HEADERS','%s'); + +/** + * Tag template for a table cell tag. + */ +define('TAG_TABLE_CELL', '%s'); + +/** + * Tag template for a table row tag. + */ +define('TAG_TABLE_ROW', '%s'); + +/** + * Tag template for a CSS link tag. + */ +define('TAG_CSS', ''); + +/** + * Tag template for a charset meta-tag. + */ +define('TAG_CHARSET', ''); + +/** + * Tag template for inline JavaScript. + */ +define('TAG_JAVASCRIPT', ''); + +/** + * Tag template for included JavaScript. + */ +define('TAG_JAVASCRIPT_INCLUDE', ''); + +?> diff --git a/libs/bake.php b/libs/bake.php index e7d05a04f..c8765046d 100644 --- a/libs/bake.php +++ b/libs/bake.php @@ -1,525 +1,525 @@ - + // -// + 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 + // -////////////////////////////////////////////////////////////////////////// - -/** - * Creates controller, model, view files, and the required directories on demand. - * Used by /scripts/bake.php. - * - * @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 - */ - -/** - * Require needed libraries. - */ -uses('object', 'inflector'); - -/** - * Bake class creates files in configured application directories. This is a - * base class for /scripts/add.php. - * - * @package cake - * @subpackage cake.libs - * @since Cake v 0.2.9 - */ -class Bake extends Object { - - /** - * Standard input stream (php://stdin). - * - * @var resource - * @access private - */ - var $stdin = null; - - /** - * Standard output stream (php://stdout). - * - * @var resource - * @access private - */ - var $stdout = null; - - /** - * Standard error stream (php://stderr). - * - * @var resource - * @access private - */ - var $stderr = null; - - /** - * Counts actions taken. - * - * @var integer - * @access private - */ - var $actions = null; - - /** - * Decides whether to overwrite existing files without asking. - * - * @var boolean - * @access private - */ - var $dontAsk = false; - - /** - * Returns code template for PHP file generator. - * - * @param string $type - * @return string - * @access private - */ - function template ($type) { - switch ($type) { - case 'view': return "%s"; - case 'model': return ""; - case 'action': return "\n\tfunction %s () {\n\t}\n"; - case 'ctrl': return ""; - case 'helper': return ""; - case 'test': return 'abc = new %s (); - } - - // called after the tests - function tearDown() { - unset($this->abc); - } - -/* - function testFoo () { - $result = $this->abc->Foo(); - $expected = \'\'; - $this->assertEquals($result, $expected); - } -*/ -} - -?>'; - default: - return false; - } - } - - - /** - * Baker's constructor method. Initialises bakery, and starts production. - * - * @param string $type - * @param array $names - * @access public - * @uses Bake::stdin Opens stream for reading. - * @uses Bake::stdout Opens stream for writing. - * @uses Bake::stderr Opens stream for writing. - * @uses Bake::newModel() Depending on the case, can create a new model. - * @uses Bake::newView() Depending on the case, can create a new view. - * @uses Bake::newController() Depending on the case, can create a new controller. - */ - function __construct ($type, $names) { - - $this->stdin = fopen('php://stdin', 'r'); - $this->stdout = fopen('php://stdout', 'w'); - $this->stderr = fopen('php://stderr', 'w'); - - // Output directory name - fwrite($this->stderr, "\n".substr(ROOT,0,strlen(ROOT)-1).":\n".str_repeat('-',strlen(ROOT)+1)."\n"); - - switch ($type) { - - case 'model': - case 'models': - foreach ($names as $model_name) - $this->newModel($model_name); - break; - - case 'controller': - case 'ctrl': - $controller = array_shift($names); - - $add_actions = array(); - foreach ($names as $action) { - $add_actions[] = $action; - $this->newView($controller, $action); - } - - $this->newController($controller, $add_actions); - break; - - case 'view': - case 'views': - $r = null; - foreach ($names as $model_name) { - if (preg_match('/^([a-z0-9_]+(?:\/[a-z0-9_]+)*)\/([a-z0-9_]+)$/i', $model_name, $r)) { - $this->newView($r[1], $r[2]); - } - } - break; - } - - if (!$this->actions) - fwrite($this->stderr, "Nothing to do, quitting.\n"); - - } - - /** - * Creates new view in VIEWS/$controller/ directory. - * - * @param string $controller - * @param string $name - * @access private - * @uses Inflector::underscore() Underscores directory's name. - * @uses Bake::createDir() Creates new directory in views dir, named after the controller. - * @uses VIEWS - * @uses Bake::createFile() Creates view file. - * @uses Bake::template() Collects view template. - * @uses Bake::actions Adds one action for each run. - */ - function newView ($controller, $name) { -// $controller = Inflector::pluralize($controller); - $dir = Inflector::underscore($controller); - $path = $dir.DS.strtolower($name).".thtml"; - $this->createDir(VIEWS.$dir); - $fn = VIEWS.$path; - $this->createFile($fn, sprintf($this->template('view'), "

Edit app".DS."views".DS."{$path} to change this message.

")); - $this->actions++; - } - - /** - * Creates new controller with defined actions, controller's test and helper - * with helper's test. - * - * @param string $name - * @param array $actions - * @access private - * @uses Inflector::pluralize() - * @uses Bake::makeController() - * @uses Bake::makeControllerTest() - * @uses Bake::makeHelper() - * @uses Bake::makeHelperTest() - * @uses Bake::actions Adds one action for each run. - */ - function newController ($name, $actions=array()) { -// $name = Inflector::pluralize($name); - $this->makeController($name, $actions); - $this->makeControllerTest($name); - $this->makeHelper($name); - $this->makeHelperTest($name); - $this->actions++; - } - - /** - * Creates new controller file with defined actions. - * - * @param string $name - * @param array $actions - * @return boolean - * @access private - * @uses Bake::makeControllerName() CamelCase for controller's name. - * @uses Bake::makeHelperName() CamelCase for helper's name. - * @uses Bake::template() Controller's template. - * @uses Bake::getActions() Actions' templates to be included in the controller. - * @uses Bake::createFile() Creates controller's file. - * @uses Bake::makeControllerFn() Underscored name for controller's filename. - */ - function makeController ($name, $actions) { - $ctrl = $this->makeControllerName($name); - $helper = $this->makeHelperName($name); - $body = sprintf($this->template('ctrl'), $ctrl, $helper, join('', $this->getActions($actions))); - return $this->createFile($this->makeControllerFn($name), $body); - } - - /** - * Returns controller's name in CamelCase. - * - * @param string $name - * @return string - * @access private - * @uses Inflector::camelize CamelCase for controller name. - */ - function makeControllerName ($name) { - return Inflector::camelize($name).'Controller'; - } - - /** - * Returns a name for controller's file, underscored. - * - * @param string $name - * @return string - * @access private - * @uses Inflector::underscore() Underscore for controller's file name. - */ - function makeControllerFn ($name) { - return CONTROLLERS.Inflector::underscore($name).'_controller.php'; - } - - /** - * Creates new test for a controller. - * - * @param string $name - * @return boolean - * @access private - * @uses CONTROLLER_TESTS - * @uses Inflector::underscore() - * @uses Bake::getTestBody() - * @uses Bake::makeControllerName() - * @uses Bake::createFile() - */ - function makeControllerTest ($name) { - $fn = CONTROLLER_TESTS.Inflector::underscore($name).'_controller_test.php'; - $body = $this->getTestBody($this->makeControllerName($name)); - return $this->createFile($fn, $body); - } - - /** - * Creates new helper. - * - * @param string $name - * @return boolean - * @access private - * @uses Bake::template() - * @uses Bake::makeHelperName() - * @uses Bake::createFile() - * @uses Bake::makeHelperFn() - */ - function makeHelper ($name) { - $body = sprintf($this->template('helper'), $this->makeHelperName($name)); - return $this->createFile($this->makeHelperFn($name), $body); - } - - /** - * Returns CamelCase name for a helper. - * - * @param string $name - * @return string - * @access private - * @uses Inflector::camelize() - */ - function makeHelperName ($name) { - return Inflector::camelize($name).'Helper'; - } - - /** - * Underscores file name for a helper. - * - * @param string $name - * @return string - * @access private - * @uses HELPERS - * @uses Inflector::underscore() - */ - function makeHelperFn ($name) { - return HELPERS.Inflector::underscore($name).'_helper.php'; - } - - /** - * Creates new test for a helper. - * - * @param string $name - * @return boolean - * @access private - * @uses HELPER_TESTS - * @uses Inflector::underscore() - * @uses Bake::getTestBody() - * @uses Bake::makeHelperName() - * @uses Bake::createFile() - */ - function makeHelperTest ($name) { - $fn = HELPER_TESTS.Inflector::underscore($name).'_helper_test.php'; - $body = $this->getTestBody($this->makeHelperName($name)); - return $this->createFile($fn, $body); - } - - /** - * Returns an array of actions' templates. - * - * @param array $as - * @return array - * @access private - * @uses Bake::template() - */ - function getActions ($as) { - $out = array(); - foreach ($as as $a) - $out[] = sprintf($this->template('action'), $a); - return $out; - } - - /** - * Returns a test template for given class. - * - * @param string $class - * @return string - * @access private - * @uses Bake::template() - */ - function getTestBody ($class) { - return sprintf($this->template('test'), $class, $class); - } - - /** - * Creates new model. - * - * @param string $name - * @access private - * @uses Bake::createFile() - * @uses Bake::getModelFn() - * @uses Bake::template() - * @uses Bake::getModelName() - * @uses Bake::makeModelTest() - * @uses Bake::actions - */ - function newModel ($name) { - $this->createFile($this->getModelFn($name), sprintf($this->template('model'), $this->getModelName($name))); - $this->makeModelTest ($name); - $this->actions++; - } - - /** - * Returns an underscored filename for a model. - * - * @param string $name - * @return string - * @access private - * @uses MODELS - * @uses Inflector::underscore() - */ - function getModelFn ($name) { - return MODELS.Inflector::underscore($name).'.php'; - } - - /** - * Creates a test for a given model. - * - * @param string $name - * @return boolean - * @access private - * @uses MODEL_TESTS - * @uses Inflector::underscore() - * @uses Bake::getTestBody() - * @uses Bake::getModelName() - * @uses Bake::createFile() - */ - function makeModelTest ($name) { - $fn = MODEL_TESTS.Inflector::underscore($name).'_test.php'; - $body = $this->getTestBody($this->getModelName($name)); - return $this->createFile($fn, $body); - } - - /** - * Returns CamelCased name of a model. - * - * @param string $name - * @return string - * @access private - * @uses Inflector::camelize() - */ - function getModelName ($name) { - return Inflector::camelize($name); - } - - /** - * Creates a file with given path and contents. - * - * @param string $path - * @param string $contents - * @return boolean - * @access private - * @uses Bake::dontAsk - * @uses Bake::stdin - * @uses Bake::stdout - * @uses Bake::stderr - */ - function createFile ($path, $contents) { - $shortPath = str_replace(ROOT,null,$path); - - if (is_file($path) && !$this->dontAsk) { - fwrite($this->stdout, "File {$shortPath} exists, overwrite? (yNaq) "); - $key = trim(fgets($this->stdin)); - - if ($key=='q') { - fwrite($this->stdout, "Quitting.\n"); - exit; - } - elseif ($key=='a') { - $this->dont_ask = true; - } - elseif ($key=='y') { - } - else { - fwrite($this->stdout, "Skip {$shortPath}\n"); - return false; - } - } - - if ($f = fopen($path, 'w')) { - fwrite($f, $contents); - fclose($f); - fwrite($this->stdout, "Wrote {$shortPath}\n"); -// debug ("Wrote {$path}"); - return true; - } - else { - fwrite($this->stderr, "Error! Couldn't open {$shortPath} for writing.\n"); -// debug ("Error! Couldn't open {$path} for writing."); - return false; - } - } - - /** - * Creates a directory with given path. - * - * @param string $path - * @return boolean - * @access private - * @uses Bake::stdin - * @uses Bake::stdout - */ - function createDir ($path) { - if (is_dir($path)) - return true; - - $shortPath = str_replace(ROOT, null, $path); - - if (mkdir($path)) { - fwrite($this->stdout, "Created {$shortPath}\n"); -// debug ("Created {$path}"); - return true; - } - else { - fwrite($this->stderr, "Error! Couldn't create dir {$shortPath}\n"); -// debug ("Error! Couldn't create dir {$path}"); - return false; - } - } - -} - -?> + + // +// + 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 + // +////////////////////////////////////////////////////////////////////////// + +/** + * Creates controller, model, view files, and the required directories on demand. + * Used by /scripts/bake.php. + * + * @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 + */ + +/** + * Require needed libraries. + */ +uses('object', 'inflector'); + +/** + * Bake class creates files in configured application directories. This is a + * base class for /scripts/add.php. + * + * @package cake + * @subpackage cake.libs + * @since Cake v 0.2.9 + */ +class Bake extends Object { + + /** + * Standard input stream (php://stdin). + * + * @var resource + * @access private + */ + var $stdin = null; + + /** + * Standard output stream (php://stdout). + * + * @var resource + * @access private + */ + var $stdout = null; + + /** + * Standard error stream (php://stderr). + * + * @var resource + * @access private + */ + var $stderr = null; + + /** + * Counts actions taken. + * + * @var integer + * @access private + */ + var $actions = null; + + /** + * Decides whether to overwrite existing files without asking. + * + * @var boolean + * @access private + */ + var $dontAsk = false; + + /** + * Returns code template for PHP file generator. + * + * @param string $type + * @return string + * @access private + */ + function template ($type) { + switch ($type) { + case 'view': return "%s"; + case 'model': return ""; + case 'action': return "\n\tfunction %s () {\n\t}\n"; + case 'ctrl': return ""; + case 'helper': return ""; + case 'test': return 'abc = new %s (); + } + + // called after the tests + function tearDown() { + unset($this->abc); + } + +/* + function testFoo () { + $result = $this->abc->Foo(); + $expected = \'\'; + $this->assertEquals($result, $expected); + } +*/ +} + +?>'; + default: + return false; + } + } + + + /** + * Baker's constructor method. Initialises bakery, and starts production. + * + * @param string $type + * @param array $names + * @access public + * @uses Bake::stdin Opens stream for reading. + * @uses Bake::stdout Opens stream for writing. + * @uses Bake::stderr Opens stream for writing. + * @uses Bake::newModel() Depending on the case, can create a new model. + * @uses Bake::newView() Depending on the case, can create a new view. + * @uses Bake::newController() Depending on the case, can create a new controller. + */ + function __construct ($type, $names) { + + $this->stdin = fopen('php://stdin', 'r'); + $this->stdout = fopen('php://stdout', 'w'); + $this->stderr = fopen('php://stderr', 'w'); + + // Output directory name + fwrite($this->stderr, "\n".substr(ROOT,0,strlen(ROOT)-1).":\n".str_repeat('-',strlen(ROOT)+1)."\n"); + + switch ($type) { + + case 'model': + case 'models': + foreach ($names as $model_name) + $this->newModel($model_name); + break; + + case 'controller': + case 'ctrl': + $controller = array_shift($names); + + $add_actions = array(); + foreach ($names as $action) { + $add_actions[] = $action; + $this->newView($controller, $action); + } + + $this->newController($controller, $add_actions); + break; + + case 'view': + case 'views': + $r = null; + foreach ($names as $model_name) { + if (preg_match('/^([a-z0-9_]+(?:\/[a-z0-9_]+)*)\/([a-z0-9_]+)$/i', $model_name, $r)) { + $this->newView($r[1], $r[2]); + } + } + break; + } + + if (!$this->actions) + fwrite($this->stderr, "Nothing to do, quitting.\n"); + + } + + /** + * Creates new view in VIEWS/$controller/ directory. + * + * @param string $controller + * @param string $name + * @access private + * @uses Inflector::underscore() Underscores directory's name. + * @uses Bake::createDir() Creates new directory in views dir, named after the controller. + * @uses VIEWS + * @uses Bake::createFile() Creates view file. + * @uses Bake::template() Collects view template. + * @uses Bake::actions Adds one action for each run. + */ + function newView ($controller, $name) { +// $controller = Inflector::pluralize($controller); + $dir = Inflector::underscore($controller); + $path = $dir.DS.strtolower($name).".thtml"; + $this->createDir(VIEWS.$dir); + $fn = VIEWS.$path; + $this->createFile($fn, sprintf($this->template('view'), "

Edit app".DS."views".DS."{$path} to change this message.

")); + $this->actions++; + } + + /** + * Creates new controller with defined actions, controller's test and helper + * with helper's test. + * + * @param string $name + * @param array $actions + * @access private + * @uses Inflector::pluralize() + * @uses Bake::makeController() + * @uses Bake::makeControllerTest() + * @uses Bake::makeHelper() + * @uses Bake::makeHelperTest() + * @uses Bake::actions Adds one action for each run. + */ + function newController ($name, $actions=array()) { +// $name = Inflector::pluralize($name); + $this->makeController($name, $actions); + $this->makeControllerTest($name); + $this->makeHelper($name); + $this->makeHelperTest($name); + $this->actions++; + } + + /** + * Creates new controller file with defined actions. + * + * @param string $name + * @param array $actions + * @return boolean + * @access private + * @uses Bake::makeControllerName() CamelCase for controller's name. + * @uses Bake::makeHelperName() CamelCase for helper's name. + * @uses Bake::template() Controller's template. + * @uses Bake::getActions() Actions' templates to be included in the controller. + * @uses Bake::createFile() Creates controller's file. + * @uses Bake::makeControllerFn() Underscored name for controller's filename. + */ + function makeController ($name, $actions) { + $ctrl = $this->makeControllerName($name); + $helper = $this->makeHelperName($name); + $body = sprintf($this->template('ctrl'), $ctrl, $helper, join('', $this->getActions($actions))); + return $this->createFile($this->makeControllerFn($name), $body); + } + + /** + * Returns controller's name in CamelCase. + * + * @param string $name + * @return string + * @access private + * @uses Inflector::camelize CamelCase for controller name. + */ + function makeControllerName ($name) { + return Inflector::camelize($name).'Controller'; + } + + /** + * Returns a name for controller's file, underscored. + * + * @param string $name + * @return string + * @access private + * @uses Inflector::underscore() Underscore for controller's file name. + */ + function makeControllerFn ($name) { + return CONTROLLERS.Inflector::underscore($name).'_controller.php'; + } + + /** + * Creates new test for a controller. + * + * @param string $name + * @return boolean + * @access private + * @uses CONTROLLER_TESTS + * @uses Inflector::underscore() + * @uses Bake::getTestBody() + * @uses Bake::makeControllerName() + * @uses Bake::createFile() + */ + function makeControllerTest ($name) { + $fn = CONTROLLER_TESTS.Inflector::underscore($name).'_controller_test.php'; + $body = $this->getTestBody($this->makeControllerName($name)); + return $this->createFile($fn, $body); + } + + /** + * Creates new helper. + * + * @param string $name + * @return boolean + * @access private + * @uses Bake::template() + * @uses Bake::makeHelperName() + * @uses Bake::createFile() + * @uses Bake::makeHelperFn() + */ + function makeHelper ($name) { + $body = sprintf($this->template('helper'), $this->makeHelperName($name)); + return $this->createFile($this->makeHelperFn($name), $body); + } + + /** + * Returns CamelCase name for a helper. + * + * @param string $name + * @return string + * @access private + * @uses Inflector::camelize() + */ + function makeHelperName ($name) { + return Inflector::camelize($name).'Helper'; + } + + /** + * Underscores file name for a helper. + * + * @param string $name + * @return string + * @access private + * @uses HELPERS + * @uses Inflector::underscore() + */ + function makeHelperFn ($name) { + return HELPERS.Inflector::underscore($name).'_helper.php'; + } + + /** + * Creates new test for a helper. + * + * @param string $name + * @return boolean + * @access private + * @uses HELPER_TESTS + * @uses Inflector::underscore() + * @uses Bake::getTestBody() + * @uses Bake::makeHelperName() + * @uses Bake::createFile() + */ + function makeHelperTest ($name) { + $fn = HELPER_TESTS.Inflector::underscore($name).'_helper_test.php'; + $body = $this->getTestBody($this->makeHelperName($name)); + return $this->createFile($fn, $body); + } + + /** + * Returns an array of actions' templates. + * + * @param array $as + * @return array + * @access private + * @uses Bake::template() + */ + function getActions ($as) { + $out = array(); + foreach ($as as $a) + $out[] = sprintf($this->template('action'), $a); + return $out; + } + + /** + * Returns a test template for given class. + * + * @param string $class + * @return string + * @access private + * @uses Bake::template() + */ + function getTestBody ($class) { + return sprintf($this->template('test'), $class, $class); + } + + /** + * Creates new model. + * + * @param string $name + * @access private + * @uses Bake::createFile() + * @uses Bake::getModelFn() + * @uses Bake::template() + * @uses Bake::getModelName() + * @uses Bake::makeModelTest() + * @uses Bake::actions + */ + function newModel ($name) { + $this->createFile($this->getModelFn($name), sprintf($this->template('model'), $this->getModelName($name))); + $this->makeModelTest ($name); + $this->actions++; + } + + /** + * Returns an underscored filename for a model. + * + * @param string $name + * @return string + * @access private + * @uses MODELS + * @uses Inflector::underscore() + */ + function getModelFn ($name) { + return MODELS.Inflector::underscore($name).'.php'; + } + + /** + * Creates a test for a given model. + * + * @param string $name + * @return boolean + * @access private + * @uses MODEL_TESTS + * @uses Inflector::underscore() + * @uses Bake::getTestBody() + * @uses Bake::getModelName() + * @uses Bake::createFile() + */ + function makeModelTest ($name) { + $fn = MODEL_TESTS.Inflector::underscore($name).'_test.php'; + $body = $this->getTestBody($this->getModelName($name)); + return $this->createFile($fn, $body); + } + + /** + * Returns CamelCased name of a model. + * + * @param string $name + * @return string + * @access private + * @uses Inflector::camelize() + */ + function getModelName ($name) { + return Inflector::camelize($name); + } + + /** + * Creates a file with given path and contents. + * + * @param string $path + * @param string $contents + * @return boolean + * @access private + * @uses Bake::dontAsk + * @uses Bake::stdin + * @uses Bake::stdout + * @uses Bake::stderr + */ + function createFile ($path, $contents) { + $shortPath = str_replace(ROOT,null,$path); + + if (is_file($path) && !$this->dontAsk) { + fwrite($this->stdout, "File {$shortPath} exists, overwrite? (yNaq) "); + $key = trim(fgets($this->stdin)); + + if ($key=='q') { + fwrite($this->stdout, "Quitting.\n"); + exit; + } + elseif ($key=='a') { + $this->dont_ask = true; + } + elseif ($key=='y') { + } + else { + fwrite($this->stdout, "Skip {$shortPath}\n"); + return false; + } + } + + if ($f = fopen($path, 'w')) { + fwrite($f, $contents); + fclose($f); + fwrite($this->stdout, "Wrote {$shortPath}\n"); +// debug ("Wrote {$path}"); + return true; + } + else { + fwrite($this->stderr, "Error! Couldn't open {$shortPath} for writing.\n"); +// debug ("Error! Couldn't open {$path} for writing."); + return false; + } + } + + /** + * Creates a directory with given path. + * + * @param string $path + * @return boolean + * @access private + * @uses Bake::stdin + * @uses Bake::stdout + */ + function createDir ($path) { + if (is_dir($path)) + return true; + + $shortPath = str_replace(ROOT, null, $path); + + if (mkdir($path)) { + fwrite($this->stdout, "Created {$shortPath}\n"); +// debug ("Created {$path}"); + return true; + } + else { + fwrite($this->stderr, "Error! Couldn't create dir {$shortPath}\n"); +// debug ("Error! Couldn't create dir {$path}"); + return false; + } + } + +} + +?> diff --git a/libs/cache.php b/libs/cache.php index a61e0866b..f4f4f0d15 100644 --- a/libs/cache.php +++ b/libs/cache.php @@ -1,150 +1,150 @@ - + // -// + 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: Cache - * Description: - * - * @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 - */ - -/** - * Enter description here... - * - */ -uses('model'); - -/** - * Enter description here... - * - * @package cake - * @subpackage cake.libs - * @since Cake v 0.2.9 - */ -class Cache extends Model { - -/** - * Identifier. Either an MD5 string or NULL. - * - * @var unknown_type - */ - var $id = null; - -/** - * Content container for cache data. - * - * @var unknown_type - */ - var $data = null; - -/** - * Content to be cached. - * - * @var unknown_type - */ - var $for_caching = null; - -/** - * Name of the database table used for caching. - * - * @var unknown_type - */ - var $use_table = 'cache'; - -/** - * Constructor. Generates an md5'ed id for internal use. Calls the constructor on Model as well. - * - * @param unknown_type $id - */ - function __construct ($id) { - $this->id = (md5($id)); - parent::__construct($this->id); - } - -/** - * Returns this object's id after setting it. If no $id is given then $this->id is returned. - * - * @param unknown_type $id - * @return unknown - */ - function id ($id=null) { - if (!$id) return $this->id; - return ($this->id = $id); - } - -/** - * Save $content in cache for $keep_for seconds. - * - * @param string $content Content to keep in cache. - * @param int $keep_for Number of seconds to keep data in cache. - * @return unknown - */ - function remember ($content, $keep_for=CACHE_PAGES_FOR) { - $data = addslashes($this->for_caching.$content); - $expire = date("Y-m-d H:i:s",time()+($keep_for>0? $keep_for: 999999999)); - return $this->query("REPLACE {$this->use_table} (id,data,expire) VALUES ('{$this->id}', '{$data}', '{$expire}')"); - } - -/** - * Returns content from the Cache object itself, if the Cache object has a non-empty data property. Else from the database cache. - * - * @return unknown - */ - function restore() { - if (empty($this->data['data'])) - return $this->find("id='{$this->id}' AND expire>NOW()"); - - return $this->data['data']; - } - -/** - * Returns true if the cache data property has current (non-stale) content for given id. - * - * @return boolean - */ - function has() { - return is_array($this->data = $this->find("id='{$this->id}' AND expire>NOW()")); - } - -/** - * Appends $string to the for_caching property of the Cache object. - * - * @param string $string - */ - function append($string) { - $this->for_caching .= $string; - } - -/** - * Clears the cache database table. - * - * @return unknown - */ - function clear() { - return $this->query("DELETE FROM {$this->use_table}"); - } -} - + + // +// + 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: Cache + * Description: + * + * @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 + */ + +/** + * Enter description here... + * + */ +uses('model'); + +/** + * Enter description here... + * + * @package cake + * @subpackage cake.libs + * @since Cake v 0.2.9 + */ +class Cache extends Model { + +/** + * Identifier. Either an MD5 string or NULL. + * + * @var unknown_type + */ + var $id = null; + +/** + * Content container for cache data. + * + * @var unknown_type + */ + var $data = null; + +/** + * Content to be cached. + * + * @var unknown_type + */ + var $for_caching = null; + +/** + * Name of the database table used for caching. + * + * @var unknown_type + */ + var $use_table = 'cache'; + +/** + * Constructor. Generates an md5'ed id for internal use. Calls the constructor on Model as well. + * + * @param unknown_type $id + */ + function __construct ($id) { + $this->id = (md5($id)); + parent::__construct($this->id); + } + +/** + * Returns this object's id after setting it. If no $id is given then $this->id is returned. + * + * @param unknown_type $id + * @return unknown + */ + function id ($id=null) { + if (!$id) return $this->id; + return ($this->id = $id); + } + +/** + * Save $content in cache for $keep_for seconds. + * + * @param string $content Content to keep in cache. + * @param int $keep_for Number of seconds to keep data in cache. + * @return unknown + */ + function remember ($content, $keep_for=CACHE_PAGES_FOR) { + $data = addslashes($this->for_caching.$content); + $expire = date("Y-m-d H:i:s",time()+($keep_for>0? $keep_for: 999999999)); + return $this->query("REPLACE {$this->use_table} (id,data,expire) VALUES ('{$this->id}', '{$data}', '{$expire}')"); + } + +/** + * Returns content from the Cache object itself, if the Cache object has a non-empty data property. Else from the database cache. + * + * @return unknown + */ + function restore() { + if (empty($this->data['data'])) + return $this->find("id='{$this->id}' AND expire>NOW()"); + + return $this->data['data']; + } + +/** + * Returns true if the cache data property has current (non-stale) content for given id. + * + * @return boolean + */ + function has() { + return is_array($this->data = $this->find("id='{$this->id}' AND expire>NOW()")); + } + +/** + * Appends $string to the for_caching property of the Cache object. + * + * @param string $string + */ + function append($string) { + $this->for_caching .= $string; + } + +/** + * Clears the cache database table. + * + * @return unknown + */ + function clear() { + return $this->query("DELETE FROM {$this->use_table}"); + } +} + ?> \ No newline at end of file diff --git a/libs/error_messages.php b/libs/error_messages.php index 0c83ef8a2..b9f857422 100644 --- a/libs/error_messages.php +++ b/libs/error_messages.php @@ -1,112 +1,112 @@ - + // -// + 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: Error Messages Defines - * - * @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 - */ - -/** - * Error string for when the specified database driver can not be found. - */ -define ('ERROR_UNKNOWN_DATABASE_DRIVER', '[DbFactory] Specified database driver (%s) not found'); - -/** - * Error string for when the dispatcher can not find a default controller. - */ -define ('ERROR_NO_CONTROLLER_SET', '[Dispatcher] No default controller, can\'t continue, check routes config'); - -/** - * Error string for when the dispatcher can not find a default action. - */ -define ('ERROR_NO_ACTION_SET', '[Dispatcher] No default action, can\'t continue, check routes config'); - -/** - * Error string for when the dispatcher can not find given controller. - */ -define ('ERROR_UNKNOWN_CONTROLLER', '[Dispatcher] Specified controller "%s" doesn\'t exist, create it first'); - -/** - * Error string for when the dispatcher can not find expected action in controller. - */ -define ('ERROR_NO_ACTION', '[Dispatcher] Action "%s" is not defined in the "%s" controller, create it first'); - -/** - * Error string for errors in view. - */ -define ('ERROR_IN_VIEW', '[Controller] Error in view "%s", got:
%s
'); - -/** - * Error string for when the controller can not find expected view. - */ -define ('ERROR_NO_VIEW', '[Controller] No template file for view "%s" (expected "%s"), create it first'); - -/** - * Error string for errors in layout. - */ -define ('ERROR_IN_LAYOUT', '[Controller] Error in layout "%s", got:
"%s"
'); - -/** - * Error string for when the controller can not find expected layout. - */ -define ('ERROR_NO_LAYOUT', '[Controller] Couln\'t find layout "%s" (expected "%s"), create it first'); - -/** - * Error string for database not being able to access the table list. - */ -define ('ERROR_NO_TABLE_LIST', '[Database] Couldn\'t get table list, check database config'); - -/** - * Error string for no corresponding database table found for model. - */ -define ('ERROR_NO_MODEL_TABLE', '[Model] No DB table for model "%s" (expected "%s"), create it first'); - -/** - * Error string for Field not present in table. - */ -define ('ERROR_NO_FIELD_IN_MODEL_DB', '[Model::set()] Field "%s" is not present in table "%s", check database schema'); - -/** - * Error string short short error message. - */ -define ('SHORT_ERROR_MESSAGE', '
%s
'); - -/** - * Error string for when original image can not be loaded. - */ -define ('ERROR_CANT_GET_ORIGINAL_IMAGE', '[Image] Couldn\'t load original image %s (tried from "%s")'); - -/** - * Error string for error 404. - */ -define ('ERROR_404', "The requested address /%s was not found on this server."); // second %s contains short error message - -/** - * Error string for error 500. - */ -define ('ERROR_500', "Application error, sorry."); - + + // +// + 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: Error Messages Defines + * + * @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 + */ + +/** + * Error string for when the specified database driver can not be found. + */ +define ('ERROR_UNKNOWN_DATABASE_DRIVER', '[DbFactory] Specified database driver (%s) not found'); + +/** + * Error string for when the dispatcher can not find a default controller. + */ +define ('ERROR_NO_CONTROLLER_SET', '[Dispatcher] No default controller, can\'t continue, check routes config'); + +/** + * Error string for when the dispatcher can not find a default action. + */ +define ('ERROR_NO_ACTION_SET', '[Dispatcher] No default action, can\'t continue, check routes config'); + +/** + * Error string for when the dispatcher can not find given controller. + */ +define ('ERROR_UNKNOWN_CONTROLLER', '[Dispatcher] Specified controller "%s" doesn\'t exist, create it first'); + +/** + * Error string for when the dispatcher can not find expected action in controller. + */ +define ('ERROR_NO_ACTION', '[Dispatcher] Action "%s" is not defined in the "%s" controller, create it first'); + +/** + * Error string for errors in view. + */ +define ('ERROR_IN_VIEW', '[Controller] Error in view "%s", got:
%s
'); + +/** + * Error string for when the controller can not find expected view. + */ +define ('ERROR_NO_VIEW', '[Controller] No template file for view "%s" (expected "%s"), create it first'); + +/** + * Error string for errors in layout. + */ +define ('ERROR_IN_LAYOUT', '[Controller] Error in layout "%s", got:
"%s"
'); + +/** + * Error string for when the controller can not find expected layout. + */ +define ('ERROR_NO_LAYOUT', '[Controller] Couln\'t find layout "%s" (expected "%s"), create it first'); + +/** + * Error string for database not being able to access the table list. + */ +define ('ERROR_NO_TABLE_LIST', '[Database] Couldn\'t get table list, check database config'); + +/** + * Error string for no corresponding database table found for model. + */ +define ('ERROR_NO_MODEL_TABLE', '[Model] No DB table for model "%s" (expected "%s"), create it first'); + +/** + * Error string for Field not present in table. + */ +define ('ERROR_NO_FIELD_IN_MODEL_DB', '[Model::set()] Field "%s" is not present in table "%s", check database schema'); + +/** + * Error string short short error message. + */ +define ('SHORT_ERROR_MESSAGE', '
%s
'); + +/** + * Error string for when original image can not be loaded. + */ +define ('ERROR_CANT_GET_ORIGINAL_IMAGE', '[Image] Couldn\'t load original image %s (tried from "%s")'); + +/** + * Error string for error 404. + */ +define ('ERROR_404', "The requested address /%s was not found on this server."); // second %s contains short error message + +/** + * Error string for error 500. + */ +define ('ERROR_500', "Application error, sorry."); + ?> \ No newline at end of file diff --git a/libs/flay.php b/libs/flay.php index 049db2bd2..d0caa2bf0 100644 --- a/libs/flay.php +++ b/libs/flay.php @@ -1,321 +1,321 @@ - + // -// + 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: Flay - * Text-to-html parser, similar to Textile or RedCloth, only with somehow different syntax. - * - * @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 - */ - -/** - * Enter description here... - */ -uses('object'); - -/** - * Text-to-html parser, similar to Textile or RedCloth, only with a little different syntax. - * - * @package cake - * @subpackage cake.libs - * @since Cake v 0.2.9 - */ - -class Flay extends Object -{ -/** - * Enter description here... - * - * @var string - */ - var $text = null; - -/** - * Enter description here... - * - * @var boolean - */ - var $allow_html = false; - -/** - * Constructor. - * - * @param unknown_type $text - */ - function __construct ($text=null) { - $this->text = $text; - parent::__construct(); - } - -/** - * Returns $text translated to HTML using the Flay syntax. - * - * @param string $text Text to format - * @param boolean $bare - * @param boolean $allowHtml Set this to trim whitespace and disable all HTML - * @return string Formatted text - */ - function toHtml ($text=null, $bare=false, $allowHtml=false) { - - if (empty($text) && empty($this->text)) - return false; - - $text = $text? $text: $this->text; - - // trim whitespace and disable all HTML - if ($allowHtml) - $text = trim($text); - else - $text = str_replace('<', '<', str_replace('>', '>', trim($text))); - - if (!$bare) { - // multi-paragraph functions - $text = preg_replace('#(?:[\n]{0,2})"""(.*)"""(?:[\n]{0,2})#s', "\n\n%BLOCKQUOTE%\n\n\\1\n\n%ENDBLOCKQUOTE%\n\n", $text); - $text = preg_replace('#(?:[\n]{0,2})===(.*)===(?:[\n]{0,2})#s', "\n\n%CENTER%\n\n\\1\n\n%ENDCENTER%\n\n", $text); - } - - // pre-parse newlines - $text = preg_replace("#\r\n#", "\n", $text); - $text = preg_replace("#[\n]{2,}#", "%PARAGRAPH%", $text); - $text = preg_replace('#[\n]{1}#', "%LINEBREAK%", $text); - - // split into paragraphs and parse - $out = ''; - foreach (split('%PARAGRAPH%', $text) as $line) { - - if ($line) { - - if (!$bare) { - // pre-parse links - $links = array(); - $regs = null; - if (preg_match_all('#\[([^\[]{4,})\]#', $line, $regs)) { - foreach ($regs[1] as $reg) { - $links[] = $reg; - $line = str_replace("[{$reg}]",'%LINK'.(count($links)-1).'%', $line); - } - } - - // MAIN TEXT FUNCTIONS - // bold - $line = ereg_replace("\*([^\*]*)\*", "\\1", $line); - // italic - $line = ereg_replace("_([^_]*)_", "\\1", $line); - } - - // entities - $line = str_replace(' - ', ' – ', $line); - $line = str_replace(' -- ', ' — ', $line); - $line = str_replace('(C)', '©', $line); - $line = str_replace('(R)', '®', $line); - $line = str_replace('(TM)', '™', $line); - - // guess e-mails - $emails = null; - if (preg_match_all("#([_A-Za-z0-9+-+]+(?:\.[_A-Za-z0-9+-]+)*@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*)#", $line, $emails)) { - foreach ($emails[1] as $email) { - $line = str_replace($email, "{$email}", $line); - } - } - - if (!$bare) { - // guess links - $urls = null; - if (preg_match_all("#((?:http|https|ftp|nntp)://[^ ]+)#", $line, $urls)) - { - foreach ($urls[1] as $url) - { - $line = str_replace($url, "{$url}", $line); - } - } - if (preg_match_all("#(www\.[^\n\%\ ]+[^\n\%\,\.\ ])#", $line, $urls)) - { - foreach ($urls[1] as $url) - { - $line = str_replace($url, "{$url}", $line); - } - } - - // re-parse links - if (count($links)) { - - for ($ii=0; $ii"; - } - elseif (preg_match('#^([^\]\ ]+)(?:\ ([^\]]+))?$#', $links[$ii], $regs)) - { - if (isset($regs[2])) - { - if (preg_match('#\.(jpg|jpeg|gif|png)$#', $regs[2])) - $body = "\"\""; - else - $body = $regs[2]; - - } - else - { - $body = $links[$ii]; - } - $with = "{$body}"; - } - else - { - $with = $prefix.$links[$ii]; - } - - $line = str_replace("%LINK{$ii}%", $with, $line); - } - } - } - - // re-parse newlines - $out .= str_replace('%LINEBREAK%', "
\n", "

{$line}

\n"); - } - } - - if (!$bare) { - // re-parse multilines - $out = str_replace('

%BLOCKQUOTE%

', "
", $out); - $out = str_replace('

%ENDBLOCKQUOTE%

', "
", $out); - $out = str_replace('

%CENTER%

', "
", $out); - $out = str_replace('

%ENDCENTER%

', "
", $out); - } - - return $out; - } - -/** - * Enter description here... - * - * @param unknown_type $string - * @return unknown - */ - function extractWords ($string) { - return preg_split('/[\s,\.:\/="!\(\)<>~\[\]]+/', $string); - } - -/** - * Enter description here... - * - * @param unknown_type $words - * @param unknown_type $string - * @param unknown_type $max_snippets - * @return unknown - */ - function markedSnippets ($words, $string, $max_snippets=5) { - - $string = strip_tags($string); - - $snips = array(); - $rest = $string; - foreach ($words as $word) { - if (preg_match_all("/[\s,]+.{0,40}{$word}.{0,40}[\s,]+/i", $rest, $r)) { - foreach ($r as $result) - $rest = str_replace($result, '', $rest); - $snips = array_merge($snips, $r[0]); - } - } - - if (count($snips) > $max_snippets) $snips = array_slice($snips, 0, $max_snippets); - $joined = join(' ... ', $snips); - $snips = $joined? "... {$joined} ...": substr($string, 0, 80).'...'; - - return Flay::colorMark($words, $snips); - } - -/** - * Enter description here... - * - * @param unknown_type $words - * @param unknown_type $string - * @return unknown - */ - function colorMark($words, $string) - { - $colors = array('yl','gr','rd','bl','fu','cy'); - - $nextColorIndex = 0; - foreach ($words as $word) - { - $string = preg_replace("/({$word})/i", '\\1", $string); - $nextColorIndex++; - } - - return $string; - } - -/** - * Enter description here... - * - * @param unknown_type $text - * @return unknown - */ - function toClean ($text) - { - return strip_tags(html_entity_decode($text, ENT_QUOTES)); - } - - function toParsedAndClean ($text) - { - return Flay::toClean(Flay::toHtml($text)); - } - -/** - * Enter description here... - * - * @param unknown_type $text - * @param unknown_type $length - * @param unknown_type $elipsis - * @return unknown - */ - function fragment ($text, $length, $elipsis='...') { - $soft=$length-5; - $hard=$length+5; - $rx = '/(.{'.$soft.','.$hard.'})[\s,\.:\/="!\(\)<>~\[\]]+.*/'; - if (preg_match($rx, $text, $r)) { - $out = $r[1]; - } - else { - $out = substr($text,0,$length); - } - - $out = $out.(strlen($out) + // +// + 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: Flay + * Text-to-html parser, similar to Textile or RedCloth, only with somehow different syntax. + * + * @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 + */ + +/** + * Enter description here... + */ +uses('object'); + +/** + * Text-to-html parser, similar to Textile or RedCloth, only with a little different syntax. + * + * @package cake + * @subpackage cake.libs + * @since Cake v 0.2.9 + */ + +class Flay extends Object +{ +/** + * Enter description here... + * + * @var string + */ + var $text = null; + +/** + * Enter description here... + * + * @var boolean + */ + var $allow_html = false; + +/** + * Constructor. + * + * @param unknown_type $text + */ + function __construct ($text=null) { + $this->text = $text; + parent::__construct(); + } + +/** + * Returns $text translated to HTML using the Flay syntax. + * + * @param string $text Text to format + * @param boolean $bare + * @param boolean $allowHtml Set this to trim whitespace and disable all HTML + * @return string Formatted text + */ + function toHtml ($text=null, $bare=false, $allowHtml=false) { + + if (empty($text) && empty($this->text)) + return false; + + $text = $text? $text: $this->text; + + // trim whitespace and disable all HTML + if ($allowHtml) + $text = trim($text); + else + $text = str_replace('<', '<', str_replace('>', '>', trim($text))); + + if (!$bare) { + // multi-paragraph functions + $text = preg_replace('#(?:[\n]{0,2})"""(.*)"""(?:[\n]{0,2})#s', "\n\n%BLOCKQUOTE%\n\n\\1\n\n%ENDBLOCKQUOTE%\n\n", $text); + $text = preg_replace('#(?:[\n]{0,2})===(.*)===(?:[\n]{0,2})#s', "\n\n%CENTER%\n\n\\1\n\n%ENDCENTER%\n\n", $text); + } + + // pre-parse newlines + $text = preg_replace("#\r\n#", "\n", $text); + $text = preg_replace("#[\n]{2,}#", "%PARAGRAPH%", $text); + $text = preg_replace('#[\n]{1}#', "%LINEBREAK%", $text); + + // split into paragraphs and parse + $out = ''; + foreach (split('%PARAGRAPH%', $text) as $line) { + + if ($line) { + + if (!$bare) { + // pre-parse links + $links = array(); + $regs = null; + if (preg_match_all('#\[([^\[]{4,})\]#', $line, $regs)) { + foreach ($regs[1] as $reg) { + $links[] = $reg; + $line = str_replace("[{$reg}]",'%LINK'.(count($links)-1).'%', $line); + } + } + + // MAIN TEXT FUNCTIONS + // bold + $line = ereg_replace("\*([^\*]*)\*", "\\1", $line); + // italic + $line = ereg_replace("_([^_]*)_", "\\1", $line); + } + + // entities + $line = str_replace(' - ', ' – ', $line); + $line = str_replace(' -- ', ' — ', $line); + $line = str_replace('(C)', '©', $line); + $line = str_replace('(R)', '®', $line); + $line = str_replace('(TM)', '™', $line); + + // guess e-mails + $emails = null; + if (preg_match_all("#([_A-Za-z0-9+-+]+(?:\.[_A-Za-z0-9+-]+)*@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*)#", $line, $emails)) { + foreach ($emails[1] as $email) { + $line = str_replace($email, "{$email}", $line); + } + } + + if (!$bare) { + // guess links + $urls = null; + if (preg_match_all("#((?:http|https|ftp|nntp)://[^ ]+)#", $line, $urls)) + { + foreach ($urls[1] as $url) + { + $line = str_replace($url, "{$url}", $line); + } + } + if (preg_match_all("#(www\.[^\n\%\ ]+[^\n\%\,\.\ ])#", $line, $urls)) + { + foreach ($urls[1] as $url) + { + $line = str_replace($url, "{$url}", $line); + } + } + + // re-parse links + if (count($links)) { + + for ($ii=0; $ii"; + } + elseif (preg_match('#^([^\]\ ]+)(?:\ ([^\]]+))?$#', $links[$ii], $regs)) + { + if (isset($regs[2])) + { + if (preg_match('#\.(jpg|jpeg|gif|png)$#', $regs[2])) + $body = "\"\""; + else + $body = $regs[2]; + + } + else + { + $body = $links[$ii]; + } + $with = "{$body}"; + } + else + { + $with = $prefix.$links[$ii]; + } + + $line = str_replace("%LINK{$ii}%", $with, $line); + } + } + } + + // re-parse newlines + $out .= str_replace('%LINEBREAK%', "
\n", "

{$line}

\n"); + } + } + + if (!$bare) { + // re-parse multilines + $out = str_replace('

%BLOCKQUOTE%

', "
", $out); + $out = str_replace('

%ENDBLOCKQUOTE%

', "
", $out); + $out = str_replace('

%CENTER%

', "
", $out); + $out = str_replace('

%ENDCENTER%

', "
", $out); + } + + return $out; + } + +/** + * Enter description here... + * + * @param unknown_type $string + * @return unknown + */ + function extractWords ($string) { + return preg_split('/[\s,\.:\/="!\(\)<>~\[\]]+/', $string); + } + +/** + * Enter description here... + * + * @param unknown_type $words + * @param unknown_type $string + * @param unknown_type $max_snippets + * @return unknown + */ + function markedSnippets ($words, $string, $max_snippets=5) { + + $string = strip_tags($string); + + $snips = array(); + $rest = $string; + foreach ($words as $word) { + if (preg_match_all("/[\s,]+.{0,40}{$word}.{0,40}[\s,]+/i", $rest, $r)) { + foreach ($r as $result) + $rest = str_replace($result, '', $rest); + $snips = array_merge($snips, $r[0]); + } + } + + if (count($snips) > $max_snippets) $snips = array_slice($snips, 0, $max_snippets); + $joined = join(' ... ', $snips); + $snips = $joined? "... {$joined} ...": substr($string, 0, 80).'...'; + + return Flay::colorMark($words, $snips); + } + +/** + * Enter description here... + * + * @param unknown_type $words + * @param unknown_type $string + * @return unknown + */ + function colorMark($words, $string) + { + $colors = array('yl','gr','rd','bl','fu','cy'); + + $nextColorIndex = 0; + foreach ($words as $word) + { + $string = preg_replace("/({$word})/i", '\\1", $string); + $nextColorIndex++; + } + + return $string; + } + +/** + * Enter description here... + * + * @param unknown_type $text + * @return unknown + */ + function toClean ($text) + { + return strip_tags(html_entity_decode($text, ENT_QUOTES)); + } + + function toParsedAndClean ($text) + { + return Flay::toClean(Flay::toHtml($text)); + } + +/** + * Enter description here... + * + * @param unknown_type $text + * @param unknown_type $length + * @param unknown_type $elipsis + * @return unknown + */ + function fragment ($text, $length, $elipsis='...') { + $soft=$length-5; + $hard=$length+5; + $rx = '/(.{'.$soft.','.$hard.'})[\s,\.:\/="!\(\)<>~\[\]]+.*/'; + if (preg_match($rx, $text, $r)) { + $out = $r[1]; + } + else { + $out = substr($text,0,$length); + } + + $out = $out.(strlen($out) \ No newline at end of file diff --git a/libs/folder.php b/libs/folder.php index 78aca4203..d020f6e1d 100644 --- a/libs/folder.php +++ b/libs/folder.php @@ -1,255 +1,255 @@ - + // -// + 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: Folder - * Folder structure browser, lists folders and files. - * - * @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('object'); - -/** - * Folder structure browser, lists folders and files. - * - * @package cake - * @subpackage cake.libs - * @since Cake v 0.2.9 - */ -class Folder extends Object { - -/** - * Enter description here... - * - * @var string - */ - var $path = null; - -/** - * Enter description here... - * - * @var boolean - */ - var $sort = false; - -/** - * Constructor. - * - * @param string $path - */ - function __construct ($path=false) { - if (empty($path)) $path = getcwd(); - $this->cd($path); - } - -/** - * Return current path. - * - * @return string Current path - */ - function pwd () { - return $this->path; - } - -/** - * Change directory to $desired_path. - * - * @param string $desired_path Path to the directory to change to - * @return string The new path. Returns false on failure - */ - function cd ($desired_path) { - $desired_path = realpath($desired_path); - $new_path = Folder::isAbsolute($desired_path)? - $desired_path: - Folder::addPathElement($this->path, $desired_path); - - return is_dir($new_path)? $this->path = $new_path: false; - } - - -/** - * Returns an array of the contents of the current directory, or false on failure. - * The returned array holds two arrays: one of dirs and one of files. - * - * @param boolean $sort - * @return array - */ - function ls($sort=true) { - $dir = opendir($this->path); - - if ($dir) { - $dirs = $files = array(); - while (false !== ($n = readdir($dir))) { - if (!preg_match('#^\.+$#', $n)) { - if (is_dir($this->addPathElement($this->path, $n))) - $dirs[] = $n; - else - $files[] = $n; - } - } - - if ($sort || $this->sort) { - sort($dirs); - sort($files); - } - - return array($dirs,$files); - } - else { - return false; - } - } - - -/** - * Returns an array of all matching files in current directory - * - * @param string $pattern Preg_match pattern (Defaults to: .*) - * @return array - */ - function find ($regexp_pattern='.*') - { - $data = $this->ls(); - - if (!is_array($data)) - return array(); - - list($dirs, $files) = $data; - - $found = array(); - foreach ($files as $file) - { - if (preg_match("/^{$regexp_pattern}$/i", $file)) - { - $found[] = $file; - } - } - - return $found; - } - - -/** - * Returns an array of all matching files in and below current directory - * - * @param string $pattern Preg_match pattern (Defaults to: .*) - * @return array Files matching $pattern - */ - function findRecursive ($pattern='.*') { - $starts_on = $this->path; - $out = $this->_findRecursive($pattern); - $this->cd($starts_on); - return $out; - } - -/** - * Private helper function for findRecursive. - * - * @param string $pattern - * @return array Files matching pattern - */ - function _findRecursive ($pattern) { - list($dirs, $files) = $this->ls(); - - $found = array(); - foreach ($files as $file) { - if (preg_match("/^{$pattern}$/i", $file)) { - $found[] = $this->addPathElement($this->path, $file); - } - } - - $start = $this->path; - foreach ($dirs as $dir) { - $this->cd($this->addPathElement($start, $dir)); - $found = array_merge($found, $this->findRecursive($pattern)); - } - - return $found; - } - -/** - * Returns true if given $path is a Windows path. - * - * @param string $path Path to check - * @return boolean - */ - function isWindowsPath ($path) { - return preg_match('#^[A-Z]:\\\#i', $path)? true: false; - } - -/** - * Returns true if given $path is an absolute path. - * - * @param string $path Path to check - * @return boolean - */ - function isAbsolute ($path) { - return preg_match('#^\/#', $path) || preg_match('#^[A-Z]:\\\#i', $path); - } - -/** - * Returns true if given $path ends in a slash (i.e. is slash-terminated). - * - * @param string $path Path to check - * @return boolean - */ - function isSlashTerm ($path) { - return preg_match('#[\\\/]$#', $path)? true: false; - } - -/** - * Returns a correct set of slashes for given $path. (\\ for Windows paths and / for other paths.) - * - * @param string $path Path to check - * @return string Set of slashes ("\\" or "/") - */ - function correctSlashFor ($path) { - return Folder::isWindowsPath($path)? '\\': '/'; - } - -/** - * Returns $path with added terminating slash (corrected for Windows or other OS). - * - * @param string $path Path to check - * @return string - */ - function slashTerm ($path) { - return $path . (Folder::isSlashTerm($path)? null: Folder::correctSlashFor($path)); - } - -/** - * Returns $path with $element added, with correct slash in-between. - * - * @param string $path - * @param string $element - * @return string - */ - function addPathElement ($path, $element) { - return Folder::slashTerm($path).$element; - } -} - + + // +// + 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: Folder + * Folder structure browser, lists folders and files. + * + * @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('object'); + +/** + * Folder structure browser, lists folders and files. + * + * @package cake + * @subpackage cake.libs + * @since Cake v 0.2.9 + */ +class Folder extends Object { + +/** + * Enter description here... + * + * @var string + */ + var $path = null; + +/** + * Enter description here... + * + * @var boolean + */ + var $sort = false; + +/** + * Constructor. + * + * @param string $path + */ + function __construct ($path=false) { + if (empty($path)) $path = getcwd(); + $this->cd($path); + } + +/** + * Return current path. + * + * @return string Current path + */ + function pwd () { + return $this->path; + } + +/** + * Change directory to $desired_path. + * + * @param string $desired_path Path to the directory to change to + * @return string The new path. Returns false on failure + */ + function cd ($desired_path) { + $desired_path = realpath($desired_path); + $new_path = Folder::isAbsolute($desired_path)? + $desired_path: + Folder::addPathElement($this->path, $desired_path); + + return is_dir($new_path)? $this->path = $new_path: false; + } + + +/** + * Returns an array of the contents of the current directory, or false on failure. + * The returned array holds two arrays: one of dirs and one of files. + * + * @param boolean $sort + * @return array + */ + function ls($sort=true) { + $dir = opendir($this->path); + + if ($dir) { + $dirs = $files = array(); + while (false !== ($n = readdir($dir))) { + if (!preg_match('#^\.+$#', $n)) { + if (is_dir($this->addPathElement($this->path, $n))) + $dirs[] = $n; + else + $files[] = $n; + } + } + + if ($sort || $this->sort) { + sort($dirs); + sort($files); + } + + return array($dirs,$files); + } + else { + return false; + } + } + + +/** + * Returns an array of all matching files in current directory + * + * @param string $pattern Preg_match pattern (Defaults to: .*) + * @return array + */ + function find ($regexp_pattern='.*') + { + $data = $this->ls(); + + if (!is_array($data)) + return array(); + + list($dirs, $files) = $data; + + $found = array(); + foreach ($files as $file) + { + if (preg_match("/^{$regexp_pattern}$/i", $file)) + { + $found[] = $file; + } + } + + return $found; + } + + +/** + * Returns an array of all matching files in and below current directory + * + * @param string $pattern Preg_match pattern (Defaults to: .*) + * @return array Files matching $pattern + */ + function findRecursive ($pattern='.*') { + $starts_on = $this->path; + $out = $this->_findRecursive($pattern); + $this->cd($starts_on); + return $out; + } + +/** + * Private helper function for findRecursive. + * + * @param string $pattern + * @return array Files matching pattern + */ + function _findRecursive ($pattern) { + list($dirs, $files) = $this->ls(); + + $found = array(); + foreach ($files as $file) { + if (preg_match("/^{$pattern}$/i", $file)) { + $found[] = $this->addPathElement($this->path, $file); + } + } + + $start = $this->path; + foreach ($dirs as $dir) { + $this->cd($this->addPathElement($start, $dir)); + $found = array_merge($found, $this->findRecursive($pattern)); + } + + return $found; + } + +/** + * Returns true if given $path is a Windows path. + * + * @param string $path Path to check + * @return boolean + */ + function isWindowsPath ($path) { + return preg_match('#^[A-Z]:\\\#i', $path)? true: false; + } + +/** + * Returns true if given $path is an absolute path. + * + * @param string $path Path to check + * @return boolean + */ + function isAbsolute ($path) { + return preg_match('#^\/#', $path) || preg_match('#^[A-Z]:\\\#i', $path); + } + +/** + * Returns true if given $path ends in a slash (i.e. is slash-terminated). + * + * @param string $path Path to check + * @return boolean + */ + function isSlashTerm ($path) { + return preg_match('#[\\\/]$#', $path)? true: false; + } + +/** + * Returns a correct set of slashes for given $path. (\\ for Windows paths and / for other paths.) + * + * @param string $path Path to check + * @return string Set of slashes ("\\" or "/") + */ + function correctSlashFor ($path) { + return Folder::isWindowsPath($path)? '\\': '/'; + } + +/** + * Returns $path with added terminating slash (corrected for Windows or other OS). + * + * @param string $path Path to check + * @return string + */ + function slashTerm ($path) { + return $path . (Folder::isSlashTerm($path)? null: Folder::correctSlashFor($path)); + } + +/** + * Returns $path with $element added, with correct slash in-between. + * + * @param string $path + * @param string $element + * @return string + */ + function addPathElement ($path, $element) { + return Folder::slashTerm($path).$element; + } +} + ?> \ No newline at end of file diff --git a/libs/inflector.php b/libs/inflector.php index 3af4d0ced..f43b80b30 100644 --- a/libs/inflector.php +++ b/libs/inflector.php @@ -1,224 +1,224 @@ - + // -// + 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: Inflector - * I'm trying to port RoR Inflector class here. - * Inflector pluralizes and singularizes English nouns. - * Test with $i = new Inflector(); $i->test(); - * - * @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 - */ - -/** - * This is a port of Ruby on Rails' Inflector class. - * Inflector pluralizes and singularizes English nouns. - * Test with $i = new Inflector(); $i->test(); - * - * @package cake - * @subpackage cake.libs - * @since Cake v 0.2.9 - */ -class Inflector extends Object -{ - -/** - * Constructor. - * - */ - function __construct () { - parent::__construct(); - } - -/** - * Return $word in plural form. - * - * @param string $word Word in singular - * @return string Word in plural - */ - function pluralize ($word) { - $plural_rules = array( - '/(x|ch|ss|sh)$/' => '\1es', # search, switch, fix, box, process, address - '/series$/' => '\1series', - '/([^aeiouy]|qu)ies$/' => '\1y', - '/([^aeiouy]|qu)y$/' => '\1ies', # query, ability, agency - '/(?:([^f])fe|([lr])f)$/' => '\1\2ves', # half, safe, wife - '/sis$/' => 'ses', # basis, diagnosis - '/([ti])um$/' => '\1a', # datum, medium - '/person$/' => 'people', # person, salesperson - '/man$/' => 'men', # man, woman, spokesman - '/child$/' => 'children', # child - '/s$/' => 's', # no change (compatibility) - '/$/' => 's' - ); - - foreach ($plural_rules as $rule => $replacement) { - if (preg_match($rule, $word)) { - return preg_replace($rule, $replacement, $word); - } - } - - return false; - } - -/** - * Return $word in singular form. - * - * @param string $word Word in plural - * @return string Word in singular - */ - function singularize ($word) { - $singular_rules = array( - '/(x|ch|ss)es$/' => '\1', - '/movies$/' => 'movie', - '/series$/' => 'series', - '/([^aeiouy]|qu)ies$/' => '\1y', - '/([lr])ves$/' => '\1f', - '/([^f])ves$/' => '\1fe', - '/(analy|ba|diagno|parenthe|progno|synop|the)ses$/' => '\1sis', - '/([ti])a$/' => '\1um', - '/people$/' => 'person', - '/men$/' => 'man', - '/status$/' => 'status', - '/children$/' => 'child', - '/news$/' => 'news', - '/s$/' => '' - ); - - foreach ($singular_rules as $rule => $replacement) { - if (preg_match($rule, $word)) { - return preg_replace($rule, $replacement, $word); - } - } - - return false; - } - -/** - * Returns given $lower_case_and_underscored_word as a camelCased word. - * - * @param string $lower_case_and_underscored_word Word to camelize - * @return string Camelized word. likeThis. - */ - function camelize($lower_case_and_underscored_word) { - return str_replace(" ","",ucwords(str_replace("_"," ",$lower_case_and_underscored_word))); - } - -/** - * Returns an underscore-syntaxed ($like_this_dear_reader) version of the $camel_cased_word. - * - * @param string $camel_cased_word Camel-cased word to be "underscorized" - * @return string Underscore-syntaxed version of the $camel_cased_word - */ - function underscore($camel_cased_word) { - $camel_cased_word = preg_replace('/([A-Z]+)([A-Z])/','\1_\2',$camel_cased_word); - return strtolower(preg_replace('/([a-z])([A-Z])/','\1_\2',$camel_cased_word)); - } - -/** - * Returns a human-readable string from $lower_case_and_underscored_word, - * by replacing underscores with a space, and by upper-casing the initial characters. - * - * @param string $lower_case_and_underscored_word String to be made more readable - * @return string Human-readable string - */ - function humanize($lower_case_and_underscored_word) { - return ucwords(str_replace("_"," ",$lower_case_and_underscored_word)); - } - -/** - * Returns corresponding table name for given $class_name. - * - * @param string $class_name Name of class to get database table name for - * @return string Name of the database table for given class - */ - function tableize($class_name) { - return Inflector::pluralize(Inflector::underscore($class_name)); - } - -/** - * Returns Cake class name ("Post" for the database table "posts".) for given database table. - * - * @param string $table_name Name of database table to get class name for - * @return string - */ - function classify($table_name) - { - return Inflector::camelize(Inflector::singularize($table_name)); - } - -/** - * Returns $class_name in underscored form, with "_id" tacked on at the end. - * This is for use in dealing with the database. - * - * @param string $class_name - * @return string - */ - function foreignKey($class_name) - { - return Inflector::underscore($class_name) . "_id"; - } - - function toControllerFilename($name) - { - return CONTROLLERS.Inflector::underscore($name).'.php'; - } - - function toHelperFilename($name) - { - return HELPERS.Inflector::underscore($name).'.php'; - } - - function toFullName($name, $correct) - { - if (strstr($name, '_') && (strtolower($name) == $name)) - { - return Inflector::camelize($name); - } - - if (preg_match("/^(.*)({$correct})$/i", $name, $reg)) - { - if ($reg[2] == $correct) - { - return $name; - } - else - { - return ucfirst($reg[1].$correct); - } - } - else - { - return ucfirst($name.$correct); - } - } - - function toLibraryFilename ($name) - { - return LIBS.Inflector::underscore($name).'.php'; - } -} - -?> + + // +// + 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: Inflector + * I'm trying to port RoR Inflector class here. + * Inflector pluralizes and singularizes English nouns. + * Test with $i = new Inflector(); $i->test(); + * + * @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 + */ + +/** + * This is a port of Ruby on Rails' Inflector class. + * Inflector pluralizes and singularizes English nouns. + * Test with $i = new Inflector(); $i->test(); + * + * @package cake + * @subpackage cake.libs + * @since Cake v 0.2.9 + */ +class Inflector extends Object +{ + +/** + * Constructor. + * + */ + function __construct () { + parent::__construct(); + } + +/** + * Return $word in plural form. + * + * @param string $word Word in singular + * @return string Word in plural + */ + function pluralize ($word) { + $plural_rules = array( + '/(x|ch|ss|sh)$/' => '\1es', # search, switch, fix, box, process, address + '/series$/' => '\1series', + '/([^aeiouy]|qu)ies$/' => '\1y', + '/([^aeiouy]|qu)y$/' => '\1ies', # query, ability, agency + '/(?:([^f])fe|([lr])f)$/' => '\1\2ves', # half, safe, wife + '/sis$/' => 'ses', # basis, diagnosis + '/([ti])um$/' => '\1a', # datum, medium + '/person$/' => 'people', # person, salesperson + '/man$/' => 'men', # man, woman, spokesman + '/child$/' => 'children', # child + '/s$/' => 's', # no change (compatibility) + '/$/' => 's' + ); + + foreach ($plural_rules as $rule => $replacement) { + if (preg_match($rule, $word)) { + return preg_replace($rule, $replacement, $word); + } + } + + return false; + } + +/** + * Return $word in singular form. + * + * @param string $word Word in plural + * @return string Word in singular + */ + function singularize ($word) { + $singular_rules = array( + '/(x|ch|ss)es$/' => '\1', + '/movies$/' => 'movie', + '/series$/' => 'series', + '/([^aeiouy]|qu)ies$/' => '\1y', + '/([lr])ves$/' => '\1f', + '/([^f])ves$/' => '\1fe', + '/(analy|ba|diagno|parenthe|progno|synop|the)ses$/' => '\1sis', + '/([ti])a$/' => '\1um', + '/people$/' => 'person', + '/men$/' => 'man', + '/status$/' => 'status', + '/children$/' => 'child', + '/news$/' => 'news', + '/s$/' => '' + ); + + foreach ($singular_rules as $rule => $replacement) { + if (preg_match($rule, $word)) { + return preg_replace($rule, $replacement, $word); + } + } + + return false; + } + +/** + * Returns given $lower_case_and_underscored_word as a camelCased word. + * + * @param string $lower_case_and_underscored_word Word to camelize + * @return string Camelized word. likeThis. + */ + function camelize($lower_case_and_underscored_word) { + return str_replace(" ","",ucwords(str_replace("_"," ",$lower_case_and_underscored_word))); + } + +/** + * Returns an underscore-syntaxed ($like_this_dear_reader) version of the $camel_cased_word. + * + * @param string $camel_cased_word Camel-cased word to be "underscorized" + * @return string Underscore-syntaxed version of the $camel_cased_word + */ + function underscore($camel_cased_word) { + $camel_cased_word = preg_replace('/([A-Z]+)([A-Z])/','\1_\2',$camel_cased_word); + return strtolower(preg_replace('/([a-z])([A-Z])/','\1_\2',$camel_cased_word)); + } + +/** + * Returns a human-readable string from $lower_case_and_underscored_word, + * by replacing underscores with a space, and by upper-casing the initial characters. + * + * @param string $lower_case_and_underscored_word String to be made more readable + * @return string Human-readable string + */ + function humanize($lower_case_and_underscored_word) { + return ucwords(str_replace("_"," ",$lower_case_and_underscored_word)); + } + +/** + * Returns corresponding table name for given $class_name. + * + * @param string $class_name Name of class to get database table name for + * @return string Name of the database table for given class + */ + function tableize($class_name) { + return Inflector::pluralize(Inflector::underscore($class_name)); + } + +/** + * Returns Cake class name ("Post" for the database table "posts".) for given database table. + * + * @param string $table_name Name of database table to get class name for + * @return string + */ + function classify($table_name) + { + return Inflector::camelize(Inflector::singularize($table_name)); + } + +/** + * Returns $class_name in underscored form, with "_id" tacked on at the end. + * This is for use in dealing with the database. + * + * @param string $class_name + * @return string + */ + function foreignKey($class_name) + { + return Inflector::underscore($class_name) . "_id"; + } + + function toControllerFilename($name) + { + return CONTROLLERS.Inflector::underscore($name).'.php'; + } + + function toHelperFilename($name) + { + return HELPERS.Inflector::underscore($name).'.php'; + } + + function toFullName($name, $correct) + { + if (strstr($name, '_') && (strtolower($name) == $name)) + { + return Inflector::camelize($name); + } + + if (preg_match("/^(.*)({$correct})$/i", $name, $reg)) + { + if ($reg[2] == $correct) + { + return $name; + } + else + { + return ucfirst($reg[1].$correct); + } + } + else + { + return ucfirst($name.$correct); + } + } + + function toLibraryFilename ($name) + { + return LIBS.Inflector::underscore($name).'.php'; + } +} + +?> diff --git a/libs/legacy.php b/libs/legacy.php index 926142e5b..28d68bd6e 100644 --- a/libs/legacy.php +++ b/libs/legacy.php @@ -1,78 +1,78 @@ - + // -// + 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 + // -////////////////////////////////////////////////////////////////////////// - -/** - * with this hack you can use clone() in PHP4 code - * use "clone($object)" not "clone $object"! the former works in both PHP4 and PHP5 - * - * - * @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 - */ - -if (version_compare(phpversion(), '5.0') < 0) { - eval(' - function clone($object) { - return $object; - } - '); -} - - -/** - * Replace file_get_contents() - * - * @category PHP - * @package PHP_Compat - * @link http://php.net/function.file_get_contents - * @author Aidan Lister - * @internal resource_context is not supported - * @since PHP 5 - * @require PHP 4.0.0 (user_error) - */ -if (!function_exists('file_get_contents')) { - function file_get_contents($filename, $incpath = false) - { - if (false === $fh = fopen($filename, 'rb', $incpath)) { - user_error('file_get_contents() failed to open stream: No such file or directory', - E_USER_WARNING); - return false; - } - - clearstatcache(); - if ($fsize = @filesize($filename)) { - $data = fread($fh, $fsize); - } else { - $data = ''; - while (!feof($fh)) { - $data .= fread($fh, 8192); - } - } - - fclose($fh); - return $data; - } -} - + + // +// + 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 + // +////////////////////////////////////////////////////////////////////////// + +/** + * with this hack you can use clone() in PHP4 code + * use "clone($object)" not "clone $object"! the former works in both PHP4 and PHP5 + * + * + * @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 + */ + +if (version_compare(phpversion(), '5.0') < 0) { + eval(' + function clone($object) { + return $object; + } + '); +} + + +/** + * Replace file_get_contents() + * + * @category PHP + * @package PHP_Compat + * @link http://php.net/function.file_get_contents + * @author Aidan Lister + * @internal resource_context is not supported + * @since PHP 5 + * @require PHP 4.0.0 (user_error) + */ +if (!function_exists('file_get_contents')) { + function file_get_contents($filename, $incpath = false) + { + if (false === $fh = fopen($filename, 'rb', $incpath)) { + user_error('file_get_contents() failed to open stream: No such file or directory', + E_USER_WARNING); + return false; + } + + clearstatcache(); + if ($fsize = @filesize($filename)) { + $data = fread($fh, $fsize); + } else { + $data = ''; + while (!feof($fh)) { + $data .= fread($fh, 8192); + } + } + + fclose($fh); + return $data; + } +} + ?> \ No newline at end of file diff --git a/libs/router.php b/libs/router.php index 9fa0e0e5b..a487e88d7 100644 --- a/libs/router.php +++ b/libs/router.php @@ -1,173 +1,173 @@ - + // -// + 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: Router - * Parses the request URL into controller, action, and parameters. - * - * @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('object', 'narray'); - -/** - * Parses the request URL into controller, action, and parameters. - * - * @package cake - * @subpackage cake.libs - * @since Cake v 0.2.9 - * - */ -class Router extends Object { - -/** - * Array of routes - * - * @var array - */ - var $routes = array(); - -/** - * TODO: Better description. Returns this object's routes array. Returns false if there are no routes available. - * - * @param string $route An empty string, or a route string "/" - * @param array $default NULL or an array describing the default route - * @see routes - * @return array Array of routes - */ - function connect ($route, $default=null) { - $parsed = $names = array (); - - $r = null; - if (($route == '') || ($route == '/')) { - $regexp = '/^[\/]*$/'; - $this->routes[] = array($route, $regexp, array(), $default); - } - else { - $elements = array(); - foreach (explode('/', $route) as $element) - if (trim($element)) $elements[] = $element; - - if (!count($elements)) - return false; - - foreach ($elements as $element) { - if (preg_match('/^:(.+)$/', $element, $r)) { - $parsed[] = '(?:\/([^\/]+))?'; - $names[] = $r[1]; - } - elseif (preg_match('/^\*$/', $element, $r)) { - $parsed[] = '(?:\/(.*))?'; - } - else { - $parsed[] = '/'.$element; - } - } - $regexp = '#^'.join('', $parsed).'[\/]*$#'; - $this->routes[] = array($route, $regexp, $names, $default); - } - - return $this->routes; - } - -/** - * TODO: Better description. Returns an array of routes. - * - * @param string $url URL to be parsed - * @return array - */ - function parse ($url) - { - // An URL should start with a '/', mod_rewrite doesn't respect that, but no-mod_rewrite version does. - // Here's the fix. - if ($url && ('/' != $url[0])) - { - $url = '/'.$url; - } - - $out = array(); - $r = null; - - $default_route = array - ( - '/:controller/:action/* (default)', - "#^(?:\/(?:([a-z0-9_\-]+)(?:\/([a-z0-9_\-]+)(?:\/(.*))?)?))[\/]*$#", - array('controller', 'action'), - array() - ); - - $this->routes[] = $default_route; - - foreach ($this->routes as $route) - { - list($route, $regexp, $names, $defaults) = $route; - - if (preg_match($regexp, $url, $r)) - { - // $this->log($url.' matched '.$regexp, 'note'); - // remove the first element, which is the url - array_shift($r); - - // hack, pre-fill the default route names - foreach ($names as $name) - $out[$name] = null; - - $ii = 0; - - if (is_array($defaults)) - { - foreach ($defaults as $name=>$value) - { - if (preg_match('#[a-z_\-]#i', $name)) - $out[$name] = $value; - else - $out['pass'][] = $value; - } - } - - foreach ($r as $found) { - // if $found is a named url element (i.e. ':action') - if (isset($names[$ii])) - { - $out[$names[$ii]] = $found; - } - // unnamed elements go in as 'pass' - else - { - $pass = new Narray(explode('/', $found)); - $pass->cleanup(); - $out['pass'] = $pass->value; - } - $ii++; - } - break; - } - } - - return $out; - } -} - + + // +// + 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: Router + * Parses the request URL into controller, action, and parameters. + * + * @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('object', 'narray'); + +/** + * Parses the request URL into controller, action, and parameters. + * + * @package cake + * @subpackage cake.libs + * @since Cake v 0.2.9 + * + */ +class Router extends Object { + +/** + * Array of routes + * + * @var array + */ + var $routes = array(); + +/** + * TODO: Better description. Returns this object's routes array. Returns false if there are no routes available. + * + * @param string $route An empty string, or a route string "/" + * @param array $default NULL or an array describing the default route + * @see routes + * @return array Array of routes + */ + function connect ($route, $default=null) { + $parsed = $names = array (); + + $r = null; + if (($route == '') || ($route == '/')) { + $regexp = '/^[\/]*$/'; + $this->routes[] = array($route, $regexp, array(), $default); + } + else { + $elements = array(); + foreach (explode('/', $route) as $element) + if (trim($element)) $elements[] = $element; + + if (!count($elements)) + return false; + + foreach ($elements as $element) { + if (preg_match('/^:(.+)$/', $element, $r)) { + $parsed[] = '(?:\/([^\/]+))?'; + $names[] = $r[1]; + } + elseif (preg_match('/^\*$/', $element, $r)) { + $parsed[] = '(?:\/(.*))?'; + } + else { + $parsed[] = '/'.$element; + } + } + $regexp = '#^'.join('', $parsed).'[\/]*$#'; + $this->routes[] = array($route, $regexp, $names, $default); + } + + return $this->routes; + } + +/** + * TODO: Better description. Returns an array of routes. + * + * @param string $url URL to be parsed + * @return array + */ + function parse ($url) + { + // An URL should start with a '/', mod_rewrite doesn't respect that, but no-mod_rewrite version does. + // Here's the fix. + if ($url && ('/' != $url[0])) + { + $url = '/'.$url; + } + + $out = array(); + $r = null; + + $default_route = array + ( + '/:controller/:action/* (default)', + "#^(?:\/(?:([a-z0-9_\-]+)(?:\/([a-z0-9_\-]+)(?:\/(.*))?)?))[\/]*$#", + array('controller', 'action'), + array() + ); + + $this->routes[] = $default_route; + + foreach ($this->routes as $route) + { + list($route, $regexp, $names, $defaults) = $route; + + if (preg_match($regexp, $url, $r)) + { + // $this->log($url.' matched '.$regexp, 'note'); + // remove the first element, which is the url + array_shift($r); + + // hack, pre-fill the default route names + foreach ($names as $name) + $out[$name] = null; + + $ii = 0; + + if (is_array($defaults)) + { + foreach ($defaults as $name=>$value) + { + if (preg_match('#[a-z_\-]#i', $name)) + $out[$name] = $value; + else + $out['pass'][] = $value; + } + } + + foreach ($r as $found) { + // if $found is a named url element (i.e. ':action') + if (isset($names[$ii])) + { + $out[$names[$ii]] = $found; + } + // unnamed elements go in as 'pass' + else + { + $pass = new Narray(explode('/', $found)); + $pass->cleanup(); + $out['pass'] = $pass->value; + } + $ii++; + } + break; + } + } + + return $out; + } +} + ?> \ No newline at end of file diff --git a/libs/validators.php b/libs/validators.php index e17918f26..d428a4b69 100644 --- a/libs/validators.php +++ b/libs/validators.php @@ -1,53 +1,53 @@ - + // -// + 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: Tort Validators - * Used to validate data in Models. - * - * @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 - */ - -/** - * Not empty. - */ -define('VALID_NOT_EMPTY', '/.+/'); - -/** - * Numbers [0-9] only. - */ -define('VALID_NUMBER', '/^[0-9]+$/'); - -/** - * A valid email address. - */ -define('VALID_EMAIL', '/^([a-z0-9][a-z0-9_\-\.\+]*)@([a-z0-9][a-z0-9\.\-]{0,63}\.[a-z]{2,3})$/i'); - -/** - * A valid year (1000-2999). - */ -define('VALID_YEAR', '/^[12][0-9]{3}$/'); - + + // +// + 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: Tort Validators + * Used to validate data in Models. + * + * @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 + */ + +/** + * Not empty. + */ +define('VALID_NOT_EMPTY', '/.+/'); + +/** + * Numbers [0-9] only. + */ +define('VALID_NUMBER', '/^[0-9]+$/'); + +/** + * A valid email address. + */ +define('VALID_EMAIL', '/^([a-z0-9][a-z0-9_\-\.\+]*)@([a-z0-9][a-z0-9\.\-]{0,63}\.[a-z]{2,3})$/i'); + +/** + * A valid year (1000-2999). + */ +define('VALID_YEAR', '/^[12][0-9]{3}$/'); + ?> \ No newline at end of file diff --git a/public/css/default.css b/public/css/default.css index 96223a9b3..0f9c525f5 100644 --- a/public/css/default.css +++ b/public/css/default.css @@ -1,110 +1,110 @@ -BODY { -font-size: 76%; -} - -BODY, INPUT, TEXTAREA { -font-family:sans-serif; -} - -H1 { -font-size:2.1em; -color: #fff; -text-align: left; -position: absolute; -padding-left: 15%; -top: 0.35em; -left: 0; -height: 4em; -} - -H2 { -font-size:1.7em; -color: #383; -} - -H3 { -font-size:1.4em; -color: #553; -} - -H4 { -font-size:1.15em; -color: #338; -} - -P { -font-size:1em; -margin-bottom:.5em; -} - -A { -white-space:nowrap; -text-decoration:underline; -} - -A:HOVER { -background-color:#EEE; -} - -CODE, PRE { -font-family:monospace; -font-size:1.1em !important; -font-size:.95em; -color:#44A; -margin:0; -} - -CODE { -color:#227; -white-space:nowrap; -margin:0 .2em; -} - -PRE { -margin-left:1em; -} - -ACRONYM { -border-bottom:1px dotted; -} - -HR { -height:0; -border-top:1px solid #AAA; -} - - -#container { -margin: 0 auto; -border-top: solid 5em #69c; -color: #333; -font: normal 1.1em Verdana; -padding: 0 15%; -} - -#content { -padding-top: 1em; -width: 100%; -text-align: left; -line-height: 170%; -} - -.notice { -padding: 1em; -background: #ffd; -border: solid 2px #eeb; -display: block; -font-family: Verdana; -} - -.tip { -background: #efe; -padding: 1em; -border: solid 2px #cdc; -} - -.error { -background: #fee; -padding: 1em; -border: solid 2px #dcc; -} +BODY { +font-size: 76%; +} + +BODY, INPUT, TEXTAREA { +font-family:sans-serif; +} + +H1 { +font-size:2.1em; +color: #fff; +text-align: left; +position: absolute; +padding-left: 15%; +top: 0.35em; +left: 0; +height: 4em; +} + +H2 { +font-size:1.7em; +color: #383; +} + +H3 { +font-size:1.4em; +color: #553; +} + +H4 { +font-size:1.15em; +color: #338; +} + +P { +font-size:1em; +margin-bottom:.5em; +} + +A { +white-space:nowrap; +text-decoration:underline; +} + +A:HOVER { +background-color:#EEE; +} + +CODE, PRE { +font-family:monospace; +font-size:1.1em !important; +font-size:.95em; +color:#44A; +margin:0; +} + +CODE { +color:#227; +white-space:nowrap; +margin:0 .2em; +} + +PRE { +margin-left:1em; +} + +ACRONYM { +border-bottom:1px dotted; +} + +HR { +height:0; +border-top:1px solid #AAA; +} + + +#container { +margin: 0 auto; +border-top: solid 5em #69c; +color: #333; +font: normal 1.1em Verdana; +padding: 0 15%; +} + +#content { +padding-top: 1em; +width: 100%; +text-align: left; +line-height: 170%; +} + +.notice { +padding: 1em; +background: #ffd; +border: solid 2px #eeb; +display: block; +font-family: Verdana; +} + +.tip { +background: #efe; +padding: 1em; +border: solid 2px #cdc; +} + +.error { +background: #fee; +padding: 1em; +border: solid 2px #dcc; +}