PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/html/modules/dbcrud/include/onupdate.php

http://xoopscube-modules.googlecode.com/
PHP | 146 lines | 130 code | 16 blank | 0 comment | 27 complexity | 4c70584fa6ba3e2dd9de16a2f29922a2 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0
  1. <?php
  2. $dirname = basename(dirname(dirname(__FILE__)));
  3. eval('function xoops_module_update_' . $dirname . '($module, $prev_version){
  4. return xgdb_onupdate($module, $prev_version, "' . $dirname . '");
  5. }');
  6. if (!function_exists('xgdb_onupdate')) {
  7. function xgdb_onupdate($module, $prev_version, $dirname) {
  8. global $msgs, $xoopsConfig, $xoopsUser;
  9. $myts =& MyTextSanitizer::getInstance();
  10. if (!is_array($msgs)) $msgs = array();
  11. $xoopsDB =& Database::getInstance();
  12. $tplfile_tbl = $xoopsDB->prefix("tplfile");
  13. $tplsource_tbl = $xoopsDB->prefix("tplsource");
  14. $data_tbl = $xoopsDB->prefix($dirname . '_xgdb_data');
  15. $item_tbl = $xoopsDB->prefix($dirname . '_xgdb_item');
  16. $newblocks_tbl = $xoopsDB->prefix("newblocks");
  17. $mid = $module->getVar('mid');
  18. $module_upload_dir = XOOPS_UPLOAD_PATH . '/' . $dirname;
  19. $tplfile_handler =& xoops_gethandler('tplfile');
  20. $template_dir = XOOPS_ROOT_PATH . '/modules/' . $dirname . '/templates';
  21. include_once XOOPS_ROOT_PATH . '/class/template.php';
  22. $msgs[] = 'Updating templates...';
  23. if ($dir_handler = @opendir($template_dir . '/')) {
  24. while (($template_file = readdir($dir_handler)) !== false) {
  25. if (substr($template_file, 0, 1) == '.') continue;
  26. elseif ($template_file == 'index.html') continue;
  27. $xgdb_template_file = $dirname . '_' . $template_file;
  28. $template_file_path = $template_dir . '/' . $template_file;
  29. if (is_file($template_file_path)) {
  30. $mtime = intval(@filemtime($template_file_path));
  31. $template =& $tplfile_handler->create();
  32. $template->setVar('tpl_source', file_get_contents($template_file_path), true);
  33. $template->setVar('tpl_refid', $mid);
  34. $template->setVar('tpl_tplset', 'default');
  35. $template->setVar('tpl_file', $xgdb_template_file);
  36. $template->setVar('tpl_desc', '', true);
  37. $template->setVar('tpl_module', $dirname);
  38. $template->setVar('tpl_lastmodified', $mtime);
  39. $template->setVar('tpl_lastimported', 0);
  40. $template->setVar('tpl_type', 'module');
  41. if (!$tplfile_handler->insert($template)) {
  42. $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not insert template <b>' . $myts->htmlSpecialChars($xgdb_template_file) . '</b> to the database.</span>';
  43. } else {
  44. $template_id = $template->getVar('tpl_id');
  45. $msgs[] = '&nbsp;&nbsp;Template <b>' . $myts->htmlSpecialChars($xgdb_template_file) . '</b> inserted to the database.';
  46. if ($xoopsConfig['template_set'] == 'default') {
  47. if (!xoops_template_touch($template_id)) {
  48. $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not recompile template <b>' . $myts->htmlSpecialChars($xgdb_template_file) . '</b>.</span>';
  49. } else {
  50. $msgs[] = '&nbsp;&nbsp;Template <b>' . $myts->htmlSpecialChars($xgdb_template_file) . '</b> recompiled.</span>';
  51. }
  52. }
  53. }
  54. }
  55. }
  56. closedir($dir_handler);
  57. }
  58. $blocks = $module->getInfo('blocks');
  59. foreach ($blocks as $func_num => $block) {
  60. $template_dir .= '/blocks';
  61. $xgdb_template_file = $block['template'];
  62. $template_file = substr($xgdb_template_file, strlen($dirname) + 1, strlen($xgdb_template_file));
  63. $template_file_path = "$template_dir/$template_file";
  64. if (file_exists($template_file_path)) {
  65. $sql = "SELECT bid FROM $newblocks_tbl WHERE mid = $mid AND func_num = $func_num AND show_func = '" . addslashes($block['show_func']) . "' AND func_file = '" . addslashes($block['file']) . "'";
  66. $res = $xoopsDB->query($sql);
  67. list($bid) = $xoopsDB->fetchRow($res);
  68. $xoopsDB->query("UPDATE $newblocks_tbl SET template = '" . addslashes($xgdb_template_file) . "' WHERE bid = $bid");
  69. $sql = "SELECT tpl_id FROM $tplfile_tbl WHERE tpl_tplset = 'default' AND tpl_file = '" . addslashes($xgdb_template_file) . "' AND tpl_module = '" . addslashes($dirname) . "' AND tpl_type = 'block'";
  70. $res = $xoopsDB->query($sql);
  71. list($tpl_id) = $xoopsDB->fetchRow($res);
  72. $xoopsDB->query("DELETE FROM $tplfile_tbl WHERE tpl_id = $tpl_id");
  73. $xoopsDB->query("DELETE FROM $tplsource_tbl WHERE tpl_id = $tpl_id");
  74. $mtime = intval(@filemtime($template_file_path));
  75. $template =& $tplfile_handler->create();
  76. $template->setVar('tpl_source', file_get_contents($template_file_path), true);
  77. $template->setVar('tpl_refid', $bid);
  78. $template->setVar('tpl_tplset', 'default');
  79. $template->setVar('tpl_file', $xgdb_template_file);
  80. $template->setVar('tpl_desc', '', true);
  81. $template->setVar('tpl_module', $dirname);
  82. $template->setVar('tpl_lastmodified', $mtime);
  83. $template->setVar('tpl_lastimported', 0);
  84. $template->setVar('tpl_type', 'block');
  85. if (!$tplfile_handler->insert($template)) {
  86. $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not update template <b>' . $myts->htmlSpecialChars($xgdb_template_file) . '</b>.</span>';
  87. } else {
  88. $msgs[] = '&nbsp;&nbsp;Template <b>' . $myts->htmlSpecialChars($xgdb_template_file) . '</b> updated.';
  89. if ($xoopsConfig['template_set'] == 'default') {
  90. $template_id = $template->getVar('tpl_id');
  91. if (!xoops_template_touch($template_id)) {
  92. $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not recompile template <b>' . $myts->htmlSpecialChars($xgdb_template_file) . '</b>.</span>';
  93. } else {
  94. $msgs[] = '&nbsp;&nbsp;Template <b>' . $myts->htmlSpecialChars($xgdb_template_file) . '</b> recompiled.';
  95. }
  96. }
  97. }
  98. }
  99. }
  100. if ($prev_version < 30) {
  101. $file = fopen(XOOPS_UPLOAD_PATH . "/" . $dirname . "/.htaccess", "w");
  102. flock($file, LOCK_EX);
  103. fputs($file, "order deny,allow\n");
  104. fputs($file, "deny from all\n");
  105. flock($file, LOCK_UN);
  106. fclose($file);
  107. $res_item = $xoopsDB->query("SELECT name FROM $item_tbl WHERE type = 'file' OR type = 'image'");
  108. while (list($col_name) = $xoopsDB->fetchRow($res_item)) {
  109. $res_data = $xoopsDB->query("SELECT id, $col_name FROM $data_tbl WHERE $col_name IS NOT NULL AND $col_name != ''");
  110. while (list($id, $file_name) = $xoopsDB->fetchRow($res_data)) {
  111. $real_file_name = urlencode("$id-$col_name-$file_name");
  112. @copy($module_upload_dir . '/' . $file_name, $module_upload_dir . '/' . $real_file_name);
  113. }
  114. }
  115. $xoopsDB->query("ALTER TABLE `$item_tbl` CHANGE `ambiguous` `search_cond` TINYINT(1) UNSIGNED NULL DEFAULT NULL;");
  116. $xoopsDB->query("ALTER TABLE `$item_tbl` ADD `disp_cond` TINYINT(1) UNSIGNED NULL AFTER `input_desc`;");
  117. }
  118. if ($prev_version < 40) {
  119. $xoopsDB->query("ALTER TABLE `$item_tbl` ADD `show_gids` VARCHAR(255) AFTER `required`;");
  120. $res = $xoopsDB->query("SELECT groupid FROM " . $xoopsDB->prefix('groups') . " ORDER BY groupid ASC");
  121. $gidstring = '|';
  122. while (list($groupid) = $xoopsDB->fetchRow($res)) {
  123. $gidstring .= $groupid . '|';
  124. }
  125. $xoopsDB->query("UPDATE `$item_tbl` SET show_gids = '$gidstring'");
  126. }
  127. return true;
  128. }
  129. }
  130. ?>