[Jaws-commits] r10817 - branches/0.8/html/gadgets/Blog

afz at jaws-project.com afz at jaws-project.com
Mon Nov 30 11:05:53 UTC 2009


Author: afz
Date: 2009-11-30 11:05:52 +0000 (Mon, 30 Nov 2009)
New Revision: 10817

Modified:
   branches/0.8/html/gadgets/Blog/LayoutHTML.php
Log:
cosmetics

Modified: branches/0.8/html/gadgets/Blog/LayoutHTML.php
===================================================================
--- branches/0.8/html/gadgets/Blog/LayoutHTML.php	2009-11-30 08:42:31 UTC (rev 10816)
+++ branches/0.8/html/gadgets/Blog/LayoutHTML.php	2009-11-30 11:05:52 UTC (rev 10817)
@@ -42,38 +42,58 @@
      * @param   int     Category ID
      * @return  string  Template content
      */
-    function EntriesByCategory($cat)
+    function EntriesByCategory($cat = null)
     {
         $model = $GLOBALS['app']->LoadGadget('Blog', 'Model');
-        $category = $model->GetCategory($cat);
-        $catname  = '';
-        if (Jaws_Error::isError($category)) {
-            $catname = _t('BLOG_RECENT_POSTS');
+        if (is_null($cat)) {
+            $title = _t('BLOG_RECENT_POSTS');
         } else {
-            $catname = _t('BLOG_RECENT_POSTS_BY_CATEGORY', $category['name']);
+            $category = $model->GetCategory($cat);
+            if (Jaws_Error::isError($category)) {
+                return false;
+            }
+            if (array_key_exists('name', $category)) {
+                $cat = $category['id'];
+                $title = _t('BLOG_RECENT_POSTS_BY_CATEGORY', $category['name']);
+            } else {
+                $cat = null;
+                $title = _t('BLOG_RECENT_POSTS_BY_CATEGORY');
+            }
         }
 
         $tpl = new Jaws_Template('gadgets/Blog/templates/');
         $tpl->Load('RecentPosts.html');
         $tpl->SetBlock('recent_posts');
-        $tpl->SetVariable('title', $catname);
+        $tpl->SetVariable('title', $title);
         $entries = $model->GetRecentEntries($cat);
         if (!Jaws_Error::IsError($entries)) {
             $date = $GLOBALS['app']->loadDate();
             foreach ($entries as $e) {
                 $tpl->SetBlock('recent_posts/item');
-                $id = empty($e['fast_url']) ? $e['id'] : $e['fast_url']; 
+                $id = empty($e['fast_url']) ? $e['id'] : $e['fast_url'];
+
+                $text = Jaws_Gadget::ParseText($e['text'], 'Blog');
+                if (strpos($text, '[more]') !== false) {
+                    $post = explode('[more]', $text);
+                    $perm_url = $GLOBALS['app']->Map->GetURLFor('Blog', 'SingleView', array('id' => $id));
+                    $text = $post[0]. ' '. _t('BLOG_READ_MORE', "$perm_url#more");
+                }
+
                 $tpl->SetVariable('url', $GLOBALS['app']->Map->GetURLFor('Blog', 'SingleView', array('id' => $id)));
                 $tpl->SetVariable('title', $e['title']);
+                $tpl->SetVariable('text', $text);
                 $tpl->SetVariable('username', $e['username']);
+                $tpl->SetVariable('posted_by', _t('BLOG_POSTED_BY'));
                 $tpl->SetVariable('name', $e['dname']);
+                $tpl->SetVariable('author-url', $GLOBALS['app']->Map->GetURLFor('Blog',
+                                                                                'ViewAuthorPage',
+                                                                                array('id' => $e['username'])));
                 $tpl->SetVariable('createtime', $date->Format($e['publishtime']));
                 $tpl->SetVariable('createtime-monthname', $date->Format($e['publishtime'], 'MN'));
                 $tpl->SetVariable('createtime-month', $date->Format($e['publishtime'], 'm'));
-                $tpl->SetVariable('createtime-day',   $date->Format($e['publishtime'], 'd'));
-                $tpl->SetVariable('createtime-year',  $date->Format($e['publishtime'], 'Y'));
-                $tpl->SetVariable('createtime-time',  $date->Format($e['publishtime'], 'g:ia'));
-                $tpl->SetVariable('entry-visits',     _t('BLOG_ENTRY_VISITS', $e['clicks']));
+                $tpl->SetVariable('createtime-day', $date->Format($e['publishtime'], 'd'));
+                $tpl->SetVariable('createtime-year', $date->Format($e['publishtime'], 'Y'));
+                $tpl->SetVariable('createtime-time', $date->Format($e['publishtime'], 'g:ia'));
                 $tpl->ParseBlock('recent_posts/item');
             }
         }
@@ -191,46 +211,7 @@
      */
     function RecentPosts()
     {
-        $tpl = new Jaws_Template('gadgets/Blog/templates/');
-        $tpl->Load('RecentPosts.html');
-        $tpl->SetBlock('recent_posts');
-        $tpl->SetVariable('title', _t('BLOG_RECENT_POSTS'));
-        $model = $GLOBALS['app']->LoadGadget('Blog', 'Model');
-        $entries = $model->GetRecentEntries();
-        if (!Jaws_Error::IsError($entries)) {
-            $date = $GLOBALS['app']->loadDate();
-            foreach ($entries as $e) {
-                $tpl->SetBlock('recent_posts/item');
-                $id = empty($e['fast_url']) ? $e['id'] : $e['fast_url'];
-
-                $text = Jaws_Gadget::ParseText($e['text'], 'Blog');
-                if (strpos($text, '[more]') !== false) {
-                    $post = explode('[more]', $text);
-                    $perm_url = $GLOBALS['app']->Map->GetURLFor('Blog', 'SingleView', array('id' => $id));
-                    $text = $post[0]. ' '. _t('BLOG_READ_MORE', "$perm_url#more");
-                }
-
-                $tpl->SetVariable('url', $GLOBALS['app']->Map->GetURLFor('Blog', 'SingleView', array('id' => $id)));
-                $tpl->SetVariable('title', $e['title']);
-                $tpl->SetVariable('text', $text);
-                $tpl->SetVariable('username', $e['username']);
-                $tpl->SetVariable('posted_by', _t('BLOG_POSTED_BY'));
-                $tpl->SetVariable('name', $e['dname']);
-                $tpl->SetVariable('author-url', $GLOBALS['app']->Map->GetURLFor('Blog',
-                                                                                'ViewAuthorPage',
-                                                                                array('id' => $e['username'])));
-                $tpl->SetVariable('createtime', $date->Format($e['publishtime']));
-                $tpl->SetVariable('createtime-monthname', $date->Format($e['publishtime'], 'MN'));
-                $tpl->SetVariable('createtime-month', $date->Format($e['publishtime'], 'm'));
-                $tpl->SetVariable('createtime-day', $date->Format($e['publishtime'], 'd'));
-                $tpl->SetVariable('createtime-year', $date->Format($e['publishtime'], 'Y'));
-                $tpl->SetVariable('createtime-time', $date->Format($e['publishtime'], 'g:ia'));
-                $tpl->ParseBlock('recent_posts/item');
-            }
-        }
-        $tpl->ParseBlock('recent_posts');
-
-        return $tpl->Get();
+        return $this->EntriesByCategory();
     }
 
     /**



More information about the Jaws-commits mailing list