PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/myalbum0/include/blocksadmin.inc.php

https://github.com/severnaya99/Sg-2010
PHP | 260 lines | 196 code | 19 blank | 45 comment | 60 complexity | ad98c8d66f5a57543148386aafec7411 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-1.0, GPL-2.0
  1. <?php
  2. // $Id: main.php,v 1.12 2004/01/06 09:36:20 okazu Exp $
  3. // ------------------------------------------------------------------------ //
  4. // XOOPS - PHP Content Management System //
  5. // Copyright (c) 2000 XOOPS.org //
  6. // <http://www.xoops.org/> //
  7. // ------------------------------------------------------------------------ //
  8. // This program is free software; you can redistribute it and/or modify //
  9. // it under the terms of the GNU General Public License as published by //
  10. // the Free Software Foundation; either version 2 of the License, or //
  11. // (at your option) any later version. //
  12. // //
  13. // You may not change or alter any portion of this comment or credits //
  14. // of supporting developers from this source code or any supporting //
  15. // source code which is considered copyrighted (c) material of the //
  16. // original comment or credit authors. //
  17. // //
  18. // This program is distributed in the hope that it will be useful, //
  19. // but WITHOUT ANY WARRANTY; without even the implied warranty of //
  20. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
  21. // GNU General Public License for more details. //
  22. // //
  23. // You should have received a copy of the GNU General Public License //
  24. // along with this program; if not, write to the Free Software //
  25. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
  26. // ------------------------------------------------------------------------ //
  27. // Author: Kazumi Ono (AKA onokazu) //
  28. // URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //
  29. // Project: The XOOPS Project //
  30. // ------------------------------------------------------------------------- //
  31. if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) {
  32. exit("Access Denied");
  33. }
  34. include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php';
  35. include XOOPS_ROOT_PATH."/modules/system/admin/blocksadmin/blocksadmin.php";
  36. $op = "list";
  37. if ( isset($HTTP_POST_VARS) ) {
  38. foreach ( $HTTP_POST_VARS as $k => $v ) {
  39. $$k = $v;
  40. }
  41. }
  42. if ( isset($HTTP_GET_VARS['op']) ) {
  43. if ($HTTP_GET_VARS['op'] == "edit" || $HTTP_GET_VARS['op'] == "delete" || $HTTP_GET_VARS['op'] == "delete_ok" || $HTTP_GET_VARS['op'] == "clone" || $HTTP_GET_VARS['op'] == 'previewpopup') {
  44. $op = $HTTP_GET_VARS['op'];
  45. $bid = isset($HTTP_GET_VARS['bid']) ? intval($HTTP_GET_VARS['bid']) : 0;
  46. }
  47. }
  48. if (isset($previewblock)) {
  49. xoops_cp_header();
  50. include_once XOOPS_ROOT_PATH.'/class/template.php';
  51. $xoopsTpl = new XoopsTpl();
  52. $xoopsTpl->xoops_setCaching(0);
  53. if (isset($bid)) {
  54. $block['bid'] = $bid;
  55. $block['form_title'] = _AM_EDITBLOCK;
  56. $myblock = new XoopsBlock($bid);
  57. $block['name'] = $myblock->getVar('name');
  58. } else {
  59. if ($op == 'save') {
  60. $block['form_title'] = _AM_ADDBLOCK;
  61. } else {
  62. $block['form_title'] = _AM_CLONEBLOCK;
  63. }
  64. $myblock = new XoopsBlock();
  65. $myblock->setVar('block_type', 'C');
  66. }
  67. $myts =& MyTextSanitizer::getInstance();
  68. $myblock->setVar('title', $myts->stripSlashesGPC($btitle));
  69. $myblock->setVar('content', $myts->stripSlashesGPC($bcontent));
  70. $dummyhtml = '<html><head><meta http-equiv="content-type" content="text/html; charset='._CHARSET.'" /><meta http-equiv="content-language" content="'._LANGCODE.'" /><title>'.$xoopsConfig['sitename'].'</title><link rel="stylesheet" type="text/css" media="all" href="'.getcss($xoopsConfig['theme_set']).'" /></head><body><table><tr><th>'.$myblock->getVar('title').'</th></tr><tr><td>'.$myblock->getContent('S', $bctype).'</td></tr></table></body></html>';
  71. $dummyfile = '_dummyfile_'.time().'.html';
  72. $fp = fopen(XOOPS_CACHE_PATH.'/'.$dummyfile, 'w');
  73. fwrite($fp, $dummyhtml);
  74. fclose($fp);
  75. $block['edit_form'] = false;
  76. $block['template'] = '';
  77. $block['op'] = $op;
  78. $block['side'] = $bside;
  79. $block['weight'] = $bweight;
  80. $block['visible'] = $bvisible;
  81. $block['title'] = $myblock->getVar('title', 'E');
  82. $block['content'] = $myblock->getVar('content', 'E');
  83. $block['modules'] =& $bmodule;
  84. $block['ctype'] = isset($bctype) ? $bctype : $myblock->getVar('c_type');
  85. $block['is_custom'] = true;
  86. $block['cachetime'] = intval($bcachetime);
  87. echo '<a href="admin.php?fct=blocksadmin">'. _AM_BADMIN .'</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;'.$block['form_title'].'<br /><br />';
  88. include XOOPS_ROOT_PATH.'/modules/system/admin/blocksadmin/blockform.php';
  89. $form->display();
  90. xoops_cp_footer();
  91. echo '<script type="text/javascript">
  92. <!--//
  93. preview_window = openWithSelfMain("'.XOOPS_URL.'/modules/system/admin.php?fct=blocksadmin&op=previewpopup&file='.$dummyfile.'", "popup", 250, 200);
  94. //-->
  95. </script>';
  96. exit();
  97. }
  98. if ($op == 'previewpopup') {
  99. $file = str_replace('..', '', XOOPS_CACHE_PATH.'/'.trim($HTTP_GET_VARS['file']));
  100. if (file_exists($file)) {
  101. include $file;
  102. @unlink($file);
  103. }
  104. exit();
  105. }
  106. if ( $op == "list" ) {
  107. xoops_cp_header();
  108. list_blocks();
  109. xoops_cp_footer();
  110. exit();
  111. }
  112. if ( $op == "order" ) {
  113. foreach (array_keys($bid) as $i) {
  114. if( $side[$i] < 0 ) {
  115. $visible[$i] = 0 ;
  116. $side[$i] = -1 ;
  117. } else {
  118. $visible[$i] = 1 ;
  119. }
  120. $bmodule[$i] = (isset($bmodule[$i]) && is_array($bmodule[$i])) ? $bmodule[$i] : array(-1) ;
  121. myblocksadmin_update_block($i, $side[$i], $weight[$i], $visible[$i], $title[$i], '', '', $bcachetime[$i], $bmodule[$i], array());
  122. // if ( $oldweight[$i] != $weight[$i] || $oldvisible[$i] != $visible[$i] || $oldside[$i] != $side[$i] )
  123. // order_block($bid[$i], $weight[$i], $visible[$i], $side[$i]); GIJ
  124. }
  125. // redirect_header("admin.php?fct=blocksadmin",1,_AM_DBUPDATED); GIJ
  126. redirect_header("myblocksadmin.php",1,_AM_DBUPDATED);
  127. exit();
  128. }
  129. if ( $op == "save" ) {
  130. save_block($bside, $bweight, $bvisible, $btitle, $bcontent, $bctype, $bmodule, $bcachetime);
  131. exit();
  132. }
  133. if ( $op == "update" ) {
  134. $bcachetime = isset($bcachetime) ? intval($bcachetime) : 0;
  135. $options = isset($options) ? $options : array();
  136. $bcontent = isset($bcontent) ? $bcontent : '';
  137. $bctype = isset($bctype) ? $bctype : '';
  138. $bmodule = (isset($bmodule) && is_array($bmodule)) ? $bmodule : array(-1) ; // GIJ +
  139. $msg = myblocksadmin_update_block($bid, $bside, $bweight, $bvisible, $btitle, $bcontent, $bctype, $bcachetime, $bmodule, $options); // GIJ c
  140. redirect_header('myblocksadmin.php',1,$msg); // GIJ +
  141. }
  142. if ( $op == "delete_ok" ) {
  143. delete_block_ok($bid);
  144. exit();
  145. }
  146. if ( $op == "delete" ) {
  147. xoops_cp_header();
  148. delete_block($bid);
  149. xoops_cp_footer();
  150. exit();
  151. }
  152. if ( $op == "edit" ) {
  153. xoops_cp_header();
  154. edit_block($bid);
  155. xoops_cp_footer();
  156. exit();
  157. }
  158. /*
  159. if ($op == 'clone') {
  160. clone_block($bid);
  161. }
  162. if ($op == 'clone_ok') {
  163. clone_block_ok($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options);
  164. }
  165. */
  166. // import from modules/system/admin/blocksadmin/blocksadmin.php
  167. function myblocksadmin_update_block($bid, $bside, $bweight, $bvisible, $btitle, $bcontent, $bctype, $bcachetime, $bmodule, $options=array())
  168. {
  169. global $xoopsConfig;
  170. if (empty($bmodule)) {
  171. xoops_cp_header();
  172. xoops_error(sprintf(_AM_NOTSELNG, _AM_VISIBLEIN));
  173. xoops_cp_footer();
  174. exit();
  175. }
  176. $myblock = new XoopsBlock($bid);
  177. // $myblock->setVar('side', $bside); GIJ -
  178. if( $bside >= 0 ) $myblock->setVar('side', $bside); // GIJ +
  179. $myblock->setVar('weight', $bweight);
  180. $myblock->setVar('visible', $bvisible);
  181. $myblock->setVar('title', $btitle);
  182. $myblock->setVar('content', $bcontent);
  183. $myblock->setVar('bcachetime', $bcachetime);
  184. if ( isset($options) && (count($options) > 0) ) {
  185. $options = implode('|', $options);
  186. $myblock->setVar('options', $options);
  187. }
  188. if ($myblock->getVar('block_type') == 'C') {
  189. switch ($bctype) {
  190. case 'H':
  191. $name = _AM_CUSTOMHTML;
  192. break;
  193. case 'P':
  194. $name = _AM_CUSTOMPHP;
  195. break;
  196. case 'S':
  197. $name = _AM_CUSTOMSMILE;
  198. break;
  199. default:
  200. $name = _AM_CUSTOMNOSMILE;
  201. break;
  202. }
  203. $myblock->setVar('name', $name);
  204. $myblock->setVar('c_type', $bctype);
  205. } else {
  206. $myblock->setVar('c_type', 'H');
  207. }
  208. $msg = _AM_DBUPDATED;
  209. if ($myblock->store() != false) {
  210. $db =& Database::getInstance();
  211. $sql = sprintf("DELETE FROM %s WHERE block_id = %u", $db->prefix('block_module_link'), $bid);
  212. $db->query($sql);
  213. foreach ($bmodule as $bmid) {
  214. $sql = sprintf("INSERT INTO %s (block_id, module_id) VALUES (%u, %d)", $db->prefix('block_module_link'), $bid, intval($bmid));
  215. $db->query($sql);
  216. }
  217. include_once XOOPS_ROOT_PATH.'/class/template.php';
  218. $xoopsTpl = new XoopsTpl();
  219. $xoopsTpl->xoops_setCaching(2);
  220. if ($myblock->getVar('template') != '') {
  221. if ($xoopsTpl->is_cached('db:'.$myblock->getVar('template'))) {
  222. if (!$xoopsTpl->clear_cache('db:'.$myblock->getVar('template'))) {
  223. $msg = 'Unable to clear cache for block ID'.$bid;
  224. }
  225. }
  226. } else {
  227. if ($xoopsTpl->is_cached('db:system_dummy.html', 'block'.$bid)) {
  228. if (!$xoopsTpl->clear_cache('db:system_dummy.html', 'block'.$bid)) {
  229. $msg = 'Unable to clear cache for block ID'.$bid;
  230. }
  231. }
  232. }
  233. } else {
  234. $msg = 'Failed update of block. ID:'.$bid;
  235. }
  236. // redirect_header('admin.php?fct=blocksadmin&amp;t='.time(),1,$msg);
  237. // exit(); GIJ -
  238. return $msg ; // GIJ +
  239. }
  240. ?>