summaryrefslogtreecommitdiff
path: root/inc/common.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/common.php')
-rw-r--r--inc/common.php88
1 files changed, 65 insertions, 23 deletions
diff --git a/inc/common.php b/inc/common.php
index 881179f4b..ac7ddd653 100644
--- a/inc/common.php
+++ b/inc/common.php
@@ -242,13 +242,16 @@ function buildURLparams($params, $sep='&'){
*/
function buildAttributes($params,$skipempty=false){
$url = '';
+ $white = false;
foreach($params as $key => $val){
if($key{0} == '_') continue;
if($val === '' && $skipempty) continue;
+ if($white) $url .= ' ';
$url .= $key.'="';
$url .= htmlspecialchars ($val);
- $url .= '" ';
+ $url .= '"';
+ $white = true;
}
return $url;
}
@@ -636,7 +639,7 @@ function clientIP($single=false){
// decide which IP to use, trying to avoid local addresses
$ip = array_reverse($ip);
foreach($ip as $i){
- if(preg_match('/^(127\.|10\.|192\.168\.|172\.((1[6-9])|(2[0-9])|(3[0-1]))\.)/',$i)){
+ if(preg_match('/^(::1|[fF][eE]80:|127\.|10\.|192\.168\.|172\.((1[6-9])|(2[0-9])|(3[0-1]))\.)/',$i)){
continue;
}else{
return $i;
@@ -801,7 +804,7 @@ function rawWiki($id,$rev=''){
/**
* Returns the pagetemplate contents for the ID's namespace
*
- * @triggers COMMON_PAGE_FROMTEMPLATE
+ * @triggers COMMON_PAGETPL_LOAD
* @author Andreas Gohr <andi@splitbrain.org>
*/
function pageTemplate($id){
@@ -809,29 +812,50 @@ function pageTemplate($id){
if (is_array($id)) $id = $id[0];
- $path = dirname(wikiFN($id));
- $tpl = '';
- if(@file_exists($path.'/_template.txt')){
- $tpl = io_readFile($path.'/_template.txt');
- }else{
- // search upper namespaces for templates
- $len = strlen(rtrim($conf['datadir'],'/'));
- while (strlen($path) >= $len){
- if(@file_exists($path.'/__template.txt')){
- $tpl = io_readFile($path.'/__template.txt');
- break;
+ // prepare initial event data
+ $data = array(
+ 'id' => $id, // the id of the page to be created
+ 'tpl' => '', // the text used as template
+ 'tplfile' => '', // the file above text was/should be loaded from
+ 'doreplace' => true // should wildcard replacements be done on the text?
+ );
+
+ $evt = new Doku_Event('COMMON_PAGETPL_LOAD',$data);
+ if($evt->advise_before(true)){
+ // the before event might have loaded the content already
+ if(empty($data['tpl'])){
+ // if the before event did not set a template file, try to find one
+ if(empty($data['tplfile'])){
+ $path = dirname(wikiFN($id));
+ $tpl = '';
+ if(@file_exists($path.'/_template.txt')){
+ $data['tplfile'] = $path.'/_template.txt';
+ }else{
+ // search upper namespaces for templates
+ $len = strlen(rtrim($conf['datadir'],'/'));
+ while (strlen($path) >= $len){
+ if(@file_exists($path.'/__template.txt')){
+ $data['tplfile'] = $path.'/__template.txt';
+ break;
+ }
+ $path = substr($path, 0, strrpos($path, '/'));
+ }
+ }
}
- $path = substr($path, 0, strrpos($path, '/'));
+ // load the content
+ $data['tpl'] = io_readFile($data['tplfile']);
}
+ if($data['doreplace']) parsePageTemplate(&$data);
}
- $data = compact('tpl', 'id');
- trigger_event('COMMON_PAGE_FROMTEMPLATE', $data, 'parsePageTemplate', true);
+ $evt->advise_after();
+ unset($evt);
+
return $data['tpl'];
}
/**
* Performs common page template replacements
- * This is the default action for COMMON_PAGE_FROMTEMPLATE
+ * This works on data from COMMON_PAGETPL_LOAD
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
@@ -1128,12 +1152,15 @@ function notify($id,$who,$rev='',$summary='',$minor=false,$replace=array()){
$diff = rawWiki($id);
}
$text = str_replace('@DIFF@',$diff,$text);
- if(utf8_strlen($conf['title']) < 20) {
- $subject = '['.$conf['title'].'] '.$subject;
+ if(empty($conf['mailprefix'])) {
+ if(utf8_strlen($conf['title']) < 20) {
+ $subject = '['.$conf['title'].'] '.$subject;
+ }else{
+ $subject = '['.utf8_substr($conf['title'], 0, 20).'...] '.$subject;
+ }
}else{
- $subject = '['.utf8_substr($conf['title'], 0, 20).'...] '.$subject;
+ $subject = '['.$conf['mailprefix'].'] '.$subject;
}
-
mail_send($to,$subject,$text,$conf['mailfrom'],'',$bcc);
}
@@ -1266,6 +1293,21 @@ function dformat($dt=null,$format=''){
}
/**
+ * Formats a timestamp as ISO 8601 date
+ *
+ * @author <ungu at terong dot com>
+ * @link http://www.php.net/manual/en/function.date.php#54072
+ */
+function date_iso8601($int_date) {
+ //$int_date: current date in UNIX timestamp
+ $date_mod = date('Y-m-d\TH:i:s', $int_date);
+ $pre_timezone = date('O', $int_date);
+ $time_zone = substr($pre_timezone, 0, 3).":".substr($pre_timezone, 3, 2);
+ $date_mod .= $time_zone;
+ return $date_mod;
+}
+
+/**
* return an obfuscated email address in line with $conf['mailguard'] setting
*
* @author Harry Fuecks <hfuecks@gmail.com>
@@ -1523,4 +1565,4 @@ function valid_input_set($param, $valid_values, $array, $exc = '') {
}
}
-//Setup VIM: ex: et ts=2 enc=utf-8 :
+//Setup VIM: ex: et ts=2 :