source: temp/test-xoops.ec-cube.net/html/modules/tinyd0/admin/mytplsform.php @ 405

Revision 405, 7.0 KB checked in by root, 20 years ago (diff)
Line 
1<?php
2// ------------------------------------------------------------------------- //
3//                              mytplsform.php                               //
4//               - XOOPS templates admin for each modules -                  //
5//                          GIJOE <http://www.peak.ne.jp/>                   //
6// ------------------------------------------------------------------------- //
7
8include_once( '../../../include/cp_header.php' ) ;
9include_once "../include/gtickets.php" ;
10include_once XOOPS_ROOT_PATH.'/class/template.php';
11
12include_once dirname(dirname(__FILE__)).'/include/Text_Diff.php' ;
13include_once dirname(dirname(__FILE__)).'/include/Text_Diff_Renderer.php' ;
14include_once dirname(dirname(__FILE__)).'/include/Text_Diff_Renderer_unified.php' ;
15
16$xoops_system_path = XOOPS_ROOT_PATH . '/modules/system' ;
17
18// initials
19$db =& Database::getInstance();
20$myts =& MyTextSanitizer::getInstance() ;
21
22// determine language
23$language = $xoopsConfig['language'] ;
24if( ! file_exists( "$xoops_system_path/language/$language/admin/tplsets.php") ) $language = 'english' ;
25
26// load language constants
27// to prevent from notice that constants already defined
28$error_reporting_level = error_reporting( 0 ) ;
29include_once( "$xoops_system_path/constants.php" ) ;
30include_once( "$xoops_system_path/language/$language/admin.php" ) ;
31include_once( "$xoops_system_path/language/$language/admin/tplsets.php" ) ;
32error_reporting( $error_reporting_level ) ;
33
34// check $xoopsModule
35if( ! is_object( $xoopsModule ) ) redirect_header( XOOPS_URL.'/user.php' , 1 , _NOPERM ) ;
36
37// check access right (needs system_admin of tplset)
38$sysperm_handler =& xoops_gethandler('groupperm');
39if (!$sysperm_handler->checkRight('system_admin', XOOPS_SYSTEM_TPLSET, $xoopsUser->getGroups())) redirect_header( XOOPS_URL.'/user.php' , 1 , _NOPERM ) ;
40
41// tpl_file from $_GET
42$tpl_file = $myts->stripSlashesGPC( @$_GET['tpl_file'] ) ;
43$tpl_file = str_replace( 'db:' , '' , $tpl_file ) ;
44$tpl_file4sql = addslashes( $tpl_file ) ;
45
46// tpl_file from $_GET
47$tpl_tplset = $myts->stripSlashesGPC( @$_GET['tpl_tplset'] ) ;
48if( ! $tpl_tplset ) $tpl_tplset = $xoopsConfig['template_set'] ;
49$tpl_tplset4sql = addslashes( $tpl_tplset ) ;
50
51// get information from tplfile table
52$sql = "SELECT * FROM ".$db->prefix("tplfile")." f NATURAL LEFT JOIN ".$db->prefix("tplsource")." s WHERE f.tpl_file='$tpl_file4sql' ORDER BY f.tpl_tplset='$tpl_tplset4sql' DESC,f.tpl_tplset='default' DESC" ;
53$tpl = $db->fetchArray( $db->query( $sql ) ) ;
54
55// error in specifying tpl_file
56if( empty( $tpl ) ) {
57    if( strncmp( $tpl_file , 'file:' , 5 ) === 0 ) {
58        die( 'Not DB template' ) ;
59    } else {
60        die( 'Invalid tpl_file.' ) ;
61    }
62}
63
64//************//
65// POST stage //
66//************//
67if( ! empty( $_POST['do_modify'] ) ) {
68    // Ticket Check
69    if ( ! $xoopsGTicket->check() ) {
70        redirect_header(XOOPS_URL.'/',3,$xoopsGTicket->getErrors());
71    }
72
73    $result = $db->query( "SELECT tpl_id FROM ".$db->prefix("tplfile")." WHERE tpl_file='$tpl_file4sql' AND tpl_tplset='".addslashes($tpl['tpl_tplset'])."'" ) ;
74    while( list( $tpl_id ) = $db->fetchRow( $result ) ) {
75        $sql = "UPDATE ".$db->prefix("tplsource")." SET tpl_source='".addslashes($myts->stripSlashesGPC($_POST['tpl_source']))."' WHERE tpl_id=$tpl_id" ;
76        if( ! $db->query( $sql ) ) die( 'SQL Error' ) ;
77        $db->query( "UPDATE ".$db->prefix("tplfile")." SET tpl_lastmodified=UNIX_TIMESTAMP() WHERE tpl_id=$tpl_id" ) ;
78        xoops_template_touch( $tpl_id ) ;
79    }
80    redirect_header( 'mytplsadmin.php?dirname='.$tpl['tpl_module'] , 1 , _MD_AM_DBUPDATED ) ;
81    exit ;
82}
83
84
85
86
87xoops_cp_header() ;
88$mymenu_fake_uri = "/admin/mytplsadmin.php?dirname={$tpl['tpl_module']}" ;
89if( file_exists( './mymenu.php' ) ) include( './mymenu.php' ) ;
90
91echo "<h3 style='text-align:left;'>"._MD_AM_TPLSETS." : ".htmlspecialchars($tpl['tpl_type'],ENT_QUOTES)." : ".htmlspecialchars($tpl['tpl_file'],ENT_QUOTES)." (".htmlspecialchars($tpl['tpl_tplset'],ENT_QUOTES).")</h3>\n" ;
92
93
94// diff from file to selected DB template
95$basefilepath = XOOPS_ROOT_PATH.'/modules/'.$tpl['tpl_module'].'/templates/'.($tpl['tpl_type']=='block'?'blocks/':'').$tpl['tpl_file'] ;
96$diff_from_file4disp = '' ;
97if( file_exists( $basefilepath ) ) {
98    $diff =& new Text_Diff( file( $basefilepath ) , explode("\n",$tpl['tpl_source']) ) ;
99    $renderer =& new Text_Diff_Renderer_unified();
100    $diff_str = htmlspecialchars( $renderer->render( $diff ) , ENT_QUOTES ) ;
101    foreach( explode( "\n" , $diff_str ) as $line ) {
102        if( ord( $line ) == 0x2d ) {
103            $diff_from_file4disp .= "<span style='color:red;'>".$line."</span>\n" ;
104        } else if( ord( $line ) == 0x2b ) {
105            $diff_from_file4disp .= "<span style='color:blue;'>".$line."</span>\n" ;
106        } else {
107            $diff_from_file4disp .= $line."\n" ;
108        }
109    }
110}
111
112// diff from DB-default to selected DB template
113$diff_from_default4disp = '' ;
114if( $tpl['tpl_tplset'] != 'default' ) {
115    list( $default_source ) = $db->fetchRow( $db->query( "SELECT tpl_source FROM ".$db->prefix("tplfile")." NATURAL LEFT JOIN ".$db->prefix("tplsource")." WHERE tpl_tplset='default' AND tpl_file='".addslashes($tpl['tpl_file'])."' AND tpl_module='".addslashes($tpl['tpl_module'])."'" ) ) ;
116    $diff =& new Text_Diff( explode("\n",$default_source) , explode("\n",$tpl['tpl_source']) ) ;
117    $renderer =& new Text_Diff_Renderer_unified();
118    $diff_str = htmlspecialchars( $renderer->render( $diff ) , ENT_QUOTES ) ;
119    foreach( explode( "\n" , $diff_str ) as $line ) {
120        if( ord( $line ) == 0x2d ) {
121            $diff_from_default4disp .= "<span style='color:red;'>".$line."</span>\n" ;
122        } else if( ord( $line ) == 0x2b ) {
123            $diff_from_default4disp .= "<span style='color:blue;'>".$line."</span>\n" ;
124        } else {
125            $diff_from_default4disp .= $line."\n" ;
126        }
127    }
128}
129
130
131echo "
132    <form name='diff_form' id='diff_form' action='' method='get'>
133    <input type='checkbox' name='display_diff2file' value='1' onClick=\"if(this.checked){document.getElementById('diff2file').style.display='block'}else{document.getElementById('diff2file').style.display='none'};\" id='display_diff2file' checked='checked' />&nbsp;<label for='display_diff2file'>diff from file</label>
134    <pre id='diff2file' style='display:block;border:1px solid black;'>$diff_from_file4disp</pre>
135    <input type='checkbox' name='display_diff2default' value='1' onClick=\"if(this.checked){document.getElementById('diff2default').style.display='block'}else{document.getElementById('diff2default').style.display='none'};\" id='display_diff2default' />&nbsp;<label for='display_diff2default'>diff from default</label>
136    <pre id='diff2default' style='display:none;border:1px solid black;'>$diff_from_default4disp</pre>
137    </form>\n" ;
138
139
140echo "
141<form name='MainForm' action='?tpl_file=".htmlspecialchars($tpl['tpl_file'],ENT_QUOTES)."&amp;tpl_tplset=".htmlspecialchars($tpl['tpl_tplset'],ENT_QUOTES)."' method='post'>
142    ".$xoopsGTicket->getTicketHtml( __LINE__ )."
143    <textarea name='tpl_source' wrap='off' style='width:600px;height:400px;'>".htmlspecialchars($tpl['tpl_source'],ENT_QUOTES)."</textarea>
144    <br />
145    <input type='submit' name='do_modify' value='"._SUBMIT."' />
146    <input type='reset' name='reset' value='reset' />
147</form>\n" ;
148
149xoops_cp_footer() ;
150
151?>
Note: See TracBrowser for help on using the repository browser.