address.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. defined('IN_PHPCMS') or exit('No permission resources.');
  3. pc_base::load_app_class('admin','admin',0);
  4. class address extends admin {
  5. public function __construct() {
  6. parent::__construct();
  7. }
  8. public function init() {
  9. include $this->admin_tpl('address');
  10. }
  11. public function update() {
  12. set_time_limit(120);
  13. $old_attachment_path = isset($_POST['old_attachment_path']) && trim($_POST['old_attachment_path']) ? trim($_POST['old_attachment_path']) : showmessage(L('old_attachment_address_empty'));
  14. $new_attachment_path = isset($_POST['new_attachment_path']) && trim($_POST['new_attachment_path']) ? trim($_POST['new_attachment_path']) : showmessage(L('new_attachment_address_empty'));
  15. //获取数据表列表
  16. $db = pc_base::load_model('site_model');
  17. $r = $db->query("show tables");
  18. $r = $db->fetch_array($db_list);
  19. foreach ($r as $k=>$v) {
  20. $v = array_pop($v);
  21. if (strpos($v, $db->db_tablepre)===false) continue;
  22. $table_name = str_replace($db->db_tablepre, '', $v);
  23. //获取每个表的数据表结构
  24. if (!$modle_table_db = pc_base::load_model($table_name.'_model')) {
  25. $modle_table_db = $db;
  26. }
  27. $s = $modle_table_db->get_fields($table_name);
  28. if ($s) {
  29. $sql = '';
  30. foreach ($s as $key=>$val) {
  31. //对数据表进行过滤,只有CHAR、TEXT或mediumtext类型的字段才可以保存下附件的地址。
  32. if (preg_match('/(char|text|mediumtext)+/i', $val)) {
  33. $sql .= !empty($sql) ? ", `$key`=replace(`$key`, '$old_attachment_path', '$new_attachment_path')" : "`$key`=replace(`$key`, '$old_attachment_path', '$new_attachment_path')";
  34. }
  35. }
  36. if (!empty($sql)) $modle_table_db->query("UPDATE ".$db->db_tablepre.$table_name." SET $sql");
  37. }
  38. }
  39. showmessage(L('operation_success'));
  40. }
  41. }