moviemodel.php
来自「a short sketch about linux syntex lines.」· PHP 代码 · 共 852 行 · 第 1/2 页
PHP
852 行
$POST['order'] = 'movid';
}
$select->order('a.`'.$POST['order'].'` DESC');
if ($pagesize){
$select->limit($pagesize);
}
$sql = $select->toString();
//echo $sql.'<br>';
if ($limitpage===true){
$total = $this->_DB->getCount($sql);
$this->total = $total;
$this->_Page->set($total);
$this->printPage = $this->_Page->PrintPage();
return $this->_DB->fetAll($sql.$this->_Page->limit());
}else{
return $this->_DB->fetAll($sql);
}
}
/*
return one row
获取一行记录。只接受询问ID参数
*/
public function getRow($id){
$select = $this->_DB->select();
$select->from(VODCMS_MOVIE.' AS a' , 'a.*');
$select->where('a.movid='.(int)$id);
$select->order('a.movid DESC');
$sql= $select->toString();
$data = $this->_DB->fetRow($sql);
$data['category'] = explode(',', $data['category']);
$data['recmd'] = $this->getRecmd($id);
$data['url'] = $this->getUrl($id);
//print_r($data['recmd']);
if (stripos(',', $data['sid']) !==false){
$data['sid'] = @explode(',', $data['sid']);
}
if (stripos(',', $data['player']) !==false){
$data['player'] = @explode(',', $data['player']);
}
return $data;
}
/*
根据分类ID传回格式化后的分类名称
*/
public function formatCategory($category){
if ($category){
if(is_array($category) == false){
$category = explode(',', $category);
}
$where = '';
foreach ($category as $row){
if($row)
$where.= $where ? ' OR id= '.(int)$row : ' id = '. (int)$row;
}
$cate = new CategoryModel();
$data = $cate->getAll('('.$where.')');
foreach ($data as $row){
$link.= '<a href="'.INSTALLDIR.'?mod=movie&category='.$row['id'].'">'.$row['category'].'</a> ';
}
unset($data);
return $link;
}
}
/*
根据传入ID隐藏影片信息
*/
public function locked($id){
if (is_array($id)){
$id = implode(',', array_map('intval', $id));
}
return $this->_DB->update(VODCMS_MOVIE, array('locked'=>1), 'movid in ('.$id.')');
}
public function unlock($id){
if (is_array($id)){
$id = implode(',', array_map('intval', $id));
}
return $this->_DB->update(VODCMS_MOVIE, array('locked'=>0), 'movid in ('.$id.')');
//echo $sql;
}
/*删除影片以及相关信息*/
public function delete($id){
if (is_numeric($id)){
$where = 'movid='. intval($id);
}else{
$where = array('mkey'=> $id);
}
$IO = new Easy_Filesystem();
$select = $this->_DB->select();
$select->from(VODCMS_MOVIE)->where($where)->limit(1);
$sql = $select->toString();
$row = $this->_DB->fetRow($sql);
if ($row['movid']){
if ($row['pic']){
$IO->delete($row['pic']);
}
if ($row['otherpic']){
$IO->delete($row['otherpic']);
}
if ($row['bt']){
$IO->delete($row['bt']);
}
$this->_DB->delete(VODCMS_MOVIE, $where);
$this->_DB->delete(VODCMS_MCLASSID, 'movid='.(int)$row['movid']);
$this->_DB->delete(VODCMS_URL, 'movid='.(int)$row['movid']);
return true;
}else{
$this->error = _('影片未找到!');
return false;
}
}
/*
根据条件检测是否存在条件记录成功返回记录ID否则返回0
*/
public function exists($where){
$select = $this->_DB->select();
$sql = $select->from(VODCMS_MOVIE)->where($where)->limit(1)->toString();
$row = $this->_DB->fetRow($sql);
if ($row['movid']){
return $row['movid'];
}else{
return 0;
}
}
public function getchr($str){
$ret="";
for($i=0;$i<strlen($str);$i++){
$p=ord(substr($str,$i,1));
if($p>160){
$q=ord(substr($str,++$i,1));
$p=$p*256+$q-65536;
}
$ret.=$p;
}
return $ret;
}
/*
根据传如字符返回首字符拼音
*/
function getLetter($char)
{
$tmp = 65536 + $this->getchr($char);
if($tmp>=45217 && $tmp<=45252) {
$getpychar= "A";
}elseif($tmp>=45253 && $tmp<=45760) {
$getpychar= "B";
}elseif($tmp>=45761 && $tmp<=46317) {
$getpychar= "C";
}elseif($tmp>=46318 && $tmp<=46825) {
$getpychar= "D";
}elseif($tmp>=46826 && $tmp<=47009) {
$getpychar= "E";
}elseif($tmp>=47010 && $tmp<=47296) {
$getpychar= "F";
}elseif($tmp>=47297 && $tmp<=47613) {
$getpychar= "G";
}elseif($tmp>=47614 && $tmp<=48118) {
$getpychar= "H";
}elseif($tmp>=48119 && $tmp<=49061) {
$getpychar= "J";
}elseif($tmp>=49062 && $tmp<=49323) {
$getpychar= "K";
}elseif($tmp>=49324 && $tmp<=49895) {
$getpychar= "L";
}elseif($tmp>=49896 && $tmp<=50370) {
$getpychar= "M";
}elseif($tmp>=50371 && $tmp<=50613) {
$getpychar= "N";
}elseif($tmp>=50614 && $tmp<=50621) {
$getpychar= "O";
}elseif($tmp>=50622 && $tmp<=50905) {
$getpychar= "P";
}elseif($tmp>=50906 && $tmp<=51386) {
$getpychar= "Q";
}elseif($tmp>=51387 && $tmp<=51445) {
$getpychar= "R";
}elseif($tmp>=51446 && $tmp<=52217) {
$getpychar= "S";
}elseif($tmp>=52218 && $tmp<=52697) {
$getpychar= "T";
}elseif($tmp>=52698 && $tmp<=52979) {
$getpychar= "W";
}elseif($tmp>=52980 && $tmp<=53640) {
$getpychar= "X";
}elseif($tmp>=53689 && $tmp<=54480) {
$getpychar= "Y";
}elseif($tmp>=54481 && $tmp<=62289) {
$getpychar= "Z";
}else{//如果不是中文,则不处理
$getpychar=$char;
}
return $getpychar;
}
/*更新影片表字段信息*/
public function update($data, $where=null){
$this->_DB->update(VODCMS_MOVIE, $data, $where);
return true;
}
/*初始化影片分类信息.将影片表中的category字段值更新到临时表mclassid中*/
public function initsCategory(){
$select = $this->_DB->select();
$sql = $select->from(VODCMS_MOVIE)->toString();
foreach ($this->_DB->fetAll($sql) as $row){
$category = explode(',', $row['category']);
$this->AddCategory($row['movid'], $category);
}
return true;
}
/*
初始化影片信息
1。更新影片分类表中的临时字段影片数
2、更新影片表中的影片集数临时字段
3、重新统计影片的评论数
*/
public function initmovie(){
$category = new CategoryModel();
$select = $this->_DB->select();
$sql = $select->from(VODCMS_CATEGORY)->toString();
foreach ($this->_DB->fetAll($sql) as $row){
$select = $this->_DB->select();
$select->from(VODCMS_MCLASSID);
$select->where('category = '.$row['id']);
$sql = $select->toString();
$total = $this->_DB->getCount($sql);
$this->_DB->update(VODCMS_CATEGORY, array('moviecount'=>$total), array('id'=> $row['id']));
}
$select = $this->_DB->select();
$sql = $select->from(VODCMS_MOVIE,'movid,title')->toString();
foreach ($this->_DB->fetAll($sql) as $row){
$select = $this->_DB->select();
$select->from(VODCMS_URL);
$sql = $select->where('movid='.$row['movid'])->toString();
$total = $this->_DB->getCount($sql);
$letter = $this->getLetter($row['title']);
$this->_DB->update(VODCMS_MOVIE,
array('urlcount'=>$total, 'letter'=> $letter), array('movid'=> $row['movid']));
unset($total, $sql);
$select = $this->_DB->select();
$select->from(VODCMS_COMMENT);
$sql = $select->where('movid='.$row['movid'])->toString();
$total = $this->_DB->getCount($sql);
$this->_DB->update(VODCMS_MOVIE,
array('review'=>$total, 'letter'=> $letter), array('movid'=> $row['movid']));
unset($total, $sql);
$select = $this->_DB->select();
$sql = $select->from(VODCMS_URL,'urlid')->where( array('movid'=> $row['movid']) )->order('sort,urlid')->toString();
$i = 0;
foreach ($this->_DB->fetAll($sql) as $rs){
$i++;
$this->_DB->update(VODCMS_URL, array('sort'=>$i), array('urlid'=> $rs['urlid']));
}
}
unset($sql);
}
/*
@param array
*/
public function getMovid($POST=null){
$category = new CategoryModel();
if ($POST['category']){
$where.= ' b.category = '.intval($POST['category']);
}
$POST['pagesize'] = $POST['pagesize'] ? $POST['pagesize'] : 1;
$select = $this->_DB->select();
$select->from(VODCMS_MOVIE.' AS a', 'DISTINCT( a.movid )');
if (intval($POST['category'])){
$select->join(VODCMS_MCLASSID.' AS b', 'a.movid = b.movid',null);
}
$select->where($where);
$select->order('modifytime DESC');
if($POST['max']){
$select->limit($POST['max']);
}else{
$select->limit(($POST['pagesize']-1)*20, 20);
}
$sql = $select->toString();
return $this->_DB->fetAll($sql);
}
//*更新中间表信息到*/
public function setMidTable($movid = 0){
/*if (is_numeric($movid) && $movid>0){
$where = ' WHERE movid='.$movid;
}
$sql = 'SELECT movid,lookgid,downgid,locked,addtime,modifytime,click FROM '.VODCMS_MOVIE.$where;
$Rows = $this->_DB->fetAll($sql);
foreach($Rows as $row){
$this->_DB->update(VODCMS_MCLASSID, $row, array('movid' => $row['movid']));
$this->_DB->update(VODCMS_RECMD, $row, array('movid' => $row['movid']));
}
unset($Rows, $row, $sql);*/
}
/*
查找有错误的影片
*/
public function findError(){
$this->_Page->set(2000, 100);
$this->printPage = $this->_Page->PrintPage();
$sql = 'SELECT * FROM '.VODCMS_MOVIE.$this->_Page->limit();
$allmovie = $this->_DB->fetAll($sql);
$Socket = new Easy_Socket();
foreach ($allmovie as $row){
if (empty($row['actor'])){
$error[] = _('主演未填写');
}
if (empty($row['category'])){
$error[] = _('分类未设置');
}
if (empty($row['pic']) || $row['pic'] == 'upload/nopic.gif'){
$error[] = _('大海报未填写');
}
if ($row['pic']){
if (stristr($row['pic'] , 'http') === false){
if( file_exists(ROOT.$row['pic']) === false ){
$error[] = _('大海报不本地存在');
}
}else{
$info = parse_url($row['pic']);
$Socket->Connect($info['host'], 80);
if ( $Socket->setQuery($info) === false){
$error[] = '图片服务器错误:'.$Socket->error;
}
}
}
if (empty($row['sid'])){
$error[] = _('服务器未设置');
}
if (empty($row['player'])){
$error[] = _('播放器未设置');
}
if (empty($row['content'])){
$error[] = _('影片介绍未设置');
}
if (empty($row['area'])){
$error[] = _('影片地区未设置');
}
if ($row['urlcount'] == 0){
$error[] = _('影片路径未填写');
}
if (is_array($error)){
$this->_DB->update(VODCMS_MOVIE, array('comments'=>'', 'comments'=> implode(',', $error)),
array('movid'=> $row['movid']));
unset($error);
//echo $this->_DB->sql;
}else{
$this->_DB->update(VODCMS_MOVIE, array('comments'=>''), array('movid'=> $row['movid']));
}
}
unset($allmovie);
}
/*
列出有问题的影片
*/
public function listError(){
return $this->getAll('comments <> \'\'');
}
/*
根据ID的变动初始化影片的分类中间表
*/
public function resetCategory($categoryid){
$select = $this->_DB->select();
$select->from(VODCMS_MCLASSID);
$select->where(array('category'=> (int)$categoryid));
$select->limit(1);
$sql = $select->toString();
$row = $this->_DB->fetRow($sql);
if ($row['movid']){
$select = $this->_DB->select();
$select->from(VODCMS_MOVIE);
$select->where(array('movid'=> (int)$row['movid']));
$sql = $select->toString();
$data = $this->_DB->fetRow($sql);
if ($data['category']){
$this->AddCategory($data['movid'], $data['category']);
}else{
$this->_DB->update(VODCMS_MOVIE, array('comments'=> '分类未设置', 'locked'=>1), array('movid'=> $data['movid']));
}
}
}
/*重新统计影片的日、周、月点播数剧*/
public function resetclick() {
//$fields = array('days', 'weeks', 'months');
$rows = $this->_DB->listfields(VODCMS_MOVIE);
foreach($rows as $row){
$fields[] = $row['Field'];
}
if( in_array('days', $fields) === false ) {
$this->_DB->exec('ALTER TABLE '.VODCMS_MOVIE.' ADD `days` INT UNSIGNED NOT NULL');
}
if( in_array('weeks', $fields) === false ) {
$this->_DB->exec('ALTER TABLE '.VODCMS_MOVIE.' ADD `weeks` INT UNSIGNED NOT NULL');
}
if( in_array('months', $fields) === false ) {
$this->_DB->exec('ALTER TABLE '.VODCMS_MOVIE.' ADD `months` INT UNSIGNED NOT NULL');
}
$select = $this->_DB->select();
$select->from(VODCMS_PLAYLOG.' as a', 'count(a.urlid) as click');
$select->join(VODCMS_URL.' as b', 'b.urlid = a.urlid', 'b.movid');
$select->where( 'TO_DAYS(from_unixtime(a.addtime)) = TO_DAYS(NOW())' );
$select->group('b.movid');
$sql = $select->toString();
foreach($this->_DB->fetAll($sql) as $row){
$this->_DB->update( VODCMS_MOVIE, array('days'=> $row['click']), array('movid' => $row['movid']) );
}
$select = $this->_DB->select();
$select->from(VODCMS_PLAYLOG.' as a', 'count(a.urlid) as click');
$select->join(VODCMS_URL.' as b', 'b.urlid = a.urlid', 'b.movid');
$select->where( 'TO_DAYS(NOW()) - TO_DAYS(from_unixtime(a.addtime)) <=7' );
$select->group('b.movid');
$sql = $select->toString();
foreach($this->_DB->fetAll($sql) as $row){
$this->_DB->update( VODCMS_MOVIE, array('weeks'=> $row['click']), array('movid' => $row['movid']) );
}
$select = $this->_DB->select();
$select->from(VODCMS_PLAYLOG.' as a', 'count(a.urlid) as click');
$select->join(VODCMS_URL.' as b', 'b.urlid = a.urlid', 'b.movid');
$select->where( 'MONTH(NOW()) = MONTH(from_unixtime(a.addtime)) ' );
$select->group('b.movid');
$sql = $select->toString();
foreach($this->_DB->fetAll($sql) as $row){
$this->_DB->update( VODCMS_MOVIE, array('months'=> $row['click']), array('movid' => $row['movid']) );
}
}
}?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?