adv_text.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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: adv_text.php 13462 2010-07-27 07:26:27Z monkey $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class adv_text {
  12. var $version = '2.0';
  13. var $name = 'text_name';
  14. var $description = 'text_desc';
  15. var $copyright = '<a href="http://www.comsenz.com" target="_blank">Comsenz Inc.</a>';
  16. var $targets = array('forum', 'group', 'home', 'portal');
  17. var $imagesizes = array('120x60', '250x60', '100x100');
  18. function getsetting() {
  19. global $_G;
  20. $settings = array(
  21. 'fids' => array(
  22. 'title' => 'text_fids',
  23. 'type' => 'mselect',
  24. 'value' => array(),
  25. ),
  26. 'groups' => array(
  27. 'title' => 'text_groups',
  28. 'type' => 'mselect',
  29. 'value' => array(),
  30. ),
  31. 'category' => array(
  32. 'title' => 'text_category',
  33. 'type' => 'mselect',
  34. 'value' => array(),
  35. ),
  36. );
  37. loadcache(array('forums', 'grouptype'));
  38. $settings['fids']['value'][] = $settings['groups']['value'][] = array(0, '&nbsp;');
  39. $settings['fids']['value'][] = $settings['groups']['value'][] = array(-1, 'text_index');
  40. if(empty($_G['cache']['forums'])) $_G['cache']['forums'] = array();
  41. foreach($_G['cache']['forums'] as $fid => $forum) {
  42. $settings['fids']['value'][] = array($fid, ($forum['type'] == 'forum' ? str_repeat('&nbsp;', 4) : ($forum['type'] == 'sub' ? str_repeat('&nbsp;', 8) : '')).$forum['name']);
  43. }
  44. foreach($_G['cache']['grouptype']['first'] as $gid => $group) {
  45. $settings['groups']['value'][] = array($gid, $group['name']);
  46. if($group['secondlist']) {
  47. foreach($group['secondlist'] as $sgid) {
  48. $settings['groups']['value'][] = array($sgid, str_repeat('&nbsp;', 4).$_G['cache']['grouptype']['second'][$sgid]['name']);
  49. }
  50. }
  51. }
  52. loadcache('portalcategory');
  53. $this->getcategory(0);
  54. $settings['category']['value'] = $this->categoryvalue;
  55. return $settings;
  56. }
  57. function getcategory($upid) {
  58. global $_G;
  59. foreach($_G['cache']['portalcategory'] as $category) {
  60. if($category['upid'] == $upid) {
  61. $this->categoryvalue[] = array($category['catid'], str_repeat('&nbsp;', $category['level'] * 4).$category['catname']);
  62. $this->getcategory($category['catid']);
  63. }
  64. }
  65. }
  66. function setsetting(&$advnew, &$parameters) {
  67. global $_G;
  68. if(is_array($advnew['targets'])) {
  69. $advnew['targets'] = implode("\t", $advnew['targets']);
  70. }
  71. if(is_array($parameters['extra']['fids']) && in_array(0, $parameters['extra']['fids'])) {
  72. $parameters['extra']['fids'] = array();
  73. }
  74. if(is_array($parameters['extra']['groups']) && in_array(0, $parameters['extra']['groups'])) {
  75. $parameters['extra']['groups'] = array();
  76. }
  77. }
  78. function evalcode() {
  79. return array(
  80. 'check' => '
  81. if($_G[\'basescript\'] == \'forum\' && $parameter[\'fids\'] && !(in_array($_G[\'fid\'], $parameter[\'fids\']) || CURMODULE == \'index\' && in_array(-1, $parameter[\'fids\']))
  82. || $_G[\'basescript\'] == \'group\' && $parameter[\'groups\'] && !(in_array($_G[\'grouptypeid\'], $parameter[\'groups\']) || CURMODULE == \'index\' && in_array(-1, $parameter[\'groups\']))
  83. || $_G[\'basescript\'] == \'portal\' && $parameter[\'category\'] && !(in_array($_G[\'catid\'], $parameter[\'category\']))
  84. ) {
  85. $checked = false;
  86. }',
  87. 'create' => '
  88. $advcount = count($adids);
  89. if($advcount > 5) {
  90. $minfillpercent = 0;
  91. for($cols = 5; $cols >= 3; $cols--) {
  92. if(($remainder = $advcount % $cols) == 0) {
  93. $advcols = $cols;
  94. break;
  95. } elseif($remainder / $cols > $minfillpercent) {
  96. $minfillpercent = $remainder / $cols;
  97. $advcols = $cols;
  98. }
  99. }
  100. } else {
  101. $advcols = $advcount;
  102. }
  103. $adcode = \'\';
  104. for($i = 0; $i < $advcols * ceil($advcount / $advcols); $i++) {
  105. $adcode .= (($i + 1) % $advcols == 1 || $advcols == 1 ? \'<tr>\' : \'\').
  106. \'<td width="\'.intval(100 / $advcols).\'%">\'.(isset($codes[$adids[$i]]) ? $codes[$adids[$i]] : \'&nbsp;\').\'</td>\'.
  107. (($i + 1) % $advcols == 0 ? "</tr>\n" : \'\');
  108. }
  109. $adcode = \'<table cellpadding="0" cellspacing="1">\'.$adcode.\'</table>\';
  110. ',
  111. );
  112. }
  113. }
  114. ?>