| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467 |
- <?php
- /**
- * Created by PhpStorm.
- * User: yunzhong
- * Date: 2020/12/17
- * Time: 11:34
- */
- function returnUrl()
- {
- $host = "";
- $port = 0;
- $database = "";
- $username = "";
- $pass = "";
- $tablepre = "ims_";
- //获取数据库配置
- if (file_exists("./database/config.php")) {
- include("./database/config.php");
- $host = $config['db']['master']['host'];
- $port = $config['db']['master']['port'];
- $database = $config['db']['master']['database'];
- $username = $config['db']['master']['username'];
- $pass = $config['db']['master']['password'];
- $tablepre = $config['db']['master']['tablepre'];
- } else {
- $env = file_get_contents('./.env');
- $env = str_replace("\n",",",$env);
- $env = str_replace(",,",",",$env);
- $env = rtrim($env,',');
- $env = explode(",",$env);
- if (is_array($env) && count($env) > 0) {
- foreach ($env as $kk => $vv) {
- if (strstr($vv, "DB_HOST")) {
- $host = explode("=", $vv)[1];
- }
- if (strstr($vv, "DB_PORT")) {
- $port = explode("=", $vv)[1];
- }
- if (strstr($vv, "DB_DATABASE")) {
- $database = explode("=", $vv)[1];
- }
- if (strstr($vv, "DB_USERNAME")) {
- $username = explode("=", $vv)[1];
- }
- if (strstr($vv, "DB_PASSWORD")) {
- $pass = explode("=", $vv)[1];
- }
- if (strstr($vv, "DB_PREFIX")) {
- $tablepre = explode("=", $vv)[1];
- }
- }
- }
- }
- if ($host != "''" && $database != "''" && $username != "''" && $pass != "''") {
- $sql = "select * from " . $tablepre . "yz_setting where uniacid = 0 and `group` = 'official_website' and `key` = 'theme_set'";
- try {
- $connect = new \PDO("mysql:host=" . $host . ";dbname=" . $database . ";port=" . $port, $username, $pass);
- $connect->prepare('set names utf8mb4')->execute();
- $res = $connect->query($sql);
- $data = $res->fetch();
- } catch (\PDOException $e) {
- echo "Error!: " . $e->getMessage() . "<br/>";
- die();
- }
- $set = unserialize($data['value']);
- if ($set['is_open'] == 2) {
- $theme_sql = "select * from " .$tablepre ."yz_official_website_theme_set where `identification` = 'uniacid_theme' and `is_default` = 1";
- try {
- $theme_connect = new \PDO("mysql:host=" . $host . ";dbname=" . $database . ";port=" . $port, $username, $pass);
- $theme_connect->prepare('set names utf8mb4')->execute();
- $theme_res = $theme_connect->query($theme_sql);
- $theme_data = $theme_res->fetch();
- if ($theme_data) {
- //https://dev8.yunzmall.com/plugins/shop_server/home?i=1
- $theme_result = !empty($theme_data['basic']) ? json_decode($theme_data['basic'],true) : [];
- $url = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . "/plugins/shop_server/home?i=".$theme_result['cus_uniacid'];
- } else {
- $default_sql = "select * from " .$tablepre ."yz_official_website_theme_set where `identification` != 'uniacid_theme' and `is_default` = 1";
- $default_connect = new \PDO("mysql:host=" . $host . ";dbname=" . $database . ";port=" . $port, $username, $pass);
- $default_connect->prepare('set names utf8mb4')->execute();
- $default_res = $default_connect->query($default_sql);
- $default_data = $default_res->fetch();
- if ($default_data) {
- $url = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . '/officialwebsite.php?page_name=default_home';
- } elseif($set['is_customize'] == '1' && $set['customize_url']) {
- $url = $set['customize_url']; //自定义跳转链接
- } else {
- $url = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . '/admin.html';
- }
- }
- } catch (\PDOException $e) {
- echo "Error!: " . $e->getMessage() . "<br/>";
- die();
- }
- } else {
- $url = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . '/admin.html';
- }
- } else {
- $url = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . '/admin.html';
- }
- return $url;
- }
- function getPei()
- {
- $host = "";
- $port = 0;
- $database = "";
- $username = "";
- $pass = "";
- $tablepre = "ims_";
- if (file_exists("./database/config.php")) {
- include("./database/config.php");
- $host = $config['db']['master']['host'];
- $port = $config['db']['master']['port'];
- $database = $config['db']['master']['database'];
- $username = $config['db']['master']['username'];
- $pass = $config['db']['master']['password'];
- $tablepre = $config['db']['master']['tablepre'];
- } else {
- $env = file_get_contents('./.env');
- $env = str_replace("\n",",",$env);
- $env = str_replace(",,",",",$env);
- $env = rtrim($env,',');
- $env = explode(",",$env);
- if (is_array($env) && count($env) > 0) {
- foreach ($env as $kk=>$vv) {
- if (strstr($vv,"DB_HOST")) {
- $host = explode("=",$vv)[1];
- }
- if (strstr($vv,"DB_PORT")) {
- $port = explode("=",$vv)[1];
- }
- if (strstr($vv,"DB_DATABASE")) {
- $database = explode("=",$vv)[1];
- }
- if (strstr($vv,"DB_USERNAME")) {
- $username = explode("=",$vv)[1];
- }
- if (strstr($vv,"DB_PASSWORD")) {
- $pass = explode("=",$vv)[1];
- }
- if (strstr($vv,"DB_PREFIX")) {
- $tablepre = explode("=",$vv)[1];
- }
- }
- }
- }
- return ["host"=>$host,"port"=>$port,"database"=>$database,"username"=>$username,"pass"=>$pass,"tablepre"=>$tablepre];
- }
- function getOfficial($name)
- {
- $data = getPei();
- $host = $data['host'];
- $port = $data['port'];
- $database = $data['database'];
- $username = $data['username'];
- $pass = $data['pass'];
- $tablepre = $data['tablepre'];
- $sql = " select ywm.*,ywt.identification as idft,ywt.top,ywt.basic,ywt.tail from ".$tablepre."yz_official_website_multiple as ywm LEFT JOIN ".$tablepre."yz_official_website_theme_set as ywt on ywm.theme_id=ywt.id where ywm.identification = :identification and ywt.is_default = 1";
- $connect = new \PDO("mysql:host=".$host.";dbname=".$database.";port=".$port,$username,$pass);
- $connect->prepare('set names utf8mb4')->execute();
- $official = $connect->prepare($sql);
- $official->bindParam(':identification',$name,PDO::PARAM_STR,15);
- $official->execute();
- $result = $official->fetch();
- $result['thumb'] = empty($result['thumb']) ? "" : yz_tomedia($result['thumb']);
- return $result;
- }
- function getCommonArticle($uniacid,$cate=0)
- {
- $data = getPei();
- $host = $data['host'];
- $port = $data['port'];
- $database = $data['database'];
- $username = $data['username'];
- $pass = $data['pass'];
- $tablepre = $data['tablepre'];
- $web_article_sql = "select ypa.id,ypa.category_id,ypa.title,ypa.`desc`,ypa.thumb,ypa.author,ypa.created_at,ypa.content,ypac.name,ypac.cate_desc,ypac.cate_img from ".$tablepre."yz_plugin_article as ypa left join ".$tablepre."yz_plugin_article_category as ypac on ypa.category_id = ypac.id where state = 1 and type != 1 and ypa.uniacid = ".$uniacid;
- if (!empty($cate)) {
- $web_article_sql .= " and ypa.category_id = :cate ";
- }
- $web_article_sql .= " order by ypa.id desc limit 6";
- $connect3 = new \PDO("mysql:host=".$host.";dbname=".$database.";port=".$port,$username,$pass);
- $connect3->prepare('set names utf8mb4')->execute();
- $web_res = $connect3->prepare($web_article_sql);
- $web_res->bindParam(':cate',$cate,PDO::PARAM_INT);
- $web_res->execute();
- $web_rel = $web_res->fetchAll();
- if ($web_rel) {
- foreach ($web_rel as $key=>$value) {
- $web_rel[$key]['web_url'] = $_SERVER['REQUEST_SCHEME'] . '://' .$_SERVER['HTTP_HOST']."/officialwebsite.php?page_name=resource_detail&article=".$value['id'];
- $web_rel[$key]['thumb'] = empty($value['thumb']) ? "" : yz_tomedia($value['thumb']);
- }
- }
- $connect3 = null;
- return $web_rel;
- }
- function getReadVolumeArticle($uniacid)
- {
- $data = getPei();
- $host = $data['host'];
- $port = $data['port'];
- $database = $data['database'];
- $username = $data['username'];
- $pass = $data['pass'];
- $tablepre = $data['tablepre'];
- $home_article_sql = "select id,category_id,title,`desc`,thumb,author,created_at,content from ".$tablepre."yz_plugin_article where state = 1 and type != 1 and uniacid = ".$uniacid." order by `id` desc limit 0,6 ";
- $connect4 = new \PDO("mysql:host=".$host.";dbname=".$database.";port=".$port,$username,$pass);
- $connect4->prepare('set names utf8mb4')->execute();
- $res_home = $connect4->query($home_article_sql);
- $home_data = $res_home->fetchAll();
- if ($home_data) {
- foreach ($home_data as $key=>$value) {
- $home_data[$key]['web_url'] = $_SERVER['REQUEST_SCHEME'] . '://' .$_SERVER['HTTP_HOST']."/officialwebsite.php?page_name=resource_detail&article=".$value['id'];
- $home_data[$key]['thumb'] = empty($value['thumb']) ? "" : yz_tomedia($value['thumb']);
- }
- }
- $connect4 = null;
- return $home_data;
- }
- function getPageCate($uniacid,$cate=0)
- {
- $data = getPei();
- $host = $data['host'];
- $port = $data['port'];
- $database = $data['database'];
- $username = $data['username'];
- $pass = $data['pass'];
- $tablepre = $data['tablepre'];
- $article_cate_sql = "select id,name,cate_desc,cate_img from ".$tablepre."yz_plugin_article_category where uniacid = ".$uniacid;
- if (!empty($cate)) {
- $article_cate_sql .= " and id = :cate ";
- }
- $article_cate_sql ." limit 1";
- $connect5 = new \PDO("mysql:host=".$host.";dbname=".$database.";port=".$port,$username,$pass);
- $connect5->prepare('set names utf8mb4')->execute();
- $res_article_cate = $connect5->prepare($article_cate_sql);
- $res_article_cate->bindParam(':cate',$cate,PDO::PARAM_INT);
- $res_article_cate->execute();
- $article_cate_data = $res_article_cate->fetch();
- if ($article_cate_data) {
- $article_cate_data['cate_url'] = $_SERVER['REQUEST_SCHEME'] . '://' .$_SERVER['HTTP_HOST']."/officialwebsite.php?page_name=resource_page&cate=".$article_cate_data['id'];
- $article_cate_data['cate_img'] = empty($article_cate_data['cate_img']) ? "" : yz_tomedia($article_cate_data['cate_img']);
- }
- $connect5 = null;
- return $article_cate_data;
- }
- function getTotalCate($uniacid,$cate=0)
- {
- $data = getPei();
- $host = $data['host'];
- $port = $data['port'];
- $database = $data['database'];
- $username = $data['username'];
- $pass = $data['pass'];
- $tablepre = $data['tablepre'];
- $article_total_sql = "select count(id) as article_total,sum(virtual_read_num) as article_read from ".$tablepre."yz_plugin_article where uniacid = ".$uniacid;
- if (!empty($cate)) {
- $article_total_sql .= " and category_id = :cate ";
- }
- $connect6 = new \PDO("mysql:host=".$host.";dbname=".$database.";port=".$port,$username,$pass);
- $connect6->prepare('set names utf8mb4')->execute();
- $article_total = $connect6->prepare($article_total_sql);
- $article_total->bindParam(':cate',$cate,PDO::PARAM_INT);
- $article_total->execute();
- $article_total_rel = $article_total->fetch();
- $connect6 = null;
- return $article_total_rel;
- }
- function getDetailArticle($article_id)
- {
- $data = getPei();
- $host = $data['host'];
- $port = $data['port'];
- $database = $data['database'];
- $username = $data['username'];
- $pass = $data['pass'];
- $tablepre = $data['tablepre'];
- $sql = " select pa.*,ac.id as cate_id,ac.name as category_name,ac.cate_desc,ac.cate_img from ".$tablepre."yz_plugin_article as pa LEFT JOIN ".$tablepre."yz_plugin_article_category as ac on pa.category_id = ac.id where pa.id = :article_id and pa.state=1 and pa.type !=1 ";
- $connect1 = new \PDO("mysql:host=".$host.";dbname=".$database.";port=".$port,$username,$pass);
- $connect1->prepare('set names utf8mb4')->execute();
- $res = $connect1->prepare($sql);
- $res->bindParam(':article_id',$article_id,PDO::PARAM_INT);
- $res->execute();
- $rel = $res->fetch();
- $rel['off_url'] = $_SERVER['REQUEST_SCHEME'] . '://' .$_SERVER['HTTP_HOST']."/officialwebsite.php?page_name=resource_page";
- $rel['thumb'] = empty($rel['thumb']) ? "" : yz_tomedia($rel['thumb']);
- $rel['cate_img'] = empty($rel['cate_img']) ? "" : yz_tomedia($rel['cate_img']);
- $connect1 = null;
- return $rel;
- }
- function getShopData()
- {
- $data = getPei();
- $host = $data['host'];
- $port = $data['port'];
- $database = $data['database'];
- $username = $data['username'];
- $pass = $data['pass'];
- $tablepre = $data['tablepre'];
- $sql = "select value from ".$tablepre."yz_setting where `group`='shop' and `key`='shop'";
- $connect2 = new \PDO("mysql:host=".$host.";dbname=".$database.";port=".$port,$username,$pass);
- $connect2->prepare('set names utf8mb4')->execute();
- $shop = $connect2->query($sql);
- $shop_data = $shop->fetch();
- return $shop_data;
- }
- function yz_tomedia($src)
- {
- if (strexists($src, 'http://') || strexists($src, 'https://')) {
- return $src;
- }
- $data = getPei();
- $host = $data['host'];
- $port = $data['port'];
- $database = $data['database'];
- $username = $data['username'];
- $pass = $data['pass'];
- $table_pre = $data['tablepre'];
- $sql = "select * from {$table_pre}yz_system_setting where `key` = 'remote'";
- $connect_ = new \PDO("mysql:host=".$host.";dbname=".$database.";port=".$port,$username,$pass);
- $connect_->prepare('set names utf8mb4')->execute();
- $system_set = $connect_->query($sql);
- $remote_setting = $system_set->fetch();
- $remote_value = $remote_setting['value'];
- if ($remote_value) {
- $remote_value = unserialize($remote_value);
- $upload_type = $remote_value['type'];
- if ($upload_type) {
- switch ($upload_type) {
- case 1 :
- $attach_url_remote = $remote_value['ftp']['url'];
- break;
- case 2 :
- $attach_url_remote = $remote_value['alioss']['url'];
- break;
- case 3 :
- $attach_url_remote = $remote_value['qiniu']['url'];
- break;
- case 4 :
- $attach_url_remote = $remote_value['cos']['url'];
- break;
- }
- return $attach_url_remote . '/' . $src;
- }
- }
- $HttpHost = $_SERVER['REQUEST_SCHEME'] . '://' .$_SERVER['HTTP_HOST'];
- $attachment = '/static/';
- //判断是否是本地不带域名图片地址
- if ((strpos($src, 'http://') === false) && (strpos($src, 'https://') === false)) {
- return $HttpHost. $attachment . 'upload/' . $src;
- }
- return $src;
- }
- function strexists($string, $find)
- {
- return !(strpos($string, $find) === false);
- }
- function getUrlAddress()
- {
- }
|