From 35f5d8a3a28c87420b60370dcc3ad2613270696f Mon Sep 17 00:00:00 2001
From: Florent Bruneau
Date: Sun, 22 Jun 2008 16:13:50 +0200
Subject: [PATCH] The core will be the core
Signed-off-by: Florent Bruneau
---
core/classes/csvimporter.php | 355 -----------------------
core/classes/env.php | 214 --------------
core/classes/miniwiki.php | 198 -------------
core/classes/mmlist.php | 38 ---
core/classes/platal.php | 354 -----------------------
core/classes/plbacktrace.php | 116 --------
core/classes/plflagset.php | 123 --------
core/classes/plglobals.php | 243 ----------------
core/classes/pliterator.php | 31 --
core/classes/pllogger.php | 114 --------
core/classes/plmailer.php | 336 ----------------------
core/classes/plmodule.php | 67 -----
core/classes/plpage.php | 446 -----------------------------
core/classes/plprofiler.php | 55 ----
core/classes/plsession.php | 204 -------------
core/classes/plset.php | 284 ------------------
core/classes/pltableeditor.php | 324 ---------------------
core/classes/plupload.php | 316 --------------------
core/classes/plwizard.php | 219 --------------
core/classes/s.php | 123 --------
core/classes/varstream.php | 107 -------
core/classes/xdb.php | 366 -----------------------
core/classes/xmlrpcclient.php | 130 ---------
core/include/misc.inc.php | 258 -----------------
core/include/platal.inc.php | 174 -----------
core/modules/core.php | 169 -----------
core/plugins/block.tidy.php | 54 ----
core/plugins/compiler.checkpasswd.php | 57 ----
core/plugins/compiler.iterate.php | 55 ----
core/plugins/compiler.javascript.php | 41 ---
core/plugins/function.select_db_table.php | 74 -----
core/plugins/function.valid_date.php | 58 ----
core/plugins/function.xsrf_token.php | 27 --
core/plugins/function.xsrf_token_field.php | 30 --
core/plugins/modifier.date_format.php | 48 ----
core/plugins/modifier.htmlentities.php | 28 --
core/plugins/modifier.miniwiki.php | 28 --
core/plugins/modifier.number_format.php | 28 --
core/plugins/modifier.uint_to_ip.php | 28 --
39 files changed, 5920 deletions(-)
delete mode 100644 core/classes/csvimporter.php
delete mode 100644 core/classes/env.php
delete mode 100644 core/classes/miniwiki.php
delete mode 100644 core/classes/mmlist.php
delete mode 100644 core/classes/platal.php
delete mode 100644 core/classes/plbacktrace.php
delete mode 100644 core/classes/plflagset.php
delete mode 100644 core/classes/plglobals.php
delete mode 100644 core/classes/pliterator.php
delete mode 100644 core/classes/pllogger.php
delete mode 100644 core/classes/plmailer.php
delete mode 100644 core/classes/plmodule.php
delete mode 100644 core/classes/plpage.php
delete mode 100644 core/classes/plprofiler.php
delete mode 100644 core/classes/plsession.php
delete mode 100644 core/classes/plset.php
delete mode 100644 core/classes/pltableeditor.php
delete mode 100644 core/classes/plupload.php
delete mode 100644 core/classes/plwizard.php
delete mode 100644 core/classes/s.php
delete mode 100644 core/classes/varstream.php
delete mode 100644 core/classes/xdb.php
delete mode 100644 core/classes/xmlrpcclient.php
delete mode 100644 core/include/misc.inc.php
delete mode 100644 core/include/platal.inc.php
delete mode 100644 core/modules/core.php
delete mode 100644 core/plugins/block.tidy.php
delete mode 100644 core/plugins/compiler.checkpasswd.php
delete mode 100644 core/plugins/compiler.iterate.php
delete mode 100644 core/plugins/compiler.javascript.php
delete mode 100644 core/plugins/function.select_db_table.php
delete mode 100644 core/plugins/function.valid_date.php
delete mode 100644 core/plugins/function.xsrf_token.php
delete mode 100644 core/plugins/function.xsrf_token_field.php
delete mode 100644 core/plugins/modifier.date_format.php
delete mode 100644 core/plugins/modifier.htmlentities.php
delete mode 100644 core/plugins/modifier.miniwiki.php
delete mode 100644 core/plugins/modifier.number_format.php
delete mode 100644 core/plugins/modifier.uint_to_ip.php
diff --git a/core/classes/csvimporter.php b/core/classes/csvimporter.php
deleted file mode 100644
index 0f576a0..0000000
--- a/core/classes/csvimporter.php
+++ /dev/null
@@ -1,355 +0,0 @@
-table = $table;
- $this->key = explode(',', $key);
- $this->do_sql = $do_sql;
- }
-
- private function processLine(array $array)
- {
- if (is_null($this->index)) {
- $this->index = array_map('strtolower', $array);
- return true;
- }
-
- if (count($array) != count($this->index)) {
- return false;
- }
- $assoc = array();
- $i = 0;
- foreach ($this->index as $key) {
- $assoc[$key] = $array[$i];
- $i++;
- }
- $this->data[] = $assoc;
- return true;
- }
-
- private function getValue($line, $key, $action)
- {
- if (@array_key_exists($action, $line)) {
- $value = $line[$action];
- } elseif (is_callable($action, false)) {
- $value = call_user_func($action, $line, $key);
- } else {
- $value = $action;
- }
- if (is_null($value) || $value == 'NULL') {
- $value = 'NULL';
- }
- return $value;
- }
-
- private function makeAssoc($line, $relation)
- {
- $ops = array();
- foreach ($relation as $key=>$ref) {
- $ops[$key] = $this->getValue($line, $key, $ref);
- }
- return $ops;
- }
-
- private function makeRequestArgs($line, $relation)
- {
- $ops = array();
- foreach ($relation as $key=>$ref) {
- $value = $this->getValue($line, $key, $ref);
- if (!is_null($value) && $value != 'NULL') {
- $value = "'" . addslashes($value) . "'";
- }
- $ops[$key] = "$key = $value";
- }
- return $ops;
- }
-
- private function makeRelation()
- {
- $relation = array();
- foreach ($this->index as $title) {
- $relation[$title] = $title;
- }
- return $relation;
- }
-
- private function execute($query)
- {
- if (!$this->do_sql) {
- echo "$query;\n";
- return false;
- }
- return XDB::execute($query);
- }
-
- private function getFieldList()
- {
- $res = XDB::query("SHOW COLUMNS FROM {$this->table}");
- if ($res->numRows()) {
- return $res->fetchColumn();
- }
- return null;
- }
-
- public function setCSV($csv, $index = null, $separator = ';')
- {
- require_once dirname(__FILE__) . '/varstream.php';
- VarStream::init();
- global $csv_source;
- $this->index = null;
-
- $csv_source = $csv;
- $res = fopen('var://csv_source', 'r');
-
- while (!feof($res)) {
- $this->processLine(fgetcsv($res, 0, $separator));
- }
- }
-
- public function run($action = CSV_UPDATE, $insert_relation = null, $update_relation = null)
- {
- if (is_null($insert_relation)) {
- $insert_relation = $this->makeRelation();
- }
- if (is_null($update_relation)) {
- $update_relation = $insert_relation;
- }
- foreach ($this->data as $line) {
- $set = join(', ', $this->makeRequestArgs($line, $insert_relation));
- switch ($action) {
- case CSV_INSERT:
- $this->execute("INSERT IGNORE INTO {$this->table} SET $set");
- break;
- case CSV_REPLACE:
- $this->execute("REPLACE INTO {$this->table} SET $set");
- break;
- case CSV_UPDATE: case CSV_UPDATEONLY:
- if ($action == CSV_UPDATEONLY || !$this->execute("INSERT INTO {$this->table} SET $set")) {
- $ops = $this->makeRequestArgs($line, $update_relation);
- $set = join(', ', $ops);
- $where = array();
- foreach ($this->key as $key) {
- $where[] = $ops[$key];
- }
- $where = join(' AND ', $where);
- $this->execute("UPDATE {$this->table} SET $set WHERE $where");
- }
- break;
- }
- }
- }
-
- static public function dynamicCond($line, $key)
- {
- static $fields, $conds, $values, $thens, $elses;
-
- if (!isset($fields)) {
- $fields = $_SESSION['csv_cond_field'];
- $conds = $_SESSION['csv_cond'];
- $values = $_SESSION['csv_cond_value'];
- $thens = $_SESSION['csv_cond_then'];
- $elses = $_SESSION['csv_cond_else'];
- }
- $field = $line[$fields[$key]];
- $cond = $conds[$key];
- $value = $values[$key];
- if (is_numeric($field) && is_numeric($value)) {
- $field = floatval($field);
- $value = floatval($value);
- }
- switch ($cond) {
- case 'defined': $ok = (!empty($field)); break;
- case 'equals': $ok = ($field == $value); break;
- case 'contains': $ok = (strpos($field, $value) !== false); break;
- case 'contained': $ok = (strpos($value, $field) !== false); break;
- case 'greater': $ok = ($field > $value); break;
- case 'greater_or_equal': $ok ($field >= $value); break;
- case 'lower': $ok = ($field < $value); break;
- case 'lower_or_equal': $ok = ($field <= $value); break;
- default: $ok = false;
- }
- if ($ok) {
- return $thens[$key];
- } else {
- return $elses[$key];
- }
- }
-
- public function registerFunction($name, $desc, $callback)
- {
- if (is_callable($callback, false, $ref)) {
- $this->user_functions['func_' . $name] = array('desc' => $desc, 'callback' => $callback);
- return true;
- }
- return false;
- }
-
- public function describe($name, $desc)
- {
- $this->field_desc[$name] = $desc;
- }
-
- public function forceValue($name, $value)
- {
- $this->field_value[$name] = $value;
- }
-
- private function cleanSession($fields)
- {
- foreach ($fields as $field) {
- unset($_SESSION[$field]);
- }
- }
-
- /** Handle insertion form
- * @param $page PlPage to process
- * @param $url URI of the page
- * @param $field Editable fields
- */
- public function apply(&$page, $url, $fields = null)
- {
- $sesfields = array('csv_value', 'csv_user_value', 'csv_cond_field',
- 'csv_update', 'csv_action', 'csv_cond_field',
- 'csv_cond', 'csv_cond_value', 'csv_cond_then',
- 'csv_cond_else', 'csv', 'csv_separator', 'csv_url');
- if ($url != @$_SESSION['csv_url']) {
- $this->cleanSession($sesfields);
- $_SESSION['csv_url'] = $url;
- }
-
- if (is_null($fields) || empty($fields)) {
- $fields = $this->getFieldList();
- }
- if (is_null($fields)) {
- return false;
- }
- foreach ($this->field_value as $key=>$value) {
- $search = array_search($key, $fields);
- unset($fields[$search]);
- }
-
- $current = Env::v('csv_page');
- if (empty($current)) {
- $current = 'source';
- }
- $next = Env::v('csv_next_page');
- if (empty($next)) {
- $next = $current;
- }
- $csv = @$_SESSION['csv'];
- if ($current == 'source' && Env::has('csv_valid')) {
- $csv = Env::v('csv_source');
- $_SESSION['csv'] = $csv;
- $next = 'values';
- }
- if ($csv) {
- if (Env::has('csv_separator')) {
- $sep = Env::v('csv_separator');
- if (empty($sep)) {
- $sep = ';';
- }
- $_SESSION['csv_separator'] = $sep;
- }
- $this->setCSV($csv, null, $_SESSION['csv_separator']);
- }
- if ($current == 'values' && Env::has('csv_valid')) {
- $next = 'valid';
- }
- if (empty($csv)) {
- $next = 'source';
- }
- if (Env::has('csv_action')) {
- $_SESSION['csv_action'] = Env::v('csv_action');
- }
- if ($next == 'valid') {
- if ($current != 'valid') {
- $cpyfields = array('csv_value', 'csv_user_value', 'csv_cond_field',
- 'csv_update', 'csv_action', 'csv_cond_field',
- 'csv_cond', 'csv_cond_value', 'csv_cond_then',
- 'csv_cond_else');
- foreach ($cpyfields as $field) {
- $_SESSION[$field] = Env::v($field);
- }
- }
- $insert = $_SESSION['csv_value'];
- $values = $_SESSION['csv_user_value'];
- $update = $_SESSION['csv_update'];
- foreach ($insert as $key=>$value) {
- if (empty($value)) {
- $insert[$key] = null;
- } elseif ($value == 'user_value') {
- $insert[$key] = $values[$key];
- } elseif ($value == 'cond_value') {
- $insert[$key] = array($this, 'dynamicCond');
- } elseif (array_key_exists($value, $this->user_functions)) {
- $insert[$key] = $this->user_functions[$value]['callback'];
- }
- if (isset($update[$key])) {
- $update[$key] = $insert[$key];
- }
- }
- foreach ($this->field_value as $key=>$value) {
- $insert[$key] = $value;
- $fields[] = $key;
- }
- if ($current == 'valid' && Env::has('csv_valid')) {
- S::assert_xsrf_token();
- $this->run($_SESSION['csv_action'], $insert, $update);
- $page->assign('csv_done', true);
- $this->cleanSession($sesfields);
- } else {
- $preview = array();
- foreach ($this->data as $line) {
- $preview[] = $this->makeAssoc($line, $insert);
- }
- $page->assign('csv_preview', $preview);
- }
- }
- $page->assign('csv_index', $this->index);
- $page->assign('csv_functions', $this->user_functions);
- $page->assign('csv_field_desc', $this->field_desc);
- $page->assign('csv_page', $next);
- $page->assign('csv_path', $url);
- $page->assign('csv_fields', $fields);
- }
-}
-
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
-?>
diff --git a/core/classes/env.php b/core/classes/env.php
deleted file mode 100644
index e3bbd88..0000000
--- a/core/classes/env.php
+++ /dev/null
@@ -1,214 +0,0 @@
-
diff --git a/core/classes/miniwiki.php b/core/classes/miniwiki.php
deleted file mode 100644
index ab547e0..0000000
--- a/core/classes/miniwiki.php
+++ /dev/null
@@ -1,198 +0,0 @@
-(\\\\*))\n/e", "str_repeat('
\n',mb_strlen('$1'))", "str_repeat('\n',mb_strlen('$1'))", "ligne1\\\\\nligne2");
-
- // * unordered list
- MiniWiki::Markup("/(^|\n)\*(([^\n]*(\n|$))(\*[^\n]*(\n|$))*)/se",
- "'
- '.str_replace(\"\\n*\",'
- ','$2').'
'",
- "'$1 -' . str_replace(\"\\n*\", \"\\n -\", '$2')",
- "* element1\n* element2\n* element3");
- // # unordered list
- MiniWiki::Markup("/(^|\n)#(([^\n]*(\n|$))(#[^\n]*(\n|$))*)/se", "'
- '.str_replace(\"\\n#\",'
- ','$2').'
'", "'$0'", "# element1\n# element2\n# element3");
-
- // bold, italic and others
- // ''' bold '''
- MiniWiki::Markup("/'''(.*?)'''/",'$1','*$1*', "'''gras'''");
- // '' italic ''
- MiniWiki::Markup("/''(.*?)''/",'$1','/$1/', "''italique''");
- // '+ big +'
- MiniWiki::Markup("/'\\+(.*?)\\+'/",'$1','*$1*', "'+grand+'");
- // '- small -'
- MiniWiki::Markup("/'\\-(.*?)\\-'/",'$1','$1', "'-petit-'");
- // '^superscript^'
- MiniWiki::Markup("/'\\^(.*?)\\^'/",'$1','$1', "'^exposant^'");
- // '_subscript_'
- MiniWiki::Markup("/'_(.*?)_'/",'$1','$1', "'_indice_'");
- // {+ underline +}
- MiniWiki::Markup("/\\{\\+(.*?)\\+\\}/",'$1','_$1_', "{+insertion+}");
- // {- strikeout -}
- MiniWiki::Markup("/\\{-(.*?)-\\}/",'$1','-$1-', "{-suppression-}");
- // {color| colored text |}
- MiniWiki::Markup("/%([a-z]+|\#[0-9a-f]{3,6})%(.*?)%%/i", "$2", "$2",
- "%red% texte en rouge %%\\\\\n%#ff0% texte en jaune %%\\\\\n%#0000ff% texte en bleu %%");
- // [+ big +] [++ bigger ++] [+++ even bigger +++] ...
- MiniWiki::Markup("/\\[(([-+])+)(.*?)\\1\\]/e","'$3'", "'$3'", "[+ grand +]\n\n[++ plus grand ++]\n\n[+++ encore plus grand +++]");
-
- // -----
- MiniWiki::Markup("/(\n|^)--(--+| \n)/s", '$1
', '$1-- '."\n", "----\n");
- // titles
- MiniWiki::$title_index = MiniWiki::Markup('/(\n|^)(!+)([^\n]*)/se',
- "'$1$3'",
- "'$1$3'", "!titre1\n\n!!titre2\n\n!!!titre3");
-
- // links
- MiniWiki::Markup('/((?:https?|ftp):\/\/(?:[\.\,\;\!\:]*[\w@~%$£µ&i#\-+=_\/\?])*)/ui',
- '\\0', '<\\0>');
- MiniWiki::Markup('/(\s|^|\[\[)www\.((?:[\.\,\;\!\:]*[\w@~%$£µ&i#\-+=_\/\?])*)/iu',
- '\\1www.\\2', '\\1');
- MiniWiki::Markup('/(?:mailto:)?([a-z0-9.\-+_]+@([\-.+_]?[a-z0-9])+)/i', '\\0', '<\\0>');
- MiniWiki::Markup('/\[\[\s*<(?:a href=")?([^">]*?)(?:">.*?<\/a)?>\s*\|([^\]]+)\]\]/i',
- '\\2', '\\2 <\\1>',
- "[[http://www.example.com|Mon site web]]\n\nhttp://www.example.com\n\ntest@example.com");
-
- // paragraphs and empty lines
- MiniWiki::Markup("/\n\n/", '', "\n\n", "paragraphe1\n\nparagraphe2");
- MiniWiki::Markup("/\n/", ' ', "\n");
- MiniWiki::Markup("/^.*<\/p>.*
.*$/s", "
$0
", "$0");
-
- // french typo rules, unbreakable spaces
- MiniWiki::Markup("/ +([!?:;])/", " $1", "$0");
- }
-
- public static function WikiToHTML($wiki, $title = false)
- {
- if (!$title) {
- $oldrule12 = MiniWiki::$replacementHTML[MiniWiki::$title_index];
- MiniWiki::$replacementHTML[MiniWiki::$title_index] = "'$0'";
- }
- $html = preg_replace(MiniWiki::$patternsWiki,
- MiniWiki::$replacementHTML,
- htmlentities(trim($wiki), ENT_COMPAT, 'UTF-8'));
- if (!$title) {
- MiniWiki::$replacementHTML[MiniWiki::$title_index] = $oldrule12;
- }
- return $html;
- }
-
- private static function justify($text, $n)
- {
- $arr = explode("\n", wordwrap($text, $n));
- $arr = array_map('trim', $arr);
- $res = '';
- foreach ($arr as $key => $line) {
- $nxl = isset($arr[$key+1]) ? trim($arr[$key+1]) : '';
- $nxl_split = preg_split('! +!u', $nxl);
- $nxw_len = count($nxl_split) ? mb_strlen($nxl_split[0]) : 0;
- $line = trim($line);
-
- if (mb_strlen($line)+1+$nxw_len < $n) {
- $res .= "$line\n";
- continue;
- }
-
- if (preg_match('![.:;]$!u',$line)) {
- $res .= "$line\n";
- continue;
- }
-
- $tmp = preg_split('! +!u', trim($line));
- $words = count($tmp);
- if ($words <= 1) {
- $res .= "$line\n";
- continue;
- }
-
- $len = array_sum(array_map('mb_strlen', $tmp));
- $empty = $n - $len;
- $sw = floatval($empty) / floatval($words-1);
-
- $cur = 0;
- $l = '';
- foreach ($tmp as $word) {
- $l .= $word;
- $cur += $sw + strlen($word); // Use strlen here instead of mb_strlen because it is used by str_pad
- // which is not multibyte compatible
- $l = str_pad($l, intval($cur + 0.5));
- }
- $res .= trim($l)."\n";
- }
- return trim($res);
- }
-
-
- public static function WikiToText($wiki, $just=false, $indent=0, $width=68, $title=false)
- {
- if (!$title) {
- $oldrule12 = MiniWiki::$replacementHTML[MiniWiki::$title_index];
- MiniWiki::$replacementHTML[MiniWiki::$title_index] = "'$0'";
- }
- //$text = trim($wiki);
- //foreach (MiniWiki::$patternsWiki as $key=>$pattern) {
- // echo $key . " - " . $pattern . "\n";
- // $text = preg_replace($pattern, MiniWiki::$replacementText[$key], $text);
- //}
- $text = preg_replace(MiniWiki::$patternsWiki, MiniWiki::$replacementText, trim($wiki));
- if (!$title) {
- MiniWiki::$replacementHTML[MiniWiki::$title_index] = $oldrule12;
- }
- $text = $just ? MiniWiki::justify($text, $width - $indent) : wordwrap($text, $width - $indent);
- if($indent) {
- $ind = str_pad('',$indent);
- $text = $ind.str_replace("\n","\n$ind",$text);
- }
- return $text;
- }
-
- static public function help($with_title = false)
- {
- if (!$with_title) {
- $info12 = MiniWiki::$info[MiniWiki::$title_index];
- unset(MiniWiki::$info[MiniWiki::$title_index]);
- }
-
- $res = array();
- foreach (MiniWiki::$info as $value) {
- $res[$value] = MiniWiki::wikiToHtml($value, true);
- }
-
- if (!$with_title) {
- MiniWiki::$info[MiniWiki::$title_index] = $info12;
- }
- return $res;
- }
-}
-
-MiniWiki::init();
-
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
-?>
diff --git a/core/classes/mmlist.php b/core/classes/mmlist.php
deleted file mode 100644
index a16b1c6..0000000
--- a/core/classes/mmlist.php
+++ /dev/null
@@ -1,38 +0,0 @@
-mail->domain : $fqdn;
- $url = "http://$uid:$pass@{$globals->lists->rpchost}:{$globals->lists->rpcport}/$dom";
- parent::__construct($url);
- if ($globals->debug & DEBUG_BT) {
- $this->bt = new PlBacktrace('MMList');
- }
- }
-}
-
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
-?>
diff --git a/core/classes/platal.php b/core/classes/platal.php
deleted file mode 100644
index 2a69b72..0000000
--- a/core/classes/platal.php
+++ /dev/null
@@ -1,354 +0,0 @@
-startAvailableAuth()) {
- Platal::page()->trigError('Données d\'authentification invalide.');
- }
-
- $modules = func_get_args();
- if (is_array($modules[0])) {
- $modules = $modules[0];
- }
- $this->path = trim(Get::_get('n', null), '/');
-
- $this->__mods = array();
- $this->__hooks = array();
-
- array_unshift($modules, 'core');
- foreach ($modules as $module) {
- $module = strtolower($module);
- $this->__mods[$module] = $m = PLModule::factory($module);
- $this->__hooks += $m->handlers();
- }
-
- if ($globals->mode == '') {
- pl_redirect('index.html');
- }
- }
-
- public function pl_self($n = null)
- {
- if (is_null($n))
- return $this->path;
-
- if ($n >= 0)
- return join('/', array_slice($this->argv, 0, $n + 1));
-
- if ($n <= -count($this->argv))
- return $this->argv[0];
-
- return join('/', array_slice($this->argv, 0, $n));
- }
-
- protected function find_hook()
- {
- $p = $this->path;
-
- while ($p) {
- if (array_key_exists($p, $this->__hooks))
- break;
-
- $p = substr($p, 0, strrpos($p, '/'));
- }
-
- if (empty($this->__hooks[$p])) {
- return null;
- }
-
- $hook = $this->__hooks[$p];
-
- if (!is_callable($hook['hook'])) {
- return null;
- }
-
- $this->https = ($hook['type'] & NO_HTTPS) ? false : true;
- $this->argv = explode('/', substr($this->path, strlen($p)));
- $this->argv[0] = $p;
-
- return $hook;
- }
-
- protected function find_nearest_key($key, array &$array)
- {
- $keys = array_keys($array);
- if (in_array($key, $keys)) {
- return $key;
- }
-
- if (($pos = strpos($key, '.php')) !== false) {
- $key = substr($key, 0, $pos);
- }
-
- $has_end = in_array("#final#", $keys);
- if (strlen($key) > 24 && $has_end) {
- return "#final#";
- }
-
- foreach ($keys as $k) {
- if ($k == "#final#") {
- continue;
- }
- $lev = levenshtein($key, $k);
-
- if ((!isset($val) || $lev < $val)
- && ($lev <= strlen($k)/2 || strpos($k, $key) !== false || strpos($key, $k) !== false)) {
- $val = $lev;
- $best = $k;
- }
- }
- if (!isset($best) && $has_end) {
- return "#final#";
- } else if (isset($best)) {
- return $best;
- }
- return null;
- }
-
- public function near_hook()
- {
- $hooks = array();
- $leafs = array();
- foreach ($this->__hooks as $hook=>$handler) {
- if (!$this->check_perms($handler['perms'])) {
- continue;
- }
- $parts = split('/', $hook);
- $place =& $hooks;
- foreach ($parts as $part) {
- if (!isset($place[$part])) {
- $place[$part] = array();
- }
- $place =& $place[$part];
- }
- $leaf = $parts[count($parts)-1];
- if (!isset($leafs[$leaf])) {
- $leafs[$leaf] = $hook;
- } else if (is_array($leafs[$leaf])) {
- $leafs[$leaf][] = $hook;
- } else {
- $leafs[$leaf] = array($hook, $leafs[$leaf]);
- }
- $place["#final#"] = array();
- }
-
- // search for the nearest full path
- $p = split('/', $this->path);
- $place =& $hooks;
- $link = '';
- foreach ($p as $k) {
- if (!isset($ended)) {
- $key = $this->find_nearest_key($k, $place);
- } else {
- $key = $k;
- }
- if ($key == "#final#") {
- if (!array_key_exists($link, $this->__hooks)) {
- $link = '';
- break;
- }
- $key = $k;
- $ended = true;
- }
- if (!is_null($key)) {
- if (!empty($link)) {
- $link .= '/';
- }
- $link .= $key;
- $place =& $place[$key];
- } else {
- $link = '';
- break;
- }
- }
- if ($link == $this->path) {
- $link = '';
- }
- if ($link && levenshtein($link, $this->path) < strlen($link)/3) {
- return $link;
- }
-
- // search for missing namespace (the given name is a leaf)
- $leaf = array_shift($p);
- $args = count($p) ? '/' . implode('/', $p) : '';
- if (isset($leafs[$leaf]) && !is_array($leafs[$leaf]) && $leafs[$leaf] != $this->path) {
- return $leafs[$leaf] . $args;
- }
- unset($val);
- $best = null;
- foreach ($leafs as $k=>&$path) {
- if (is_array($path)) {
- continue;
- }
- $lev = levenshtein($leaf, $k);
-
- if ((!isset($val) || $lev < $val)
- && ($lev <= strlen($k)/2 || strpos($k, $leaf) !== false || strpos($leaf, $k) !== false)) {
- $val = $lev;
- $best = $path;
- }
- }
- return $best == null ? ( $link ? $link : null ) : $best . $args;
- }
-
- protected function check_perms($perms)
- {
- if (!$perms) { // No perms, no check
- return true;
- }
- $s_perms = S::v('perms');
- return $s_perms->hasFlagCombination($perms);
- }
-
- private function call_hook(PlPage &$page)
- {
- $hook = $this->find_hook();
- if (empty($hook)) {
- return PL_NOT_FOUND;
- }
- global $globals, $session;
- if ($this->https && !$_SERVER['HTTPS'] && $globals->core->secure_domain) {
- http_redirect('https://' . $globals->core->secure_domain . $_SERVER['REQUEST_URI']);
- }
-
- $args = $this->argv;
- $args[0] =& $page;
-
- if ($hook['auth'] > S::v('auth', AUTH_PUBLIC)) {
- if ($hook['type'] & DO_AUTH) {
- if (!$session->start($hook['auth'])) {
- $this->force_login($page);
- }
- } else {
- return PL_FORBIDDEN;
- }
- }
- if ($hook['auth'] != AUTH_PUBLIC && !$this->check_perms($hook['perms'])) {
- return PL_FORBIDDEN;
- }
-
- $val = call_user_func_array($hook['hook'], $args);
- if ($val == PL_DO_AUTH) {
- // The handler need a better auth with the current args
- if (!$session->start($hook['auth'])) {
- $this->force_login($page);
- }
- $val = call_user_func_array($hook['hook'], $args);
- }
- return $val;
- }
-
- public function force_login(PlPage &$page)
- {
- header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden');
- if (S::logged()) {
- $page->changeTpl('core/password_prompt_logged.tpl');
- $page->addJsLink('do_challenge_response_logged.js');
- } else {
- $page->changeTpl('core/password_prompt.tpl');
- $page->addJsLink('do_challenge_response.js');
- }
- $page->assign('platal', $this);
- $page->run();
- }
-
- public function run()
- {
- $page =& self::page();
-
- if (empty($this->path)) {
- $this->path = 'index';
- }
-
- $page->assign('platal', $this);
- switch ($this->call_hook($page)) {
- case PL_FORBIDDEN:
- $this->__mods['core']->handler_403($page);
- break;
-
- case PL_NOT_FOUND:
- $this->__mods['core']->handler_404($page);
- break;
- }
-
- $page->assign('platal', $this);
- $page->run();
- }
-
- public function on_subscribe($forlife, $uid, $promo, $pass)
- {
- $args = func_get_args();
- foreach ($this->__mods as $mod) {
- if (!is_callable($mod, 'on_subscribe'))
- continue;
- call_user_func_array(array($mod, 'on_subscribe'), $args);
- }
- }
-
- static public function &page()
- {
- global $platal;
- if (is_null(self::$_page)) {
- $pageclass = PL_PAGE_CLASS;
- self::$_page = new $pageclass();
- }
- return self::$_page;
- }
-
- static public function &session()
- {
- global $session;
- return $session;
- }
-
- static public function &globals()
- {
- global $globals;
- return $globals;
- }
-}
-
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
-?>
diff --git a/core/classes/plbacktrace.php b/core/classes/plbacktrace.php
deleted file mode 100644
index 9fb80ec..0000000
--- a/core/classes/plbacktrace.php
+++ /dev/null
@@ -1,116 +0,0 @@
-add($entry, $sizef, $timef, $errorf);
- }
- }
-
- private function fixCharset($action)
- {
- if (!is_string($action)) {
- return $action;
- } else {
- return is_utf8($action) ? $action : utf8_encode($action);
- }
- }
-
- private function add(array &$entry, $sizef = 'rows', $timef = 'exectime', $errorf = 'error')
- {
- $trace = array();
- $trace['action'] = $this->fixCharset($entry['action']);
- unset($entry['action']);
- $trace['exectime'] = @$entry[$timef];
- $this->totaltime += $trace['exectime'];
- unset($entry[$timef]);
- $trace['rows'] = @$entry[$sizef];
- unset($entry[$sizef]);
- $trace['error'] = $this->fixCharset(@$entry[$errorf]);
- unset($entry[$errorf]);
- if ($trace['error']) {
- $this->error = true;
- }
- $trace['data'] = array($this->fixCharset($entry));
- $this->traces[] =& $trace;
- }
-
- public function newEvent($action, $rows = 0, $error = null, array $userdata = array())
- {
- $trace = array('action' => $this->fixCharset($action), 'time' => 0);
- $this->traces[] =& $trace;
- $this->update($rows, $error, $userdata);
- }
-
- public function start($action)
- {
- $this->traces[] = array('action' => $this->fixCharset($action), 'starttime' => microtime(true));;
- }
-
- public function stop($rows = 0, $error = null, array $userdata = array())
- {
- $time = microtime(true);
- if (!$this->traces) {
- return;
- }
- $trace =& $this->traces[count($this->traces) - 1];
- $trace['exectime'] = $time - $trace['starttime'];
- unset($trace['starttime']);
- $this->totaltime += $trace['exectime'];
- $this->update($rows, $error, $userdata);
- }
-
- public function update($rows = 0, $error = null, array $userdata = array())
- {
- $trace =& $this->traces[count($this->traces) - 1];
- $trace['rows'] = $rows;
- $trace['error'] = $this->fixCharset($error);
- array_walk_recursive($userdata, array($this, 'fixCharset'));
- $trace['data'] = $userdata;
- if ($trace['error']) {
- $this->error = true;
- }
- }
-
- public static function clean()
- {
- foreach (PlBacktrace::$bt as $name=>&$entry) {
- if (!$entry->traces) {
- unset(PlBacktrace::$bt[$name]);
- }
- }
- }
-}
-
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
-?>
diff --git a/core/classes/plflagset.php b/core/classes/plflagset.php
deleted file mode 100644
index 1971751..0000000
--- a/core/classes/plflagset.php
+++ /dev/null
@@ -1,123 +0,0 @@
-sep = $sep;
- $splitted = explode($sep, $flags);
- foreach ($splitted as $part) {
- $this->values[$part] = true;
- }
- }
-
-
- /** add flag
- * @param $flag XXX
- * @return VOID
- */
- public function addFlag($flag)
- {
- if (empty($flag)) {
- return;
- }
- $this->values[$flag] = true;
- }
-
-
- /** test si flag ou pas
- * @param $flag XXX
- * @return 1 || 0
- */
- public function hasFlag($flag)
- {
- return !empty($flag) && isset($this->values[$flag]) && $this->values[$flag];
- }
-
- /** test flag combination
- */
- public function hasFlagCombination($flag)
- {
- $perms = explode(',', $flag);
- foreach ($perms as $perm)
- {
- $ok = true;
- $rights = explode(':', $perm);
- foreach ($rights as $right) {
- if (($right{0} == '!' && $this->hasFlag(substr($right, 1))) || !$this->hasFlag($right)) {
- $ok = false;
- }
- }
- if ($ok) {
- return true;
- }
- }
- return false;
- }
-
- /** remove flag
- * @param $flag XXX
- * @return VOID
- */
- public function rmFlag($flag)
- {
- if (empty($flag)) {
- return;
- }
- if (isset($this->values[$flag])) {
- unset($this->values[$flag]);
- }
- }
-
-
- /** return the PlFlagSet
- */
- public function flags()
- {
- $flags = '';
- foreach ($this->values as $key=>$value) {
- if (!empty($flags)) {
- $flags .= $this->sep;
- }
- if ($value) {
- $flags .= $key;
- }
- }
- return $flags;
- }
-}
-
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
-?>
diff --git a/core/classes/plglobals.php b/core/classes/plglobals.php
deleted file mode 100644
index 2636890..0000000
--- a/core/classes/plglobals.php
+++ /dev/null
@@ -1,243 +0,0 @@
-
- * [SectionName]
- * fieldname = value
- *
- *
- * With this configuration file, you'll be able to access 'value' via
- * $globals->sectionname->fieldname. Let say 'sectionname' is a namespace
- *
- *
- * You should derivate this class into a local Globals class. In this class
- * you can specify configuration variables that belongs to the 'global' namespace
- * (accessible via $global->fieldname). To do so, just define the fieldname
- * in your class and set its value in the [Core] section of you ini file.
- */
-class PlGlobals
-{
- public $coreVersion = '0.9.17';
-
- /** Debug level.
- * This is a combination of the DEBUG_ flags. As soon as at least
- * one flag is set, the debug mode is activated, this means:
- * - debug panel on the top of the pages
- * - don't hide php notices
- * - recompile templates when they have been changed
- */
- public $debug = 0;
-
- /** Access mode.
- */
- public $mode = 'rw'; // 'rw' => read/write,
- // 'r' => read/only
- // '' => site down
-
- /** BaseURL of the site.
- * This is read from the HTTP headers if available but you MUST give a
- * default value for this field in you configuration file (because, this
- * can be used in CLI scripts that has no access no HTTP headers...)
- *
- * [Core]
- * baseurl = "https//www.mysite.org/"
- */
- public $baseurl;
-
- /** In case your base url is https-based, this provied an HTTP-based value
- * for the URL.
- */
- public $baseurl_http;
-
- /** paths */
- public $spoolroot;
-
- /** Localization configuration.
- */
- public $locale;
- public $timezone;
-
- /** You must give a list of file to load.
- * The filenames given are relatives to the config path of your plat/al installation.
- */
- public function __construct(array $files)
- {
- $this->spoolroot = dirname(dirname(dirname(__FILE__)));
-
- $this->readConfig($files);
- if (isset($_SERVER) && isset($_SERVER['SERVER_NAME'])) {
- $base = empty($_SERVER['HTTPS']) ? 'http://' : 'https://';
- $this->baseurl = @trim($base .$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF']), '/');
- $this->baseurl_http = @trim('http://'.$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF']), '/');
- }
-
- $this->setLocale();
- }
-
- private function readIniFile($filename)
- {
- $array = parse_ini_file($filename, true);
- if (!is_array($array)) {
- return;
- }
- foreach ($array as $cat => $conf) {
- $c = strtolower($cat);
- foreach ($conf as $k => $v) {
- if ($c == 'core' && property_exists($this, $k)) {
- $this->$k=$v;
- } else {
- if (!isset($this->$c)) {
- $this->$c = new stdClass;
- }
- $this->$c->$k = $v;
- }
- }
- }
- }
-
- private function readConfig(array $files)
- {
- foreach ($files as $file) {
- $this->readIniFile($this->spoolroot . '/configs/' . $file);
- }
- if (file_exists($this->spoolroot.'/spool/conf/platal.dynamic.conf')) {
- $this->readIniFile($this->spoolroot.'/spool/conf/platal.dynamic.conf');
- }
- }
-
- /** Writes an ini file separated in categories
- * @param filename the name of the file to write (overwrite existing)
- * @param categories an array of categories (array of keys and values)
- */
- private function writeIniFile($filename, &$categories)
- {
- // [category]
- // key = value
- $f = fopen($filename, 'w');
- foreach ($categories as $cat => $conf) {
- fwrite($f, '; {{{ '.$cat."\n\n");
- fwrite($f, '['.$cat.']'."\n\n");
- foreach ($conf as $k => $v) {
- fwrite($f, $k.' = "'.str_replace('"','\\"',$v).'"'."\n");
- }
- fwrite($f, "\n".'; }}}'."\n");
- }
- fwrite($f, '; vim:set syntax=dosini foldmethod=marker:'."\n");
- fclose($f);
- }
-
- /** Change dynamic config file
- * @param conf array of keys and values to add or replace
- * @param category name of category to change
- *
- * Opens the dynamic conf file and set values from conf in specified
- * category. Updates config vars too.
- */
- public function changeDynamicConfig($conf, $category = 'Core')
- {
- $dynamicfile = $this->spoolroot.'/spool/conf/platal.dynamic.conf';
- if (file_exists($dynamicfile)) {
- $array = parse_ini_file($dynamicfile, true);
- } else {
- $array = null;
- }
- if (!is_array($array)) {
- // dynamic conf is empty
- $array = array($category => $conf);
- } else {
- // looks for a category that looks the same (case insensitive)
- $same = false;
- foreach ($array as $m => &$c) {
- if (strtolower($m) == strtolower($category)) {
- $same = $m;
- break;
- }
- }
- if (!$same) {
- // this category doesn't exist yet
- $array[$category] = $conf;
- } else {
- // this category already exists
- $conflower = array();
- foreach ($conf as $k => $v) {
- $conflower[strtolower($k)] = $v;
- }
- // $conflower is now same as $conf but with lower case keys
- // replaces values of keys that already exists
- foreach ($array[$same] as $k => $v) {
- if (isset($conflower[strtolower($k)])) {
- $array[$same][$k] = $conflower[strtolower($k)];
- unset($conflower[strtolower($k)]);
- }
- }
- // add new keys
- foreach ($conf as $k => $v) {
- if (isset($conflower[strtolower($k)])) {
- $array[$same][$k] = $v;
- }
- }
- }
- }
- // writes the file over
- $this->writeIniFile($dynamicfile, $array);
- // rereads the new config to correctly set vars
- $this->readIniFile($dynamicfile);
- }
-
- public function bootstrap($conf, $callback, $category = 'Core')
- {
- $bootstrap = false;
- $category = strtolower($category);
- foreach ($conf as $key) {
- if (!isset($this->$category->$key)) {
- $bootstrap = true;
- break;
- }
- }
- if ($bootstrap) {
- call_user_func($callback);
- }
- }
-
- private function setLocale()
- {
- setlocale(LC_MESSAGES, $this->locale);
- setlocale(LC_TIME, $this->locale);
- setlocale(LC_CTYPE, $this->locale);
- date_default_timezone_set($this->timezone);
- mb_internal_encoding("UTF-8");
- }
-}
-
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
-?>
diff --git a/core/classes/pliterator.php b/core/classes/pliterator.php
deleted file mode 100644
index 0b5f254..0000000
--- a/core/classes/pliterator.php
+++ /dev/null
@@ -1,31 +0,0 @@
-
diff --git a/core/classes/pllogger.php b/core/classes/pllogger.php
deleted file mode 100644
index 0381926..0000000
--- a/core/classes/pllogger.php
+++ /dev/null
@@ -1,114 +0,0 @@
-uid = $uid;
- $this->session = $this->writeSession($uid, $suid);
-
- // retrieve available actions
- $res = XDB::iterRow("SELECT id, text FROM logger.actions");
-
- while (list($action_id, $action_text) = $res->next()) {
- $this->actions[$action_text] = $action_id;
- }
- }
-
- /** Creates a new session entry in database and return its ID.
- *
- * @param $uid the id of the logged user
- * @param $suid the id of the administrator who has just su'd to the user
- * @return session the session id
- */
- private function writeSession($uid, $suid = 0)
- {
- $ip = $_SERVER['REMOTE_ADDR'];
- $host = strtolower(gethostbyaddr($_SERVER['REMOTE_ADDR']));
- $browser = (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '');
-
- @list($forward_ip,) = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
- $forward_host = $forward_ip;
- if ($forward_host) {
- $forward_host = strtolower(gethostbyaddr($forward_host));
- }
- $proxy = '';
- if ($forward_ip || @$_SERVER['HTTP_VIA']) {
- $proxy = 'proxy';
- }
-
- XDB::execute("INSERT INTO logger.sessions
- SET uid={?}, host={?}, ip={?}, forward_ip={?}, forward_host={?}, browser={?}, suid={?}, flags={?}",
- $uid, $host, ip_to_uint($ip), ip_to_uint($forward_ip), $forward_host, $browser, $suid, $proxy);
- if ($forward_ip) {
- $this->proxy_ip = $ip;
- $this->proxy_host = $host;
- $this->ip = $forward_ip;
- $this->host = $forward_host;
- } else {
- $this->ip = $ip;
- $this->host = $host;
- }
-
- return XDB::insertId();
- }
-
-
- /** Logs an action and its related data.
- *
- * @param $action le type d'action
- * @param $data les données (id de liste, etc.)
- * @return VOID
- */
- public function log($action, $data = null)
- {
- if (isset($this->actions[$action])) {
- XDB::execute("INSERT INTO logger.events
- SET session={?}, action={?}, data={?}",
- $this->session, $this->actions[$action], $data);
- } else {
- trigger_error("PlLogger: unknown action, $action", E_USER_WARNING);
- }
- }
-}
-
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
-?>
diff --git a/core/classes/plmailer.php b/core/classes/plmailer.php
deleted file mode 100644
index 2106d50..0000000
--- a/core/classes/plmailer.php
+++ /dev/null
@@ -1,336 +0,0 @@
-tpl = $tpl;
- $this->caching = false;
- $this->compile_check = true;
-
- $this->template_dir = $globals->spoolroot . "/templates/";
- $this->compile_dir = $globals->spoolroot . "/spool/mails_c/";
- $this->config_dir = $globals->spoolroot . "/configs/";
- array_unshift($this->plugins_dir, $globals->spoolroot."/plugins/");
-
- $this->register_outputfilter(Array($this, 'mail_format'));
- $this->register_function('from', Array($this, 'setFrom'));
- $this->register_function('to', Array($this, 'addTo'));
- $this->register_function('cc', Array($this, 'addCc'));
- $this->register_function('bcc', Array($this, 'addBcc'));
- $this->register_function('subject', Array($this, 'setSubject'));
- $this->register_function('add_header', Array($this, 'addHeader'));
- $this->assign_by_ref('globals', $globals);
- }
-
- public static function &get(&$mailer, $tpl)
- {
- static $plmail;
- if (!isset($plmail) || $plmail->tpl != $tpl) {
- $plmail = new PlMail($tpl);
- }
- $plmail->mailer =& $mailer;
- return $plmail;
- }
-
- public function run($version)
- {
- $this->assign('mail_part', $version);
- $text = $this->fetch($this->tpl);
- if ($version == 'text') {
- return wordwrap($text, 78);
- }
- return $text;
- }
-
- /** used to remove the empty lines due to {from ...}, {to ...} ... functions */
- static public function mail_format($output, &$smarty)
- {
- return "\n".trim($output)."\n";
- }
-
- static protected function format_addr(&$params)
- {
- if (isset($params['full'])) {
- return $params['full'];
- } elseif (empty($params['text'])) {
- return $params['addr'];
- } else {
- return $params['text'].' <'.$params['addr'].'>';
- }
- }
-
- /** template function : from.
- * {from full=...} for an already formatted address
- * {from addr=... [text=...]} else
- */
- public function setFrom($params, &$smarty)
- {
- $smarty->mailer->setFrom(PlMail::format_addr($params));
- }
-
- /** template function : to.
- * {to full=...} for an already formatted address
- * {to addr=... [text=...]} else
- */
- public function addTo($params, &$smarty)
- {
- $smarty->mailer->addTo(PlMail::format_addr($params));
- }
-
- /** template function : cc.
- * {cc full=...} for an already formatted address
- * {cc addr=... [text=...]} else
- */
- public function addCc($params, &$smarty)
- {
- $smarty->mailer->addCc(PlMail::format_addr($params));
- }
-
- /** template function : bcc.
- * {bcc full=...} for an already formatted address
- * {bcc addr=... [text=...]} else
- */
- public function addBcc($params, &$smarty)
- {
- $smarty->mailer->addBcc(PlMail::format_addr($params));
- }
-
- /** template function : subject.
- * {subject text=...}
- */
- public function setSubject($params, &$smarty)
- {
- $smarty->mailer->setSubject($params['text']);
- }
-
- /** template function : add_header.
- * {add_header name=... value=...}
- */
- public function addHeader($params, &$smarty)
- {
- $smarty->mailer->addHeader($params['name'], $params['value']);
- }
-}
-
-require_once('Mail.php');
-require_once('Mail/mime.php');
-
-/** Class for sending inline or multipart-emails.
- * Based on Diogenes' HermesMailer
- */
-class PlMailer extends Mail_Mime {
-
- private $mail;
- private $page = null;
- private $charset;
- private $wiki = null;
-
- function __construct($tpl = null, $charset = "UTF-8")
- {
- $this->charset = $charset;
- $this->Mail_Mime("\n");
- $this->mail = Mail::factory('sendmail', Array('sendmail_args' => '-oi'));
- if (!is_null($tpl)) {
- $this->page =& PlMail::get($this, $tpl);
- }
- }
-
- /**
- * converts all : Foo Bar Baz into "Foo Bar Baz" which is RFC compliant
- */
- private function correct_emails($email)
- {
- return preg_replace('!(^|, *)([^<"]+?) *(<[^>]*>)!u', '\1"\2" \3', $email);
- }
-
- public function addTo($email)
- {
- $email = $this->correct_emails($email);
- if (isset($this->_headers['To'])) {
- $this->_headers['To'] .= ", $email";
- } else {
- $this->_headers['To'] = $email;
- }
- }
-
- public function addCc($email)
- {
- return parent::addCc($this->correct_emails($email));
- }
-
- public function addBcc($email)
- {
- return parent::addBcc($this->correct_emails($email));
- }
-
- public function setFrom($email)
- {
- return parent::setFrom($this->correct_emails($email));
- }
-
- public function addHeader($hdr,$val)
- {
- switch($hdr) {
- case 'From':
- $this->setFrom($val);
- break;
-
- case 'To':
- unset($this->_headers[$hdr]);
- $this->addTo($val);
- break;
-
- case 'Cc':
- unset($this->_headers[$hdr]);
- $this->addCc($val);
- break;
-
- case 'Bcc':
- unset($this->_headers[$hdr]);
- $this->addBcc($val);
- break;
-
- default:
- $this->headers(Array($hdr=>$val));
- }
- }
-
- public function addUploadAttachment(PlUpload &$upload, $name)
- {
- $encoding = $upload->isType('text') ? 'quoted-printable' : 'base64';
- $this->addAttachment($upload->getContents(), $upload->contentType(), $name, false, $encoding);
- }
-
- public function assign($var, $value)
- {
- if (!is_null($this->page)) {
- $this->page->assign($var, $value);
- }
- }
-
- public function assign_by_ref($var, &$value)
- {
- if (!is_null($this->page)) {
- $this->page->assign_by_ref($var, $value);
- }
- }
-
- public function register_modifier($var, $callback)
- {
- if (!is_null($this->page)) {
- $this->page->register_modifier($var, $callback);
- }
- }
-
- public function register_function($var, $callback)
- {
- if (!is_null($this->page)) {
- $this->page->register_function($var, $callback);
- }
- }
-
- public function setWikiBody($wiki)
- {
- $this->wiki = $wiki;
- }
-
- private function processPage($with_html = true)
- {
- if (!is_null($this->page)) {
- global $globals;
- if (!($globals->debug & DEBUG_SMARTY)) {
- $level = error_reporting(0);
- }
- $this->page->run('head'); // process page headers
- $this->wiki = trim($this->page->run('wiki')); // get wiki
- if (!$this->wiki) {
- $this->setTxtBody($this->page->run('text'));
- if ($with_html) {
- $html = trim($this->page->run('html'));
- if (!empty($html)) {
- $this->setHtmlBody($html);
- }
- }
- }
- if (!($globals->debug & DEBUG_SMARTY)) {
- error_reporting($level);
- }
- }
- if ($this->wiki) {
- $this->setTxtBody(MiniWiki::WikiToText($this->wiki, false, 0, 78));
- if ($with_html) {
- $this->setHtmlBody('' . MiniWiki::WikiToHtml($this->wiki, true) . '');
- }
- }
- }
-
- public function send($with_html = true)
- {
- $this->processPage($with_html);
- if (S::v('forlife')) {
- global $globals;
- $this->addHeader('X-Org-Mail', S::v('forlife') . '@' . $globals->mail->domain);
- }
- $addrs = Array();
- foreach(Array('To', 'Cc', 'Bcc') as $hdr) {
- if(isset($this->_headers[$hdr])) {
- require_once 'Mail/RFC822.php';
- $parsed = @Mail_RFC822::parseAddressList($this->_headers[$hdr]);
- if (is_array($parsed)) {
- $addrs = array_merge($addrs, $parsed);
- }
- }
- }
- if(empty($addrs)) {
- return false;
- }
-
- $dests = Array();
- foreach($addrs as $a) {
- $dests[] = "{$a->mailbox}@{$a->host}";
- }
-
- // very important to do it in THIS order very precisely.
- $body = $this->get(array('text_charset' => $this->charset,
- 'text_encoding' => '8bit',
- 'html_charset' => $this->charset,
- 'head_charset' => $this->charset));
- $hdrs = $this->headers();
- if (empty($hdrs['From'])) {
- trigger_error('Empty "From", mail not sent', E_USER_WARNING);
- return false;
- }
- return $this->mail->send($dests, $hdrs, $body);
- }
-}
-
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
-?>
diff --git a/core/classes/plmodule.php b/core/classes/plmodule.php
deleted file mode 100644
index 9d5dc9b..0000000
--- a/core/classes/plmodule.php
+++ /dev/null
@@ -1,67 +0,0 @@
- array($this, 'handler_'.$fun),
- 'auth' => $auth,
- 'perms' => $perms,
- 'type' => $type);
- }
-
- /* static functions */
-
- public static function factory($modname)
- {
- global $globals;
- if ($modname == 'core') {
- $mod_path = $globals->spoolroot . '/core/modules/' . $modname . '.php';
- } else {
- $mod_path = $globals->spoolroot . '/modules/' . $modname . '.php';
- }
- $class = ucfirst($modname) . 'Module';
-
- require_once $mod_path;
- return new $class();
- }
-}
-
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
-?>
diff --git a/core/classes/plpage.php b/core/classes/plpage.php
deleted file mode 100644
index 5230036..0000000
--- a/core/classes/plpage.php
+++ /dev/null
@@ -1,446 +0,0 @@
-caching = false;
- $this->config_overwrite = false;
- $this->use_sub_dirs = false;
- $this->template_dir = $globals->spoolroot . '/templates/';
- $this->compile_dir = $globals->spoolroot . '/spool/templates_c/';
- array_unshift($this->plugins_dir,
- $globals->spoolroot . '/core/plugins/',
- $globals->spoolroot . '/plugins/');
- $this->config_dir = $globals->spoolroot . '/configs/';
-
- $this->compile_check = !empty($globals->debug);
-
- $this->_errors = array('errors' => array());
- $this->_jsonVars = array();
- $this->_failure = false;
-
- if ($globals->mode != 'rw') {
- $this->trigError("En raison d'une maintenance, une partie des fonctionnalités du site sont"
- . " actuellement désactivée, en particuliers aucune donnée ne sera sauvegardée");
- }
- $this->register_prefilter('at_to_globals');
- $this->addJsLink('xorg.js');
- $this->addJsLink('jquery.js');
- }
-
- // }}}
- // {{{ function changeTpl()
-
- public function changeTpl($tpl, $type = SKINNED)
- {
- $this->_tpl = $tpl;
- $this->_page_type = $type;
- $this->assign('pl_tpl', $tpl);
- }
-
- // }}}
- // {{{ function raw()
-
- public function raw()
- {
- global $globals;
- $this->assign('globals', $globals);
- return $this->fetch($this->_tpl);
- }
-
- // }}}
- // {{{ function _run()
-
- protected function _run($skin)
- {
- global $globals, $TIME_BEGIN;
-
- Platal::session()->close();
-
- $this->register_prefilter('trimwhitespace');
- $this->register_prefilter('form_force_encodings');
- $this->register_prefilter('wiki_include');
- $this->register_prefilter('if_has_perms');
- $this->assign('pl_triggers', $this->_errors);
- $this->assign('pl_errors', $this->nb_errs());
- $this->assign('pl_failure', $this->_failure);
- $this->assign_by_ref('globals', $globals);
-
- if (Env::has('json') && count($this->_jsonVars)) {
- return $this->jsonDisplay();
- }
-
- if (Env::v('display') == 'light') {
- $this->_page_type = SIMPLE;
- } elseif (Env::v('display') == 'raw') {
- $this->_page_type = NO_SKIN;
- } elseif (Env::v('display') == 'full') {
- $this->_page_typ = SKINNED;
- }
-
- switch ($this->_page_type) {
- case NO_SKIN:
- if (!($globals->debug & DEBUG_SMARTY)) {
- error_reporting(0);
- }
- $this->display($this->_tpl);
- exit;
-
- case SIMPLE:
- $this->assign('simple', true);
-
- case SKINNED:
- $this->register_modifier('escape_html', 'escape_html');
- $this->default_modifiers = Array('@escape_html');
- }
- if (S::i('auth') <= AUTH_PUBLIC) {
- $this->register_outputfilter('hide_emails');
- }
- $this->addJsLink('wiki.js');
- header("Accept-Charset: utf-8");
- if (Env::v('forceXml')) {
- header("Content-Type: text/xml; charset=utf-8");
- }
-
- if (!$globals->debug) {
- error_reporting(0);
- $this->display($skin);
- exit;
- }
-
- $this->assign('validate', true);
- if (!($globals->debug & DEBUG_SMARTY)) {
- error_reporting(0);
- }
- $START_SMARTY = microtime(true);
- $result = $this->fetch($skin);
- $ttime = sprintf('Temps total: %.02fs (Smarty %.02fs) - Mémoire totale : %dKo
',
- microtime(true) - $TIME_BEGIN, microtime(true) - $START_SMARTY,
- memory_get_peak_usage(true) / 1024);
- if ($globals->debug & DEBUG_BT) {
- PlBacktrace::clean();
- $this->assign_by_ref('backtraces', PlBacktrace::$bt);
- $result = str_replace('@@BACKTRACE@@', $this->fetch('skin/common.backtrace.tpl'), $result);
- } else {
- $result = str_replace('@@BACKTRACE@@', '', $result);
- }
-
- $replc = "VALIDATION HTML INACTIVE
";
- if ($globals->debug & DEBUG_VALID) {
- $fd = fopen($this->compile_dir."/valid.html","w");
- fwrite($fd, $result);
- fclose($fd);
-
- exec($globals->spoolroot."/bin/devel/xhtml.validate.pl ".$this->compile_dir."/valid.html", $val);
- foreach ($val as $h) {
- if (preg_match("/^X-W3C-Validator-Errors: (\d+)$/", $h, $m)) {
- $replc = 'HTML OK
';
- if ($m[1]) {
- $replc = "{$m[1]} ERREUR(S) !!!
";
- }
- break;
- }
- }
- }
-
- echo str_replace("@HOOK@", $ttime.$replc, $result);
- exit;
- }
-
- abstract public function run();
-
- // }}}
- // {{{ function nb_errs()
-
- public function nb_errs()
- {
- return count($this->_errors['errors']);
- }
-
- // }}}
- // {{{ function trig()
-
- private function trig($msg, $type = 'errors')
- {
- if (!isset($this->_errors[$type])) {
- $this->_errors[$type] = array();
- }
- $this->_errors[$type][] = $msg;
- }
-
- public function trigError($msg)
- {
- $this->trig($msg, 'errors');
- }
-
- public function trigWarning($msg)
- {
- $this->trig($msg, 'warnings');
- }
-
- public function trigSuccess($msg)
- {
- $this->trig($msg, 'success');
- }
-
- // }}}
- // {{{ function kill()
-
- public function kill($msg)
- {
- global $platal;
-
- $this->assign('platal', $platal);
- $this->trigError($msg);
- $this->_failure = true;
- $this->run();
- }
-
- // }}}
- // {{{ function addJsLink
-
- public function addJsLink($path)
- {
- $this->append('pl_js', $path);
- }
-
- // }}}
- // {{{ function addCssLink
-
- public function addCssLink($path)
- {
- $this->append('pl_css', $path);
- }
-
- // }}}
- // {{{ function addCssInline
-
- public function addCssInline($css)
- {
- if (!empty($css)) {
- $this->append('pl_inline_css', $css);
- }
- }
-
- // }}}
- // {{{ function setRssLink
-
- public function setRssLink($title, $path)
- {
- $this->assign('pl_rss', array('title' => $title, 'href' => $path));
- }
-
- // }}}
- // {{{ function jsonDisplay
- protected function jsonDisplay()
- {
- header("Content-type: text/javascript; charset=utf-8");
- array_walk_recursive($this->_jsonVars, "escape_xorgDB");
- $jsonbegin = Env::v('jsonBegin');
- $jsonend = Env::v('jsonEnd');
- if (Env::has('jsonVar')) {
- $jsonbegin = Env::v('jsonVar').' = ';
- $jsonend = ';';
- } elseif (Env::has('jsonFunc')) {
- $jsonbegin = Env::v('jsonFunc').'(';
- $jsonend = ');';
- }
- echo $jsonbegin, json_encode($this->_jsonVars), $jsonend;
- exit;
- }
- // }}}
- // {{{ function jsonAssign
- public function jsonAssign($var, $value)
- {
- $this->_jsonVars[$var] = $value;
- }
-
- // }}}
-}
-
-function escape_xorgDB(&$item, $key)
-{
- if (is_a($item, 'XOrgDBIterator')) {
- $expanded = array();
- while ($a = $item->next()) {
- $expanded[] = $a;
- }
- $item = $expanded;
- }
-}
-
-// {{{ function escape_html ()
-
-/**
- * default smarty plugin, used to auto-escape dangerous html.
- *
- * < --> <
- * > --> >
- * " --> "
- * & not followed by some entity --> &
- */
-function escape_html($string)
-{
- if (is_string($string)) {
- return htmlspecialchars($string, ENT_QUOTES, 'UTF-8');
- } else {
- return $string;
- }
-}
-
-// }}}
-// {{{ function at_to_globals()
-
-/**
- * helper
- */
-
-function _to_globals($s) {
- global $globals;
- $t = explode('.',$s);
- if (count($t) == 1) {
- return var_export($globals->$t[0],true);
- } else {
- return var_export($globals->$t[0]->$t[1],true);
- }
-}
-
-/**
- * compilation plugin used to import $globals confing through #globals.foo.bar# directives
- */
-
-function at_to_globals($tpl_source, &$smarty)
-{
- return preg_replace('/#globals\.([a-zA-Z0-9_.]+?)#/e', '_to_globals(\'\\1\')', $tpl_source);
- }
-
- // }}}
- // {{{ function trimwhitespace
-
- function trimwhitespace($source, &$smarty)
- {
- $tags = '(script|pre|textarea)';
- preg_match_all("!<$tags.*?>.*?(\\1)>!ius", $source, $tagsmatches);
- $source = preg_replace("!<$tags.*?>.*?(\\1)>!ius", "&&&tags&&&", $source);
-
- // remove all leading spaces, tabs and carriage returns NOT
- // preceeded by a php close tag.
- $source = preg_replace('/((?)\n)[\s]+/m', '\1', $source);
- $source = preg_replace("!&&&tags&&&!e", 'array_shift($tagsmatches[0])', $source);
-
- return $source;
- }
-
- // }}}
- // {{{ function wiki_include
-
-function wiki_include($source, &$smarty)
-{
- return preg_replace('/\{include( [^}]*)? wiki=([^} ]+)(.*?)\}/ui',
- '{include\1 file="../spool/wiki.d/cache_\2.tpl"\3 included=1}',
- $source);
-}
-
-// }}}
-//{{{ function hasPerm
-
-function if_has_perms($source, &$smarty)
-{
- $source = preg_replace('/\{if([^}]*) (\!?)hasPerms\(([^)]+)\)([^}]*)\}/',
- '{if\1 \2$smarty.session.perms->hasFlagCombination(\3)\4}',
- $source);
-return preg_replace('/\{if([^}]*) (\!?)hasPerm\(([^)]+)\)([^}]*)\}/',
- '{if\1 \2($smarty.session.perms && $smarty.session.perms->hasFlag(\3))\4}',
- $source);
-}
-
-// }}}
-// {{{
-
-function form_force_encodings($source, &$smarty)
-{
- return preg_replace('/