Example #1
0
 /**
  * Attempt to find a page in the CMS, return the response
  *
  * @param  string  The url to load, will be autodetected if needed
  * @return void
  */
 public function action_view($url = NULL)
 {
     if (Kohana::$profiling === TRUE) {
         // Start a new benchmark
         $benchmark = Profiler::start('Kohanut', 'Kohanut Controller');
     }
     // If no $url is passed, default to the server request uri
     if ($url === NULL) {
         $url = $_SERVER['REQUEST_URI'];
     }
     // Trim off Kohana::$base_url
     $url = preg_replace('#^' . Kohana::$base_url . '#', '', $url);
     // Ensure no trailing slash
     $url = preg_replace('/\\/$/', '', $url);
     // Ensure no leading slash
     $url = preg_replace('/^\\//', '', $url);
     // Remove anything ofter a ? or #
     $url = preg_replace('/[\\?#].+/', '', $url);
     // Try to find what to do on this url
     try {
         // Make sure the url is clean. See http://www.faqs.org/rfcs/rfc2396.html see section 2.3
         // TODO - this needs to be better
         if (preg_match("/[^\\/A-Za-z0-9-_\\.!~\\*\\(\\)]/", $url)) {
             Kohana::$log->add('INFO', "Kohanut - Request had unknown characters. '{$url}'");
             throw new Kohanut_Exception("Url request had unknown characters '{$url}'", array(), 404);
         }
         // Check for a redirect on this url
         Sprig::factory('kohanut_redirect', array('url', $url))->go();
         // Find the page that matches this url, and isn't an external link
         $query = DB::select()->where('url', '=', $url)->where('islink', '=', 0);
         $page = Sprig::factory('kohanut_page')->load($query);
         if (!$page->loaded()) {
             // Could not find page in database, throw a 404
             Kohana::$log->add('INFO', "Kohanut - Could not find '{$url}' (404)");
             throw new Kohanut_Exception("Could not find '{$page->url}'", array(), 404);
         }
         // Set the status to 200, rather than 404, which was set by the router with the reflectionexception
         Kohanut::status(200);
         $out = $page->render();
     } catch (Kohanut_Exception $e) {
         // Find the error page
         $error = Sprig::factory('kohanut_page', array('url' => 'error'))->load();
         // If i couldn't find the error page, just give a generic message
         if (!$error->loaded()) {
             Kohanut::status(404);
             $this->request->response = View::factory('kohanut/generic404');
             return;
         }
         // Set the response
         $out = $error->render();
     }
     if (isset($benchmark)) {
         // Stop the benchmark
         Profiler::stop($benchmark);
     }
     // Set the response
     $this->request->response = $out;
 }
Example #2
0
 public function action_override()
 {
     // Create the content
     $content = array(new View('override'), new View('override-column'));
     // Call Kohanut
     $this->request->response = Kohanut::override('Two Column', 'samples/override', $content);
     // You can manually set the title, and meta data here.
     Kohanut::$page->title = "Sample - Override";
     Kohanut::$page->metadesc = "Description";
 }
Example #3
0
 public function action_edit($id)
 {
     // Find the page
     $page = Jelly::select('kohanut_page', $id);
     if (!$page->loaded()) {
         return $this->admin_error(__('Could not find page with ID :id.', array(':id' => $id)));
     }
     // If this page is an external link, there is no content to edit, redirect to edit meta
     if ($page->islink) {
         $this->request->redirect(Route::get('kohanut-admin')->uri(array('controller' => 'pages', 'action' => 'meta', 'params' => $id)));
     }
     // If there is post, they are adding a new element
     if ($_POST) {
         $this->request->redirect(Route::get('kohanut-admin')->uri(array('controller' => 'elements', 'action' => 'add', 'params' => Arr::get($_POST, 'type', NULL) . '/' . $id . '/' . Arr::get($_POST, 'area', NULL))));
     }
     // Make it so the usual admin stuff is not shown
     $this->auto_render = FALSE;
     // Make it so the admin pane for pages is shown
     Kohanut::$adminmode = TRUE;
     Kohanut::style(Route::get('kohanut-media')->uri(array('file' => 'css/page.css')));
     // Render the page
     $this->request->response = $page->render();
 }
Example #4
0
 /**
  * Renders the page
  *
  * @returns a view file
  */
 public function render()
 {
     if (!$this->loaded()) {
         throw new Kohanut_Exception("Page render failed because page was not loaded.", array(), 404);
     }
     Kohanut::$page = $this;
     // Build the view
     return new View('kohanut/xhtml', array('layoutcode' => $this->layout->render()));
 }
Example #5
0
}
if (isset(Kohanut::$page->metakw) && Kohanut::$page->metakw != "") {
    ?>
	<meta name="keywords" content="<?php 
    echo Kohanut::$page->metakw;
    ?>
" />
<?php 
}
//	<meta name="generator" content="Kohanut" />
?>
<!-- Begin Kohanut includes -->
<?php 
echo Kohanut::style_render();
echo Kohanut::script_render();
echo Kohanut::meta_render();
?>
<!-- End Kohanut includes -->

</head>
<body<?php 
if (Kohanut::$adminmode) {
    echo " id='kohanut_admin'";
}
?>
>
<?php 
if (Kohanut::$adminmode) {
    ?>
<!-- Admin mode header -->
<div id="kohanut_header">