Permalink
Browse files

Importing stuff, this includes basic route checking

  • Loading branch information...
0 parents commit b702dff68a595ea73662325d5d912e8306f93c72 @BRMatt committed Oct 4, 2009
@@ -0,0 +1 @@
+**/**/*.php~
@@ -0,0 +1,35 @@
+<?php defined('SYSPATH') OR die('No direct script access');
+
+Class Controller_Devils_Controller extends Controller_Template
+{
+ public $template = 'devils/layout';
+
+ public $auto_render = TRUE;
+
+ function after()
+ {
+ $devils = array();
+ $route = Route::get('devilities');
+
+ foreach(Kohana::list_files('classes/controller/devils') as $devil => $_ignore)
+ {
+ // The name of our devil, horns removed
+ $devil = substr($devil, strrpos($devil, '/') +1, - strlen(EXT));
+
+ // The wolf is not a devil!
+ if($devil === 'controller' OR $devil === 'media')
+ continue;
+
+ $attributes = ($devil == $this->request->controller) ? array('class' => 'selected') : array();
+ $params = array('controller'=>$devil);
+
+ $devils[] = Html::anchor($route->uri($params), ucfirst($devil), $attributes);
+ }
+
+
+ $this->template->set('devils', $devils);
+
+ // Render the template
+ return parent::after();
+ }
+}
@@ -0,0 +1,11 @@
+<?php defined('SYSPATH') OR die('No direct script access');
+
+Class Controller_Devils_Main extends Controller_Devils_Controller
+{
+ public $template = 'devils/layout';
+
+ function action_index()
+ {
+
+ }
+}
@@ -0,0 +1,29 @@
+<?php
+
+Class Controller_Devils_Media extends Controller
+{
+ public function action_index()
+ {
+ // Get the file path from the request
+ $file = $this->request->param('id');
+
+ // Find the file extension
+ $ext = pathinfo($file, PATHINFO_EXTENSION);
+
+ // Remove the extension from the filename
+ $file = substr($file, 0, -(strlen($ext) + 1));
+
+ if ($file = Kohana::find_file('media/'.$ext, $file, $ext))
+ {
+ // Send the file content as the response
+ $this->request->response = file_get_contents($file);
+ }
+ else
+ {
+ // Return a 404 status
+ $this->request->status = 404;
+ }
+ // Set the content type for this extension
+ $this->request->headers['Content-Type'] = File::mime_by_ext($ext);
+ }
+}
@@ -0,0 +1,81 @@
+<?php defined('SYSPATH') OR die('No Direct Script Access');
+
+
+Class Controller_Devils_Routes extends Controller_Devils_Main
+{
+ function action_index()
+ {
+ // TODO: Allow users to "generate" code for routes
+ $this->request->redirect($this->request->uri(array('action' => 'check')));
+ }
+
+ function action_check()
+ {
+ $all_routes = Route::all();
+ $errors = array();
+ $routes = array();
+ $results= array();
+
+ $validation = Validate::factory($_POST)
+ ->filter('tests', 'trim')
+ ->rule('route_id', 'is_array')
+ ->rule('route_id', 'count')
+ ->rule('tests', 'not_empty');
+
+ $submitted = $validation->check();
+ $data = $validation->as_array();
+
+ if($submitted)
+ {
+ $data['tests'] = str_replace("\n\r", "\n", $data['tests']);
+ $tests = explode("\n", $data['tests']);
+
+ for($test = 0, $test_count = count($tests); $test < $test_count; ++$test)
+ {
+ $tests[$test] = trim(trim($tests[$test], '/'));
+ }
+
+ foreach((array) $data['route_id'] as $route_id)
+ {
+ $route = NULL;
+
+ if($route_id === '::CREATE::')
+ {
+ // Create a route on the fly
+ $route_id = 'KohanaRocksMySocks';
+
+ $route = new Route($route_id, $data['route_uri']);
+ }
+ else
+ {
+ $route = Route::get($route_id);
+ }
+
+ $route_id = $route_id . ' - <em>'.htmlspecialchars($route->uri).'</em>';
+ $results[$route_id] = array();
+
+ foreach($tests as $test)
+ {
+ $matches = $route->matches($test);
+
+ // Make the test display as /
+ if(empty($test))
+ $test = '/';
+
+ // Store the result and the parsed parameters
+ $results[$route_id][$test] = array(
+ 'matched' => $matches !== FALSE,
+ 'params' => $matches !== FALSE ? $matches : array()
+ );
+ }
+ }
+ }
+
+ $this->template->title = 'Check your Routes';
+ $this->template->body = new View('devils/routes/check');
+ $this->template->body->data = $data;
+ $this->template->body->defined_routes = $all_routes;
+ $this->template->body->errors = $validation->errors();
+ $this->template->body->results = $results;
+ }
+}
@@ -0,0 +1,9 @@
+<?php
+
+Class Route extends Kohana_Route
+{
+ public function __get($var)
+ {
+ return isset($this->{'_'.$var}) ? $this->{'_'.$var} : $this->$var;
+ }
+}
@@ -0,0 +1,9 @@
+<?php
+
+
+Route::set('devilities', 'devils(/<controller>(/<action>)(/<id>))', array('id' => '.*'))
+ ->defaults(array(
+ 'directory' => 'devils',
+ 'controller' => 'main',
+ 'action' => 'index',
+ ));
@@ -0,0 +1,112 @@
+
+/** This is the root form class **/
+.formable {}
+
+.formable fieldset {border: 1px solid #DFDFDF; border-radius: 10px; -moz-border-radius: 10px; -webkit-border-radius: 10px 10px;padding:0 0 10px 0;}
+
+
+.formable .ctrlHolder,
+.formable .buttonHolder,
+.formable p {padding: 8px; margin: 3px 10px;}
+
+.formable fieldset legend {
+ margin: 5px;
+ padding: 5px;
+ border: 1px solid #DFDFDF;
+ font-weight: bold;
+ color: #5F5F5F;
+ border-radius: 5px;
+ -moz-border-radius: 5px;
+ -webkit-border-radius: 5px 5px;
+ font-size: 1.3em;
+}
+
+.formable fieldset legend:hover {color: #3F3F3F;}
+
+.formable .ctrlHolder .fieldHint {color: #7F7F7F; margin: 2px 2px 0; padding: 0;}
+.formable em {color:#DF2929; margin:0 4px;font-weight:bolder;}
+
+/** Clearfix **/
+/*
+.formable .ctrlHolder,
+.formable .buttonHolder {overflow: auto;}
+*/
+.formable .ctrlHolder:after,
+.formable .buttonHolder:after {
+ clear: both;
+ content: ' ';
+ display: block;
+ font-size: 0;
+ line-height: 0;
+ visibility: hidden;
+ width: 0;
+ height: 0;
+}
+
+
+* html .formable .ctrlHolder {
+ height: 1%;
+}
+
+.formable .ctrlHolder {
+ display: block;
+}
+
+.formable .ctrlHolder label {font-size: 1.1em; font-weight: bold;}
+
+/** Form input styles **/
+.formable .ctrlHolder input[type="text"],
+.formable .ctrlHolder input[type="password"],
+.formable .ctrlHolder .textInput {font-size: 1.2em; border: 2px solid #DFDFDF; padding: 3px;}
+
+.formable .ctrlHolder input[type="text"]:focus,
+.formable .ctrlHolder input[type="password"]:focus,
+.formable .ctrlHolder .textInput:focus {border: 2px solid #4C70AF; outline: none;}
+
+.formable .ctrlHolder input.inputValid {border: 2px solid #319F40;}
+.formable .ctrlHolder input.inputInvalid,
+.formable .errorField input[type="text"],
+.formable .errorField input.textInput {border: 2px solid #CF3333;}
+
+/** Form styles **/
+.formable .inlineLabels .ctrlHolder label,
+.formable .ctrlHolder label {display: block; float: left; width: 42%;}
+
+.formable .inlineLabels .ctrlHolder input[type="text"],
+.formable .inlineLabels .ctrlHolder input[type="password"],
+.formable .inlineLabels .ctrlHolder .textInput,
+.formable .ctrlHolder input[type="text"],
+.formable .ctrlHolder input[type="password"],
+.formable .ctrlHolder .textInput {width: 55%;}
+
+.formable .blockLabels .ctrlHolder label {display: block; width: 100%;}
+.formable .blockLabels .ctrlHolder input[type="text"],
+.formable .blockLabels .ctrlHolder input[type="password"],
+.formable .blockLabels .ctrlHolder .textInput {width: 98%;}
+
+/** Form errors **/
+.formable .errorField {background-color: #FFAFB2; padding:8px; -moz-border-radius: 2px; -webkit-border-radius: 2px; border-radius: 2px;}
+.formable .errorMessage {background-color: #EF686D; padding: 5px 10px; font-weight: bold; color: #FFFFFF; margin: 0;-moz-border-radius: 2px; -webkit-border-radius: 2px; border-radius: 2px;}
+.formable .ctrlHolder .errorMessage {margin: 0 0 8px 0;}
+/** Form widgets **/
+
+.formable .ctrlWidget-Name label {display: block; width: 100%;}
+.formable .ctrlWidget-Name #first-name,
+.formable .ctrlWidget-Name #last-name {width: 47%; float: left;margin: 0 2.3% 0 0;}
+.formable .ctrlWidget-Name #last-name {margin: 0;}
+
+.formable .ctrlWidget-PasswordConfirm #password,
+.formable .ctrlWidget-PasswordConfirm #password-confirm {width: 47%; float: left;margin-right:2.3%;}
+.formable .ctrlWidget-PasswordConfirm #password-confirm {margin-right: 0;}
+
+.formable .ctrlWidget-YesNo label,
+.formable .blockLabels .ctrlWidget-YesNo label {float:left; display: block; width: 51%;}
+
+.formable .ctrlWidget-YesNo div {width:49%; float:right;}
+
+.formable .ctrlWidget-YesNo span,
+.formable .inlineLabels .ctrlWidget-YesNo span {/*display: block;*/margin-right: 10px;}
+
+.formable .ctrlWidget-YesNo span label,
+.formable .inlineLabels .ctrlWidget-YesNo span label,
+.formable .blockLabels .ctrlWidget-YesNo span label{float: none; display: inline; width: auto;}
@@ -0,0 +1,53 @@
+/* http://meyerweb.com/eric/tools/css/reset/ */
+/* v1.0 | 20080212 */
+
+html, body, div, span, applet, object, iframe,
+h1, h2, h3, h4, h5, h6, p, blockquote, pre,
+a, abbr, acronym, address, big, cite, code,
+del, dfn, em, font, img, ins, kbd, q, s, samp,
+small, strike, strong, sub, sup, tt, var,
+b, u, i, center,
+dl, dt, dd, ol, ul, li,
+fieldset, form, label, legend,
+table, caption, tbody, tfoot, thead, tr, th, td {
+ margin: 0;
+ padding: 0;
+ border: 0;
+ outline: 0;
+ font-size: 100%;
+ vertical-align: baseline;
+ background: transparent;
+}
+body {
+ line-height: 1;
+}
+ol, ul {
+ list-style: none;
+}
+blockquote, q {
+ quotes: none;
+}
+blockquote:before, blockquote:after,
+q:before, q:after {
+ content: '';
+ content: none;
+}
+
+/* remember to define focus styles! */
+:focus {
+ outline: 0;
+}
+
+/* remember to highlight inserts somehow! */
+ins {
+ text-decoration: none;
+}
+del {
+ text-decoration: line-through;
+}
+
+/* tables still need 'cellspacing="0"' in the markup */
+table {
+ border-collapse: collapse;
+ border-spacing: 0;
+}
Oops, something went wrong.

0 comments on commit b702dff

Please sign in to comment.