From 2edc53510280e2473b3392d505e404f7168847bc Mon Sep 17 00:00:00 2001 From: Fredric N Date: Sat, 28 May 2011 18:33:37 +0200 Subject: [PATCH] fixed a bunch of stuff --- TODO | 2 +- application/Bootstrap.php | 4 +- application/languages/se.ini | 5 +- application/models/ModelBlogPost.php | 47 ++++++++------ application/models/ModelTag.php | 3 + .../modules/admin/views/layout/default.phtml | 2 + .../blog/controllers/ArchiveController.php | 15 +++-- .../blog/controllers/IndexController.php | 3 +- .../blog/views/scripts/archive/filter.phtml | 21 ++++-- .../blog/views/scripts/index/latest.phtml | 11 ++-- .../blog/views/scripts/index/read.phtml | 7 +- .../default/controllers/ProfileController.php | 41 ++++++------ .../default/views/layout/default.phtml | 10 +++ library/Fiktiv/Controller/Plugin/Language.php | 2 + library/Fiktiv/Highlighter.php | 3 +- public/index.php | 7 +- public/js/nicEdit/nicCode/icons/code.png | Bin 0 -> 389 bytes public/js/nicEdit/nicCode/nicCode.js | 61 ++++++++++++++++++ public/js/nicEdit/nicEdit.js | 2 +- 19 files changed, 180 insertions(+), 66 deletions(-) create mode 100644 public/js/nicEdit/nicCode/icons/code.png create mode 100644 public/js/nicEdit/nicCode/nicCode.js diff --git a/TODO b/TODO index f021570..061170f 100644 --- a/TODO +++ b/TODO @@ -3,4 +3,4 @@ - Blog - Administration UI - Implement form decorators -- Do not connect models and datapoints. If datapoints want to return a model object thats fine but the model is not a part of the data storage(!) \ No newline at end of file +- Use Zend db structure \ No newline at end of file diff --git a/application/Bootstrap.php b/application/Bootstrap.php index 44bdae6..327d6ee 100644 --- a/application/Bootstrap.php +++ b/application/Bootstrap.php @@ -208,6 +208,8 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap */ protected function _initAutoloader() { + $this->bootstrap('session'); + $autoloader = Zend_Loader_Autoloader::getInstance(); $autoloader->registerNamespace('Fiktiv_'); $autoloader->setFallbackAutoloader(true); @@ -297,4 +299,4 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH . '/../library/Fiktiv/Controller/Action/Helper', 'Fiktiv_Controller_Action_Helper'); } -} \ No newline at end of file +} diff --git a/application/languages/se.ini b/application/languages/se.ini index b2f4227..01582da 100644 --- a/application/languages/se.ini +++ b/application/languages/se.ini @@ -59,4 +59,7 @@ by = av cookies = kakor behind the site = om webbplatsen -February = februari \ No newline at end of file +filter archive by = filtrera arkivet på + +date = datum +tag = tagg \ No newline at end of file diff --git a/application/models/ModelBlogPost.php b/application/models/ModelBlogPost.php index 1e4b585..f143a42 100644 --- a/application/models/ModelBlogPost.php +++ b/application/models/ModelBlogPost.php @@ -27,42 +27,53 @@ class ModelBlogPost extends Fiktiv_Model_Abstract } } - + + /** + * Find all posts with tag. + * + * @param string $tag + * @return mixed + */ public function findByTag($tag) { - // Is this right? - $tags = new ModelTag(); - $row = $tags->fetchRow("name = 'Linux'"); - $posts = $row->findManyToManyRowset('ModelBlogPost', 'ModelPostTag'); + + $row = $tags->fetchRow($this->quoteInto('name = ?', $tag)); + + if ($row) { + $posts = $row->findManyToManyRowset('ModelBlogPost', 'ModelPostTag'); - return $posts; + return $posts; + } + + return null; } public function findByDate($date, $format) { - // This is a joke, FIXIT! - - $date = new Fiktiv_Date($date,$format); - - $where = $this->quoteInto('DATE_FORMAT(pubDate,"%Y %M") LIKE ?', $date->toString('Y MMMM')); + $date = new Fiktiv_Date($date, $format, Zend_Registry::get('Zend_Locale')); + + $where = $this->quoteInto('DATE_FORMAT(pubDate,"%Y %m") LIKE ?', $date->toString('yyyy MM')); return $this->fetchAll($where); } public function findByPermlink($permlink) { - return $this->fetchRow($this->quoteInto('permlink', $permlink)); + return $this->fetchRow($this->quoteInto('permlink = ?', $permlink)); } public function createPost($data, $id = null) { $myTags = explode(',', $data['tags']); unset($data['tags']); - $data['userId'] = Zend_Auth::getInstance()->getIdentity()->id; - $data['pubDate'] = Zend_Date::now()->getIso(); - $data['isPublished'] = 1; + if (null == $id) { + $data['userId'] = Zend_Auth::getInstance()->getIdentity()->id; + $data['pubDate'] = Zend_Date::now()->getIso(); + $data['isPublished'] = 1; + $data['permlink'] = $this->generatePermalink($data['title']); + } if ($id) { $row = $this->find($id)->current(); @@ -79,9 +90,9 @@ class ModelBlogPost extends Fiktiv_Model_Abstract } - protected function generatePermalink() + protected function generatePermalink($title) { - $permalink = $this->_data['title']; + $permalink = date('Y-m').'-'.$title; // All to lowercase $permalink = strtolower($permalink); @@ -105,6 +116,6 @@ class ModelBlogPost extends Fiktiv_Model_Abstract $permalink = str_replace($char,$value,$permalink); } - $this->_data['permalink'] = $permalink; + return $permalink; } } \ No newline at end of file diff --git a/application/models/ModelTag.php b/application/models/ModelTag.php index 0a1a709..8197f65 100644 --- a/application/models/ModelTag.php +++ b/application/models/ModelTag.php @@ -16,6 +16,9 @@ class ModelTag extends Fiktiv_Model_Abstract foreach ($tags as $key => $tag) { $tags[$key] = trim($tag); + if (empty($tags[$key])) + continue; + $tag = $this->fetchRow($this->quoteInto('name = ?', $tags[$key])); if (!$tag) { diff --git a/application/modules/admin/views/layout/default.phtml b/application/modules/admin/views/layout/default.phtml index 48c17c0..e49f3d2 100644 --- a/application/modules/admin/views/layout/default.phtml +++ b/application/modules/admin/views/layout/default.phtml @@ -7,7 +7,9 @@ + + headScript() ?> diff --git a/application/modules/blog/controllers/ArchiveController.php b/application/modules/blog/controllers/ArchiveController.php index ad2aa5f..2deb669 100644 --- a/application/modules/blog/controllers/ArchiveController.php +++ b/application/modules/blog/controllers/ArchiveController.php @@ -10,19 +10,20 @@ class Blog_ArchiveController extends Fiktiv_Controller_Action public function filterAction() { - - $params = $this->_getAllParams(); - $blogposts = new ModelBlogPost(); + $params = $this->_getAllParams(); + if (array_key_exists('date', $params)) { - - $this->view->posts = $blogposts->findByDate($params['date'], '%Y-%MM'); + $this->view->filterType = 'date'; + $this->view->filterValue = str_replace('-',' ',$params['date']); + $this->view->posts = $blogposts->findByDate($params['date'], 'yyyy-MMMM'); } else if (array_key_exists('tag', $params)) { - + $this->view->filterType = 'tag'; + $this->view->filterValue = $params['tag']; $this->view->posts = $blogposts->findByTag($params['tag']); - } + } } \ No newline at end of file diff --git a/application/modules/blog/controllers/IndexController.php b/application/modules/blog/controllers/IndexController.php index 016a211..135be51 100644 --- a/application/modules/blog/controllers/IndexController.php +++ b/application/modules/blog/controllers/IndexController.php @@ -22,8 +22,9 @@ class Blog_IndexController extends Fiktiv_Controller_Action public function readAction() { $posts = new ModelBlogPost(); - $this->view->post = $posts->findByPermlink($this->_getParam('id', null)); + $this->view->post = $posts->findByPermlink($this->_getParam('id', null)); + if (!$this->view->post) $this->_redirect(array('action' => 'latest')); diff --git a/application/modules/blog/views/scripts/archive/filter.phtml b/application/modules/blog/views/scripts/archive/filter.phtml index 540d4f9..1f1382b 100644 --- a/application/modules/blog/views/scripts/archive/filter.phtml +++ b/application/modules/blog/views/scripts/archive/filter.phtml @@ -1,12 +1,20 @@ « translate('u:back') ?> +

translate('u:filter archive by') . ' ' . $this->translate($this->filterType) ?> - filterValue ?>

+ + +setHighlighter('geshi'); +?> + posts as $post) : ?>

