[Jaws-commits] r12451 - in trunk/jaws/html/gadgets/StaticPage: . hooks

afz at jaws-project.com afz at jaws-project.com
Thu Jan 19 11:34:45 UTC 2012


Author: afz
Date: 2012-01-19 11:34:45 +0000 (Thu, 19 Jan 2012)
New Revision: 12451

Modified:
   trunk/jaws/html/gadgets/StaticPage/Actions.php
   trunk/jaws/html/gadgets/StaticPage/AdminHTML.php
   trunk/jaws/html/gadgets/StaticPage/HTML.php
   trunk/jaws/html/gadgets/StaticPage/LayoutHTML.php
   trunk/jaws/html/gadgets/StaticPage/Map.php
   trunk/jaws/html/gadgets/StaticPage/Model.php
   trunk/jaws/html/gadgets/StaticPage/hooks/Search.php
   trunk/jaws/html/gadgets/StaticPage/hooks/URLList.php
Log:
Updated StaticPage maps

Modified: trunk/jaws/html/gadgets/StaticPage/Actions.php
===================================================================
--- trunk/jaws/html/gadgets/StaticPage/Actions.php	2012-01-19 11:33:48 UTC (rev 12450)
+++ trunk/jaws/html/gadgets/StaticPage/Actions.php	2012-01-19 11:34:45 UTC (rev 12451)
@@ -5,13 +5,14 @@
  * @category   GadgetActions
  * @package    StaticPage
  * @author     Pablo Fischer <pablo at pablo.com.mx>
+ * @author     Ali Fazelzadeh <afz at php.net>
  * @copyright  2004-2012 Jaws Development Group
  * @license    http://www.gnu.org/copyleft/gpl.html
  */
 $actions = array();
 
 $actions['Page']       = array('NormalAction');
-$actions['PagesList']  = array('NormalAction');
+$actions['Pages']      = array('NormalAction');
 $actions['GroupPages'] = array('NormalAction');
 $actions['PagesTree']  = array('NormalAction');
 

Modified: trunk/jaws/html/gadgets/StaticPage/AdminHTML.php
===================================================================
--- trunk/jaws/html/gadgets/StaticPage/AdminHTML.php	2012-01-19 11:33:48 UTC (rev 12450)
+++ trunk/jaws/html/gadgets/StaticPage/AdminHTML.php	2012-01-19 11:34:45 UTC (rev 12451)
@@ -4,8 +4,9 @@
  *
  * @category   GadgetAdmin
  * @package    StaticPage
- * @author     Jon Wood      <jon at jellybob.co.uk>
+ * @author     Jon Wood <jon at jellybob.co.uk>
  * @author     Pablo Fischer <pablo at pablo.com.mx>
+ * @author     Ali Fazelzadeh <afz at php.net>
  * @copyright  2004-2012 Jaws Development Group
  * @license    http://www.gnu.org/copyleft/gpl.html
  */
@@ -178,13 +179,12 @@
         $add_turl  = BASE_SCRIPT . '?gadget=StaticPage&action=AddNewTranslation&page=';
         $edit_turl = BASE_SCRIPT . '?gadget=StaticPage&action=EditTranslation&id=';
         $date = $GLOBALS['app']->loadDate();
