PageRenderTime 48ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/source/function/function_importdata.php

https://github.com/jinbo51/DiscuzX
PHP | 185 lines | 171 code | 8 blank | 6 comment | 6 complexity | 90d3165f73b5b1d14a002df59c4c0e52 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: function_importdata.php 32104 2012-11-12 02:22:38Z monkey $
  7. */
  8. if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
  9. exit('Access Denied');
  10. }
  11. function import_smilies() {
  12. $smileyarray = getimportdata('Discuz! Smilies');
  13. $renamed = 0;
  14. if(C::t('forum_imagetype')->count_by_name('smiley', $smileyarray['name'])) {
  15. $smileyarray['name'] .= '_'.random(4);
  16. $renamed = 1;
  17. }
  18. $data = array(
  19. 'name' => $smileyarray['name'],
  20. 'type' => 'smiley',
  21. 'directory' => $smileyarray['directory'],
  22. );
  23. $typeid = C::t('forum_imagetype')->insert($data, true);
  24. foreach($smileyarray['smilies'] as $key => $smiley) {
  25. C::t('common_smiley')->insert(array('type'=>'smiley', 'typeid'=>$typeid, 'displayorder'=>$smiley['displayorder'], 'code'=>'', 'url'=>$smiley['url']));
  26. }
  27. C::t('common_smiley')->update_code_by_typeid($typeid);
  28. updatecache(array('smileytypes', 'smilies', 'smileycodes', 'smilies_js'));
  29. return $renamed;
  30. }
  31. function import_styles($ignoreversion = 1, $dir = '', $restoreid = 0, $updatecache = 1, $validate = 1) {
  32. global $_G, $importtxt, $stylearray;
  33. if(!isset($dir)) {
  34. $stylearrays = array(getimportdata('Discuz! Style'));
  35. } else {
  36. require_once libfile('function/cloudaddons');
  37. if(!$restoreid) {
  38. $dir = str_replace(array('/', '\\'), '', $dir);
  39. $templatedir = DISCUZ_ROOT.'./template/'.$dir;
  40. if($validate) {
  41. cloudaddons_validator($dir.'.template');
  42. }
  43. } else {
  44. $templatedir = DISCUZ_ROOT.$dir;
  45. $dir = basename($dir);
  46. if($validate) {
  47. cloudaddons_validator($dir.'.template');
  48. }
  49. }
  50. $searchdir = dir($templatedir);
  51. $stylearrays = array();
  52. while($searchentry = $searchdir->read()) {
  53. if(substr($searchentry, 0, 13) == 'discuz_style_' && fileext($searchentry) == 'xml') {
  54. $importfile = $templatedir.'/'.$searchentry;
  55. $importtxt = implode('', file($importfile));
  56. $stylearrays[] = getimportdata('Discuz! Style');
  57. }
  58. }
  59. }
  60. foreach($stylearrays as $stylearray) {
  61. if(empty($ignoreversion) && strip_tags($stylearray['version']) != strip_tags($_G['setting']['version'])) {
  62. cpmsg('styles_import_version_invalid', 'action=styles', 'error', array('cur_version' => $stylearray['version'], 'set_version' => $_G['setting']['version']));
  63. }
  64. if(!$restoreid) {
  65. $renamed = 0;
  66. if($stylearray['templateid'] != 1) {
  67. $templatedir = DISCUZ_ROOT.'./'.$stylearray['directory'];
  68. if(!is_dir($templatedir)) {
  69. if(!@mkdir($templatedir, 0777)) {
  70. $basedir = dirname($stylearray['directory']);
  71. cpmsg('styles_import_directory_invalid', 'action=styles', 'error', array('basedir' => $basedir, 'directory' => $stylearray['directory']));
  72. }
  73. }
  74. if(!($templateid = C::t('common_template')->get_templateid($stylearray['tplname']))) {
  75. $templateid = C::t('common_template')->insert(array(
  76. 'name' => $stylearray['tplname'],
  77. 'directory' => $stylearray['directory'],
  78. 'copyright' => $stylearray['copyright']
  79. ), true);
  80. }
  81. } else {
  82. $templateid = 1;
  83. }
  84. if(C::t('common_style')->check_stylename($stylearray['name'])) {
  85. $renamed = 1;
  86. } else {
  87. $styleidnew = C::t('common_style')->insert(array('name' => $stylearray['name'], 'templateid' => $templateid), true);
  88. }
  89. } else {
  90. $styleidnew = $restoreid;
  91. C::t('common_stylevar')->delete_by_styleid($styleidnew);
  92. }
  93. foreach($stylearray['style'] as $variable => $substitute) {
  94. $substitute = @dhtmlspecialchars($substitute);
  95. C::t('common_stylevar')->insert(array('styleid' => $styleidnew, 'variable' => $variable, 'substitute' => $substitute));
  96. }
  97. }
  98. if($dir) {
  99. cloudaddons_installlog($dir.'.template');
  100. }
  101. if($updatecache) {
  102. updatecache('styles');
  103. updatecache('setting');
  104. }
  105. return $renamed;
  106. }
  107. function import_block($xmlurl, $clientid, $xmlkey = '', $signtype = '', $ignoreversion = 1, $update = 0) {
  108. global $_G, $importtxt;
  109. $_GET['importtype'] = $_GET['importtxt'] = '';
  110. $xmlurl = strip_tags($xmlurl);
  111. $clientid = strip_tags($clientid);
  112. $xmlkey = strip_tags($xmlkey);
  113. $parse = parse_url($xmlurl);
  114. if(!empty($parse['host'])) {
  115. $queryarr = explode('&', $parse['query']);
  116. $para = array();
  117. foreach($queryarr as $value){
  118. $k = $v = '';
  119. list($k,$v) = explode('=', $value);
  120. if(!empty($k) && !empty($v)) {
  121. $para[$k] = $v;
  122. }
  123. }
  124. $para['clientid'] = $clientid;
  125. $para['op'] = 'getconfig';
  126. $para['charset'] = CHARSET;
  127. $signurl = create_sign_url($para, $xmlkey, $signtype);
  128. $pos = strpos($xmlurl, '?');
  129. $pos = $pos === false ? strlen($xmlurl) : $pos;
  130. $signurl = substr($xmlurl, 0, $pos).'?'.$signurl;
  131. $importtxt = @dfsockopen($signurl);
  132. } else {
  133. $importtxt = @implode('', file($xmlurl));
  134. }
  135. $blockarrays = getimportdata('Discuz! Block', 0);
  136. if(empty($blockarrays['name']) || empty($blockarrays['fields']) || empty($blockarrays['getsetting'])) {
  137. cpmsg(cplang('import_data_typeinvalid').cplang($importtxt), '', 'error');
  138. }
  139. if(empty($ignoreversion) && strip_tags($blockarrays['version']) != strip_tags($_G['setting']['version'])) {
  140. cpmsg(cplang('blockxml_import_version_invalid'), '', 'error', array('cur_version' => $blockarrays['version'], 'set_version' => $_G['setting']['version']));
  141. }
  142. $data = array(
  143. 'name' => dhtmlspecialchars($blockarrays['name']),
  144. 'version' => dhtmlspecialchars($blockarrays['version']),
  145. 'url' => $xmlurl,
  146. 'clientid' => $clientid,
  147. 'key' => $xmlkey,
  148. 'signtype' => !empty($signtype) ? 'MD5' : '',
  149. 'data' => serialize($blockarrays)
  150. );
  151. if(!$update) {
  152. C::t('common_block_xml')->insert($data);
  153. } else {
  154. C::t('common_block_xml')->update($update, $data);
  155. }
  156. }
  157. function create_sign_url($para, $key = '', $signtype = ''){
  158. ksort($para);
  159. $url = http_build_query($para);
  160. if(!empty($signtype) && strtoupper($signtype) == 'MD5') {
  161. $sign = md5(urldecode($url).$key);
  162. $url = $url.'&sign='.$sign;
  163. } else {
  164. $url = $url.'&sign='.$key;
  165. }
  166. return $url;
  167. }
  168. ?>