title ?>

getPubDate()->toString('yyyy-MM-dd').' '.$this->translate('TIME_AT').' '.$post->getPubDate()->toString('HH:mm').' '.$post->getAuthor()->firstName ?>

- content ?> + replaceCodeblock($post->content) ?>
hasTags()): ?> @@ -14,12 +22,13 @@
getTags()->count(); - for ($i = 0; $i < $count-1; $i++): ?> - getTags()->getRow($i)->name ?>, - getTags() as $tag) { + + echo ''.$tag->name.''; + + echo (--$count > 0) ? ', ' : ''; + } ?> - getTags()->getRow($i)->name ?>
diff --git a/application/modules/blog/views/scripts/index/latest.phtml b/application/modules/blog/views/scripts/index/latest.phtml index 1e99fb1..0b25887 100644 --- a/application/modules/blog/views/scripts/index/latest.phtml +++ b/application/modules/blog/views/scripts/index/latest.phtml @@ -21,12 +21,13 @@
getTags()->count(); - for ($i = 0; $i < $count-1; $i++): ?> - getTags()->getRow($i)->name ?>, - getTags() as $tag) { + + echo ''.$tag->name.''; + + echo (--$count > 0) ? ', ' : ''; + } ?> - getTags()->getRow($i)->name ?>
diff --git a/application/modules/blog/views/scripts/index/read.phtml b/application/modules/blog/views/scripts/index/read.phtml index 2b3e5d2..f0cc2c8 100644 --- a/application/modules/blog/views/scripts/index/read.phtml +++ b/application/modules/blog/views/scripts/index/read.phtml @@ -1,4 +1,7 @@ - +setHighlighter('geshi'); +?> post)): ?> @@ -7,7 +10,7 @@

