From d99b82ef7f41b293ad9a8161c111128da8450027 Mon Sep 17 00:00:00 2001 From: Austin Mason Date: Thu, 17 Aug 2017 11:07:08 -0500 Subject: [PATCH 1/2] Fixed array declaration for PHP 5.3 compatibility Declaration of $descriptorSpec in line 315 was causing fatal 500 errors on system with PHP 5.3 installed. --- controllers/IndexController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/controllers/IndexController.php b/controllers/IndexController.php index db51f82..16ffc37 100644 --- a/controllers/IndexController.php +++ b/controllers/IndexController.php @@ -312,11 +312,11 @@ protected function executeCommand($command, &$status, &$output, &$errors) // fails with a "Permission Denied" error because the current working // directory cannot be set properly via exec(). Note that exec() works // fine when executing in the web environment but fails in CLI. - $descriptorSpec = [ + $descriptorSpec = array( 0 => array('pipe', 'r'), //STDIN 1 => array('pipe', 'w'), //STDOUT 2 => array('pipe', 'w'), //STDERR - ]; + ); if ($proc = proc_open($command, $descriptorSpec, $pipes, getcwd())) { $output = stream_get_contents($pipes[1]); $errors = stream_get_contents($pipes[2]); From 6751c63366bd36b35cfd18a5b2ef8b78551013e5 Mon Sep 17 00:00:00 2001 From: Daniel Berthereau Date: Mon, 8 Jan 2018 00:00:00 +0100 Subject: [PATCH 2/2] Updated for the new site. --- README.md | 6 +- .../Controller/Action/Helper/Addons.php | 107 ++++++++++-------- plugin.ini | 4 +- views/admin/index/index.php | 2 +- 4 files changed, 65 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index 6008e29..948cd3e 100644 --- a/README.md +++ b/README.md @@ -26,8 +26,8 @@ Warning Use it at your own risk. -It’s always recommended to backup your files and database regularly so you can -roll back if needed. +It’s always recommended to backup your files and your databases and to check +your archives regularly so you can roll back if needed. Troubleshooting @@ -69,7 +69,7 @@ Copyright --------- * Copyright AcuGIS, 2017 -* Copyright Daniel Berthereau, 2017 +* Copyright Daniel Berthereau, 2017-2018 [Escher]: https://github.com/AcuGIS/Escher diff --git a/libraries/Escher/Controller/Action/Helper/Addons.php b/libraries/Escher/Controller/Action/Helper/Addons.php index 08d6c8b..ffe837f 100644 --- a/libraries/Escher/Controller/Action/Helper/Addons.php +++ b/libraries/Escher/Controller/Action/Helper/Addons.php @@ -24,11 +24,11 @@ class Escher_Controller_Action_Helper_Addons extends Zend_Controller_Action_Help */ protected $data = array( 'omekaplugin' => array( - 'source' => 'https://omeka.org/add-ons/plugins/', + 'source' => 'https://omeka.org/classic/plugins/', 'destination' => PLUGIN_DIR, ), 'omekatheme' => array( - 'source' => 'https://omeka.org/add-ons/themes/', + 'source' => 'https://omeka.org/classic/themes/', 'destination' => PUBLIC_THEME_DIR, ), 'plugin' => array( @@ -300,58 +300,69 @@ protected function extractAddonListFromOmeka($html, $type) libxml_use_internal_errors(true); $pokemon_doc = new DOMDocument(); - $pokemon_doc->loadHTML($html); + $result = $pokemon_doc->loadHTML($html); $pokemon_xpath = new DOMXPath($pokemon_doc); - $pokemon_row = $pokemon_xpath->query('//a[@class="omeka-addons-button"]/@href'); - if ($pokemon_row->length > 0) { - foreach ($pokemon_row as $row) { - $url = $row->nodeValue; - $filename = basename(parse_url($url, PHP_URL_PATH)); - list($name, $version) = $this->_extractNameAndVersion($filename); - if (empty($name)) { - continue; - } - - $addonName = preg_replace('~[^A-Za-z0-9]~', '', $name); - $server = strtolower(parse_url($url, PHP_URL_HOST)); - $zip = $url; - - $addon = array(); - $addon['type'] = $type; - $addon['name'] = str_replace(array('-', '_'), ' ', $name); - $addon['basename'] = $addonName; - $addon['dir'] = $addonName; - $addon['version'] = $version; - $addon['zip'] = $zip; - $addon['server'] = $server; - - $list[$url] = $addon; + + // New format is the one of Github: /TagVersion/NameGivenByAuthor.zip. + switch ($type) { + case 'omekaplugin': + $query = '//div[@id="module-list"]/div[@class="module"]/div[@class="download"]/a[@class="button"]/@href'; + break; + case 'omekatheme': + $query = '//div[@id="theme-list"]/div[@class="theme"]/div[@class="download"]/a[@class="button"]/@href'; + break; + default: + return []; + } + + $pokemon_row = $pokemon_xpath->query($query); + if ($pokemon_row->length <= 0) { + // Check if the site is still broken. + $html = str_replace('', '', $html); + $pokemon_doc = new DOMDocument(); + $result = $pokemon_doc->loadHTML($html); + $pokemon_xpath = new DOMXPath($pokemon_doc); + $pokemon_row = $pokemon_xpath->query($query); + if ($pokemon_row->length <= 0) { + return array(); } } - return $list; - } + foreach ($pokemon_row as $row) { + $url = $row->nodeValue; + $filename = basename(parse_url($url, PHP_URL_PATH)); + $query = '//a[@href="' . $url . '"]/../../div/h4/a'; + $name_row = $pokemon_xpath->query($query); + if (empty($name_row)) { + continue; + } + $name = $name_row->item(0)->nodeValue; - /** - * Helper to extract the name and the version from the name of a zip file. - * - * @param string $filename - * @return array - */ - protected function _extractNameAndVersion($filename) - { - // Some addons have "-" in name; some have letters in version. - $result = preg_match('~([^\d]+)\-(\d.*)\.zip~', $filename, $matches); - // Manage for example "Select2". - if (empty($matches)) { - $result = preg_match('~(.*?)\-(\d.*)\.zip~', $filename, $matches); - } - if (empty($matches)) { - return array(null, null); + $query = '//a[@href="' . $url . '"]/../span[@class="version"]'; + $version_row = $pokemon_xpath->query($query); + $version = $version_row->item(0)->nodeValue; + $version = trim(str_replace('Latest Version:', '', $version)); + + $query = '//a[@href="' . $url . '"]/../../div/h4/a/@href'; + $addon_row = $pokemon_xpath->query($query); + $addonName = $addon_row->item(0)->nodeValue; + + $server = strtolower(parse_url($url, PHP_URL_HOST)); + $zip = $url; + + $addon = array(); + $addon['type'] = $type; + $addon['name'] = $name; + $addon['basename'] = $addonName; + $addon['dir'] = $addonName; + $addon['version'] = $version; + $addon['zip'] = $zip; + $addon['server'] = $server; + + $list[$url] = $addon; } - $name = $matches[1]; - $version = $matches[2]; - return array($name, $version); + + return $list; } /** diff --git a/plugin.ini b/plugin.ini index d0f990e..f124fc2 100644 --- a/plugin.ini +++ b/plugin.ini @@ -6,6 +6,6 @@ tags = "utility, admin" license="GPLv3" link="https://www.acugis.com" support_link="https://forum.omeka.org" -version="2.3.2" +version="2.4.0" omeka_minimum_version="2.0" -omeka_target_version="2.5" +omeka_target_version="2.5.1" diff --git a/views/admin/index/index.php b/views/admin/index/index.php index 49cd815..98b2c03 100644 --- a/views/admin/index/index.php +++ b/views/admin/index/index.php @@ -15,7 +15,7 @@ ', '', '', '', - '', ''); ?> + '', ''); ?>