block_xml.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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: block_xml.php 28663 2012-03-07 05:50:37Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class block_xml extends discuz_block {
  12. var $blockdata = array();
  13. function block_xml($xmlid = null) {
  14. if(!empty($xmlid)) {
  15. if(!($blockxml = C::t('common_block_xml')->fetch($xmlid))) {
  16. return;
  17. }
  18. $this->blockdata = $blockxml;
  19. $this->blockdata['data'] = (array)dunserialize($blockxml['data']);
  20. } else {
  21. foreach(C::t('common_block_xml')->range() as $value) {
  22. $one = $value;
  23. $one['data'] = (array)dunserialize($value['data']);
  24. $this->blockdata[] = $one;
  25. }
  26. }
  27. }
  28. function name() {
  29. return dhtmlspecialchars($this->blockdata['data']['name']);
  30. }
  31. function blockclass() {
  32. return dhtmlspecialchars($this->blockdata['data']['blockclass']);
  33. }
  34. function fields() {
  35. return dhtmlspecialchars($this->blockdata['data']['fields']);
  36. }
  37. function getsetting() {
  38. return dhtmlspecialchars($this->blockdata['data']['getsetting']);
  39. }
  40. function getdata($style, $parameter) {
  41. $parameter = $this->cookparameter($parameter);
  42. $array = array();
  43. foreach($parameter as $key => $value) {
  44. if(is_array($value)) {
  45. $parameter[$key] = implode(',', $value);
  46. }
  47. }
  48. $parameter['clientid'] = $this->blockdata['clientid'];
  49. $parameter['op'] = 'getdata';
  50. $parameter['charset'] = CHARSET;
  51. $parameter['version'] = $this->blockdata['version'];
  52. $xmlurl = $this->blockdata['url'];
  53. $parse = parse_url($xmlurl);
  54. if(!empty($parse['host'])) {
  55. define('IN_ADMINCP', true);
  56. require_once libfile('function/importdata');
  57. $importtxt = @dfsockopen($xmlurl, 0, create_sign_url($parameter, $this->blockdata['key'], $this->blockdata['signtype']));
  58. } else {
  59. $ctx = stream_context_create(array('http' => array('timeout' => 20)));
  60. $importtxt = @file_get_contents($xmlurl, false, $ctx);
  61. }
  62. if($importtxt) {
  63. require libfile('class/xml');
  64. $array = xml2array($importtxt);
  65. }
  66. $idtype = 'xml_'.$this->blockdata['id'];
  67. foreach($array['data'] as $key=>$value) {
  68. $value['idtype'] = $idtype;
  69. $array['data'][$key] = $value;
  70. }
  71. if(empty($array['data'])) $array['data'] = null;
  72. return $array;
  73. }
  74. }
  75. ?>