adv_couplebanner.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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_couplebanner.php 26692 2011-12-20 05:27:38Z monkey $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class adv_couplebanner {
  12. var $version = '1.1';
  13. var $name = 'couplebanner_name';
  14. var $description = 'couplebanner_desc';
  15. var $copyright = '<a href="http://www.comsenz.com" target="_blank">Comsenz Inc.</a>';
  16. var $targets = array('portal', 'home', 'member', 'forum', 'group', 'search', 'userapp', 'plugin', 'custom');
  17. var $imagesizes = array('60x120', '60x250', '60x468');
  18. function getsetting() {
  19. global $_G;
  20. $settings = array(
  21. 'fids' => array(
  22. 'title' => 'couplebanner_fids',
  23. 'type' => 'mselect',
  24. 'value' => array(),
  25. ),
  26. 'groups' => array(
  27. 'title' => 'couplebanner_groups',
  28. 'type' => 'mselect',
  29. 'value' => array(),
  30. ),
  31. 'category' => array(
  32. 'title' => 'couplebanner_category',
  33. 'type' => 'mselect',
  34. 'value' => array(),
  35. ),
  36. 'position' => array(
  37. 'title' => 'couplebanner_position',
  38. 'type' => 'mradio',
  39. 'value' => array(
  40. array(1, 'couplebanner_position_left'),
  41. array(2, 'couplebanner_position_right'),
  42. ),
  43. 'default' => 1,
  44. ),
  45. 'coupleadid' => array(
  46. 'title' => 'couplebanner_coupleadid',
  47. 'type' => 'select',
  48. 'value' => array(),
  49. ),
  50. 'disableclose' => array(
  51. 'title' => 'couplebanner_disableclose',
  52. 'type' => 'mradio',
  53. 'value' => array(
  54. array(0, 'couplebanner_show'),
  55. array(1, 'couplebanner_hidden'),
  56. ),
  57. 'default' => 0,
  58. )
  59. );
  60. loadcache(array('forums', 'grouptype'));
  61. $settings['fids']['value'][] = $settings['groups']['value'][] = array(0, '&nbsp;');
  62. $settings['fids']['value'][] = $settings['groups']['value'][] = array(-1, 'couplebanner_index');
  63. if(empty($_G['cache']['forums'])) $_G['cache']['forums'] = array();
  64. foreach($_G['cache']['forums'] as $fid => $forum) {
  65. $settings['fids']['value'][] = array($fid, ($forum['type'] == 'forum' ? str_repeat('&nbsp;', 4) : ($forum['type'] == 'sub' ? str_repeat('&nbsp;', 8) : '')).$forum['name']);
  66. }
  67. foreach($_G['cache']['grouptype']['first'] as $gid => $group) {
  68. $settings['groups']['value'][] = array($gid, str_repeat('&nbsp;', 4).$group['name']);
  69. if($group['secondlist']) {
  70. foreach($group['secondlist'] as $sgid) {
  71. $settings['groups']['value'][] = array($sgid, str_repeat('&nbsp;', 8).$_G['cache']['grouptype']['second'][$sgid]['name']);
  72. }
  73. }
  74. }
  75. foreach(C::t('common_advertisement')->fetch_all_by_type('couplebanner') as $couple) {
  76. $settings['coupleadid']['value'][] = array($couple['advid'], $couple['title']);
  77. }
  78. loadcache('portalcategory');
  79. $this->categoryvalue[] = array(-1, 'couplebanner_index');
  80. $this->getcategory(0);
  81. $settings['category']['value'] = $this->categoryvalue;
  82. return $settings;
  83. }
  84. function getcategory($upid) {
  85. global $_G;
  86. foreach($_G['cache']['portalcategory'] as $category) {
  87. if($category['upid'] == $upid) {
  88. $this->categoryvalue[] = array($category['catid'], str_repeat('&nbsp;', $category['level'] * 4).$category['catname']);
  89. $this->getcategory($category['catid']);
  90. }
  91. }
  92. }
  93. function setsetting(&$advnew, &$parameters) {
  94. global $_G;
  95. if(is_array($advnew['targets'])) {
  96. $advnew['targets'] = implode("\t", $advnew['targets']);
  97. }
  98. if(is_array($parameters['extra']['fids']) && in_array(0, $parameters['extra']['fids'])) {
  99. $parameters['extra']['fids'] = array();
  100. }
  101. if(is_array($parameters['extra']['groups']) && in_array(0, $parameters['extra']['groups'])) {
  102. $parameters['extra']['groups'] = array();
  103. }
  104. if(is_array($parameters['extra']['category']) && in_array(0, $parameters['extra']['category'])) {
  105. $parameters['extra']['category'] = array();
  106. }
  107. }
  108. function evalcode() {
  109. return array(
  110. 'check' => '
  111. if($params[2] != $parameter[\'position\']
  112. || $_G[\'basescript\'] == \'forum\' && $parameter[\'fids\'] && !(in_array($_G[\'fid\'], $parameter[\'fids\']) || CURMODULE == \'index\' && in_array(-1, $parameter[\'fids\']))
  113. || $_G[\'basescript\'] == \'group\' && $parameter[\'groups\'] && !(in_array($_G[\'grouptypeid\'], $parameter[\'groups\']) || CURMODULE == \'index\' && in_array(-1, $parameter[\'groups\']))
  114. || $_G[\'basescript\'] == \'portal\' && $parameter[\'category\'] && !(!empty($_G[\'catid\']) && in_array($_G[\'catid\'], $parameter[\'category\']) || empty($_G[\'catid\']) && in_array(-1, $parameter[\'category\']))
  115. ) {
  116. $checked = false;
  117. }',
  118. 'create' => '
  119. if(empty($_G[\'couplebrother\'])) {
  120. $coupleadid = $adids[array_rand($adids)];
  121. $_G[\'couplebrother\'] = $parameters[$coupleadid][\'coupleadid\'];
  122. } else {
  123. $coupleadid = $_G[\'couplebrother\'];
  124. }
  125. $adcode = empty($parameter[\'disableclose\']) ? (empty($_G[\'cookie\'][\'adclose_\'.$coupleadid]) ? $codes[$coupleadid].\'<br /><a href="javascript:;" onclick="setcookie(\\\'adclose_\'.$coupleadid.\'\\\', 1, 86400);this.parentNode.style.display=\\\'none\\\'"><img src="\'.STATICURL.\'image/common/ad_close.gif" /></a>\' : \'\') : $codes[$coupleadid];
  126. ',
  127. );
  128. }
  129. }
  130. ?>