diff --git a/VERSION.txt b/VERSION.txt index f85849c87..ef10ab617 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -6,4 +6,4 @@ // +---------------------------------------------------------------------------------------------------+ // /////////////////////////////////////////////////////////////////////////////////////////////////////////// -1.0.1.2767 \ No newline at end of file +1.1.2.2802 \ No newline at end of file diff --git a/app/webroot/css/cake.basic.css b/app/webroot/css/cake.basic.css new file mode 100644 index 000000000..08c989d82 --- /dev/null +++ b/app/webroot/css/cake.basic.css @@ -0,0 +1,264 @@ +*{ +margin:0; +padding:0; +} + +body{ +font-family:verdana,helvetica,arial,sans-serif; +font-size:12px; +text-align:center; +color:#fff; +background:#003d4c; +} + +/* +* General Style Info +*/ + +a{ +color:#003d4c; +text-decoration:none; +} +a:hover{ +color:#003d4c; +text-decoration:underline; +} + +a img{ +border:none; +} + +h1, h2,h3{ +font-family:'Gill Sans'; +font-size:28px; +font-weight:normal; +} +h1{ +padding:0.5em 0; +color:#003d4c; +} +em { + font-size: 12px; +} +h2{ +padding-top:0.15em; +margin:0.3em 0; +color:#e32; +} + +h3{ +font-size:18px; +padding-top:0.5em; +color:#003d4c; +} + +h4{ +color:#ff9966; +font-size:20px; +padding-top:0.5em; +font-weight:normal; +} + +blockquote{ +padding: 10px; +padding-left: 20px; +padding-right: 20px; +} + +#content ol, #content ul{ +margin:0 1em; +padding:0 2em; +} + +/* +* Layout +*/ + +#container{ +text-align:left; +margin-left:0px; +} + +#header{ +height:200px; +background:#003d4c; +} + +#header h1{ +color:#fff; +font-family: 'Gill Sans'; +font-size: 45px; +font-weight:normal; +} + +#header h1.logo { +float:left; +} + +#header h1.logo a{ +display:block; +width:226px; +height:176px; +background: transparent url('images/logo.gif') no-repeat top; +} + +#header h1.logo a:hover{ +background:url('images/logo.gif') no-repeat bottom; +} + +#content{ +width: auto; +min-width: 860px; +min-height: 720px; +padding:15px 20px 50px 20px; +margin: 0px 10px 0px 40px; +color:#333; +background:#fff ; +border-right: 6px solid #222; +} + +/* +* Navigation +*/ +#navigation{ +float:left; +height: 146px; +width:710px; +background:#003d4c url(images/nav_bg.gif) no-repeat; +padding-left: 20px; +} +#navigation ul{ + +} + +#navigation ul li{ +list-style-type:none; +display:inline; +} + +#navigation ul li a{ +font-weight:bold; +display:block; +float:left; +color:#000; +} + +#navigation ul li a span{ +display:block; +margin-right:12px; +padding:10px 6px 9px 9px; +} + +#navigation ul li.active a span{ +padding:10px 6px 9px 9px; +} + + + +#navigation ul li a:hover, #navigation ul li.active a{ +background:url(images/nav_item_bg.gif) no-repeat bottom right; +} + +#navigation ul li a:hover span, #navigation ul li.active a span{ +background:url(images/nav_item_bg.gif) no-repeat bottom left; +} + +#footer { + color: #fff; + background-color: #003d4c; + padding: 4px 10px; + text-align: right; +} +#footer a{ + color: #fff; +} +.left { + float:left; +} +.right { + float:right; +} +.clear { + clear:both; + height: 0px; + line-height: 0px; +} + + +/* tables */ + +table { + width: 100%; + border: 1px solid #003d4c; + color:#333; + background-color: #fff; + clear:both; + padding: 0; + margin: 0 0 2em 0; + white-space: normal; +} +th { + background-color: #ccc; + border-top: 1px solid #fff; + border-left: 1px solid #fff; + border-right: 1px solid #003d4c; + border-bottom: 1px solid #003d4c; + text-align: center; + padding:1px; +} +table tr td { + border-right: 1px solid #ccc; + padding:4px 4px; + vertical-align:top; + text-align: center; +} +table tr.altRow td { + background: #f4f4f4; +} + +/* scaffold show */ + + +div.related { + clear:both; + display:block; +} +dl { + line-height:2em; + margin:1em; + float:left; + width: 400px; +} +dt { + font-weight: bold; + vertical-align:top; +} +dd { + margin-left:10em; + margin-top:-2em; + vertical-align:top; +} + +/* scaffold buttons */ + + +.notice { + color: #DB8101; + background-color: #ddd; + display: block; + padding: 1em; +} +.tip { + color: #DB8101; + background-color: #ddd; + display: block; + padding: 1em; +} + + +/* action links */ +ul.actions { + float:left; + margin-left: 10px; + width: 200px; +} \ No newline at end of file diff --git a/app/webroot/css/cake.default.css b/app/webroot/css/cake.default.css deleted file mode 100644 index 117a762d2..000000000 --- a/app/webroot/css/cake.default.css +++ /dev/null @@ -1,195 +0,0 @@ -/* CSS Document */ -@import url("cake.forms.css"); - -* { - padding:0; - margin:0; -} -body { - font: 76% Verdana, Arial, Sans-serif; - color: #333; -} -img { - border:0; -} -#wrapper { - text-align:left; -} -#header { - height: 101px; - background: #0D5087 url(../img/cake.header_bg.png) repeat-x left top; - border-bottom: 1px solid #000; -} -#content { - min-height:400px; - background-color: #fff; - padding:2em 4em; -} -#footer { - text-align:center; - padding:1em 0; - font-size:smaller; - border-top:1px solid #333; - background-color: #063260; - color:#fff; - line-height:1.5; -} -#footer a { - color:#fff; -} - -h1, h2, h3, h4 { -padding-bottom:0.5em; -} -h1 { - font-family:"Trebuchet MS",Verdana,Arial,Sans-serif; -} -h1, a { - color:#DB8101; -} -h1 em, a em { - color:#008BCC; - font-style: normal; -} -ul.colored a em -h2 { - font-style: italic; - font-weight: bold; - color:#666; -} -a:hover, a:hover em { -color:#A22424; -text-decoration:none; -} -#content p, #content ul, #content ol { -line-height:1.5; -padding-bottom:1em; -} -ul, ol { -margin-left:3em; -} - -/* tables */ - -table { - width: 100%; - background-color: #fff; - border: 1px solid #333; - clear:both; - margin: 0 0 2em 0; - white-space: normal; -} -th { - background-color: #ccc; - border-top: 1px solid #fff; - border-right: 1px solid #666; - border-bottom: 1px solid #666; - text-align: center; - padding:3px; -} -table tr td { - border-right: 1px solid #ccc; - padding:4px 4px; - vertical-align:top; - text-align: center; -} -table tr.altRow td { - background: #f4f4f4; -} - -/* scaffold show */ - - -div.related { - clear:both; - display:block; -} -dl { - line-height:2em; - margin:1em; -} -dt { - font-weight: bold; - vertical-align:top; -} -dd { - margin-left:10em; - margin-top:-2em; - vertical-align:top; -} - -/* scaffold buttons */ - - -.notice { - color: #DB8101; - background-color: #ddd; - display: block; - padding: 1em; -} -.tip { - color: #DB8101; - background-color: #ddd; - display: block; - padding: 1em; -} - -ul.actions { - list-style: none; - text-align:left; - margin:2em 0; - padding: 0; -} -ul.actions li { - margin-left:1em; - list-style: none; - display: inline; -} -ul.actions li a, ul.actions li input { - padding: 2px 12px; - color: #DB8101; - background-color:#ccc; - text-decoration: none; - border: 1px solid #666; - line-height: 24px; - font-weight: bold; - text-align:center; - text-decoration: none; -} -ul.actions li a:hover { - color: #DB8101; - background-color:#fff; - text-decoration: none; -} -td.listactions { - width: 14em; - text-align: center; - white-space: nowrap; -} -td.listactions a { - padding: 0px 8px; - text-align:center; - font-weight: bold; - color: #DB8101; - background-color:#ccc; - text-decoration: none; - border: 1px solid #666; - white-space: nowrap; -} -td.listactions a:hover { - color: #fff; - background-color:#DB8101; -} - -/* index links */ - -ul.colored a { - -} -ul.colored a em { - -} - -a { -font-weight: bold; -} \ No newline at end of file diff --git a/app/webroot/css/cake.ie.css b/app/webroot/css/cake.ie.css deleted file mode 100644 index cee4e1734..000000000 --- a/app/webroot/css/cake.ie.css +++ /dev/null @@ -1,9 +0,0 @@ -form div, -form div label.labelCheckbox, form div label.labelRadio, -form div small, -form div label.labelCheckbox, form div label.labelRadio, label.labelCheckbox, label.labelRadio { - height: expression('1%'); -} -form div fieldset input.inputText, form div fieldset input.inputPassword, form div fieldset input.inputFile, form div fieldset textarea.inputTextarea { - margin: expression('0px 0px 0px -124px'); -} diff --git a/app/webroot/css/images/arrow.gif b/app/webroot/css/images/arrow.gif new file mode 100644 index 000000000..965b0aa4e Binary files /dev/null and b/app/webroot/css/images/arrow.gif differ diff --git a/app/webroot/css/images/container_bg.gif b/app/webroot/css/images/container_bg.gif new file mode 100755 index 000000000..fed97a9a5 Binary files /dev/null and b/app/webroot/css/images/container_bg.gif differ diff --git a/app/webroot/css/images/logo.gif b/app/webroot/css/images/logo.gif new file mode 100755 index 000000000..0d0cf000b Binary files /dev/null and b/app/webroot/css/images/logo.gif differ diff --git a/app/webroot/css/images/nav_bg.gif b/app/webroot/css/images/nav_bg.gif new file mode 100755 index 000000000..4b320be84 Binary files /dev/null and b/app/webroot/css/images/nav_bg.gif differ diff --git a/app/webroot/css/images/nav_item_bg.gif b/app/webroot/css/images/nav_item_bg.gif new file mode 100755 index 000000000..d106c10e8 Binary files /dev/null and b/app/webroot/css/images/nav_item_bg.gif differ diff --git a/app/webroot/img/cake.header_bg.png b/app/webroot/img/cake.header_bg.png deleted file mode 100644 index dcf1b7d05..000000000 Binary files a/app/webroot/img/cake.header_bg.png and /dev/null differ diff --git a/app/webroot/img/cake.logo.png b/app/webroot/img/cake.logo.png deleted file mode 100644 index e39381882..000000000 Binary files a/app/webroot/img/cake.logo.png and /dev/null differ diff --git a/cake/basics.php b/cake/basics.php index e4954451c..8be3a16d9 100644 --- a/cake/basics.php +++ b/cake/basics.php @@ -356,7 +356,7 @@ function listClasses($path) } } closedir($dir); - return $classes; + return $classes; } /** @@ -499,11 +499,11 @@ if (!function_exists('sortByKey')) if ($order == 'asc') { - asort($sa, $type); + asort($sa, $type); } else { - arsort($sa, $type); + arsort($sa, $type); } foreach ($sa as $key=>$val) @@ -608,11 +608,11 @@ function aa() { if ($l+1 < count($args)) { - $a[$args[$l]] = $args[$l+1]; + $a[$args[$l]] = $args[$l+1]; } else { - $a[$args[$l]] = null; + $a[$args[$l]] = null; } $l++; } @@ -729,7 +729,7 @@ function am () { if (!is_array($a)) { - $a = array($a); + $a = array($a); } $r = array_merge($r, $a); } @@ -1141,4 +1141,51 @@ function convertSlash($string) return $string; } +/** + * chmod recursively on a directory + * + * @param string $path + * @param int $mode + * @return boolean + */ +function chmodr($path, $mode = 0755) +{ + if (!is_dir($path)) + { + return chmod($path, $mode); + } + $dir = opendir($path); + while ($file = readdir($dir)) + { + if($file != '.' && $file != '..') + { + $fullpath = $path.'/'.$file; + if(!is_dir($fullpath)) + { + if (!chmod($fullpath, $mode)) + { + return false; + } + } + else + { + if (!chmodr($fullpath, $mode)) + { + return false; + } + } + } + } + + closedir($dir); + if(chmod($path, $mode)) + { + return true; + } + else + { + return false; + } +} + ?> \ No newline at end of file diff --git a/cake/bootstrap.php b/cake/bootstrap.php index 32132e9d6..803d26368 100644 --- a/cake/bootstrap.php +++ b/cake/bootstrap.php @@ -62,7 +62,7 @@ if (empty($uri) && defined('BASE_URL')) if (strpos($uri, 'index.php') !== false) { $uri = r ('?', '', $uri); - $elements = explode('/index.php', $uri); + $elements = explode('/index.php', $uri); } else { diff --git a/cake/dispatcher.php b/cake/dispatcher.php index 6e062cec1..77952cbb5 100644 --- a/cake/dispatcher.php +++ b/cake/dispatcher.php @@ -410,8 +410,9 @@ class Dispatcher extends Object $docRoot = env('DOCUMENT_ROOT'); $scriptName = env('PHP_SELF'); $r = null; + $appDirName = str_replace('/','\/',preg_quote(APP_DIR)); - if (preg_match('/'.APP_DIR.'\\'.DS.WEBROOT_DIR.'/', $docRoot)) + if (preg_match('/'.$appDirName.'\\'.DS.WEBROOT_DIR.'/', $docRoot)) { $this->webroot = '/'; if (preg_match('/^(.*)\/index\.php$/', $scriptName, $r)) @@ -429,7 +430,7 @@ class Dispatcher extends Object $webroot = setUri(); $htaccess = preg_replace('/(?:'.APP_DIR.'(.*)|index\\.php(.*))/i', '', $webroot).APP_DIR.'/'.WEBROOT_DIR.'/'; } - if (preg_match('/^(.*)\\/'.APP_DIR.'\\/'.WEBROOT_DIR.'\\/index\\.php$/', $scriptName, $regs)) + if (preg_match('/^(.*)\\/'.$appDirName.'\\/'.WEBROOT_DIR.'\\/index\\.php$/', $scriptName, $regs)) { if(APP_DIR === 'app') { diff --git a/cake/libs/controller/components/dbacl/db_acl.php b/cake/libs/controller/components/dbacl/db_acl.php index 1fc9742c8..f626b98d6 100644 --- a/cake/libs/controller/components/dbacl/db_acl.php +++ b/cake/libs/controller/components/dbacl/db_acl.php @@ -265,20 +265,25 @@ class DB_ACL extends AclBase trigger_error('Null id provided in DB_ACL::get'.$object, E_USER_WARNING); return null; } - $obj = new $obj; - + $obj = new $object; + if (is_numeric($id)) { - $conditions = array('Aco.user_id' => $id); + $key = 'user_id'; + if ($object == 'Aco') + { + $key = 'object_id'; + } + $conditions = array($object.'.'.$key => $id); } else { - $conditions = array('Aco.alias' => $id); + $conditions = array($object.'.alias' => $id); } $tmp = $obj->find($conditions); - $aco->setId($tmp['Aco']['id']); - return $aco; + $obj->id = $tmp[$object]['id']; + return $obj; } /** diff --git a/cake/libs/controller/components/dbacl/models/aclnode.php b/cake/libs/controller/components/dbacl/models/aclnode.php index ad6344507..8887c6508 100644 --- a/cake/libs/controller/components/dbacl/models/aclnode.php +++ b/cake/libs/controller/components/dbacl/models/aclnode.php @@ -65,10 +65,10 @@ class AclNode extends AppModel if($parent_id == null || $parent_id === 0) { - $parent = $this->find(null, "MAX(rght)", null, null, 0); - $parent['lft'] = $parent[0]['MAX(rght)']; + $parent = $this->find(null, 'MAX(rght) as rght', null, -1); + $parent['lft'] = $parent[0]['rght']; - if($parent[0]['MAX(rght)'] == null) + if($parent[0]['rght'] == null || !$parent[0]['rght']) { // The tree is empty $parent['lft'] = 0; @@ -141,7 +141,7 @@ class AclNode extends AppModel if($parent_id == null) { - $newParent = $this->find(null, "MAX(rght) as lft", null, 0); + $newParent = $this->find(null, 'MAX(rght) as lft', null, -1); $newParent = $newParent[0]; $newParent['rght'] = $newParent['lft']; } diff --git a/cake/libs/controller/components/request_handler.php b/cake/libs/controller/components/request_handler.php index 4e75c68b3..1feafce53 100644 --- a/cake/libs/controller/components/request_handler.php +++ b/cake/libs/controller/components/request_handler.php @@ -52,15 +52,15 @@ class RequestHandlerComponent extends Object var $disableStartup = false; var $__requestContent = array( - 'js' => 'text/javascript', - 'css' => 'text/css', - 'html' => 'text/html', - 'form' => 'application/x-www-form-urlencoded', - 'file' => 'multipart/form-data', - 'xhtml' => array('application/xhtml+xml', 'application/xhtml', 'text/xhtml'), - 'xml' => array('application/xml', 'text/xml'), - 'rss' => 'application/rss+xml', - 'atom' => 'application/atom+xml' + 'js' => 'text/javascript', + 'css' => 'text/css', + 'html' => 'text/html', + 'form' => 'application/x-www-form-urlencoded', + 'file' => 'multipart/form-data', + 'xhtml' => array('application/xhtml+xml', 'application/xhtml', 'text/xhtml'), + 'xml' => array('application/xml', 'text/xml'), + 'rss' => 'application/rss+xml', + 'atom' => 'application/atom+xml' ); var $__acceptTypes = array(); @@ -336,7 +336,7 @@ class RequestHandlerComponent extends Object $str = $this->stripImages($str); $str = $this->stripScripts($str); return $str; - } + } /** * Strips the specified tags from output diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index 0c03f8ddb..e4ce991c5 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -944,6 +944,7 @@ class Controller extends Object unset($this->params['data'][$this->modelClass][$field['name'].'_min']); unset($this->params['data'][$this->modelClass][$field['name'].'_meridian']); $this->params['data'][$this->modelClass][$field['name']] = $newDate; + $this->data[$this->modelClass][$field['name']] = $newDate; } else if( 'datetime' == $field['type'] && isset($this->params['data'][$this->modelClass][$field['name'].'_year'] ) ) { @@ -963,6 +964,7 @@ class Controller extends Object unset($this->params['data'][$this->modelClass][$field['name'].'_min']); unset($this->params['data'][$this->modelClass][$field['name'].'_meridian']); $this->params['data'][$this->modelClass][$field['name']] = $newDate; + $this->data[$this->modelClass][$field['name']] = $newDate; } } } diff --git a/cake/libs/error.php b/cake/libs/error.php index 960b27aac..87d7ff74f 100644 --- a/cake/libs/error.php +++ b/cake/libs/error.php @@ -126,9 +126,9 @@ class ErrorHandler extends Object header("HTTP/1.0 404 Not Found"); $this->error( - array('code' => '404', - 'name' => 'Not found', - 'message' => sprintf(__("The requested address %s was not found on this server.", true), $url, $message), + array('code' => '404', + 'name' => 'Not found', + 'message' => sprintf(__("The requested address %s was not found on this server.", true), $url, $message), 'base' => $base ) ); diff --git a/cake/libs/model/datasources/datasource.php b/cake/libs/model/datasources/datasource.php index 1baff1a5b..d0f3b88ef 100644 --- a/cake/libs/model/datasources/datasource.php +++ b/cake/libs/model/datasources/datasource.php @@ -493,7 +493,7 @@ class DataSource extends Object * Enter description here... The special {n}, as seen in the Model::generateList method, is taken care of here. * * @param array $data - * @param mixed $path As an array, or as a dot-separated string. + * @param mixed $path As an array, or as a dot-separated string. * @return array */ function getFieldValue ($data, $path) diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 4330c82ad..102c3ddf6 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -124,14 +124,14 @@ class DboSource extends DataSource { if (is_array($data)) { - $out = array(); - $keys = array_keys($data); - $count = count($data); - for ($i = 0; $i < $count; $i++) - { + $out = array(); + $keys = array_keys($data); + $count = count($data); + for ($i = 0; $i < $count; $i++) + { $out[$keys[$i]] = $this->value($data[$keys[$i]]); - } - return $out; + } + return $out; } else { @@ -445,11 +445,11 @@ class DboSource extends DataSource $this->_queriesTime += $this->took; $this->_queriesLog[] = array( - 'query' => $sql, - 'error' => $this->error, - 'affected' => $this->affected, - 'numRows' => $this->numRows, - 'took' => $this->took + 'query' => $sql, + 'error' => $this->error, + 'affected' => $this->affected, + 'numRows' => $this->numRows, + 'took' => $this->took ); if (count($this->_queriesLog) > $this->_queriesLogMax) @@ -470,25 +470,25 @@ class DboSource extends DataSource * * @param string $sql Query to show information on. */ - function showQuery($sql) - { - $error = $this->error; + function showQuery($sql) + { + $error = $this->error; - if (strlen($sql) > 200 && !$this->fullDebug) - { - $sql = substr($sql, 0, 200) .'[...]'; - } + if (strlen($sql) > 200 && !$this->fullDebug) + { + $sql = substr($sql, 0, 200) .'[...]'; + } - if ($this->debug || $error) - { - print("

Query: {$sql} [Aff:{$this->affected} Num:{$this->numRows} Took:{$this->took}ms]"); - if($error) - { - print("
ERROR: {$this->error}"); - } - print('

'); - } - } + if ($this->debug || $error) + { + print("

Query: {$sql} [Aff:{$this->affected} Num:{$this->numRows} Took:{$this->took}ms]"); + if($error) + { + print("
ERROR: {$this->error}"); + } + print('

