Skip to content

Commit

Permalink
Merge branch 'xupdate' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
nao-pon committed Dec 29, 2012
2 parents b174e13 + 8dc39ce commit 7d1376f
Show file tree
Hide file tree
Showing 15 changed files with 221 additions and 81 deletions.
Expand Up @@ -89,7 +89,7 @@ <h3><{$dirname|xoops_escape:show}></h3>
</td>
</tr>
<{/if}>
<{if $options.writable_dir || $options.writable_file || $options.install_only || $options.delete_dir || $options.delete_file}>
<{if $options.writable_dir || $options.writable_file || $options.no_overwrite || $options.no_update || $options.delete_dir || $options.delete_file}>
<tr class="<{cycle values='odd,even'}>">
<td class="legacy_list_select">options</td>
<td class="legacy_list_select">
Expand All @@ -116,18 +116,29 @@ <h3><{$dirname|xoops_escape:show}></h3>
</tr>
<{/foreach}>
<{/if}>
<{if $options.install_only}>
<tr><th class="ehad" colspan="2"><{$smarty.const._AD_XUPDATE_LANG_INSTALL_ONLY}></th></tr>
<{if $options.no_overwrite}>
<tr><th class="ehad" colspan="2"><{$smarty.const._AD_XUPDATE_LANG_NO_OVERWRITE}></th></tr>
<{counter start=0 skip=1 assign=count}>
<{foreach from=$options.install_only item=_item}>
<{foreach from=$options.no_overwrite item=_item}>
<{counter assign=count}>
<tr>
<td class='even'><label for='install_only_<{$count}>'><{$_item}></label></td>
<td class='even'><input type='checkbox' name='install_only[]' id='install_only_<{$count}>' value='<{$_item}>' /></td>
<td class='even'><label for='no_overwrite_<{$count}>'><{$_item}></label></td>
<td class='even'><input type='checkbox' name='no_overwrite[]' id='no_overwrite_<{$count}>' value='<{$_item}>' /></td>
</tr>
<{/foreach}>
<{/if}>
<{if $options.delete_dir}>
<{if $options.no_update}>
<tr><th class="ehad" colspan="2"><{$smarty.const._AD_XUPDATE_LANG_NO_UPDATE}></th></tr>
<{counter start=0 skip=1 assign=count}>
<{foreach from=$options.no_update item=_item}>
<{counter assign=count}>
<tr>
<td class='even'><label for='no_update_<{$count}>'><{$_item}></label></td>
<td class='even'><input type='checkbox' name='no_update[]' id='no_update_<{$count}>' value='<{$_item}>' /></td>
</tr>
<{/foreach}>
<{/if}>
<{if $options.delete_dir}>
<tr><th class="ehad" colspan="2"><{$smarty.const._AD_XUPDATE_LANG_DELETE_DIR}></th></tr>
<{counter start=0 skip=1 assign=count}>
<{foreach from=$options.delete_dir item=_item}>
Expand Down
Expand Up @@ -89,7 +89,7 @@ <h3><{$dirname|xoops_escape:show}></h3>
</td>
</tr>
<{/if}>
<{if $options.writable_dir || $options.writable_file || $options.install_only || $options.delete_dir || $options.delete_file}>
<{if $options.writable_dir || $options.writable_file || $options.no_overwrite || $options.no_update || $options.delete_dir || $options.delete_file}>
<tr class="<{cycle values='odd,even'}>">
<td class="legacy_list_select">options</td>
<td class="legacy_list_select">
Expand All @@ -116,14 +116,25 @@ <h3><{$dirname|xoops_escape:show}></h3>
</tr>
<{/foreach}>
<{/if}>
<{if $options.install_only}>
<tr><th class="ehad" colspan="2"><{$smarty.const._AD_XUPDATE_LANG_INSTALL_ONLY}></th></tr>
<{if $options.no_overwrite}>
<tr><th class="ehad" colspan="2"><{$smarty.const._AD_XUPDATE_LANG_NO_OVERWRITE}></th></tr>
<{counter start=0 skip=1 assign=count}>
<{foreach from=$options.install_only item=_item}>
<{foreach from=$options.no_overwrite item=_item}>
<{counter assign=count}>
<tr>
<td class='even'><label for='install_only_<{$count}>'><{$_item}></label></td>
<td class='even'><input type='checkbox' name='install_only[]' id='install_only_<{$count}>' value='<{$_item}>' /></td>
<td class='even'><label for='no_overwrite_<{$count}>'><{$_item}></label></td>
<td class='even'><input type='checkbox' name='no_overwrite[]' id='no_overwrite_<{$count}>' value='<{$_item}>' /></td>
</tr>
<{/foreach}>
<{/if}>
<{if $options.no_update}>
<tr><th class="ehad" colspan="2"><{$smarty.const._AD_XUPDATE_LANG_NO_UPDATE}></th></tr>
<{counter start=0 skip=1 assign=count}>
<{foreach from=$options.no_update item=_item}>
<{counter assign=count}>
<tr>
<td class='even'><label for='no_update_<{$count}>'><{$_item}></label></td>
<td class='even'><input type='checkbox' name='no_update[]' id='no_update_<{$count}>' value='<{$_item}>' /></td>
</tr>
<{/foreach}>
<{/if}>
Expand Down
Expand Up @@ -62,7 +62,7 @@ <h3><{if $screen_shot}><img src="<{$screen_shot}>" alt="" /> <{/if}><{$dirname|x
<{$description}>
</td>
</tr>
<{if $options.writable_dir || $options.writable_file || $options.install_only || $options.delete_dir || $options.delete_file}>
<{if $options.writable_dir || $options.writable_file || $options.no_overwrite || $options.no_update || $options.delete_dir || $options.delete_file}>
<tr class="<{cycle values='odd,even'}>">
<td class="legacy_list_select">options</td>
<td class="legacy_list_select">
Expand All @@ -89,14 +89,25 @@ <h3><{if $screen_shot}><img src="<{$screen_shot}>" alt="" /> <{/if}><{$dirname|x
</tr>
<{/foreach}>
<{/if}>
<{if $options.install_only}>
<tr><th class="ehad" colspan="2"><{$smarty.const._AD_XUPDATE_LANG_INSTALL_ONLY}></th></tr>
<{if $options.no_overwrite}>
<tr><th class="ehad" colspan="2"><{$smarty.const._AD_XUPDATE_LANG_NO_OVERWRITE}></th></tr>
<{counter start=0 skip=1 assign=count}>
<{foreach from=$options.install_only item=_item}>
<{foreach from=$options.no_overwrite item=_item}>
<{counter assign=count}>
<tr>
<td class='even'><label for='install_only_<{$count}>'><{$_item}></label></td>
<td class='even'><input type='checkbox' name='install_only[]' id='install_only_<{$count}>' value='<{$_item}>' /></td>
<td class='even'><label for='no_overwrite_<{$count}>'><{$_item}></label></td>
<td class='even'><input type='checkbox' name='no_overwrite[]' id='no_overwrite_<{$count}>' value='<{$_item}>' /></td>
</tr>
<{/foreach}>
<{/if}>
<{if $options.no_update}>
<tr><th class="ehad" colspan="2"><{$smarty.const._AD_XUPDATE_LANG_NO_UPDATE}></th></tr>
<{counter start=0 skip=1 assign=count}>
<{foreach from=$options.no_update item=_item}>
<{counter assign=count}>
<tr>
<td class='even'><label for='no_update_<{$count}>'><{$_item}></label></td>
<td class='even'><input type='checkbox' name='no_update[]' id='no_update_<{$count}>' value='<{$_item}>' /></td>
</tr>
<{/foreach}>
<{/if}>
Expand Down
Expand Up @@ -70,7 +70,7 @@ <h4><{$storeObject->getShow('name')}></h4>
<a href="index.php?action=ThemeStore&amp;<{$pageNavi->getPrefix()}><{$sid_query}><{$filter_query}>sort=<{$smarty.const.MODULE_SORT_KEY_LASTUPDATE}>"><img src="<{"icons/up.png"|theme}>" alt="<{$smarty.const._ASCENDING}>" title="<{$smarty.const._ASCENDING}>" /></a>
<a href="index.php?action=ThemeStore&amp;<{$pageNavi->getPrefix()}><{$sid_query}><{$filter_query}>sort=-<{$smarty.const.MODULE_SORT_KEY_LASTUPDATE}>"><img src="<{"icons/down.png"|theme}>" alt="<{$smarty.const._DESCENDING}>" title="<{$smarty.const._DESCENDING}>" /></a>
</th>
<th><{$smarty.const._AD_LEGACY_LANG_PACKAGE}>
<th colspan="2"><{$smarty.const._AD_LEGACY_LANG_PACKAGE}>
<a href="index.php?action=ThemeStore&amp;<{$pageNavi->getPrefix()}><{$sid_query}><{$filter_query}>sort=<{$smarty.const.MODULE_SORT_KEY_TARGET_KEY}>"><img src="<{"icons/up.png"|theme}>" alt="<{$smarty.const._ASCENDING}>" title="<{$smarty.const._ASCENDING}>" /></a>
<a href="index.php?action=ThemeStore&amp;<{$pageNavi->getPrefix()}><{$sid_query}><{$filter_query}>sort=-<{$smarty.const.MODULE_SORT_KEY_TARGET_KEY}>"><img src="<{"icons/down.png"|theme}>" alt="<{$smarty.const._DESCENDING}>" title="<{$smarty.const._DESCENDING}>" /></a>
</th>
Expand Down Expand Up @@ -125,11 +125,14 @@ <h4><{$storeObject->getShow('name')}></h4>
<{$module->getVar('last_update')|xoops_formattimestamp:l}>
<{/if}>
</td>
<td class="legacy_list_screenshot">
<{if $module->options.screen_shot}><img src="<{$module->options.screen_shot}>" align="middle" height="60" /><{/if}>
</td>
<td class="legacy_list_select">
<{if $module->getShow('detail_url')}>
<a href="<{$module->getShow('detail_url')}>" target="_blank"><{if $module->options.screen_shot}><img src="<{$module->options.screen_shot}>" align="middle" height="60" /> <{/if}><{$module->getShow('target_key')}></a>
<a href="<{$module->getShow('detail_url')}>" target="_blank"><{$module->getShow('target_key')}></a>
<{else}>
<{if $module->options.screen_shot}><img src="<{$module->options.screen_shot}>" align="middle" height="60" /> <{/if}><{$module->getShow('target_key')}>
<{$module->getShow('target_key')}>
<{/if}>
<br/><{$module->get('description')}>
</td>
Expand Down Expand Up @@ -163,7 +166,7 @@ <h4><{$storeObject->getShow('name')}></h4>
</tr>
<{/foreach}>
<tr>
<td class="foot" colspan="<{if $sid}>3<{else}>4<{/if}>">
<td class="foot" colspan="<{if $sid}>4<{else}>5<{/if}>">
<{xoops_token form=$actionForm}>
</td>
<td class="foot" colspan="2">
Expand All @@ -181,3 +184,19 @@ <h4><{$storeObject->getShow('name')}></h4>
<{include file="admin_tagcloud.html"}>

</div>

<script type="text/javascript">
jQuery(function($) {
var popup = $('<img>').css('position', 'absolute'), next;

$('.legacy_list_screenshot img').hover(
function() {
popup.attr('src', $(this).attr('src')).css($(this).parent('td').next().offset());
$('body').append(popup);
},
function() {
popup.remove();
}
);
})
</script>
Expand Up @@ -274,22 +274,20 @@ public function executeViewSuccess(&$render)
}
}
}
$_arr = $this->Xupdate->get('install_only');
if(!empty($this->options['install_only']) && count($this->options['install_only'])>0){
// checked means allow overwrite
$xupdateFtpModuleInstall->options['no_overwrite'] = array();
$xupdateFtpModuleInstall->options['install_only'] = array();
//if ( isset($mobj->mModule) && $mobj->mModule->get('isactive')==true ){
if ( isset($mobj->mModule) ){
foreach ($this->options['install_only'] as $item){
$_key = 'no_overwrite';
if (substr($item, -1) === '*') {
$_key = $is_install? 'no_overwrite' : 'install_only';
}
if ( !is_array($_arr) || (is_array($_arr) && !in_array( $item, $_arr ))){
$item = rtrim($item, '*');
$xupdateFtpModuleInstall->options[$_key][] = $item;
}
$_arr = $this->Xupdate->get('no_overwrite');
if(!empty($this->options['no_overwrite']) && count($this->options['no_overwrite'])>0){
foreach ($this->options['no_overwrite'] as $item){
if ( !is_array($_arr) || (is_array($_arr) && !in_array( $item, $_arr ))){
$xupdateFtpModuleInstall->options['no_overwrite'][] = $item;
}
}
}
$_arr = $this->Xupdate->get('no_update');
if(!empty($this->options['no_update']) && count($this->options['no_update'])>0){
$_key = $is_install? 'no_overwrite' : 'no_update';
foreach ($this->options['no_update'] as $item){
if ( !is_array($_arr) || (is_array($_arr) && !in_array( $item, $_arr ))){
$xupdateFtpModuleInstall->options[$_key][] = $item;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions xoops_trust_path/modules/xupdate/class/Ftp.class.php
Expand Up @@ -465,9 +465,9 @@ private function _getFileList($dir, $list=array('dir'=> array(), 'file' => array

private function _dont_overwrite($file, $dir_chk = false)
{
list($no_overwrite, $install_only) = $this->no_overwrite;
if ($install_only) {
foreach ($install_only as $item) {
list($no_overwrite, $no_update) = $this->no_overwrite;
if ($no_update) {
foreach ($no_update as $item) {
if( strpos($file, $item) === 0){
return true;
}
Expand Down
71 changes: 55 additions & 16 deletions xoops_trust_path/modules/xupdate/class/XupdateUtils.class.php
Expand Up @@ -107,19 +107,58 @@ public static function toShow($str) {
* @param int $limit
* @return string
*/
public static function getRedirectUrl($url) {
$headers = get_headers($url, 1);
$location = isset($headers['Location'])? $headers['Location'] : (isset($headers['location'])? $headers['location'] : '');
if ($location) {
if (is_array($location)) {
$url = array_pop($location);
} else {
$url = $location;
public static function getRedirectUrl($url, $redirect = 10) {
if ($headers = @ get_headers($url, 1)) {
$location = isset($headers['Location'])? $headers['Location'] : (isset($headers['location'])? $headers['location'] : '');
if ($location) {
if (is_array($location)) {
$url = array_pop($location);
} else {
$url = $location;
}
}
} else {
$url = self::curlGetRedirectUrl($url);
}
return $url;
}

/**
* Get redirect URL with cURL
*
* @param $url
* @param $ch
* @param $max_redirect
* @param $redirects
* @return string
*/
public static function curlGetRedirectUrl($url, $ch = null, $max_redirect = 10, $redirects = 0) {
if ($max_redirect < $redirects) {
return $url;
}
if (! $ch) {
$ch = curl_init($url);
}
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

$data = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307) {
list($header) = explode("\r\n\r\n", $data, 2);
if (preg_match('/(?:Location:|URI:)(.*?)\n/i', $header, $matches)) {
$url = trim($matches[1]);
curl_setopt($ch, CURLOPT_URL, $url);
$redirects++;
return self::curlGetRedirectUrl($url, $ch, $max_redirect, $redirects);
}
}
curl_close($ch);
return $url;
}

/**
* Check, Is directory writable
*
Expand All @@ -129,14 +168,14 @@ public static function getRedirectUrl($url) {
public static function checkDirWritable($dir) {
$ret = false;
$dir = rtrim($dir, '/\\');
if (!empty($dir) && is_dir($dir)) {
$test = $dir . DIRECTORY_SEPARATOR . 'writable.check';
if (@ touch($test)) {
$ret = true;
unlink($test);
} else {
$ret = false;
}
if (!empty($dir) && is_dir($dir)) {
$test = $dir . DIRECTORY_SEPARATOR . 'writable.check';
if (@ touch($test)) {
$ret = true;
unlink($test);
} else {
$ret = false;
}
}
return $ret;
}
Expand Down
Expand Up @@ -112,7 +112,7 @@ public function setmModule($readini = true)
if ($readini) {
if (($this->getVar('version') && $this->mModule->getVar('version') < $this->getVar('version'))
||
(isset($this->modinfo['detailed_version']) && $this->modinfo['detailed_version'] != $this->options['detailed_version'])) {
(isset($this->modinfo['detailed_version']) && $this->_check_hasupdate($this->modinfo['detailed_version'], $this->options['detailed_version']))) {
$this->setVar('hasupdate', 1);
} else {
$this->setVar('hasupdate', 0);
Expand Down Expand Up @@ -224,7 +224,7 @@ public function setmModule($readini = true)
$this->setVar('options', serialize($this->options));
if (($this->getVar('version') && $this->mModule->getVar('version') < $this->getVar('version'))
||
(isset($this->modinfo['detailed_version']) && $this->modinfo['detailed_version'] != $this->options['detailed_version'])) {
(isset($this->modinfo['detailed_version']) && $this->_check_hasupdate($this->modinfo['detailed_version'], $this->options['detailed_version']))) {
$this->setVar('hasupdate', 1);
} else {
$this->setVar('hasupdate', 0);
Expand Down Expand Up @@ -365,10 +365,15 @@ public function unserialize_options($readini = false)
} else {
$options['writable_file'] = array();
}
if(isset($options['install_only'])) {
if (! $readini) array_walk( $options['install_only'], array($this, '_printf'), array($dirname, XOOPS_ROOT_PATH, XOOPS_TRUST_PATH) );
if(isset($options['no_overwrite'])) {
if (! $readini) array_walk( $options['no_overwrite'], array($this, '_printf'), array($dirname, XOOPS_ROOT_PATH, XOOPS_TRUST_PATH) );
} else {
$options['install_only'] = array();
$options['no_overwrite'] = array();
}
if(isset($options['no_update'])) {
if (! $readini) array_walk( $options['no_update'], array($this, '_printf'), array($dirname, XOOPS_ROOT_PATH, XOOPS_TRUST_PATH) );
} else {
$options['no_update'] = array();
}
if(isset($options['delete_dir'])) {
if (! $readini) array_walk( $options['delete_dir'], array($this, '_printf'), array($dirname, XOOPS_ROOT_PATH, XOOPS_TRUST_PATH) );
Expand Down Expand Up @@ -421,6 +426,21 @@ private function _getStoreNameBySid($sid) {
}
return $names[$sid];
}

/**
* Check hasupdate (compare $version1[local], $version2[fetched])
*
* @param $version1
* @param $version2
* @return boolean
*/
private function _check_hasupdate($version1, $version2) {
if (preg_match('/\d+/', $version1) && preg_match('/\d+/', $version2)) {
return version_compare($version1, $version2, '<');
} else {
return ($version1 != $version2);
}
}

} // end class

Expand Down
Expand Up @@ -119,10 +119,10 @@ public function execute( $caller )
if(! isset($this->options['no_overwrite'])){
$this->options['no_overwrite'] = array();
}
if(! isset($this->options['install_only'])){
$this->options['install_only'] = array();
if(! isset($this->options['no_update'])){
$this->options['no_update'] = array();
}
$this->Ftp->set_no_overwrite(array($this->options['no_overwrite'], $this->options['install_only']));
$this->Ftp->set_no_overwrite(array($this->options['no_overwrite'], $this->options['no_update']));
$GLOBALS['xupdate_stage'] = 5;
if (!$this->uploadFiles()){
$this->_set_error_log(_MI_XUPDATE_ERR_FTP_UPLOADFILES);
Expand Down

0 comments on commit 7d1376f

Please sign in to comment.