Skip to content

Commit

Permalink
Updated for the new site.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-KM committed Jan 7, 2018
1 parent d99b82e commit 6751c63
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 54 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -69,7 +69,7 @@ Copyright
---------

* Copyright AcuGIS, 2017
* Copyright Daniel Berthereau, 2017
* Copyright Daniel Berthereau, 2017-2018


[Escher]: https://github.com/AcuGIS/Escher
Expand Down
107 changes: 59 additions & 48 deletions libraries/Escher/Controller/Action/Helper/Addons.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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('</footer>', '</nav></footer>', $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;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions plugin.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion views/admin/index/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<?php echo __('For more information on addons, see the pages %splugins%s and %sthemes%s or on %sOmeka.org%s.',
'<a href="https://daniel-km.github.io/UpgradeToOmekaS/omeka_plugins.html">', '</a>',
'<a href="https://daniel-km.github.io/UpgradeToOmekaS/omeka_themes.html">', '</a>',
'<a href="https://omeka.org/add-ons">', '</a>'); ?>
'<a href="https://omeka.org/classic">', '</a>'); ?>
</p>
<p class="explanation">
<?php echo _('Addons with an asterisk are already downloaded.'); ?>
Expand Down

0 comments on commit 6751c63

Please sign in to comment.