'); + } + } /** * The "C" in CRUD @@ -708,16 +708,16 @@ class DboSource extends DataSource if ($query) { if (!isset($resultSet) || !is_array($resultSet)) { - if (DEBUG) - { - e('
SQL Error in model '.$model->name.': '); - if (isset($this->error) && $this->error != null) - { - e($this->error); - } - e('
'); - } - return null; + if (DEBUG) + { + e('
SQL Error in model '.$model->name.': '); + if (isset($this->error) && $this->error != null) + { + e($this->error); + } + e('
'); + } + return null; } $count = count($resultSet); @@ -787,7 +787,7 @@ class DboSource extends DataSource } } } - $data[$association] = $merge[0][$association]; + $data[$association] = $merge[0][$association]; } } else @@ -1212,7 +1212,7 @@ class DboSource extends DataSource $combined = array_combine($fields, $values); foreach ($combined as $field => $value) { - $updates[] = $this->name($field).'='.$this->value($value, $model->getColumnType($field)); + $updates[] = $this->name($field).'='.$this->value($value, $model->getColumnType($field)); } $sql = 'UPDATE '.$this->name($model->table); diff --git a/cake/libs/model/dbo/dbo_postgres.php b/cake/libs/model/dbo/dbo_postgres.php index c6205887d..09151e726 100644 --- a/cake/libs/model/dbo/dbo_postgres.php +++ b/cake/libs/model/dbo/dbo_postgres.php @@ -66,7 +66,7 @@ class DboPostgres extends DboSource 'date' => array('name' => 'date'), 'binary' => array('name' => 'bytea'), 'boolean' => array('name' => 'boolean'), - 'number' => array('name' => 'numeric')); + 'number' => array('name' => 'numeric')); var $startQuote = '"'; @@ -124,7 +124,7 @@ class DboPostgres extends DboSource */ function fetchRow ($assoc = false) { - if(is_resource($this->_result)) + if(is_resource($this->_result)) { $this->resultSet($this->_result); $resultRow = $this->fetchResult(); @@ -212,7 +212,7 @@ class DboPostgres extends DboSource { if ($data == '*') { - return '*'; + return '*'; } $pos = strpos($data, '"'); if ($pos === false) @@ -499,7 +499,7 @@ class DboPostgres extends DboSource } if (strpos($col, 'timestamp') !== false) { - return 'datetime'; + return 'datetime'; } if ($col == 'boolean') { diff --git a/cake/libs/model/dbo/dbo_sqlite.php b/cake/libs/model/dbo/dbo_sqlite.php index 469daac98..c7594ab09 100644 --- a/cake/libs/model/dbo/dbo_sqlite.php +++ b/cake/libs/model/dbo/dbo_sqlite.php @@ -135,7 +135,7 @@ class DboSqlite extends DboSource */ function fetchRow ($assoc = false) { - if(is_resource($this->_result)) + if(is_resource($this->_result)) { $this->resultSet($this->_result); $resultRow = $this->fetchResult(); diff --git a/cake/libs/model/model_php4.php b/cake/libs/model/model_php4.php index cd13d3bdf..ef807be1b 100644 --- a/cake/libs/model/model_php4.php +++ b/cake/libs/model/model_php4.php @@ -249,9 +249,9 @@ class Model extends Object * * @var array */ - var $__associationKeys = array('belongsTo' => array('className', 'conditions', 'order', 'foreignKey', 'counterCache'), - 'hasOne' => array('className', 'conditions', 'order', 'foreignKey', 'dependent'), - 'hasMany' => array('className', 'conditions', 'order', 'foreignKey', 'fields', 'dependent', 'exclusive', 'finderQuery', 'counterQuery'), + var $__associationKeys = array('belongsTo' => array('className', 'conditions', 'order', 'foreignKey', 'counterCache'), + 'hasOne' => array('className', 'conditions', 'order', 'foreignKey', 'dependent'), + 'hasMany' => array('className', 'conditions', 'order', 'foreignKey', 'fields', 'dependent', 'exclusive', 'finderQuery', 'counterQuery'), 'hasAndBelongsToMany' => array('className', 'joinTable', 'fields', 'foreignKey', 'associationForeignKey', 'conditions', 'order', 'uniq', 'finderQuery', 'deleteQuery', 'insertQuery') ); @@ -1250,11 +1250,11 @@ class Model extends Object } $queryData = array( - 'conditions' => $conditions, - 'fields' => $fields, - 'joins' => array(), - 'limit' => $limit_str, - 'order' => $order + 'conditions' => $conditions, + 'fields' => $fields, + 'joins' => array(), + 'limit' => $limit_str, + 'order' => $order ); if (!$this->beforeFind($queryData)) diff --git a/cake/libs/model/model_php5.php b/cake/libs/model/model_php5.php index 5efe21bf7..7818e0e8b 100644 --- a/cake/libs/model/model_php5.php +++ b/cake/libs/model/model_php5.php @@ -249,9 +249,9 @@ class Model extends Object * * @var array */ - var $__associationKeys = array('belongsTo' => array('className', 'conditions', 'order', 'foreignKey', 'counterCache'), - 'hasOne' => array('className', 'conditions', 'order', 'foreignKey', 'dependent'), - 'hasMany' => array('className', 'conditions', 'order', 'foreignKey', 'fields', 'dependent', 'exclusive', 'finderQuery', 'counterQuery'), + var $__associationKeys = array('belongsTo' => array('className', 'conditions', 'order', 'foreignKey', 'counterCache'), + 'hasOne' => array('className', 'conditions', 'order', 'foreignKey', 'dependent'), + 'hasMany' => array('className', 'conditions', 'order', 'foreignKey', 'fields', 'dependent', 'exclusive', 'finderQuery', 'counterQuery'), 'hasAndBelongsToMany' => array('className', 'joinTable', 'fields', 'foreignKey', 'associationForeignKey', 'conditions', 'order', 'uniq', 'finderQuery', 'deleteQuery', 'insertQuery') ); @@ -1246,11 +1246,11 @@ class Model extends Object } $queryData = array( - 'conditions' => $conditions, - 'fields' => $fields, - 'joins' => array(), - 'limit' => $limit_str, - 'order' => $order + 'conditions' => $conditions, + 'fields' => $fields, + 'joins' => array(), + 'limit' => $limit_str, + 'order' => $order ); if (!$this->beforeFind($queryData)) diff --git a/cake/libs/session.php b/cake/libs/session.php index 1f8fa3e3b..db8c1157e 100644 --- a/cake/libs/session.php +++ b/cake/libs/session.php @@ -135,7 +135,7 @@ class CakeSession extends Object if (!isset($_SESSION)) { - $this->__begin(); + $this->__begin(); } $this->__checkValid(); @@ -298,9 +298,9 @@ class CakeSession extends Object */ function __destroy($key) { - $db =& ConnectionManager::getDataSource('default'); - $db->execute("DELETE FROM ".$db->name('cake_sessions')." WHERE ".$db->name('cake_sessions.id')." = ".$db->value($key, 'integer')); - return true; + $db =& ConnectionManager::getDataSource('default'); + $db->execute("DELETE FROM ".$db->name('cake_sessions')." WHERE ".$db->name('cake_sessions.id')." = ".$db->value($key, 'integer')); + return true; } /** @@ -334,9 +334,9 @@ class CakeSession extends Object */ function __gc($expires) { - $db =& ConnectionManager::getDataSource('default'); - $db->execute("DELETE FROM ".$db->name('cake_sessions')." WHERE ".$db->name('cake_sessions.expires')." < " . $db->value(time())); - return true; + $db =& ConnectionManager::getDataSource('default'); + $db->execute("DELETE FROM ".$db->name('cake_sessions')." WHERE ".$db->name('cake_sessions.expires')." < " . $db->value(time())); + return true; } /** @@ -506,14 +506,14 @@ class CakeSession extends Object $row = $db->query("SELECT ".$db->name('cake_sessions.data')." FROM ".$db->name('cake_sessions')." WHERE ".$db->name('cake_sessions.id')." = ".$db->value($key), false); - if ($row && $row[0]['cake_sessions']['data']) - { - return $row[0]['cake_sessions']['data']; - } - else - { - return false; - } + if ($row && $row[0]['cake_sessions']['data']) + { + return $row[0]['cake_sessions']['data']; + } + else + { + return false; + } } /** @@ -625,33 +625,33 @@ class CakeSession extends Object switch (CAKE_SECURITY) { case 'high': - $factor = 10; - break; - case 'medium': - $factor = 100; - break; - case 'low': - $factor = 300; - break; + $factor = 10; + break; + case 'medium': + $factor = 100; + break; + case 'low': + $factor = 300; + break; - default: - $factor = 10; - break; + default: + $factor = 10; + break; } $expires = time() + CAKE_SESSION_TIMEOUT * $factor; - $row = $db->query("SELECT COUNT(id) AS count FROM ".$db->name('cake_sessions')." WHERE ".$db->name('cake_sessions.id')." = ".$db->value($key), false); + $row = $db->query("SELECT COUNT(id) AS count FROM ".$db->name('cake_sessions')." WHERE ".$db->name('cake_sessions.id')." = ".$db->value($key), false); - if($row[0][0]['count'] > 0) - { - $db->execute("UPDATE ".$db->name('cake_sessions')." SET ".$db->name('cake_sessions.data')." = ".$db->value($value).", ".$db->name('cake_sessions.expires')." = ".$db->value($expires)." WHERE ".$db->name('cake_sessions.id')." = ".$db->value($key)); - } - else - { - $db->execute("INSERT INTO ".$db->name('cake_sessions')." (".$db->name('cake_sessions.data').",".$db->name('cake_sessions.expires').",".$db->name('cake_sessions.id').") VALUES (".$db->value($value).", ".$db->value($expires).", ".$db->value($key).")"); - } - return true; + if($row[0][0]['count'] > 0) + { + $db->execute("UPDATE ".$db->name('cake_sessions')." SET ".$db->name('cake_sessions.data')." = ".$db->value($value).", ".$db->name('cake_sessions.expires')." = ".$db->value($expires)." WHERE ".$db->name('cake_sessions.id')." = ".$db->value($key)); + } + else + { + $db->execute("INSERT INTO ".$db->name('cake_sessions')." (".$db->name('cake_sessions.data').",".$db->name('cake_sessions.expires').",".$db->name('cake_sessions.id').") VALUES (".$db->value($value).", ".$db->value($expires).", ".$db->value($key).")"); + } + return true; } } ?> \ No newline at end of file diff --git a/cake/libs/view/helpers/ajax.php b/cake/libs/view/helpers/ajax.php index e99a71864..bd07ad39d 100644 --- a/cake/libs/view/helpers/ajax.php +++ b/cake/libs/view/helpers/ajax.php @@ -68,7 +68,7 @@ class AjaxHelper extends Helper * * @var array */ - var $dragOptions = array('handle', 'revert', 'constraint', 'change'); + var $dragOptions = array('handle', 'revert', 'constraint', 'change', 'ghosting'); /** * Options for droppable. @@ -359,7 +359,7 @@ class AjaxHelper extends Helper $htmlOptions['onclick'] = "return false;"; return $this->Html->submit($title, $htmlOptions) . - $this->Javascript->event('"'.$htmlOptions['id'].'"', 'click', $this->remoteFunction($options)); + $this->Javascript->event('"'.$htmlOptions['id'].'"', 'click', $this->remoteFunction($options)); } /** @@ -673,9 +673,9 @@ class AjaxHelper extends Helper /** * Returns a string of JavaScript with the given option data as a JavaScript options hash. * - * @param array $options Options in the shape of keys and values - * @param array $acceptable Array of legal keys in this options context - * @return string String of Javascript array definition + * @param array $options Options in the shape of keys and values + * @param array $acceptable Array of legal keys in this options context + * @return string String of Javascript array definition */ function _buildOptions ($options, $acceptable) { if(is_array($options)) @@ -703,7 +703,7 @@ class AjaxHelper extends Helper * * @param string $klass Name of JavaScript class * @param string $name - * @param array $options Ajax options + * @param array $options Ajax options * @return string Formatted JavaScript */ function _buildObserver ($klass, $name, $options=null) @@ -744,8 +744,8 @@ class AjaxHelper extends Helper /** * Returns a string of JavaScript with a string representation of given options array. * - * @param array $options Ajax options array - * @param array $stringOpts Options as strings in an array + * @param array $options Ajax options array + * @param array $stringOpts Options as strings in an array * @access private * @return array */ diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 3b0fd8204..73bef9891 100644 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -86,8 +86,8 @@ class FormHelper extends Helper { return true; } - else - { + else + { return false; } } @@ -136,7 +136,7 @@ class FormHelper extends Helper * @param bool $required True if this field is a required field. * @param string $errorMsg Text that will appear if an error has occurred. * @param int $size Size attribute for INPUT element - * @param array $htmlOptions HTML options array. + * @param array $htmlOptions HTML options array. * @return string The formatted INPUT element, with a label and wrapped in a div. */ function generateInputDiv($tagName, $prompt, $required=false, $errorMsg=null, $size=20, $htmlOptions=null ) @@ -173,7 +173,7 @@ class FormHelper extends Helper * @param string $prompt Text that will appear in the label field. * @param bool $required True if this field is a required field. * @param string $errorMsg Text that will appear if an error has occurred. - * @param array $htmlOptions HTML options array. + * @param array $htmlOptions HTML options array. * @return string The formatted checkbox div */ function generateCheckboxDiv($tagName, $prompt, $required=false, $errorMsg=null, $htmlOptions=null ) @@ -288,7 +288,7 @@ class FormHelper extends Helper * @param string $errorMsg ext that will appear if an error has occurred. * @param integer $cols Number of columns. * @param integer $rows Number of rows. - * @param array $htmlOptions HTML options array. + * @param array $htmlOptions HTML options array. * @return string The formatted TEXTAREA element, wrapped in a div. */ function generateAreaDiv($tagName, $prompt, $required=false, $errorMsg=null, $cols=60, $rows=10, $htmlOptions=null ) @@ -322,15 +322,15 @@ class FormHelper extends Helper /** * Returns a formatted SELECT tag for HTML FORMs. * - * @param string $tagName This should be "Modelname/fieldname" - * @param string $prompt Text that will appear in the label field - * @param array $options Options to be contained in SELECT element - * @param string $selected Currently selected item - * @param array $selectAttr Array of HTML attributes for the SELECT element - * @param array $optionAttr Array of HTML attributes for the OPTION elements - * @param bool $required True if this field is required - * @param string $errorMsg Text that will appear if an error has occurred - * @return string The formatted INPUT element, wrapped in a div + * @param string $tagName This should be "Modelname/fieldname" + * @param string $prompt Text that will appear in the label field + * @param array $options Options to be contained in SELECT element + * @param string $selected Currently selected item + * @param array $selectAttr Array of HTML attributes for the SELECT element + * @param array $optionAttr Array of HTML attributes for the OPTION elements + * @param bool $required True if this field is required + * @param string $errorMsg Text that will appear if an error has occurred + * @return string The formatted INPUT element, wrapped in a div */ function generateSelectDiv($tagName, $prompt, $options, $selected=null, $selectAttr=null, $optionAttr=null, $required=false, $errorMsg=null) { @@ -361,9 +361,9 @@ class FormHelper extends Helper /** * Returns a formatted submit widget for HTML FORMs. * - * @param string $displayText Text that will appear on the widget - * @param array $htmlOptions HTML options array - * @return string The formatted submit widget + * @param string $displayText Text that will appear on the widget + * @param array $htmlOptions HTML options array + * @return string The formatted submit widget */ function generateSubmitDiv($displayText, $htmlOptions = null) { diff --git a/cake/libs/view/helpers/html.php b/cake/libs/view/helpers/html.php index 3112da346..b2c71e7f3 100644 --- a/cake/libs/view/helpers/html.php +++ b/cake/libs/view/helpers/html.php @@ -143,7 +143,7 @@ class HtmlHelper extends Helper * + '/' - the method will find base URL of application. * + A combination of controller/action - the method will find url for it. * - * @param string $url Cake-relative URL, like "/products/edit/92" or "/presidents/elect/4" + * @param string $url Cake-relative URL, like "/products/edit/92" or "/presidents/elect/4" * @param boolean $return Wheter this method should return a value or * output it. This overrides AUTO_OUTPUT. * @return mixed Either string or boolean value, depends on AUTO_OUTPUT @@ -154,8 +154,8 @@ function url($url = null, $return = false) $base = $this->base; if($this->plugin != null) { - $base = preg_replace('/'.$this->plugin.'/', '', $this->base); - $base = str_replace('//','', $base); + $base = preg_replace('/'.$this->plugin.'/', '', $this->base); + $base = str_replace('//','', $base); $pos1 = strrpos($base, '/'); $char = strlen($base) -1; if($pos1 == $char) @@ -188,7 +188,7 @@ function url($url = null, $return = false) * If the $url is empty, $title is used instead. * * @param string $title The content of the A tag. - * @param string $url Cake-relative URL, or external URL (starts with http://) + * @param string $url Cake-relative URL, or external URL (starts with http://) * @param array $htmlAttributes Array of HTML attributes. * @param string $confirmMessage Confirmation message. * @param boolean $escapeTitle Whether or not the text in the $title variable should be HTML escaped. @@ -346,17 +346,17 @@ function url($url = null, $return = false) if (isset($htmlAttributes['value'])) { - $htmlAttributes['checked'] = ($htmlAttributes['value'] == $value)? 'checked': null; - if ($htmlAttributes['checked'] == '0') { - $notCheckedValue = -1; - } + $htmlAttributes['checked'] = ($htmlAttributes['value'] == $value)? 'checked': null; + if ($htmlAttributes['checked'] == '0') { + $notCheckedValue = -1; + } } else { $model = new $this->model; $db =& ConnectionManager::getDataSource($model->useDbConfig); $value = $db->boolean($value); - $htmlAttributes['checked'] = $value? 'checked': null; + $htmlAttributes['checked'] = $value? 'checked': null; $htmlAttributes['value'] = 1; } @@ -420,11 +420,11 @@ function url($url = null, $return = false) { if(count($this->_crumbs)) { - $out = array(); - if($startText) - { - $out[] = $this->link($startText, '/'); - } + $out = array(); + if($startText) + { + $out[] = $this->link($startText, '/'); + } foreach ($this->_crumbs as $crumb) { $out[] = $this->link($crumb[0], $crumb[1]); @@ -532,8 +532,8 @@ function url($url = null, $return = false) * Creates a set of radio widgets. * * @param string $fieldName Name of a field, like this "Modelname/fieldname" - * @param array $options Radio button options array - * @param array $inbetween String that separates the radio buttons. + * @param array $options Radio button options array + * @param array $inbetween String that separates the radio buttons. * @param array $htmlAttributes Array of HTML attributes. * @param boolean $return Wheter this method should return a value * or output it. This overrides AUTO_OUTPUT. @@ -562,9 +562,9 @@ function url($url = null, $return = false) /** * Returns a row of formatted and named TABLE headers. * - * @param array $names Array of tablenames. - * @param array $trOptions HTML options for TR elements. - * @param array $thOptions HTML options for TH elements. + * @param array $names Array of tablenames. + * @param array $trOptions HTML options for TR elements. + * @param array $thOptions HTML options for TH elements. * @param boolean $return Wheter this method should return a value * @return string */ @@ -583,11 +583,11 @@ function url($url = null, $return = false) /** * Returns a formatted string of table rows (TR's with TD's in them). * - * @param array $data Array of table data - * @param array $oddTrOptions HTML options for odd TR elements - * @param array $evenTrOptions HTML options for even TR elements + * @param array $data Array of table data + * @param array $oddTrOptions HTML options for odd TR elements + * @param array $evenTrOptions HTML options for even TR elements * @param boolean $return Wheter this method should return a value - * @return string Formatted HTML + * @return string Formatted HTML */ function tableCells($data, $oddTrOptions=null, $evenTrOptions=null, $return=false) { @@ -616,7 +616,7 @@ function url($url = null, $return = false) /** * Returns value of $fieldName. Null if the tag does not exist. * - * @param string $fieldName Fieldname as "Modelname/fieldname" string + * @param string $fieldName Fieldname as "Modelname/fieldname" string * @return unknown Value of the named tag. */ function tagValue ($fieldName) @@ -638,8 +638,8 @@ function url($url = null, $return = false) /** * Returns false if given FORM field has no errors. Otherwise it returns the constant set in the array Model->validationErrors. * - * @param string $model Model name as string - * @param string $field Fieldname as string + * @param string $model Model name as string + * @param string $field Fieldname as string * @return boolean True on errors. */ function tagIsInvalid ($model, $field) @@ -682,8 +682,8 @@ function url($url = null, $return = false) /** * Returns a formatted error message for given FORM field, NULL if no errors. * - * @param string $field A field name, like "Modelname/fieldname" - * @param string $text Error message + * @param string $field A field name, like "Modelname/fieldname" + * @param string $text Error message * @return string If there are errors this method returns an error message, else NULL. */ function tagErrorMsg ($field, $text) diff --git a/cake/libs/view/helpers/time.php b/cake/libs/view/helpers/time.php index cb73616c8..efab5def0 100644 --- a/cake/libs/view/helpers/time.php +++ b/cake/libs/view/helpers/time.php @@ -191,7 +191,7 @@ class TimeHelper extends Helper * @return boolean True if datetime string is within current year */ function isThisYear ($date_string, $return = false) - { + { $date = $this->fromString($date_string); $ret = date('Y', $date) == date('Y', time()); @@ -207,7 +207,7 @@ class TimeHelper extends Helper * @return boolean True if datetime string was yesterday */ function wasYesterday ($date_string, $return = false) - { + { $date = $this->fromString($date_string); $ret = date('Y-m-d', $date) == date('Y-m-d', strtotime('yesterday')); @@ -223,7 +223,7 @@ class TimeHelper extends Helper * @return boolean True if datetime string was yesterday */ function isTomorrow ($date_string, $return = false) - { + { $date = $this->fromString($date_string); $ret = date('Y-m-d', $date) == date('Y-m-d', strtotime('tomorrow')); @@ -239,7 +239,7 @@ class TimeHelper extends Helper * @return int Unix timestamp */ function toUnix ($date_string, $return = false) - { + { $ret = strtotime($date_string); return $this->output($ret, $return); @@ -254,7 +254,7 @@ class TimeHelper extends Helper * @return string Formatted date string */ function toAtom ($date_string, $return = false) - { + { $date = $this->fromString($date_string); $ret = date('Y-m-d\TH:i:s\Z', $date); @@ -380,7 +380,7 @@ class TimeHelper extends Helper * @param boolean $return Whether this method should return a value * or output it. This overrides AUTO_OUTPUT. * @return string Relative time string. - * @see timeAgoInWords + * @see timeAgoInWords */ function relativeTime ($datetime_string, $format = 'j/n/y', $return = false) { diff --git a/cake/libs/view/templates/layouts/default.thtml b/cake/libs/view/templates/layouts/default.thtml index 018ae438b..ea7513f78 100644 --- a/cake/libs/view/templates/layouts/default.thtml +++ b/cake/libs/view/templates/layouts/default.thtml @@ -28,50 +28,51 @@ -CakePHP : A Rapid Development Framework :: <?php echo $title_for_layout?> +CakePHP : The PHP Rapid Development Framework :: <?php echo $title_for_layout?> charset('UTF-8')?> -css('cake.default')?> - +css('cake.basic', 'stylesheet', array("media"=>"all" ));?> +css('cake.forms', 'stylesheet', array("media"=>"all" ));?> - -
- -
- controller->Session)) $this->controller->Session->flash(); ?> - -
- - -
+ +
+ +
+ controller->Session->check('Message.flash')) $this->controller->Session->flash(); ?> + +
+
+ + +
\ No newline at end of file diff --git a/cake/libs/view/templates/pages/home.thtml b/cake/libs/view/templates/pages/home.thtml index b6543119e..c0b63fe5e 100644 --- a/cake/libs/view/templates/pages/home.thtml +++ b/cake/libs/view/templates/pages/home.thtml @@ -35,18 +35,18 @@

CakeisConnected() ? ' is able to' : ' is not able to';?> connect to the database.


-

CakePHP

+

CakePHP

If you plan to upgrade from an older version, you may also want to read the changelog

-

Editing this Page

+

Editing this Page

-To change the content of this page, create: /app/views/pages/home.thtml.
-To change its layout, create: /app/views/layouts/default.thtml.
+To change the content of this page, create: /app/views/pages/home.thtml.
+To change its layout, create: /app/views/layouts/default.thtml.
See the wiki for more info
-You can also add some CSS styles for your pages at: app/webroot/css/. +You can also add some CSS styles for your pages at: app/webroot/css/.

-

More about Cake

+

More about Cake

CakePHP is a rapid development framework for PHP which uses commonly known design patterns like Active Record, Association Data Mapping, Front Controller and MVC. @@ -56,24 +56,24 @@ Our primary goal is to provide a structured framework that enables PHP users at to rapidly develop robust web applications, without any loss to flexibility.

