/** class for describing flags
*/
-class flagset {
- /** string that holds the flagset */
- var $value;
+class Flagset
+{
+ /** string that holds the flagset */
+ private $value;
- /** the boundary between flags */
- var $sep = ",";
+ /** the boundary between flags */
+ private $sep = ",";
- /** set flag
- * @param $flags services FROM coupures
- * @return VOID
- */
- function flagset( $flags="" ) {
- $this->value = $flags;
- }
+ /** set flag
+ * @param $flags services FROM coupures
+ * @return VOID
+ */
+ public function __construct($flags = "")
+ {
+ $this->value = $flags;
+ }
- /** add flag
- * @param $flag XXX
- * @return VOID
- */
- function addflag($flag) {
- if (!$flag) return;
- if (!$this->hasflag($flag)) {
- if ($this->value)
- $this->value .= $this->sep;
- $this->value .= $flag;
+ /** add flag
+ * @param $flag XXX
+ * @return VOID
+ */
+ public function addflag($flag)
+ {
+ if (!$flag) return;
+ if (!$this->hasflag($flag)) {
+ if ($this->value)
+ $this->value .= $this->sep;
+ $this->value .= $flag;
+ }
}
- }
- /** test si flag ou pas
- * @param $flag XXX
- * @return 1 || 0
- */
- function hasflag($flag) {
- $tok = strtok($this->value,$this->sep);
- while ($tok) {
- if ($tok==$flag) return 1;
- $tok = strtok($this->sep);
+ /** test si flag ou pas
+ * @param $flag XXX
+ * @return 1 || 0
+ */
+ public function hasflag($flag)
+ {
+ $tok = strtok($this->value,$this->sep);
+ while ($tok) {
+ if ($tok==$flag) return 1;
+ $tok = strtok($this->sep);
+ }
+ return 0;
}
- return 0;
- }
- /** remove flag
- * @param $flag XXX
- * @return VOID
- */
- function rmflag($flag) {
- if (!$flag) return;
- $newvalue = "";
- $tok = strtok($this->value,$this->sep);
- while ($tok) {
- if ($tok!=$flag) {
- if ($newvalue)
- $newvalue .= $this->sep;
- $newvalue .= $tok;
- }
- $tok = strtok($this->sep);
+ /** remove flag
+ * @param $flag XXX
+ * @return VOID
+ */
+ public function rmflag($flag)
+ {
+ if (!$flag) return;
+ $newvalue = "";
+ $tok = strtok($this->value,$this->sep);
+ while ($tok) {
+ if ($tok!=$flag) {
+ if ($newvalue)
+ $newvalue .= $this->sep;
+ $newvalue .= $tok;
+ }
+ $tok = strtok($this->sep);
+ }
+ $this->value=$newvalue;
}
- $this->value=$newvalue;
- }
}
class MMList extends XmlrpcClient
{
- function __construct($uid, $pass, $fqdn = null)
+ public function __construct($uid, $pass, $fqdn = null)
{
global $globals;
}
}
- function __call($method, $args)
+ public function __call($method, $args)
{
return parent::__call($method, $args);
}
class Platal
{
- var $__mods;
- var $__hooks;
+ private $__mods;
+ private $__hooks;
- var $ns;
- var $path;
- var $argv;
+ public $ns;
+ public $path;
+ public $argv;
- function Platal()
+ public function __construct()
{
$modules = func_get_args();
+ if (is_array($modules[0])) {
+ $modules = $modules[0];
+ }
$this->path = trim(Get::_get('n', null), '/');
$this->__mods = array();
}
}
- function pl_self($n = null)
+ public function pl_self($n = null)
{
if (is_null($n))
return $this->path;
return join('/', array_slice($this->argv, 0, $n));
}
- function find_hook()
+ protected function find_hook()
{
$p = $this->path;
return $hook;
}
- function find_nearest_key($key, &$array)
+ protected function find_nearest_key($key, array &$array)
{
$keys = array_keys($array);
if (in_array($key, $keys)) {
return null;
}
- function near_hook()
+ protected function near_hook()
{
$hooks = array();
foreach ($this->__hooks as $hook=>$handler) {
return null;
}
- function call_hook(&$page)
+ private function call_hook(PlatalPage &$page)
{
$hook = $this->find_hook();
if (empty($hook)) {
return $val;
}
- function force_login(&$page)
+ protected function force_login(PlatalPage &$page)
{
if (S::logged()) {
$page->changeTpl('core/password_prompt_logged.tpl');
$page->run();
}
- function run()
+ public function run()
{
global $page;
$page->run();
}
- function on_subscribe($forlife, $uid, $promo, $pass)
+ private function on_subscribe($forlife, $uid, $promo, $pass)
{
$args = func_get_args();
foreach ($this->__mods as $mod) {
class PlatalPage extends Smarty
{
- var $_page_type;
- var $_tpl;
- var $_errors;
- var $_failure;
+ private $_page_type;
+ private $_tpl;
+ private $_errors;
+ private $_failure;
// defaults
var $caching = false;
// {{{ function PlatalPage()
- function PlatalPage($tpl, $type = SKINNED)
+ public function __construct($tpl, $type = SKINNED)
{
- global $globals;
+ parent::Smarty();
- $this->Smarty();
+ global $globals;
$this->template_dir = $globals->spoolroot."/templates/";
$this->compile_dir = $globals->spoolroot."/spool/templates_c/";
// }}}
// {{{ function changeTpl()
- function changeTpl($tpl, $type = SKINNED)
+ public function changeTpl($tpl, $type = SKINNED)
{
$this->_tpl = $tpl;
$this->_page_type = $type;
// }}}
// {{{ function _run()
- function _run($skin)
+ protected function _run($skin)
{
global $globals, $TIME_BEGIN;
// }}}
// {{{ function nb_errs()
- function nb_errs()
+ public function nb_errs()
{
return count($this->_errors);
}
// }}}
// {{{ function trig()
- function trig($msg)
+ public function trig($msg)
{
$this->_errors[] = $msg;
}
// }}}
// {{{ function kill()
- function kill($msg)
+ public function kill($msg)
{
global $platal;
// }}}
// {{{ function addJsLink
- function addJsLink($path)
+ public function addJsLink($path)
{
$this->append('xorg_js', $path);
}
// }}}
// {{{ function addCssLink
- function addCssLink($path)
+ public function addCssLink($path)
{
$this->append('xorg_css', $path);
}
// }}}
// {{{ function addCssInline
- function addCssInline($css)
+ public function addCssInline($css)
{
if (!empty($css)) {
$this->append('xorg_inline_css', $css);
// }}}
// {{{ function setRssLink
- function setRssLink($title, $path)
+ public function setRssLink($title, $path)
{
$this->assign('xorg_rss', array('title' => $title, 'href' => $path));
}
--- /dev/null
+<?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 *
+ ***************************************************************************/
+
+interface PlIterator
+{
+ public function next();
+ public function total();
+ public function first();
+ public function last();
+}
+
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+?>
{
function handlers() { die("implement me"); }
- function make_hook($fun, $auth, $perms = '', $type = DO_AUTH)
+ public function make_hook($fun, $auth, $perms = '', $type = DO_AUTH)
{
return array('hook' => array($this, 'handler_'.$fun),
'auth' => $auth,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
***************************************************************************/
-class PLTableEditor {
+class PLTableEditor
+{
// the plat/al name of the page
- var $pl;
+ public $pl;
// the table name
- var $table;
+ public $table;
// joint tables to delete when deleting an entry
- var $jtables = array();
+ public $jtables = array();
// sorting field
- var $sort = array();
+ public $sort = array();
// the id field
- var $idfield;
+ public $idfield;
// possibility to edit the field
- var $idfield_editable;
+ public $idfield_editable;
// vars
- var $vars;
+ public $vars;
// number of displayed fields
- var $nbfields;
+ public $nbfields;
// the field for sorting entries
- var $sortfield;
- var $sortdesc = false;
+ public $sortfield;
+ public $sortdesc = false;
// action to do to delete row:
- // null => delete effectively, false => no deletion, SQL
- var $delete_action;
- var $delete_message;
+ // null => delete effectively, false => no deletion, SQL
+ public $delete_action;
+ public $delete_message;
// Should "Save" button return to the list view
- var $auto_return = true;
+ public $auto_return = true;
/* table editor for platal
* $plname : the PLname of the page, ex: admin/payments
* $idfield : the field of the table which is the id, ex: id
* $editid : is the id editable or not (if not, it is considered as an int)
*/
- function PLTableEditor($plname, $table, $idfield, $editid=false)
+ public function __construct($plname, $table, $idfield, $editid=false)
{
$this->pl = $plname;
$this->table = $table;
}
$this->vars[$idfield]['desc'] = 'id';
}
+
// called before creating a new entry
- function prepare_new()
+ private function prepare_new()
{
$entry = array();
foreach ($this->vars as $field => $descr) {
}
return $this->prepare_edit($entry);
}
+
// called before editing $entry
- function prepare_edit(&$entry) {
+ private function prepare_edit(&$entry)
+ {
foreach ($this->vars as $field => $descr) {
if ($descr['Type'] == 'set') {
// get the list of options selected
}
return $entry;
}
+
// set whether the save button show redirect to list view or edit view
- function list_on_edit($var)
+ public function list_on_edit($var)
{
$this->auto_return = $var;
}
+
// change display of a field
- function describe($name, $desc, $display) {
+ public function describe($name, $desc, $display)
+ {
$this->vars[$name]['desc'] = $desc;
$this->vars[$name]['display'] = $display;
}
+
// add a join table, when deleting a row corresponding entries will be deleted in these tables
- function add_join_table($name,$joinid,$joindel,$joinextra="") {
+ public function add_join_table($name,$joinid,$joindel,$joinextra="")
+ {
if ($joindel)
$this->jtables[$name] = array("joinid" => $joinid,"joinextra" => $joinextra?(" AND ".$joinextra):"");
}
+
// add a sort key
- function add_sort_field($key, $desc = false, $default = false)
+ public function add_sort_field($key, $desc = false, $default = false)
{
- if ($default) {
- $this->sortfield = $key . ($desc ? ' DESC' : '');
- } else {
- $this->sort[] = $key . ($desc ? ' DESC' : '');
+ if ($default) {
+ $this->sortfield = $key . ($desc ? ' DESC' : '');
+ } else {
+ $this->sort[] = $key . ($desc ? ' DESC' : '');
}
}
+
// set an action when trying to delete row
- function on_delete($action = NULL, $message = NULL)
+ public function on_delete($action = NULL, $message = NULL)
{
- $this->delete_action = $action;
- $this->delete_message = $message;
+ $this->delete_action = $action;
+ $this->delete_message = $message;
}
+
// call when done
- function apply(&$page, $action, $id = false) {
+ public function apply(PlatalPage &$page, $action, $id = false)
+ {
$page->changeTpl('core/table-editor.tpl');
$list = true;
if ($action == 'delete') {
- if (!isset($this->delete_action)) {
- foreach ($this->jtables as $table => $j)
- XDB::execute("DELETE FROM {$table} WHERE {$j['joinid']} = {?}{$j['joinextra']}", $id);
- XDB::execute("DELETE FROM {$this->table} WHERE {$this->idfield} = {?}",$id);
- $page->trig("L'entrée ".$id." a été supprimée.");
- } else if ($this->delete_action) {
- XDB::execute($this->delete_action, $id);
- if (isset($this->delete_message)) {
- $page->trig($this->delete_message);
- } else {
- $page->trig("L'entrée ".$id." a été supprimée.");
- }
- } else {
- $page->trig("Impossible de supprimer l'entrée.");
- }
+ if (!isset($this->delete_action)) {
+ foreach ($this->jtables as $table => $j)
+ XDB::execute("DELETE FROM {$table} WHERE {$j['joinid']} = {?}{$j['joinextra']}", $id);
+ XDB::execute("DELETE FROM {$this->table} WHERE {$this->idfield} = {?}",$id);
+ $page->trig("L'entrée ".$id." a été supprimée.");
+ } else if ($this->delete_action) {
+ XDB::execute($this->delete_action, $id);
+ if (isset($this->delete_message)) {
+ $page->trig($this->delete_message);
+ } else {
+ $page->trig("L'entrée ".$id." a été supprimée.");
+ }
+ } else {
+ $page->trig("Impossible de supprimer l'entrée.");
+ }
}
if ($action == 'edit') {
$r = XDB::query("SELECT * FROM {$this->table} WHERE {$this->idfield} = {?}",$id);
}
}
if ($action == 'sort') {
- $this->sortfield = $id;
+ $this->sortfield = $id;
}
if ($action == 'sortdesc') {
- $this->sortfield = $id.' DESC';
+ $this->sortfield = $id.' DESC';
}
if ($list) {
// user can sort by field by clicking the title of the column
class Trombi extends XOrgPlugin
{
- var $_get_vars = array('offset');
- var $limit = 24;
- var $admin = false;
- var $showpromo = true;
+ private $limit = 24;
+ private $admin = false;
+ private $showpromo = true;
- function setNbRows($row)
+ public function __construct($funcname = null, $prefix = null)
+ {
+ $this->_get_vars = array('offset');
+ parent::__construct($funcname, $prefix);
+ }
+
+ public function setNbRows($row)
{ $this->limit = $row*3; }
- function setAdmin()
+ public function setAdmin()
{ $this->admin = true; }
- function hidePromo()
+ public function hidePromo()
{ $this->showpromo = false; }
- function show()
+ public function show()
{
- /* this point is nasty... but since show() is called from the template ...
- * I can't see any more clever way to achieve that
- */
- global $page;
+ /* this point is nasty... but since show() is called from the template ...
+ * I can't see any more clever way to achieve that
+ */
+ global $page;
- $offset = intval($this->get_value('offset'));
- list($total, $list) = call_user_func($this->_callback, $offset, $this->limit);
- $page_max = intval(($total-1)/$this->limit);
+ $offset = intval($this->get_value('offset'));
+ list($total, $list) = call_user_func($this->_callback, $offset, $this->limit);
+ $page_max = intval(($total-1)/$this->limit);
- $links = Array();
- if ($offset) {
- $links[] = Array('u'=> $this->make_url($offset-1), 'i' => $offset-1, 'text' => 'précédent');
- }
- for ($i = 0; $i <= $page_max ; $i++) {
- $links[] = Array('u'=>$this->make_url($i), 'i' => $i, 'text' => $i+1);
+ $links = Array();
+ if ($offset) {
+ $links[] = Array('u'=> $this->make_url($offset-1), 'i' => $offset-1, 'text' => 'précédent');
+ }
+ for ($i = 0; $i <= $page_max ; $i++) {
+ $links[] = Array('u'=>$this->make_url($i), 'i' => $i, 'text' => $i+1);
+ }
+ if ($offset < $page_max) {
+ $links[] = Array ('u' => $this->make_url($offset+1), 'i' => $offset+1, 'text' => 'suivant');
}
- if ($offset < $page_max) {
- $links[] = Array ('u' => $this->make_url($offset+1), 'i' => $offset+1, 'text' => 'suivant');
- }
- $page->assign_by_ref('trombi_show_promo', $this->showpromo);
- $page->assign_by_ref('trombi_list', $list);
- $page->assign_by_ref('trombi_links', $links);
- $page->assign('trombi_admin', $this->admin);
- return $page->fetch('include/trombi.tpl');
+ $page->assign_by_ref('trombi_show_promo', $this->showpromo);
+ $page->assign_by_ref('trombi_list', $list);
+ $page->assign_by_ref('trombi_links', $links);
+ $page->assign('trombi_admin', $this->admin);
+ return $page->fetch('include/trombi.tpl');
}
}
private $varname;
private $position;
- function stream_open($path, $mode, $options, &$opened_path)
+ public function stream_open($path, $mode, $options, &$opened_path)
{
$url = parse_url($path);
$this->varname = $url['host'];
return true;
}
- function stream_close()
+ public function stream_close()
{
}
- function stream_read($count)
+ public function stream_read($count)
{
$ret = substr($GLOBALS[$this->varname], $this->position, $count);
$this->position += strlen($ret);
return $ret;
}
- function stream_write($data)
+ public function stream_write($data)
{
$len = strlen($data);
if ($len > $this->position + strlen($GLOBALS[$this->varname])) {
$this->position += $len;
}
- function stream_eof()
+ public function stream_eof()
{
return $this->position >= strlen($GLOBALS[$this->varname]);
}
- function stream_tell()
+ public function stream_tell()
{
return $this->position;
}
- function stream_seek($offs, $whence)
+ public function stream_seek($offs, $whence)
{
switch ($whence) {
case SEEK_SET:
return 0;
}
- function stream_flush()
+ public function stream_flush()
{
}
- static function init()
+ static public function init()
{
stream_wrapper_register('var','VarStream');
}
}
}
-class XOrgDBIterator
+require_once dirname(__FILE__) . '/pliterator.php';
+
+class XOrgDBIterator implements PlIterator
{
private $_result;
private $_pos;
class Xnet extends Platal
{
- function Xnet()
+ public function __construct()
{
$modules = func_get_args();
- call_user_func_array(array(&$this, 'Platal'), $modules);
+ parent::__construct($modules);
global $globals;
if ($globals->asso()) {
}
}
- function find_nearest_key($key, &$array)
+ protected function find_nearest_key($key, array &$array)
{
global $globals;
if (in_array('%grp', array_keys($array)) && $key == $globals->asso('diminutif')) {
return parent::find_nearest_key($key, $array);
}
- function near_hook()
+ protected function near_hook()
{
global $globals;
$link = str_replace('%grp', $globals->asso('diminutif'), parent::near_hook());
return null;
}
- function find_hook()
+ protected function find_hook()
{
$ans = parent::find_hook();
if ($ans && $this->ns) {
return $ans;
}
- function force_login(&$page)
+ protected function force_login(&$page)
{
http_redirect(S::v('loginX'));
}
class XOrgPlugin
{
/** have to override, contents the fields names used to drive the plugin */
- var $_get_vars = array();
+ public $_get_vars = array();
/** some polymorphism at low cost, may be used, or not */
- var $_callback;
+ public $_callback;
/** constructor.
* the constructor override $_get_vars settings by prefixing the names with $prefix
*/
- function XOrgPlugin($funcname='', $prefix='')
+ public function __construct($funcname='', $prefix='')
{
- $this->_callback = $funcname;
- $this->_prefix = $prefix;
- foreach ($this->_get_vars as $key=>$val) {
+ $this->_callback = $funcname;
+ $this->_prefix = $prefix;
+ foreach ($this->_get_vars as $key=>$val) {
$this->_get_vars[$key] = $prefix.$val;
}
}
/** transparent access to $_GET, wrt the right $prefix
*/
- function get_value($key)
+ public function get_value($key)
{
return Get::v($this->_prefix.$key);
}
/** construct an url with the given parameters to drive the plugin.
* leave all other GET params alone
*/
- function make_url($params)
+ public function make_url($params)
{
- $get = Array();
- $args = isset($params) ? $params : Array();
+ $get = Array();
+ $args = isset($params) ? $params : Array();
- if (!is_array($args)) {
+ if (!is_array($args)) {
$args = array($this->_get_vars[0]=>$params);
- }
+ }
- foreach ($_GET as $key=>$val) {
+ foreach ($_GET as $key=>$val) {
if ($key == 'n') {
continue;
}
- if (in_array($key, $this->_get_vars) && array_key_exists($key, $args)) {
+ if (in_array($key, $this->_get_vars) && array_key_exists($key, $args)) {
continue;
}
- $get[] = urlencode($key) . '=' . urlencode($val);
- }
+ $get[] = urlencode($key) . '=' . urlencode($val);
+ }
- foreach ($this->_get_vars as $key) {
- if (array_key_exists($key, $args)) {
- if ($args[$key]) {
+ foreach ($this->_get_vars as $key) {
+ if (array_key_exists($key, $args)) {
+ if ($args[$key]) {
$get[] = urlencode($key) . '=' . urlencode($args[$key]);
}
} elseif (Get::has('key')) {
- $get[] = urlencode($key) . '=' . urlencode(Get::v($key));
- }
- }
+ $get[] = urlencode($key) . '=' . urlencode(Get::v($key));
+ }
+ }
- return pl_self() . '?' . join('&', $get);
+ return pl_self() . '?' . join('&', $get);
}
/** need to be overriden. */
- function show ()
+ public function show()
{
return '';
}
require_once('xorg.misc.inc.php');
require_once('user.func.inc.php');
-class VCardIterator
+class VCardIterator implements PlIterator
{
private $user_list = array();
private $count = 0;
class XnetPage extends PlatalPage
{
- var $nomenu = false;
+ public $nomenu = false;
// {{{ function XnetPage()
- function XnetPage($tpl, $type=SKINNED)
+ public function __construct($tpl, $type=SKINNED)
{
- $this->PlatalPage($tpl, $type);
+ parent::__construct($tpl, $type);
$this->register_function('list_all_my_groups', 'list_all_my_groups');
$this->register_modifier('cat_pp', 'cat_pp');
// }}}
// {{{ function run()
- function run()
+ public function run()
{
if (!$this->nomenu) {
$this->useMenu();
// }}}
// {{{ function setType
- function setType($type)
+ public function setType($type)
{
$this->assign('xnet_type', strtolower($type));
}
// }}}
// {{{ function useMenu
- function useMenu()
+ private function useMenu()
{
global $globals;
class XorgPage extends PlatalPage
{
- function XorgPage($tpl, $type = SKINNED)
+ public function __construct($tpl, $type = SKINNED)
{
- $this->PlatalPage($tpl, $type);
+ parent::__construct($tpl, $type);
}
- function run()
+ public function run()
{
global $globals, $platal;
$this->assign('globals', $globals);
}
// }}}
-// {{{ class XorgAdmin
-
-/** Une classe pour les pages réservées aux admins (authentifiés!).
- */
-class XorgAdmin extends XorgPage
-{
- // {{{ function XorgAdmin()
-
- function XorgAdmin($tpl, $type = SKINNED)
- {
- $this->XorgPage($tpl, $type);
- check_perms();
- }
-
- // }}}
-}
-
-// }}}
function _new_page($type, $tpl_name, $admin=false)
{