From 08614d65a9983e2cdd99f01b2d5adda054104cb4 Mon Sep 17 00:00:00 2001 From: Radex Date: Wed, 18 Feb 2009 19:59:02 +0100 Subject: [PATCH] =?utf8?q?kolejna=20partia=20drobniejszych=20zmian=20(wci?= =?utf8?q?=C4=85=C5=BC=20mo=C5=BCliwe,=20=C5=BCe=20zacommitowany=20waterme?= =?utf8?q?lon=20nie=20odpali?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit między innymi: - zmiana działania plDate (zamiast 12.06.2009 jest 12 stycznia 2009) - pobieranie i zapisywanie konfiguracji z bazy danych (tabela config) - masowe zamiany [ControllerName] na __construct --- wtrmln/helpers/text.php | 48 +++++++++++++++- .../controllers/profile.php => libs/block.php} | 19 +++--- wtrmln/libs/config.php | 50 ++++++++++++++++ wtrmln/libs/controller.php | 11 +++- wtrmln/libs/db.php | 9 +-- .../controllers/profile.php => libs/libs.php} | 27 ++++----- wtrmln/libs/pluginscdb.php | 4 +- wtrmln/libs/url.php | 6 +- wtrmln/libs/viewtags.php | 67 +++++++++++++++++++--- wtrmln/modules/acinfo/index.html | 0 wtrmln/modules/admin/index.html | 0 wtrmln/modules/blocks/index.html | 0 wtrmln/modules/controllers/benchmarkmanager.php | 14 ++--- wtrmln/modules/controllers/login.php | 4 +- wtrmln/modules/controllers/pages.php | 2 +- wtrmln/modules/controllers/profile.php | 6 +- 16 files changed, 209 insertions(+), 58 deletions(-) copy wtrmln/{modules/controllers/profile.php => libs/block.php} (79%) copy wtrmln/{modules/controllers/profile.php => libs/libs.php} (76%) create mode 100644 wtrmln/modules/acinfo/index.html create mode 100644 wtrmln/modules/admin/index.html create mode 100644 wtrmln/modules/blocks/index.html diff --git a/wtrmln/helpers/text.php b/wtrmln/helpers/text.php index 5e6cf96..7efa52b 100644 --- a/wtrmln/helpers/text.php +++ b/wtrmln/helpers/text.php @@ -77,6 +77,8 @@ function generatePlFormOf($int, $odm1, $odm2, $odm3) function plDate($timestamp) { + $timestamp = intval($timestamp); + // mniej niż minuta temu if($timestamp + 60 > time()) @@ -88,13 +90,13 @@ function plDate($timestamp) if($timestamp + 3600 > time()) { - $minutesAgo = (int) ((time() - $timestamp)/60); + $minutesAgo = (int) ((time() - $timestamp) / 60); return $minutesAgo . ' ' . generatePlFormOf($minutesAgo, 'minutę', 'minuty', 'minut') . ' temu'; } // dane z timestampu - list($day, $month, $year, $hour, $minute) = explode('.', date('d.m.Y.H.i', $timestamp)); + list($day, $month, $year, $hour, $minute) = explode('.', date('j.m.Y.H.i', $timestamp)); // dane z teraz @@ -123,7 +125,47 @@ function plDate($timestamp) // dawniej niż przedwczoraj - return $day . '.' . $month . '.' . $year . ' ' . $hour . ':' . $minute; + switch($month) + { + case 1: + $month = 'stycznia'; + break; + case 2: + $month = 'lutego'; + break; + case 3: + $month = 'marca'; + break; + case 4: + $month = 'kwietnia'; + break; + case 5: + $month = 'maja'; + break; + case 6: + $month = 'czerwca'; + break; + case 7: + $month = 'lipca'; + break; + case 8: + $month = 'sierpnia'; + break; + case 9: + $month = 'września'; + break; + case 10: + $month = 'października'; + break; + case 11: + $month = 'listopada'; + break; + case 12: + $month = 'grudnia'; + break; + } + + return $day . ' ' . $month . ' ' . $year . ' ' . $hour . ':' . $minute; } ?> diff --git a/wtrmln/modules/controllers/profile.php b/wtrmln/libs/block.php similarity index 79% copy from wtrmln/modules/controllers/profile.php copy to wtrmln/libs/block.php index 64778f3..e8bf310 100644 --- a/wtrmln/modules/controllers/profile.php +++ b/wtrmln/libs/block.php @@ -3,7 +3,7 @@ Watermelon CMS -Copyright 2008 Radosław Pietruszewski +Copyright 2009 Radosław Pietruszewski This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -20,16 +20,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ********************************************************************/ -class Profile extends Controller +class Block { - function Profile() + function __construct() { - parent::Controller(); - } - - function Index() - { - SetH1('Panel użytkownika'); + $this->url = new URL(); + $this->db = new DB(); + $this->load = new Loader(); + $this->user = new User(); } } -?> + +?> \ No newline at end of file diff --git a/wtrmln/libs/config.php b/wtrmln/libs/config.php index 79f70c9..90fc33d 100644 --- a/wtrmln/libs/config.php +++ b/wtrmln/libs/config.php @@ -29,6 +29,14 @@ class Config public static $defaultController; public static $theme; private static $superusers = null; + private static $dbconfig = array(); + private static $dbconfigLoaded = false; + + /* + * public static void setSuperusers(string[] $superusers) + * + * ustawia listę administratorów na $superusers + */ public static function setSuperusers(array $superusers) { @@ -38,10 +46,52 @@ class Config } } + /* + * public static string[] getSuperusers() + * + * zwraca listę administratorów + */ + public static function getSuperusers() { return self::$superusers; } + + /* + * public static mixed getConf(string $fieldname) + * + * pobiera z bazy danych wartość konfiguracji $fieldname i zwraca ją + */ + + public static function getConf($fieldname) + { + if(!self::$dbconfigLoaded) + { + $data = DB::query("SELECT * FROM `__config`"); + + while($field = $data->to_obj()) + { + self::$dbconfig[$field->field] = $field->value; + } + + self::$dbconfigLoaded = true; + } + + return self::$dbconfig[$fieldname]; + } + + /* + * public static void setConf(string $fieldname, string $fieldvalue) + * + * ustawia w bazie danych wartość pola $fieldname na $fieldvalue + */ + + public static function setConf($fieldname, $fieldvalue) + { + self::$dbconfig[$fieldname] = $fieldvalue; + + DB::query("INSERT INTO `__config` (`field`, `value`) VALUES ('%1', '%2') ON DUPLICATE KEY UPDATE `value` = '%2'", $fieldname, $fieldvalue); + } } ?> diff --git a/wtrmln/libs/controller.php b/wtrmln/libs/controller.php index 1acec2e..c0bbe3e 100644 --- a/wtrmln/libs/controller.php +++ b/wtrmln/libs/controller.php @@ -3,7 +3,7 @@ Watermelon CMS -Copyright 2008 Radosław Pietruszewski +Copyright 2008-2009 Radosław Pietruszewski This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -31,6 +31,15 @@ class Controller $this->load = new Loader(); $this->user = new User(); self::$_user = $this->user; + + if(defined('ADMIN_MODE')) + { + if(!$this->user->IsAdmin()) + { + header('Location: ' . WTRMLN_MAINURL . 'login'); + exit; + } + } } /* diff --git a/wtrmln/libs/db.php b/wtrmln/libs/db.php index 9bb856e..ed4a916 100644 --- a/wtrmln/libs/db.php +++ b/wtrmln/libs/db.php @@ -1,4 +1,4 @@ - diff --git a/wtrmln/libs/pluginscdb.php b/wtrmln/libs/pluginscdb.php index 0f446be..1361185 100644 --- a/wtrmln/libs/pluginscdb.php +++ b/wtrmln/libs/pluginscdb.php @@ -1,4 +1,4 @@ -[\s]+<\?php else\{ \?>#', '', $data); // tag end - - $data = preg_replace('##', '', $data); + + /*$data = preg_replace('##', '', $data);*/ //deprecated + + // tag nick + + //$data = preg_replace_callback('##', array('ViewTags', 'tag_nick'), $data); + $data = preg_replace('##', '', $data); + + // tag date + + //$data = preg_replace_callback('##', array('ViewTags', 'tag_date'), $data); + $data = preg_replace('##', '', $data); + + // tag unpack + + $data = preg_replace('##', ' $var){$$key = $var;} ?>', $data); + + // tag list object + + $data = preg_replace('##', 'to_obj()){foreach($\\1_item as $key => $var){$$key = $var;} ?>', $data); + $data = preg_replace('##', '', $data); // tag load page $data = preg_replace_callback('#]+)>#', array('ViewTags', 'tag_load_page'), $data); - + + // tag block + + $data = preg_replace('#]+)>#', '', $data); + return $data; } @@ -103,6 +126,36 @@ class ViewTags { return ''; } + + /* + * private static string tag_nick(string[2] $data) + * + * obsługuje pobieranie nicku tzn. zamienia przykładowe + * na + * UID jest brany z drugiego elementu $data. Pierwszy jest + * niewykorzystywany. Istnieje on ze względu na sposób działania funkcji + * preg_replace_callback. + */ + + private static function tag_nick($data) + { + return ''; + } + + /* + * private static string tag_date(string[2] $data) + * + * obsługuje wyświetlanie polskich dat tzn. zamienia przykładowe + * na + * timestamp jest brany z drugiego elementu $data. Pierwszy jest + * niewykorzystywany. Istnieje on ze względu na sposób działania funkcji + * preg_replace_callback. + */ + + private static function tag_date($data) + { + return ''; + } /* * private static string tag_foreach(string[2] $data) diff --git a/wtrmln/modules/acinfo/index.html b/wtrmln/modules/acinfo/index.html new file mode 100644 index 0000000..e69de29 diff --git a/wtrmln/modules/admin/index.html b/wtrmln/modules/admin/index.html new file mode 100644 index 0000000..e69de29 diff --git a/wtrmln/modules/blocks/index.html b/wtrmln/modules/blocks/index.html new file mode 100644 index 0000000..e69de29 diff --git a/wtrmln/modules/controllers/benchmarkmanager.php b/wtrmln/modules/controllers/benchmarkmanager.php index a27e7d7..f70a3c8 100644 --- a/wtrmln/modules/controllers/benchmarkmanager.php +++ b/wtrmln/modules/controllers/benchmarkmanager.php @@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. class BenchmarkManager extends Controller { - function BenchmarkManager() + function __construct() { parent::Controller(); } @@ -37,7 +37,7 @@ class BenchmarkManager extends Controller // jeśli brak benchmarków - if($benchmarksResult->num_rows() == 0) + if(!$benchmarksResult->exists()) { echo 'brak benchmarków'; return; @@ -47,15 +47,13 @@ class BenchmarkManager extends Controller while($benchmark = $benchmarksResult->to_obj()) { - $benchmarks[$benchmark->name][] = (int) $benchmark->value; + $benchmarks[$benchmark->name][] = $benchmark->value; } // robimy listę foreach($benchmarks as $key => $var) { - $values = array(); - echo '

' . $key . ' [Usuń]

'; echo ''; @@ -85,18 +83,20 @@ class BenchmarkManager extends Controller echo ''; } - $values[] = $value; + $valuesCounter++; + $values = bcadd($values, $value); } echo '
'; - echo 'Średni wynik: ' . (int) (array_sum($values) / count($values)) . ' µs'; + echo 'Średni wynik: ' . bcdiv($values, $valuesCounter) . ' µs'; } } function delete() { $this->db->query("DELETE FROM `__benchmark` WHERE `name` = '%1'", $this->url->segment(1)); + $this->db->query("OPTIMIZE TABLE `__benchmark`"); echo 'done, wróć'; } diff --git a/wtrmln/modules/controllers/login.php b/wtrmln/modules/controllers/login.php index 0713de1..7b6e3c8 100644 --- a/wtrmln/modules/controllers/login.php +++ b/wtrmln/modules/controllers/login.php @@ -3,7 +3,7 @@ Watermelon CMS -Copyright 2008 Radosław Pietruszewski +Copyright 2008-2009 Radosław Pietruszewski This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. class Login extends Controller { - function Login() + function __construct() { parent::Controller(); } diff --git a/wtrmln/modules/controllers/pages.php b/wtrmln/modules/controllers/pages.php index f29f478..efdcddd 100644 --- a/wtrmln/modules/controllers/pages.php +++ b/wtrmln/modules/controllers/pages.php @@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. class Pages extends Controller { - function Pages() + function __construct() { parent::Controller(); } diff --git a/wtrmln/modules/controllers/profile.php b/wtrmln/modules/controllers/profile.php index 64778f3..5b8ddbf 100644 --- a/wtrmln/modules/controllers/profile.php +++ b/wtrmln/modules/controllers/profile.php @@ -3,7 +3,7 @@ Watermelon CMS -Copyright 2008 Radosław Pietruszewski +Copyright 2008-2009 Radosław Pietruszewski This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -22,11 +22,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. class Profile extends Controller { - function Profile() + function __construct() { parent::Controller(); } - + function Index() { SetH1('Panel użytkownika'); -- 2.11.4.GIT