\ No newline at end of file diff --git a/cake/libs/view/view.php b/cake/libs/view/view.php index 8ad65b5b3..b0cce925e 100644 --- a/cake/libs/view/view.php +++ b/cake/libs/view/view.php @@ -246,9 +246,9 @@ class View extends Object * Renders view for given action and layout. If $file is given, that is used * for a view filename (e.g. customFunkyView.thtml). * - * @param string $action Name of action to render for - * @param string $layout Layout to use - * @param string $file Custom filename for view + * @param string $action Name of action to render for + * @param string $layout Layout to use + * @param string $file Custom filename for view */ function render($action=null, $layout=null, $file=null) { @@ -392,9 +392,9 @@ class View extends Object * Element. * * @link http://wiki.cakephp.org/docs:view:renderelement - * @param string $name Name of template file in the/app/views/elements/ folder - * @param array $params Array of data to be made available to the for rendered view (i.e. the Element) - * @return string Rendered output + * @param string $name Name of template file in the/app/views/elements/ folder + * @param array $params Array of data to be made available to the for rendered view (i.e. the Element) + * @return string Rendered output */ function renderElement($name, $params=array()) { @@ -495,7 +495,7 @@ class View extends Object /** * Sets layout to be used when rendering. * - * @param string $layout Name of layout. + * @param string $layout Name of layout. */ function setLayout($layout) { @@ -505,9 +505,9 @@ class View extends Object /** * Displays an error page to the user. Uses layouts/error.html to render the page. * - * @param int $code HTTP Error code (for instance: 404) - * @param string $name Name of the error (for instance: Not Found) - * @param string $message Error message as a web page + * @param int $code HTTP Error code (for instance: 404) + * @param string $name Name of the error (for instance: Not Found) + * @param string $message Error message as a web page */ function error ($code, $name, $message) { diff --git a/cake/scripts/bake.php b/cake/scripts/bake.php index d2be36b69..870e7f933 100644 --- a/cake/scripts/bake.php +++ b/cake/scripts/bake.php @@ -32,9 +32,11 @@ ini_set('display_errors', '1'); ini_set('error_reporting', '7'); $app = 'app'; -$core = null; $root = dirname(dirname(dirname(__FILE__))); +$core = null; $here = $argv[0]; +$help = null; +$project = null; for ($i = 1; $i < count($argv); $i += 2) { @@ -50,6 +52,14 @@ for ($i = 1; $i < count($argv); $i += 2) case '-root': $root = $argv[$i + 1]; break; + case '-help': + case '-h': + $help = true; + break; + case '-project': + $project = true; + $projectPath = $argv[$i + 1]; + break; } } @@ -69,7 +79,7 @@ if(function_exists('ini_set')) require_once (ROOT.'cake'.DS.'basics.php'); require_once (ROOT.'cake'.DS.'config'.DS.'paths.php'); require_once (ROOT.'cake'.DS.'dispatcher.php'); -require_once (CONFIGS.'core.php'); +require_once (ROOT.'cake'.DS.'scripts'.DS.'templates'.DS.'skel'.DS.'config'.DS.'core.php'); uses ('inflector'); uses ('model'.DS.'model'); @@ -85,1060 +95,1186 @@ uses(DS.'controller'.DS.'scaffold'); $pattyCake = new Bake(); +if($help === true) +{ + $pattyCake->help(); + exit(); +} + +if($project === true) +{ + $pattyCake->project($projectPath); + exit(); +} + $pattyCake->main(); + class Bake { - var $stdin; - var $stdout; - var $stderr; + var $stdin; + var $stdout; + var $stderr; + var $lowCtrl = null; + var $interactive = false; - function __construct() - { - $this->stdin = fopen('php://stdin', 'r'); + function __construct() + { + $this->stdin = fopen('php://stdin', 'r'); $this->stdout = fopen('php://stdout', 'w'); $this->stderr = fopen('php://stderr', 'w'); - } - - function Bake() - { - return $this->__construct(); - } - - function main() - { - $this->stdout(''); - $this->stdout('____ ____ _ _ ____ ___ _ _ ___ ___ ____ _ _ ____ '); - $this->stdout('| |__| |_/ |___ |__] |__| |__] |__] |__| |_/ |___ '); - $this->stdout('|___ | | | \_ |___ | | | | |__] | | | \_ |___ '); - $this->hr(); - - if(!file_exists(CONFIGS.'database.php')) - { - $this->stdout(''); - $this->stdout(''); - $this->stdout('Your database configuration was not found. Take a moment to create one:'); - $this->stdout(''); - $this->stdout(''); - $this->doDbConfig(); - } - - require_once (CONFIGS.'database.php'); - - $this->stdout('[M]odel'); - $this->stdout('[C]ontroller'); - $this->stdout('[V]iew'); - - $invalidSelection = true; - - while ($invalidSelection) - { - - $classToBake = strtoupper($this->getInput('Please select a class to Bake:', array('M', 'V', 'C'))); - - switch($classToBake) - { - case 'M': - $invalidSelection = false; - $this->doModel(); - break; - case 'V': - $invalidSelection = false; - $this->doView(); - break; - case 'C': - $invalidSelection = false; - $this->doController(); - break; - default: - $this->stdout('You have made an invalid selection. Please choose a type of class to Bake by entering M, V, or C.'); - } - } - } - - /*---- ----*/ - - function doDbConfig() - { - $this->hr(); - $this->stdout('Database Configuration Bake:'); - $this->hr(); - - $driver = 'mysql'; - $connect = 'mysql_pconnect'; - - $host = ''; - - while ($host == '') - { - $host = $this->getInput('What is the hostname for the database server?', null, 'localhost'); - - if ($host == '') - { - $this->stdout('The host name you supplied was empty. Please supply a hostname.'); - } - } - - $login = ''; - - while ($login == '') - { - $login = $this->getInput('What is the database username?'); - - if ($login == '') - { - $this->stdout('The database username you supplied was empty. Please try again.'); - } - } - - $password = ''; - - while ($password == '') - { - $password = $this->getInput('What is the database password?'); - - if ($password == '') - { - $this->stdout('The password you supplied was empty. Please try again.'); - } - } - - $database = ''; - - while ($database == '') - { - $database = $this->getInput('What is the name of the database you will be using?'); - - if ($database == '') - { - $this->stdout('The database name you supplied was empty. Please try again.'); - } - } - - $this->stdout(''); - $this->hr(); - $this->stdout('The following database configuration will be created:'); - $this->hr(); - $this->stdout("Host: $host"); - $this->stdout("User: $login"); - $this->stdout("Pass: " . str_repeat('*', strlen($password))); - $this->stdout("Database: $database"); - $this->hr(); - - $looksGood = $this->getInput('Look okay?', array('y', 'n'), 'y'); - - if (strtolower($looksGood) == 'y' || strtolower($looksGood) == 'yes') - { - $this->bakeDbConfig($host, $login, $password, $database); - } - else - { - $this->stdout('Bake Aborted.'); - } - } - - function doModel() - { - $this->hr(); - $this->stdout('Model Bake:'); - $this->hr(); - - $dbConnection = 'default'; - - /*$usingDefault = $this->getInput('Will your model be using a database connection setting other than the default?'); - if (strtolower($usingDefault) == 'y' || strtolower($usingDefault) == 'yes') - { - $dbConnection = $this->getInput('Please provide the name of the connection you wish to use.'); - }*/ - - $modelName = ''; - - $db =& ConnectionManager::getDataSource($dbConnection); - $tables = $db->listSources(); - $inflect = new Inflector(); - - $this->stdout('Possible models based on your current database:'); - - for ($i = 0; $i < count($tables); $i++) - { - $this->stdout($i + 1 . ". " . $inflect->camelize($inflect->singularize($tables[$i]))); - } - - while ($modelName == '') - { - $modelName = $this->getInput('Enter a number from the list above, or type in the name of another model.'); - - if ($modelName == '' || intval($modelName) > $i) - { - $this->stdout('Error:'); - $this->stdout("The model name you supplied was empty, or the number \nyou selected was not an option. Please try again."); - $modelName = ''; - } - } - - if (intval($modelName) > 0 && intval($modelName) <= $i ) - { - $modelClassName = $inflect->camelize($inflect->singularize($tables[$modelName - 1])); - $modelTableName = $tables[intval($modelName) - 1]; - } - else - { - $modelClassName = $inflect->camelize($modelName); - - $this->stdout("\nGiven your model named '$modelClassName', Cake would expect a database table named '" . $inflect->pluralize($modelName) . "'."); - $tableIsGood = $this->getInput('Is this correct?', array('y','n'), 'y'); - - if (strtolower($tableIsGood) == 'n' || strtolower($tableIsGood) == 'no') - { - $modelTableName = $this->getInput('What is the name of the table (enter "null" to use NO table)?'); - } - } - - $wannaDoValidation = $this->getInput('Would you like to supply validation criteria for the fields in your model?', array('y','n'), 'y'); - $validate = array(); - - $tempModel = new Model(false, $modelTableName); - $modelFields = $db->describe($tempModel); - - if (array_search($modelTableName, $tables) !== false && (strtolower($wannaDoValidation) == 'y' || strtolower($wannaDoValidation) == 'yes')) - { - foreach($modelFields as $field) - { - $this->stdout(''); - $prompt .= 'Name: ' . $field['name'] . "\n"; - $prompt .= 'Type: ' . $field['type'] . "\n"; - $prompt .= '---------------------------------------------------------------'."\n"; - $prompt .= 'Please select one of the following validation options:'."\n"; - $prompt .= '---------------------------------------------------------------'."\n"; - $prompt .= "1- VALID_NOT_EMPTY\n"; - $prompt .= "2- VALID_EMAIL\n"; - $prompt .= "3- VALID_NUMBER\n"; - $prompt .= "4- VALID_YEAR\n"; - $prompt .= "5- Do not do any validation on this field.\n\n"; - $prompt .= "... or enter in a valid regex validation string.\n\n"; - - if($field['name'] == 'id' || $field['name'] == 'created' || $field['name'] == 'modified') - { - $validation = $this->getInput($prompt, null, '5'); - } - else - { - $validation = $this->getInput($prompt, null, '1'); - } - - switch ($validation) { - case '1': - $validate[$field['name']] = 'VALID_NOT_EMPTY'; - break; - case '2': - $validate[$field['name']] = 'VALID_EMAIL'; - break; - case '3': - $validate[$field['name']] = 'VALID_NUMBER'; - break; - case '4': - $validate[$field['name']] = 'VALID_YEAR'; - break; - case '5': - break; - default: - $validate[$field['name']] = $validation; - break; - } - } - } - - $modelTableName == null ? $modelTableName = $inflect->pluralize($modelName) : $modelTableName = $modelTableName; - - $wannaDoAssoc = $this->getInput('Would you like define model associations (hasMany, hasOne, belongsTo, etc.)?', array('y','n'), 'y'); - if((strtolower($wannaDoAssoc) == 'y' || strtolower($wannaDoAssoc) == 'yes')) - { - $this->stdout('One moment while I try to detect any associations...'); - - //Look for belongsTo - foreach($modelFields as $field) - { - $offset = strpos($field['name'], '_id'); - - if($offset !== false) - { - $belongsToClasses[] = $inflect->camelize(substr($field['name'], 0, $offset)); - } - } - - //Look for hasOne and hasMany and hasAndBelongsToMany - foreach($tables as $table) - { - $tempModelOthers = new Model(false, $table); - $modelFieldsTemp = $db->describe($tempModelOthers); - - foreach($modelFieldsTemp as $field) - { - if($field['name'] == $inflect->singularize($modelTableName).'_id') - { - $hasOneClasses[] = $inflect->camelize($inflect->singularize($table)); - $hasManyClasses[] = $inflect->camelize($inflect->singularize($table)); - } - } - - $offset = strpos($table, $modelTableName . '_'); - if($offset !== false) - { - $offset = strlen($modelTableName . '_'); - $hasAndBelongsToManyClasses[] = $inflect->camelize($inflect->singularize(substr($table, $offset))); - } - - $offset = strpos($table, '_' . $modelTableName); - if ($offset !== false) - { - $hasAndBelongsToManyClasses[] = $inflect->camelize($inflect->singularize(substr($table, 0, $offset))); - } - } - - $this->stdout('Done.'); - - $this->hr(); - - //if none found... - if(count($hasOneClasses) < 1 && count($hasManyClasses) < 1 && count($hasAndBelongsToManyClasses) < 1 && count($belongsToClasses)) - { - $this->stdout('None found.'); - } - else - { - $this->stdout('Please confirm the following associations:'); - $this->hr(); - - if(count($belongsToClasses)) - { - for($i = 0; $i < count($belongsToClasses); $i++) - { - $response = $this->getInput("$modelClassName belongsTo {$belongsToClasses[$i]}?", array('y','n'), 'y'); - if($response == 'y') - { - $modelAssociations['belongsTo'][] = $belongsToClasses[$i]; - } - } - } - - if(count($hasOneClasses)) - { - for($i = 0; $i < count($hasOneClasses); $i++) - { - $response = $this->getInput("$modelClassName hasOne {$hasOneClasses[$i]}?", array('y','n'), 'y'); - if($response == 'y') - { - $modelAssociations['hasOne'][] = $hasOneClasses[$i]; - } - } - } - - if(count($hasManyClasses)) - { - for($i = 0; $i < count($hasManyClasses); $i++) - { - $response = $this->getInput("$modelClassName hasMany {$hasManyClasses[$i]}?", array('y','n'), 'y'); - if($response == 'y') - { - $modelAssociations['hasMany'][] = $hasManyClasses[$i]; - } - } - } - - if(count($hasAndBelongsToManyClasses)) - { - for($i = 0; $i < count($hasAndBelongsToManyClasses); $i++) - { - $response = $this->getInput("$modelClassName hasAndBelongsToMany {$hasAndBelongsToManyClasses[$i]}?", array('y','n'), 'y'); - if($response == 'y') - { - $modelAssociations['hasAndBelongsToMany'][] = $hasAndBelongsToManyClasses[$i]; - } - } - } - - } - - $wannaDoMoreAssoc = $this->getInput('Would you like to define some additional model associations?', array('y','n'), 'y'); - while((strtolower($wannaDoMoreAssoc) == 'y' || strtolower($wannaDoMoreAssoc) == 'yes')) - { - $assocs = array(1=>'belongsTo', 2=>'hasOne', 3=>'hasMany', 4=>'hasAndBelongsToMany'); - - $bad = true; - - while($bad) - { - $this->stdout('What is the association type?'); - $prompt = "1- belongsTo\n"; - $prompt .= "2- hasOne\n"; - $prompt .= "3- hasMany\n"; - $prompt .= "4- hasAndBelongsToMany\n"; - $assocType = intval($this->getInput($prompt, null, null)); - - if(intval($assocType) < 1 || intval($assocType) > 4) - { - $this->stdout('The selection you entered was invalid. Please enter a number between 1 and 4.'); - } - else - { - $bad = false; - } - } - - $assocClassName = $this->getInput('Classname of associated Model?'); - - $modelAssociations[$assocs[$assocType]][] = $assocClassName; - - $this->stdout("Association '$modelClassName {$assocs[$assocType]} $assocClassName' defined."); - - $wannaDoMoreAssoc = $this->getInput('Define another association?', array('y','n'), 'y'); - } - } - - $this->stdout(''); - $this->hr(); - $this->stdout('The following model will be created:'); - $this->hr(); - $this->stdout("Model Name: $modelClassName"); - $this->stdout("DB Connection: " . ($usingDefault ? 'default' : $dbConnection)); - $this->stdout("Model Table: " . $modelTableName); - $this->stdout("Validation: " . print_r($validate, true)); - - if(count($belongsToClasses) || count($hasOneClasses) || count($hasManyClasses) || count($hasAndBelongsToManyClasses)) - { - $this->stdout("Associations:"); - - if(count($modelAssociations['belongsTo'])) - { - for($i = 0; $i < count($modelAssociations['belongsTo']); $i++) - { - $this->stdout(" $modelClassName belongsTo {$modelAssociations['belongsTo'][$i]}"); - } - } - - if(count($modelAssociations['hasOne'])) - { - for($i = 0; $i < count($modelAssociations['hasOne']); $i++) - { - $this->stdout(" $modelClassName hasOne {$modelAssociations['hasOne'][$i]}"); - } - } - - if(count($modelAssociations['hasMany'])) - { - for($i = 0; $i < count($modelAssociations['hasMany']); $i++) - { - $this->stdout(" $modelClassName hasMany {$modelAssociations['hasMany'][$i]}"); - } - } - - if(count($modelAssociations['hasAndBelongsToMany'])) - { - for($i = 0; $i < count($modelAssociations['hasAndBelongsToMany']); $i++) - { - $this->stdout(" $modelClassName hasAndBelongsToMany {$modelAssociations['hasAndBelongsToMany'][$i]}"); - } - } - } - - $this->hr(); - - $looksGood = $this->getInput('Look okay?', array('y','n'), 'y'); - - if (strtolower($looksGood) == 'y' || strtolower($looksGood) == 'yes') - { - if ($inflect->camelize($inflect->singularize($modelTableName)) == $modelClassName) - { - // set it to null... - // putting $useTable in the model - // is unnecessary. - $modelTableName = null; - } - $this->bakeModel($modelClassName, $dbConnection, $modelTableName, $validate, $modelAssociations); - - if ($this->doUnitTest()) - { - $this->bakeUnitTest('model', $modelClassName); - } - } - else - { - $this->stdout('Bake Aborted.'); - } - - } - - function doView() - { - $this->hr(); - $this->stdout('View Bake:'); - $this->hr(); - - $controllerName = ''; - - $inflect = new Inflector(); - - while ($controllerName == '') - { - $controllerName = $this->getInput('Controller Name? (plural)'); - - if ($controllerName == '') - { - $this->stdout('The controller name you supplied was empty. Please try again.'); - } - } - - $controllerName = $inflect->underscore($controllerName); - - $wannaDoScaffold = $this->getInput("Would you like to create some scaffolded views (index, add, view, edit) for this controller?\nNOTE: Before doing so, you'll need to create your controller and model classes (including associated models).", array('y','n'), 'n'); - $uses = array(); - - if (strtolower($wannaDoScaffold) == 'y' || strtolower($wannaDoScaffold) == 'yes') - { - $file = CONTROLLERS . $controllerName . '_controller.php'; - - if(!file_exists($file)) - { - $this->stdout(''); - $this->stdout("The file '$file' could not be found.\nIn order to scaffold, you'll need to first create the controller. "); - $this->stdout(''); - die(); - } - else - { - require_once(CONTROLLERS . $controllerName . '_controller.php'); - $controller = $inflect->camelize($controllerName . '_controller'); - $temp = new $controller(); - - if(!in_array('Form', $temp->helpers)) - { - $temp->helpers[] = 'Form'; - } - - loadModels(); - $temp->constructClasses(); - - $fieldNames = $temp->generateFieldNames(null, false); - - uses('view'.DS.'helpers'.DS.'html'); - uses('view'.DS.'helpers'.DS.'form'); - $this->Html = new HtmlHelper(); - $this->Html->tags = $this->Html->loadConfig(); - - if(!empty($temp->{$temp->modelClass}->alias)) - { - foreach ($temp->{$temp->modelClass}->alias as $key => $value) - { - $alias[] = $key; - } - } - - //-------------------------[INDEX]-------------------------// - - $indexView .= "

List " . $inflect->pluralize($temp->modelKey) . "

\n\n"; - $indexView .= "\n"; - $indexView .= "\n"; - - foreach ($fieldNames as $fieldName) - { - $indexView .= "\t\n"; - } - - $indexView .= "\t\n"; - $indexView .= "\n"; - - $indexView .= "\n"; - - $indexView .= "\n"; - - $count = 0; - - foreach($fieldNames as $field => $value) - { - if(isset($value['foreignKey'])) - { - $otherModelKey = Inflector::underscore($value['modelKey']); - $otherControllerName = $value['controller']; - $otherModelObject =& ClassRegistry::getObject($otherModelKey); - - if(is_object($otherModelObject)) - { - $indexView .= "\t\n"; - } - else - { - $indexView .= "\t\n"; - } - $count++; - } - else - { - $indexView .= "\t\n"; - } - } - - - - $id = $temp->{$temp->modelClass}->primaryKey; - - $indexView .= "\t
".$fieldName['prompt']."Actions
getDisplayField() ."'] ?>modelClass}']['{$field}'] ?>\n"; - $indexView .= "\t\tlink('View','/$temp->viewPath/view/' . \$row['{$temp->modelClass}']['$id'])?>\n"; + $this->welcome(); + } + + function Bake() + { + return $this->__construct(); + } + + function main() + { + if(!file_exists(CONFIGS.'database.php')) + { + $this->stdout(''); + $this->stdout(''); + $this->stdout('Your database configuration was not found. Take a moment to create one:'); + $this->stdout(''); + $this->stdout(''); + $this->doDbConfig(); + } + + require_once (CONFIGS.'database.php'); + + $this->stdout('[M]odel'); + $this->stdout('[C]ontroller'); + $this->stdout('[V]iew'); + + $invalidSelection = true; + + while ($invalidSelection) + { + + $classToBake = strtoupper($this->getInput('Please select a class to Bake:', array('M', 'V', 'C'))); + + switch($classToBake) + { + case 'M': + $invalidSelection = false; + $this->doModel(); + break; + case 'V': + $invalidSelection = false; + $this->doView(); + break; + case 'C': + $invalidSelection = false; + $this->doController(); + break; + default: + $this->stdout('You have made an invalid selection. Please choose a type of class to Bake by entering M, V, or C.'); + } + } + } + + /*---- ----*/ + + function doDbConfig() + { + $this->hr(); + $this->stdout('Database Configuration Bake:'); + $this->hr(); + + $driver = 'mysql'; + $connect = 'mysql_connect'; + + $host = ''; + + while ($host == '') + { + $host = $this->getInput('What is the hostname for the database server?', null, 'localhost'); + + if ($host == '') + { + $this->stdout('The host name you supplied was empty. Please supply a hostname.'); + } + } + + $login = ''; + + while ($login == '') + { + $login = $this->getInput('What is the database username?'); + + if ($login == '') + { + $this->stdout('The database username you supplied was empty. Please try again.'); + } + } + + $password = ''; + + while ($password == '') + { + $password = $this->getInput('What is the database password?'); + + if ($password == '') + { + $this->stdout('The password you supplied was empty. Please try again.'); + } + } + + $database = ''; + + while ($database == '') + { + $database = $this->getInput('What is the name of the database you will be using?'); + + if ($database == '') + { + $this->stdout('The database name you supplied was empty. Please try again.'); + } + } + + $this->stdout(''); + $this->hr(); + $this->stdout('The following database configuration will be created:'); + $this->hr(); + $this->stdout("Host: $host"); + $this->stdout("User: $login"); + $this->stdout("Pass: " . str_repeat('*', strlen($password))); + $this->stdout("Database: $database"); + $this->hr(); + + $looksGood = $this->getInput('Look okay?', array('y', 'n'), 'y'); + + if (strtolower($looksGood) == 'y' || strtolower($looksGood) == 'yes') + { + $this->bakeDbConfig($host, $login, $password, $database); + } + else + { + $this->stdout('Bake Aborted.'); + } + } + + function doModel() + { + $this->hr(); + $this->stdout('Model Bake:'); + $this->hr(); + $this->interactive = true; + + $dbConnection = 'default'; + + /*$usingDefault = $this->getInput('Will your model be using a database connection setting other than the default?'); + if (strtolower($usingDefault) == 'y' || strtolower($usingDefault) == 'yes') + { + $dbConnection = $this->getInput('Please provide the name of the connection you wish to use.'); + }*/ + + $modelName = ''; + + $db =& ConnectionManager::getDataSource($dbConnection); + $tables = $db->listSources(); + $inflect = new Inflector(); + + $this->stdout('Possible models based on your current database:'); + + for ($i = 0; $i < count($tables); $i++) + { + $this->stdout($i + 1 . ". " . $inflect->camelize($inflect->singularize($tables[$i]))); + } + + while ($modelName == '') + { + $modelName = $this->getInput('Enter a number from the list above, or type in the name of another model.'); + + if ($modelName == '' || intval($modelName) > $i) + { + $this->stdout('Error:'); + $this->stdout("The model name you supplied was empty, or the number \nyou selected was not an option. Please try again."); + $modelName = ''; + } + } + + if (intval($modelName) > 0 && intval($modelName) <= $i ) + { + $modelClassName = $inflect->camelize($inflect->singularize($tables[$modelName - 1])); + $modelTableName = $tables[intval($modelName) - 1]; + } + else + { + $modelClassName = $inflect->camelize($modelName); + + $this->stdout("\nGiven your model named '$modelClassName', Cake would expect a database table named '" . $inflect->pluralize($modelName) . "'."); + $tableIsGood = $this->getInput('Is this correct?', array('y','n'), 'y'); + + if (strtolower($tableIsGood) == 'n' || strtolower($tableIsGood) == 'no') + { + $modelTableName = $this->getInput('What is the name of the table (enter "null" to use NO table)?'); + } + } + + $wannaDoValidation = $this->getInput('Would you like to supply validation criteria for the fields in your model?', array('y','n'), 'y'); + $validate = array(); + + $tempModel = new Model(false, $modelTableName); + $modelFields = $db->describe($tempModel); + + if (array_search($modelTableName, $tables) !== false && (strtolower($wannaDoValidation) == 'y' || strtolower($wannaDoValidation) == 'yes')) + { + foreach($modelFields as $field) + { + $this->stdout(''); + $prompt .= 'Name: ' . $field['name'] . "\n"; + $prompt .= 'Type: ' . $field['type'] . "\n"; + $prompt .= '---------------------------------------------------------------'."\n"; + $prompt .= 'Please select one of the following validation options:'."\n"; + $prompt .= '---------------------------------------------------------------'."\n"; + $prompt .= "1- VALID_NOT_EMPTY\n"; + $prompt .= "2- VALID_EMAIL\n"; + $prompt .= "3- VALID_NUMBER\n"; + $prompt .= "4- VALID_YEAR\n"; + $prompt .= "5- Do not do any validation on this field.\n\n"; + $prompt .= "... or enter in a valid regex validation string.\n\n"; + + if($field['name'] == 'id' || $field['name'] == 'created' || $field['name'] == 'modified') + { + $validation = $this->getInput($prompt, null, '5'); + } + else + { + $validation = $this->getInput($prompt, null, '1'); + } + + switch ($validation) { + case '1': + $validate[$field['name']] = 'VALID_NOT_EMPTY'; + break; + case '2': + $validate[$field['name']] = 'VALID_EMAIL'; + break; + case '3': + $validate[$field['name']] = 'VALID_NUMBER'; + break; + case '4': + $validate[$field['name']] = 'VALID_YEAR'; + break; + case '5': + break; + default: + $validate[$field['name']] = $validation; + break; + } + } + } + + $modelTableName == null ? $modelTableName = $inflect->pluralize($modelName) : $modelTableName = $modelTableName; + + $wannaDoAssoc = $this->getInput('Would you like define model associations (hasMany, hasOne, belongsTo, etc.)?', array('y','n'), 'y'); + if((strtolower($wannaDoAssoc) == 'y' || strtolower($wannaDoAssoc) == 'yes')) + { + $this->stdout('One moment while I try to detect any associations...'); + + //Look for belongsTo + foreach($modelFields as $field) + { + $offset = strpos($field['name'], '_id'); + + if($offset !== false) + { + $belongsToClasses[] = $inflect->camelize(substr($field['name'], 0, $offset)); + } + } + + //Look for hasOne and hasMany and hasAndBelongsToMany + foreach($tables as $table) + { + $tempModelOthers = new Model(false, $table); + $modelFieldsTemp = $db->describe($tempModelOthers); + + foreach($modelFieldsTemp as $field) + { + if($field['name'] == $inflect->singularize($modelTableName).'_id') + { + $hasOneClasses[] = $inflect->camelize($inflect->singularize($table)); + $hasManyClasses[] = $inflect->camelize($inflect->singularize($table)); + } + } + + $offset = strpos($table, $modelTableName . '_'); + if($offset !== false) + { + $offset = strlen($modelTableName . '_'); + $hasAndBelongsToManyClasses[] = $inflect->camelize($inflect->singularize(substr($table, $offset))); + } + + $offset = strpos($table, '_' . $modelTableName); + if ($offset !== false) + { + $hasAndBelongsToManyClasses[] = $inflect->camelize($inflect->singularize(substr($table, 0, $offset))); + } + } + + $this->stdout('Done.'); + + $this->hr(); + + //if none found... + if(count($hasOneClasses) < 1 && count($hasManyClasses) < 1 && count($hasAndBelongsToManyClasses) < 1 && count($belongsToClasses)) + { + $this->stdout('None found.'); + } + else + { + $this->stdout('Please confirm the following associations:'); + $this->hr(); + + if(count($belongsToClasses)) + { + for($i = 0; $i < count($belongsToClasses); $i++) + { + $response = $this->getInput("$modelClassName belongsTo {$belongsToClasses[$i]}?", array('y','n'), 'y'); + if($response == 'y') + { + $modelAssociations['belongsTo'][] = $belongsToClasses[$i]; + } + } + } + + if(count($hasOneClasses)) + { + for($i = 0; $i < count($hasOneClasses); $i++) + { + $response = $this->getInput("$modelClassName hasOne {$hasOneClasses[$i]}?", array('y','n'), 'y'); + if($response == 'y') + { + $modelAssociations['hasOne'][] = $hasOneClasses[$i]; + } + } + } + + if(count($hasManyClasses)) + { + for($i = 0; $i < count($hasManyClasses); $i++) + { + $response = $this->getInput("$modelClassName hasMany {$hasManyClasses[$i]}?", array('y','n'), 'y'); + if($response == 'y') + { + $modelAssociations['hasMany'][] = $hasManyClasses[$i]; + } + } + } + + if(count($hasAndBelongsToManyClasses)) + { + for($i = 0; $i < count($hasAndBelongsToManyClasses); $i++) + { + $response = $this->getInput("$modelClassName hasAndBelongsToMany {$hasAndBelongsToManyClasses[$i]}?", array('y','n'), 'y'); + if($response == 'y') + { + $modelAssociations['hasAndBelongsToMany'][] = $hasAndBelongsToManyClasses[$i]; + } + } + } + + } + + $wannaDoMoreAssoc = $this->getInput('Would you like to define some additional model associations?', array('y','n'), 'y'); + while((strtolower($wannaDoMoreAssoc) == 'y' || strtolower($wannaDoMoreAssoc) == 'yes')) + { + $assocs = array(1=>'belongsTo', 2=>'hasOne', 3=>'hasMany', 4=>'hasAndBelongsToMany'); + + $bad = true; + + while($bad) + { + $this->stdout('What is the association type?'); + $prompt = "1- belongsTo\n"; + $prompt .= "2- hasOne\n"; + $prompt .= "3- hasMany\n"; + $prompt .= "4- hasAndBelongsToMany\n"; + $assocType = intval($this->getInput($prompt, null, null)); + + if(intval($assocType) < 1 || intval($assocType) > 4) + { + $this->stdout('The selection you entered was invalid. Please enter a number between 1 and 4.'); + } + else + { + $bad = false; + } + } + + $assocClassName = $this->getInput('Classname of associated Model?'); + + $modelAssociations[$assocs[$assocType]][] = $assocClassName; + + $this->stdout("Association '$modelClassName {$assocs[$assocType]} $assocClassName' defined."); + + $wannaDoMoreAssoc = $this->getInput('Define another association?', array('y','n'), 'y'); + } + } + + $this->stdout(''); + $this->hr(); + $this->stdout('The following model will be created:'); + $this->hr(); + $this->stdout("Model Name: $modelClassName"); + $this->stdout("DB Connection: " . ($usingDefault ? 'default' : $dbConnection)); + $this->stdout("Model Table: " . $modelTableName); + $this->stdout("Validation: " . print_r($validate, true)); + + if(count($belongsToClasses) || count($hasOneClasses) || count($hasManyClasses) || count($hasAndBelongsToManyClasses)) + { + $this->stdout("Associations:"); + + if(count($modelAssociations['belongsTo'])) + { + for($i = 0; $i < count($modelAssociations['belongsTo']); $i++) + { + $this->stdout(" $modelClassName belongsTo {$modelAssociations['belongsTo'][$i]}"); + } + } + + if(count($modelAssociations['hasOne'])) + { + for($i = 0; $i < count($modelAssociations['hasOne']); $i++) + { + $this->stdout(" $modelClassName hasOne {$modelAssociations['hasOne'][$i]}"); + } + } + + if(count($modelAssociations['hasMany'])) + { + for($i = 0; $i < count($modelAssociations['hasMany']); $i++) + { + $this->stdout(" $modelClassName hasMany {$modelAssociations['hasMany'][$i]}"); + } + } + + if(count($modelAssociations['hasAndBelongsToMany'])) + { + for($i = 0; $i < count($modelAssociations['hasAndBelongsToMany']); $i++) + { + $this->stdout(" $modelClassName hasAndBelongsToMany {$modelAssociations['hasAndBelongsToMany'][$i]}"); + } + } + } + + $this->hr(); + + $looksGood = $this->getInput('Look okay?', array('y','n'), 'y'); + + if (strtolower($looksGood) == 'y' || strtolower($looksGood) == 'yes') + { + if ($inflect->camelize($inflect->singularize($modelTableName)) == $modelClassName) + { + // set it to null... + // putting $useTable in the model + // is unnecessary. + $modelTableName = null; + } + $this->bakeModel($modelClassName, $dbConnection, $modelTableName, $validate, $modelAssociations); + + if ($this->doUnitTest()) + { + $this->bakeUnitTest('model', $modelClassName); + } + } + else + { + $this->stdout('Bake Aborted.'); + } + + } + + function doView() + { + $this->hr(); + $this->stdout('View Bake:'); + $this->hr(); + $uses = array(); + $wannaDoScaffold = 'y'; + $controllerName = ''; + + $inflect = new Inflector(); + + while ($controllerName == '') + { + $controllerName = $this->getInput('Controller Name? (plural)'); + + if ($controllerName == '') + { + $this->stdout('The controller name you supplied was empty. Please try again.'); + } + } + + $controllerName = $inflect->underscore($controllerName); + $this->lowCtrl = $controllerName; + + $doItInteractive = $this->getInput("Would you like bake to build your views interactively?\nWarning: Choosing no will overwrite {$controllerClassName} views if it exist.", array('y','n'), 'y'); + + if (strtolower($doItInteractive) == 'y' || strtolower($doItInteractive) == 'yes') + { + $this->interactive = true; + $wannaDoScaffold = $this->getInput("Would you like to create some scaffolded views (index, add, view, edit) for this controller?\nNOTE: Before doing so, you'll need to create your controller and model classes (including associated models).", array('y','n'), 'n'); + } + + if (strtolower($wannaDoScaffold) == 'y' || strtolower($wannaDoScaffold) == 'yes') + { + $file = CONTROLLERS . $controllerName . '_controller.php'; + + if(!file_exists($file)) + { + $this->stdout(''); + $this->stdout("The file '$file' could not be found.\nIn order to scaffold, you'll need to first create the controller. "); + $this->stdout(''); + die(); + } + else + { + require_once(CONTROLLERS . $controllerName . '_controller.php'); + $controller = $inflect->camelize($controllerName . '_controller'); + $temp = new $controller(); + + if(!in_array('Form', $temp->helpers)) + { + $temp->helpers[] = 'Form'; + } + + loadModels(); + $temp->constructClasses(); + + $fieldNames = $temp->generateFieldNames(null, false); + + uses('view'.DS.'helpers'.DS.'html'); + uses('view'.DS.'helpers'.DS.'form'); + $this->Html = new HtmlHelper(); + $this->Html->tags = $this->Html->loadConfig(); + + if(!empty($temp->{$temp->modelClass}->alias)) + { + foreach ($temp->{$temp->modelClass}->alias as $key => $value) + { + $alias[] = $key; + } + } + + //-------------------------[INDEX]-------------------------// + + $indexView .= "

List " . $inflect->pluralize($temp->modelKey) . "

\n\n"; + $indexView .= "\n"; + $indexView .= "\n"; + + foreach ($fieldNames as $fieldName) + { + $indexView .= "\t\n"; + } + + $indexView .= "\t\n"; + $indexView .= "\n"; + + $indexView .= "lowCtrl} as \$row): ?>\n"; + + $indexView .= "\n"; + + $count = 0; + + foreach($fieldNames as $field => $value) + { + if(isset($value['foreignKey'])) + { + $otherModelKey = Inflector::underscore($value['modelKey']); + $otherControllerName = $value['controller']; + $otherModelObject =& ClassRegistry::getObject($otherModelKey); + + if(is_object($otherModelObject)) + { + $indexView .= "\t\n"; + } + else + { + $indexView .= "\t\n"; + } + $count++; + } + else + { + $indexView .= "\t\n"; + } + } + + + + $id = $temp->{$temp->modelClass}->primaryKey; + + $indexView .= "\t\n"; + $indexView .= "\t\n"; - $indexView .= "\n"; + $indexView .= "\n"; - $indexView .= "\n"; - $indexView .= "
".$fieldName['prompt']."Actions
getDisplayField() ."'] ?>modelClass}']['{$field}'] ?>\n"; + $indexView .= "\t\tlink('View','/$temp->viewPath/view/' . \$row['{$temp->modelClass}']['$id'])?>\n"; $indexView .= "\t\tlink('Edit','/$temp->viewPath/edit/' . \$row['{$temp->modelClass}']['$id'])?>\n"; $indexView .= "\t\tlink('Delete','/$temp->viewPath/delete/' . \$row['{$temp->modelClass}']['$id'])?>\n"; - $indexView .= "\t
\n\n"; + $indexView .= "\n"; + $indexView .= "
\n\n"; - $indexView .= "\n"; + $indexView .= "\n"; - //-------------------------[VIEW]-------------------------// + //-------------------------[VIEW]-------------------------// - $modelName = $temp->modelClass; - $modelKey = Inflector::underscore($modelName); - $objModel =& ClassRegistry::getObject($modelKey); + $modelName = $temp->modelClass; + $modelKey = Inflector::underscore($modelName); + $objModel =& ClassRegistry::getObject($modelKey); - $viewView .= "

