@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | /** |
| 12 | 12 | * Custom exception handler. |
| 13 | 13 | */ |
| 14 | -set_exception_handler(function ($exception) { |
|
| 14 | +set_exception_handler(function($exception) { |
|
| 15 | 15 | errorPage( |
| 16 | 16 | "<p><b>img.php: Uncaught exception:</b> <p>" |
| 17 | 17 | . $exception->getMessage() |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * Get configuration options from file, if the file exists, else use $config |
| 29 | 29 | * if its defined or create an empty $config. |
| 30 | 30 | */ |
| 31 | -$configFile = __DIR__.'/'.basename(__FILE__, '.php').'_config.php'; |
|
| 31 | +$configFile = __DIR__ . '/' . basename(__FILE__, '.php') . '_config.php'; |
|
| 32 | 32 | |
| 33 | 33 | if (is_file($configFile)) { |
| 34 | 34 | $config = require $configFile; |
@@ -47,11 +47,11 @@ discard block |
||
| 47 | 47 | * Setup the autoloader, but not when using a bundle. |
| 48 | 48 | */ |
| 49 | 49 | if (!defined("CIMAGE_BUNDLE")) { |
| 50 | - if (!isset($config["autoloader"])) { |
|
| 50 | + if (!isset($config[ "autoloader" ])) { |
|
| 51 | 51 | die("CImage: Missing autoloader."); |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - require $config["autoloader"]; |
|
| 54 | + require $config[ "autoloader" ]; |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | // Specific settings for each mode |
| 91 | -if ($mode == 'strict') { |
|
| 91 | +if ($mode=='strict') { |
|
| 92 | 92 | |
| 93 | 93 | error_reporting(0); |
| 94 | 94 | ini_set('display_errors', 0); |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | $status = false; |
| 98 | 98 | $verboseFile = false; |
| 99 | 99 | |
| 100 | -} elseif ($mode == 'production') { |
|
| 100 | +} elseif ($mode=='production') { |
|
| 101 | 101 | |
| 102 | 102 | error_reporting(-1); |
| 103 | 103 | ini_set('display_errors', 0); |
@@ -106,14 +106,14 @@ discard block |
||
| 106 | 106 | $status = false; |
| 107 | 107 | $verboseFile = false; |
| 108 | 108 | |
| 109 | -} elseif ($mode == 'development') { |
|
| 109 | +} elseif ($mode=='development') { |
|
| 110 | 110 | |
| 111 | 111 | error_reporting(-1); |
| 112 | 112 | ini_set('display_errors', 1); |
| 113 | 113 | ini_set('log_errors', 0); |
| 114 | 114 | $verboseFile = false; |
| 115 | 115 | |
| 116 | -} elseif ($mode == 'test') { |
|
| 116 | +} elseif ($mode=='test') { |
|
| 117 | 117 | |
| 118 | 118 | error_reporting(-1); |
| 119 | 119 | ini_set('display_errors', 1); |
@@ -155,20 +155,20 @@ discard block |
||
| 155 | 155 | if ($pwd) { |
| 156 | 156 | switch ($pwdType) { |
| 157 | 157 | case 'md5': |
| 158 | - $passwordMatch = ($pwdConfig === md5($pwd)); |
|
| 158 | + $passwordMatch = ($pwdConfig===md5($pwd)); |
|
| 159 | 159 | break; |
| 160 | 160 | case 'hash': |
| 161 | 161 | $passwordMatch = password_verify($pwd, $pwdConfig); |
| 162 | 162 | break; |
| 163 | 163 | case 'text': |
| 164 | - $passwordMatch = ($pwdConfig === $pwd); |
|
| 164 | + $passwordMatch = ($pwdConfig===$pwd); |
|
| 165 | 165 | break; |
| 166 | 166 | default: |
| 167 | 167 | $passwordMatch = false; |
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | -if ($pwdAlways && $passwordMatch !== true) { |
|
| 171 | +if ($pwdAlways && $passwordMatch!==true) { |
|
| 172 | 172 | errorPage("Password required and does not match or exists.", 403); |
| 173 | 173 | } |
| 174 | 174 | |
@@ -184,19 +184,19 @@ discard block |
||
| 184 | 184 | $allowHotlinking = getConfig('allow_hotlinking', true); |
| 185 | 185 | $hotlinkingWhitelist = getConfig('hotlinking_whitelist', array()); |
| 186 | 186 | |
| 187 | -$serverName = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null; |
|
| 188 | -$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null; |
|
| 187 | +$serverName = isset($_SERVER[ 'SERVER_NAME' ]) ? $_SERVER[ 'SERVER_NAME' ] : null; |
|
| 188 | +$referer = isset($_SERVER[ 'HTTP_REFERER' ]) ? $_SERVER[ 'HTTP_REFERER' ] : null; |
|
| 189 | 189 | $refererHost = parse_url($referer, PHP_URL_HOST); |
| 190 | 190 | |
| 191 | 191 | if (!$allowHotlinking) { |
| 192 | 192 | if ($passwordMatch) { |
| 193 | 193 | ; // Always allow when password match |
| 194 | 194 | verbose("Hotlinking since passwordmatch"); |
| 195 | - } elseif ($passwordMatch === false) { |
|
| 195 | + } elseif ($passwordMatch===false) { |
|
| 196 | 196 | errorPage("Hotlinking/leeching not allowed when password missmatch.", 403); |
| 197 | 197 | } elseif (!$referer) { |
| 198 | 198 | errorPage("Hotlinking/leeching not allowed and referer is missing.", 403); |
| 199 | - } elseif (strcmp($serverName, $refererHost) == 0) { |
|
| 199 | + } elseif (strcmp($serverName, $refererHost)==0) { |
|
| 200 | 200 | ; // Allow when serverName matches refererHost |
| 201 | 201 | verbose("Hotlinking disallowed but serverName matches refererHost."); |
| 202 | 202 | } elseif (!empty($hotlinkingWhitelist)) { |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | */ |
| 284 | 284 | $allowRemote = getConfig('remote_allow', false); |
| 285 | 285 | |
| 286 | -if ($allowRemote && $passwordMatch !== false) { |
|
| 286 | +if ($allowRemote && $passwordMatch!==false) { |
|
| 287 | 287 | $cacheRemote = $cache->getPathToSubdir("remote"); |
| 288 | 288 | |
| 289 | 289 | $pattern = getConfig('remote_pattern', null); |
@@ -307,10 +307,10 @@ discard block |
||
| 307 | 307 | verbose("shortcut = $shortcut"); |
| 308 | 308 | |
| 309 | 309 | if (isset($shortcut) |
| 310 | - && isset($shortcutConfig[$shortcut])) { |
|
| 310 | + && isset($shortcutConfig[ $shortcut ])) { |
|
| 311 | 311 | |
| 312 | - parse_str($shortcutConfig[$shortcut], $get); |
|
| 313 | - verbose("shortcut-constant = {$shortcutConfig[$shortcut]}"); |
|
| 312 | + parse_str($shortcutConfig[ $shortcut ], $get); |
|
| 313 | + verbose("shortcut-constant = {$shortcutConfig[ $shortcut ]}"); |
|
| 314 | 314 | $_GET = array_merge($_GET, $get); |
| 315 | 315 | } |
| 316 | 316 | |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | preg_match($validFilename, $srcImage) |
| 346 | 346 | or errorPage('Source filename contains invalid characters.', 404); |
| 347 | 347 | |
| 348 | -if ($dummyEnabled && $srcImage === $dummyFilename) { |
|
| 348 | +if ($dummyEnabled && $srcImage===$dummyFilename) { |
|
| 349 | 349 | |
| 350 | 350 | // Prepare to create a dummy image and use it as the source image. |
| 351 | 351 | $dummyImage = true; |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | preg_match($validFilename, $srcImage) |
| 369 | 369 | or errorPage('Source (alt) filename contains invalid characters.', 404); |
| 370 | 370 | |
| 371 | - if ($dummyEnabled && $srcImage === $dummyFilename) { |
|
| 371 | + if ($dummyEnabled && $srcImage===$dummyFilename) { |
|
| 372 | 372 | // Check if src-alt is the dummy image |
| 373 | 373 | $dummyImage = true; |
| 374 | 374 | } |
@@ -388,7 +388,7 @@ discard block |
||
| 388 | 388 | // Check that the image is a file below the directory 'image_path'. |
| 389 | 389 | $imageDir = realpath($imagePath); |
| 390 | 390 | |
| 391 | - substr_compare($imageDir, $pathToImage, 0, strlen($imageDir)) == 0 |
|
| 391 | + substr_compare($imageDir, $pathToImage, 0, strlen($imageDir))==0 |
|
| 392 | 392 | or errorPage( |
| 393 | 393 | 'Security constraint: Source image is not below the directory "image_path" |
| 394 | 394 | as specified in the config file img_config.php.', |
@@ -404,7 +404,7 @@ discard block |
||
| 404 | 404 | * Manage size constants from config file, use constants to replace values |
| 405 | 405 | * for width and height. |
| 406 | 406 | */ |
| 407 | -$sizeConstant = getConfig('size_constant', function () { |
|
| 407 | +$sizeConstant = getConfig('size_constant', function() { |
|
| 408 | 408 | |
| 409 | 409 | // Set sizes to map constant to value, easier to use with width or height |
| 410 | 410 | $sizes = array( |
@@ -418,7 +418,7 @@ discard block |
||
| 418 | 418 | $gridColumns = 24; |
| 419 | 419 | |
| 420 | 420 | for ($i = 1; $i <= $gridColumns; $i++) { |
| 421 | - $sizes['c' . $i] = ($gridColumnWidth + $gridGutterWidth) * $i - $gridGutterWidth; |
|
| 421 | + $sizes[ 'c' . $i ] = ($gridColumnWidth + $gridGutterWidth)*$i - $gridGutterWidth; |
|
| 422 | 422 | } |
| 423 | 423 | |
| 424 | 424 | return $sizes; |
@@ -435,12 +435,12 @@ discard block |
||
| 435 | 435 | $maxWidth = getConfig('max_width', 2000); |
| 436 | 436 | |
| 437 | 437 | // Check to replace predefined size |
| 438 | -if (isset($sizes[$newWidth])) { |
|
| 439 | - $newWidth = $sizes[$newWidth]; |
|
| 438 | +if (isset($sizes[ $newWidth ])) { |
|
| 439 | + $newWidth = $sizes[ $newWidth ]; |
|
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | // Support width as % of original width |
| 443 | -if ($newWidth && $newWidth[strlen($newWidth)-1] == '%') { |
|
| 443 | +if ($newWidth && $newWidth[ strlen($newWidth) - 1 ]=='%') { |
|
| 444 | 444 | is_numeric(substr($newWidth, 0, -1)) |
| 445 | 445 | or errorPage('Width % not numeric.', 404); |
| 446 | 446 | } else { |
@@ -460,12 +460,12 @@ discard block |
||
| 460 | 460 | $maxHeight = getConfig('max_height', 2000); |
| 461 | 461 | |
| 462 | 462 | // Check to replace predefined size |
| 463 | -if (isset($sizes[$newHeight])) { |
|
| 464 | - $newHeight = $sizes[$newHeight]; |
|
| 463 | +if (isset($sizes[ $newHeight ])) { |
|
| 464 | + $newHeight = $sizes[ $newHeight ]; |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | // height |
| 468 | -if ($newHeight && $newHeight[strlen($newHeight)-1] == '%') { |
|
| 468 | +if ($newHeight && $newHeight[ strlen($newHeight) - 1 ]=='%') { |
|
| 469 | 469 | is_numeric(substr($newHeight, 0, -1)) |
| 470 | 470 | or errorPage('Height % out of range.', 404); |
| 471 | 471 | } else { |
@@ -482,7 +482,7 @@ discard block |
||
| 482 | 482 | * aspect-ratio, ar - affecting the resulting image width, height and resize options |
| 483 | 483 | */ |
| 484 | 484 | $aspectRatio = get(array('aspect-ratio', 'ar')); |
| 485 | -$aspectRatioConstant = getConfig('aspect_ratio_constant', function () { |
|
| 485 | +$aspectRatioConstant = getConfig('aspect_ratio_constant', function() { |
|
| 486 | 486 | return array( |
| 487 | 487 | '3:1' => 3/1, |
| 488 | 488 | '3:2' => 3/2, |
@@ -496,15 +496,15 @@ discard block |
||
| 496 | 496 | |
| 497 | 497 | // Check to replace predefined aspect ratio |
| 498 | 498 | $aspectRatios = call_user_func($aspectRatioConstant); |
| 499 | -$negateAspectRatio = ($aspectRatio && $aspectRatio[0] == '!') ? true : false; |
|
| 499 | +$negateAspectRatio = ($aspectRatio && $aspectRatio[ 0 ]=='!') ? true : false; |
|
| 500 | 500 | $aspectRatio = $negateAspectRatio ? substr($aspectRatio, 1) : $aspectRatio; |
| 501 | 501 | |
| 502 | -if (isset($aspectRatios[$aspectRatio])) { |
|
| 503 | - $aspectRatio = $aspectRatios[$aspectRatio]; |
|
| 502 | +if (isset($aspectRatios[ $aspectRatio ])) { |
|
| 503 | + $aspectRatio = $aspectRatios[ $aspectRatio ]; |
|
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | if ($negateAspectRatio) { |
| 507 | - $aspectRatio = 1 / $aspectRatio; |
|
| 507 | + $aspectRatio = 1/$aspectRatio; |
|
| 508 | 508 | } |
| 509 | 509 | |
| 510 | 510 | is_null($aspectRatio) |
@@ -565,10 +565,10 @@ discard block |
||
| 565 | 565 | |
| 566 | 566 | verbose("fill-to-fit = $fillToFit"); |
| 567 | 567 | |
| 568 | -if ($fillToFit !== null) { |
|
| 568 | +if ($fillToFit!==null) { |
|
| 569 | 569 | |
| 570 | 570 | if (!empty($fillToFit)) { |
| 571 | - $bgColor = $fillToFit; |
|
| 571 | + $bgColor = $fillToFit; |
|
| 572 | 572 | verbose("fillToFit changed bgColor to = $bgColor"); |
| 573 | 573 | } |
| 574 | 574 | |
@@ -611,7 +611,7 @@ discard block |
||
| 611 | 611 | $useOriginal = getDefined(array('skip-original', 'so'), false, true); |
| 612 | 612 | $useOriginalDefault = getConfig('skip_original', false); |
| 613 | 613 | |
| 614 | -if ($useOriginalDefault === true) { |
|
| 614 | +if ($useOriginalDefault===true) { |
|
| 615 | 615 | verbose("skip original is default ON"); |
| 616 | 616 | $useOriginal = false; |
| 617 | 617 | } |
@@ -755,13 +755,13 @@ discard block |
||
| 755 | 755 | $filters = array(); |
| 756 | 756 | $filter = get(array('filter', 'f')); |
| 757 | 757 | if ($filter) { |
| 758 | - $filters[] = $filter; |
|
| 758 | + $filters[ ] = $filter; |
|
| 759 | 759 | } |
| 760 | 760 | |
| 761 | 761 | for ($i = 0; $i < 10; $i++) { |
| 762 | 762 | $filter = get(array("filter{$i}", "f{$i}")); |
| 763 | 763 | if ($filter) { |
| 764 | - $filters[] = $filter; |
|
| 764 | + $filters[ ] = $filter; |
|
| 765 | 765 | } |
| 766 | 766 | } |
| 767 | 767 | |
@@ -778,7 +778,7 @@ discard block |
||
| 778 | 778 | |
| 779 | 779 | verbose("outputformat = $outputFormat"); |
| 780 | 780 | |
| 781 | -if ($outputFormat == 'ascii') { |
|
| 781 | +if ($outputFormat=='ascii') { |
|
| 782 | 782 | $defaultOptions = getConfig( |
| 783 | 783 | 'ascii-options', |
| 784 | 784 | array( |
@@ -791,25 +791,25 @@ discard block |
||
| 791 | 791 | $options = get('ascii'); |
| 792 | 792 | $options = explode(',', $options); |
| 793 | 793 | |
| 794 | - if (isset($options[0]) && !empty($options[0])) { |
|
| 795 | - $defaultOptions['characterSet'] = $options[0]; |
|
| 794 | + if (isset($options[ 0 ]) && !empty($options[ 0 ])) { |
|
| 795 | + $defaultOptions[ 'characterSet' ] = $options[ 0 ]; |
|
| 796 | 796 | } |
| 797 | 797 | |
| 798 | - if (isset($options[1]) && !empty($options[1])) { |
|
| 799 | - $defaultOptions['scale'] = $options[1]; |
|
| 798 | + if (isset($options[ 1 ]) && !empty($options[ 1 ])) { |
|
| 799 | + $defaultOptions[ 'scale' ] = $options[ 1 ]; |
|
| 800 | 800 | } |
| 801 | 801 | |
| 802 | - if (isset($options[2]) && !empty($options[2])) { |
|
| 803 | - $defaultOptions['luminanceStrategy'] = $options[2]; |
|
| 802 | + if (isset($options[ 2 ]) && !empty($options[ 2 ])) { |
|
| 803 | + $defaultOptions[ 'luminanceStrategy' ] = $options[ 2 ]; |
|
| 804 | 804 | } |
| 805 | 805 | |
| 806 | 806 | if (count($options) > 3) { |
| 807 | 807 | // Last option is custom character string |
| 808 | - unset($options[0]); |
|
| 809 | - unset($options[1]); |
|
| 810 | - unset($options[2]); |
|
| 808 | + unset($options[ 0 ]); |
|
| 809 | + unset($options[ 1 ]); |
|
| 810 | + unset($options[ 2 ]); |
|
| 811 | 811 | $characterString = implode($options); |
| 812 | - $defaultOptions['customCharacterSet'] = $characterString; |
|
| 812 | + $defaultOptions[ 'customCharacterSet' ] = $characterString; |
|
| 813 | 813 | } |
| 814 | 814 | |
| 815 | 815 | $img->setAsciiOptions($defaultOptions); |
@@ -923,7 +923,7 @@ discard block |
||
| 923 | 923 | /** |
| 924 | 924 | * Prepare a dummy image and use it as source image. |
| 925 | 925 | */ |
| 926 | -if ($dummyImage === true) { |
|
| 926 | +if ($dummyImage===true) { |
|
| 927 | 927 | $dummyDir = $cache->getPathToSubdir("dummy"); |
| 928 | 928 | |
| 929 | 929 | $img->setSaveFolder($dummyDir) |
@@ -983,7 +983,7 @@ discard block |
||
| 983 | 983 | if ($status) { |
| 984 | 984 | $text = "img.php version = " . CIMAGE_VERSION . "\n"; |
| 985 | 985 | $text .= "PHP version = " . PHP_VERSION . "\n"; |
| 986 | - $text .= "Running on: " . $_SERVER['SERVER_SOFTWARE'] . "\n"; |
|
| 986 | + $text .= "Running on: " . $_SERVER[ 'SERVER_SOFTWARE' ] . "\n"; |
|
| 987 | 987 | $text .= "Allow remote images = $allowRemote\n"; |
| 988 | 988 | |
| 989 | 989 | $res = $cache->getStatusOfSubdir(""); |
@@ -1015,10 +1015,10 @@ discard block |
||
| 1015 | 1015 | $no = extension_loaded('gd') ? null : 'NOT'; |
| 1016 | 1016 | $text .= "Extension gd is $no loaded.<br>"; |
| 1017 | 1017 | |
| 1018 | - $text .= checkExternalCommand("PNG LOSSY", $postProcessing["png_lossy"], $postProcessing["png_lossy_cmd"]); |
|
| 1019 | - $text .= checkExternalCommand("PNG FILTER", $postProcessing["png_filter"], $postProcessing["png_filter_cmd"]); |
|
| 1020 | - $text .= checkExternalCommand("PNG DEFLATE", $postProcessing["png_deflate"], $postProcessing["png_deflate_cmd"]); |
|
| 1021 | - $text .= checkExternalCommand("JPEG OPTIMIZE", $postProcessing["jpeg_optimize"], $postProcessing["jpeg_optimize_cmd"]); |
|
| 1018 | + $text .= checkExternalCommand("PNG LOSSY", $postProcessing[ "png_lossy" ], $postProcessing[ "png_lossy_cmd" ]); |
|
| 1019 | + $text .= checkExternalCommand("PNG FILTER", $postProcessing[ "png_filter" ], $postProcessing[ "png_filter_cmd" ]); |
|
| 1020 | + $text .= checkExternalCommand("PNG DEFLATE", $postProcessing[ "png_deflate" ], $postProcessing[ "png_deflate_cmd" ]); |
|
| 1021 | + $text .= checkExternalCommand("JPEG OPTIMIZE", $postProcessing[ "jpeg_optimize" ], $postProcessing[ "jpeg_optimize_cmd" ]); |
|
| 1022 | 1022 | |
| 1023 | 1023 | if (!$no) { |
| 1024 | 1024 | $text .= print_r(gd_info(), 1); |
@@ -1101,12 +1101,12 @@ discard block |
||
| 1101 | 1101 | */ |
| 1102 | 1102 | if ($verbose) { |
| 1103 | 1103 | $query = array(); |
| 1104 | - parse_str($_SERVER['QUERY_STRING'], $query); |
|
| 1105 | - unset($query['verbose']); |
|
| 1106 | - unset($query['v']); |
|
| 1107 | - unset($query['nocache']); |
|
| 1108 | - unset($query['nc']); |
|
| 1109 | - unset($query['json']); |
|
| 1104 | + parse_str($_SERVER[ 'QUERY_STRING' ], $query); |
|
| 1105 | + unset($query[ 'verbose' ]); |
|
| 1106 | + unset($query[ 'v' ]); |
|
| 1107 | + unset($query[ 'nocache' ]); |
|
| 1108 | + unset($query[ 'nc' ]); |
|
| 1109 | + unset($query[ 'json' ]); |
|
| 1110 | 1110 | $url1 = '?' . htmlentities(urldecode(http_build_query($query))); |
| 1111 | 1111 | $url2 = '?' . urldecode(http_build_query($query)); |
| 1112 | 1112 | echo <<<EOD |
@@ -10,9 +10,9 @@ |
||
| 10 | 10 | //echo showEnvironment(get_defined_vars(), get_defined_functions()); |
| 11 | 11 | |
| 12 | 12 | // Prepare classes |
| 13 | -$classes[] = "article"; |
|
| 13 | +$classes[ ] = "article"; |
|
| 14 | 14 | if (isset($class)) { |
| 15 | - $classes[] = $class; |
|
| 15 | + $classes[ ] = $class; |
|
| 16 | 16 | } |
| 17 | 17 | ?> |
| 18 | 18 | <article <?= classList($classes) ?>> |
@@ -19,19 +19,19 @@ discard block |
||
| 19 | 19 | ?> |
| 20 | 20 | <?php foreach ($posts as $item) : |
| 21 | 21 | $sql = "select * from v_post_votes where post_id=?;"; |
| 22 | - $db = $this->di->get("db"); |
|
| 23 | - $score = $db->executeFetchAll($sql, [$item->id]); |
|
| 22 | + $db = $this->di->get("db"); |
|
| 23 | + $score = $db->executeFetchAll($sql, [ $item->id ]); |
|
| 24 | 24 | if (!$score) { |
| 25 | 25 | $score = 0; |
| 26 | 26 | } else { |
| 27 | - $score = $score[0]-> postscore; |
|
| 27 | + $score = $score[ 0 ]-> postscore; |
|
| 28 | 28 | }?> |
| 29 | 29 | |
| 30 | 30 | <div class=posts> |
| 31 | 31 | <div class=leftpost> |
| 32 | 32 | <div class=countvotes><?= $score?></div> |
| 33 | 33 | <div class=countvotes>votes</div> |
| 34 | - <div class=countanswers><?= $item->answer?: 0?></div> |
|
| 34 | + <div class=countanswers><?= $item->answer ?: 0?></div> |
|
| 35 | 35 | <div class=countvotes>answers</div> |
| 36 | 36 | </div> |
| 37 | 37 | <div class=rightpost> |
@@ -59,9 +59,9 @@ discard block |
||
| 59 | 59 | <table class=table> |
| 60 | 60 | <?php foreach ($answers as $answer): |
| 61 | 61 | if ($answer->accepted==1) { |
| 62 | - $acceptAns ="accepted"; |
|
| 62 | + $acceptAns = "accepted"; |
|
| 63 | 63 | } else { |
| 64 | - $acceptAns ="NoShowAcceptButton"; |
|
| 64 | + $acceptAns = "NoShowAcceptButton"; |
|
| 65 | 65 | }; |
| 66 | 66 | ?> |
| 67 | 67 | <tr> |
@@ -24,20 +24,20 @@ discard block |
||
| 24 | 24 | ?> |
| 25 | 25 | <?php foreach ($posts as $item) : |
| 26 | 26 | $sql = "select * from v_post_votes where post_id=?;"; |
| 27 | - $db = $this->di->get("db"); |
|
| 28 | - $score = $db->executeFetchAll($sql, [$item->id]); |
|
| 27 | + $db = $this->di->get("db"); |
|
| 28 | + $score = $db->executeFetchAll($sql, [ $item->id ]); |
|
| 29 | 29 | if (!$score) { |
| 30 | 30 | $score = 0; |
| 31 | 31 | } else { |
| 32 | - $score = $score[0]-> postscore; |
|
| 32 | + $score = $score[ 0 ]-> postscore; |
|
| 33 | 33 | }; |
| 34 | - $urlToShowPost = url("post/show/$item->id");?> |
|
| 34 | + $urlToShowPost = url("post/show/$item->id"); ?> |
|
| 35 | 35 | |
| 36 | 36 | <div class=posts> |
| 37 | 37 | <div class=leftpost> |
| 38 | 38 | <div class=countvotes><?= $score?></div> |
| 39 | 39 | <div class=countvotes>votes</div> |
| 40 | - <div class=countanswers><?= $item->answer?: 0?></div> |
|
| 40 | + <div class=countanswers><?= $item->answer ?: 0?></div> |
|
| 41 | 41 | <div class=countvotes>answers</div> |
| 42 | 42 | </div> |
| 43 | 43 | <div class=rightpost> |
@@ -64,14 +64,14 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | <?php foreach ($answers as $answer): |
| 66 | 66 | if ($answer->accepted==1) { |
| 67 | - $acceptAns ="accepted"; |
|
| 67 | + $acceptAns = "accepted"; |
|
| 68 | 68 | } else { |
| 69 | - $acceptAns ="NoShowAcceptButton"; |
|
| 69 | + $acceptAns = "NoShowAcceptButton"; |
|
| 70 | 70 | }; |
| 71 | 71 | // var_dump($acceptAns); |
| 72 | 72 | ?> |
| 73 | 73 | <div class=profileposts> |
| 74 | - <a href="<?= url("post/show/{$answer->post_id}"); ?>"><?= Markdown::defaultTransform($answer->comment);?></a> |
|
| 74 | + <a href="<?= url("post/show/{$answer->post_id}"); ?>"><?= Markdown::defaultTransform($answer->comment); ?></a> |
|
| 75 | 75 | <div class=<?=$acceptAns?>><i class="fa-2x fas fa-check"></i></div> |
| 76 | 76 | </div> |
| 77 | 77 | <?php endforeach; ?> |
@@ -36,19 +36,19 @@ |
||
| 36 | 36 | ?> |
| 37 | 37 | <?php foreach ($items as $item) : |
| 38 | 38 | $sql = "select * from v_post_votes where post_id=?;"; |
| 39 | - $db = $this->di->get("db"); |
|
| 40 | - $score = $db->executeFetchAll($sql, [$item->id]); |
|
| 39 | + $db = $this->di->get("db"); |
|
| 40 | + $score = $db->executeFetchAll($sql, [ $item->id ]); |
|
| 41 | 41 | if (!$score) { |
| 42 | 42 | $score = 0; |
| 43 | 43 | } else { |
| 44 | - $score = $score[0]-> postscore; |
|
| 44 | + $score = $score[ 0 ]-> postscore; |
|
| 45 | 45 | }?> |
| 46 | 46 | |
| 47 | 47 | <div class=posts> |
| 48 | 48 | <div class=leftpost> |
| 49 | 49 | <div class=countvotes><?= $score?></div> |
| 50 | 50 | <div class=countvotes>votes</div> |
| 51 | - <div class=countanswers><?= $item->answer?: 0?></div> |
|
| 51 | + <div class=countanswers><?= $item->answer ?: 0?></div> |
|
| 52 | 52 | <div class=countvotes>answers</div> |
| 53 | 53 | </div> |
| 54 | 54 | <div class=rightpost> |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | <div><?= Markdown::defaultTransform($post->content) ?></div> |
| 26 | 26 | <div> |
| 27 | 27 | <?php foreach (explode(",", $post->tags) as $tag) : |
| 28 | - $urlToShowTag = url("tags/show/$tag");?> |
|
| 28 | + $urlToShowTag = url("tags/show/$tag"); ?> |
|
| 29 | 29 | <a class=onetag href="<?= $urlToShowTag ?>"><?= $tag ?></a> |
| 30 | 30 | <?php endforeach; ?> |
| 31 | 31 | </div> |
@@ -66,32 +66,32 @@ discard block |
||
| 66 | 66 | $urlToReply = url("comment/reply/$answer->id/$post->id"); |
| 67 | 67 | $urlToAccept = url("comment/accept/$answer->id/$post->id"); |
| 68 | 68 | // get the score for each answer |
| 69 | - $db = $this->di->get("db"); |
|
| 69 | + $db = $this->di->get("db"); |
|
| 70 | 70 | $sql = "select * from v_comments_user where comment_reply_id=?;"; |
| 71 | - $replys= $db->executeFetchAll($sql, [$answer->id]); |
|
| 71 | + $replys = $db->executeFetchAll($sql, [ $answer->id ]); |
|
| 72 | 72 | $sql = "select * from v_comment_votes where comment_id=?;"; |
| 73 | - $commentscore= $db->executeFetchAll($sql, [$answer->id]); |
|
| 73 | + $commentscore = $db->executeFetchAll($sql, [ $answer->id ]); |
|
| 74 | 74 | // Set the accepted button according the status of answer and owner |
| 75 | 75 | // var_dump($status, $answer->accepted); |
| 76 | 76 | if ($isOwner) { |
| 77 | 77 | if ($answer->accepted==0) { |
| 78 | - $acceptAns="check"; |
|
| 78 | + $acceptAns = "check"; |
|
| 79 | 79 | } elseif ($answer->accepted==1) { |
| 80 | - $acceptAns="accepted"; |
|
| 80 | + $acceptAns = "accepted"; |
|
| 81 | 81 | } |
| 82 | 82 | } else { |
| 83 | 83 | if ($answer->accepted==1) { |
| 84 | - $acceptAns="accepted"; |
|
| 84 | + $acceptAns = "accepted"; |
|
| 85 | 85 | } elseif ($answer->accepted==0) { |
| 86 | - $acceptAns="NoShowAcceptButton"; |
|
| 86 | + $acceptAns = "NoShowAcceptButton"; |
|
| 87 | 87 | } |
| 88 | 88 | } |
| 89 | 89 | if (!$commentscore) { |
| 90 | 90 | $commentscore = 0; |
| 91 | 91 | } else { |
| 92 | - $commentscore = $commentscore[0]-> commentscore; |
|
| 92 | + $commentscore = $commentscore[ 0 ]-> commentscore; |
|
| 93 | 93 | } |
| 94 | - $urlToComment =url("comment/$answer->id"); |
|
| 94 | + $urlToComment = url("comment/$answer->id"); |
|
| 95 | 95 | // var_dump($acceptAns);?> |
| 96 | 96 | <div class=posts> |
| 97 | 97 | <div class=leftpost> |
@@ -22,7 +22,7 @@ |
||
| 22 | 22 | endif; |
| 23 | 23 | ?> |
| 24 | 24 | <?php foreach ($items as $item) : |
| 25 | - $urlToShow = url("post/show/$item->id");?> |
|
| 25 | + $urlToShow = url("post/show/$item->id"); ?> |
|
| 26 | 26 | |
| 27 | 27 | <div class=posts> |
| 28 | 28 | <div class=leftpost> |
@@ -21,19 +21,19 @@ |
||
| 21 | 21 | ?> |
| 22 | 22 | <?php foreach ($posts as $item) : |
| 23 | 23 | $sql = "select * from v_post_votes where post_id=?;"; |
| 24 | - $db = $this->di->get("db"); |
|
| 25 | - $score = $db->executeFetchAll($sql, [$item->id]); |
|
| 24 | + $db = $this->di->get("db"); |
|
| 25 | + $score = $db->executeFetchAll($sql, [ $item->id ]); |
|
| 26 | 26 | if (!$score) { |
| 27 | 27 | $score = 0; |
| 28 | 28 | } else { |
| 29 | - $score = $score[0]-> postscore; |
|
| 29 | + $score = $score[ 0 ]-> postscore; |
|
| 30 | 30 | }?> |
| 31 | 31 | |
| 32 | 32 | <div class=posts> |
| 33 | 33 | <div class=leftpost> |
| 34 | 34 | <div class=countvotes><?= $score?></div> |
| 35 | 35 | <div class=countvotes>votes</div> |
| 36 | - <div class=countanswers><?= $item->answer?: 0?></div> |
|
| 36 | + <div class=countanswers><?= $item->answer ?: 0?></div> |
|
| 37 | 37 | <div class=countvotes>answers</div> |
| 38 | 38 | </div> |
| 39 | 39 | <div class=rightpost> |
@@ -196,7 +196,7 @@ |
||
| 196 | 196 | } |
| 197 | 197 | $page->add("post/show", |
| 198 | 198 | ["post" => $posts[0], |
| 199 | - "postscore" => $postscore, |
|
| 199 | + "postscore" => $postscore, |
|
| 200 | 200 | "answers" => $answers, |
| 201 | 201 | "comments0" => $comments0, |
| 202 | 202 | "isOwner" => $isOwner, |
@@ -44,10 +44,10 @@ discard block |
||
| 44 | 44 | // Connect the database |
| 45 | 45 | $this->db = $this->di->get("db"); |
| 46 | 46 | $this->db->connect(); |
| 47 | - if ($this->currentUser !=null) { |
|
| 47 | + if ($this->currentUser!=null) { |
|
| 48 | 48 | $sql = "SELECT id from users where username = ?;"; |
| 49 | - $res = $this->db->executeFetchAll($sql, [$this->currentUser]); |
|
| 50 | - $this->userId = $res[0]->id; |
|
| 49 | + $res = $this->db->executeFetchAll($sql, [ $this->currentUser ]); |
|
| 50 | + $this->userId = $res[ 0 ]->id; |
|
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | |
@@ -114,13 +114,13 @@ discard block |
||
| 114 | 114 | $tags = $request->getPost("Tags") ?: null; |
| 115 | 115 | |
| 116 | 116 | $sql = "INSERT INTO posts (title, content, user_id) VALUES (?, ?, ?);"; |
| 117 | - $this->db->execute($sql, [$title, $content, $this->userId]); |
|
| 117 | + $this->db->execute($sql, [ $title, $content, $this->userId ]); |
|
| 118 | 118 | $lastInsertId = $this->db->lastInsertId(); |
| 119 | 119 | var_dump($lastInsertId); |
| 120 | 120 | $tagsArray = explode(",", $tags); |
| 121 | 121 | foreach ($tagsArray as $value) { |
| 122 | 122 | $sql = "INSERT INTO post2tag (post_id, tag_name) VALUES (?, ?);"; |
| 123 | - $this->db->execute($sql, [$lastInsertId, trim($value)]); |
|
| 123 | + $this->db->execute($sql, [ $lastInsertId, trim($value) ]); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | return $response->redirect("post"); |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | $comment = $request->getPost("answer") ?: null; |
| 147 | 147 | |
| 148 | 148 | $sql = "INSERT INTO comments (comment, user_id, post_id, answer) VALUES (?, ?, ?, ?);"; |
| 149 | - $this->db->execute($sql, [$comment, $this->userId, $post_id, 1]); |
|
| 149 | + $this->db->execute($sql, [ $comment, $this->userId, $post_id, 1 ]); |
|
| 150 | 150 | $response = $this->di->get("response"); |
| 151 | 151 | return $response->redirect("post/show/$post_id"); |
| 152 | 152 | } |
@@ -171,31 +171,31 @@ discard block |
||
| 171 | 171 | $orderBy = $request->getGet("orderby") ?: "created"; |
| 172 | 172 | $order = $request->getGet("order") ?: "asc"; |
| 173 | 173 | $sql = "SELECT * from v_all_user WHERE id=?;"; |
| 174 | - $posts = $this->db->executeFetchAll($sql, [$postid]); |
|
| 174 | + $posts = $this->db->executeFetchAll($sql, [ $postid ]); |
|
| 175 | 175 | |
| 176 | 176 | $sql = "SELECT * from v_comments_user WHERE post_id=? and answer=1 order by accepted desc, $orderBy $order;"; |
| 177 | 177 | //Get the answers for the post |
| 178 | - $answers = $this->db->executeFetchAll($sql, [$postid]); |
|
| 178 | + $answers = $this->db->executeFetchAll($sql, [ $postid ]); |
|
| 179 | 179 | $sql = "SELECT * from v_comments_user WHERE post_id=? and answer=0 and ISNULL(comment_reply_id);"; |
| 180 | 180 | // Get the comments for the post |
| 181 | - $comments0 = $this->db->executeFetchAll($sql, [$postid]); |
|
| 181 | + $comments0 = $this->db->executeFetchAll($sql, [ $postid ]); |
|
| 182 | 182 | |
| 183 | 183 | $sql = "select * from v_post_votes where post_id=?;"; |
| 184 | - $postscore = $this->db->executeFetchAll($sql, [$postid]); |
|
| 184 | + $postscore = $this->db->executeFetchAll($sql, [ $postid ]); |
|
| 185 | 185 | // var_dump($answers); |
| 186 | 186 | if (!$postscore) { |
| 187 | 187 | $postscore = 0; |
| 188 | 188 | } else { |
| 189 | - $postscore = $postscore[0]-> postscore; |
|
| 189 | + $postscore = $postscore[ 0 ]-> postscore; |
|
| 190 | 190 | } |
| 191 | 191 | // check if the current user is the owner of the question, if yes, show the accepted answer button otherwise not |
| 192 | 192 | // var_dump($this->currentUser,$posts[0]->username ); |
| 193 | - $isOwner=true; |
|
| 194 | - if ($this->currentUser != $posts[0]->username ) { |
|
| 193 | + $isOwner = true; |
|
| 194 | + if ($this->currentUser!=$posts[ 0 ]->username) { |
|
| 195 | 195 | $isOwner = false; |
| 196 | 196 | } |
| 197 | 197 | $page->add("post/show", |
| 198 | - ["post" => $posts[0], |
|
| 198 | + [ "post" => $posts[ 0 ], |
|
| 199 | 199 | "postscore" => $postscore, |
| 200 | 200 | "answers" => $answers, |
| 201 | 201 | "comments0" => $comments0, |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | $page = $this->di->get("page"); |
| 213 | 213 | |
| 214 | 214 | $sql = "INSERT INTO post_votes (score, post_id, user_id) VALUES (?, ?, ?);"; |
| 215 | - $this->db->execute($sql, [1, $id, $this->userId]); |
|
| 215 | + $this->db->execute($sql, [ 1, $id, $this->userId ]); |
|
| 216 | 216 | |
| 217 | 217 | |
| 218 | 218 | $response = $this->di->get("response"); |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | $page = $this->di->get("page"); |
| 225 | 225 | |
| 226 | 226 | $sql = "INSERT INTO post_votes (score, post_id, user_id) VALUES (?, ?, ?);"; |
| 227 | - $this->db->execute($sql, [-1, $id, $this->userId]); |
|
| 227 | + $this->db->execute($sql, [-1, $id, $this->userId ]); |
|
| 228 | 228 | |
| 229 | 229 | |
| 230 | 230 | $response = $this->di->get("response"); |