zb_system/function/lib/base.php 的 Save() 函数
接口 Filter_Plugin_Post_Save 和 Filter_Plugin_PostArticle_Core 只能改 ID外的内容。
Save() 如果新增ID 为空,直接忽略ID 写入,写入后sql返回文章ID
如果不为空 则直接根据ID进行更新。
所以,要修改 文章ID,两种方式,
1 文章发布前 挂 Filter_Plugin_Post_Save 和 Filter_Plugin_PostArticle_Core 把计算出来的 ID(如值 222) 写入zbp_post表(其他值默认值空值), + $post->ID = 222;
这样 在save时候,直接更新了。
2 文章发布后 改ID 挂 Filter_Plugin_PostArticle_Succeed 接口,获取ID, 把 计算出来的id 覆盖掉获取的ID(建议第一中,事少)。
可以用 $article->ID == 0 判断是否新文章。
public function Save()
{
# 打印当前php 的 根目录到文件名的全路径 和 当前行数
#print_r(debug_backtrace());
#die();
#print_r($this->data);
#die("s");
global $bloghost;
#print_r($this->idname);
# die();
if (array_key_exists('Meta', $this->data)) {
$this->data['Meta'] = $this->Metas->Serialize();
}
#print_r($this->datainfo);
#die(" end");
$keys = array();
foreach ($this->datainfo as $key => $value) {
if (!is_array($value) || count($value) < 4) {
continue;
}
$keys[] = $value[0];
}
$keyvalue = array_fill_keys($keys, '');
$keyvalue_orig = array();
foreach ($this->datainfo as $key => $value) {
if (!is_array($value) || count($value) < 4) {
continue;
}
if (!array_key_exists($key, $this->data)) {
//如果unset(某个$key)就不再插入或修改该数据
unset($keyvalue[$value[0]]);
continue;
}
if ($value[1] == 'boolean') {
$keyvalue[$value[0]] = (int)$this->data[$key];
$keyvalue_orig[$value[0]] = (int)$this->original[$key];
} elseif ($value[1] == 'integer') {
$keyvalue[$value[0]] = (int)$this->data[$key];
$keyvalue_orig[$value[0]] = (int)$this->original[$key];
} elseif ($value[1] == 'float') {
$keyvalue[$value[0]] = (float)$this->data[$key];
$keyvalue_orig[$value[0]] = (float)$this->original[$key];
} elseif ($value[1] == 'double') {
$keyvalue[$value[0]] = (float)$this->data[$key];
$keyvalue_orig[$value[0]] = (float)$this->original[$key];
} elseif ($value[1] == 'string' || $value[1] == 'char') {
if ($key == 'Meta' || $bloghost == '/') {
$keyvalue[$value[0]] = $this->data[$key];
$keyvalue_orig[$value[0]] = $this->original[$key];
} else {
$keyvalue[$value[0]] = ($this->isreplacehost) ? $this->ReplaceHost2Tag($this->data[$key]) : $this->data[$key];
$keyvalue_orig[$value[0]] = ($this->isreplacehost) ? $this->ReplaceHost2Tag($this->original[$key]) : $this->original[$key];
}
} else {
$keyvalue[$value[0]] = $this->data[$key];
$keyvalue_orig[$value[0]] = $this->original[$key];
}
}
array_shift($keyvalue);
array_shift($keyvalue_orig);
$id_name = $this->idname;
$id_field = $this->datainfo[$id_name][0];
if (empty($this->$id_name)) {
if (count($keyvalue) == 0) {
return true;
}
$sql = $this->db->sql->Insert($this->table, $keyvalue);
$this->$id_name = $this->db->Insert($sql);
} else {
foreach ($keyvalue as $key => $value) {
if (array_key_exists($key, $keyvalue_orig)) {
if ($value === $keyvalue_orig[$key]) {
unset($keyvalue[$key]);
}
}
}
if (count($keyvalue) == 0) {
return true;
}
$sql = $this->db->sql->Update($this->table, $keyvalue, array(array('=', $id_field, $this->$id_name)));
$r = $this->db->Update($sql);
$this->original = $this->data;
return $r;
}
$this->original = $this->data;
return true;
}