View " . $inflect->pluralize($temp->modelKey) . "

\n\n"; + $viewView .= "

View " . $inflect->pluralize($temp->modelKey) . "

\n\n"; - $viewView .= "\n"; + $viewView .= "
\n"; - $count = 0; - foreach($fieldNames as $field => $value) - { - $viewView .= "\n"; - $viewView .= "\t\n"; + $count = 0; + foreach($fieldNames as $field => $value) + { + $viewView .= "\n"; + $viewView .= "\t\n"; - if(isset($value['foreignKey'])) - { - $otherModelObject =& ClassRegistry::getObject(Inflector::underscore($objModel->tableToModel[$value['table']])); - $displayField = $otherModelObject->getDisplayField(); + if(isset($value['foreignKey'])) + { + $otherModelObject =& ClassRegistry::getObject(Inflector::underscore($objModel->tableToModel[$value['table']])); + $displayField = $otherModelObject->getDisplayField(); - $viewView .= "\t\n"; + $viewView .= "\t\n"; - $count++; - } - else - { - $viewView .= "\t\n"; - } + $count++; + } + else + { + $viewView .= "\t\n"; + } - $viewView .= "\n"; - } + $viewView .= "\n"; + } - $viewView .= "
link(\$data['{$alias[$count]}']['{$displayField}'], '/" . $inflect->underscore($value['controller']) . "/view/' . \$data['{$objModel->tableToModel[$objModel->table]}']['{$field}'])?>link(\${$this->lowCtrl}['{$alias[$count]}']['{$displayField}'], '/" . $inflect->underscore($value['controller']) . "/view/' . \${$this->lowCtrl}['{$objModel->tableToModel[$objModel->table]}']['{$field}'])?>tableToModel[$objModel->table]}']['{$field}']?>lowCtrl}['{$objModel->tableToModel[$objModel->table]}']['{$field}']?>
\n"; + $viewView .= "\n"; - $viewView .= "\n\n"; - foreach ($objModel->hasOne as $association => $relation) - { - $model = $relation['className']; - $otherModelName = $objModel->tableToModel[$objModel->{$model}->table]; - $controller = $inflect->pluralize($model); - $new = true; - $viewView .= "

Related " . $inflect->humanize($association) . "

\n"; - $viewView .= "
\n"; - $viewView .= "\n"; - $viewView .= "\t \$value): ?>\n"; - $viewView .= "\t\t
\n"; - $viewView .= "\t\t
\n"; - $viewView .= "\t\n"; - $viewView .= "\t\n"; - $viewView .= "\n"; - $viewView .= "
\n"; + foreach ($objModel->hasOne as $association => $relation) + { + $model = $relation['className']; + $otherModelName = $objModel->tableToModel[$objModel->{$model}->table]; + $controller = $inflect->pluralize($model); + $new = true; + $viewView .= "

Related " . $inflect->humanize($association) . "

\n"; + $viewView .= "
\n"; + $viewView .= "lowCtrl}['{$association}']) && is_array(\${$this->lowCtrl}['{$association}'])): ?>\n"; + $viewView .= "\tlowCtrl}['{$association}'] as \$field => \$value): ?>\n"; + $viewView .= "\t\t
\n"; + $viewView .= "\t\t
\n"; + $viewView .= "\t\n"; + $viewView .= "\t\n"; + $viewView .= "\n"; + $viewView .= "
\n"; - } + } - $relations = array_merge($objModel->hasMany, $objModel->hasAndBelongsToMany); + $relations = array_merge($objModel->hasMany, $objModel->hasAndBelongsToMany); - foreach($relations as $association => $relation) - { - $model = $relation['className']; - $count = 0; - $otherModelName = $inflect->singularize($model); - $controller = $inflect->pluralize($model); + foreach($relations as $association => $relation) + { + $model = $relation['className']; + $count = 0; + $otherModelName = $inflect->singularize($model); + $controller = $inflect->pluralize($model); - $viewView .= "\n

Related " . $inflect->humanize($inflect->pluralize($association)) . "

\n"; - $viewView .= "\n"; + $viewView .= "\n

Related " . $inflect->humanize($inflect->pluralize($association)) . "

\n"; + $viewView .= "lowCtrl}['{$association}']['0']) && is_array(\${$this->lowCtrl}['{$association}'])):?>\n"; - $viewView .= "\n"; - $viewView .= "\n"; + $viewView .= "
\n"; + $viewView .= "\n"; - $viewView .= " \$value): ?>\n"; - $viewView .= "\n"; - $viewView .= "\n"; + $viewView .= "lowCtrl}['{$association}']['0'] as \$column => \$value): ?>\n"; + $viewView .= "\n"; + $viewView .= "\n"; - $viewView .= "\n"; - $viewView .= "\n"; + $viewView .= "\n"; + $viewView .= "\n"; - $viewView .= "\n"; + $viewView .= "lowCtrl}['{$association}'] as \$row):?>\n"; - $viewView .= "\n"; + $viewView .= "\n"; - $viewView .= "\t \$value):?>\n"; - $viewView .= "\t\t\n"; - $viewView .= "\t\n"; + $viewView .= "\t \$value):?>\n"; + $viewView .= "\t\t\n"; + $viewView .= "\t\n"; - $viewView .= "controller->{$modelName}->{$association})):?>\n"; - $viewView .= "\n"; - $viewView .= "\n"; - $viewView .= "\n"; + $viewView .= "\n"; + $viewView .= "\n"; - $viewView .= "\n"; + $viewView .= "\n"; + $viewView .= "\n"; - $viewView .= "\n"; - $viewView .= "\n"; + $viewView .= "\n"; + $viewView .= "\n"; - $viewView .= "
Actions
Actions
\n"; - $viewView .= "\tlink('View', '/" . $inflect->underscore($controller) . "/view/' . \$row[\$this->controller->{$modelName}->{$association}->primaryKey])?>\n"; + $viewView .= "controller->{$modelName}->{$association})):?>\n"; + $viewView .= "\n"; + $viewView .= "\tlink('View', '/" . $inflect->underscore($controller) . "/view/' . \$row[\$this->controller->{$modelName}->{$association}->primaryKey])?>\n"; $viewView .= "\tlink('Edit', '/" . $inflect->underscore($controller) . "/edit/' . \$row[\$this->controller->{$modelName}->{$association}->primaryKey])?>\n"; $viewView .= "\tlink('Delete', '/" . $inflect->underscore($controller) . "/delete/' . \$row[\$this->controller->{$modelName}->{$association}->primaryKey])?>\n"; - $viewView .= "\n"; - $viewView .= "\tlink('View', '/" . $inflect->underscore($controller) . "/view/' . \$row[\$this->controller->{$modelName}->primaryKey])?>\n"; + $viewView .= "\n"; + $viewView .= "\tlink('View', '/" . $inflect->underscore($controller) . "/view/' . \$row[\$this->controller->{$modelName}->primaryKey])?>\n"; $viewView .= "\tlink('Edit', '/" . $inflect->underscore($controller) . "/edit/' . \$row[\$this->controller->{$modelName}->primaryKey])?>\n"; $viewView .= "\tlink('Delete', '/" . $inflect->underscore($controller) . "/delete/' . \$row[\$this->controller->{$modelName}->primaryKey])?>\n"; - $viewView .= "
\n"; - $viewView .= "\n\n"; + $viewView .= "\n"; + $viewView .= "\n\n"; - $viewView .= "\n"; - } + } - //-------------------------[ADD]-------------------------// + //-------------------------[ADD]-------------------------// - $addView .= "

New " . $temp->modelKey . "

\n"; - $addView .= ""; + $addView .= "

New " . $temp->modelKey . "

\n"; - $fields .= $this->Html->formTag('/'. $temp->viewPath . '/add') . "\n"; - $fields .= $this->generateFields($temp->generateFieldNames(null, true)); - $fields .= $this->generateSubmitDiv('Add'); + $fields .= $this->Html->formTag('/'. $temp->viewPath . '/add') . "\n"; + $fields .= $this->generateFields($temp->generateFieldNames(null, true)); + $fields .= $this->generateSubmitDiv('Add'); - $addView .= $fields; + $addView .= $fields; - $addView .= "\n"; - $addView .= "\n"; - //-------------------------[EDIT]-------------------------// + //-------------------------[EDIT]-------------------------// - $editView .= "

Edit " . $temp->modelKey . "

\n"; + $editView .= "

Edit " . $temp->modelKey . "

