New main page of the site with a multi-topic site preview based on PlWizard
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 21 Sep 2007 22:03:34 +0000 (00:03 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 21 Sep 2007 22:03:34 +0000 (00:03 +0200)
with configuration and sources taken from specific wiki pages.
This still need CSS customization, but I won't do this, so, either somebody
takes this task, or this will remain ugly.

Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
14 files changed:
ChangeLog
classes/plwizard.php
modules/platal.php
modules/platal/review.inc.php [new file with mode: 0644]
modules/profile.php
modules/profile/decos.inc.php
modules/profile/general.inc.php
modules/profile/groups.inc.php
modules/profile/jobs.inc.php
modules/profile/mentor.inc.php
modules/profile/page.inc.php
modules/profile/skills.inc.php
templates/core/plwizard.tpl
templates/platal/review.tpl [new file with mode: 0644]

index d41f469..fdc829b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,9 @@ New:
     * Lists:
         - Asynchronous mail moderation (should avoid server overload)      -FRU
 
+    * Platal:
+        - New default page with a flexible multi-topic presentation        -FRU
+
     * Profile:
         - #28: Use group/subscription list from Xnet                       -FRU
 
index b5affd1..78242f2 100644 (file)
@@ -37,7 +37,7 @@ interface PlWizardPage
 
     /** Prepare the page by assigning to it any useful value.
      */
-    public function prepare(PlatalPage &$page);
+    public function prepare(PlatalPage &$page, $id);
 
     /** Process information resulting of the application of the page.
      * This function must return a clue indicating the next page to show.
@@ -67,13 +67,14 @@ class PlWizard
     protected $name;
     protected $layout;
     protected $stateless;
+    protected $ajax;
 
     protected $pages;
     protected $titles;
     protected $lookup;
     protected $inv_lookup;
 
-    public function __construct($name, $layout, $stateless = false)
+    public function __construct($name, $layout, $stateless = false, $ajax = true)
     {
         $this->name      = 'wiz_' . $name;
         $this->layout    = $layout;
@@ -81,6 +82,7 @@ class PlWizard
         $this->pages  = array();
         $this->lookup = array();
         $this->titles = array();
+        $this->ajax   = $ajax;
         if (!isset($_SESSION[$this->name])) {
             $_SESSION[$this->name] = array();
             $_SESSION[$this->name . '_page']  = null;
@@ -136,7 +138,7 @@ class PlWizard
         return new $page($this);
     }
 
-    public function apply(PlatalPage &$smarty, $baseurl, $pgid = null)
+    public function apply(PlatalPage &$smarty, $baseurl, $pgid = null, $mode = 'normal')
     {
         if ($this->stateless && (isset($this->lookup[$pgid]) || isset($this->pages[$pgid]))) { 
             $curpage = is_numeric($pgid) ? $pgid : $this->lookup[$pgid]; 
@@ -194,16 +196,22 @@ class PlWizard
         } else if (!isset($page)) {
             $page = $this->getPage($curpage);
         }
-        $smarty->changeTpl($this->layout);
+        if ($mode == 'ajax') {
+            header('Content-Type: text/html; charset=utf-8');
+            $smarty->changeTpl($page->template(), NO_SKIN);
+        } else {
+            $smarty->changeTpl($this->layout);
+        }
         $smarty->assign('pages', $this->titles);
         $smarty->assign('current', $curpage);
         $smarty->assign('lookup', $this->inv_lookup);
         $smarty->assign('stateless', $this->stateless);
         $smarty->assign('wiz_baseurl', $baseurl);
+        $smarty->assign('wiz_ajax', $this->ajax);
         $smarty->assign('tab_width', (int)(99 / count($this->pages)));
         $smarty->assign('wiz_page', $page->template());
         $smarty->assign('xorg_no_errors', true);
-        $page->prepare($smarty);
+        $page->prepare($smarty, isset($this->inv_lookup[$curpage]) ? $this->inv_lookup[$curpage] : $curpage);
     }
 }
 
index 4ba4740..9ef16e4 100644 (file)
@@ -39,7 +39,7 @@ class PlatalModule extends PLModule
     {
         return array(
             'index'       => $this->make_hook('index',     AUTH_PUBLIC),
-           'cacert.pem'  => $this->make_hook('cacert',    AUTH_PUBLIC),
+            'cacert.pem'  => $this->make_hook('cacert',    AUTH_PUBLIC),
             'changelog'   => $this->make_hook('changelog', AUTH_PUBLIC),
 
             // Preferences thingies
@@ -55,6 +55,7 @@ class PlatalModule extends PLModule
             'password/smtp' => $this->make_hook('smtppass',  AUTH_MDP),
             'recovery'      => $this->make_hook('recovery',  AUTH_PUBLIC),
             'exit'          => $this->make_hook('exit', AUTH_PUBLIC),
+            'review'        => $this->make_hook('review', AUTH_PUBLIC),
             'deconnexion.php' => $this->make_hook('exit', AUTH_PUBLIC),
         );
     }
@@ -63,6 +64,8 @@ class PlatalModule extends PLModule
     {
         if (S::logged()) {
             pl_redirect('events');
+        } else if (!@$GLOBALS['IS_XNET_SITE']) {
+            pl_redirect('review');
         }
     }
 
@@ -417,6 +420,31 @@ Adresse de secours : " . Post::v('email') : ""));
             $page->changeTpl('platal/exit.tpl');
         }
     }
+
+    function handler_review(&$page, $action = null, $mode = null) 
+    {
+        require_once 'wiki.inc.php';
+        require_once dirname(__FILE__) . '/platal/review.inc.php';
+        $dir = wiki_work_dir();
+        $dom = 'Review';
+        if (@$GLOBALS['IS_XNET_SITE']) {
+            $dom .= 'Xnet';
+        }
+        if (!is_dir($dir)) {
+            $page->kill("Impossible de trouver le wiki");
+        }
+        if (!file_exists($dir . '/' . $dom . '.Admin')) {
+            $page->kill("Impossible de trouver la page d'administration");
+        }
+        $conf = preg_grep('/^text=/', explode("\n", file_get_contents($dir . '/' . $dom . '.Admin')));
+        $conf = preg_split('/(text\=|\%0a)/', array_shift($conf), -1, PREG_SPLIT_NO_EMPTY);
+        $wiz = new PlWizard('Tour d\'horizon', 'core/plwizard.tpl', true);
+        foreach ($conf as $line) {
+            $list = preg_split('/\s*[*|]\s*/', $line, -1, PREG_SPLIT_NO_EMPTY);
+            $wiz->addPage('ReviewPage', $list[0], $list[1]);
+        }
+        $wiz->apply($page, 'review', $action, $mode);
+    }
 }
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
diff --git a/modules/platal/review.inc.php b/modules/platal/review.inc.php
new file mode 100644 (file)
index 0000000..3cf4f27
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+/***************************************************************************
+ *  Copyright (C) 2003-2007 Polytechnique.org                              *
+ *  http://opensource.polytechnique.org/                                   *
+ *                                                                         *
+ *  This program is free software; you can redistribute it and/or modify   *
+ *  it under the terms of the GNU General Public License as published by   *
+ *  the Free Software Foundation; either version 2 of the License, or      *
+ *  (at your option) any later version.                                    *
+ *                                                                         *
+ *  This program is distributed in the hope that it will be useful,        *
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
+ *  GNU General Public License for more details.                           *
+ *                                                                         *
+ *  You should have received a copy of the GNU General Public License      *
+ *  along with this program; if not, write to the Free Software            *
+ *  Foundation, Inc.,                                                      *
+ *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
+ ***************************************************************************/
+
+__autoload('PlWizard');
+
+class ReviewPage implements PlWizardPage
+{
+    public function __construct(PlWizard &$wiz) { }
+    public function template() { return 'platal/review.tpl'; }
+    public function process() { }
+
+    public function prepare(PlatalPage &$page, $id)
+    {
+        require_once 'wiki.inc.php';
+        $dom = (@$GLOBALS['IS_XNET_SITE'] ? 'ReviewXnet' : 'Review') . '.' . ucfirst($id);
+        wiki_require_page($dom);
+        $page->assign('article', $dom);
+    }
+}
+
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+?>
index 2fede87..00969c2 100644 (file)
@@ -329,7 +329,7 @@ class ProfileModule extends PLModule
 
         $page->addJsLink('ajax.js');
         $page->addJsLink('jquery.js');