-        $xss  = $GLOBALS['app']->loadClass('XSS', 'Jaws_XSS');
 
         foreach ($pages as $page) {
             $pageData = array();
             $pageData['title'] = '<a href="'.$edit_url.$page['page_id'].'">'.$page['title'].'</a>';
 
-            $param = array('id' => !empty($page['fast_url']) ? $xss->filter($page['fast_url']) : $page['page_id']);
+            $param = array('pid' => !empty($page['fast_url']) ? $page['fast_url'] : $page['page_id']);
             $furl = $GLOBALS['app']->Map->GetURLFor('StaticPage', 'Page', $param);
             $pageData['furl']  = '<a href="'.$furl.'">'.$page['fast_url'].'</a>';
             $pageData['group'] = $page['gtitle'];

Modified: trunk/jaws/html/gadgets/StaticPage/HTML.php
===================================================================
--- trunk/jaws/html/gadgets/StaticPage/HTML.php	2012-01-19 11:33:48 UTC (rev 12450)
+++ trunk/jaws/html/gadgets/StaticPage/HTML.php	2012-01-19 11:34:45 UTC (rev 12451)
@@ -39,16 +39,24 @@
      * @access public
      * @return string
      */
-    function Page($page_id = null)
+    function Page($page_id = null, $base_action = 'Page')
     {
+        $xss = $GLOBALS['app']->loadClass('XSS', 'Jaws_XSS');
         $request =& Jaws_Request::getInstance();
-        $post = $request->get(array('id','language'), 'get');
+        $post = $request->get(array('gid', 'pid','language'), 'get');
+        $post['gid'] = $xss->defilter($post['gid'], true);
+        $post['pid'] = $xss->defilter($post['pid'], true);
 
-        $xss  = $GLOBALS['app']->loadClass('XSS', 'Jaws_XSS');
-        $post['id'] = $xss->defilter($post['id'], true);
+        $model = $GLOBALS['app']->LoadGadget('StaticPage', 'Model');
+        if ($base_action == 'Pages') {
+            $group = $model->GetGroup($post['gid']);
+            if (Jaws_Error::IsError($group) || empty($group)) {
+                require_once JAWS_PATH . 'include/Jaws/HTTPError.php';
+                return Jaws_HTTPError::Get(404);
+            }
+        }
 
-        $model = $GLOBALS['app']->LoadGadget('StaticPage', 'Model');
-        $page_id = is_null($page_id)? $post['id'] : $page_id;
+        $page_id = is_null($page_id)? $post['pid'] : $page_id;
         $page_language = $post['language'];
         if (empty($page_language)) {
             // if page language not set try to load language traslation of page that same as site language
@@ -58,12 +66,7 @@
             }
         }
 
-        if (empty($page_language)) {
-            $page = $model->GetPage($page_id);
-        } else {
-            $page = $model->GetPage($page_id, $page_language);
-        }
-
+        $page = $model->GetPage($page_id,  $page_language);
         if (Jaws_Error::IsError($page)) {
             require_once JAWS_PATH . 'include/Jaws/HTTPError.php';
             return Jaws_HTTPError::Get(404);
@@ -100,9 +103,16 @@
                             //if ($page['language'] == $trans['language']) continue;
                             $tpl->SetBlock('page/translations/language');
                             $tpl->SetVariable('lang', $trans['language']);
-                            $param = array('id' => !empty($page['fast_url']) ? $page['fast_url'] : $page['page_id'],
-                                           'language' => $trans['language']);
-                            $tpl->SetVariable('url', $this->GetURLFor('Page', $param));
+                            if ($base_action = 'Pages') {
+                                $param = array('gid' => !empty($group['fast_url'])? $group['fast_url'] : $group['id'],
+                                               'pid' => !empty($page['fast_url'])? $page['fast_url'] : $page['page_id'],
+                                               'language' => $trans['language']);
+                                $tpl->SetVariable('url', $this->GetURLFor('Pages', $param));
+                            } else {
+                                $param = array('pid' => !empty($page['fast_url']) ? $page['fast_url'] : $page['page_id'],
+                                               'language' => $trans['language']);
+                                $tpl->SetVariable('url', $this->GetURLFor('Page', $param));
+                            }
                             $tpl->ParseBlock('page/translations/language');
                         }
                         $tpl->ParseBlock('page/translations');
@@ -116,18 +126,6 @@
     }
 
     /**
-     * Displays an index of available static pages.
-     *
-     * @access public
-     * @return string
-     */
-    function PagesList()
-    {
-        $layoutGadget = $GLOBALS['app']->LoadGadget('StaticPage', 'LayoutHTML');
-        return $layoutGadget->PagesList();
-    }
-
-    /**
      * Displays an index of available groups.
      *
      * @access public
@@ -154,10 +152,28 @@
         $gid = $xss->defilter($gid, true);
 
         $layoutGadget = $GLOBALS['app']->LoadGadget('StaticPage', 'LayoutHTML');
-        return $layoutGadget->GroupPages($gid);
+        $result = $layoutGadget->GroupPages($gid);
+        if (!$result) {
+            require_once JAWS_PATH . 'include/Jaws/HTTPError.php';
+            $result = Jaws_HTTPError::Get(404);
+        }
+
+        return $result;
     }
 
     /**
+     * Displays an individual page.
+     *
+     * @var	int	$id	Page ID (optional)
+     * @access public
+     * @return string
+     */
+    function Pages()
+    {
+        return $this->Page(null, 'Pages');
+    }
+
+    /**
      * Displays groups and pages as tree
      *
      * @access  public
@@ -188,9 +204,10 @@
                 foreach ($pages as $page) {
                     if ($page['published']) {
                         $tpl->SetBlock('pages_tree/g_item/p_item');
-                        $param = array('id' => empty($page['fast_url']) ? $page['base_id'] : $page['fast_url'],
+                        $param = array('gid' => empty($group['fast_url'])? $group['id'] : $group['fast_url'],
+                                       'pid' => empty($page['fast_url'])? $page['base_id'] : $page['fast_url'],
                                        'language' => $page['language']);
-                        $plink = $GLOBALS['app']->Map->GetURLFor('StaticPage', 'Page', $param);
+                        $plink = $GLOBALS['app']->Map->GetURLFor('StaticPage', 'Pages', $param);
                         $tpl->SetVariable('page', $page['title']);
                         $tpl->SetVariable('plink',  $plink);
                         $tpl->ParseBlock('pages_tree/g_item/p_item');

Modified: trunk/jaws/html/gadgets/StaticPage/LayoutHTML.php
===================================================================
--- trunk/jaws/html/gadgets/StaticPage/LayoutHTML.php	2012-01-19 11:33:48 UTC (rev 12450)
+++ trunk/jaws/html/gadgets/StaticPage/LayoutHTML.php	2012-01-19 11:34:45 UTC (rev 12451)
@@ -55,7 +55,7 @@
         $tpl->SetVariable('title', _t('STATICPAGE_PAGES_LIST'));
         foreach ($pages as $page) {
             if ($page['published'] === true) {
-                $param = array('id' => empty($page['fast_url']) ? $page['base_id'] : $page['fast_url'],
+                $param = array('pid' => empty($page['fast_url']) ? $page['base_id'] : $page['fast_url'],
                                'language' => $page['language']);
                 $link = $GLOBALS['app']->Map->GetURLFor('StaticPage', 'Page', $param);
                 $tpl->SetBlock('index/item');
@@ -111,7 +111,7 @@
     {
         $model = $GLOBALS['app']->LoadGadget('StaticPage', 'Model');
         $group = $model->GetGroup($gid);
-        if (Jaws_Error::IsError($group) or $group == null) {
+        if (Jaws_Error::IsError($group) || $group == null) {
             return false;
         }
 
@@ -130,9 +130,10 @@
         $tpl->SetVariable('title', $group['title']);
         foreach ($pages as $page) {
             if ($page['published']) {
-                $param = array('id' => empty($page['fast_url']) ? $page['base_id'] : $page['fast_url'],
+                $param = array('gid' => empty($group['fast_url'])? $group['id'] : $group['fast_url'],
+                               'pid' => empty($page['fast_url']) ? $page['base_id'] : $page['fast_url'],
                                'language' => $page['language']);
-                $link = $GLOBALS['app']->Map->GetURLFor('StaticPage', 'Page', $param);
+                $link = $GLOBALS['app']->Map->GetURLFor('StaticPage', 'Pages', $param);
                 $tpl->SetBlock('group_pages/item');
                 $tpl->SetVariable('page', $page['title']);
                 $tpl->SetVariable('link',  $link);

Modified: trunk/jaws/html/gadgets/StaticPage/Map.php
===================================================================
--- trunk/jaws/html/gadgets/StaticPage/Map.php	2012-01-19 11:33:48 UTC (rev 12450)
+++ trunk/jaws/html/gadgets/StaticPage/Map.php	2012-01-19 11:34:45 UTC (rev 12451)
@@ -10,22 +10,35 @@
  * @license    http://www.gnu.org/copyleft/gpl.html
  */
 $maps[] = array('DefaultAction', 'page/default');