\n"; - $editView .= "
viewPath}/edit/tableToModel[$objModel->table]}']['$id'] ?>\" method=\"post\">\n"; + $editView .= "viewPath}/edit/lowCtrl}['{$objModel->tableToModel[$objModel->table]}']['$id'] ?>\" method=\"post\">\n"; - $fields = $this->generateFields($temp->generateFieldNames(null, true)); - $fields .= "hidden('{$objModel->name}/{$id}', array('value' => \$data['{$objModel->tableToModel[$objModel->table]}']['$id']))?>"; - $fields .= $this->generateSubmitDiv('Save'); + $fields = $this->generateFields($temp->generateFieldNames(null, true)); + $fields .= "hidden('{$objModel->name}/{$id}', array('value' => \${$this->lowCtrl}['{$objModel->tableToModel[$objModel->table]}']['$id']))?>"; + $fields .= $this->generateSubmitDiv('Save'); - $editView .= $fields; + $editView .= $fields; - $editView .= "
\n"; - $editView .= "\n"; - //------------------------------------------------------------------------------------// + //------------------------------------------------------------------------------------// - if(!file_exists(VIEWS.strtolower($controllerName))) - { - mkdir(VIEWS.strtolower($controllerName)); - } + if(!file_exists(VIEWS.strtolower($controllerName))) + { + mkdir(VIEWS.strtolower($controllerName)); + } - $filename = VIEWS . strtolower($controllerName) . DS . 'index.thtml'; - $this->createFile($filename, $indexView); + $filename = VIEWS . strtolower($controllerName) . DS . 'index.thtml'; + $this->createFile($filename, $indexView); - $filename = VIEWS . strtolower($controllerName) . DS . 'view.thtml'; - $this->createFile($filename, $viewView); + $filename = VIEWS . strtolower($controllerName) . DS . 'view.thtml'; + $this->createFile($filename, $viewView); - $filename = VIEWS . strtolower($controllerName) . DS . 'add.thtml'; - $this->createFile($filename, $addView); + $filename = VIEWS . strtolower($controllerName) . DS . 'add.thtml'; + $this->createFile($filename, $addView); - $filename = VIEWS . strtolower($controllerName) . DS . 'edit.thtml'; - $this->createFile($filename, $editView); + $filename = VIEWS . strtolower($controllerName) . DS . 'edit.thtml'; + $this->createFile($filename, $editView); - $this->hr(); - $this->stdout(''); - $this->stdout('Note:'."\n"); - $this->stdout("\t- If you're using a non-domain install, change URL paths \n\t from /controller/action to /cake_install/controller/action\n"); - $this->hr(); + $this->hr(); + $this->stdout(''); + $this->stdout('Note:'."\n"); + $this->stdout("\t- If you're using a non-domain install, change URL paths \n\t from /controller/action to /cake_install/controller/action\n"); + $this->hr(); - $this->stdout(''); - $this->stdout('View Scaffolding Complete.'."\n"); + $this->stdout(''); + $this->stdout('View Scaffolding Complete.'."\n"); - } - } - else - { - $actionName = ''; + } + } + else + { + $actionName = ''; - while ($actionName == '') - { - $actionName = $this->getInput('Action Name? (use camelCased function name)'); + while ($actionName == '') + { + $actionName = $this->getInput('Action Name? (use camelCased function name)'); - if ($actionName == '') - { - $this->stdout('The action name you supplied was empty. Please try again.'); - } - } + if ($actionName == '') + { + $this->stdout('The action name you supplied was empty. Please try again.'); + } + } - $this->stdout(''); - $this->hr(); - $this->stdout('The following view will be created:'); - $this->hr(); - $this->stdout("Controller Name: $controllerName"); - $this->stdout("Action Name: $actionName"); - $this->stdout("Path: app/views/" . strtolower($controllerName) . DS . $inflect->underscore($actionName) . '.thtml'); - $this->hr(); + $this->stdout(''); + $this->hr(); + $this->stdout('The following view will be created:'); + $this->hr(); + $this->stdout("Controller Name: $controllerName"); + $this->stdout("Action Name: $actionName"); + $this->stdout("Path: app/views/" . strtolower($controllerName) . DS . $inflect->underscore($actionName) . '.thtml'); + $this->hr(); - $looksGood = $this->getInput('Look okay?', array('y','n'), 'y'); + $looksGood = $this->getInput('Look okay?', array('y','n'), 'y'); - if (strtolower($looksGood) == 'y' || strtolower($looksGood) == 'yes') - { - $this->bakeView($controllerName, $actionName); - } - else - { - $this->stdout('Bake Aborted.'); - } - } - } + if (strtolower($looksGood) == 'y' || strtolower($looksGood) == 'yes') + { + $this->bakeView($controllerName, $actionName); + } + else + { + $this->stdout('Bake Aborted.'); + } + } + } - function doController() - { - $this->hr(); - $this->stdout('Controller Bake:'); - $this->hr(); + function doController() + { + $this->hr(); + $this->stdout('Controller Bake:'); + $this->hr(); - $controllerName = ''; + $controllerName = ''; + $uses = array(); + $helpers = array(); + $components = array(); + $wannaDoScaffolding = 'y'; + while ($controllerName == '') + { + $controllerName = $this->getInput('Controller name? Remember that Cake controller names are plural.'); - while ($controllerName == '') - { - $controllerName = $this->getInput('Controller name? Remember that Cake controller names are plural.'); + if ($controllerName == '') + { + $this->stdout('The controller name you supplied was empty. Please try again.'); + } + } - if ($controllerName == '') - { - $this->stdout('The controller name you supplied was empty. Please try again.'); - } - } + $inflect = new Inflector(); - $inflect = new Inflector(); + $controllerClassName = $inflect->camelize($controllerName); - $controllerClassName = $inflect->camelize($controllerName); + $doItInteractive = $this->getInput("Would you like bake to build your controller interactively?\nWarning: Choosing no will overwrite {$controllerClassName} controller if it exist.", array('y','n'), 'y'); - $wannaDoUses = $this->getInput("Would you like this controller to use other models besides '" . $inflect->singularize($controllerClassName) . "'?", array('y','n'), 'n'); - $uses = array(); + if (strtolower($doItInteractive) == 'y' || strtolower($doItInteractive) == 'yes') + { + $this->interactive = true; + $wannaDoUses = $this->getInput("Would you like this controller to use other models besides '" . $inflect->singularize($controllerClassName) . "'?", array('y','n'), 'n'); - if (strtolower($wannaDoUses) == 'y' || strtolower($wannaDoUses) == 'yes') - { - $usesList = $this->getInput("Please provide a comma separated list of the classnames of other models you'd like to use.\nExample: 'Author, Article, Book'"); - $usesListTrimmed = str_replace(' ', '', $usesList); - $uses = explode(',', $usesListTrimmed); - } + if (strtolower($wannaDoUses) == 'y' || strtolower($wannaDoUses) == 'yes') + { + $usesList = $this->getInput("Please provide a comma separated list of the classnames of other models you'd like to use.\nExample: 'Author, Article, Book'"); + $usesListTrimmed = str_replace(' ', '', $usesList); + $uses = explode(',', $usesListTrimmed); + } - $wannaDoHelpers = $this->getInput("Would you like this controller to use other helpers besides HtmlHelper?", array('y','n'), 'n'); - $helpers = array(); + $wannaDoHelpers = $this->getInput("Would you like this controller to use other helpers besides HtmlHelper?", array('y','n'), 'n'); - if (strtolower($wannaDoHelpers) == 'y' || strtolower($wannaDoHelpers) == 'yes') - { - $helpersList = $this->getInput("Please provide a comma separated list of the other helper names you'd like to use.\nExample: 'Ajax, Javascript, Time'"); - $helpersListTrimmed = str_replace(' ', '', $helpersList); - $helpers = explode(',', $helpersListTrimmed); - } + if (strtolower($wannaDoHelpers) == 'y' || strtolower($wannaDoHelpers) == 'yes') + { + $helpersList = $this->getInput("Please provide a comma separated list of the other helper names you'd like to use.\nExample: 'Ajax, Javascript, Time'"); + $helpersListTrimmed = str_replace(' ', '', $helpersList); + $helpers = explode(',', $helpersListTrimmed); + } - $wannaDoComponents = $this->getInput("Would you like this controller to use any components?", array('y','n'), 'n'); - $components = array(); + $wannaDoComponents = $this->getInput("Would you like this controller to use any components?", array('y','n'), 'n'); - if (strtolower($wannaDoComponents) == 'y' || strtolower($wannaDoComponents) == 'yes') - { - $componentsList = $this->getInput("Please provide a comma separated list of the component names you'd like to use.\nExample: 'Acl, MyNiftyHelper'"); - $componentsListTrimmed = str_replace(' ', '', $componentsList); - $components = explode(',', $componentsListTrimmed); - } + if (strtolower($wannaDoComponents) == 'y' || strtolower($wannaDoComponents) == 'yes') + { + $componentsList = $this->getInput("Please provide a comma separated list of the component names you'd like to use.\nExample: 'Acl, MyNiftyHelper'"); + $componentsListTrimmed = str_replace(' ', '', $componentsList); + $components = explode(',', $componentsListTrimmed); + } - $wannaDoScaffolding = $this->getInput("Would to include some basic class methods (index(), add(), view(), edit())?", array('y','n'), 'n'); + $wannaDoScaffolding = $this->getInput("Would to include some basic class methods (index(), add(), view(), edit())?", array('y','n'), 'n'); + } - if (strtolower($wannaDoScaffolding) == 'y' || strtolower($wannaDoScaffolding) == 'yes') - { - $controllerModel = $inflect->singularize($controllerClassName); - loadModels(); - $tempModel = new $controllerModel(); + if (strtolower($wannaDoScaffolding) == 'y' || strtolower($wannaDoScaffolding) == 'yes') + { + $controllerModel = $inflect->singularize($controllerClassName); + $this->lowCtrl = Inflector::underscore($controllerName); + loadModels(); + if(!class_exists($controllerModel)) + { + $this->stdout('You must have a model for this class to build scaffold methods. Please try again.'); + exit; + } + $tempModel = new $controllerModel(); - $actions .= "\n"; - $actions .= "\tfunction index()\n"; - $actions .= "\t{\n"; - $actions .= "\t\t\$this->{$controllerModel}->recursive = 0;\n"; - $actions .= "\t\t\$this->set('data', \$this->{$controllerModel}->findAll());\n"; - $actions .= "\t}\n"; + $actions .= "\n"; + $actions .= "\tfunction index()\n"; + $actions .= "\t{\n"; + $actions .= "\t\t\$this->{$controllerModel}->recursive = 0;\n"; + $actions .= "\t\t\$this->set('{$this->lowCtrl}', \$this->{$controllerModel}->findAll());\n"; + $actions .= "\t}\n"; - $actions .= "\n"; - $actions .= "\tfunction add()\n"; - $actions .= "\t{\n"; - $actions .= "\t\tif(empty(\$this->data))\n"; - $actions .= "\t\t{\n"; - $actions .= "\t\t\t\$this->render();\n"; - $actions .= "\t\t}\n"; - $actions .= "\t\telse\n"; - $actions .= "\t\t{\n"; - $actions .= "\t\t\tif(\$this->{$controllerModel}->save(\$this->data))\n"; - $actions .= "\t\t\t{\n"; - $actions .= "\t\t\t\t\$this->flash('{$controllerModel} saved.', '/{$controllerName}/index');\n"; - $actions .= "\t\t\t}\n"; - $actions .= "\t\t\telse\n"; - $actions .= "\t\t\t{\n"; - $actions .= "\t\t\t\t\$this->render();\n"; - $actions .= "\t\t\t}\n"; - $actions .= "\t\t}\n"; - $actions .= "\t}\n"; - - $actions .= "\n"; - $actions .= "\tfunction edit(\$id)\n"; - $actions .= "\t{\n"; - $actions .= "\t\tif(empty(\$this->data))\n"; - $actions .= "\t\t{\n"; - $actions .= "\t\t\t\$this->set('data', \$this->{$controllerModel}->find('{$controllerModel}.{$tempModel->primaryKey} = ' . \$id));\n"; - $actions .= "\t\t}\n"; - $actions .= "\t\telse\n"; - $actions .= "\t\t{\n"; - $actions .= "\t\t\tif(\$this->{$controllerModel}->save(\$this->data))\n"; - $actions .= "\t\t\t{\n"; - $actions .= "\t\t\t\t\$this->flash('{$controllerModel} saved.', '/{$controllerName}/index');\n"; - $actions .= "\t\t\t}\n"; - $actions .= "\t\t\telse\n"; - $actions .= "\t\t\t{\n"; - $actions .= "\t\t\t\t\$this->set('data', \$this->data);\n"; - $actions .= "\t\t\t\t\$this->validateErrors(\$this->{$controllerModel});\n"; - $actions .= "\t\t\t\t\$this->render();\n"; - $actions .= "\t\t\t}\n"; - $actions .= "\t\t}\n"; - $actions .= "\t}\n"; - - $actions .= "\n"; - $actions .= "\tfunction view(\$id)\n"; - $actions .= "\t{\n"; - $actions .= "\t\t\$this->set('data', \$this->{$controllerModel}->find('{$controllerModel}.{$tempModel->primaryKey} = ' . \$id));\n"; - $actions .= "\t}\n"; - - $actions .= "\n"; - $actions .= "\tfunction delete(\$id)\n"; - $actions .= "\t{\n"; - $actions .= "\t\t\$this->{$controllerModel}->del(\$id);\n"; - $actions .= "\t\t\$this->redirect('/{$controllerName}/index');\n"; - $actions .= "\t}\n"; - $actions .= "\n"; - - $lowerCaseModel = strtolower(substr($controllerModel, 0, 1)) . substr($controllerModel, 1); - if($tempModel->displayField === null) - { - $tempModel->displayField = 'name'; - } + $actions .= "\n"; + $actions .= "\tfunction add()\n"; + $actions .= "\t{\n"; + $actions .= "\t\tif(empty(\$this->data))\n"; + $actions .= "\t\t{\n"; + foreach($tempModel->hasAndBelongsToMany as $association => $relation) + { + if(!empty($relation['className'])) + { + $model = $relation['className']; + $lowerName = strtolower($association); + $actions .= "\t\t\t\$this->set('{$lowerName}Array', \$this->{$controllerModel}->{$model}->generateList());\n"; + $actions .= "\t\t\t\$this->set('selected{$model}', null);\n"; + } + } + foreach($tempModel->belongsTo as $association => $relation) + { + if(!empty($relation['className'])) + { + $model = $relation['className']; + $lowerName = strtolower(substr( $relation['foreignKey'], 0, strpos( $relation['foreignKey'], "_id" ) )); + $actions .= "\t\t\t\$this->set('{$lowerName}Array', \$this->{$controllerModel}->{$model}->generateList());\n"; + } + } + $actions .= "\t\t\t\$this->set('{$this->lowCtrl}', null);\n"; + $actions .= "\t\t}\n"; + $actions .= "\t\telse\n"; + $actions .= "\t\t{\n"; + $actions .= "\t\t\t\$this->cleanUpFields();\n"; + $actions .= "\t\t\tif(\$this->{$controllerModel}->save(\$this->data))\n"; + $actions .= "\t\t\t{\n"; + $actions .= "\t\t\t\t\$this->flash('{$controllerModel} saved.', '/{$this->lowCtrl}/index');\n"; + $actions .= "\t\t\t}\n"; + $actions .= "\t\t\telse\n"; + $actions .= "\t\t\t{\n"; + $actions .= "\t\t\t\t\$data = \$this->data;\n"; + $actions .= "\t\t\t\t\$this->set('{$this->lowCtrl}', \$data);\n"; + foreach($tempModel->hasAndBelongsToMany as $association => $relation) + { + if(!empty($relation['className'])) + { + $model = $relation['className']; + $associationModel = new $model(); + $lowerName = strtolower($association); + $actions .= "\t\t\t\t\${$lowerName} = null;\n"; + $actions .= "\t\t\t\t\$this->set('{$lowerName}Array', \$this->{$controllerModel}->{$model}->generateList());\n"; + $actions .= "\t\t\t\tif(isset(\$data['{$model}']['{$model}']))\n"; + $actions .= "\t\t\t\t{\n"; + $actions .= "\t\t\t\t\tforeach(\$data['{$model}']['{$model}'] as \$var)\n"; + $actions .= "\t\t\t\t\t{\n"; + $actions .= "\t\t\t\t\t\t\${$lowerName}[\$var] = \$var;\n"; + $actions .= "\t\t\t\t\t}\n"; + $actions .= "\t\t\t\t}\n"; + $actions .= "\t\t\t\t\$this->set('selected{$model}', \${$lowerName});\n"; + } + } + foreach($tempModel->belongsTo as $association => $relation) + { + if(!empty($relation['className'])) + { + $model = $relation['className']; + $lowerName = strtolower(substr( $relation['foreignKey'], 0, strpos( $relation['foreignKey'], "_id" ) )); + $actions .= "\t\t\t\t\$this->set('{$lowerName}Array', \$this->{$controllerModel}->{$model}->generateList());\n"; + } + } + $actions .= "\t\t\t}\n"; + $actions .= "\t\t}\n"; + $actions .= "\t}\n"; - $actions .= "\tfunction {$lowerCaseModel}List()\n"; - $actions .= "\t{\n"; - $actions .= "\t\t\$this->{$controllerModel}->recursive = 0;\n"; - $actions .= "\t\t\$vars = \$this->{$controllerModel}->findAll(null,'{$tempModel->name}.{$tempModel->primaryKey}, {$tempModel->name}.{$tempModel->displayField}');\n"; - $actions .= "\t\tforeach(\$vars as \$var)\n"; - $actions .= "\t\t{\n"; - $actions .= "\t\t\t\$list[\$var['{$controllerModel}']['{$tempModel->primaryKey}']] = \$var['{$controllerModel}']['{$tempModel->displayField}'];\n"; - $actions .= "\t\t}\n"; - $actions .= "\n"; - $actions .= "\t\treturn \$list;\n"; - $actions .= "\t}\n"; - } + $actions .= "\n"; + $actions .= "\tfunction edit(\$id)\n"; + $actions .= "\t{\n"; + $actions .= "\t\tif(empty(\$this->data))\n"; + $actions .= "\t\t{\n"; + $actions .= "\t\t\t\$data = \$this->{$controllerModel}->read(null, \$id);\n"; + $actions .= "\t\t\t\$this->set('{$this->lowCtrl}', \$data );\n"; + foreach($tempModel->hasAndBelongsToMany as $association => $relation) + { + if(!empty($relation['className'])) + { + $model = $relation['className']; + $associationModel = new $model(); + $lowerName = strtolower($association); + $actions .= "\t\t\t\${$lowerName} = null;\n"; + $actions .= "\t\t\t\$this->set('{$lowerName}Array', \$this->{$controllerModel}->{$model}->generateList());\n"; + $actions .= "\t\t\tforeach(\$data['{$model}'] as \$var)\n"; + $actions .= "\t\t\t{\n"; + $actions .= "\t\t\t\t\${$lowerName}[\$var['{$associationModel->primaryKey}']] = \$var['{$associationModel->primaryKey}'];\n"; + $actions .= "\t\t\t}\n"; + $actions .= "\t\t\t\$this->set('selected{$model}', \${$lowerName});\n"; + } + } + foreach($tempModel->belongsTo as $association => $relation) + { + if(!empty($relation['className'])) + { + $model = $relation['className']; + $lowerName = strtolower(substr( $relation['foreignKey'], 0, strpos( $relation['foreignKey'], "_id" ) )); + $actions .= "\t\t\t\$this->set('{$lowerName}Array', \$this->{$controllerModel}->{$model}->generateList());\n"; + } + } + $actions .= "\t\t}\n"; + $actions .= "\t\telse\n"; + $actions .= "\t\t{\n"; + $actions .= "\t\t\t\$this->cleanUpFields();\n"; + $actions .= "\t\t\tif(\$this->{$controllerModel}->save(\$this->data))\n"; + $actions .= "\t\t\t{\n"; + $actions .= "\t\t\t\t\$this->flash('{$controllerModel} saved.', '/{$this->lowCtrl}/index');\n"; + $actions .= "\t\t\t}\n"; + $actions .= "\t\t\telse\n"; + $actions .= "\t\t\t{\n"; + $actions .= "\t\t\t\t\$data = \$this->data;\n"; + $actions .= "\t\t\t\t\$this->set('{$this->lowCtrl}', \$data);\n"; + foreach($tempModel->hasAndBelongsToMany as $association => $relation) + { + if(!empty($relation['className'])) + { + $model = $relation['className']; + $associationModel = new $model(); + $lowerName = strtolower($association); + $actions .= "\t\t\t\t\${$lowerName} = null;\n"; + $actions .= "\t\t\t\t\$this->set('{$lowerName}Array', \$this->{$controllerModel}->{$model}->generateList());\n"; + $actions .= "\t\t\t\tif(isset(\$data['{$model}']['{$model}']))\n"; + $actions .= "\t\t\t\t{\n"; + $actions .= "\t\t\t\t\tforeach(\$data['{$model}']['{$model}'] as \$var)\n"; + $actions .= "\t\t\t\t\t{\n"; + $actions .= "\t\t\t\t\t\t\${$lowerName}[\$var] = \$var;\n"; + $actions .= "\t\t\t\t\t}\n"; + $actions .= "\t\t\t\t}\n"; + $actions .= "\t\t\t\t\$this->set('selected{$model}', \${$lowerName});\n"; + } + } + foreach($tempModel->belongsTo as $association => $relation) + { + if(!empty($relation['className'])) + { + $model = $relation['className']; + $lowerName = strtolower(substr( $relation['foreignKey'], 0, strpos( $relation['foreignKey'], "_id" ) )); + $actions .= "\t\t\t\t\$this->set('{$lowerName}Array', \$this->{$controllerModel}->{$model}->generateList());\n"; + } + } + $actions .= "\t\t\t}\n"; + $actions .= "\t\t}\n"; + $actions .= "\t}\n"; - $this->stdout(''); - $this->hr(); - $this->stdout('The following controller will be created:'); - $this->hr(); - $this->stdout("Controller Name: $controllerName"); - if(count($uses)) - { - $this->stdout("Uses: ", false); - foreach($uses as $use) - { - if ($use != $uses[count($uses) - 1]) - { - $this->stdout(ucfirst($use) . ", ", false); - } - else - { - $this->stdout(ucfirst($use)); - } - } - } - if(count($helpers)) - { - $this->stdout("Helpers: ", false); - foreach($helpers as $help) - { - if ($help != $helpers[count($helpers) - 1]) - { - $this->stdout(ucfirst($help) . ", ", false); - } - else - { - $this->stdout(ucfirst($help)); - } - } - } - if(count($components)) - { - $this->stdout("Components: ", false); - foreach($components as $comp) - { - if ($comp != $components[count($components) - 1]) - { - $this->stdout(ucfirst($comp) . ", ", false); - } - else - { - $this->stdout(ucfirst($comp)); - } - } - } - $this->hr(); + $actions .= "\n"; + $actions .= "\tfunction view(\$id)\n"; + $actions .= "\t{\n"; + $actions .= "\t\t\$this->set('{$this->lowCtrl}', \$this->{$controllerModel}->read(null, \$id));\n"; + $actions .= "\t}\n"; - $looksGood = $this->getInput('Look okay?', array('y','n'), 'y'); + $actions .= "\n"; + $actions .= "\tfunction delete(\$id)\n"; + $actions .= "\t{\n"; + $actions .= "\t\t\$this->{$controllerModel}->del(\$id);\n"; + $actions .= "\t\t\$this->redirect('/{$this->lowCtrl}/index');\n"; + $actions .= "\t}\n"; + $actions .= "\n"; + } - if (strtolower($looksGood) == 'y' || strtolower($looksGood) == 'yes') - { - $this->bakeController($controllerClassName, $uses, $helpers, $components, $actions); + if($this->interactive === true) + { + $this->stdout(''); + $this->hr(); + $this->stdout('The following controller will be created:'); + $this->hr(); + $this->stdout("Controller Name: $controllerName"); - if ($this->doUnitTest()) - { - $this->bakeUnitTest('controller', $controllerClassName); - } - } - else - { - $this->stdout('Bake Aborted.'); - } - } + if(count($uses)) + { + $this->stdout("Uses: ", false); + foreach($uses as $use) + { + if ($use != $uses[count($uses) - 1]) + { + $this->stdout(ucfirst($use) . ", ", false); + } + else + { + $this->stdout(ucfirst($use)); + } + } + } + + if(count($helpers)) + { + $this->stdout("Helpers: ", false); + foreach($helpers as $help) + { + if ($help != $helpers[count($helpers) - 1]) + { + $this->stdout(ucfirst($help) . ", ", false); + } + else + { + $this->stdout(ucfirst($help)); + } + } + } + + if(count($components)) + { + $this->stdout("Components: ", false); + foreach($components as $comp) + { + if ($comp != $components[count($components) - 1]) + { + $this->stdout(ucfirst($comp) . ", ", false); + } + else + { + $this->stdout(ucfirst($comp)); + } + } + } + + $this->hr(); + + $looksGood = $this->getInput('Look okay?', array('y','n'), 'y'); + + if (strtolower($looksGood) == 'y' || strtolower($looksGood) == 'yes') + { + $this->bakeController($controllerClassName, $uses, $helpers, $components, $actions); + + if ($this->doUnitTest()) + { + $this->bakeUnitTest('controller', $controllerClassName); + } + } + else + { + $this->stdout('Bake Aborted.'); + } + } + else + { + $this->bakeController($controllerClassName, $uses, $helpers, $components, $actions); + exit(); + } + } function doUnitTest() { @@ -1150,386 +1286,387 @@ class Bake { $result = strtolower($unitTest) == 'y' || strtolower($unitTest) == 'yes'; if ($result) { - $this->stdout("\nYou can download the Cake test suite from http://cakeforge.org/frs/?group_id=62", true); + $this->stdout("\nYou can download the Cake test suite from http://cakeforge.org/frs/?group_id=62", true); } return $result; } - /*---- ----*/ + /*---- ----*/ - function bakeDbConfig($host, $login, $password, $database) - { - $out = " 'mysql',\n"; - $out .= "\t\t'connect' => 'mysql_pconnect',\n"; - $out .= "\t\t'host' => '$host',\n"; - $out .= "\t\t'login' => '$login',\n"; - $out .= "\t\t'password' => '$password',\n"; - $out .= "\t\t'database' => '$database' \n"; - $out .= "\t);\n"; - $out .= "}\n"; - $out .= "?>"; + function bakeDbConfig($host, $login, $password, $database) + { + $out = " 'mysql',\n"; + $out .= "\t\t'connect' => 'mysql_connect',\n"; + $out .= "\t\t'host' => '$host',\n"; + $out .= "\t\t'login' => '$login',\n"; + $out .= "\t\t'password' => '$password',\n"; + $out .= "\t\t'database' => '$database' \n"; + $out .= "\t);\n"; + $out .= "}\n"; + $out .= "?>"; - $filename = CONFIGS.'database.php'; + $filename = CONFIGS.'database.php'; - $this->createFile($filename, $out); - } + $this->createFile($filename, $out); + } - function bakeModel($modelClassName, $dbConnection, $modelTableName, $validate, $modelAssociations) - { - $out = " " . $validate[$keys[$i]] . ",\n"; - } - $out .= "\t);\n"; - } + if (count($validate)) { + $out .= "\tvar \$validate = array(\n"; + $keys = array_keys($validate); + for($i = 0; $i < count($validate); $i++) + { + $out .= "\t\t'" . $keys[$i] . "' => " . $validate[$keys[$i]] . ",\n"; + } + $out .= "\t);\n"; + } - $out .= "\n"; + $out .= "\n"; - if(count($modelAssociations['belongsTo']) || count($modelAssociations['hasOne']) || count($modelAssociations['hasMany']) || count($modelAssociations['hasAndBelongsToMany'])) - { - if(count($modelAssociations['belongsTo'])) - { - $out .= "\tvar \$belongsTo = array(\n"; + if(count($modelAssociations['belongsTo']) || count($modelAssociations['hasOne']) || count($modelAssociations['hasMany']) || count($modelAssociations['hasAndBelongsToMany'])) + { + $out.= "\t//The Associations below have been created with all possible keys, those that are not needed can be removed\n"; + if(count($modelAssociations['belongsTo'])) + { + $out .= "\tvar \$belongsTo = array(\n"; - for($i = 0; $i < count($modelAssociations['belongsTo']); $i++) - { - $out .= "\t\t\t'{$modelAssociations['belongsTo'][$i]}' =>\n"; - $out .= "\t\t\t array('className' => '{$modelAssociations['belongsTo'][$i]}',\n"; - $out .= "\t\t\t 'conditions' => '',\n"; - $out .= "\t\t\t 'order' => '',\n"; - $out .= "\t\t\t 'foreignKey' => '',\n"; - $out .= "\t\t\t 'counterCache' => ''),\n\n"; - } + for($i = 0; $i < count($modelAssociations['belongsTo']); $i++) + { + $out .= "\t\t\t'{$modelAssociations['belongsTo'][$i]}' =>\n"; + $out .= "\t\t\t array('className' => '{$modelAssociations['belongsTo'][$i]}',\n"; + $out .= "\t\t\t 'conditions' => '',\n"; + $out .= "\t\t\t 'order' => '',\n"; + $out .= "\t\t\t 'foreignKey' => '',\n"; + $out .= "\t\t\t 'counterCache' => ''),\n\n"; + } - $out .= "\t);\n\n"; - } + $out .= "\t);\n\n"; + } - if(count($modelAssociations['hasOne'])) - { - $out .= "\tvar \$hasOne = array(\n"; + if(count($modelAssociations['hasOne'])) + { + $out .= "\tvar \$hasOne = array(\n"; - for($i = 0; $i < count($modelAssociations['hasOne']); $i++) - { - $out .= "\t\t\t'{$modelAssociations['hasOne'][$i]}' =>\n"; - $out .= "\t\t\t array('className' => '{$modelAssociations['hasOne'][$i]}',\n"; - $out .= "\t\t\t 'conditions' => '',\n"; - $out .= "\t\t\t 'order' => '',\n"; - $out .= "\t\t\t 'foreignKey' => '',\n"; - $out .= "\t\t\t 'dependent' => ''),\n\n"; - } + for($i = 0; $i < count($modelAssociations['hasOne']); $i++) + { + $out .= "\t\t\t'{$modelAssociations['hasOne'][$i]}' =>\n"; + $out .= "\t\t\t array('className' => '{$modelAssociations['hasOne'][$i]}',\n"; + $out .= "\t\t\t 'conditions' => '',\n"; + $out .= "\t\t\t 'order' => '',\n"; + $out .= "\t\t\t 'foreignKey' => '',\n"; + $out .= "\t\t\t 'dependent' => ''),\n\n"; + } - $out .= "\t);\n\n"; - } + $out .= "\t);\n\n"; + } - if(count($modelAssociations['hasMany'])) - { - $out .= "\tvar \$hasMany = array(\n"; + if(count($modelAssociations['hasMany'])) + { + $out .= "\tvar \$hasMany = array(\n"; - for($i = 0; $i < count($modelAssociations['hasMany']); $i++) - { - $out .= "\t\t\t'{$modelAssociations['hasMany'][$i]}' =>\n"; - $out .= "\t\t\t array('className' => '{$modelAssociations['hasMany'][$i]}',\n"; - $out .= "\t\t\t 'conditions' => '',\n"; - $out .= "\t\t\t 'order' => '',\n"; - $out .= "\t\t\t 'foreignKey' => '',\n"; - $out .= "\t\t\t 'dependent' => '',\n"; - $out .= "\t\t\t 'exclusive' => '',\n"; - $out .= "\t\t\t 'finderSql' => '',\n"; - $out .= "\t\t\t 'counterSql' => ''),\n\n"; - } + for($i = 0; $i < count($modelAssociations['hasMany']); $i++) + { + $out .= "\t\t\t'{$modelAssociations['hasMany'][$i]}' =>\n"; + $out .= "\t\t\t array('className' => '{$modelAssociations['hasMany'][$i]}',\n"; + $out .= "\t\t\t 'conditions' => '',\n"; + $out .= "\t\t\t 'order' => '',\n"; + $out .= "\t\t\t 'foreignKey' => '',\n"; + $out .= "\t\t\t 'dependent' => '',\n"; + $out .= "\t\t\t 'exclusive' => '',\n"; + $out .= "\t\t\t 'finderSql' => '',\n"; + $out .= "\t\t\t 'counterSql' => ''),\n\n"; + } - $out .= "\t);\n\n"; - } + $out .= "\t);\n\n"; + } - if(count($modelAssociations['hasAndBelongsToMany'])) - { - $out .= "\tvar \$hasAndBelongsToMany = array(\n"; + if(count($modelAssociations['hasAndBelongsToMany'])) + { + $out .= "\tvar \$hasAndBelongsToMany = array(\n"; - for($i = 0; $i < count($modelAssociations['hasAndBelongsToMany']); $i++) - { - $out .= "\t\t\t'{$modelAssociations['hasAndBelongsToMany'][$i]}' =>\n"; - $out .= "\t\t\t array('className' => '{$modelAssociations['hasAndBelongsToMany'][$i]}',\n"; - $out .= "\t\t\t 'conditions' => '',\n"; - $out .= "\t\t\t 'order' => '',\n"; - $out .= "\t\t\t 'foreignKey' => '',\n"; - $out .= "\t\t\t 'joinTable' => '',\n"; - $out .= "\t\t\t 'associationForeignKey' => '',\n"; - $out .= "\t\t\t 'uniq' => '',\n"; - $out .= "\t\t\t 'finderQuery' => '',\n"; - $out .= "\t\t\t 'deleteQuery' => '',\n"; - $out .= "\t\t\t 'insertQuery' => ''),\n\n"; - } + for($i = 0; $i < count($modelAssociations['hasAndBelongsToMany']); $i++) + { + $out .= "\t\t\t'{$modelAssociations['hasAndBelongsToMany'][$i]}' =>\n"; + $out .= "\t\t\t array('className' => '{$modelAssociations['hasAndBelongsToMany'][$i]}',\n"; + $out .= "\t\t\t 'conditions' => '',\n"; + $out .= "\t\t\t 'order' => '',\n"; + $out .= "\t\t\t 'foreignKey' => '',\n"; + $out .= "\t\t\t 'joinTable' => '',\n"; + $out .= "\t\t\t 'associationForeignKey' => '',\n"; + $out .= "\t\t\t 'uniq' => '',\n"; + $out .= "\t\t\t 'finderQuery' => '',\n"; + $out .= "\t\t\t 'deleteQuery' => '',\n"; + $out .= "\t\t\t 'insertQuery' => ''),\n\n"; + } - $out .= "\t);\n\n"; - } - } + $out .= "\t);\n\n"; + } + } - $out .= "}\n"; - $out .= "?>"; + $out .= "}\n"; + $out .= "?>"; - $inflect = new Inflector(); + $inflect = new Inflector(); - $filename = MODELS.$inflect->underscore($modelClassName) . '.php'; + $filename = MODELS.$inflect->underscore($modelClassName) . '.php'; - $this->createFile($filename, $out); - } + $this->createFile($filename, $out); + } - function bakeView($controllerName, $actionName, $content = '') - { - $out = "

