📄 update.php
字号:
<?php/*** @package EasyGallery* @copyright (C) 2006 Joomla-addons.org* @author Adam van Dongen* @version $Id: update.php 4 2007-06-16 14:22:19Z websmurf $* * --------------------------------------------------------------------------------* All rights reserved. Easy Gallery Component for Joomla!** This program is free software; you can redistribute it and/or* modify it under the terms of the Joomla-addons Free Software License * See LICENSE.php for more information.** This program is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * --------------------------------------------------------------------------------**/defined( '_VALID_MOS' ) or die( 'Restricted access' );$xajax->registerFunction(array("compairHash", "update", "compairHash"), XAJAX_POST);$xajax->registerFunction(array("updateFile", "update", "updateFile"), XAJAX_POST);class update { /** * Show files and hashes * */ function show(){ global $option, $mainframe; $files = mosReadDirectory(PATH_EASYGALLERY, '.php', true, true); $f_files = mosReadDirectory($mainframe->getCfg('absolute_path') . '/components/com_easygallery', '.php', true, true); $files = array_merge($files, $f_files); $f = array(); for($i=0,$n=count($files);$i<$n;$i++){ $file = str_replace('\\', '/', $files[$i]); //skip backup files if(strpos($file, 'php-bak')){ continue; } $content = file_get_contents($file); $content = str_replace(array("\n", "\r"), '', $content); //remove breaks to avoid different md5 $hash = md5($content); $obj = new stdClass(); $obj->file = str_replace($mainframe->getCfg('absolute_path'), '', $file); $obj->hash = $hash; $f[] = $obj; } HTML_easygallery::showUpdates($f); } /** * Compair local hash with remote server. * * @param string $file * @param string $hash * @param int $id */ function compairHash($file, $hash, $id){ $objResponse = new xajaxResponse(); if(!function_exists('fopen') || !ini_get('allow_url_fopen')){ $objResponse->addAssign('file_' . $id, 'innerHTML', 'Fopen not defined or allow_url_fopen disabled'); return $objResponse->getXML(); } $return = ''; $fp = @fopen('http://www.joomla-addons.org/updates/easygallery' . str_replace(array('administrator/components/com_easygallery', 'components/com_easygallery'), '', $file) . '.txt', 'r'); if($fp){ $content = ""; do { $data = fread($fp, 8192); if (strlen($data) == 0) { break; } $content .= $data; } while(true); fclose ($fp); $content = str_replace(array("\n", "\r"), '', $content); //remove breaks to avoid different md5 $r_hash = md5($content); $return = ($hash == $r_hash ? '<font color="green">' . $r_hash . '</font>' : '<font color="red">' . $r_hash . '</font> <a href="javascript:void(0);" onclick="updateFile(\'' . $file . '\', \'' . $hash . '\', ' . $id . ');">[ update ]</a>'); } else { $objResponse->addAssign('file_' . $id, 'innerHTML', 'Error opening file on remote server'); return $objResponse->getXML(); } $objResponse->addAssign('file_' . $id, 'innerHTML', $return); return $objResponse->getXML(); } /** * Update file from remote version * * @param string $file */ function updateFile($file, $hash, $id, $no_ftp, $ftp_host, $ftp_port, $ftp_user, $ftp_pass, $ftp_path){ global $mainframe; $objResponse = new xajaxResponse(); if($no_ftp == false){ //use ftp if(!function_exists('ftp_connect')){ $objResponse->addAlert('The ftp_connect function is not available on your installation. Update cannot be performed'); return $objResponse->getXML(); } } if(!function_exists('fopen') || !ini_get('allow_url_fopen')){ $objResponse->addAlert('Fopen not defined or allow_url_fopen disabled'); return $objResponse->getXML(); } $fp = @fopen('http://www.joomla-addons.org/updates/easygallery' . str_replace(array('administrator/components/com_easygallery', 'components/com_easygallery'), '', $file) . '.txt', 'r'); if($fp){ $content = ""; do { $data = fread($fp, 8192); if (strlen($data) == 0) { break; } $content .= $data; } while(true); fclose ($fp); $r_hash = md5(str_replace(array("\n", "\r"), '', $content)); } else { $objResponse->addAlert('Error opening file on remote server'); return $objResponse->getXML(); } if($no_ftp == "false"){ //use ftp $ftp = ftp_connect($ftp_host, $ftp_port); if(!$ftp){ $objResponse->addAlert(sprintf('Failed to connect to host: %s', $ftp_host)); return $objResponse->getXML(); } if(!ftp_login($ftp, $ftp_user, $ftp_pass)){ $objResponse->addAlert('Login to ftp server failed'); return $objResponse->getXML(); } if(substr($ftp_path, 0, 1) != '/'){ $objResponse->addAlert('FTP path MUST start with a leading slash'); return $objResponse->getXML(); } $ftp_path = $ftp_path . '' . $file; if(file_exists($mainframe->getCfg('absolute_path') . '' . $file . '-bak')){ ftp_delete($ftp, $ftp_path . '-bak'); $objResponse->addAlert(sprintf('Backup file allready existed: %s, file deleted', $file . '-bak')); } $fp = fopen('http://www.joomla-addons.org/updates/easygallery' . str_replace(array('administrator/components/com_easygallery', 'components/com_easygallery'), '', $file) . '.txt', 'r'); if(!ftp_rename($ftp, $ftp_path, $ftp_path . '-bak')){ $objResponse->addAlert(sprintf('Failed to rename %s to %s', $file, $file . '-bak')); return $objResponse->getXML(); } if(!ftp_fput($ftp, $ftp_path, $fp, FTP_ASCII)){ $objResponse->addAlert(sprintf('Failed to write content to %s', $file)); return $objResponse->getXML(); } fclose($fp); } else { //use php to write if(file_exists($mainframe->getCfg('absolute_path') . '' . $file . '-bak')){ unlink($mainframe->getCfg('absolute_path') . '' . $file . '-bak'); $objResponse->addAlert(sprintf('Backup file allready existed: %s, file deleted', $file . '-bak')); } if(!rename($mainframe->getCfg('absolute_path') . '' . $file, $mainframe->getCfg('absolute_path') . '' . $file . '-bak')){ $objResponse->addAlert(sprintf('Failed to rename %s to %s', $file, $file . '-bak')); return $objResponse->getXML(); } $fp = fopen($mainframe->getCfg('absolute_path') . '' . $file, 'w+'); if(!fwrite($fp, $content)){ $objResponse->addAlert(sprintf('Failed to write content to %s', $file)); return $objResponse->getXML(); } fclose($fp); } $objResponse->addAlert('File updated');// $objResponse->addScript('compairFileHash(\''. $file . '\',\'' . $hash . '\',' . $id . ');'); $objResponse->addAssign('file_' . $id, 'innerHTML', '- refresh to re-check -'); return $objResponse->getXML(); }}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -