/*****************************************************************************\
+-----------------------------------------------------------------------------+
| X-Cart |
| Copyright (c) 2001-2002 Ruslan R. Fazliev. All rights reserved. |
+-----------------------------------------------------------------------------+
| The Ruslan R. Fazliev forbids, under any circumstances, the unauthorized |
| reproduction of software or use of illegally obtained software. Making |
| illegal copies of software is prohibited. Individuals who violate copyright |
| law and software licensing agreements may be subject to criminal or civil |
| action by the owner of the copyright. |
| |
| 1. It is illegal to copy a software, and install that single program for |
| simultaneous use on multiple machines. |
| |
| 2. Unauthorized copies of software may not be used in any way. This applies |
| even though you yourself may not have made the illegal copy. |
| |
| 3. Purchase of the appropriate number of copies of a software is necessary |
| for maintaining legal status. |
| |
| DISCLAIMER |
| |
| THIS SOFTWARE IS PROVIDED BY Ruslan R. Fazliev ``AS IS'' AND ANY |
| EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| DISCLAIMED. IN NO EVENT SHALL Ruslan R. Fazliev OR ITS |
| CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| |
| The Initial Developer of the Original Code is Ruslan R. Fazliev. |
| Portions created by Ruslan R. Fazliev are Copyright (C) 2001-2002 |
| Ruslan R. Fazliev. All Rights Reserved. |
+-----------------------------------------------------------------------------+
\*****************************************************************************/
#
# $Id: file_operations.php,v 1.19 2002/11/14 07:58:19 zorg Exp $
#
#
# Security check
#
$file = str_replace("..","",$file);
$dir = str_replace("..","",$dir);
$filename = str_replace("..","",$filename);
#
# This function generates a list of all files with ".tpl" extension
#
function list_all_templates ($dir, $parent_dir) {
$all_files=array();
if(!$handle = opendir($dir)) return $all_files;
while (false !== ($file = readdir($handle)))
if (is_file($dir."/".$file) && substr($file,-4,4)==".tpl")
$all_files[$parent_dir."/".$file]="Q";
elseif (is_dir($dir."/".$file) && $file != "." && $file != "..")
$all_files=array_merge($all_files, list_all_templates ($dir."/".$file,$parent_dir."/".$file))
;
closedir($handle);
return $all_files;
}
#
# Save file mode
#
if($REQUEST_METHOD=="POST" && $mode=="save_file") {
if($fw = @fopen($root_dir.$filename,"w")) {
fputs($fw, stripslashes($filebody));
fclose($fw);
}
else $smarty->assign("io_error","1");
$smarty->assign("filename",$filename);
$smarty->assign("main","edit_file_message");
} elseif ($REQUEST_METHOD=="POST" && $mode=="restore" && $filename) {
#
# This facility restores the corrupted template from the repository
#
if (!@copy($templates_repository.$filename, $root_dir.$filename))
$smarty->assign("io_error","1");
$smarty->assign("filename",$filename);
$smarty->assign("main","edit_file_message");
} elseif ($REQUEST_METHOD=="POST" && $mode=="restore_all") {
#
# Restore all files from $template_repository
#
$files_to_restore = list_all_templates ($templates_repository,"");
if(!empty($files_to_restore)) {
foreach($files_to_restore as $file_to_restore => $file_status) {
echo "Restoring $file_to_restore - ";
if (!@copy($templates_repository.$file_to_restore, $root_dir.$file_to_restore))
echo " FAILED TO RESTORE";
else
echo " successfully restored";
echo " \n";
flush();
}
exit;
} else {
$smarty->assign("io_error","3");
$smarty->assign ("main", "copy_file_message");
}
} elseif ($REQUEST_METHOD=="POST" && $mode=="compile_all") {
#
# Compile all files from $template_repository
#
set_time_limit(1800);
$files_to_restore = list_all_templates ($root_dir,"");
if(!empty($files_to_restore)) {
#
# Generate search and replace arrays for preg_replace
#
$search_array = array();
$search1_array = array();
$replace_array = array();
$replace1_array = array();
$language_entries = func_query("select name, value from $sql_tbl[languages] where code='$language'");
foreach($language_entries as $language_entry) {
$search_array[]="'{.lng\.$language_entry[name]}'";
$search1_array[]="'.lng\.$language_entry[name](\W)'";
$replace_array[]=$language_entry["value"];
$replace1_array[]="\"$language_entry[value]\"\\1";
}
#
# Perform compilation
#
foreach($files_to_restore as $file_to_restore => $file_status) {
echo "Compiling $file_to_restore - ";
if(is_writable($root_dir.$file_to_restore) && is_readable($root_dir.$file_to_restore)) {
$file_strings = file($root_dir.$file_to_restore);
$fp = fopen($root_dir.$file_to_restore, "w");
#
# Patching head.tpl to disable languages