From c65359e4447fd7d38bc3a4fa212734a9c1f78aee Mon Sep 17 00:00:00 2001 From: Cameron Date: Mon, 2 Jun 2014 17:07:02 -0700 Subject: [PATCH] Removed Months and Days from language files. Replaced with strftime() functions. New 'terms' method added to Date handler. eg. e107::getDate()->terms('month'); returns an array of month names in the current language. --- e107_handlers/date_handler.php | 57 +++++++++++++++++++ e107_plugins/blogcalendar_menu/archive.php | 7 ++- .../blogcalendar_menu/blogcalendar_menu.php | 6 +- e107_plugins/blogcalendar_menu/calendar.php | 4 +- .../blogcalendar_menu/languages/English.php | 23 -------- e107_plugins/news/news_months_menu.php | 5 +- 6 files changed, 69 insertions(+), 33 deletions(-) diff --git a/e107_handlers/date_handler.php b/e107_handlers/date_handler.php index d754cceda..5b1a800fa 100644 --- a/e107_handlers/date_handler.php +++ b/e107_handlers/date_handler.php @@ -24,6 +24,63 @@ class convert } + + + /** + * Return an array of language terms representing months + * @param $type string : month, month-short, day, day-short, day-shortest + * @return array + * TODO Cache! + */ + public function terms($type='month') + { + if($type == 'month' || $type == 'month-short') + { + $val = ($type == 'month-short') ? '%b' : '%B'; //eg. 'Aug' / 'August' + $marray = array(); + for ($i=1; $i < 13; $i++) + { + $marray[] = strftime($val,mktime(1,1,1,$i,1,2000)); + } + + return $marray; + } + + if(substr($type,0,3) == 'day') + { + $days = array(); + for ($i=2; $i < 9; $i++) + { + switch ($type) + { + case 'day-shortest': // eg. 'Tu' + $days[] = substr(strftime('%a',mktime(1,1,1,6,$i,2014)),0,2); + break; + + case 'day-short': // eg. 'Tue' + $days[] = strftime('%a',mktime(1,1,1,6,$i,2014)); + break; + + default: // eg. 'Tuesday' + $days[] = strftime('%A',mktime(1,1,1,6,$i,2014)); + break; + } + } + + return $days; + } + + + + return false; + } + + + + + + + /** * Convert datestamp to human readable date. * System time offset is considered. diff --git a/e107_plugins/blogcalendar_menu/archive.php b/e107_plugins/blogcalendar_menu/archive.php index 4d12fc90a..94a7cda46 100644 --- a/e107_plugins/blogcalendar_menu/archive.php +++ b/e107_plugins/blogcalendar_menu/archive.php @@ -30,9 +30,10 @@ require_once(HEADERF); // --------------------- $bcSql = new db; $prefix = e_PLUGIN_ABS."blogcalendar_menu"; -$marray = array(BLOGCAL_M1, BLOGCAL_M2, BLOGCAL_M3, BLOGCAL_M4, - BLOGCAL_M5, BLOGCAL_M6, BLOGCAL_M7, BLOGCAL_M8, - BLOGCAL_M9, BLOGCAL_M10, BLOGCAL_M11, BLOGCAL_M12); +$marray = e107::getDate()->terms('month'); + + + // if nr of rows per month is not set, default to 3 $months_per_row = $pref['blogcal_mpr']?$pref['blogcal_mpr']: "3"; diff --git a/e107_plugins/blogcalendar_menu/blogcalendar_menu.php b/e107_plugins/blogcalendar_menu/blogcalendar_menu.php index 1f0f9c282..70fbd659a 100644 --- a/e107_plugins/blogcalendar_menu/blogcalendar_menu.php +++ b/e107_plugins/blogcalendar_menu/blogcalendar_menu.php @@ -34,7 +34,11 @@ if(false === $cached) // initialization + fetch options // ------------------------------ $prefix = e_PLUGIN_ABS."blogcalendar_menu"; - $marray = array(BLOGCAL_M1, BLOGCAL_M2, BLOGCAL_M3, BLOGCAL_M4, BLOGCAL_M5, BLOGCAL_M6, BLOGCAL_M7, BLOGCAL_M8, BLOGCAL_M9, BLOGCAL_M10, BLOGCAL_M11, BLOGCAL_M12); + $marray = e107::getDate()->terms('month'); + + + + $pref['blogcal_ws'] = "monday"; // ---------------------------------------------- diff --git a/e107_plugins/blogcalendar_menu/calendar.php b/e107_plugins/blogcalendar_menu/calendar.php index 3e8ac840b..34041a7e5 100644 --- a/e107_plugins/blogcalendar_menu/calendar.php +++ b/e107_plugins/blogcalendar_menu/calendar.php @@ -32,8 +32,8 @@ function calendar($req_day, $req_month, $req_year, $links = NULL, $ws = "sunday" $pref = e107::getPref(); // prepare the day array - $darray = array(BLOGCAL_D1, BLOGCAL_D2, BLOGCAL_D3, BLOGCAL_D4, BLOGCAL_D5, BLOGCAL_D6, BLOGCAL_D7); - $marray = array('',BLOGCAL_M1, BLOGCAL_M2, BLOGCAL_M3, BLOGCAL_M4, BLOGCAL_M5, BLOGCAL_M6, BLOGCAL_M7, BLOGCAL_M8, BLOGCAL_M9, BLOGCAL_M10, BLOGCAL_M11, BLOGCAL_M12); + $darray = e107::getDate()->terms('day-shortest'); + $marray = e107::getDate()->terms('month'); // what day does the week start on? switch($ws) diff --git a/e107_plugins/blogcalendar_menu/languages/English.php b/e107_plugins/blogcalendar_menu/languages/English.php index 7ee63695b..6d3ea4d5b 100644 --- a/e107_plugins/blogcalendar_menu/languages/English.php +++ b/e107_plugins/blogcalendar_menu/languages/English.php @@ -10,28 +10,6 @@ define("BLOGCAL_L1", "News by month"); define("BLOGCAL_L2", "Archive"); - -define("BLOGCAL_D1", "Mo"); -define("BLOGCAL_D2", "Tu"); -define("BLOGCAL_D3", "We"); -define("BLOGCAL_D4", "Th"); -define("BLOGCAL_D5", "Fr"); -define("BLOGCAL_D6", "Sa"); -define("BLOGCAL_D7", "Su"); - -define("BLOGCAL_M1", "January"); -define("BLOGCAL_M2", "February"); -define("BLOGCAL_M3", "March"); -define("BLOGCAL_M4", "April"); -define("BLOGCAL_M5", "May"); -define("BLOGCAL_M6", "June"); -define("BLOGCAL_M7", "July"); -define("BLOGCAL_M8", "August"); -define("BLOGCAL_M9", "September"); -define("BLOGCAL_M10", "October"); -define("BLOGCAL_M11", "November"); -define("BLOGCAL_M12", "December"); - define("BLOGCAL_1", "News Items"); define("BLOGCAL_CONF1", "Months/row"); @@ -39,7 +17,6 @@ define("BLOGCAL_CONF2", "Cellpadding"); //define("BLOGCAL_CONF3", "Update Menu Settings"); define("BLOGCAL_CONF4", "BlogCal Menu Configuration"); //define("BLOGCAL_CONF5", "BlogCal menu configuration saved"); - define("BLOGCAL_ARCHIV1", "Select Archive"); ?> \ No newline at end of file diff --git a/e107_plugins/news/news_months_menu.php b/e107_plugins/news/news_months_menu.php index 9f5218478..dd631ec72 100644 --- a/e107_plugins/news/news_months_menu.php +++ b/e107_plugins/news/news_months_menu.php @@ -33,10 +33,7 @@ if(false === $cached) $tp = e107::getParser(); $sql = e107::getDb(); - $marray = array(BLOGCAL_M1, BLOGCAL_M2, BLOGCAL_M3, BLOGCAL_M4, - BLOGCAL_M5, BLOGCAL_M6, BLOGCAL_M7, BLOGCAL_M8, - BLOGCAL_M9, BLOGCAL_M10, BLOGCAL_M11, BLOGCAL_M12); - + $marray = e107::getDate()->getTerms('month'); // TODO parms //$parms['year'] = "2011 0";