post->title ?>

post->getPubDate()->toString('yyyy-MM-dd').' '.$this->translate('TIME_AT').' '.$this->post->getPubDate()->toString('HH:mm').' '.$this->translate('by').' '.$this->post->getAuthor()->firstName ?>

-
post->content ?>
+
replaceCodeblock($this->post->content) ?>
\ No newline at end of file diff --git a/application/modules/default/controllers/ProfileController.php b/application/modules/default/controllers/ProfileController.php index 4514bb6..2a7443e 100644 --- a/application/modules/default/controllers/ProfileController.php +++ b/application/modules/default/controllers/ProfileController.php @@ -28,9 +28,9 @@ class ProfileController extends Fiktiv_Controller_Action )); $options = array( - User::AVATAR_NONE => 'Ingen avatar', - User::AVATAR_FIKTIV => 'Egen avatar', - User::AVATAR_GRVTAR => 'Gravatar' + 1 => 'Ingen avatar', + 2 => 'Egen avatar', + 3 => 'Gravatar' ); $form->addElement('select', 'avatar', array( 'label' => 'u:avatar type', @@ -82,7 +82,8 @@ class ProfileController extends Fiktiv_Controller_Action $form->addDisplayGroup( array( 'password', - 'passwordConfirm' + 'passwordConfirm', + 'save' ), 'partThree', array( @@ -90,19 +91,16 @@ class ProfileController extends Fiktiv_Controller_Action ) ); - $form->addDisplayGroup( - array( - 'save' - ), - 'partThree' - ); - - $user = Zend_Auth::getInstance()->getIdentity(); + $auth = Zend_Auth::getInstance(); + $user = $auth->getIdentity(); if ($this->_request->isPost()) { + $users = new ModelUser(); + $userRow = $users->find($user->id)->current(); + $data = $this->_request->getPost(); if ($data['password'] !== $data['passwordConfirm'] || empty($data['password'])) { @@ -113,22 +111,27 @@ class ProfileController extends Fiktiv_Controller_Action } else { - if ($user->setPassword($data['password'])) - $this->view->messages = 'Lösenordet är ändrat!'; + //if ($users->setPassword($user->id, $data['password'])) + // $this->view->messages = 'Lösenordet är ändrat!'; unset($data['password']); } - + + unset($data['password']); unset($data['passwordConfirm']); unset($data['save']); - - $user->setAttribs($data); - $user->save(); + $userRow->setFromArray($data); + $userRow->save(); + // Update auth session + $user = (object) array_merge((array)$user, $userRow->toArray()); + unset($user->salt); + unset($user->password); + $auth->getStorage()->write($user); } - $form->populate($user->toArray()); + $form->populate((array)$user); } } \ No newline at end of file diff --git a/application/modules/default/views/layout/default.phtml b/application/modules/default/views/layout/default.phtml index b02893d..177ee54 100644 --- a/application/modules/default/views/layout/default.phtml +++ b/application/modules/default/views/layout/default.phtml @@ -38,6 +38,16 @@ + getDevice()->getBrowser(); + echo ' '; + echo implode('.', array_slice(explode('.', $obj->getDevice()->getBrowserVersion()), 0, 2)); + + + ?> +
translate('u:cookies')?> - translate('uw:about')?>
diff --git a/library/Fiktiv/Controller/Plugin/Language.php b/library/Fiktiv/Controller/Plugin/Language.php index 60f0cd2..41a9a34 100644 --- a/library/Fiktiv/Controller/Plugin/Language.php +++ b/library/Fiktiv/Controller/Plugin/Language.php @@ -39,6 +39,8 @@ class Fiktiv_Controller_Plugin_Language extends Zend_Controller_Plugin_Abstract 'en' => 'en_US' ); + Zend_Registry::set('Zend_Locale', new Zend_Locale($lookup[$lang])); + $database = $bootstrap->getResource('database'); $database->query("SET lc_time_names = ?;", $lookup[$lang]); } diff --git a/library/Fiktiv/Highlighter.php b/library/Fiktiv/Highlighter.php index dd16187..77f3643 100644 --- a/library/Fiktiv/Highlighter.php +++ b/library/Fiktiv/Highlighter.php @@ -37,11 +37,10 @@ class Fiktiv_Highlighter { foreach ($code[1] as $key => $lang) { $c = str_replace('
', "\n",html_entity_decode($code[2][$key], ENT_COMPAT,'UTF-8')); - $block = str_replace($code[2][$key], html_entity_decode($this->highlight($c, $lang), ENT_COMPAT, 'UTF-8'), $block); + $block = str_replace($code[2][$key], $this->highlight($c, $lang), $block); } } - return $block; } diff --git a/public/index.php b/public/index.php index b3a6a9f..5ef8b63 100644 --- a/public/index.php +++ b/public/index.php @@ -3,8 +3,11 @@ defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application')); +defined('APPLICATION_EXTERNAL') || + define('APPLICATION_EXTERNAL', realpath(dirname(__FILE__) . '/../external')); + defined('APPLICATION_ENV') || - define('APPLICATION_ENV',(getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production')); + define('APPLICATION_ENV',(getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'development')); set_include_path(implode(PATH_SEPARATOR, array( APPLICATION_PATH . '/../library', @@ -21,4 +24,4 @@ $application = new Zend_Application( ); $application->bootstrap() - ->run(); \ No newline at end of file + ->run(); diff --git a/public/js/nicEdit/nicCode/icons/code.png b/public/js/nicEdit/nicCode/icons/code.png new file mode 100644 index 0000000000000000000000000000000000000000..e093032a77d0b90d3a5dc05759dd6bcc2ad51715 GIT binary patch literal 389 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4mJh`2Kmqb6B!s7SkfJR9T^zbpD<_bdda}R zAX(xXQ4*Y=R#Ki=l*-_klAn~S;F+74o*I;zm{M7IGS!BGfl=Jk#WBRarVN+_aq#bL7(V`;A3{8f-7j?xb?Z|NE2tw9nju^?cpxXEDZZ<*U+u>LyQ!dAV%* zf97<%e=8=GwDKNheRb4a+3C6c-+5bK9j))*$Nv4vV?9shlb+T7wI%#2;wGOjmM@55 zxn>aHvr{SMcER(ASC5wekBxqJ=

'); + + // calling the function + insertAtCursor(document.getElementById('content'), 'test'); + + } +}); + +nicEditors.registerPlugin(nicPlugin,nicExampleOptions); \ No newline at end of file diff --git a/public/js/nicEdit/nicEdit.js b/public/js/nicEdit/nicEdit.js index 79f0aa2..02bb990 100644 --- a/public/js/nicEdit/nicEdit.js +++ b/public/js/nicEdit/nicEdit.js @@ -110,4 +110,4 @@ var nicCodeOptions = { }; -var nicCodeButton=nicEditorAdvancedButton.extend({width:"350px",addPane:function(){this.addForm({"":{type:"title",txt:"Edit HTML"},code:{type:"content",value:this.ne.selectedInstance.getContent(),style:{width:"340px",height:"200px"}}})},submit:function(B){var A=this.inputs.code.value;this.ne.selectedInstance.setContent(A);this.removePane()}});nicEditors.registerPlugin(nicPlugin,nicCodeOptions); +var nicCodeButton=nicEditorAdvancedButton.extend({width:"600px",addPane:function(){this.addForm({"":{type:"title",txt:"Edit HTML"},code:{type:"content",value:this.ne.selectedInstance.getContent(),style:{width:"590px",height:"300px"}}})},submit:function(B){var A=this.inputs.code.value;this.ne.selectedInstance.setContent(A);this.removePane()}});nicEditors.registerPlugin(nicPlugin,nicCodeOptions);