-$maps[] = array('PagesList',  'page/index');
-$maps[] = array('PagesList',  'page/pages');
-$maps[] = array('GroupsList', 'page/groups');
-$maps[] = array('GroupPages',
-                'page/group/{gid}',
+$maps[] = array('PagesTree', 'page/index');
+$maps[] = array('Page', 
+                'page/{pid}/{language}',
                 '',
-                array('gid' => '[[:alnum:][:space:][:punct:]]+$')
+                array('pid'      => '[[:alnum:][:space:][:punct:]]+',
+                      'language' => '[[:lower:]-]+$',)
                 );
 $maps[] = array('Page', 
-                'page/{id}/{language}',
+                'page/{pid}',
                 '',
-                array('id'       =>  '[[:alnum:][:space:][:punct:]]+',
-                      'language' =>  '[[:lower:]-]+$',)
+                array('pid' => '[[:alnum:][:space:][:punct:]]+$',)
                 );
-$maps[] = array('Page', 
-                'page/{id}',
+// new maps
+$maps[] = array('Pages', 
+                'pages/{gid}/{pid}/{language}',
                 '',
-                array('id' =>  '[[:alnum:][:space:][:punct:]]+$',)
+                array('gid'      => '[[:alnum:][:space:][:punct:]]+',
+                      'pid'      => '[[:alnum:][:space:][:punct:]]+',
+                      'language' => '[[:lower:]-]+$',)
                 );
+$maps[] = array('Pages', 
+                'pages/{gid}/{pid}',
+                '',
+                array('gid' => '[[:alnum:][:space:][:punct:]]+',
+                      'pid' => '[[:alnum:][:space:][:punct:]]+$',)
+                );
+$maps[] = array('GroupPages',
+                'pages/{gid}',
+                '',
+                array('gid' => '[[:alnum:][:space:][:punct:]]+$',)
+                );
+$maps[] = array('GroupsList', 'pages');

Modified: trunk/jaws/html/gadgets/StaticPage/Model.php
===================================================================
--- trunk/jaws/html/gadgets/StaticPage/Model.php	2012-01-19 11:33:48 UTC (rev 12450)
+++ trunk/jaws/html/gadgets/StaticPage/Model.php	2012-01-19 11:34:45 UTC (rev 12451)
@@ -19,7 +19,7 @@
      * @param   int     $id     The ID or fast_url of the page to get.
      * @return  array   An array containing the page information, or false if no page could be loaded.
      */
-    function GetPage($id, $language = null)
+    function GetPage($id, $language = '')
     {
         $sql = '
             SELECT
@@ -301,7 +301,8 @@
 
         $sql = '
             SELECT [id], [title], [fast_url], [visible]
-            FROM [[static_pages_groups]] WHERE ';
+            FROM [[static_pages_groups]]
+            WHERE ';
 
         if (is_numeric($id)) {
             $sql .= '[id] = {id}';

Modified: trunk/jaws/html/gadgets/StaticPage/hooks/Search.php
===================================================================
--- trunk/jaws/html/gadgets/StaticPage/hooks/Search.php	2012-01-19 11:33:48 UTC (rev 12450)
+++ trunk/jaws/html/gadgets/StaticPage/hooks/Search.php	2012-01-19 11:34:45 UTC (rev 12451)
@@ -71,4 +71,5 @@
 
         return $pages;
     }
-}
+
+}
\ No newline at end of file

Modified: trunk/jaws/html/gadgets/StaticPage/hooks/URLList.php
===================================================================
--- trunk/jaws/html/gadgets/StaticPage/hooks/URLList.php	2012-01-19 11:33:48 UTC (rev 12450)
+++ trunk/jaws/html/gadgets/StaticPage/hooks/URLList.php	2012-01-19 11:34:45 UTC (rev 12451)
@@ -21,10 +21,10 @@
         $urls   = array();
         $urls[] = array('url'   => $GLOBALS['app']->Map->GetURLFor('StaticPage', 'DefaultAction'),
                         'title' => _t('STATICPAGE_NAME'));
-        $urls[] = array('url'   => $GLOBALS['app']->Map->GetURLFor('StaticPage', 'PagesList'),
-                        'title' => _t('STATICPAGE_PAGES_LIST'));
         $urls[] = array('url'   => $GLOBALS['app']->Map->GetURLFor('StaticPage', 'GroupsList'),
                         'title' => _t('STATICPAGE_GROUPS_LIST'));
+        $urls[] = array('url'   => $GLOBALS['app']->Map->GetURLFor('StaticPage', 'PagesTree'),
+                        'title' => _t('STATICPAGE_PAGES_TREE'));
 
         //Load model
         $max_size = 32;
@@ -39,21 +39,23 @@
             $urls[] = array('url'    => $url,
                             'title'  => '\\'. $group['title'],
                             'title2' => ($GLOBALS['app']->UTF8->strlen($group['title']) >= $max_size)?
-                                        $GLOBALS['app']->UTF8->substr($group['title'], 0, $max_size).'...' :
-                                        $group['title']);
+                                         $GLOBALS['app']->UTF8->substr($group['title'], 0, $max_size).'...' :
+                                         $group['title']);
             $pages = $model->GetPages($group['id']);
             foreach($pages as $page) {
                 if ($page['published'] === true) {
                     $url   = $GLOBALS['app']->Map->GetURLFor(
                                                     'StaticPage',
-                                                    'Page',
-                                                    array('id' => empty($page['fast_url'])?
-                                                                        $page['base_id'] : $page['fast_url']));
+                                                    'Pages',
+                                                    array('gid' => empty($group['fast_url'])?
+                                                                         $group['id'] : $group['fast_url'],
+                                                          'pid' => empty($page['fast_url'])?
+                                                                         $page['base_id'] : $page['fast_url']));
                     $urls[] = array('url'    => $url,
                                     'title'  => '\\'. $group['title'].'\\'. $page['title'],
                                     'title2' => ($GLOBALS['app']->UTF8->strlen($page['title']) >= $max_size)?
-                                                $GLOBALS['app']->UTF8->substr($page['title'], 0, $max_size).'...' :
-                                                $page['title']);
+                                                 $GLOBALS['app']->UTF8->substr($page['title'], 0, $max_size).'...' :
+                                                 $page['title']);
                 }
             }
         }



More information about the Jaws-commits mailing list