From 469ea99678d30447648f9f34352d3ac2449bb717 Mon Sep 17 00:00:00 2001 From: Fredric N Date: Sat, 30 Oct 2010 13:49:59 +0200 Subject: [PATCH] Model work and som library changes --- application/Bootstrap.php | 4 ++-- application/models/BlogPost.php | 22 ++++++++++++++++--- application/models/Mapper/BlogPost.php | 4 ++++ library/Fiktiv/Controller/Action.php | 11 ++++++++++ .../Controller/Action/Helper/Translate.php | 15 ------------- library/Fiktiv/Controller/Plugin/Layout.php | 7 +++--- library/Fiktiv/View/Helper/Translate.php | 4 ++-- public/.htaccess | 5 ++++- 8 files changed, 45 insertions(+), 27 deletions(-) delete mode 100644 library/Fiktiv/Controller/Action/Helper/Translate.php diff --git a/application/Bootstrap.php b/application/Bootstrap.php index fef5e41..e76b554 100644 --- a/application/Bootstrap.php +++ b/application/Bootstrap.php @@ -30,7 +30,7 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap // Set userrole for navigation $auth = Zend_Auth::getInstance(); - //var_dump($auth->getIdentity()->userRole); + if ($auth->hasIdentity()) { $view->navigation()->setRole($auth->getIdentity()->userRole); } else { @@ -117,7 +117,7 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap $this->bootstrap('front'); $router = $this->getResource('front')->getRouter(); - + // Set global lang param $router->setGlobalParam('lang', 'sv'); diff --git a/application/models/BlogPost.php b/application/models/BlogPost.php index 0aed522..ade1a60 100644 --- a/application/models/BlogPost.php +++ b/application/models/BlogPost.php @@ -50,9 +50,10 @@ class BlogPost extends Fiktiv_Model_Abstract public function setTitle($title) { - if (is_string($title) && null == $title[30]) { + if (is_string($title) && !isset($title[30])) { $this->_data['title'] = $title; + $this->generatePermalink(); return true; } @@ -131,6 +132,16 @@ class BlogPost extends Fiktiv_Model_Abstract $this->_data['isPublished'] = (boolean)$flag; } + public function setPermalink($permalink) + { + if (is_string($permalink)) { + $this->_data['permalink'] = $permalink; + return true; + } + + return false; + } + protected function generatePermalink() { $permalink = $this->_data['title']; @@ -139,14 +150,19 @@ class BlogPost extends Fiktiv_Model_Abstract $permalink = strtolower($permalink); // Remove special characters - //$permalink = filter_var($permalink, FILTER_SANITIZE_SPECIAL_CHARS); - + $permalink = filter_var($permalink, FILTER_SANITIZE_SPECIAL_CHARS); + // Replace stuff $replace = array( ' ' => '-', 'å' => 'a', 'ä' => 'a', 'ö' => 'o', + '_' => '-', + '!' => '', + '?' => '', + '.' => '', + ',' => '', ); foreach($replace as $char => $value) { $permalink = str_replace($char,$value,$permalink); diff --git a/application/models/Mapper/BlogPost.php b/application/models/Mapper/BlogPost.php index 2da8c69..1b01c84 100644 --- a/application/models/Mapper/BlogPost.php +++ b/application/models/Mapper/BlogPost.php @@ -103,8 +103,12 @@ class Mapper_BlogPost extends Fiktiv_Model_Mapper_DbTableAbstract public function save(BlogPost $post) { $data = $post->toArray(); + unset($data['id']); + $tags = $data['tags']; + unset($data['tags']); + return $this->_dbTable->update( $data, $this->quoteInto('id = ?',$post->getId()) diff --git a/library/Fiktiv/Controller/Action.php b/library/Fiktiv/Controller/Action.php index 0b016a3..a3759a0 100644 --- a/library/Fiktiv/Controller/Action.php +++ b/library/Fiktiv/Controller/Action.php @@ -16,4 +16,15 @@ class Fiktiv_Controller_Action extends Zend_Controller_Action return call_user_func(array($this->_helper, $name)); } } + + /** + * Direct access to translate with out going + * through view. + * @return string + */ + public function translate() + { + $args = func_get_args(); + return call_user_func_array(array($this->view, 'translate'), $args); + } } \ No newline at end of file diff --git a/library/Fiktiv/Controller/Action/Helper/Translate.php b/library/Fiktiv/Controller/Action/Helper/Translate.php deleted file mode 100644 index afdc4c8..0000000 --- a/library/Fiktiv/Controller/Action/Helper/Translate.php +++ /dev/null @@ -1,15 +0,0 @@ -view, 'translate'), $args); - } - - public function direct() - { - return $this->translate(); - } -} \ No newline at end of file diff --git a/library/Fiktiv/Controller/Plugin/Layout.php b/library/Fiktiv/Controller/Plugin/Layout.php index e999aee..405a26e 100644 --- a/library/Fiktiv/Controller/Plugin/Layout.php +++ b/library/Fiktiv/Controller/Plugin/Layout.php @@ -11,10 +11,9 @@ class Fiktiv_Controller_Plugin_Layout extends Zend_Controller_Plugin_Abstract public function preDispatch(Zend_Controller_Request_Abstract $request) { - $bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap'); - $layout = $bootstrap->getResource('layout'); - - $moduleName = $request->getModuleName(); + $layout = Zend_Layout::getMvcInstance(); + + $moduleName = strtolower($request->getModuleName()); if (file_exists(APPLICATION_PATH . '/modules/' . $moduleName . '/views/layout/' . $this->_default . '.phtml')) { diff --git a/library/Fiktiv/View/Helper/Translate.php b/library/Fiktiv/View/Helper/Translate.php index 2bd42a1..8646eeb 100644 --- a/library/Fiktiv/View/Helper/Translate.php +++ b/library/Fiktiv/View/Helper/Translate.php @@ -17,8 +17,8 @@ class Fiktiv_View_Helper_Translate extends Zend_View_Helper_Translate { $options = func_get_args(); $key = array_shift($options); - - if ($options[count($options)-1] === true) { + + if (isset($options[0]) && $options[count($options)-1] === true) { foreach ($options as &$opt) { $opt = parent::translate($opt); } diff --git a/public/.htaccess b/public/.htaccess index 1da30f9..e92ede7 100755 --- a/public/.htaccess +++ b/public/.htaccess @@ -5,4 +5,7 @@ RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] -RewriteRule ^.*$ index.php [NC,L] \ No newline at end of file +RewriteRule ^.*$ index.php [NC,L] + + +php_flag short_open_tag on \ No newline at end of file