mikuli.cz

:)
git clone https://git.sr.ht/~ashymad/mikuli.cz
Log | Files | Refs

commit da71a8c9e9313ec8c7c273d363f2e640389c9aa1
parent 8f310a5df4686e4e1b2f42803db175c956bc67f9
Author: markseu <mark2011@mayberg.se>
Date:   Sat,  7 Jul 2018 14:21:21 +0200

Updated plugins, summer cleanup

Diffstat:
Msystem/plugins/command.php | 93+++++++++++++++++++++++++++++++++++--------------------------------------------
Msystem/plugins/update.php | 80++++++++++++++++++++++++++++++++++---------------------------------------------
2 files changed, 75 insertions(+), 98 deletions(-)

diff --git a/system/plugins/command.php b/system/plugins/command.php @@ -5,7 +5,7 @@ class YellowCommand { - const VERSION = "0.7.5"; + const VERSION = "0.7.6"; var $yellow; //access to API var $files; //number of files var $links; //number of links @@ -333,50 +333,44 @@ class YellowCommand { $statusCode = 200; $broken = $redirect = $data = array(); - if(extension_loaded("curl")) + $staticUrl = $this->yellow->config->get("staticUrl"); + list($scheme, $address, $base) = $this->yellow->lookup->getUrlInformation($staticUrl); + $staticLocations = $this->getContentLocations(true); + uksort($links, "strnatcasecmp"); + foreach($links as $url=>$value) { - $staticUrl = $this->yellow->config->get("staticUrl"); - list($scheme, $address, $base) = $this->yellow->lookup->getUrlInformation($staticUrl); - $staticLocations = $this->getContentLocations(true); - uksort($links, "strnatcasecmp"); - foreach($links as $url=>$value) + if(defined("DEBUG") && DEBUG>=1) echo "YellowCommand::analyseLinks url:$url\n"; + if(preg_match("#^$staticUrl#", $url)) { - if(defined("DEBUG") && DEBUG>=1) echo "YellowCommand::analyseLinks url:$url\n"; - if(preg_match("#^$staticUrl#", $url)) - { - $location = substru($url, 32); - $fileName = $path.substru($url, 32); - if(is_readable($fileName)) continue; - if(in_array($location, $staticLocations)) continue; - } - if(preg_match("/^(http|https):/", $url)) + $location = substru($url, 32); + $fileName = $path.substru($url, 32); + if(is_readable($fileName)) continue; + if(in_array($location, $staticLocations)) continue; + } + if(preg_match("/^(http|https):/", $url)) + { + $referer = "$scheme://$address".(($pos = strposu($value, ',')) ? substru($value, 0, $pos) : $value); + $statusCodeUrl = $this->getLinkStatus($url, $referer); + if($statusCodeUrl!=200) { - $referer = "$scheme://$address".(($pos = strposu($value, ',')) ? substru($value, 0, $pos) : $value); - $statusCodeUrl = $this->getLinkStatus($url, $referer); - if($statusCodeUrl!=200) - { - $statusCode = max($statusCode, $statusCodeUrl); - $data[$url] = "$statusCodeUrl,$value"; - } + $statusCode = max($statusCode, $statusCodeUrl); + $data[$url] = "$statusCodeUrl,$value"; } } - foreach($data as $url=>$value) + } + foreach($data as $url=>$value) + { + $locations = preg_split("/\s*,\s*/", $value); + $statusCodeUrl = array_shift($locations); + foreach($locations as $location) { - $locations = preg_split("/\s*,\s*/", $value); - $statusCodeUrl = array_shift($locations); - foreach($locations as $location) - { - if($statusCodeUrl==302) continue; - if($statusCodeUrl>=300 && $statusCodeUrl<=399) { - $redirect["$scheme://$address$location -> $url - ".$this->getStatusFormatted($statusCodeUrl)] = $statusCodeUrl; - } else { - $broken["$scheme://$address$location -> $url - ".$this->getStatusFormatted($statusCodeUrl)] = $statusCodeUrl; - } + if($statusCodeUrl==302) continue; + if($statusCodeUrl>=300 && $statusCodeUrl<=399) { + $redirect["$scheme://$address$location -> $url - ".$this->getStatusFormatted($statusCodeUrl)] = $statusCodeUrl; + } else { + $broken["$scheme://$address$location -> $url - ".$this->getStatusFormatted($statusCodeUrl)] = $statusCodeUrl; } } - } else { - $statusCode = 500; - echo "ERROR checking links: Plugin 'command' requires cURL library!\n"; } return array($statusCode, $broken, $redirect); } @@ -646,21 +640,16 @@ class YellowCommand // Return link status function getLinkStatus($url, $referer) { - if(extension_loaded("curl")) - { - $curlHandle = curl_init(); - curl_setopt($curlHandle, CURLOPT_URL, $url); - curl_setopt($curlHandle, CURLOPT_REFERER, $referer); - curl_setopt($curlHandle, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; DatenstromYellow/".YellowCore::VERSION."; LinkChecker)"); - curl_setopt($curlHandle, CURLOPT_NOBODY, 1); - curl_setopt($curlHandle, CURLOPT_CONNECTTIMEOUT, 30); - curl_exec($curlHandle); - $statusCode = curl_getinfo($curlHandle, CURLINFO_HTTP_CODE); - curl_close($curlHandle); - if(defined("DEBUG") && DEBUG>=2) echo "YellowCommand::getLinkStatus status:$statusCode url:$url<br/>\n"; - } else { - $statusCode = 500; - } + $curlHandle = curl_init(); + curl_setopt($curlHandle, CURLOPT_URL, $url); + curl_setopt($curlHandle, CURLOPT_REFERER, $referer); + curl_setopt($curlHandle, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; DatenstromYellow/".YellowCore::VERSION."; LinkChecker)"); + curl_setopt($curlHandle, CURLOPT_NOBODY, 1); + curl_setopt($curlHandle, CURLOPT_CONNECTTIMEOUT, 30); + curl_exec($curlHandle); + $statusCode = curl_getinfo($curlHandle, CURLINFO_HTTP_CODE); + curl_close($curlHandle); + if(defined("DEBUG") && DEBUG>=2) echo "YellowCommand::getLinkStatus status:$statusCode url:$url<br/>\n"; return $statusCode; } } diff --git a/system/plugins/update.php b/system/plugins/update.php @@ -5,7 +5,7 @@ class YellowUpdate { - const VERSION = "0.7.12"; + const VERSION = "0.7.13"; var $yellow; //access to API var $updates; //number of updates @@ -639,22 +639,17 @@ class YellowUpdate // Check web server rewrite function checkServerRewrite($scheme, $address, $base, $location, $fileName) { - $ok = true; - if(extension_loaded("curl")) - { - $curlHandle = curl_init(); - $location = $this->yellow->config->get("assetLocation").$this->yellow->page->get("theme").".css"; - $url = $this->yellow->lookup->normaliseUrl($scheme, $address, $base, $location); - curl_setopt($curlHandle, CURLOPT_URL, $url); - curl_setopt($curlHandle, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; YellowCore/".YellowCore::VERSION).")"; - curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($curlHandle, CURLOPT_CONNECTTIMEOUT, 30); - $rawData = curl_exec($curlHandle); - $statusCode = curl_getinfo($curlHandle, CURLINFO_HTTP_CODE); - curl_close($curlHandle); - if(empty($rawData) || $statusCode!=200) $ok = false; - } - return $ok; + $curlHandle = curl_init(); + $location = $this->yellow->config->get("assetLocation").$this->yellow->page->get("theme").".css"; + $url = $this->yellow->lookup->normaliseUrl($scheme, $address, $base, $location); + curl_setopt($curlHandle, CURLOPT_URL, $url); + curl_setopt($curlHandle, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; YellowCore/".YellowCore::VERSION).")"; + curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curlHandle, CURLOPT_CONNECTTIMEOUT, 30); + $rawData = curl_exec($curlHandle); + $statusCode = curl_getinfo($curlHandle, CURLINFO_HTTP_CODE); + curl_close($curlHandle); + return !empty($rawData) && $statusCode==200; } // Return raw data for installation page @@ -802,38 +797,31 @@ class YellowUpdate // Return software file function getSoftwareFile($url) { - $fileData = ""; - if(extension_loaded("curl")) - { - $urlRequest = $url; - if(preg_match("#^https://github.com/(.+)/raw/(.+)$#", $url, $matches)) - { - $urlRequest = "https://raw.githubusercontent.com/".$matches[1]."/".$matches[2]; - } - $curlHandle = curl_init(); - curl_setopt($curlHandle, CURLOPT_URL, $urlRequest); - curl_setopt($curlHandle, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; DatenstromYellow/".YellowCore::VERSION."; SoftwareUpdater)"); - curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($curlHandle, CURLOPT_CONNECTTIMEOUT, 30); - $rawData = curl_exec($curlHandle); - $statusCode = curl_getinfo($curlHandle, CURLINFO_HTTP_CODE); - curl_close($curlHandle); - if($statusCode==200) - { - $fileData = $rawData; - } else if($statusCode==0) { - $statusCode = 500; - list($scheme, $address) = $this->yellow->lookup->getUrlInformation($url); - $this->yellow->page->error($statusCode, "Can't connect to server '$scheme://$address'!"); - } else { - $statusCode = 500; - $this->yellow->page->error($statusCode, "Can't download file '$url'!"); - } - if(defined("DEBUG") && DEBUG>=2) echo "YellowUpdate::getSoftwareFile status:$statusCode url:$url<br/>\n"; + $urlRequest = $url; + if(preg_match("#^https://github.com/(.+)/raw/(.+)$#", $url, $matches)) + { + $urlRequest = "https://raw.githubusercontent.com/".$matches[1]."/".$matches[2]; + } + $curlHandle = curl_init(); + curl_setopt($curlHandle, CURLOPT_URL, $urlRequest); + curl_setopt($curlHandle, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; DatenstromYellow/".YellowCore::VERSION."; SoftwareUpdater)"); + curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curlHandle, CURLOPT_CONNECTTIMEOUT, 30); + $rawData = curl_exec($curlHandle); + $statusCode = curl_getinfo($curlHandle, CURLINFO_HTTP_CODE); + curl_close($curlHandle); + if($statusCode==200) + { + $fileData = $rawData; + } else if($statusCode==0) { + $statusCode = 500; + list($scheme, $address) = $this->yellow->lookup->getUrlInformation($url); + $this->yellow->page->error($statusCode, "Can't connect to server '$scheme://$address'!"); } else { $statusCode = 500; - $this->yellow->page->error($statusCode, "Plugin 'update' requires cURL library!"); + $this->yellow->page->error($statusCode, "Can't download file '$url'!"); } + if(defined("DEBUG") && DEBUG>=2) echo "YellowUpdate::getSoftwareFile status:$statusCode url:$url<br/>\n"; return array($statusCode, $fileData); }