fun.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: yunzhong
  5. * Date: 2020/12/17
  6. * Time: 11:34
  7. */
  8. function returnUrl()
  9. {
  10. $host = "";
  11. $port = 0;
  12. $database = "";
  13. $username = "";
  14. $pass = "";
  15. $tablepre = "ims_";
  16. //获取数据库配置
  17. if (file_exists("./database/config.php")) {
  18. include("./database/config.php");
  19. $host = $config['db']['master']['host'];
  20. $port = $config['db']['master']['port'];
  21. $database = $config['db']['master']['database'];
  22. $username = $config['db']['master']['username'];
  23. $pass = $config['db']['master']['password'];
  24. $tablepre = $config['db']['master']['tablepre'];
  25. } else {
  26. $env = file_get_contents('./.env');
  27. $env = str_replace("\n",",",$env);
  28. $env = str_replace(",,",",",$env);
  29. $env = rtrim($env,',');
  30. $env = explode(",",$env);
  31. if (is_array($env) && count($env) > 0) {
  32. foreach ($env as $kk => $vv) {
  33. if (strstr($vv, "DB_HOST")) {
  34. $host = explode("=", $vv)[1];
  35. }
  36. if (strstr($vv, "DB_PORT")) {
  37. $port = explode("=", $vv)[1];
  38. }
  39. if (strstr($vv, "DB_DATABASE")) {
  40. $database = explode("=", $vv)[1];
  41. }
  42. if (strstr($vv, "DB_USERNAME")) {
  43. $username = explode("=", $vv)[1];
  44. }
  45. if (strstr($vv, "DB_PASSWORD")) {
  46. $pass = explode("=", $vv)[1];
  47. }
  48. if (strstr($vv, "DB_PREFIX")) {
  49. $tablepre = explode("=", $vv)[1];
  50. }
  51. }
  52. }
  53. }
  54. if ($host != "''" && $database != "''" && $username != "''" && $pass != "''") {
  55. $sql = "select * from " . $tablepre . "yz_setting where uniacid = 0 and `group` = 'official_website' and `key` = 'theme_set'";
  56. try {
  57. $connect = new \PDO("mysql:host=" . $host . ";dbname=" . $database . ";port=" . $port, $username, $pass);
  58. $connect->prepare('set names utf8mb4')->execute();
  59. $res = $connect->query($sql);
  60. $data = $res->fetch();
  61. } catch (\PDOException $e) {
  62. echo "Error!: " . $e->getMessage() . "<br/>";
  63. die();
  64. }
  65. $set = unserialize($data['value']);
  66. if ($set['is_open'] == 2) {
  67. $theme_sql = "select * from " .$tablepre ."yz_official_website_theme_set where `identification` = 'uniacid_theme' and `is_default` = 1";
  68. try {
  69. $theme_connect = new \PDO("mysql:host=" . $host . ";dbname=" . $database . ";port=" . $port, $username, $pass);
  70. $theme_connect->prepare('set names utf8mb4')->execute();
  71. $theme_res = $theme_connect->query($theme_sql);
  72. $theme_data = $theme_res->fetch();
  73. if ($theme_data) {
  74. //https://dev8.yunzmall.com/plugins/shop_server/home?i=1
  75. $theme_result = !empty($theme_data['basic']) ? json_decode($theme_data['basic'],true) : [];
  76. $url = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . "/plugins/shop_server/home?i=".$theme_result['cus_uniacid'];
  77. } else {
  78. $default_sql = "select * from " .$tablepre ."yz_official_website_theme_set where `identification` != 'uniacid_theme' and `is_default` = 1";
  79. $default_connect = new \PDO("mysql:host=" . $host . ";dbname=" . $database . ";port=" . $port, $username, $pass);
  80. $default_connect->prepare('set names utf8mb4')->execute();
  81. $default_res = $default_connect->query($default_sql);
  82. $default_data = $default_res->fetch();
  83. if ($default_data) {
  84. $url = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . '/officialwebsite.php?page_name=default_home';
  85. } elseif($set['is_customize'] == '1' && $set['customize_url']) {
  86. $url = $set['customize_url']; //自定义跳转链接
  87. } else {
  88. $url = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . '/admin.html';
  89. }
  90. }
  91. } catch (\PDOException $e) {
  92. echo "Error!: " . $e->getMessage() . "<br/>";
  93. die();
  94. }
  95. } else {
  96. $url = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . '/admin.html';
  97. }
  98. } else {
  99. $url = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . '/admin.html';
  100. }
  101. return $url;
  102. }
  103. function getPei()
  104. {
  105. $host = "";
  106. $port = 0;
  107. $database = "";
  108. $username = "";
  109. $pass = "";
  110. $tablepre = "ims_";
  111. if (file_exists("./database/config.php")) {
  112. include("./database/config.php");
  113. $host = $config['db']['master']['host'];
  114. $port = $config['db']['master']['port'];
  115. $database = $config['db']['master']['database'];
  116. $username = $config['db']['master']['username'];
  117. $pass = $config['db']['master']['password'];
  118. $tablepre = $config['db']['master']['tablepre'];
  119. } else {
  120. $env = file_get_contents('./.env');
  121. $env = str_replace("\n",",",$env);
  122. $env = str_replace(",,",",",$env);
  123. $env = rtrim($env,',');
  124. $env = explode(",",$env);
  125. if (is_array($env) && count($env) > 0) {
  126. foreach ($env as $kk=>$vv) {
  127. if (strstr($vv,"DB_HOST")) {
  128. $host = explode("=",$vv)[1];
  129. }
  130. if (strstr($vv,"DB_PORT")) {
  131. $port = explode("=",$vv)[1];
  132. }
  133. if (strstr($vv,"DB_DATABASE")) {
  134. $database = explode("=",$vv)[1];
  135. }
  136. if (strstr($vv,"DB_USERNAME")) {
  137. $username = explode("=",$vv)[1];
  138. }
  139. if (strstr($vv,"DB_PASSWORD")) {
  140. $pass = explode("=",$vv)[1];
  141. }
  142. if (strstr($vv,"DB_PREFIX")) {
  143. $tablepre = explode("=",$vv)[1];
  144. }
  145. }
  146. }
  147. }
  148. return ["host"=>$host,"port"=>$port,"database"=>$database,"username"=>$username,"pass"=>$pass,"tablepre"=>$tablepre];
  149. }
  150. function getOfficial($name)
  151. {
  152. $data = getPei();
  153. $host = $data['host'];
  154. $port = $data['port'];
  155. $database = $data['database'];
  156. $username = $data['username'];
  157. $pass = $data['pass'];
  158. $tablepre = $data['tablepre'];
  159. $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";
  160. $connect = new \PDO("mysql:host=".$host.";dbname=".$database.";port=".$port,$username,$pass);
  161. $connect->prepare('set names utf8mb4')->execute();
  162. $official = $connect->prepare($sql);
  163. $official->bindParam(':identification',$name,PDO::PARAM_STR,15);
  164. $official->execute();
  165. $result = $official->fetch();
  166. $result['thumb'] = empty($result['thumb']) ? "" : yz_tomedia($result['thumb']);
  167. return $result;
  168. }
  169. function getCommonArticle($uniacid,$cate=0)
  170. {
  171. $data = getPei();
  172. $host = $data['host'];
  173. $port = $data['port'];
  174. $database = $data['database'];
  175. $username = $data['username'];
  176. $pass = $data['pass'];
  177. $tablepre = $data['tablepre'];
  178. $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;
  179. if (!empty($cate)) {
  180. $web_article_sql .= " and ypa.category_id = :cate ";
  181. }
  182. $web_article_sql .= " order by ypa.id desc limit 6";
  183. $connect3 = new \PDO("mysql:host=".$host.";dbname=".$database.";port=".$port,$username,$pass);
  184. $connect3->prepare('set names utf8mb4')->execute();
  185. $web_res = $connect3->prepare($web_article_sql);
  186. $web_res->bindParam(':cate',$cate,PDO::PARAM_INT);
  187. $web_res->execute();
  188. $web_rel = $web_res->fetchAll();
  189. if ($web_rel) {
  190. foreach ($web_rel as $key=>$value) {
  191. $web_rel[$key]['web_url'] = $_SERVER['REQUEST_SCHEME'] . '://' .$_SERVER['HTTP_HOST']."/officialwebsite.php?page_name=resource_detail&article=".$value['id'];
  192. $web_rel[$key]['thumb'] = empty($value['thumb']) ? "" : yz_tomedia($value['thumb']);
  193. }
  194. }
  195. $connect3 = null;
  196. return $web_rel;
  197. }
  198. function getReadVolumeArticle($uniacid)
  199. {
  200. $data = getPei();
  201. $host = $data['host'];
  202. $port = $data['port'];
  203. $database = $data['database'];
  204. $username = $data['username'];
  205. $pass = $data['pass'];
  206. $tablepre = $data['tablepre'];
  207. $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 ";
  208. $connect4 = new \PDO("mysql:host=".$host.";dbname=".$database.";port=".$port,$username,$pass);
  209. $connect4->prepare('set names utf8mb4')->execute();
  210. $res_home = $connect4->query($home_article_sql);
  211. $home_data = $res_home->fetchAll();
  212. if ($home_data) {
  213. foreach ($home_data as $key=>$value) {
  214. $home_data[$key]['web_url'] = $_SERVER['REQUEST_SCHEME'] . '://' .$_SERVER['HTTP_HOST']."/officialwebsite.php?page_name=resource_detail&article=".$value['id'];
  215. $home_data[$key]['thumb'] = empty($value['thumb']) ? "" : yz_tomedia($value['thumb']);
  216. }
  217. }
  218. $connect4 = null;
  219. return $home_data;
  220. }
  221. function getPageCate($uniacid,$cate=0)
  222. {
  223. $data = getPei();
  224. $host = $data['host'];
  225. $port = $data['port'];
  226. $database = $data['database'];
  227. $username = $data['username'];
  228. $pass = $data['pass'];
  229. $tablepre = $data['tablepre'];
  230. $article_cate_sql = "select id,name,cate_desc,cate_img from ".$tablepre."yz_plugin_article_category where uniacid = ".$uniacid;
  231. if (!empty($cate)) {
  232. $article_cate_sql .= " and id = :cate ";
  233. }
  234. $article_cate_sql ." limit 1";
  235. $connect5 = new \PDO("mysql:host=".$host.";dbname=".$database.";port=".$port,$username,$pass);
  236. $connect5->prepare('set names utf8mb4')->execute();
  237. $res_article_cate = $connect5->prepare($article_cate_sql);
  238. $res_article_cate->bindParam(':cate',$cate,PDO::PARAM_INT);
  239. $res_article_cate->execute();
  240. $article_cate_data = $res_article_cate->fetch();
  241. if ($article_cate_data) {
  242. $article_cate_data['cate_url'] = $_SERVER['REQUEST_SCHEME'] . '://' .$_SERVER['HTTP_HOST']."/officialwebsite.php?page_name=resource_page&cate=".$article_cate_data['id'];
  243. $article_cate_data['cate_img'] = empty($article_cate_data['cate_img']) ? "" : yz_tomedia($article_cate_data['cate_img']);
  244. }
  245. $connect5 = null;
  246. return $article_cate_data;
  247. }
  248. function getTotalCate($uniacid,$cate=0)
  249. {
  250. $data = getPei();
  251. $host = $data['host'];
  252. $port = $data['port'];
  253. $database = $data['database'];
  254. $username = $data['username'];
  255. $pass = $data['pass'];
  256. $tablepre = $data['tablepre'];
  257. $article_total_sql = "select count(id) as article_total,sum(virtual_read_num) as article_read from ".$tablepre."yz_plugin_article where uniacid = ".$uniacid;
  258. if (!empty($cate)) {
  259. $article_total_sql .= " and category_id = :cate ";
  260. }
  261. $connect6 = new \PDO("mysql:host=".$host.";dbname=".$database.";port=".$port,$username,$pass);
  262. $connect6->prepare('set names utf8mb4')->execute();
  263. $article_total = $connect6->prepare($article_total_sql);
  264. $article_total->bindParam(':cate',$cate,PDO::PARAM_INT);
  265. $article_total->execute();
  266. $article_total_rel = $article_total->fetch();
  267. $connect6 = null;
  268. return $article_total_rel;
  269. }
  270. function getDetailArticle($article_id)
  271. {
  272. $data = getPei();
  273. $host = $data['host'];
  274. $port = $data['port'];
  275. $database = $data['database'];
  276. $username = $data['username'];
  277. $pass = $data['pass'];
  278. $tablepre = $data['tablepre'];
  279. $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 ";
  280. $connect1 = new \PDO("mysql:host=".$host.";dbname=".$database.";port=".$port,$username,$pass);
  281. $connect1->prepare('set names utf8mb4')->execute();
  282. $res = $connect1->prepare($sql);
  283. $res->bindParam(':article_id',$article_id,PDO::PARAM_INT);
  284. $res->execute();
  285. $rel = $res->fetch();
  286. $rel['off_url'] = $_SERVER['REQUEST_SCHEME'] . '://' .$_SERVER['HTTP_HOST']."/officialwebsite.php?page_name=resource_page";
  287. $rel['thumb'] = empty($rel['thumb']) ? "" : yz_tomedia($rel['thumb']);
  288. $rel['cate_img'] = empty($rel['cate_img']) ? "" : yz_tomedia($rel['cate_img']);
  289. $connect1 = null;
  290. return $rel;
  291. }
  292. function getShopData()
  293. {
  294. $data = getPei();
  295. $host = $data['host'];
  296. $port = $data['port'];
  297. $database = $data['database'];
  298. $username = $data['username'];
  299. $pass = $data['pass'];
  300. $tablepre = $data['tablepre'];
  301. $sql = "select value from ".$tablepre."yz_setting where `group`='shop' and `key`='shop'";
  302. $connect2 = new \PDO("mysql:host=".$host.";dbname=".$database.";port=".$port,$username,$pass);
  303. $connect2->prepare('set names utf8mb4')->execute();
  304. $shop = $connect2->query($sql);
  305. $shop_data = $shop->fetch();
  306. return $shop_data;
  307. }
  308. function yz_tomedia($src)
  309. {
  310. if (strexists($src, 'http://') || strexists($src, 'https://')) {
  311. return $src;
  312. }
  313. $data = getPei();
  314. $host = $data['host'];
  315. $port = $data['port'];
  316. $database = $data['database'];
  317. $username = $data['username'];
  318. $pass = $data['pass'];
  319. $table_pre = $data['tablepre'];
  320. $sql = "select * from {$table_pre}yz_system_setting where `key` = 'remote'";
  321. $connect_ = new \PDO("mysql:host=".$host.";dbname=".$database.";port=".$port,$username,$pass);
  322. $connect_->prepare('set names utf8mb4')->execute();
  323. $system_set = $connect_->query($sql);
  324. $remote_setting = $system_set->fetch();
  325. $remote_value = $remote_setting['value'];
  326. if ($remote_value) {
  327. $remote_value = unserialize($remote_value);
  328. $upload_type = $remote_value['type'];
  329. if ($upload_type) {
  330. switch ($upload_type) {
  331. case 1 :
  332. $attach_url_remote = $remote_value['ftp']['url'];
  333. break;
  334. case 2 :
  335. $attach_url_remote = $remote_value['alioss']['url'];
  336. break;
  337. case 3 :
  338. $attach_url_remote = $remote_value['qiniu']['url'];
  339. break;
  340. case 4 :
  341. $attach_url_remote = $remote_value['cos']['url'];
  342. break;
  343. }
  344. return $attach_url_remote . '/' . $src;
  345. }
  346. }
  347. $HttpHost = $_SERVER['REQUEST_SCHEME'] . '://' .$_SERVER['HTTP_HOST'];
  348. $attachment = '/static/';
  349. //判断是否是本地不带域名图片地址
  350. if ((strpos($src, 'http://') === false) && (strpos($src, 'https://') === false)) {
  351. return $HttpHost. $attachment . 'upload/' . $src;
  352. }
  353. return $src;
  354. }
  355. function strexists($string, $find)
  356. {
  357. return !(strpos($string, $find) === false);
  358. }
  359. function getUrlAddress()
  360. {
  361. }