$actionName

\n"; - $out .= $content; + function bakeView($controllerName, $actionName, $content = '') + { + $out = "

$actionName

\n"; + $out .= $content; - $inflect = new Inflector(); + $inflect = new Inflector(); - if(!file_exists(VIEWS.strtolower($controllerName))) - { - mkdir(VIEWS.strtolower($controllerName)); - } + if(!file_exists(VIEWS.strtolower($controllerName))) + { + mkdir(VIEWS.strtolower($controllerName)); + } - $filename = VIEWS . strtolower($controllerName) . DS . $inflect->underscore($actionName) . '.thtml'; + $filename = VIEWS . strtolower($controllerName) . DS . $inflect->underscore($actionName) . '.thtml'; - $this->createFile($filename, $out); - } + $this->createFile($filename, $out); + } - function bakeController($controllerName, $uses, $helpers, $components, $actions = '') - { - $inflect = new Inflector(); + function bakeController($controllerName, $uses, $helpers, $components, $actions = '') + { + $inflect = new Inflector(); - $out = "singularize($controllerName) . "', "; + if (count($uses)) + { + $out .= "\tvar \$uses = array('" . $inflect->singularize($controllerName) . "', "; - foreach($uses as $use) - { - if ($use != $uses[count($uses) - 1]) - { - $out .= "'" . ucfirst($use) . "', "; - } - else - { - $out .= "'" . ucfirst($use) . "'"; - } - } + foreach($uses as $use) + { + if ($use != $uses[count($uses) - 1]) + { + $out .= "'" . ucfirst($use) . "', "; + } + else + { + $out .= "'" . ucfirst($use) . "'"; + } + } - $out .= ");\n"; + $out .= ");\n"; - } + } - if (count($helpers)) - { - $out .= "\tvar \$helpers = array('Html', "; + if (count($helpers)) + { + $out .= "\tvar \$helpers = array('Html', "; - foreach($helpers as $help) - { - if ($help != $helpers[count($helpers) - 1]) - { - $out .= "'" . ucfirst($help) . "', "; - } - else - { - $out .= "'" . ucfirst($help) . "'"; - } - } + foreach($helpers as $help) + { + if ($help != $helpers[count($helpers) - 1]) + { + $out .= "'" . ucfirst($help) . "', "; + } + else + { + $out .= "'" . ucfirst($help) . "'"; + } + } - $out .= ");\n"; + $out .= ");\n"; - } + } - if (count($components)) - { - $out .= "\tvar \$components = array("; + if (count($components)) + { + $out .= "\tvar \$components = array("; - foreach($components as $comp) - { - if ($comp != $components[count($components) - 1]) - { - $out .= "'" . ucfirst($comp) . "', "; - } - else - { - $out .= "'" . ucfirst($comp) . "'"; - } - } + foreach($components as $comp) + { + if ($comp != $components[count($components) - 1]) + { + $out .= "'" . ucfirst($comp) . "', "; + } + else + { + $out .= "'" . ucfirst($comp) . "'"; + } + } - $out .= ");\n"; + $out .= ");\n"; - } + } - $out .= $actions; + $out .= $actions; - $out .= "}\n"; - $out .= "?>"; + $out .= "}\n"; + $out .= "?>"; - $filename = CONTROLLERS . $inflect->underscore($controllerName) . '_controller.php'; + $filename = CONTROLLERS . $inflect->underscore($controllerName) . '_controller.php'; - $this->createFile($filename, $out); - } + $this->createFile($filename, $out); + } - function bakeUnitTest($type, $className) - { - $out = 'object = new {$className}();\n"; - $out .= "\t}\n\n\tfunction tearDown()\n\t{\n\t\tunset(\$this->object);\n\t}\n"; - $out .= "\n\t/*\n\tfunction testMe()\n\t{\n"; - $out .= "\t\t\$result = \$this->object->doSomething();\n"; - $out .= "\t\t\$expected = 1;\n"; - $out .= "\t\t\$this->assertEquals(\$result, \$expected);\n\t}\n\t*/\n}"; - $path = MODEL_TESTS; - $filename = Inflector::underscore($className).'.test.php'; - break; + function bakeUnitTest($type, $className) + { + $out = 'object = new {$className}();\n"; + $out .= "\t}\n\n\tfunction tearDown()\n\t{\n\t\tunset(\$this->object);\n\t}\n"; + $out .= "\n\t/*\n\tfunction testMe()\n\t{\n"; + $out .= "\t\t\$result = \$this->object->doSomething();\n"; + $out .= "\t\t\$expected = 1;\n"; + $out .= "\t\t\$this->assertEquals(\$result, \$expected);\n\t}\n\t*/\n}"; + $path = MODEL_TESTS; + $filename = Inflector::underscore($className).'.test.php'; + break; - case 'controller': - $out .= 'loadControllerTest();'."\n\n"; - $out .= "class {$className}ControllerTestCase extends UnitTestCase\n{\n"; - $out .= "\tvar \$object = null;\n\n"; - $out .= "\tfunction setUp()\n\t{\n\t\t\$this->object = new {$className}();\n"; - $out .= "\t}\n\n\tfunction tearDown()\n\t{\n\t\tunset(\$this->object);\n\t}\n"; - $out .= "\n\t/*\n\tfunction testMe()\n\t{\n"; - $out .= "\t\t\$result = \$this->object->doSomething();\n"; - $out .= "\t\t\$expected = 1;\n"; - $out .= "\t\t\$this->assertEquals(\$result, \$expected);\n\t}\n\t*/\n}"; - $path = CONTROLLER_TESTS; - $filename = Inflector::underscore($className.'Controller').'.test.php'; - break; + case 'controller': + $out .= 'loadControllerTest();'."\n\n"; + $out .= "class {$className}ControllerTestCase extends UnitTestCase\n{\n"; + $out .= "\tvar \$object = null;\n\n"; + $out .= "\tfunction setUp()\n\t{\n\t\t\$this->object = new {$className}();\n"; + $out .= "\t}\n\n\tfunction tearDown()\n\t{\n\t\tunset(\$this->object);\n\t}\n"; + $out .= "\n\t/*\n\tfunction testMe()\n\t{\n"; + $out .= "\t\t\$result = \$this->object->doSomething();\n"; + $out .= "\t\t\$expected = 1;\n"; + $out .= "\t\t\$this->assertEquals(\$result, \$expected);\n\t}\n\t*/\n}"; + $path = CONTROLLER_TESTS; + $filename = Inflector::underscore($className.'Controller').'.test.php'; + break; - default: - $error = true; - break; - } - $out .= "\n?>"; - if (!$error) - { - $this->stdout("Baking unit test for $className..."); - $path = explode(DS, $path); - foreach($path as $i => $val) - { - if ($val == '') - { - unset($path[$i]); - } - } - $path = implode(DS, $path); + default: + $error = true; + break; + } + $out .= "\n?>"; + if (!$error) + { + $this->stdout("Baking unit test for $className..."); + $path = explode(DS, $path); + foreach($path as $i => $val) + { + if ($val == '') + { + unset($path[$i]); + } + } + $path = implode(DS, $path); - if (!is_dir(DS.$path)) - { - $create = $this->getInput("Unit test directory does not exist. Create it?", array('y','n'), 'y'); - if (low($create) == 'y' || low($create) == 'yes') - { - $build = array(); - foreach(explode(DS, $path) as $i => $dir) - { - $build[] = $dir; - if (!is_dir(DS.implode(DS, $build))) - { - mkdir(DS.implode(DS, $build)); - } - } - } - } + if (!is_dir(DS.$path)) + { + $create = $this->getInput("Unit test directory does not exist. Create it?", array('y','n'), 'y'); + if (low($create) == 'y' || low($create) == 'yes') + { + $build = array(); + foreach(explode(DS, $path) as $i => $dir) + { + $build[] = $dir; + if (!is_dir(DS.implode(DS, $build))) + { + mkdir(DS.implode(DS, $build)); + } + } + } + } - $this->createFile(DS.$path.DS.$filename, $out); - } - } + $this->createFile(DS.$path.DS.$filename, $out); + } + } - /*----General purpose functions----*/ + /*----General purpose functions----*/ - function getInput($prompt, $options = null, $default = null) - { - if (!is_array($options)) - { - $print_options = ''; - } - else - { - $print_options = '(' . implode('/', $options) . ')'; - } + function getInput($prompt, $options = null, $default = null) + { + if (!is_array($options)) + { + $print_options = ''; + } + else + { + $print_options = '(' . implode('/', $options) . ')'; + } - if($default == null) - { - $this->stdout(''); - $this->stdout($prompt . " $print_options \n" . '> ', false); - } - else - { - $this->stdout(''); - $this->stdout($prompt . " $print_options \n" . "[$default] > ", false); - } + if($default == null) + { + $this->stdout(''); + $this->stdout($prompt . " $print_options \n" . '> ', false); + } + else + { + $this->stdout(''); + $this->stdout($prompt . " $print_options \n" . "[$default] > ", false); + } - $result = trim(fgets($this->stdin)); + $result = trim(fgets($this->stdin)); - if($default != null && empty($result)) - { - return $default; - } - else - { - return $result; - } - } + if($default != null && empty($result)) + { + return $default; + } + else + { + return $result; + } + } - function stdout($string, $newline = true) - { - if ($newline) - { - fwrite($this->stdout, $string . "\n"); - } - else - { - fwrite($this->stdout, $string); - } - } + function stdout($string, $newline = true) + { + if ($newline) + { + fwrite($this->stdout, $string . "\n"); + } + else + { + fwrite($this->stdout, $string); + } + } - function stderr($string) - { - fwrite($this->stderr, $string); - } + function stderr($string) + { + fwrite($this->stderr, $string); + } - function hr() - { - $this->stdout('---------------------------------------------------------------'); - } + function hr() + { + $this->stdout('---------------------------------------------------------------'); + } - function createFile ($path, $contents) + function createFile ($path, $contents) { echo "\nCreating file $path\n"; $shortPath = str_replace(ROOT,null,$path); - - if (is_file($path) && !$this->dontAsk) + $path = str_replace('//', '/', $path); + if (is_file($path) && $this->interactive === true) { fwrite($this->stdout, "File {$shortPath} exists, overwrite? (y/n/q):"); $key = trim(fgets($this->stdin)); @@ -1687,7 +1824,7 @@ class Bake { $htmlAttributes['rows'] = $rows; $tagNameArray = explode('/', $tagName); - $htmlAttributes['value'] = "\$data['{$tagNameArray[0]}']['{$tagNameArray[1]}']"; + $htmlAttributes['value'] = "\${$this->lowCtrl}['{$tagNameArray[0]}']['{$tagNameArray[1]}']"; $str = "\ttextarea('{$tagName}', " . $this->attributesToArray($htmlAttributes) . ") ?>\n"; $str .= "\ttagErrorMsg('{$tagName}', 'Error message for {$tagNameArray[1]} goes here.') ?>\n"; @@ -1718,7 +1855,7 @@ class Bake { $htmlOptions['id'] = strtolower(str_replace('/', '_',$tagName)); $tagNameArray = explode('/', $tagName); - $htmlAttributes['checked'] = "\$data['{$tagNameArray[0]}']['{$tagNameArray[1]}'] ? 'checked' : ''"; + $htmlAttributes['checked'] = "\${$this->lowCtrl}['{$tagNameArray[0]}']['{$tagNameArray[1]}'] ? 'checked' : ''"; $str = "\tcheckbox('{$tagName}', null, " . $this->attributesToArray($htmlAttributes) . ")?>\n"; @@ -1748,7 +1885,7 @@ class Bake { { $htmlOptions['id'] = strtolower(str_replace('/', '_',$tagName)); $tagNameArray = explode('/', $tagName); - $str = "\tdateTimeOptionTag('{$tagName}', 'MDY' , 'NONE', \$data['{$tagNameArray[0]}']['{$tagNameArray[1]}'], " . $this->attributesToArray($htmlOptions) . ")?>\n"; + $str = "\tdateTimeOptionTag('{$tagName}', 'MDY' , 'NONE', \${$this->lowCtrl}['{$tagNameArray[0]}']['{$tagNameArray[1]}'], " . $this->attributesToArray($htmlOptions) . ")?>\n"; $str .= "\ttagErrorMsg('{$tagName}', 'Error message for {$tagNameArray[1]} goes here.') ?>\n"; $strLabel = "\n\t" . $this->labelTag( $tagName, $prompt ); @@ -1776,7 +1913,7 @@ class Bake { { $htmlOptions['id'] = strtolower(str_replace('/', '_',$tagName)); $tagNameArray = explode('/', $tagName); - $str = "\tdateTimeOptionTag('{$tagName}', 'MDY' , '12', \$data['{$tagNameArray[0]}']['{$tagNameArray[1]}'], " . $this->attributesToArray($htmlOptions) . ")?>\n"; + $str = "\tdateTimeOptionTag('{$tagName}', 'MDY' , '12', \${$this->lowCtrl}['{$tagNameArray[0]}']['{$tagNameArray[1]}'], " . $this->attributesToArray($htmlOptions) . ")?>\n"; $str .= "\ttagErrorMsg('{$tagName}', 'Error message for {$tagNameArray[1]} goes here.') ?>\n"; $strLabel = "\n\t" . $this->labelTag( $tagName, $prompt ); $divClass = "optional"; @@ -1807,7 +1944,7 @@ class Bake { $htmlAttributes['size'] = $size; $tagNameArray = explode('/', $tagName); - $htmlAttributes['value'] = "\$data['{$tagNameArray[0]}']['{$tagNameArray[1]}']"; + $htmlAttributes['value'] = "\${$this->lowCtrl}['{$tagNameArray[0]}']['{$tagNameArray[1]}']"; $str = "\tinput('{$tagName}', " . $this->attributesToArray($htmlAttributes) . ") ?>\n"; $str .= "\ttagErrorMsg('{$tagName}', 'Error message for {$tagNameArray[1]} goes here.') ?>\n"; @@ -1844,22 +1981,16 @@ class Bake { $controllerPath = strtolower(substr($inflect->pluralize($properModel), 0, 1)) . substr($inflect->pluralize($properModel), 1); $actionPath = strtolower(substr($properModel, 0, 1)) . substr($properModel, 1) . 'List'; $path = "/$controllerPath/$actionPath"; - + $lowerName = strtolower($tagNameArray[0]); if($selectAttr['multiple'] != 'multiple') { - $str = "\tselectTag('{$tagName}', " . "\$this->requestAction('{$path}'), \$data['{$tagNameArray[0]}']['{$tagNameArray[1]}'], " . $this->attributesToArray($selectAttr) . ") ?>\n"; - $str .= "\ttagErrorMsg('{$tagName}', 'Error message for {$tagNameArray[1]} goes here.') ?>\n"; + $str = "\tselectTag('{$tagName}', " . "\${$model}Array, \${$this->lowCtrl}['{$tagNameArray[0]}']['{$tagNameArray[1]}'], " . $this->attributesToArray($selectAttr) . ") ?>\n"; + $str .= "\ttagErrorMsg('{$tagName}', 'Error message for {$tagNameArray[1]} goes here.') ?>\n"; } else { - $lowerName = strtolower($tagNameArray[0]); - $str = "\t\n"; - $str .= "\t\n"; - $str .= "\t\n"; - $str .= "\t\n"; - $str .= "\t\n"; - $str .= "\tselectTag('{$tagName}', " . "\$this->requestAction('{$path}'), \${$lowerName}Options, " . $this->attributesToArray($selectAttr) . ") ?>\n"; - $str .= "\ttagErrorMsg('{$tagName}', 'Error message for {$tagNameArray[1]} goes here.') ?>\n"; + $str = "\tselectTag('{$tagName}', \${$lowerName}Array, \$selected{$tagNameArray[0]}, array('multiple' => 'multiple', 'class' => 'selectMultiple', 'id' => '{$lowerName}_{$lowerName}', )) ?>\n"; + $str .= "\ttagErrorMsg('{$tagName}', 'Error message for {$tagNameArray[1]} goes here.') ?>\n"; } $strLabel = "\n\t" . $this->labelTag( $tagName, $prompt ); @@ -1901,8 +2032,8 @@ class Bake { { return true; } - else - { + else + { return false; } } @@ -1917,50 +2048,277 @@ class Bake { return sprintf( TAG_DIV, $class, $text ) . "\n"; } - //=-=-=-= - function attributesToArray($htmlAttributes) { - if (is_array($htmlAttributes)) - { - $keys = array_keys($htmlAttributes); - $vals = array_values($htmlAttributes); + if (is_array($htmlAttributes)) + { + $keys = array_keys($htmlAttributes); + $vals = array_values($htmlAttributes); - $out = "array("; + $out = "array("; - for($i = 0; $i < count($htmlAttributes); $i++) - { - //don't put vars in quotes - if(substr($vals[$i], 0, 1) != '$') - { - $out .= "'{$keys[$i]}' => '{$vals[$i]}', "; - } - else - { - $out .= "'{$keys[$i]}' => {$vals[$i]}, "; - } - } + for($i = 0; $i < count($htmlAttributes); $i++) + { + //don't put vars in quotes + if(substr($vals[$i], 0, 1) != '$') + { + $out .= "'{$keys[$i]}' => '{$vals[$i]}', "; + } + else + { + $out .= "'{$keys[$i]}' => {$vals[$i]}, "; + } + } - //Chop off last comma - if(substr($out, -3, 1) == ',') - { - $out = substr($out, 0, strlen($out) - 2); - } - $out .= ")"; + //Chop off last comma + if(substr($out, -3, 1) == ',') + { + $out = substr($out, 0, strlen($out) - 2); + } + $out .= ")"; - return $out; - } - else - { - return 'array()'; - } + return $out; + } + else + { + return 'array()'; + } + } + + function help() + { + $doItInteractive = $this->getInput("The help section is not completed use interactive mode?", array('y','n'), 'y'); + + if (strtolower($doItInteractive) == 'y' || strtolower($doItInteractive) == 'yes') + { + $this->interactive = true; + $this->main(); + } + } + + function project($projectPath) + { + if($projectPath != '') + { + while ($this->__checkPath($projectPath) === true) + { + $projectPath = $this->getInput('Directory exists please choose another name:'); + $this->__buildDirLayout($projectPath); + exit(); + } + } + else + { + while ($projectPath == '') + { + $projectPath = $this->getInput("What is the full path for this app including the app directory name?\nExample: ".ROOT."myapp", null, ROOT.'myapp'); + + if ($projectPath == '') + { + $this->stdout('The directory path you supplied was empty. Please try again.'); + } + } + } + while ($this->__checkPath($projectPath) === true || $projectPath == '') + { + $projectPath = $this->getInput('Directory path exists please choose another:'); + while ($projectPath == '') + { + $projectPath = $this->getInput('The directory path you supplied was empty. Please try again.'); + } + } + $parentPath = explode(DS, $projectPath); + $count = count($parentPath); + $appName = $parentPath[$count - 1]; + unset($parentPath[$count - 1]); + $parentPath = implode(DS, $parentPath); + if(!is_writable($parentPath)) + { + $projectPath = $this->getInput('The directory path is not writable. Please try again'); + $this->project($projectPath); + } + + $this->__buildDirLayout($projectPath, $appName); + exit(); + } + + function __checkPath($projectPath) + { + if(is_dir($projectPath)) + { + return true; + } + else + { + return false; + } + } + + function __buildDirLayout($projectPath, $appName) + { + $skel = ''; + if($this->__checkPath(ROOT.'cake'.DS.'scripts'.DS.'templates'.DS.'skel') === true) + { + $skel = ROOT.'cake'.DS.'scripts'.DS.'templates'.DS.'skel'; + } + else + { + while ($skel == '') + { + $skel = $this->getInput("What is the full path for the cake install app directory?\nExample: ", null, ROOT.'app'.DS); + + if ($skel == '') + { + $this->stdout('The directory path you supplied was empty. Please try again.'); + } + else + { + while ($this->__checkPath($skel) === false) + { + $skel = $this->getInput('Directory path does not exist please choose another:'); + } + } + } + } + + $this->stdout(''); + $this->hr(); + $this->stdout("Skel Directory: $skel"); + $this->stdout("Will be copied to:"); + $this->stdout("New App Direcotry: $projectPath"); + $this->hr(); + + $looksGood = $this->getInput('Look okay?', array('y', 'n', 'q'), 'y'); + + if (strtolower($looksGood) == 'y' || strtolower($looksGood) == 'yes') + { + $verboseOuptut = $this->getInput('Do you want verbose output?', array('y', 'n'), 'n'); + $verbose = false; + if (strtolower($verboseOuptut) == 'y' || strtolower($verboseOuptut) == 'yes') + { + $verbose = true; + } + $this->copydirr($skel, $projectPath, 0755, $verbose); + $this->hr(); + $this->stdout('Created: '.$projectPath); + $this->hr(); + $this->stdout('Creating welcome page'); + $this->hr(); + $this->__defaultHome($projectPath, $appName); + $this->stdout('Welcome page created'); + if(chmodr($projectPath.DS.'tmp', 0777) === false) + { + $this->stdout('Could not set permissions on '. $projectPath.DS.'tmp'.DS.'*'); + $this->stdout('You must manually check that these directories can be wrote to by the server'); + } + return; + } + elseif (strtolower($looksGood) == 'q' || strtolower($looksGood) == 'quit') + { + $this->stdout('Bake Aborted.'); + } + else + { + $this->project($projectPath); + } + } + + function copydirr($fromDir, $toDir, $chmod = 0755, $verbose = false) + { + $errors=array(); + $messages=array(); + if (!is_dir($toDir)) + { + mkdir($toDir, 0755); + } + if (!is_writable($toDir)) + { + $errors[]='target '.$toDir.' is not writable'; + } + if (!is_dir($fromDir)) + { + $errors[]='source '.$fromDir.' is not a directory'; + } + if (!empty($errors)) + { + if ($verbose) + { + foreach($errors as $err) + { + $this->stdout('Error: '.$err); + } + } + return false; + } + + $exceptions=array('.','..'); + $handle = opendir($fromDir); + while (false!==($item = readdir($handle))) + { + if (!in_array($item,$exceptions)) + { + $from = str_replace('//','/',$fromDir.'/'.$item); + $to = str_replace('//','/',$toDir.'/'.$item); + if (is_file($from)) + { + if (@copy($from, $to)) + { + chmod($to, $chmod); + touch($to, filemtime($from)); + $messages[]='File copied from '.$from.' to '.$to; + } + else + { + $errors[]='cannot copy file from '.$from.' to '.$to; + } + } + if (is_dir($from)) + { + if (@mkdir($to)) + { + chmod($to,$chmod); + $messages[]='Directory created: '.$to; + } + else + { + $errors[]='cannot create directory '.$to; + } + $this->copydirr($from,$to,$chmod,$verbose); + } + } + } + + closedir($handle); + if ($verbose) + { + foreach($errors as $err) + { + $this->stdout('Error: '.$err); + } + foreach($messages as $msg) + { + $this->stdout($msg); + } + } + return true; + } + + function welcome() + { + $this->stdout(''); + $this->stdout(' ___ __ _ _ ___ __ _ _ __ __ __ _ _ ___ '); + $this->stdout('| |__| |_/ |__ |__] |__| |__] |__] |__| |_/ |__ '); + $this->stdout('|___ | | | \_ |___ | | | | |__] | | | \_ |___ '); + $this->hr(); + $this->stdout(''); + } + + function __defaultHome($dir, $app) + { + $path = $dir.DS.'views'.DS.'pages'.DS; + include(ROOT.'cake'.DS.'scripts'.DS.'templates'.DS.'views'.DS.'home.thtml'); + $this->createFile($path.'home.thtml', $output); } } -/* -@@@ -Make options array in selectTag dynamic (create a listModels function in the controller and use requestAction?) - -*/ - ?> \ No newline at end of file diff --git a/cake/scripts/templates/skel/.htaccess b/cake/scripts/templates/skel/.htaccess new file mode 100644 index 000000000..0ed8662ea --- /dev/null +++ b/cake/scripts/templates/skel/.htaccess @@ -0,0 +1,5 @@ + + RewriteEngine on + RewriteRule ^$ webroot/ [L] + RewriteRule (.*) webroot/$1 [L] + \ No newline at end of file diff --git a/cake/scripts/templates/skel/config/acl.ini.php b/cake/scripts/templates/skel/config/acl.ini.php new file mode 100644 index 000000000..b454368dd --- /dev/null +++ b/cake/scripts/templates/skel/config/acl.ini.php @@ -0,0 +1,76 @@ +; +; SVN FILE: $Id$ +;/** +; * Short description for file. +; * +; * +; * PHP versions 4 and 5 +; * +; * CakePHP : Rapid Development Framework +; * Copyright (c) 2006, Cake Software Foundation, Inc. +; * 1785 E. Sahara Avenue, Suite 490-204 +; * Las Vegas, Nevada 89104 +; * +; * Licensed under The MIT License +; * Redistributions of files must retain the above copyright notice. +; * +; * @filesource +; * @copyright Copyright (c) 2006, Cake Software Foundation, Inc. +; * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project +; * @package cake +; * @subpackage cake.app.config +; * @since CakePHP v 0.10.0.1076 +; * @version $Revision$ +; * @modifiedby $LastChangedBy$ +; * @lastmodified $Date$ +; * @license http://www.opensource.org/licenses/mit-license.php The MIT License +; */ + +; acl.ini.php - Cake ACL Configuration +; --------------------------------------------------------------------- +; Use this file to specify user permissions. +; aco = access control object (something in your application) +; aro = access request object (something requesting access) +; +; User records are added as follows: +; +; [uid] +; groups = group1, group2, group3 +; allow = aco1, aco2, aco3 +; deny = aco4, aco5, aco6 +; +; Group records are added in a similar manner: +; +; [gid] +; allow = aco1, aco2, aco3 +; deny = aco4, aco5, aco6 +; +; The allow, deny, and groups sections are all optional. +; NOTE: groups names *cannot* ever be the same as usernames! +; +; ACL permissions are checked in the following order: +; 1. Check for user denies (and DENY if specified) +; 2. Check for user allows (and ALLOW if specified) +; 3. Gather user's groups +; 4. Check group denies (and DENY if specified) +; 5. Check group allows (and ALLOW if specified) +; 6. If no aro, aco, or group information is found, DENY +; +; --------------------------------------------------------------------- + +;------------------------------------- +;Users +;------------------------------------- + +[username-goes-here] +groups = group1, group2 +deny = aco1, aco2 +allow = aco3, aco4 + +;------------------------------------- +;Groups +;------------------------------------- + +[groupname-goes-here] +deny = aco5, aco6 +allow = aco7, aco8 \ No newline at end of file diff --git a/cake/scripts/templates/skel/config/bootstrap.php b/cake/scripts/templates/skel/config/bootstrap.php new file mode 100644 index 000000000..5b7793c28 --- /dev/null +++ b/cake/scripts/templates/skel/config/bootstrap.php @@ -0,0 +1,50 @@ + + * Copyright (c) 2006, Cake Software Foundation, Inc. + * 1785 E. Sahara Avenue, Suite 490-204 + * Las Vegas, Nevada 89104 + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @copyright Copyright (c) 2006, Cake Software Foundation, Inc. + * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project + * @package cake + * @subpackage cake.app.config + * @since CakePHP v 0.10.8.2117 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + */ + +/** + * + * This file is loaded automatically by the app/webroot/index.php file after the core bootstrap.php is loaded + * This is an application wide file to load any function that is not used within a class define. + * You can also use this to include or require any files in your application. + * + */ + +/** + * The settings below can be used to set additional paths to models, views and controllers. + * This is related to Ticket #470 (https://trac.cakephp.org/ticket/470) + * + * $modelPaths = array('full path to models', 'second full path to models', 'etc...'); + * $viewPaths = array('this path to views', 'second full path to views', 'etc...'); + * $controllerPaths = array('this path to controllers', 'second full path to controllers', 'etc...'); + * + */ + +//EOF +?> \ No newline at end of file diff --git a/cake/scripts/templates/skel/config/core.php b/cake/scripts/templates/skel/config/core.php new file mode 100644 index 000000000..810828212 --- /dev/null +++ b/cake/scripts/templates/skel/config/core.php @@ -0,0 +1,153 @@ + + * Copyright (c) 2006, Cake Software Foundation, Inc. + * 1785 E. Sahara Avenue, Suite 490-204 + * Las Vegas, Nevada 89104 + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @copyright Copyright (c) 2006, Cake Software Foundation, Inc. + * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project + * @package cake + * @subpackage cake.app.config + * @since CakePHP v 0.2.9 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + */ + +/** + * If you do not have mod rewrite on your system + * or if you prefer to use CakePHP pretty urls. + * uncomment the line below. + * Note: If you do have mod rewrite but prefer the + * CakePHP pretty urls, you also have to remove the + * .htaccess files + * release/.htaccess + * release/app/.htaccess + * release/app/webroot/.htaccess + */ +//define ('BASE_URL', env('SCRIPT_NAME')); + +/** + * Set debug level here: + * - 0: production + * - 1: development + * - 2: full debug with sql + * - 3: full debug with sql and dump of the current object + * + * In production, the "flash messages" redirect after a time interval. + * With the other debug levels you get to click the "flash message" to continue. + * + */ +define('DEBUG', 1); +/** + * Turn of caching checking wide. + * You must still use the controller var cacheAction inside you controller class. + * You can either set it controller wide, or in each controller method. + * use var $cacheAction = true; or in the controller method $this->cacheAction = true; + */ +define ('CACHE_CHECK', false); +/** + * Error constant. Used for differentiating error logging and debugging. + * Currently PHP supports LOG_DEBUG + */ +define ('LOG_ERROR', 2); +/** + * CakePHP includes 3 types of session saves + * database or file. Set this to your preferred method. + * If you want to use your own save handler place it in + * app/config/name.php DO NOT USE file or database as the name. + * and use just the name portion below. + * + * Setting this to cake will save files to /cakedistro/tmp directory + * Setting it to php will use the php default save path + * Setting it to database will use the database + * + * + */ +define('CAKE_SESSION_SAVE', 'php'); +/** + * Set a random string of used in session. + * + */ +define('CAKE_SESSION_STRING', 'DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi'); +/** + * Set the name of session cookie + * + */ +define('CAKE_SESSION_COOKIE', 'CAKEPHP'); + +/** + * Set level of Cake security. + * + */ +define('CAKE_SECURITY', 'high'); + +/** + * Set Cake Session time out. + * If CAKE_SECURITY define is set + * high: multiplied by 10 + * medium: is multiplied by 100 + * low is: multiplied by 300 + * + * Number below is seconds. + */ +define('CAKE_SESSION_TIMEOUT', '120'); + +/** + * Uncomment the define below to use cake built in admin routes. + * You can set this value to anything you want. + * All methods related to the admin route should be prefixed with the + * name you set CAKE_ADMIN to. + * For example: admin_index, admin_edit + */ +//define('CAKE_ADMIN', 'admin'); + +/** + * The define below is used to turn cake built webservices + * on or off. Default setting is off. + */ +define('WEBSERVICES', 'off'); + +/** + * Compress output CSS (removing comments, whitespace, repeating tags etc.) + * This requires a/var/cache directory to be writable by the web server (caching). + * To use, prefix the CSS link URL with '/ccss/' instead of '/css/' or use Controller::cssTag(). + */ +define('COMPRESS_CSS', false); + +/** + * If set to true, helpers would output data instead of returning it. + */ +define('AUTO_OUTPUT', false); + +/** + * If set to false, session would not automatically be started. + */ +define('AUTO_SESSION', true); + +/** + * Set the max size of file to use md5() . + */ +define('MAX_MD5SIZE', (5*1024)*1024 ); + +/** + * To use Access Control Lists with Cake... + */ +define('ACL_CLASSNAME', 'DB_ACL'); +define('ACL_FILENAME', 'dbacl'.DS.'db_acl'); + +?> \ No newline at end of file diff --git a/cake/scripts/templates/skel/config/database.php.default b/cake/scripts/templates/skel/config/database.php.default new file mode 100644 index 000000000..77288bf1f --- /dev/null +++ b/cake/scripts/templates/skel/config/database.php.default @@ -0,0 +1,79 @@ + + * Copyright (c) 2006, Cake Software Foundation, Inc. + * 1785 E. Sahara Avenue, Suite 490-204 + * Las Vegas, Nevada 89104 + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @copyright Copyright (c) 2006, Cake Software Foundation, Inc. + * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project + * @package cake + * @subpackage cake.app.config + * @since CakePHP v 0.2.9 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + */ + +/** + * In this file you set up your database connection details. + * + * @package cake + * @subpackage cake.config + */ + + +/** + * Database configuration class. + * You can specify multiple configurations for production, development and testing. + * + * driver => + * mysql, postgres, sqlite, adodb-drivername, pear-drivername + * + * connect => + * MySQL set the connect to either mysql_pconnect of mysql_connect + * PostgreSQL set the connect to either pg_pconnect of pg_connect + * SQLite set the connect to sqlite_popen sqlite_open + * ADOdb set the connect to one of these + * (http://phplens.com/adodb/supported.databases.html) and + * append it '|p' for persistent connection. (mssql|p for example, or just mssql for not persistent) + * + * host => + * the host you connect to the database + * MySQL 'localhost' to add a port number use 'localhost:port#' + * PostgreSQL 'localhost' to add a port number use 'localhost port=5432' + * + */ +class DATABASE_CONFIG +{ + var $default = array('driver' => 'mysql', + 'connect' => 'mysql_connect', + 'host' => 'localhost', + 'login' => 'user', + 'password' => 'password', + 'database' => 'project_name', + 'prefix' => ''); + + var $test = array('driver' => 'mysql', + 'connect' => 'mysql_connect', + 'host' => 'localhost', + 'login' => 'user', + 'password' => 'password', + 'database' => 'project_name-test', + 'prefix' => ''); +} + +?> \ No newline at end of file diff --git a/cake/scripts/templates/skel/config/inflections.php b/cake/scripts/templates/skel/config/inflections.php new file mode 100644 index 000000000..42c973e99 --- /dev/null +++ b/cake/scripts/templates/skel/config/inflections.php @@ -0,0 +1,74 @@ + + * Copyright (c) 2006, Cake Software Foundation, Inc. + * 1785 E. Sahara Avenue, Suite 490-204 + * Las Vegas, Nevada 89104 + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @copyright Copyright (c) 2006, Cake Software Foundation, Inc. + * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project + * @package cake + * @subpackage cake.app.config + * @since CakePHP v 1.0.0.2312 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + */ + +/** + * This is a key => value array of regex used to match words. + * If key matches then the value is returned. + * + * $pluralRules = array('/(s)tatus$/i' => '\1\2tatuses', '/^(ox)$/i' => '\1\2en', '/([m|l])ouse$/i' => '\1ice'); + */ +$pluralRules = array(); +/** + * This is a key only array of plural words that should not be inflected. + * Notice the last comma + * + * $uninflectedPlural = array('.*[nrlm]ese', '.*deer', '.*fish', '.*measles', '.*ois', '.*pox'); + */ +$uninflectedPlural = array(); +/** + * This is a key => value array of plural irregular words. + * If key matches then the value is returned. + * + * $irregularPlural = array('atlas' => 'atlases', 'beef' => 'beefs', 'brother' => 'brothers') + */ +$irregularPlural = array(); +/** + * This is a key => value array of regex used to match words. + * If key matches then the value is returned. + * + * $singularRules = array('/(s)tatuses$/i' => '\1\2tatus', '/(matr)ices$/i' =>'\1ix','/(vert|ind)ices$/i') + */ +$singularRules = array(); +/** + * This is a key only array of singular words that should not be inflected. + * You should not have to change this value below if you do change it use same format + * as the $uninflectedPlural above. + */ +$uninflectedSingular = $uninflectedPlural; +/** + * This is a key => value array of singular irregular words. + * Most of the time this will be a reverse of the above $irregularPlural array + * You should not have to change this value below if you do change it use same format + * + * $irregularSingular = array('atlases' => 'atlas', 'beefs' => 'beef', 'brothers' => 'brother') + */ +$irregularSingular = array_flip($irregularPlural); +?> \ No newline at end of file diff --git a/cake/scripts/templates/skel/config/routes.php b/cake/scripts/templates/skel/config/routes.php new file mode 100644 index 000000000..52dabb918 --- /dev/null +++ b/cake/scripts/templates/skel/config/routes.php @@ -0,0 +1,51 @@ + + * Copyright (c) 2006, Cake Software Foundation, Inc. + * 1785 E. Sahara Avenue, Suite 490-204 + * Las Vegas, Nevada 89104 + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @copyright Copyright (c) 2006, Cake Software Foundation, Inc. + * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project + * @package cake + * @subpackage cake.app.config + * @since CakePHP v 0.2.9 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + */ + +/** + * Here, we are connecting '/' (base path) to controller called 'Pages', + * its action called 'display', and we pass a param to select the view file + * to use (in this case, /app/views/pages/home.thtml)... + */ +$Route->connect ('/', array('controller'=>'pages', 'action'=>'display', 'home')); + +/** + * ...and connect the rest of 'Pages' controller's urls. + */ +$Route->connect ('/pages/*', array('controller'=>'pages', 'action'=>'display')); + +/** + * Then we connect url '/test' to our test controller. This is helpfull in + * developement. + */ +$Route->connect ('/tests', array('controller'=>'tests', 'action'=>'index')); + +?> diff --git a/cake/scripts/templates/skel/config/sql/db_acl.sql b/cake/scripts/templates/skel/config/sql/db_acl.sql new file mode 100644 index 000000000..8c7aae84f --- /dev/null +++ b/cake/scripts/templates/skel/config/sql/db_acl.sql @@ -0,0 +1,30 @@ +CREATE TABLE `acos` ( + `id` int(11) NOT NULL auto_increment, + `model` varchar(255) NOT NULL default '', + `object_id` int(11) default NULL, + `alias` varchar(255) NOT NULL default '', + `lft` int(11) default NULL, + `rght` int(11) default NULL, + PRIMARY KEY (`id`) +); + +CREATE TABLE `aros` ( + `id` int(11) NOT NULL auto_increment, + `model` varchar(255) NOT NULL default '', + `user_id` int(11) default NULL, + `alias` varchar(255) NOT NULL default '', + `lft` int(11) default NULL, + `rght` int(11) default NULL, + PRIMARY KEY (`id`) +); + +CREATE TABLE `aros_acos` ( + `id` int(11) NOT NULL auto_increment, + `aro_id` int(11) default NULL, + `aco_id` int(11) default NULL, + `_create` int(1) NOT NULL default '0', + `_read` int(1) NOT NULL default '0', + `_update` int(1) NOT NULL default '0', + `_delete` int(11) NOT NULL default '0', + PRIMARY KEY (`id`) +); diff --git a/cake/scripts/templates/skel/config/sql/sessions.sql b/cake/scripts/templates/skel/config/sql/sessions.sql new file mode 100644 index 000000000..6ff635dfa --- /dev/null +++ b/cake/scripts/templates/skel/config/sql/sessions.sql @@ -0,0 +1,11 @@ +-- @copyright Copyright (c) 2006, Cake Software Foundation, Inc. +-- @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project +-- @since CakePHP v 0.10.8.1997 +-- @version $Revision$ + +CREATE TABLE cake_sessions ( + id varchar(255) NOT NULL default '', + data text, + expires int(11) default NULL, + PRIMARY KEY (id) +); \ No newline at end of file diff --git a/cake/scripts/templates/skel/index.php b/cake/scripts/templates/skel/index.php new file mode 100644 index 000000000..4dc8cfe57 --- /dev/null +++ b/cake/scripts/templates/skel/index.php @@ -0,0 +1,27 @@ + + * Copyright (c) 2006, Cake Software Foundation, Inc. + * 1785 E. Sahara Avenue, Suite 490-204 + * Las Vegas, Nevada 89104 + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @copyright Copyright (c) 2006, Cake Software Foundation, Inc. + * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project + * @package cake + * @subpackage cake.app + * @since CakePHP v 0.10.0.1076 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + */ +require 'webroot'.DIRECTORY_SEPARATOR.'index.php'; +?> \ No newline at end of file diff --git a/cake/scripts/templates/skel/views/layouts/ajax.thtml b/cake/scripts/templates/skel/views/layouts/ajax.thtml new file mode 100644 index 000000000..4b9624a2b --- /dev/null +++ b/cake/scripts/templates/skel/views/layouts/ajax.thtml @@ -0,0 +1,31 @@ + + * Copyright (c) 2006, Cake Software Foundation, Inc. + * 1785 E. Sahara Avenue, Suite 490-204 + * Las Vegas, Nevada 89104 + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @copyright Copyright (c) 2006, Cake Software Foundation, Inc. + * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project + * @package cake + * @subpackage cake.cake.libs.view.templates.layouts + * @since CakePHP v 0.10.0.1076 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + */ +?> + \ No newline at end of file diff --git a/cake/scripts/templates/skel/views/layouts/default.thtml b/cake/scripts/templates/skel/views/layouts/default.thtml new file mode 100644 index 000000000..3dcdbb07f --- /dev/null +++ b/cake/scripts/templates/skel/views/layouts/default.thtml @@ -0,0 +1,29 @@ + + + +CakePHP : <?php echo $title_for_layout?> + +css('generic.basic');?> +css('generic.forms');?> + + +
+ +
+ controller->Session->check('Message.flash')) + $this->controller->Session->flash(); + ?> + +
+ +
+ + \ No newline at end of file diff --git a/cake/scripts/templates/skel/views/layouts/flash.thtml b/cake/scripts/templates/skel/views/layouts/flash.thtml new file mode 100644 index 000000000..3183f013e --- /dev/null +++ b/cake/scripts/templates/skel/views/layouts/flash.thtml @@ -0,0 +1,51 @@ + + * Copyright (c) 2006, Cake Software Foundation, Inc. + * 1785 E. Sahara Avenue, Suite 490-204 + * Las Vegas, Nevada 89104 + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @copyright Copyright (c) 2006, Cake Software Foundation, Inc. + * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project + * @package cake + * @subpackage cake.cake.libs.view.templates.layouts + * @since CakePHP v 0.10.0.1076 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + */ +?> + + + +<?php echo $page_title?> + + + + + + + + + +

