/** * Module Cloner file * * Enable webmasters to clone the news module. * * NOTE : Please give credits if you copy this code ! * * @package News * @author DNPROSSI * @copyright (c) DNPROSSI */ function nw_cloneFileFolder($path, $patterns) { $patKeys = array_keys($patterns); $patValues = array_values($patterns); // work around for PHP < 5.0.x if(!function_exists('file_put_contents')) { function file_put_contents($filename, $data, $file_append = false) { $fp = fopen($filename, (!$file_append ? 'w+' : 'a+')); if ( !$fp ) { trigger_error('file_put_contents cannot write in file.', E_USER_ERROR); return; } fputs($fp, $data); fclose($fp); } } $newpath = str_replace($patKeys[0], $patValues[0], $path); if ( is_dir($path) ) { // create new dir if ( !is_dir($newpath) ){ mkdir($newpath); }; // check all files in dir, and process them if ( $handle = opendir($path) ) { while ( $file = readdir($handle) ) { if ( $file != '.' && $file != '..' ) { nw_cloneFileFolder("$path/$file", $patterns); } } closedir($handle); } } else { //trigger_error('in else', E_USER_ERROR); if ( preg_match('/(.jpg|.gif|.png|.zip)$/i', $path) ) { copy($path, $newpath); } else { $content = file_get_contents($path); for ( $i = 0; $i < sizeof($patterns); ++$i ) { $content = str_replace($patKeys[$i], $patValues[$i], $content); } file_put_contents($newpath, $content); //trigger_error($path. ' ---- ' .$newpath , E_USER_WARNING); } } }
/** * Clone Upgrade - DNPROSSI */ function CloneUpgrade() { include_once "cloner.php"; global $xoopsDB, $xoopsConfig, $xoopsModule; if ( !isset($_GET['clone_id']) ) { //trigger_error("Not set", E_USER_WARNING); redirect_header('index.php?op=cloner', 5, _AM_NW_CLONER_NOMODULEID); } else { $cloneid = $_GET['clone_id']; $result = $xoopsDB->query("SELECT * FROM " . $xoopsDB->prefix('news_clonerdata') . " WHERE clone_id = " . $cloneid ); $ix = 0; while ( $clone = $xoopsDB->fetchArray($result) ) { $clone_arr[$ix] = $clone; $ix++; } $org_modulename = $xoopsModule->name(); $org_dirname = $xoopsModule->dirname(); $org_version = $xoopsModule->version(); $org_subprefix = NW_SUBPREFIX; $upg_modulename = $clone_arr[0]['clone_name']; $upg_dirname = $clone_arr[0]['clone_dir']; $upg_version = $clone_arr[0]['clone_version']; $upg_subprefix = $clone_arr[0]['clone_subprefix']; $patterns = array( $org_dirname => $upg_dirname, '$modversion["name"] = "' . $org_modulename . '"' => '$modversion["name"] = "' . $upg_modulename . '"', $org_subprefix => strtolower($upg_subprefix), strtoupper($org_subprefix) => strtoupper($upg_subprefix), ); $patKeys = array_keys($patterns); $patValues = array_values($patterns); $newPath = str_replace($patKeys[0], $patValues[0], NW_MODULE_PATH); $oldlogo = $newPath . "/" . $org_dirname . "_logo.png"; $newlogo = $newPath . "/" . $upg_dirname . "_logo.png"; nw_cloneFileFolder(NW_MODULE_PATH, $patterns); //rename logo.png @rename( $oldlogo, $newlogo ); $path_array[0] = $newPath . '/templates/'; $path_array[1] = $newPath . '/templates/blocks/'; nw_deleteclonefile($path_array, $upg_subprefix); // check all files in dir, and process them nw_clonefilename($path_array, $org_subprefix, $upg_subprefix); //Update module dtb $xoopsDB->queryF("UPDATE " . $xoopsDB->prefix('news_clonerdata') . " SET clone_version = " . $org_version . " WHERE clone_id = " . $cloneid); $label = sprintf(_AM_NW_CLONER_UPRADED, $upg_modulename); redirect_header('index.php?op=cloner', 5, $label); } }