(1)找到phpcmsmodulescontenttemplates文件夹的content_edit.tpl.php和content_add.tpl.php两个文件
content_edit.tpl.php大概80行,找到如下代码:
- </tbody></table>
在这行代码之前加入如下代码:
- <tr>
- <th width="80">阅读量</th>
- <td><input type='text' name='info[views]' id='views' value='<?php echo $views;?>' size='3' class='input-text'> (默认随机生成)</td>
- </tr>
同样content_add.tpl.php大概82行,找到如下代码:
- </tbody></table>
- <tr>
- <th width="80">阅读量</th>
- <td><input type='text' name='info[views]' id='views' value='<?php echo $views;?>' size='3' class='input-text'> (默认随机生成)</td>
- </tr>
(2)找到phpcmsmodelcontent_model.class.php找到大概107行:
改成:
- //添加统计
- $this->hits_db = pc_base::load_model('hits_model');
- $hitsid = 'c-'.$modelid.'-'.$id;
- $this->hits_db->insert(array('hitsid'=>$hitsid,'catid'=>$systeminfo['catid'],'updatetime'=>SYS_TIME));
然后301行找到代码:
- //添加统计
- $views = $data['views'];
- $this->hits_db = pc_base::load_model('hits_model');
- $hitsid = 'c-'.$modelid.'-'.$id;
- $this->hits_db->insert(array('hitsid'=>$hitsid,'catid'=>$systeminfo['catid'],'views'=>$views,'updatetime'=>SYS_TIME));
在这之前加入代码:
- //调用 update
(3)找到phpcmsmodulescontentcontent.php文件
- //添加统计
- $views = $data['views'];
- $this->hits_db = pc_base::load_model('hits_model');
- $hitsid = 'c-'.$this->modelid.'-'.$id;
- $this->hits_db->update(array('views' => $views),array('hitsid' => $hitsid));
大概163行找到代码:
在这下边新增一个生成随机点击量的代码:
- param::set_cookie('module', 'content');
然后找到代码大概250行:
- $views = rand(10,999);/*生成随机点击数*/
在这后边新增代码:
- $forminfos = $content_form->get($data);
- $formValidator = $content_form->formValidator;
加完之后,更新缓存,你可以尝试一下新增或者修改文章,看看是否可以任意修改阅读量!
- /*加载点击*/
- $hitsid = "c-".$modelid."-".$id;
- $db_hits = pc_base::load_model('hits_model');//引入hits
- $view = $db_hits ->get_one(array('hitsid' => $hitsid),'views');
- $views = $view['views'];