-        $wiz = new PlWizard('Profil', 'core/plwizard.tpl', true);
+        $wiz = new PlWizard('Profil', 'core/plwizard.tpl', true, false);
         require_once dirname(__FILE__) . '/profile/page.inc.php';
         $wiz->addPage('ProfileGeneral', 'Général', 'general');
         $wiz->addPage('ProfileAddresses', 'Adresses personnelles', 'adresses');
index ebd8f12..9aaea5e 100644 (file)
@@ -115,9 +115,9 @@ class ProfileDecos extends ProfilePage
         }
     }
 
-    public function prepare(PlatalPage &$page)
+    public function prepare(PlatalPage &$page, $id)
     {
-        parent::prepare($page);
+        parent::prepare($page, $id);
         $res    = XDB::iterator("SELECT  *
                                    FROM  profile_medals_grades
                                ORDER BY  mid, pos");
index 3e66990..3cd19e4 100644 (file)
@@ -197,9 +197,9 @@ class ProfileGeneral extends ProfilePage
         }
     }
 
-    public function prepare(PlatalPage &$page)
+    public function prepare(PlatalPage &$page, $id)
     {
-        parent::prepare($page);
+        parent::prepare($page, $id);
         require_once "applis.func.inc.php";
     }
 }
index a967b94..f274eb6 100644 (file)
@@ -105,9 +105,9 @@ class ProfileGroups extends ProfilePage
         $this->settings['binets']   = new ProfileGroup('binets', 'user_id', 'binet_id');
     }
 
