@@ -212,8 +212,10 @@ |
||
| 212 | 212 | */ |
| 213 | 213 | if ( file_exists(APP . 'Config' . DS . 'installed.txt') ) : |
| 214 | 214 | Configure::write('Saito.installed', TRUE); |
| 215 | -else : |
|
| 215 | +else { |
|
| 216 | + : |
|
| 216 | 217 | Configure::write('Saito.installed', FALSE); |
| 218 | +} |
|
| 217 | 219 | endif; |
| 218 | 220 | |
| 219 | 221 | /** |
@@ -305,8 +305,10 @@ |
||
| 305 | 305 | |
| 306 | 306 | if ($this->isLoggedIn()): |
| 307 | 307 | $this->_Controller->Auth->allow(); |
| 308 | - else: |
|
| 308 | + else { |
|
| 309 | + : |
|
| 309 | 310 | $this->_Controller->Auth->deny(); |
| 311 | + } |
|
| 310 | 312 | endif; |
| 311 | 313 | |
| 312 | 314 | $this->_Controller->Auth->autoRedirect = false; // don't redirect after Auth->login() |
@@ -89,8 +89,10 @@ discard block |
||
| 89 | 89 | $this->Session->setFlash(__('Error moving category.'), |
| 90 | 90 | 'flash/error'); |
| 91 | 91 | $failure = $failure || true; |
| 92 | - else: |
|
| 92 | + else { |
|
| 93 | + : |
|
| 93 | 94 | $this->Session->setFlash(__('Category moved.'), 'flash/notice'); |
| 95 | + } |
|
| 94 | 96 | endif; |
| 95 | 97 | endif; |
| 96 | 98 | |
@@ -99,8 +101,10 @@ discard block |
||
| 99 | 101 | $this->Session->setFlash(__("Error deleting category."), |
| 100 | 102 | 'flash/error'); |
| 101 | 103 | $failure = $failure || true; |
| 102 | - else: |
|
| 104 | + else { |
|
| 105 | + : |
|
| 103 | 106 | $this->Session->setFlash(__('Category deleted.'), 'flash/notice'); |
| 107 | + } |
|
| 104 | 108 | endif; |
| 105 | 109 | |
| 106 | 110 | if ($failure == false) : |
@@ -242,7 +242,8 @@ discard block |
||
| 242 | 242 | $this->_stop(); |
| 243 | 243 | } |
| 244 | 244 | // answering through POST request |
| 245 | - else : |
|
| 245 | + else { |
|
| 246 | + : |
|
| 246 | 247 | if ($this->localReferer('action') === 'mix') { |
| 247 | 248 | // answer request came from mix ansicht |
| 248 | 249 | $this->redirect( |
@@ -253,6 +254,7 @@ discard block |
||
| 253 | 254 | '#' => $this->Entry->id |
| 254 | 255 | ] |
| 255 | 256 | ); |
| 257 | + } |
|
| 256 | 258 | |
| 257 | 259 | } else { |
| 258 | 260 | // normal posting from entries/add or entries/view |
@@ -267,7 +269,8 @@ discard block |
||
| 267 | 269 | } |
| 268 | 270 | return; |
| 269 | 271 | endif; |
| 270 | - else : |
|
| 272 | + else { |
|
| 273 | + : |
|
| 271 | 274 | // Error while trying to save a post |
| 272 | 275 | if (count($this->Entry->validationErrors) === 0) { |
| 273 | 276 | $this->Session->setFlash( |
@@ -276,6 +279,7 @@ discard block |
||
| 276 | 279 | ), |
| 277 | 280 | 'flash/error' |
| 278 | 281 | ); |
| 282 | + } |
|
| 279 | 283 | } |
| 280 | 284 | endif; |
| 281 | 285 | |
@@ -584,10 +588,12 @@ discard block |
||
| 584 | 588 | ); |
| 585 | 589 | $entry = $this->dic->newInstance('\Saito\Posting\Posting', ['rawData' => $newEntry]); |
| 586 | 590 | $this->set('entry', $entry); |
| 587 | - else : |
|
| 591 | + else { |
|
| 592 | + : |
|
| 588 | 593 | // validation errors |
| 589 | 594 | foreach ($errors as $field => $error) { |
| 590 | 595 | $message = __d('nondynamic', $field) . ": " . __d( 'nondynamic', $error[0]); |
| 596 | + } |
|
| 591 | 597 | $this->JsData->addAppJsMessage( |
| 592 | 598 | $message, |
| 593 | 599 | [ |
@@ -69,8 +69,7 @@ discard block |
||
| 69 | 69 | return false; // we couldn't save the file, return false |
| 70 | 70 | } |
| 71 | 71 | unset($Model->data[$Model->alias][$this->options['fileVar']]); |
| 72 | - } |
|
| 73 | - else { |
|
| 72 | + } else { |
|
| 74 | 73 | unset($Model->data[$Model->alias]); |
| 75 | 74 | } |
| 76 | 75 | } |
@@ -88,13 +87,11 @@ discard block |
||
| 88 | 87 | if($this->Uploader->hasUpload()){ |
| 89 | 88 | if($this->Uploader->checkFile() && $this->Uploader->checkType() && $this->Uploader->checkSize()){ |
| 90 | 89 | $Model->beforeValidate(); |
| 91 | - } |
|
| 92 | - else { |
|
| 90 | + } else { |
|
| 93 | 91 | $Model->validationErrors[$this->options['fileVar']] = $this->Uploader->showErrors(); |
| 94 | 92 | } |
| 95 | 93 | } |
| 96 | - } |
|
| 97 | - elseif(isset($this->options['required']) && $this->options['required']){ |
|
| 94 | + } elseif(isset($this->options['required']) && $this->options['required']){ |
|
| 98 | 95 | $Model->validationErrors[$this->options['fileVar']] = 'No File'; |
| 99 | 96 | } |
| 100 | 97 | return $Model->beforeValidate(); |
@@ -72,12 +72,10 @@ discard block |
||
| 72 | 72 | $Model = ClassRegistry::init($this->options['fileModel']); |
| 73 | 73 | if(method_exists($Model, $this->options['fileNameFunction'])){ |
| 74 | 74 | $fileName = $Model->{$this->options['fileNameFunction']}($fileName); |
| 75 | - } |
|
| 76 | - elseif(function_exists($this->options['fileNameFunction'])){ |
|
| 75 | + } elseif(function_exists($this->options['fileNameFunction'])){ |
|
| 77 | 76 | $fileName = call_user_func($this->options['fileNameFunction'], $fileName); |
| 78 | 77 | } |
| 79 | - } |
|
| 80 | - else { |
|
| 78 | + } else { |
|
| 81 | 79 | if(function_exists($this->options['fileNameFunction'])){ |
| 82 | 80 | $fileName = call_user_func($this->options['fileNameFunction'], $fileName); |
| 83 | 81 | } |
@@ -140,8 +138,7 @@ discard block |
||
| 140 | 138 | if(move_uploaded_file($this->file['tmp_name'], $target_path)){ |
| 141 | 139 | $this->finalFile = basename($target_path); |
| 142 | 140 | return $this->finalFile; |
| 143 | - } |
|
| 144 | - else{ |
|
| 141 | + } else{ |
|
| 145 | 142 | $this->_error('Unable to save temp file to file system.'); |
| 146 | 143 | return false; |
| 147 | 144 | } |
@@ -154,7 +151,9 @@ discard block |
||
| 154 | 151 | * @return void |
| 155 | 152 | */ |
| 156 | 153 | function setFile($file = null){ |
| 157 | - if($file) $this->file = $file; |
|
| 154 | + if($file) { |
|
| 155 | + $this->file = $file; |
|
| 156 | + } |
|
| 158 | 157 | } |
| 159 | 158 | |
| 160 | 159 | /** |
@@ -203,8 +202,7 @@ discard block |
||
| 203 | 202 | if(is_array($types) && !in_array($this->file['type'], $types)){ |
| 204 | 203 | $this->_error("{$this->file['type']} is not an allowed type."); |
| 205 | 204 | return false; |
| 206 | - } |
|
| 207 | - else { |
|
| 205 | + } else { |
|
| 208 | 206 | return true; |
| 209 | 207 | } |
| 210 | 208 | } |
@@ -226,8 +224,7 @@ discard block |
||
| 226 | 224 | if($this->hasUpload() && $this->file){ |
| 227 | 225 | if(isset($this->file['error']) && $this->file['error'] == UPLOAD_ERR_OK ) { |
| 228 | 226 | return true; |
| 229 | - } |
|
| 230 | - else { |
|
| 227 | + } else { |
|
| 231 | 228 | $this->_error($this->uploadErrors[$this->file['error']]); |
| 232 | 229 | } |
| 233 | 230 | } |
@@ -246,11 +243,9 @@ discard block |
||
| 246 | 243 | if($this->hasUpload() && $this->file){ |
| 247 | 244 | if(!$this->options['maxFileSize']){ //We don't want to test maxFileSize |
| 248 | 245 | return true; |
| 249 | - } |
|
| 250 | - elseif($this->options['maxFileSize'] && $this->file['size'] < $this->options['maxFileSize']){ |
|
| 246 | + } elseif($this->options['maxFileSize'] && $this->file['size'] < $this->options['maxFileSize']){ |
|
| 251 | 247 | return true; |
| 252 | - } |
|
| 253 | - else { |
|
| 248 | + } else { |
|
| 254 | 249 | // $this->_error("File exceeds {$this->options['maxFileSize']} byte limit."); |
| 255 | 250 | $this->_error("File exceeds size limit."); |
| 256 | 251 | } |
@@ -115,8 +115,7 @@ discard block |
||
| 115 | 115 | $img = false; |
| 116 | 116 | if(is_string($name)){ |
| 117 | 117 | $img = $this->_getImageByName(); |
| 118 | - } |
|
| 119 | - elseif(is_int($name)){ |
|
| 118 | + } elseif(is_int($name)){ |
|
| 120 | 119 | $img = $this->_getImageById(); |
| 121 | 120 | } |
| 122 | 121 | |
@@ -145,8 +144,7 @@ discard block |
||
| 145 | 144 | unset($options['model'], $options['var']); |
| 146 | 145 | |
| 147 | 146 | return $this->Form->input("{$configs['model']}.".$this->inputCount++.".{$configs['var']}", array_merge(array('type'=>'file'), $options)); |
| 148 | - } |
|
| 149 | - else { |
|
| 147 | + } else { |
|
| 150 | 148 | return "<input type='file' name='data[{$configs['var']}][".$this->inputCount++."]' />"; |
| 151 | 149 | } |
| 152 | 150 | } |
@@ -166,8 +164,7 @@ discard block |
||
| 166 | 164 | if(!empty($upload)){ |
| 167 | 165 | $this->fileName = $upload[$this->settings['fileModel']][$this->settings['fields']['name']]; |
| 168 | 166 | return $this->_getImageByName(); |
| 169 | - } |
|
| 170 | - else{ |
|
| 167 | + } else{ |
|
| 171 | 168 | return false; |
| 172 | 169 | } |
| 173 | 170 | } |
@@ -180,8 +177,7 @@ discard block |
||
| 180 | 177 | function _getFullPath(){ |
| 181 | 178 | if($this->_isOutsideSource()){ |
| 182 | 179 | return $this->fileName; |
| 183 | - } |
|
| 184 | - else { |
|
| 180 | + } else { |
|
| 185 | 181 | return WWW_ROOT . $this->_getUploadPath(); |
| 186 | 182 | } |
| 187 | 183 | } |
@@ -194,8 +190,7 @@ discard block |
||
| 194 | 190 | function _getImagePath(){ |
| 195 | 191 | if($this->_isOutsideSource()){ |
| 196 | 192 | return $this->fileName; |
| 197 | - } |
|
| 198 | - else { |
|
| 193 | + } else { |
|
| 199 | 194 | return '/' . $this->_getUploadPath(); |
| 200 | 195 | } |
| 201 | 196 | } |
@@ -227,7 +222,9 @@ discard block |
||
| 227 | 222 | */ |
| 228 | 223 | function _getImageByName(){ |
| 229 | 224 | //only proceed if we actually have the file in question |
| 230 | - if(!$this->_isOutsideSource() && !file_exists($this->_getFullPath())) return false; |
|
| 225 | + if(!$this->_isOutsideSource() && !file_exists($this->_getFullPath())) { |
|
| 226 | + return false; |
|
| 227 | + } |
|
| 231 | 228 | |
| 232 | 229 | //resize if we have resize on, a width, and if it doesn't already exist. |
| 233 | 230 | if($this->options['autoResize'] && $this->options['width'] > 0 && !file_exists($this->_getResizeNameOrPath($this->_getFullPath()))){ |
@@ -257,8 +254,7 @@ discard block |
||
| 257 | 254 | $this->newImage = new RResizeImage($this->_getFullPath()); |
| 258 | 255 | if($this->newImage->imgWidth > $this->options['width']){ |
| 259 | 256 | $this->newImage->resize_limitwh($this->options['width'], 0, $this->_getResizeNameOrPath($this->_getFullPath())); |
| 260 | - } |
|
| 261 | - else { |
|
| 257 | + } else { |
|
| 262 | 258 | //$this->autoResize = false; |
| 263 | 259 | } |
| 264 | 260 | } |
@@ -272,12 +268,10 @@ discard block |
||
| 272 | 268 | if(!$this->_isOutsideSource() && $this->options['autoResize'] && $this->options['width'] > 0){ |
| 273 | 269 | if(isset($this->newImage) && $this->newImage->imgWidth && $this->newImage->imgWidth <= $this->options['width']){ |
| 274 | 270 | $image = $this->_getImagePath(); |
| 275 | - } |
|
| 276 | - else { |
|
| 271 | + } else { |
|
| 277 | 272 | $image = $this->_getResizeNameOrPath($this->_getImagePath()); |
| 278 | 273 | } |
| 279 | - } |
|
| 280 | - else { |
|
| 274 | + } else { |
|
| 281 | 275 | $image = $this->_getImagePath(); |
| 282 | 276 | } |
| 283 | 277 | |
@@ -285,13 +279,14 @@ discard block |
||
| 285 | 279 | //unset the default options |
| 286 | 280 | unset($options['resizedDir'], $options['uploadDir'], $options['imagePathOnly'], $options['autoResize'], $options['resizeThumbOnly']); |
| 287 | 281 | //unset width only if we're not an outsourced image, we have resize turned on, or we don't have a width to begin with. |
| 288 | - if(!$this->_isOutsideSource() && ($this->options['resizeThumbOnly'] || !$options['width'])) unset($options['width']); |
|
| 282 | + if(!$this->_isOutsideSource() && ($this->options['resizeThumbOnly'] || !$options['width'])) { |
|
| 283 | + unset($options['width']); |
|
| 284 | + } |
|
| 289 | 285 | |
| 290 | 286 | //return the impage path or image html |
| 291 | 287 | if($this->options['imagePathOnly']){ |
| 292 | 288 | return $image; |
| 293 | - } |
|
| 294 | - else { |
|
| 289 | + } else { |
|
| 295 | 290 | return $this->Html->image($image, $options); |
| 296 | 291 | } |
| 297 | 292 | } |
@@ -435,8 +430,12 @@ discard block |
||
| 435 | 430 | $this->_error="Could not resize given image"; |
| 436 | 431 | return false; |
| 437 | 432 | } |
| 438 | - if($width<=0) $width=$this->imgWidth; |
|
| 439 | - if($height<=0) $height=$this->imgHeight; |
|
| 433 | + if($width<=0) { |
|
| 434 | + $width=$this->imgWidth; |
|
| 435 | + } |
|
| 436 | + if($height<=0) { |
|
| 437 | + $height=$this->imgHeight; |
|
| 438 | + } |
|
| 440 | 439 | |
| 441 | 440 | return $this->_resize($width,$height,$newfile); |
| 442 | 441 | } |
@@ -461,11 +460,9 @@ discard block |
||
| 461 | 460 | $this->_getImageInfo(); |
| 462 | 461 | if($this->imgType=='GIF'){ |
| 463 | 462 | $this->_img=@imagecreatefromgif($this->imgFile); |
| 464 | - } |
|
| 465 | - elseif($this->imgType=='JPG'){ |
|
| 463 | + } elseif($this->imgType=='JPG'){ |
|
| 466 | 464 | $this->_img=@imagecreatefromjpeg($this->imgFile); |
| 467 | - } |
|
| 468 | - elseif($this->imgType=='PNG'){ |
|
| 465 | + } elseif($this->imgType=='PNG'){ |
|
| 469 | 466 | $this->_img=@imagecreatefrompng($this->imgFile); |
| 470 | 467 | } |
| 471 | 468 | |
@@ -497,7 +494,9 @@ discard block |
||
| 497 | 494 | if($this->imgType=='GIF' || $this->imgType=='PNG') { |
| 498 | 495 | /** Code to keep transparency of image **/ |
| 499 | 496 | $colorcount = imagecolorstotal($this->_img); |
| 500 | - if ($colorcount == 0) $colorcount = 256; |
|
| 497 | + if ($colorcount == 0) { |
|
| 498 | + $colorcount = 256; |
|
| 499 | + } |
|
| 501 | 500 | imagetruecolortopalette($newimg,true,$colorcount); |
| 502 | 501 | imagepalettecopy($newimg,$this->_img); |
| 503 | 502 | $transparentcolor = imagecolortransparent($this->_img); |
@@ -511,8 +510,7 @@ discard block |
||
| 511 | 510 | if(@preg_match("/\..*+$/",@basename($this->imgFile),$matches)){ |
| 512 | 511 | $newfile=@substr_replace($this->imgFile,"_har",-@strlen($matches[0]),0); |
| 513 | 512 | } |
| 514 | - } |
|
| 515 | - elseif(!empty($newfile)){ |
|
| 513 | + } elseif(!empty($newfile)){ |
|
| 516 | 514 | if(!@preg_match("/\..*+$/",@basename($newfile))){ |
| 517 | 515 | if(@preg_match("/\..*+$/",@basename($this->imgFile),$matches)){ |
| 518 | 516 | $newfile=$newfile.$matches[0]; |
@@ -523,26 +521,21 @@ discard block |
||
| 523 | 521 | if($this->imgType=='GIF'){ |
| 524 | 522 | if(!empty($newfile)){ |
| 525 | 523 | @imagegif($newimg,$newfile); |
| 526 | - } |
|
| 527 | - else { |
|
| 524 | + } else { |
|
| 528 | 525 | @header("Content-type: image/gif"); |
| 529 | 526 | @imagegif($newimg); |
| 530 | 527 | } |
| 531 | - } |
|
| 532 | - elseif($this->imgType=='JPG'){ |
|
| 528 | + } elseif($this->imgType=='JPG'){ |
|
| 533 | 529 | if(!empty($newfile)){ |
| 534 | 530 | @imagejpeg($newimg,$newfile); |
| 535 | - } |
|
| 536 | - else { |
|
| 531 | + } else { |
|
| 537 | 532 | @header("Content-type: image/jpeg"); |
| 538 | 533 | @imagejpeg($newimg); |
| 539 | 534 | } |
| 540 | - } |
|
| 541 | - elseif($this->imgType=='PNG'){ |
|
| 535 | + } elseif($this->imgType=='PNG'){ |
|
| 542 | 536 | if(!empty($newfile)){ |
| 543 | 537 | @imagepng($newimg,$newfile); |
| 544 | - } |
|
| 545 | - else{ |
|
| 538 | + } else{ |
|
| 546 | 539 | @header("Content-type: image/png"); |
| 547 | 540 | @imagepng($newimg); |
| 548 | 541 | } |
@@ -132,8 +132,7 @@ discard block |
||
| 132 | 132 | try { |
| 133 | 133 | @ConnectionManager::create('default', $config); |
| 134 | 134 | $db = ConnectionManager::getDataSource('default'); |
| 135 | - } |
|
| 136 | - catch (MissingConnectionException $e) { |
|
| 135 | + } catch (MissingConnectionException $e) { |
|
| 137 | 136 | $this->Session->setFlash(__('Could not connect to database: %s', $e->getMessage()), 'default', array('class' => 'error')); |
| 138 | 137 | $this->redirect(array('action' => 'database')); |
| 139 | 138 | } |
@@ -196,8 +195,7 @@ discard block |
||
| 196 | 195 | $create = $db->createSchema($schema, $table); |
| 197 | 196 | try { |
| 198 | 197 | $db->execute($create); |
| 199 | - } |
|
| 200 | - catch (PDOException $e) { |
|
| 198 | + } catch (PDOException $e) { |
|
| 201 | 199 | $this->Session->setFlash(__('Could not create table: %s', $e->getMessage()), 'default', array('class' => 'error')); |
| 202 | 200 | $this->redirect(array('action' => 'database')); |
| 203 | 201 | } |
@@ -193,8 +193,12 @@ discard block |
||
| 193 | 193 | # Fake Textile class. It calls Markdown instead. |
| 194 | 194 | class Textile { |
| 195 | 195 | function TextileThis($text, $lite='', $encode='') { |
| 196 | - if ($lite == '' && $encode == '') $text = Markdown($text); |
|
| 197 | - if (function_exists('SmartyPants')) $text = SmartyPants($text); |
|
| 196 | + if ($lite == '' && $encode == '') { |
|
| 197 | + $text = Markdown($text); |
|
| 198 | + } |
|
| 199 | + if (function_exists('SmartyPants')) { |
|
| 200 | + $text = SmartyPants($text); |
|
| 201 | + } |
|
| 198 | 202 | return $text; |
| 199 | 203 | } |
| 200 | 204 | # Fake restricted version: restrictions are not supported for now. |
@@ -387,7 +391,9 @@ discard block |
||
| 387 | 391 | |
| 388 | 392 | |
| 389 | 393 | function hashHTMLBlocks($text) { |
| 390 | - if ($this->no_markup) return $text; |
|
| 394 | + if ($this->no_markup) { |
|
| 395 | + return $text; |
|
| 396 | + } |
|
| 391 | 397 | |
| 392 | 398 | $less_than_tab = $this->tab_width - 1; |
| 393 | 399 | |
@@ -673,7 +679,9 @@ discard block |
||
| 673 | 679 | # |
| 674 | 680 | # Turn Markdown link shortcuts into XHTML <a> tags. |
| 675 | 681 | # |
| 676 | - if ($this->in_anchor) return $text; |
|
| 682 | + if ($this->in_anchor) { |
|
| 683 | + return $text; |
|
| 684 | + } |
|
| 677 | 685 | $this->in_anchor = true; |
| 678 | 686 | |
| 679 | 687 | # |
@@ -767,8 +775,7 @@ discard block |
||
| 767 | 775 | $link_text = $this->runSpanGamut($link_text); |
| 768 | 776 | $result .= ">$link_text</a>"; |
| 769 | 777 | $result = $this->hashPart($result); |
| 770 | - } |
|
| 771 | - else { |
|
| 778 | + } else { |
|
| 772 | 779 | $result = $whole_match; |
| 773 | 780 | } |
| 774 | 781 | return $result; |
@@ -869,8 +876,7 @@ discard block |
||
| 869 | 876 | } |
| 870 | 877 | $result .= $this->empty_element_suffix; |
| 871 | 878 | $result = $this->hashPart($result); |
| 872 | - } |
|
| 873 | - else { |
|
| 879 | + } else { |
|
| 874 | 880 | # If there's no such link ID, leave intact: |
| 875 | 881 | $result = $whole_match; |
| 876 | 882 | } |
@@ -928,8 +934,9 @@ discard block |
||
| 928 | 934 | } |
| 929 | 935 | function _doHeaders_callback_setext($matches) { |
| 930 | 936 | # Terrible hack to check we haven't found an empty list item. |
| 931 | - if ($matches[2] == '-' && preg_match('{^-(?: |$)}', $matches[1])) |
|
| 932 | - return $matches[0]; |
|
| 937 | + if ($matches[2] == '-' && preg_match('{^-(?: |$)}', $matches[1])) { |
|
| 938 | + return $matches[0]; |
|
| 939 | + } |
|
| 933 | 940 | |
| 934 | 941 | $level = $matches[2]{0} == '=' ? 1 : 2; |
| 935 | 942 | $block = "<h$level>".$this->runSpanGamut($matches[1])."</h$level>"; |
@@ -996,8 +1003,7 @@ discard block |
||
| 996 | 1003 | '.$whole_list_re.' |
| 997 | 1004 | }mx', |
| 998 | 1005 | array(&$this, '_doLists_callback'), $text); |
| 999 | - } |
|
| 1000 | - else { |
|
| 1006 | + } else { |
|
| 1001 | 1007 | $text = preg_replace_callback('{ |
| 1002 | 1008 | (?:(?<=\n)\n|\A\n?) # Must eat the newline |
| 1003 | 1009 | '.$whole_list_re.' |
@@ -1087,8 +1093,7 @@ discard block |
||
| 1087 | 1093 | # Replace marker with the appropriate whitespace indentation |
| 1088 | 1094 | $item = $leading_space . str_repeat(' ', strlen($marker_space)) . $item; |
| 1089 | 1095 | $item = $this->runBlockGamut($this->outdent($item)."\n"); |
| 1090 | - } |
|
| 1091 | - else { |
|
| 1096 | + } else { |
|
| 1092 | 1097 | # Recursion for sub-lists: |
| 1093 | 1098 | $item = $this->doLists($this->outdent($item)); |
| 1094 | 1099 | $item = preg_replace('/\n+$/', '', $item); |
@@ -1358,8 +1363,7 @@ discard block |
||
| 1358 | 1363 | $value = preg_replace('/^([ ]*)/', "<p>", $value); |
| 1359 | 1364 | $value .= "</p>"; |
| 1360 | 1365 | $grafs[$key] = $this->unhash($value); |
| 1361 | - } |
|
| 1362 | - else { |
|
| 1366 | + } else { |
|
| 1363 | 1367 | # Is a block. |
| 1364 | 1368 | # Modify elements of @grafs in-place... |
| 1365 | 1369 | $graf = $value; |
@@ -1507,8 +1511,11 @@ discard block |
||
| 1507 | 1511 | # roughly 10% raw, 45% hex, 45% dec |
| 1508 | 1512 | # '@' *must* be encoded. I insist. |
| 1509 | 1513 | if ($r > 90 && $char != '@') /* do nothing */; |
| 1510 | - else if ($r < 45) $chars[$key] = '&#x'.dechex($ord).';'; |
|
| 1511 | - else $chars[$key] = '&#'.$ord.';'; |
|
| 1514 | + else if ($r < 45) { |
|
| 1515 | + $chars[$key] = '&#x'.dechex($ord).';'; |
|
| 1516 | + } else { |
|
| 1517 | + $chars[$key] = '&#'.$ord.';'; |
|
| 1518 | + } |
|
| 1512 | 1519 | } |
| 1513 | 1520 | } |
| 1514 | 1521 | |
@@ -1566,8 +1573,7 @@ discard block |
||
| 1566 | 1573 | if (isset($parts[1])) { |
| 1567 | 1574 | $output .= $this->handleSpanToken($parts[1], $parts[2]); |
| 1568 | 1575 | $str = $parts[2]; |
| 1569 | - } |
|
| 1570 | - else { |
|
| 1576 | + } else { |
|
| 1571 | 1577 | break; |
| 1572 | 1578 | } |
| 1573 | 1579 | } |
@@ -1649,7 +1655,9 @@ discard block |
||
| 1649 | 1655 | # function that will loosely count the number of UTF-8 characters with a |
| 1650 | 1656 | # regular expression. |
| 1651 | 1657 | # |
| 1652 | - if (function_exists($this->utf8_strlen)) return; |
|
| 1658 | + if (function_exists($this->utf8_strlen)) { |
|
| 1659 | + return; |
|
| 1660 | + } |
|
| 1653 | 1661 | $this->utf8_strlen = create_function('$text', 'return preg_match_all( |
| 1654 | 1662 | "/[\\\\x00-\\\\xBF]|[\\\\xC0-\\\\xFF][\\\\x80-\\\\xBF]*/", |
| 1655 | 1663 | $text, $m);'); |
@@ -1744,8 +1752,9 @@ discard block |
||
| 1744 | 1752 | $this->footnote_counter = 1; |
| 1745 | 1753 | |
| 1746 | 1754 | foreach ($this->predef_abbr as $abbr_word => $abbr_desc) { |
| 1747 | - if ($this->abbr_word_re) |
|
| 1748 | - $this->abbr_word_re .= '|'; |
|
| 1755 | + if ($this->abbr_word_re) { |
|
| 1756 | + $this->abbr_word_re .= '|'; |
|
| 1757 | + } |
|
| 1749 | 1758 | $this->abbr_word_re .= preg_quote($abbr_word); |
| 1750 | 1759 | $this->abbr_desciptions[$abbr_word] = trim($abbr_desc); |
| 1751 | 1760 | } |
@@ -1834,7 +1843,9 @@ discard block |
||
| 1834 | 1843 | # |
| 1835 | 1844 | # Returns an array of that form: ( processed text , remaining text ) |
| 1836 | 1845 | # |
| 1837 | - if ($text === '') return array('', ''); |
|
| 1846 | + if ($text === '') { |
|
| 1847 | + return array('', ''); |
|
| 1848 | + } |
|
| 1838 | 1849 | |
| 1839 | 1850 | # Regex to check for the presense of newlines around a block tag. |
| 1840 | 1851 | $newline_before_re = '/(?:^\n?|\n\n)*$/'; |
@@ -1940,8 +1951,7 @@ discard block |
||
| 1940 | 1951 | # End marker found: pass text unchanged until marker. |
| 1941 | 1952 | $parsed .= $tag . $matches[0]; |
| 1942 | 1953 | $text = substr($text, strlen($matches[0])); |
| 1943 | - } |
|
| 1944 | - else { |
|
| 1954 | + } else { |
|
| 1945 | 1955 | # Unmatched marker: just skip it. |
| 1946 | 1956 | $parsed .= $tag; |
| 1947 | 1957 | } |
@@ -1966,8 +1976,7 @@ discard block |
||
| 1966 | 1976 | # End marker found: pass text unchanged until marker. |
| 1967 | 1977 | $parsed .= $tag . $matches[0]; |
| 1968 | 1978 | $text = substr($text, strlen($matches[0])); |
| 1969 | - } |
|
| 1970 | - else { |
|
| 1979 | + } else { |
|
| 1971 | 1980 | # No end marker: just skip it. |
| 1972 | 1981 | $parsed .= $tag; |
| 1973 | 1982 | } |
@@ -2014,8 +2023,11 @@ discard block |
||
| 2014 | 2023 | # |
| 2015 | 2024 | # Increase/decrease nested tag count. |
| 2016 | 2025 | # |
| 2017 | - if ($tag{1} == '/') $depth--; |
|
| 2018 | - else if ($tag{strlen($tag)-2} != '/') $depth++; |
|
| 2026 | + if ($tag{1} == '/') { |
|
| 2027 | + $depth--; |
|
| 2028 | + } else if ($tag{strlen($tag)-2} != '/') { |
|
| 2029 | + $depth++; |
|
| 2030 | + } |
|
| 2019 | 2031 | |
| 2020 | 2032 | if ($depth < 0) { |
| 2021 | 2033 | # |
@@ -2027,8 +2039,7 @@ discard block |
||
| 2027 | 2039 | } |
| 2028 | 2040 | |
| 2029 | 2041 | $parsed .= $tag; |
| 2030 | - } |
|
| 2031 | - else { |
|
| 2042 | + } else { |
|
| 2032 | 2043 | $parsed .= $tag; |
| 2033 | 2044 | } |
| 2034 | 2045 | } while ($depth >= 0); |
@@ -2046,7 +2057,9 @@ discard block |
||
| 2046 | 2057 | # |
| 2047 | 2058 | # Returns an array of that form: ( processed text , remaining text ) |
| 2048 | 2059 | # |
| 2049 | - if ($text === '') return array('', ''); |
|
| 2060 | + if ($text === '') { |
|
| 2061 | + return array('', ''); |
|
| 2062 | + } |
|
| 2050 | 2063 | |
| 2051 | 2064 | # Regex to match `markdown` attribute inside of a tag. |
| 2052 | 2065 | $markdown_attr_re = ' |
@@ -2097,8 +2110,9 @@ discard block |
||
| 2097 | 2110 | # Get the name of the starting tag. |
| 2098 | 2111 | # (This pattern makes $base_tag_name_re safe without quoting.) |
| 2099 | 2112 | # |
| 2100 | - if (preg_match('/^<([\w:$]*)\b/', $text, $matches)) |
|
| 2101 | - $base_tag_name_re = $matches[1]; |
|
| 2113 | + if (preg_match('/^<([\w:$]*)\b/', $text, $matches)) { |
|
| 2114 | + $base_tag_name_re = $matches[1]; |
|
| 2115 | + } |
|
| 2102 | 2116 | |
| 2103 | 2117 | # |
| 2104 | 2118 | # Loop through every tag until we find the corresponding closing tag. |
@@ -2135,15 +2149,17 @@ discard block |
||
| 2135 | 2149 | { |
| 2136 | 2150 | # Just add the tag to the block as if it was text. |
| 2137 | 2151 | $block_text .= $tag; |
| 2138 | - } |
|
| 2139 | - else { |
|
| 2152 | + } else { |
|
| 2140 | 2153 | # |
| 2141 | 2154 | # Increase/decrease nested tag count. Only do so if |
| 2142 | 2155 | # the tag's name match base tag's. |
| 2143 | 2156 | # |
| 2144 | 2157 | if (preg_match('{^</?'.$base_tag_name_re.'\b}', $tag)) { |
| 2145 | - if ($tag{1} == '/') $depth--; |
|
| 2146 | - else if ($tag{strlen($tag)-2} != '/') $depth++; |
|
| 2158 | + if ($tag{1} == '/') { |
|
| 2159 | + $depth--; |
|
| 2160 | + } else if ($tag{strlen($tag)-2} != '/') { |
|
| 2161 | + $depth++; |
|
| 2162 | + } |
|
| 2147 | 2163 | } |
| 2148 | 2164 | |
| 2149 | 2165 | # |
@@ -2190,13 +2206,17 @@ discard block |
||
| 2190 | 2206 | } |
| 2191 | 2207 | |
| 2192 | 2208 | # Append tag content to parsed text. |
| 2193 | - if (!$span_mode) $parsed .= "\n\n$block_text\n\n"; |
|
| 2194 | - else $parsed .= "$block_text"; |
|
| 2209 | + if (!$span_mode) { |
|
| 2210 | + $parsed .= "\n\n$block_text\n\n"; |
|
| 2211 | + } else { |
|
| 2212 | + $parsed .= "$block_text"; |
|
| 2213 | + } |
|
| 2195 | 2214 | |
| 2196 | 2215 | # Start over a new block. |
| 2197 | 2216 | $block_text = ""; |
| 2217 | + } else { |
|
| 2218 | + $block_text .= $tag; |
|
| 2198 | 2219 | } |
| 2199 | - else $block_text .= $tag; |
|
| 2200 | 2220 | } |
| 2201 | 2221 | |
| 2202 | 2222 | } while ($depth > 0); |
@@ -2261,12 +2281,15 @@ discard block |
||
| 2261 | 2281 | return $text; |
| 2262 | 2282 | } |
| 2263 | 2283 | function _doHeaders_attr($attr) { |
| 2264 | - if (empty($attr)) return ""; |
|
| 2284 | + if (empty($attr)) { |
|
| 2285 | + return ""; |
|
| 2286 | + } |
|
| 2265 | 2287 | return " id=\"$attr\""; |
| 2266 | 2288 | } |
| 2267 | 2289 | function _doHeaders_callback_setext($matches) { |
| 2268 | - if ($matches[3] == '-' && preg_match('{^- }', $matches[1])) |
|
| 2269 | - return $matches[0]; |
|
| 2290 | + if ($matches[3] == '-' && preg_match('{^- }', $matches[1])) { |
|
| 2291 | + return $matches[0]; |
|
| 2292 | + } |
|
| 2270 | 2293 | $level = $matches[3]{0} == '=' ? 1 : 2; |
| 2271 | 2294 | $attr = $this->_doHeaders_attr($id =& $matches[2]); |
| 2272 | 2295 | $block = "<h$level$attr>".$this->runSpanGamut($matches[1])."</h$level>"; |
@@ -2364,10 +2387,15 @@ discard block |
||
| 2364 | 2387 | # Reading alignement from header underline. |
| 2365 | 2388 | $separators = preg_split('/ *[|] */', $underline); |
| 2366 | 2389 | foreach ($separators as $n => $s) { |
| 2367 | - if (preg_match('/^ *-+: *$/', $s)) $attr[$n] = ' align="right"'; |
|
| 2368 | - else if (preg_match('/^ *:-+: *$/', $s))$attr[$n] = ' align="center"'; |
|
| 2369 | - else if (preg_match('/^ *:-+ *$/', $s)) $attr[$n] = ' align="left"'; |
|
| 2370 | - else $attr[$n] = ''; |
|
| 2390 | + if (preg_match('/^ *-+: *$/', $s)) { |
|
| 2391 | + $attr[$n] = ' align="right"'; |
|
| 2392 | + } else if (preg_match('/^ *:-+: *$/', $s)) { |
|
| 2393 | + $attr[$n] = ' align="center"'; |
|
| 2394 | + } else if (preg_match('/^ *:-+ *$/', $s)) { |
|
| 2395 | + $attr[$n] = ' align="left"'; |
|
| 2396 | + } else { |
|
| 2397 | + $attr[$n] = ''; |
|
| 2398 | + } |
|
| 2371 | 2399 | } |
| 2372 | 2400 | |
| 2373 | 2401 | # Parsing span elements, including code spans, character escapes, |
@@ -2380,8 +2408,9 @@ discard block |
||
| 2380 | 2408 | $text = "<table>\n"; |
| 2381 | 2409 | $text .= "<thead>\n"; |
| 2382 | 2410 | $text .= "<tr>\n"; |
| 2383 | - foreach ($headers as $n => $header) |
|
| 2384 | - $text .= " <th$attr[$n]>".$this->runSpanGamut(trim($header))."</th>\n"; |
|
| 2411 | + foreach ($headers as $n => $header) { |
|
| 2412 | + $text .= " <th$attr[$n]>".$this->runSpanGamut(trim($header))."</th>\n"; |
|
| 2413 | + } |
|
| 2385 | 2414 | $text .= "</tr>\n"; |
| 2386 | 2415 | $text .= "</thead>\n"; |
| 2387 | 2416 | |
@@ -2399,8 +2428,9 @@ discard block |
||
| 2399 | 2428 | $row_cells = array_pad($row_cells, $col_count, ''); |
| 2400 | 2429 | |
| 2401 | 2430 | $text .= "<tr>\n"; |
| 2402 | - foreach ($row_cells as $n => $cell) |
|
| 2403 | - $text .= " <td$attr[$n]>".$this->runSpanGamut(trim($cell))."</td>\n"; |
|
| 2431 | + foreach ($row_cells as $n => $cell) { |
|
| 2432 | + $text .= " <td$attr[$n]>".$this->runSpanGamut(trim($cell))."</td>\n"; |
|
| 2433 | + } |
|
| 2404 | 2434 | $text .= "</tr>\n"; |
| 2405 | 2435 | } |
| 2406 | 2436 | $text .= "</tbody>\n"; |
@@ -2526,8 +2556,7 @@ discard block |
||
| 2526 | 2556 | $def = str_repeat(' ', strlen($marker_space)) . $def; |
| 2527 | 2557 | $def = $this->runBlockGamut($this->outdent($def . "\n\n")); |
| 2528 | 2558 | $def = "\n". $def ."\n"; |
| 2529 | - } |
|
| 2530 | - else { |
|
| 2559 | + } else { |
|
| 2531 | 2560 | $def = rtrim($def); |
| 2532 | 2561 | $def = $this->runSpanGamut($this->outdent($def)); |
| 2533 | 2562 | } |
@@ -2801,8 +2830,9 @@ discard block |
||
| 2801 | 2830 | function _stripAbbreviations_callback($matches) { |
| 2802 | 2831 | $abbr_word = $matches[1]; |
| 2803 | 2832 | $abbr_desc = $matches[2]; |
| 2804 | - if ($this->abbr_word_re) |
|
| 2805 | - $this->abbr_word_re .= '|'; |
|
| 2833 | + if ($this->abbr_word_re) { |
|
| 2834 | + $this->abbr_word_re .= '|'; |
|
| 2835 | + } |
|
| 2806 | 2836 | $this->abbr_word_re .= preg_quote($abbr_word); |
| 2807 | 2837 | $this->abbr_desciptions[$abbr_word] = trim($abbr_desc); |
| 2808 | 2838 | return ''; # String that will replace the block |