global.func.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. defined('IN_PHPCMS') or exit('No permission resources.');
  3. /**
  4. * 外部数据源缓存
  5. */
  6. function dbsource_cache() {
  7. $db = pc_base::load_model('dbsource_model');
  8. $list = $db->select();
  9. $data = array();
  10. if ($list) {
  11. foreach ($list as $val) {
  12. $data[$val['name']] = array('hostname'=>$val['host'].':'.$val['port'], 'database' =>$val['dbname'] , 'db_tablepre'=>$val['dbtablepre'], 'username' =>$val['username'],'password' => $val['password'],'charset'=>$val['charset'],'debug'=>0,'pconnect'=>0,'autoconnect'=>0);
  13. }
  14. } else {
  15. return false;
  16. }
  17. return setcache('dbsource', $data, 'commons');
  18. }
  19. /**
  20. * 获取模型PC标签配置相信
  21. * @param $module 模型名
  22. */
  23. function pc_tag_class ($module) {
  24. $filepath = PC_PATH.'modules'.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.'classes'.DIRECTORY_SEPARATOR.$module.'_tag.class.php';
  25. if (file_exists($filepath)) {
  26. $pc_tag = pc_base::load_app_class($module.'_tag', $module);
  27. if (!method_exists($pc_tag, 'pc_tag')) {
  28. showmessage(L('the_module_will_not_support_the_operation'));
  29. }
  30. $html = $pc_tag->pc_tag();
  31. } else {
  32. showmessage(L('the_module_will_not_support_the_operation'), HTTP_REFERER);
  33. }
  34. return $html;
  35. }
  36. /**
  37. * 返回模板地址。
  38. * @param $id 数据源调用ID
  39. */
  40. function template_url($id) {
  41. $filepath = CACHE_PATH.'caches_template'.DIRECTORY_SEPARATOR.'dbsource'.DIRECTORY_SEPARATOR.$id.'.php';
  42. if (!file_exists($filepath)) {
  43. $datacall = pc_base::load_model('datacall_model');
  44. $str = $datacall->get_one(array('id'=>$id), 'template');
  45. $dir = dirname($filepath);
  46. if(!is_dir($dir)) {
  47. mkdir($dir, 0777, true);
  48. }
  49. $tpl = pc_base::load_sys_class('template_cache');
  50. $str = $tpl->template_parse($str['template']);
  51. @file_put_contents($filepath, $str);
  52. }
  53. return $filepath;
  54. }
  55. ?>