dedeCMS二次开发api简单接口代码

时间:2021-06-28 18:21:28   收藏:0   阅读:0
<?php

$cfg_NotPrintHead = false;
header("Content-Type: text/html; charset=utf-8");
include_once (dirname(__FILE__)."/../include/common.inc.php");
error_reporting(E_ALL || ~E_NOTICE);
require_once(DEDEINC.‘/json.class.php‘);

$reval = array();
empty($dopost)? "" : $dopost;
$tid = isset($tid) && is_numeric($tid) ? $tid : 0;
$orderby=empty($orderby)?‘id‘:$orderby; //排序方式,默认ID

$typeid = GetSonTypeID($tid)?GetSonTypeID($tid):$tid;//获取当前栏目子栏目,如果没有子栏目,返回当前栏目ID

if($dopost == "arclist"){
    
    $page = isset($page) && is_numeric($page) ? $page : 1;
    $limit = isset($limit) && is_numeric($limit)? $limit : 10;
    $start = ($page-1)*$limit;
    
    $rows = $dsql->GetOne("SELECT COUNT(id) AS total FROM `#@__archives` WHERE typeid in($typeid) and arcrank=0");
    if(is_array($rows)){
        $Total= $rows[‘total‘];
    }else{
        $Total = 0;
    }
    $pagesize = ceil($Total/$limit);
    
    $dsql->SetQuery("SELECT id,title,litpic,pubdate,description FROM `#@__archives` WHERE typeid in($typeid) and arcrank=0 ORDER BY $orderby DESC LIMIT $start,$limit");
    $dsql->Execute(‘me‘);
    while ($row = $dsql->GetArray(‘me‘)) {
        //$row[‘title‘] = gb2utf8($row[‘title‘]);
        $row[‘pubdate‘] = date(‘Y-m-d‘,$row[‘pubdate‘]);
        $reval[] = $row;
    }
    //var_dump($Total);
    $ouput = array(‘lists‘=>$reval,‘pagesize‘=>$pagesize);
    $json = new Services_JSON(SERVICES_JSON_SUPPRESS_ERRORS);
    exit($json->encode($ouput));
}

if($dopost == "view"){
    
    $row1 = $dsql->GetOne("SELECT * FROM `#@__archives` WHERE id = $aid");
    $row2 = $dsql->GetOne("SELECT * FROM `#@__addonarticle` WHERE aid = $aid");
    
    $row1[‘pubdate‘] = date(‘Y-m-d‘,$row1[‘pubdate‘]);
    $row2[‘body‘] = StrReplace($row2[‘body‘]);
    
    $row = array_merge($row1,$row2);
    $json = new Services_JSON(SERVICES_JSON_SUPPRESS_ERRORS);
    exit($json->encode($row));
}

if($dopost == "type"){
    
    $row1 = $dsql->GetOne("SELECT * FROM `#@__arctype` WHERE id = $tid");
    $row1[‘content‘] = StrReplace($row1[‘content‘]);
    $dsql->SetQuery("SELECT id,typename FROM `#@__arctype` WHERE reid in($tid) AND ishidden<>1 ORDER BY sortrank");
    $dsql->Execute(‘me‘);
    while ($row2 = $dsql->GetArray(‘me‘)) {
        $reval[] = $row2;
    }
    $json = new Services_JSON(SERVICES_JSON_SUPPRESS_ERRORS);
    $ouput = array(‘sontype‘=>$reval,‘type‘=>$row1);
    //var_dump($ouput);
    exit($json->encode($ouput));
}
/*
* 递归获取符合条件的子栏目
* @param $tid 栏目ID
* @return string
* */
function GetSonTypeID($tid){
    global $dsql;
    $dsql->SetQuery("SELECT id FROM `#@__arctype` WHERE reid in($tid) AND ishidden<>1 ORDER BY sortrank");
    $dsql->Execute($tid);
    $typeid = ‘‘;
    while($row=$dsql->GetObject($tid)){
        $typeid .= "{$row->id},";
        $typeid .= GetSonTypeID($row->id);
    }
    return trim($typeid,‘,‘);
}

function StrReplace($string){
    $rep1 = [
        ‘&rdquo;‘,
        ‘&ldquo;‘,
        ‘&sup3;‘,
        ‘&le;‘,
        ‘&mdash;‘,
        ‘&rsquo;‘,
        ‘&lsquo;‘,
        ‘&hellip;‘,
        ‘&bull;‘,
        ‘&eta;‘,
        ‘&times;‘,
        ‘&mu;‘,
        ‘&middot;‘,
        ‘&asymp;‘,
        ‘&Omega;‘,
        ‘&deg‘,
        ‘&minus‘,
        ‘src="/uploads/‘
    ];
    $rep2 = [
        ‘”‘,
        ‘“‘,
        ‘3‘,
        ‘≤‘,
        ‘—‘,
        ‘‘‘,
        ‘’‘,
        ‘…‘,
        ‘?‘,
        ‘η‘,
        ‘ב,
        ‘μ‘,
        ‘·‘,
        ‘≈‘,
        ‘Ω‘,
        ‘°‘,
        ‘?‘,
        ‘src="https://www.yourweb.com/uploads/‘
    ];
    return str_replace($rep1,$rep2,$string);
}


?>

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!