-    public function prepare(PlatalPage &$page)
+    public function prepare(PlatalPage &$page, $id)
     {
-        parent::prepare($page);
+        parent::prepare($page, $id);
         $page->assign('mygroups', XDB::iterator("SELECT  a.nom, a.site, a.diminutif, a.unsub_url, a.pub, m.perms
                                                    FROM  groupex.asso    AS a
                                              INNER JOIN  groupex.membres AS m ON (m.asso_id = a.id)
index 5b497c9..4f79328 100644 (file)
@@ -202,9 +202,9 @@ class ProfileJobs extends ProfilePage
         parent::saveData();
     }
 
-    public function prepare(PlatalPage &$page)
+    public function prepare(PlatalPage &$page, $id)
     {
-        parent::prepare($page);
+        parent::prepare($page, $id);
         $page->assign('secteurs', XDB::iterator("SELECT  id, label
                                                    FROM  emploi_secteur"));
         $page->assign('fonctions', XDB::iterator("SELECT  id, fonction_fr, FIND_IN_SET('titre', flags) AS title
index 5928acd..fbc06ec 100644 (file)
@@ -148,9 +148,9 @@ class ProfileMentor extends ProfilePage
         }
     }
 
-    public function prepare(PlatalPage &$page)
+    public function prepare(PlatalPage &$page, $id)
     {
-        parent::prepare($page);
+        parent::prepare($page, $id);
         $page->assign('secteurs_sel', XDB::iterator("SELECT  id, label
                                                        FROM  emploi_secteur"));
     }
index e06e247..e30023d 100644 (file)
@@ -242,7 +242,7 @@ abstract class ProfilePage implements PlWizardPage
         return 'profile/base.tpl';
     }
 
-    public function prepare(PlatalPage &$page)
+    public function prepare(PlatalPage &$page, $id)
     {
         if (count($this->values) == 0) {
             $this->fetchData();
index a922fc0..17444eb 100644 (file)
@@ -89,9 +89,9 @@ class ProfileSkills extends ProfilePage
         $this->settings['langues'] = new ProfileSkill('langues', 'lid', 'langue_fr');
     }
 
-    public function prepare(PlatalPage &$page)
+    public function prepare(PlatalPage &$page, $id)
     {
-        parent::prepare($page);
+        parent::prepare($page, $id);
         $page->assign('comp_list', XDB::iterator("SELECT  id, text_fr, FIND_IN_SET('titre',flags) AS title
                                                     FROM  competences_def"));
         $page->assign('comp_level', array('initié' => 'initié',
index 3a0d2ad..0f55d7a 100644 (file)
 {*  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA               *}
 {*                                                                        *}
 {**************************************************************************}
+{javascript name="jquery"}
+<script type="text/javascript">//<![CDATA[
+  {if ($stateless || $id gt $current) && $wiz_ajax}
+  {literal}
+  function changePage(obj, id)
+  {
+    var myUrl = obj.href;
+    $.ajax({ url: myUrl + "/ajax",
+             global: false,
+             dataTye: 'html',
+             error: function(request, error) {
+                      document.location = myUrl;
+                    },
+             success: function(data) {
+                        $(".wiz_content").empty().prepend(data);
+                        $(".wiz_tab").removeClass("active");
+                        $("#wiz_tab_" + id).addClass("active");
+                      }
+          });
+    return false;
+  }
+  {/literal}
+  {else}
+  {literal}
+  function changePage(obj)
+  {
+    return true;
+  }
+  {/literal}
+  {/if}
+//]]></script>
 
 <div class="wizard" style="clear: both">
   <div class="wiz_header">
     {foreach from=$pages item=title key=id}
     <div class="wiz_tab {if $id eq $current}active{/if} {if !$stateless && $current gt $id}grayed{/if}"
-         style="float: left; width: {$tab_width}%">
-      {if $stateless || $id gt $current}<a href="{$wiz_baseurl}/{$lookup[$id]}">{/if}
+         style="float: left; width: {$tab_width}%" id="wiz_tab_{$lookup[$id]}">
+      {if $stateless || $id gt $current}
+        <a href="{$wiz_baseurl}/{$lookup[$id]}" onclick="return changePage(this, '{$lookup[$id]}')">{/if}
       {$title}
       {if $stateless || $id gt $current}</a>{/if}
     </div>
diff --git a/templates/platal/review.tpl b/templates/platal/review.tpl
new file mode 100644 (file)
index 0000000..c43d65e
--- /dev/null
@@ -0,0 +1,27 @@
+{**************************************************************************}
+{*                                                                        *}
+{*  Copyright (C) 2003-2007 Polytechnique.org                             *}
+{*  http://opensource.polytechnique.org/                                  *}
+{*                                                                        *}
+{*  This program is free software; you can redistribute it and/or modify  *}
+{*  it under the terms of the GNU General Public License as published by  *}
+{*  the Free Software Foundation; either version 2 of the License, or     *}
+{*  (at your option) any later version.                                   *}
+{*                                                                        *}
+{*  This program is distributed in the hope that it will be useful,       *}
+{*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *}
+{*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *}
+{*  GNU General Public License for more details.                          *}
+{*                                                                        *}
+{*  You should have received a copy of the GNU General Public License     *}
+{*  along with this program; if not, write to the Free Software           *}
+{*  Foundation, Inc.,                                                     *}
+{*  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA               *}
+{*                                                                        *}
+{**************************************************************************}
+
+<div>
+  {include wiki=$article}
+</div>
+
+{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}