+ + + \ No newline at end of file diff --git a/cake/scripts/templates/skel/webroot/.htaccess b/cake/scripts/templates/skel/webroot/.htaccess new file mode 100644 index 000000000..f9d8b938b --- /dev/null +++ b/cake/scripts/templates/skel/webroot/.htaccess @@ -0,0 +1,6 @@ + + RewriteEngine On + RewriteCond %{REQUEST_FILENAME} !-d + RewriteCond %{REQUEST_FILENAME} !-f + RewriteRule ^(.*)$ index.php?url=$1 [QSA,L] + \ No newline at end of file diff --git a/cake/scripts/templates/skel/webroot/css.php b/cake/scripts/templates/skel/webroot/css.php new file mode 100644 index 000000000..a000320ba --- /dev/null +++ b/cake/scripts/templates/skel/webroot/css.php @@ -0,0 +1,116 @@ + + * Copyright (c) 2006, Cake Software Foundation, Inc. + * 1785 E. Sahara Avenue, Suite 490-204 + * Las Vegas, Nevada 89104 + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @copyright Copyright (c) 2006, Cake Software Foundation, Inc. + * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project + * @package cake + * @subpackage cake.app.webroot + * @since CakePHP 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... + */ +require(CONFIGS.'paths.php'); +require(CAKE.'basics.php'); +require(LIBS.'folder.php'); +require(LIBS.'file.php'); +require(LIBS.'legacy.php'); + +/** + * Enter description here... + * + * @param unknown_type $path + * @param unknown_type $name + * @return unknown + */ +function make_clean_css ($path, $name) +{ + require(VENDORS.'csspp'.DS.'csspp.php'); + + $data = file_get_contents($path); + $csspp = new csspp(); + $output = $csspp->compress($data); + + $ratio = 100-(round(strlen($output)/strlen($data), 3)*100); + $output = " /* file: $name, ratio: $ratio% */ " . $output; + + return $output; +} + +/** + * Enter description here... + * + * @param unknown_type $path + * @param unknown_type $content + * @return unknown + */ +function write_css_cache ($path, $content) +{ + if (!is_dir(dirname($path))) + mkdir(dirname($path)); + + $cache = new File($path); + return $cache->write($content); +} + +if (preg_match('|\.\.|', $url) || !preg_match('|^ccss/(.+)$|i', $url, $regs)) + die('Wrong file name.'); + +$filename = 'css/'.$regs[1]; +$filepath = CSS.$regs[1]; +$cachepath = CACHE.'css'.DS.str_replace(array('/','\\'), '-', $regs[1]); + +if (!file_exists($filepath)) + die('Wrong file name.'); + + +if (file_exists($cachepath)) +{ + $templateModified = filemtime($filepath); + $cacheModified = filemtime($cachepath); + + if ($templateModified > $cacheModified) + { + $output = make_clean_css ($filepath, $filename); + write_css_cache ($cachepath, $output); + } + else + { + $output = file_get_contents($cachepath); + } +} +else +{ + $output = make_clean_css ($filepath, $filename); + write_css_cache ($cachepath, $output); +} + +header("Date: ".date("D, j M Y G:i:s ", $templateModified).'GMT'); +header("Content-Type: text/css"); +header("Expires: ".gmdate("D, j M Y H:i:s", time()+DAY)." GMT"); +header("Cache-Control: cache");// HTTP/1.1 +header("Pragma: cache");// HTTP/1.0 +print $output; + +?> \ No newline at end of file diff --git a/cake/scripts/templates/skel/webroot/css/generic.basic.css b/cake/scripts/templates/skel/webroot/css/generic.basic.css new file mode 100644 index 000000000..ec5a30822 --- /dev/null +++ b/cake/scripts/templates/skel/webroot/css/generic.basic.css @@ -0,0 +1,176 @@ +*{ +margin:0; +padding:0; +} + +body{ +font-family:verdana,helvetica,arial,sans-serif; +font-size:12px; +text-align:center; +color:#333; +background:#fff; +line-height: 18px; +} + +/* +* General Style Info +*/ + +a{ +color:#003d4c; +text-decoration:none; +} +a:hover{ +color:#003d4c; +text-decoration:underline; +} + +a img{ +border:none; +} + +h1, h2, h3, h4{ +font-family:'Gill Sans'; +font-weight:normal; +} + +h1{ +font-size:28px; +padding:0.5em 0; +color:#003d4c; +} + +em { + font-size: 12px; +} + +h2{ +font-size:24px; +padding-top:0.15em; +margin:0.3em 0; +color:#e32000; +} + +h3{ +font-size:18px; +padding-top:0.5em; +color:#003d4c; +} + +h4{ +color:#ff9966; +font-size:16px; +padding-top:0.5em; +font-weight:normal; +} +ul, li { +margin: 0 12px; +} + +/* +* Layout +*/ + +#container{ +text-align:left; +} + +#header{ +background:#003d4c; +padding: 4px 20px; +} + +#header h1{ +color:#fff; +font-family: 'Gill Sans'; +font-size: 45px; +font-weight:normal; +} + + +#content{ +padding: 10px 40px; +} +#footer{ +padding: 6px 10px; +background:#003d4c; +text-align: right; +} + +/* tables */ + +table { + width: 100%; + border: 1px solid #003d4c; + color:#333; + background-color: #fff; + clear:both; + padding: 0; + margin: 0 0 2em 0; + white-space: normal; +} +th { + background-color: #ccc; + border-top: 1px solid #fff; + border-left: 1px solid #fff; + border-right: 1px solid #003d4c; + border-bottom: 1px solid #003d4c; + text-align: center; + padding:1px; +} +table tr td { + border-right: 1px solid #ccc; + padding:4px 4px; + vertical-align:top; + text-align: center; +} +table tr.altRow td { + background: #f4f4f4; +} + +/* scaffold show */ + + +div.related { + clear:both; + display:block; +} +dl { + line-height:2em; + margin:1em; + float:left; + width: 400px; +} +dt { + font-weight: bold; + vertical-align:top; +} +dd { + margin-left:10em; + margin-top:-2em; + vertical-align:top; +} + +/* scaffold buttons */ + + +.notice { + color: #DB8101; + background-color: #ddd; + display: block; + padding: 1em; +} +.tip { + color: #DB8101; + background-color: #ddd; + display: block; + padding: 1em; +} + + +/* action links */ +ul.actions { + float:left; + margin-left: 10px; + width: 200px; +} \ No newline at end of file diff --git a/cake/scripts/templates/skel/webroot/css/generic.forms.css b/cake/scripts/templates/skel/webroot/css/generic.forms.css new file mode 100644 index 000000000..243b3f18b --- /dev/null +++ b/cake/scripts/templates/skel/webroot/css/generic.forms.css @@ -0,0 +1,279 @@ +/* form.css */ + +form { + margin: 0 4px; + font-size: 120%; + border-width: 0px 0px 0px 0px; + border-style: solid; + border-color: #DB8101; +} + +form fieldset { + font-size: 100%; + border-color: #000000; + border-width: 1px 0px 0px 0px; + border-style: solid none none none; + padding: 10px; +} + +form fieldset legend { + font-size: 150%; + font-weight: normal; + color: #000; + padding: 0px 5px; +} + +label { + font-size: 150%; +} + +label u { + font-style: normal; + text-decoration: underline; +} + +input, select, textarea { + font-family: Tahoma, Arial, sans-serif; + font-size: 100%; + color: #000; +} + +textarea { + overflow: auto; +} + +form div { + clear: left; + display: block; + margin: 5px 0px 0px 0px; + padding: 1px 3px; +} + +form fieldset div.notes { + float: right; + width: 158px; + height: auto; + margin: 0px 0px 10px 10px; + padding: 5px; + border: 1px solid #666; + background-color: #ffffe1; + color: #666; + font-size: 88%; +} + +form fieldset div.notes h4 { + background-image: url(/images/icon_info.gif); + background-repeat: no-repeat; + background-position: top left; + padding: 3px 0px 3px 27px; + border-width: 0px 0px 1px 0px; + border-style: solid; + border-color: #666; + color: #666; + font-size: 110%; +} + +form fieldset div.notes p { + margin: 0em 0em 1.2em 0em; + color: #666; +} + +form fieldset div.notes p.last { + margin: 0em; +} + +form div fieldset { + clear: none; + border-width: 0px 1px 0px 1px; + border-style: solid; + border-color: #666; + margin: 0px 0px 0px 142px; + padding: 0px 5px 5px 5px; +} + +form div fieldset legend { + font-size: 100%; + padding: 0px 3px 0px 9px; +} + +form div.required fieldset legend { + font-weight: bold; +} + +form div label { + display: block; + float: left; + width: 200px; + background-color: #f4f4f4; + font-size: 16px; + padding: 3px 5px; + margin: 0px 0px 5px 0px; + text-align: right; +} + +form div.optional label, label.optional { + font-weight: normal; +} + +form div.required label, label.required { + font-weight: bold; +} + +form div label.labelCheckbox, form div label.labelRadio { + float: none; + display: block; + margin: 0px 0px 5px 142px; + text-align: left; +} + +form div fieldset label.labelCheckbox, form div fieldset label.labelRadio { + margin: 0px 0px 5px 0px; +} +p.error { + color: #DB8101; + background-color: #DBA941; + font-size: 14px; + padding: 1em; +} + +form div input, form div select, form div textarea { + padding: 1px 3px; + margin: 0px 0px 0px 0px; +} + +form div input.inputFile { + width: 211px; +} + +form div select.selectOne, form div select.selectMultiple { + width: 211px; + padding: 1px 3px; +} + +form div input.inputCheckbox, form div input.inputRadio, input.inputCheckbox, input.inputRadio { + display: inline; + height: 14px; + width: 14px; + background-color: transparent; + border-width: 0px; +} + +form div.submit { + padding: 0px 0px 0px 140px; + clear:both; + display:block; +} + +div.submit input { + padding: 2px 12px; + color: #DB8101; + background-color:#ccc; + text-decoration: none; + border: 1px solid #666; + font-size: 14px; + font-weight: bold; + text-align:center; + text-decoration: none; + width: auto; +} +div.submit input:hover { + padding: 2px 12px; + color: #fff; + background-color:#DB8101; + text-decoration: none; + border: 1px solid #666; + font-size: 14px; + font-weight: bold; + text-align:center; + text-decoration: none; + width: auto; +} + +form div.submit div input.inputSubmit, form div.submit div input.inputButton { + float: right; + margin: 0px 0px 0px 5px; +} + +form div small { + display: block; + margin: 0px 0px 5px 142px; + padding: 1px 3px; + font-size: 88%; +} + +/* form.import.css */ + +form fieldset legend { + line-height: 150%; +} + +form input, form select, form textarea { + background-color: #fff; +} + +div.optional label:before { + content: ''; +} + +div.required label:before { + content: ''; +} + +form div label.labelCheckbox, form div label.labelRadio, label.labelCheckbox, label.labelRadio { + display: block; + width: 190px; + padding: 4px 0px 0px 18px; + text-indent: -18px; + line-height: 120%; +} + +form div label.labelCheckbox input.inputCheckbox, form div label.labelRadio input.inputRadio, label.labelCheckbox input.inputCheckbox, label.labelRadio input.inputRadio { + margin: 0; +} + +form div fieldset input.inputText, form div fieldset input.inputPassword, form div fieldset input.inputFile, form div fieldset textarea.inputTextarea { + width: 160px; + margin: 0px 0px 0px 18px; +} + +form div label.compact { + display: inline; + width: auto; + padding: 4px 10px 0px 0px; + text-indent: 0px; + margin: 0; +} + +form div.wide label { + float: none; + display: block; +} + +form div label.wide { + width: 348px; +} + +form div.wide input.inputText, form div.wide input.inputPassword, form div.wide input.inputFile, form div.wide select, form div.wide textarea { + width: 344px; + margin: 0; +} + +form div.notes p, form div small { + line-height: 125%; +} + +form div.wide small { + margin: 0px 0px 5px 0px; +} + +div.date select { + width:auto; +} + +select.autoWidth { + width:auto; +} + +option { + padding-left:1em; +} \ No newline at end of file diff --git a/cake/scripts/templates/skel/webroot/favicon.ico b/cake/scripts/templates/skel/webroot/favicon.ico new file mode 100644 index 000000000..8c5c557bf Binary files /dev/null and b/cake/scripts/templates/skel/webroot/favicon.ico differ diff --git a/cake/scripts/templates/skel/webroot/img/cake.power.png b/cake/scripts/templates/skel/webroot/img/cake.power.png new file mode 100644 index 000000000..699ef80fd Binary files /dev/null and b/cake/scripts/templates/skel/webroot/img/cake.power.png differ diff --git a/cake/scripts/templates/skel/webroot/index.php b/cake/scripts/templates/skel/webroot/index.php new file mode 100644 index 000000000..728591072 --- /dev/null +++ b/cake/scripts/templates/skel/webroot/index.php @@ -0,0 +1,114 @@ + + * Copyright (c) 2006, Cake Software Foundation, Inc. + * 1785 E. Sahara Avenue, Suite 490-204 + * Las Vegas, Nevada 89104 + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @copyright Copyright (c) 2006, Cake Software Foundation, Inc. + * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project + * @package cake + * @subpackage cake.app.webroot + * @since CakePHP v 0.2.9 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + */ + +/** + * Do not change + */ +if (!defined('DS')) +{ + define('DS', DIRECTORY_SEPARATOR); +} + +/** + * These defines should only be edited if you have cake installed in + * a directory layout other than the way it is distributed. + * Each define has a commented line of code that explains what you would change. + * + */ +if (!defined('ROOT')) +{ +//define('ROOT', 'FULL PATH TO DIRECTORY WHERE APP DIRECTORY IS LOCATED DO NOT ADD A TRAILING DIRECTORY SEPARATOR'; +//You should also use the DS define to seperate your directories + define('ROOT', dirname(dirname(dirname(__FILE__)))); +} + +if (!defined('APP_DIR')) +{ +//define('APP_DIR', 'DIRECTORY NAME OF APPLICATION'; + define ('APP_DIR', basename(dirname(dirname(__FILE__)))); +} + +/** + * This only needs to be changed if the cake installed libs are located + * outside of the distributed directory structure. + */ +if (!defined('CAKE_CORE_INCLUDE_PATH')) +{ +//define ('CAKE_CORE_INCLUDE_PATH', FULL PATH TO DIRECTORY WHERE CAKE CORE IS INSTALLED DO NOT ADD A TRAILING DIRECTORY SEPARATOR'; +//You should also use the DS define to seperate your directories + define('CAKE_CORE_INCLUDE_PATH', ROOT); +} + + +/////////////////////////////// +//DO NOT EDIT BELOW THIS LINE// +/////////////////////////////// + +if (!defined('WEBROOT_DIR')) +{ + define ('WEBROOT_DIR', basename(dirname(__FILE__))); +} + +if (!defined('WWW_ROOT')) +{ + define('WWW_ROOT', dirname(__FILE__).DS); +} + +if(!defined('CORE_PATH')) +{ + if(function_exists('ini_set')) + { + ini_set('include_path',ini_get('include_path').PATH_SEPARATOR.CAKE_CORE_INCLUDE_PATH.PATH_SEPARATOR.ROOT.DS.APP_DIR.DS); + define('APP_PATH', null); + define('CORE_PATH', null); + } + else + { + define('APP_PATH', ROOT.DS.APP_DIR.DS); + define('CORE_PATH', CAKE_CORE_INCLUDE_PATH.DS); + } +} + +require CORE_PATH.'cake'.DS.'bootstrap.php'; + +if(isset($_GET['url']) && $_GET['url'] === 'favicon.ico') +{ +} +else +{ + $Dispatcher= new Dispatcher (); + $Dispatcher->dispatch($url); +} + +if (DEBUG) +{ + echo ""; +} +?> \ No newline at end of file diff --git a/cake/scripts/templates/skel/webroot/js/vendors.php b/cake/scripts/templates/skel/webroot/js/vendors.php new file mode 100644 index 000000000..4dd8d34c4 --- /dev/null +++ b/cake/scripts/templates/skel/webroot/js/vendors.php @@ -0,0 +1,40 @@ + + * Copyright (c) 2006, Cake Software Foundation, Inc. + * 1785 E. Sahara Avenue, Suite 490-204 + * Las Vegas, Nevada 89104 + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @copyright Copyright (c) 2006, Cake Software Foundation, Inc. + * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project + * @package cake + * @subpackage cake.app.webroot.js + * @since CakePHP 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... + */ +if(is_file('../../vendors/javascript/'.$_GET['file']) && (preg_match('/(.+)\\.js/', $_GET['file']))) +{ + readfile('../../vendors/javascript/'.$_GET['file']); +} + +?> diff --git a/cake/scripts/templates/views/home.thtml b/cake/scripts/templates/views/home.thtml new file mode 100644 index 000000000..068b38060 --- /dev/null +++ b/cake/scripts/templates/views/home.thtml @@ -0,0 +1,16 @@ +Your database configuration file is

