www.gusucode.com > 网猫影视系统NetMao Movie 4.6.6 开源版源码程序 > upload/admin/part7.inc.php
<?php /* *###################################### * Netmao Movie 4.x - NetMao Movie System * Copyright (c) 2007-2008 NetMao.cn * For further information go to http://www.netmao.cn/ * This copyright notice must stay intact for use. *###################################### */ if(!defined('IN_NetMao') || !isset($PHP_SELF) || !preg_match("/[\/\\\\]nmadmin\.php$/", $PHP_SELF)) exit('Access Denied'); if($action == 'templates') { if(!$edit) { if(!$tplsubmit) { $tpls = ''; $query = $db->query("SELECT * FROM {$tablepre}templates"); while($tpl = $db->fetch_array($query)) { $tpls[] = $tpl; } nmcptpl('templates'); } else { if($newname) { if(!$newdirectory) { nmsg('templates_new_directory_invalid','','back'); } elseif(!istpldir($newdirectory)) { $directory = $newdirectory; nmsg('templates_directory_invalid','','back'); } $db->query("INSERT INTO {$tablepre}templates (name, directory, copyright) VALUES ('$newname', '$newdirectory', '$newcopyright')"); } foreach($directorynew as $id => $directory) { if(!$delete || ($delete && !in_array($id, $delete))) { if(!istpldir($directory)) { nmsg('templates_directory_invalid','','back'); } elseif($id == 1 && $directory != './templates/default') { nmsg('templates_default_directory_invalid','','back'); } $db->query("UPDATE {$tablepre}templates SET name='$namenew[$id]', directory='$directorynew[$id]' WHERE templateid='$id'"); } } if($ids = implodeids( $delete )) { if(in_array('1', $delete)) { nmsg('templates_delete_invalid','','back'); } $db->query("DELETE FROM {$tablepre}templates WHERE templateid IN ($ids) AND templateid<>'1'"); $db->query("UPDATE {$tablepre}styles SET templateid='1' WHERE templateid IN ($ids)"); } updatecache('styles'); nmsg('templates_update_succeed', '?action=templates'); } } else { $query = $db->query("SELECT * FROM {$tablepre}templates WHERE templateid='$edit'"); if(!$template = $db->fetch_array($query)) { nmsg('undefined_action','','back'); } elseif(!istpldir($template['directory'])) { $directory = $template['directory']; nmsg('templates_directory_invalid','','back'); } $warning = $template['templateid'] == 1 ? $lang['templates_edit_default_comment'] : $lang['templates_edit_nondefault_comment']; if($keyword) { $keywordadd = " - $lang[templates_keyword] <i>".htmlspecialchars(stripslashes($keyword))."</i> - <a href=\"?action=templates&edit=$edit\" style=\"color: #FFFFFF\">[ $cplang[templates_view_all] ]</a>"; $keywordenc = rawurlencode($keyword); } $tpldir = dir(NetMao_ROOT.'./'.$template['directory']); $tplarray = $langarray = array(); while($entry = $tpldir->read()) { $extmid = strtolower(tplext($entry)); $extend = strtolower(fileext($entry)); if($extend == 'htm') { $tplname = substr($entry, 0, -4); $pos = strpos($tplname, '_'); if($keyword) { if(!stristr(implode("\n", file(NetMao_ROOT."$template[directory]/$entry")), $keyword)) { continue; } } if(!$pos) { $tplarray[$tplname][] = $tplname; } else { $tplarray[substr($tplname, 0, $pos)][] = $tplname; } } elseif($extend == 'js') { if($keyword) { if(!stristr(implode("\n", file(NetMao_ROOT."$template[directory]/$entry")), $keyword)) { continue; } } $jsarray[] = substr($entry, 0, -3); } elseif($extmid == 'ctrl.php') { if($keyword) { if(!stristr(implode("\n", file(NetMao_ROOT."$template[directory]/$entry")), $keyword)) { continue; } } $ctrlarray[] = substr($entry, 0, -9); } elseif($extmid == 'lang.php') { if($keyword) { if(!stristr(implode("\n", file(NetMao_ROOT."$template[directory]/$entry")), $keyword)) { continue; } } $langarray[] = substr($entry, 0, -9); } } $tpldir->close(); ksort($tplarray); ksort($langarray); $templates = $languages = ''; foreach($tplarray as $tpl => $subtpls) { $templates .= "<ul><li><b>$tpl</b><ul>\n"; foreach($subtpls as $subtpl) { $filename = "$subtpl.htm"; $templates .= "<li>$subtpl <a href=\"?action=tpledit&templateid=$template[templateid]&fn=$filename&keyword=$keywordenc\">[$lang[edit]]</a> ". "<a href=\"?action=tpledit&templateid=$template[templateid]&fn=$filename&delete=yes\">[$lang[delete]]</a>"; } $templates .= "</ul></ul>\n"; } foreach($langarray as $langpack) { $languages .= "<ul><li>$langpack <a href=\"?action=tpledit&templateid=$template[templateid]&fn=$langpack.lang.php\">[$lang[edit]]</a></ul>\n"; } nmcptpl('templates'); } } elseif($action == 'tpledit') { $query = $db->query("SELECT * FROM {$tablepre}templates WHERE templateid='$templateid'"); if(!$template = $db->fetch_array($query)) { nmsg('templates_edit_nonexistence','','back'); } if (strstr($fn, '/') || strstr($fn, '..')) { nmsg('templates_edit_nonexistence','','back'); } $filename = NetMao_ROOT."$template[directory]/$fn"; if(!is_writeable($filename)) { nmsg('templates_edit_invalid','','back'); } if(!$editsubmit && $delete != 'yes') { $keywordenc = rawurlencode($keyword); $fp = @fopen($filename, 'rb'); $content = @fread($fp, filesize($filename)); fclose($fp); $content = str_replace("\\'", "'", htmlspecialchars($content)); include nmcptpl('templates'); } elseif($delete == 'yes') { if(!$confirmed) { nmsg('templates_delete_confirm', "?action=tpledit&templateid=$templateid&fn=$fn&delete=yes", 'form'); } else { if(@unlink($filename)) { nmsg('templates_delete_succeed', "?action=templates&edit=$templateid"); } else { nmsg('templates_delete_fail','','back'); } } } else { $fp = fopen($filename, 'w'); flock($fp, 2); fwrite($fp, stripslashes(str_replace("\x0d\x0a", "\x0a", $templatenew))); fclose($fp); nmsg('templates_edit_succeed', "?action=templates&edit=$templateid&keyword=$keyword"); } } elseif($action == 'tpladd') { $query = $db->query("SELECT * FROM {$tablepre}templates WHERE templateid='$edit'"); if(!$template = $db->fetch_array($query)) { nmsg('templates_add_invalid','','back'); } elseif(!istpldir($template['directory'])) { $directory = $template['directory']; nmsg('templates_directory_invalid1','','back'); } if($type=='ctrl'){ if(file_exists(NetMao_ROOT."$template[directory]/$name.ctrl.php")){ nmsg('templates_add_duplicate','','back'); }elseif(!@$fp = fopen(NetMao_ROOT."$template[directory]/$name.ctrl.php", 'w')){ nmsg('templates_add_file_invalid','','back'); } @fclose($fp); nmsg('templates_add_succeed', "?action=tpledit&templateid=1&fn=$name.ctrl.php"); }elseif($type=='js'){ if(file_exists(NetMao_ROOT."$template[directory]/$name.js")){ nmsg('templates_add_duplicate','','back'); }elseif(!@$fp = fopen(NetMao_ROOT."$template[directory]/$name.js", 'w')){ nmsg('templates_add_file_invalid','','back'); } @fclose($fp); nmsg('templates_add_succeed', "?action=tpledit&templateid=1&fn=$name.js"); }else{ if(file_exists(NetMao_ROOT."$template[directory]/$name.htm")){ nmsg('templates_add_duplicate','','back'); }elseif(!@$fp = fopen(NetMao_ROOT."$template[directory]/$name.htm", 'w')){ nmsg('templates_add_file_invalid','','back'); } @fclose($fp); nmsg('templates_add_succeed', "?action=tpledit&templateid=1&fn=$name.htm"); } } ?>