[geeklog-cvs] geeklog: New function COM_setLangIdAndAttribute to avoid code du...
geeklog-cvs at lists.geeklog.net
geeklog-cvs at lists.geeklog.net
Sun Nov 30 07:20:51 EST 2008
details: http://project.geeklog.net/cgi-bin/hgweb.cgi/rev/8dfc96e19331
changeset: 6488:8dfc96e19331
user: Dirk Haun <dirk at haun-online.de>
date: Sun Nov 30 13:04:17 2008 +0100
description:
New function COM_setLangIdAndAttribute to avoid code duplication setting the {lang_id} and {lang_attribute} variables
diffstat:
4 files changed, 66 insertions(+), 97 deletions(-)
plugins/staticpages/functions.inc | 3
public_html/admin/plugins/staticpages/install.php | 4
public_html/article.php | 47 ---------
public_html/lib-common.php | 109 +++++++++++----------
diffs (216 lines):
diff -r 63901185e583 -r 8dfc96e19331 plugins/staticpages/functions.inc
--- a/plugins/staticpages/functions.inc Sun Nov 30 09:23:40 2008 +0100
+++ b/plugins/staticpages/functions.inc Sun Nov 30 13:04:17 2008 +0100
@@ -409,8 +409,7 @@
$print->set_var('site_slogan', $_CONF['site_slogan']);
$print->set_var('direction', $LANG_DIRECTION);
- $print->set_var('lang_id', ''); // TBD
- $print->set_var('lang_attribute', ''); // TBD
+ COM_setLangIdAndAttribute($print);
$print->set_var('xhtml', XHTML);
$print->set_var('page_title', $_CONF['site_name'] . ' - '
. stripslashes($A['sp_title']));
diff -r 63901185e583 -r 8dfc96e19331 public_html/admin/plugins/staticpages/install.php
--- a/public_html/admin/plugins/staticpages/install.php Sun Nov 30 09:23:40 2008 +0100
+++ b/public_html/admin/plugins/staticpages/install.php Sun Nov 30 13:04:17 2008 +0100
@@ -94,6 +94,10 @@
}
if (!function_exists('COM_showMessageText')) {
+ return false;
+ }
+
+ if (!function_exists('COM_setLangIdAndAttribute')) {
return false;
}
diff -r 63901185e583 -r 8dfc96e19331 public_html/article.php
--- a/public_html/article.php Sun Nov 30 09:23:40 2008 +0100
+++ b/public_html/article.php Sun Nov 30 13:04:17 2008 +0100
@@ -191,51 +191,10 @@
$story_template->set_var ('lang_full_article', $LANG08[33]);
$story_template->set_var ('article_url', $articleUrl);
- $langAttr = '';
- if( !empty( $_CONF['languages'] ) && !empty( $_CONF['language_files'] ))
- {
- $langId = COM_getLanguageId();
- }
- else
- {
- // try to derive the language id from the locale
- $l = explode( '.', $_CONF['locale'] );
- $langId = $l[0];
- }
- if( !empty( $langId ))
- {
- $l = explode( '-', str_replace( '_', '-', $langId ));
- if(( count( $l ) == 1 ) && ( strlen( $langId ) == 2 ))
- {
- $langAttr = 'lang="' . $langId . '"';
- }
- else if( count( $l ) == 2 )
- {
- if(( $l[0] == 'i' ) || ( $l[0] == 'x' ))
- {
- $langId = implode( '-', $l );
- $langAttr = 'lang="' . $langId . '"';
- }
- else if( strlen( $l[0] ) == 2 )
- {
- $langId = implode( '-', $l );
- $langAttr = 'lang="' . $langId . '"';
- }
- else
- {
- $langId = $l[0];
- }
- }
- }
- $story_template->set_var('lang_id', $langId);
- if (!empty($_CONF['languages']) && !empty($_CONF['language_files'])) {
- $story_template->set_var('lang_attribute', $langAttr);
- } else {
- $story_template->set_var('lang_attribute', '');
- }
+ COM_setLangIdAndAttribute($story_template);
- $story_template->parse ('output', 'article');
- $display = $story_template->finish ($story_template->get_var('output'));
+ $story_template->parse('output', 'article');
+ $display = $story_template->finish($story_template->get_var('output'));
} else {
// Set page title
$pagetitle = $story->DisplayElements('title');
diff -r 63901185e583 -r 8dfc96e19331 public_html/lib-common.php
--- a/public_html/lib-common.php Sun Nov 30 09:23:40 2008 +0100
+++ b/public_html/lib-common.php Sun Nov 30 13:04:17 2008 +0100
@@ -1016,48 +1016,7 @@
}
$header->set_var('page_title_and_site_name', $title_and_name);
- $langAttr = '';
- if( !empty( $_CONF['languages'] ) && !empty( $_CONF['language_files'] ))
- {
- $langId = COM_getLanguageId();
- }
- else
- {
- // try to derive the language id from the locale
- $l = explode( '.', $_CONF['locale'] );
- $langId = $l[0];
- }
- if( !empty( $langId ))
- {
- $l = explode( '-', str_replace( '_', '-', $langId ));
- if(( count( $l ) == 1 ) && ( strlen( $langId ) == 2 ))
- {
- $langAttr = 'lang="' . $langId . '"';
- }
- else if( count( $l ) == 2 )
- {
- if(( $l[0] == 'i' ) || ( $l[0] == 'x' ))
- {
- $langId = implode( '-', $l );
- $langAttr = 'lang="' . $langId . '"';
- }
- else if( strlen( $l[0] ) == 2 )
- {
- $langId = implode( '-', $l );
- $langAttr = 'lang="' . $langId . '"';
- }
- else
- {
- $langId = $l[0];
- }
- }
- }
- $header->set_var('lang_id', $langId);
- if (!empty($_CONF['languages']) && !empty($_CONF['language_files'])) {
- $header->set_var('lang_attribute', $langAttr);
- } else {
- $header->set_var('lang_attribute', '');
- }
+ COM_setLangIdAndAttribute($header);
$header->set_var( 'background_image', $_CONF['layout_url']
. '/images/bg.' . $_IMAGE_TYPE );
@@ -6782,20 +6741,68 @@
return $wiki->transform($wikitext, 'Xhtml');
}
+/**
+* Set the {lang_id} and {lang_attribute} variables for a template
+*
+* @param ref $template template to use
+* @return void
+* @note {lang_attribute} is only set in multi-language environments.
+*
+*/
+function COM_setLangIdAndAttribute(&$template)
+{
+ global $_CONF;
+
+ $langAttr = '';
+ $langId = '';
+
+ if (!empty($_CONF['languages']) && !empty($_CONF['language_files'])) {
+ $langId = COM_getLanguageId();
+ } else {
+ // try to derive the language id from the locale
+ $l = explode('.', $_CONF['locale']); // get rid of character set
+ $langId = $l[0];
+ $l = explode('@', $langId); // get rid of '@euro', etc.
+ $langId = $l[0];
+ }
+
+ if (!empty($langId)) {
+ $l = explode('-', str_replace('_', '-', $langId));
+ if ((count($l) == 1) && (strlen($langId) == 2)) {
+ $langAttr = 'lang="' . $langId . '"';
+ } else if (count($l) == 2) {
+ if (($l[0] == 'i') || ($l[0] == 'x')) {
+ $langId = implode('-', $l);
+ $langAttr = 'lang="' . $langId . '"';
+ } else if (strlen($l[0]) == 2) {
+ $langId = implode('-', $l);
+ $langAttr = 'lang="' . $langId . '"';
+ } else {
+ $langId = $l[0];
+ // this isn't a valid lang attribute, so don't set $langAttr
+ }
+ }
+ }
+ $template->set_var('lang_id', $langId);
+
+ if (!empty($_CONF['languages']) && !empty($_CONF['language_files'])) {
+ $template->set_var('lang_attribute', $langAttr);
+ } else {
+ $template->set_var('lang_attribute', '');
+ }
+}
+
// Now include all plugin functions
-foreach( $_PLUGINS as $pi_name )
-{
- require_once( $_CONF['path'] . 'plugins/' . $pi_name . '/functions.inc' );
+foreach ($_PLUGINS as $pi_name) {
+ require_once $_CONF['path'] . 'plugins/' . $pi_name . '/functions.inc';
}
// Check and see if any plugins (or custom functions)
// have scheduled tasks to perform
-if( $_CONF['cron_schedule_interval'] > 0 )
-{
- if(( DB_getItem( $_TABLES['vars'], 'value', "name='last_scheduled_run'" )
- + $_CONF['cron_schedule_interval'] ) <= time())
- {
- DB_query( "UPDATE {$_TABLES['vars']} SET value=UNIX_TIMESTAMP() WHERE name='last_scheduled_run'" );
+if ($_CONF['cron_schedule_interval'] > 0) {
+ if ((DB_getItem($_TABLES['vars'], 'value', "name='last_scheduled_run'")
+ + $_CONF['cron_schedule_interval']) <= time()) {
+ DB_query("UPDATE {$_TABLES['vars']} SET value=UNIX_TIMESTAMP() WHERE name='last_scheduled_run'");
PLG_runScheduledTask();
}
}
More information about the geeklog-cvs
mailing list