增加根据节点批量更新静态链接

hotfix/远程访问多媒体中心
LiaoYijun 8 years ago
parent 1bbb725d95
commit 7c91fa0919

@ -12,6 +12,7 @@ class Welcome extends CI_Controller {
$this->load->model('Area_model');
$this->load->model('InfoStructures_model');
$this->load->model('Information_model');
$this->load->model('InfoContents_model');
$this->load->model('Coupon_model');
}
@ -94,6 +95,106 @@ class Welcome extends CI_Controller {
$this->load->view('bootstrap/footer');
}
public function get_infomation_urls($is_parent_id) {
$this->output->enable_profiler(FALSE);
$structure = $this->InfoStructures_model->Detail($is_parent_id);
if (empty($structure)) {
show_404();
return false;
}
$data['all_information'] = $this->Information_model->get_list_by_path($structure->is_path);
$this->load->view('bootstrap/header', $data);
$this->load->view('bootstrap/static_url', $data);
$this->load->view('bootstrap/footer');
}
public function change_static_url($info_id) {
$information = $this->Information_model->Detail($info_id);
$htm_doc = new DOMDocument();
libxml_use_internal_errors(true);
$htm_doc->strictErrorChecking = false;
if (empty($information->ic_content)) {
$this->echo_json([
'status' => 'error',
'infoId' => $info_id,
'message' => 'info content is empty'
]);
return;
}
$htm_doc->loadHTML($information->ic_content);
$htm_doc->normalizeDocument();
$img_list = $htm_doc->getElementsByTagName('img');
foreach ($img_list as $img) {
$img_src = $img->getAttribute('src');
$img_src = $this->check_url($img_src);
}
$information->ic_content = $htm_doc->saveHTML();
$this->InfoContents_model->Update(
$information->is_ic_id,
$information->ic_url,
$information->ic_url_title,
$information->ic_type,
$information->ic_title,
$information->ic_content,
$information->ic_summary,
$information->ic_seo_title,
$information->ic_seo_description,
$information->ic_seo_keywords,
$information->ic_show_bread_crumbs,
$information->ic_status,
$information->ic_template,
$information->ic_photo,
$information->ic_photo_width,
$information->ic_photo_height,
$information->ic_recommend_tours,
$information->ic_recommend_packages,
$information->ic_ht_area_id,
$information->ic_ht_area_type,
$information->ic_ht_product_id,
$information->ic_ht_product_type,
$information->ic_author);
$this->echo_json([
'status' => 'ok',
'infoId' => $info_id,
'message' => 'success'
]);
}
private function echo_json($obj) {
$this->output
->set_content_type('application/json')
->set_output(json_encode($obj));
}
private function check_url($subject) {
$result = $subject;
$check_rules = array(
'/^\/image\/(.*)/' => '//images.chinahighlights.com/image/',
'/^http:\/\/images.chinahighlights.com(.*)/' => '//images.chinahighlights.com',
'/^http:\/\/data.chinahighlights.com(.*)/' => '//data.chinahighlights.com',
'/^http:\/\/www.chinahighlights.com(.*)/' => '//www.chinahighlights.com');
foreach ($check_rules as $pattern => $replace) {
// echo 'key: '.$pattern.'; val: '.$replace.'</br>';
$result = $this->replace_url($pattern, $replace, $result);
}
return $result;
}
private function replace_url($pattern, $replace, $subject) {
$result = $subject;
$match_result = array();
preg_match($pattern, $subject, $match_result);
$result_count = count($match_result);
if ($result_count == 2) {
$result = $replace.$match_result[1];
}
return $result;
}
//生肖促销订单查询
public function coupon() {
$data['countryList'] = $this->Area_model->get_country_list();

@ -0,0 +1,68 @@
<script language="javascript">
$(function() {
var idList = [];
var index = 0;
$("td[data-id]").each(function(index, element) {
idList[index] = $(element).data("id");
});
console.info(idList);
$("#startButton").click(function() {
batch_update_cache(idList[index]);
});
function batch_update_cache(infoId) {
var $statusLabel = $("#status" + infoId);
$statusLabel.html("\u7a0d\u7b49...");
console.info("infoId: " + infoId + "; length: " + idList.length + "; index: " + index);
$.get("/info.php/welcome/change_static_url/" + infoId,
function(result) {
console.info(result);
$statusLabel.html(result.message);
index++;
if (index < idList.length) {
batch_update_cache(idList[index]);
}
});
}
});
</script>
<div class="row-fluid">
<div class="span1">
</div>
<div class="span10">
<table class="table table-striped">
<thead>
<tr>
<th class="span1">#ID</th>
<th class="span9">URL</th>
<th class="span2"><button id="startButton">开始</button></th>
</tr>
</thead>
<tbody>
<?php
foreach ($all_information as $key => $info) {
if ($info->ic_status == 1 && !empty($info->ic_url)) {
?>
<tr>
<td data-id='<?php echo $info->is_ic_id; ?>'><?php echo $info->is_ic_id; ?></td>
<td class="cache_url"><?php echo $info->ic_url; ?></a></td>
<td id="status<?php echo $info->is_ic_id; ?>"><i class="icon-refresh"></i></td>
</tr>
<?php }
} ?>
</tbody>
</table>
</div>
<div class="span1">
</div>
</div>
Loading…
Cancel
Save