zoukankan      html  css  js  c++  java
  • dedeCMS二次开发api简单接口代码

    <?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 = [
            '”',
            '“',
            '³',
            '≤',
            '—',
            '‘',
            '’',
            '…',
            '•',
            'η',
            '×',
            'μ',
            '·',
            '≈',
            'Ω',
            '°',
            '−',
            'src="https://www.yourweb.com/uploads/'
        ];
        return str_replace($rep1,$rep2,$string);
    }
    
    
    ?>
  • 相关阅读:
    摘录一下 上海富豪颜立燕拆借爱建资金路径曝光 暴富的关键词
    pixysoft.framework.security.sso 开发实录
    Pixysoft.Framework.Apis 开发实录
    动态加载Assembly的一系列恶心问题
    让我们开发的系统具有学习能力 我的突发奇想!
    利用RealProxy,强化AOP,在”牛粪“的周围插上”鲜花“
    Pixysoft.Applications.BugTraces 开发实录
    打造第二代测试框架TestDriven 2.0(四)—— 代码对象化建模技术
    软件工程革命三部曲 —— 外传 过程控制
    破解typemock 流水账
  • 原文地址:https://www.cnblogs.com/panziwen/p/14933566.html
Copyright © 2011-2022 走看看