\n"; +$output .= "\n"; +$output .= "\n"; +$output .= "getDataSource('default'); ?>\n"; +$output .= "

CakeisConnected() ? ' is able to' : ' is not able to';?> connect to the database.

\n"; +$output .= "
\n"; +$output .= "\n"; +$output .= "

CakePHP just \"Baked\" your application: ".Inflector::humanize($app)."

\n"; +$output .= "

Editing this Page

\n"; +$output .= "

\n"; +$output .= "To change the content of this page, edit: ".$dir.DS."views".DS."pages".DS."home.thtml.
\n"; +$output .= "To change its layout, edit: ".$dir.DS."views".DS."layouts".DS."default.thtml.
\n"; +$output .= "You can also add some CSS styles for your pages at: ".$dir.DS."webroot/css/.\n"; +$output .= "

\n"; +?> \ No newline at end of file diff --git a/index.php b/index.php index f6d11db16..c114aa0fb 100644 --- a/index.php +++ b/index.php @@ -37,7 +37,7 @@ define ('DS', DIRECTORY_SEPARATOR); define ('ROOT', dirname(__FILE__)); define ('WEBROOT_DIR', 'webroot'); -define('WWW_ROOT', ROOT.APP_DIR.DS.WEBROOT_DIR.DS); +define('WWW_ROOT', ROOT.DS.APP_DIR.DS.WEBROOT_DIR.DS); /** * This only needs to be changed if the cake installed libs are located * outside of the distributed directory structure.