Exemplo n.º 1
0
 public function action_edit($id)
 {
     // Sanitize
     $id = (int) $id;
     // Find the snippet
     $snippet = Kohanut_Element::factory('snippet')->values(array('id' => $id));
     $snippet->load();
     $this->view->title = "Editing Snippet";
     $this->view->body = new View('kohanut/snippets/edit', array('snippet' => $snippet, 'errors' => false, 'success' => false));
     if (!$snippet->loaded()) {
         return $this->admin_error("Could not find snippet with id <strong>{$id}</strong>.");
     }
     if ($_POST) {
         $snippet->values($_POST);
         // Make sure there are no twig syntax errors
         if ($snippet->twig) {
             try {
                 $test = Kohanut_Twig::render($_POST['code']);
             } catch (Twig_SyntaxError $e) {
                 $e->setFilename('code');
                 $this->view->body->errors[] = "There was a Twig Syntax error: " . $e->getMessage();
                 return;
             }
         }
         // Try saving the snippet
         try {
             $snippet->update();
             $this->view->body->success = "Updated Successfully";
         } catch (Validate_Exception $e) {
             $this->view->body->errors = $e->array->errors('snippet');
         }
     }
 }
Exemplo n.º 2
0
 protected function _render()
 {
     $out = $this->code;
     // Should we run it through markdown?
     if ($this->markdown) {
         $out = Markdown($out);
     }
     // Should we run it through twig?
     if ($this->twig) {
         $out = Kohanut_Twig::render($out);
     }
     return $out;
 }
Exemplo n.º 3
0
 public function render()
 {
     // Ensure the layout is loaded
     if (!$this->loaded()) {
         return "Layout Failed to render because it wasn't loaded.";
     }
     if (Kohana::$profiling === TRUE) {
         // Start a new benchmark
         $benchmark = Profiler::start('Kohanut', 'Render Layout');
     }
     $out = Kohanut_Twig::render($this->code);
     if (isset($benchmark)) {
         // Stop the benchmark
         Profiler::stop($benchmark);
     }
     return $out;
 }
Exemplo n.º 4
0
 /**
  * Render a twig template.
  * 
  * @param  string  The code to render
  * @return string
  */
 public static function render($code)
 {
     if (Kohana::$profiling === TRUE) {
         // Start a new benchmark
         $benchmark = Profiler::start('Kohanut', 'Twig Render');
     }
     if (self::$twig === null) {
         // Make the twig loader, environment and template and pass the layout code.
         $loader = new Twig_Loader_String();
         self::$twig = new Twig_Environment($loader, array('cache' => APPPATH . 'cache/twig'));
     }
     $template = self::$twig->loadTemplate($code);
     $out = $template->render(array('Kohanut' => new Kohanut()));
     if (isset($benchmark)) {
         // Stop the benchmark
         Profiler::stop($benchmark);
     }
     return $out;
 }
Exemplo n.º 5
0
 public function action_add($page, $area)
 {
     $view = View::factory('kohanut/elements/content/add', array('element' => $this, 'errors' => false, 'page' => $page, 'area' => $area));
     if ($_POST) {
         $this->set($_POST);
         if ($this->twig) {
             try {
                 $test = Kohanut_Twig::render($_POST['code']);
             } catch (Twig_SyntaxError $e) {
                 $e->setFilename('code');
                 $view->errors[] = "There was a Twig Syntax error: " . $e->getMessage();
                 return $view;
             }
         }
         try {
             $this->save();
             $this->create_block($page, $area);
             Request::instance()->redirect(Route::get('kohanut-admin')->uri(array('controller' => 'pages', 'action' => 'edit', 'params' => $page)));
         } catch (Validate_Exception $e) {
             $view->errors = $e->array->errors('page');
         }
     }
     return $view;
 }