From 7783971742e69fbd5ad26b0daf75bd4a3043aff0 Mon Sep 17 00:00:00 2001
From: Andreas Gohr <andi@splitbrain.org>
Date: Sat, 24 May 2014 13:59:49 +0200
Subject: [PATCH] more reformatting

---
 inc/parser/code.php     |  12 +-
 inc/parser/metadata.php | 286 ++++++++++++++++++++--------------------
 2 files changed, 152 insertions(+), 146 deletions(-)

diff --git a/inc/parser/code.php b/inc/parser/code.php
index d77ffd1aa..00b956c27 100644
--- a/inc/parser/code.php
+++ b/inc/parser/code.php
@@ -7,25 +7,25 @@
 if(!defined('DOKU_INC')) die('meh.');
 
 class Doku_Renderer_code extends Doku_Renderer {
-    var $_codeblock=0;
+    var $_codeblock = 0;
 
     /**
      * Send the wanted code block to the browser
      *
      * When the correct block was found it exits the script.
      */
-    function code($text, $language = null, $filename='' ) {
+    function code($text, $language = null, $filename = '') {
         global $INPUT;
         if(!$language) $language = 'txt';
         if(!$filename) $filename = 'snippet.'.$language;
         $filename = utf8_basename($filename);
         $filename = utf8_stripspecials($filename, '_');
 
-        if($this->_codeblock == $INPUT->str('codeblock')){
+        if($this->_codeblock == $INPUT->str('codeblock')) {
             header("Content-Type: text/plain; charset=utf-8");
             header("Content-Disposition: attachment; filename=$filename");
             header("X-Robots-Tag: noindex");
-            echo trim($text,"\r\n");
+            echo trim($text, "\r\n");
             exit;
         }
 
@@ -35,7 +35,7 @@ class Doku_Renderer_code extends Doku_Renderer {
     /**
      * Wraps around code()
      */
-    function file($text, $language = null, $filename='') {
+    function file($text, $language = null, $filename = '') {
         $this->code($text, $language, $filename);
     }
 
@@ -53,7 +53,7 @@ class Doku_Renderer_code extends Doku_Renderer {
      *
      * @returns string 'code'
      */
-    function getFormat(){
+    function getFormat() {
         return 'code';
     }
 }
diff --git a/inc/parser/metadata.php b/inc/parser/metadata.php
index 82a268fd6..e19aa602a 100644
--- a/inc/parser/metadata.php
+++ b/inc/parser/metadata.php
@@ -6,14 +6,14 @@
  */
 if(!defined('DOKU_INC')) die('meh.');
 
-if ( !defined('DOKU_LF') ) {
+if(!defined('DOKU_LF')) {
     // Some whitespace to help View > Source
-    define ('DOKU_LF',"\n");
+    define ('DOKU_LF', "\n");
 }
 
-if ( !defined('DOKU_TAB') ) {
+if(!defined('DOKU_TAB')) {
     // Some whitespace to help View > Source
-    define ('DOKU_TAB',"\t");
+    define ('DOKU_TAB', "\t");
 }
 
 /**
@@ -21,55 +21,55 @@ if ( !defined('DOKU_TAB') ) {
  */
 class Doku_Renderer_metadata extends Doku_Renderer {
 
-    var $doc  = '';
+    var $doc = '';
     var $meta = array();
     var $persistent = array();
 
     var $headers = array();
     var $capture = true;
-    var $store   = '';
+    var $store = '';
     var $firstimage = '';
 
-    function getFormat(){
+    function getFormat() {
         return 'metadata';
     }
 
-    function document_start(){
+    function document_start() {
         global $ID;
 
         $this->headers = array();
 
         // external pages are missing create date
-        if(!$this->persistent['date']['created']){
+        if(!$this->persistent['date']['created']) {
             $this->persistent['date']['created'] = filectime(wikiFN($ID));
         }
-        if(!isset($this->persistent['user'])){
+        if(!isset($this->persistent['user'])) {
             $this->persistent['user'] = '';
         }
-        if(!isset($this->persistent['creator'])){
+        if(!isset($this->persistent['creator'])) {
             $this->persistent['creator'] = '';
         }
         // reset metadata to persistent values
         $this->meta = $this->persistent;
     }
 
-    function document_end(){
+    function document_end() {
         global $ID;
 
         // store internal info in metadata (notoc,nocache)
         $this->meta['internal'] = $this->info;
 
-        if (!isset($this->meta['description']['abstract'])){
+        if(!isset($this->meta['description']['abstract'])) {
             // cut off too long abstracts
             $this->doc = trim($this->doc);
-            if (strlen($this->doc) > 500)
+            if(strlen($this->doc) > 500)
                 $this->doc = utf8_substr($this->doc, 0, 500).'…';
             $this->meta['description']['abstract'] = $this->doc;
         }
 
         $this->meta['relation']['firstimage'] = $this->firstimage;
 
-        if(!isset($this->meta['date']['modified'])){
+        if(!isset($this->meta['date']['modified'])) {
             $this->meta['date']['modified'] = filemtime(wikiFN($ID));
         }
 
@@ -79,54 +79,57 @@ class Doku_Renderer_metadata extends Doku_Renderer {
         global $conf;
 
         //only add items within configured levels
-        if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){
+        if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']) {
             // the TOC is one of our standard ul list arrays ;-)
             $this->meta['description']['tableofcontents'][] = array(
-              'hid'   => $id,
-              'title' => $text,
-              'type'  => 'ul',
-              'level' => $level-$conf['toptoclevel']+1
+                'hid'   => $id,
+                'title' => $text,
+                'type'  => 'ul',
+                'level' => $level - $conf['toptoclevel'] + 1
             );
         }
 
     }
 
     function header($text, $level, $pos) {
-        if (!isset($this->meta['title'])) $this->meta['title'] = $text;
+        if(!isset($this->meta['title'])) $this->meta['title'] = $text;
 
         // add the header to the TOC
-        $hid = $this->_headerToLink($text,'true');
+        $hid = $this->_headerToLink($text, 'true');
         $this->toc_additem($hid, $text, $level);
 
         // add to summary
-        if ($this->capture && ($level > 1)) $this->doc .= DOKU_LF.$text.DOKU_LF;
+        if($this->capture && ($level > 1)) $this->doc .= DOKU_LF.$text.DOKU_LF;
     }
 
-    function section_open($level){}
-    function section_close(){}
+    function section_open($level) {
+    }
+
+    function section_close() {
+    }
 
-    function cdata($text){
-      if ($this->capture) $this->doc .= $text;
+    function cdata($text) {
+        if($this->capture) $this->doc .= $text;
     }
 
-    function p_open(){
-      if ($this->capture) $this->doc .= DOKU_LF;
+    function p_open() {
+        if($this->capture) $this->doc .= DOKU_LF;
     }
 
-    function p_close(){
-        if ($this->capture){
-            if (strlen($this->doc) > 250) $this->capture = false;
+    function p_close() {
+        if($this->capture) {
+            if(strlen($this->doc) > 250) $this->capture = false;
             else $this->doc .= DOKU_LF;
         }
     }
 
-    function linebreak(){
-        if ($this->capture) $this->doc .= DOKU_LF;
+    function linebreak() {
+        if($this->capture) $this->doc .= DOKU_LF;
     }
 
-    function hr(){
-        if ($this->capture){
-            if (strlen($this->doc) > 250) $this->capture = false;
+    function hr() {
+        if($this->capture) {
+            if(strlen($this->doc) > 250) $this->capture = false;
             else $this->doc .= DOKU_LF.'----------'.DOKU_LF;
         }
     }
@@ -141,7 +144,7 @@ class Doku_Renderer_metadata extends Doku_Renderer {
      * @author Andreas Gohr <andi@splitbrain.org>
      */
     function footnote_open() {
-        if ($this->capture){
+        if($this->capture) {
             // move current content to store and record footnote
             $this->store = $this->doc;
             $this->doc   = '';
@@ -157,141 +160,144 @@ class Doku_Renderer_metadata extends Doku_Renderer {
      * @author Andreas Gohr
      */
     function footnote_close() {
-        if ($this->capture){
+        if($this->capture) {
             // restore old content
-            $this->doc = $this->store;
+            $this->doc   = $this->store;
             $this->store = '';
         }
     }
 
-    function listu_open(){
-        if ($this->capture) $this->doc .= DOKU_LF;
+    function listu_open() {
+        if($this->capture) $this->doc .= DOKU_LF;
     }
 
-    function listu_close(){
-        if ($this->capture && (strlen($this->doc) > 250)) $this->capture = false;
+    function listu_close() {
+        if($this->capture && (strlen($this->doc) > 250)) $this->capture = false;
     }
 
-    function listo_open(){
-        if ($this->capture) $this->doc .= DOKU_LF;
+    function listo_open() {
+        if($this->capture) $this->doc .= DOKU_LF;
     }
 
-    function listo_close(){
-        if ($this->capture && (strlen($this->doc) > 250)) $this->capture = false;
+    function listo_close() {
+        if($this->capture && (strlen($this->doc) > 250)) $this->capture = false;
     }
 
-    function listitem_open($level){
-        if ($this->capture) $this->doc .= str_repeat(DOKU_TAB, $level).'* ';
+    function listitem_open($level) {
+        if($this->capture) $this->doc .= str_repeat(DOKU_TAB, $level).'* ';
     }
 
-    function listitem_close(){
-        if ($this->capture) $this->doc .= DOKU_LF;
+    function listitem_close() {
+        if($this->capture) $this->doc .= DOKU_LF;
     }
 
-    function listcontent_open(){}
-    function listcontent_close(){}
+    function listcontent_open() {
+    }
 
-    function unformatted($text){
-        if ($this->capture) $this->doc .= $text;
+    function listcontent_close() {
     }
 
-    function preformatted($text){
-        if ($this->capture) $this->doc .= $text;
+    function unformatted($text) {
+        if($this->capture) $this->doc .= $text;
     }
 
-    function file($text, $lang = null, $file = null){
-        if ($this->capture){
+    function preformatted($text) {
+        if($this->capture) $this->doc .= $text;
+    }
+
+    function file($text, $lang = null, $file = null) {
+        if($this->capture) {
             $this->doc .= DOKU_LF.$text;
-            if (strlen($this->doc) > 250) $this->capture = false;
+            if(strlen($this->doc) > 250) $this->capture = false;
             else $this->doc .= DOKU_LF;
         }
     }
 
-    function quote_open(){
-        if ($this->capture) $this->doc .= DOKU_LF.DOKU_TAB.'"';
+    function quote_open() {
+        if($this->capture) $this->doc .= DOKU_LF.DOKU_TAB.'"';
     }
 
-    function quote_close(){
-        if ($this->capture){
+    function quote_close() {
+        if($this->capture) {
             $this->doc .= '"';
-            if (strlen($this->doc) > 250) $this->capture = false;
+            if(strlen($this->doc) > 250) $this->capture = false;
             else $this->doc .= DOKU_LF;
         }
     }
 
-    function code($text, $language = null, $file = null){
-        if ($this->capture){
+    function code($text, $language = null, $file = null) {
+        if($this->capture) {
             $this->doc .= DOKU_LF.$text;
-            if (strlen($this->doc) > 250) $this->capture = false;
+            if(strlen($this->doc) > 250) $this->capture = false;
             else $this->doc .= DOKU_LF;
-      }
+        }
     }
 
-    function acronym($acronym){
-        if ($this->capture) $this->doc .= $acronym;
+    function acronym($acronym) {
+        if($this->capture) $this->doc .= $acronym;
     }
 
-    function smiley($smiley){
-        if ($this->capture) $this->doc .= $smiley;
+    function smiley($smiley) {
+        if($this->capture) $this->doc .= $smiley;
     }
 
-    function entity($entity){
-        if ($this->capture) $this->doc .= $entity;
+    function entity($entity) {
+        if($this->capture) $this->doc .= $entity;
     }
 
-    function multiplyentity($x, $y){
-        if ($this->capture) $this->doc .= $x.'×'.$y;
+    function multiplyentity($x, $y) {
+        if($this->capture) $this->doc .= $x.'×'.$y;
     }
 
-    function singlequoteopening(){
+    function singlequoteopening() {
         global $lang;
-        if ($this->capture) $this->doc .= $lang['singlequoteopening'];
+        if($this->capture) $this->doc .= $lang['singlequoteopening'];
     }
 
-    function singlequoteclosing(){
+    function singlequoteclosing() {
         global $lang;
-        if ($this->capture) $this->doc .= $lang['singlequoteclosing'];
+        if($this->capture) $this->doc .= $lang['singlequoteclosing'];
     }
 
     function apostrophe() {
         global $lang;
-        if ($this->capture) $this->doc .= $lang['apostrophe'];
+        if($this->capture) $this->doc .= $lang['apostrophe'];
     }
 
-    function doublequoteopening(){
+    function doublequoteopening() {
         global $lang;
-        if ($this->capture) $this->doc .= $lang['doublequoteopening'];
+        if($this->capture) $this->doc .= $lang['doublequoteopening'];
     }
 
-    function doublequoteclosing(){
+    function doublequoteclosing() {
         global $lang;
-        if ($this->capture) $this->doc .= $lang['doublequoteclosing'];
+        if($this->capture) $this->doc .= $lang['doublequoteclosing'];
     }
 
     function camelcaselink($link) {
         $this->internallink($link, $link);
     }
 
-    function locallink($hash, $name = null){
+    function locallink($hash, $name = null) {
         if(is_array($name)) {
             $this->_firstimage($name['src']);
-            if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']);
+            if($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']);
         }
     }
 
     /**
      * keep track of internal links in $this->meta['relation']['references']
      */
-    function internallink($id, $name = null){
+    function internallink($id, $name = null) {
         global $ID;
 
         if(is_array($name)) {
             $this->_firstimage($name['src']);
-            if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']);
+            if($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']);
         }
 
         $parts = explode('?', $id, 2);
-        if (count($parts) === 2) {
+        if(count($parts) === 2) {
             $id = $parts[0];
         }
 
@@ -307,80 +313,80 @@ class Doku_Renderer_metadata extends Doku_Renderer {
         // p_set_metadata($id, $data);
 
         // add link title to summary
-        if ($this->capture){
+        if($this->capture) {
             $name = $this->_getLinkTitle($name, $default, $id);
             $this->doc .= $name;
         }
     }
 
-    function externallink($url, $name = null){
+    function externallink($url, $name = null) {
         if(is_array($name)) {
             $this->_firstimage($name['src']);
-            if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']);
+            if($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']);
         }
 
-        if ($this->capture){
-            $this->doc .= $this->_getLinkTitle($name, '<' . $url . '>');
+        if($this->capture) {
+            $this->doc .= $this->_getLinkTitle($name, '<'.$url.'>');
         }
     }
 
-    function interwikilink($match, $name = null, $wikiName, $wikiUri){
+    function interwikilink($match, $name = null, $wikiName, $wikiUri) {
         if(is_array($name)) {
             $this->_firstimage($name['src']);
-            if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']);
+            if($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']);
         }
 
-        if ($this->capture){
+        if($this->capture) {
             list($wikiUri, $hash) = explode('#', $wikiUri, 2);
             $name = $this->_getLinkTitle($name, $wikiUri);
             $this->doc .= $name;
         }
     }
 
-    function windowssharelink($url, $name = null){
+    function windowssharelink($url, $name = null) {
         if(is_array($name)) {
             $this->_firstimage($name['src']);
-            if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']);
+            if($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']);
         }
 
-        if ($this->capture){
-            if ($name) $this->doc .= $name;
+        if($this->capture) {
+            if($name) $this->doc .= $name;
             else $this->doc .= '<'.$url.'>';
         }
     }
 
-    function emaillink($address, $name = null){
+    function emaillink($address, $name = null) {
         if(is_array($name)) {
             $this->_firstimage($name['src']);
-            if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']);
+            if($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']);
         }
 
-        if ($this->capture){
-            if ($name) $this->doc .= $name;
+        if($this->capture) {
+            if($name) $this->doc .= $name;
             else $this->doc .= '<'.$address.'>';
         }
     }
 
-    function internalmedia($src, $title=null, $align=null, $width=null,
-                           $height=null, $cache=null, $linking=null){
-        if ($this->capture && $title) $this->doc .= '['.$title.']';
+    function internalmedia($src, $title = null, $align = null, $width = null,
+                           $height = null, $cache = null, $linking = null) {
+        if($this->capture && $title) $this->doc .= '['.$title.']';
         $this->_firstimage($src);
         $this->_recordMediaUsage($src);
     }
 
-    function externalmedia($src, $title=null, $align=null, $width=null,
-                           $height=null, $cache=null, $linking=null){
-        if ($this->capture && $title) $this->doc .= '['.$title.']';
+    function externalmedia($src, $title = null, $align = null, $width = null,
+                           $height = null, $cache = null, $linking = null) {
+        if($this->capture && $title) $this->doc .= '['.$title.']';
         $this->_firstimage($src);
     }
 
-    function rss($url,$params) {
+    function rss($url, $params) {
         $this->meta['relation']['haspart'][$url] = true;
 
         $this->meta['date']['valid']['age'] =
-              isset($this->meta['date']['valid']['age']) ?
-                  min($this->meta['date']['valid']['age'],$params['refresh']) :
-                  $params['refresh'];
+            isset($this->meta['date']['valid']['age']) ?
+                min($this->meta['date']['valid']['age'], $params['refresh']) :
+                $params['refresh'];
     }
 
     //----------------------------------------------------------
@@ -392,19 +398,19 @@ class Doku_Renderer_metadata extends Doku_Renderer {
      *
      * @author Andreas Gohr <andi@splitbrain.org>
      */
-    function _simpleTitle($name){
+    function _simpleTitle($name) {
         global $conf;
 
         if(is_array($name)) return '';
 
-        if($conf['useslash']){
+        if($conf['useslash']) {
             $nssep = '[:;/]';
-        }else{
+        } else {
             $nssep = '[:;]';
         }
-        $name = preg_replace('!.*'.$nssep.'!','',$name);
+        $name = preg_replace('!.*'.$nssep.'!', '', $name);
         //if there is a hash we use the anchor name only
-        $name = preg_replace('!.*#!','',$name);
+        $name = preg_replace('!.*#!', '', $name);
         return $name;
     }
 
@@ -415,12 +421,12 @@ class Doku_Renderer_metadata extends Doku_Renderer {
      * @param boolean $create  Create a new unique ID?
      * @author Andreas Gohr <andi@splitbrain.org>
      */
-    function _headerToLink($title, $create=false) {
-        if($create){
-            return sectionID($title,$this->headers);
-        }else{
+    function _headerToLink($title, $create = false) {
+        if($create) {
+            return sectionID($title, $this->headers);
+        } else {
             $check = false;
-            return sectionID($title,$check);
+            return sectionID($title, $check);
         }
     }
 
@@ -429,16 +435,16 @@ class Doku_Renderer_metadata extends Doku_Renderer {
      *
      * @author Harry Fuecks <hfuecks@gmail.com>
      */
-    function _getLinkTitle($title, $default, $id=null) {
+    function _getLinkTitle($title, $default, $id = null) {
         global $conf;
 
         $isImage = false;
-        if (is_array($title)){
+        if(is_array($title)) {
             if($title['title']) return '['.$title['title'].']';
-        } else if (is_null($title) || trim($title)==''){
-            if (useHeading('content') && $id){
-                $heading = p_get_first_heading($id,METADATA_DONT_RENDER);
-                if ($heading) return $heading;
+        } else if(is_null($title) || trim($title) == '') {
+            if(useHeading('content') && $id) {
+                $heading = p_get_first_heading($id, METADATA_DONT_RENDER);
+                if($heading) return $heading;
             }
             return $default;
         } else {
@@ -446,15 +452,15 @@ class Doku_Renderer_metadata extends Doku_Renderer {
         }
     }
 
-    function _firstimage($src){
+    function _firstimage($src) {
         if($this->firstimage) return;
         global $ID;
 
-        list($src,$hash) = explode('#',$src,2);
-        if(!media_isexternal($src)){
-            resolve_mediaid(getNS($ID),$src, $exists);
+        list($src, $hash) = explode('#', $src, 2);
+        if(!media_isexternal($src)) {
+            resolve_mediaid(getNS($ID), $src, $exists);
         }
-        if(preg_match('/.(jpe?g|gif|png)$/i',$src)){
+        if(preg_match('/.(jpe?g|gif|png)$/i', $src)) {
             $this->firstimage = $src;
         }
     }
@@ -463,7 +469,7 @@ class Doku_Renderer_metadata extends Doku_Renderer {
         global $ID;
 
         list ($src, $hash) = explode('#', $src, 2);
-        if (media_isexternal($src)) return;
+        if(media_isexternal($src)) return;
         resolve_mediaid(getNS($ID), $src, $exists);
         $this->meta['relation']['media'][$src] = $exists;
     }
-- 
GitLab