adv.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <?php
  2. function get_style_forminput($code = '', $array = '')
  3. {
  4. $title = is_array($array) ? $array['title'] : '';
  5. $url = is_array($array) ? $array['url'] : '';
  6. $link = is_array($array) ? $array['link'] : '';
  7. $size = is_array($array) ? $array['size'] : '';
  8. $width = is_array($array) ? $array['width'] : '';
  9. $height = is_array($array) ? $array['height'] : '';
  10. $alt = is_array($array) ? $array['alt'] : '';
  11. $vbm_style_form = array('code' => '
  12. <table border="0" cellspacing="0" cellpadding="0" class="vbm">
  13. <tr class="firstr"><td colspan="2">HTML 代码</td></tr>
  14. <tr><td width="45%" bgcolor="white" valign="top">广告 HTML 代码:<br /><i style="color:#666">请直接输入需要展现的广告的 HTML 代码</i></td><td bgcolor="white"><textarea rows="10" name="advnew[code][html]" id="advnew[code][html]" cols="50">' . $code . '</textarea></td></tr>
  15. </table>', 'text' => '
  16. <table border="0" cellspacing="0" cellpadding="0" class="vbm">
  17. <tr class="firstr"><td colspan="2">文字广告</td></tr>
  18. <tr><td width="45%" bgcolor="white" >文字内容(<font color="red">*必填</font>):<br /><i style="color:#666">请输入文字广告的显示内容</i></td><td bgcolor="white"><input class="text" type="text" size="50" name="advnew[text][title]" value="' . $title . '" >
  19. </td>
  20. </tr>
  21. <tr>
  22. <td width="45%" bgcolor="white" >文字链接(<font color="red">*必填</font>):<br /><i style="color:#666">请输入文字广告指向的 URL 链接地址</i></td><td bgcolor="white"><input class="text" type="text" size="50" name="advnew[text][link]" value="' . $link . '" >
  23. </td>
  24. </tr>
  25. <tr>
  26. <td width="45%" bgcolor="white" >文字大小(选填):<br /><i style="color:#666">请输入文字广告的内容显示字体,可使用 pt、px、em 为单位</i></td>
  27. <td bgcolor="white"><input class="text" type="text" size="50" name="advnew[text][size]" value="' . $size . '" >
  28. </td>
  29. </tr>
  30. </table>', 'image' => '
  31. <table border="0" cellspacing="0" cellpadding="0" class="vbm">
  32. <tr class="firstr"><td colspan="2">图片广告</td></tr>
  33. <tr><td width="45%" bgcolor="white" >图片地址(<font color="red">*必填</font>):<br /><i style="color:#666">请输入图片广告的图片调用地址</i></td><td bgcolor="white">
  34. <input name="advnew[image][url]" id=imgsrc type="text" class="text" value="' . $url . '"/>
  35. <label><input type="radio" onclick=\'document.getElementById("iframe").style.display = "none";\' name="ifout" value="no" checked="checked" class="radio"/>远程图片</label>
  36. <label><input type="radio" onclick=\'document.getElementById("iframe").style.display = "block";\' name="ifout" value="yes" class="radio"/>本地上传</label>
  37. <iframe src="include/upfile.php?watermark=0&adv=1" width="450" frameborder="0" scrolling="no" onload="this.height=iFrame1.document.body.scrollHeight" id="iframe" style="display:none; margin-top:10px"></iframe>
  38. </td>
  39. </tr>
  40. <tr>
  41. <td width="45%" bgcolor="white" >图片链接(<font color="red">*必填</font>):<br /><i style="color:#666">请输入图片广告指向的 URL 链接地址</i></td>
  42. <td bgcolor="white"><input class="text" type="text" size="50" name="advnew[image][link]" value="' . $link . '" >
  43. </td>
  44. </tr>
  45. <tr>
  46. <td width="45%" bgcolor="white" >图片宽度(选填):<br /><i style="color:#666">请输入图片广告的宽度,单位为像素</i></td>
  47. <td bgcolor="white"><input class="text" type="text" size="50" name="advnew[image][width]" value="' . $width . '" ></td>
  48. </tr>
  49. <tr><td width="45%" bgcolor="white" >图片高度(选填):<br /><i style="color:#666">请输入图片广告的高度,单位为像素</i></td><td bgcolor="white"><input class="text" type="text" size="50" name="advnew[image][height]" value="' . $height . '" >
  50. </td>
  51. </tr>
  52. <tr>
  53. <td width="45%" bgcolor="white" >图片替换文字(选填):<br /><i style="color:#666">请输入图片广告的鼠标悬停文字信息</i></td><td bgcolor="white"><input class="text" type="text" size="50" name="advnew[image][alt]" value="' . $alt . '" >
  54. </td>
  55. </tr>
  56. </table>', 'flash' => '
  57. <table border="0" cellspacing="0" cellpadding="0" class="vbm">
  58. <tr class="firstr"><td colspan="2">Flash 广告</td></tr>
  59. <tr><td width="45%" bgcolor="white" >Flash 地址(<font color="red">*必填</font>):<br /><i style="color:#666">请输入 Flash 广告的调用地址</i></td>
  60. <td bgcolor="white"><input class="text" type="text" size="50" name="advnew[flash][url]" value="' . $url . '" >
  61. </td>
  62. </tr>
  63. <tr>
  64. <td width="45%" bgcolor="white">Flash 宽度(<font color="red">*必填</font>):<br /><i style="color:#666">请输入 Flash 广告的宽度,单位为像素</i></td>
  65. <td bgcolor="white"><input class="text" type="text" size="50" name="advnew[flash][width]" value="' . $width . '" >
  66. </td>
  67. </tr>
  68. <tr>
  69. <td width="45%" bgcolor="white" >Flash 高度(<font color="red">*必填</font>):<br /><i style="color:#666">请输入 Flash 广告的高度,单位为像素</i></td>
  70. <td bgcolor="white"><input class="text" type="text" size="50" name="advnew[flash][height]" value="' . $height . '" >
  71. </td>
  72. </tr>
  73. </table>');
  74. foreach ($vbm_style_form as $ktypeform => $vform) {
  75. $mymps .= '<div id="style_' . $ktypeform . '" style="';
  76. if (is_array($array)) {
  77. $mymps .= $array[style] == $ktypeform ? 'display:yes' : 'display:none';
  78. }
  79. else {
  80. $mymps .= $array == $ktypeform ? 'display:yes' : 'display:none';
  81. }
  82. $mymps .= '" class="maintablediv">';
  83. $mymps .= $vform;
  84. $mymps .= '</div>';
  85. }
  86. return $mymps;
  87. }
  88. function get_adv_style($style = '', $formname = 'style')
  89. {
  90. global $vbm_adv_style;
  91. $vbm_adv_style_form = '<select name=\'' . $formname . '\' id=\'' . $formname . '\' style="vertical-align: middle" onchange="var styles, key;styles=new Array(\'code\',\'text\',\'image\',\'flash\'); for(key in styles) {var obj=$obj(\'style_\'+styles[key]); obj.style.display=styles[key]==this.options[this.selectedIndex].value?\'\':\'none\';}">';
  92. foreach ($vbm_adv_style as $k => $v) {
  93. if ($k == $style && $k != '') {
  94. $vbm_adv_style_form .= '<option value=\'' . $k . '\' selected style=\'background-color:#6EB00C;color:white\'>' . $v . '</option>
  95. ';
  96. }
  97. else {
  98. $vbm_adv_style_form .= '<option value=\'' . $k . '\'>' . $v . '</option>
  99. ';
  100. }
  101. }
  102. $vbm_adv_style_form .= '</select>
  103. ';
  104. return $vbm_adv_style_form;
  105. }
  106. function get_adv_option($type = '', $formname = 'type')
  107. {
  108. global $vbm_adv_type;
  109. $vbm_adv_type_form = '<select name=\'' . $formname . '\' id=\'' . $formname . '\' onchange="if(this.options[this.selectedIndex].value) {this.form.submit()}" style="vertical-align: middle">';
  110. $vbm_adv_type_form .= '<option value=\'\' selected>请选择广告类型</option>
  111. ';
  112. foreach ($vbm_adv_type as $k => $v) {
  113. if ($k == $type && $k != '') {
  114. $vbm_adv_type_form .= '<option value=\'' . $k . '\' selected style=\'background-color:#6EB00C;color:white\'>' . $v['name'] . '</option>
  115. ';
  116. }
  117. else {
  118. $vbm_adv_type_form .= '<option value=\'' . $k . '\'>' . $v['name'] . '</option>
  119. ';
  120. }
  121. }
  122. $vbm_adv_type_form .= '</select>
  123. ';
  124. return $vbm_adv_type_form;
  125. }
  126. function get_infoad_target($selected)
  127. {
  128. $category_cache = get_categories_tree('', 'category');
  129. $option .= '<option value=\'all\' ';
  130. $option .= $selected[0] == 'all' ? ' selected ' : '';
  131. $option .= '>全部</option>';
  132. foreach ($category_cache as $k => $v) {
  133. $option .= '<optgroup label=\'' . $v['catname'] . '\'>';
  134. if ($v[children]) {
  135. foreach ($v[children] as $child) {
  136. $option .= '<option value=' . $child['catid'];
  137. $option .= is_array($selected) && in_array($child[catid], $selected) ? ' selected' : '';
  138. $option .= '>' . $child['catname'] . '</option>';
  139. }
  140. }
  141. $option .= '</optgroup>';
  142. }
  143. return $option;
  144. }
  145. define('CURSCRIPT', 'advertisement');
  146. require_once dirname(__FILE__) . '/global.php';
  147. require_once MYMPS_INC . '/db.class.php';
  148. require_once dirname(__FILE__) . '/include/adv.inc.php';
  149. $part = $part ? $part : 'list';
  150. (!defined('IN_ADMIN') || !defined('IN_MYMPS')) && exit('Access Denied');
  151. if (!submit_check(CURSCRIPT . '_submit')) {
  152. chk_admin_purview('purview_管理广告位');
  153. if ($part == 'intro') {
  154. $here = '广告位详细介绍';
  155. }
  156. else if ($part == 'add') {
  157. $here = '增加广告';
  158. }
  159. else if ($part == 'edit') {
  160. $here = '广告修改';
  161. !($edit = $db->getRow('SELECT * FROM `' . $db_mymps . 'advertisement` WHERE advid = ' . $advid)) && write_msg('当前广告不存在!');
  162. $edit['targets'] = explode(' ', $edit['targets']);
  163. $adv_style = $charset == 'utf-8' ? utf8_unserialize($edit[parameters]) : unserialize($edit[parameters]);
  164. }
  165. else {
  166. $here = '广告管理';
  167. $where = $type ? ' WHERE type = \'' . $type . '\'' : '';
  168. $rows_num = mymps_count(CURSCRIPT, $where);
  169. $param = setParam(array('part', 'type'));
  170. $adv = array();
  171. $adv = page1('SELECT * FROM `' . $db_mymps . 'advertisement` ' . $where . ' ORDER BY displayorder ASC');
  172. }
  173. include $part == 'add' || $part == 'edit' ? mymps_tpl(CURSCRIPT) : mymps_tpl(CURSCRIPT . '_' . $part);
  174. }
  175. else {
  176. if ($part == 'list') {
  177. if (is_array($titlenew)) {
  178. foreach ($titlenew as $key => $value) {
  179. $db->query('UPDATE `' . $db_mymps . 'advertisement` SET title = \'' . $value . '\',displayorder=\'' . $displayorder[$key] . '\',available=\'' . $available[$key] . '\' WHERE advid = \'' . $key . '\'');
  180. }
  181. }
  182. if (is_array($delids)) {
  183. foreach ($delids as $kids => $vids) {
  184. mymps_delete('advertisement', 'WHERE advid = ' . $vids);
  185. }
  186. }
  187. }
  188. else {
  189. $advnew['starttime'] = $advnew['starttime'] ? strtotime($advnew['starttime']) : 0;
  190. $advnew['endtime'] = $advnew['endtime'] ? strtotime($advnew['endtime']) : 0;
  191. if (!$advnew['title']) {
  192. write_msg('广告标题不能为空!');
  193. }
  194. else if (50 < strlen($advnew['title'])) {
  195. write_msg('广告标题太长了,请少于25个字符!');
  196. }
  197. else {
  198. if ($advnew['endtime'] && ($advnew['endtime'] <= time() || $advnew['endtime'] <= $advnew['starttime'])) {
  199. write_msg('截止时间不能小于当前时间或起始时间');
  200. }
  201. else {
  202. if ($advnew['style'] == 'code' && !$advnew['code']['html'] || $advnew['style'] == 'text' && (!$advnew['text']['title'] || !$advnew['text']['link']) || $advnew['style'] == 'image' && (!$advnew['image']['url'] || !$advnew['image']['link']) || $advnew['style'] == 'flash' && (!$advnew['flash']['url'] || !$advnew['flash']['width'] || !$advnew['flash']['height'])) {
  203. write_msg('广告参数提交非法!');
  204. }
  205. }
  206. }
  207. if ($part == 'advadd') {
  208. $db->query('INSERT INTO ' . $db_mymps . 'advertisement (available, type)
  209. VALUES (\'1\', \'' . $type . '\')');
  210. $advid = $db->insert_id();
  211. }
  212. else {
  213. $type = $db->getOne('SELECT type FROM ' . $db_mymps . 'advertisement WHERE advid=\'' . $advid . '\'');
  214. }
  215. foreach ($advnew[$advnew['style']] as $key => $val) {
  216. $advnew[$advnew['style']][$key] = stripslashes($val);
  217. }
  218. $targetsarray = array();
  219. if (is_array($advnew['targets'])) {
  220. foreach ($advnew['targets'] as $target) {
  221. if (in_array($target, array('index', 'all')) || preg_match('/^\\d+$/', $target)) {
  222. $targetsarray[] = $target;
  223. }
  224. }
  225. }
  226. $advnew['targets'] = implode(' ', $targetsarray);
  227. $advnew['displayorder'] = isset($advnew['displayorder']) ? implode(' ', $advnew['displayorder']) : '';
  228. switch ($advnew['style']) {
  229. case 'code':
  230. $advnew['code'] = $advnew['code']['html'];
  231. $advnew['code'] = str_replace('";', '" ;', $advnew['code']);
  232. break;
  233. case 'text':
  234. $advnew['code'] = '<a href="' . $advnew['text']['link'] . '" target="_blank" ' . ($advnew['text']['size'] ? 'style="font-size: ' . $advnew['text']['size'] . '"' : '') . '>' . $advnew['text']['title'] . '</a>';
  235. break;
  236. case 'image':
  237. $advnew['code'] = '<a href="' . $advnew['image']['link'] . '" target="_blank"><img src="' . $advnew['image']['url'] . '"' . ($advnew['image']['height'] ? ' height="' . $advnew['image']['height'] . '"' : '') . ($advnew['image']['width'] ? ' width="' . $advnew['image']['width'] . '"' : '') . ($advnew['image']['alt'] ? ' alt="' . $advnew['image']['alt'] . '"' : '') . ' border="0"></a>';
  238. break;
  239. case 'flash':
  240. $advnew['code'] = '<embed width="' . $advnew['flash']['width'] . '" height="' . $advnew['flash']['height'] . '" src="' . $advnew['flash']['url'] . '" type="application/x-shockwave-flash"></embed>';
  241. break;
  242. }
  243. if ($type == 'floatad') {
  244. $sourcecode = $advnew['code'];
  245. $advnew['floath'] = 40 <= $advnew['floath'] && $advnew['floath'] <= 600 ? intval($advnew['floath']) : 200;
  246. $advnew['code'] = str_replace(array('
  247. ', '
  248. ', '
  249. '), '<br />', $advnew['code']);
  250. $advnew['code'] = addslashes($advnew['code'] . '<br /><span style="text-align:left; display:block; width:30px"><a href="javascript:void();" onMouseOver="this.style.cursor=\'pointer\'" onClick="closeBanner();">关闭</a></span>');
  251. $advnew['code'] = 'theFloaters.addItem(\'floatAdv1\',6,\'document.documentElement.clientHeight-' . $advnew['floath'] . '\',\'<div style="position: absolute; right: 6px; top: 25px;">' . $advnew['code'] . '</div>\');';
  252. }
  253. else if ($type == 'couplead') {
  254. $advnew['code'] = addslashes($advnew['code'] . '<br /><span style="text-align:left; display:block; width:30px"><a href="javascript:void();" onMouseOver="this.style.cursor=\'pointer\'" onClick="closeBanner();">关闭</a></span>');
  255. $advnew['code'] = 'theFloaters.addItem(\'coupleAdL\',6,0,\'<div style="position: absolute; left: 6px; top: 42px;">' . $advnew['code'] . '</div>\');theFloaters.addItem(\'coupleAdR\',\'document.body.clientWidth-6\',0,\'<div style="position: absolute; right: 6px; top: 42px;">' . $advnew['code'] . '</div>\');';
  256. }
  257. else if ($type == 'intercat') {
  258. $advnew['position'] = is_array($advnew['position']) && !in_array('0', $advnew['position']) ? $advnew['position'] : '';
  259. }
  260. if ($advnew['style'] == 'code') {
  261. $advnew['parameters'] = addslashes(serialize(array_merge(array('style' => $advnew['style']), array('html' => $advnew['code']), array('position' => $advnew['position']), array('displayorder' => $advnew['displayorder']), $sourcecode ? array('sourcecode' => $sourcecode) : array(), $advnew['floath'] ? array('floath' => $advnew['floath']) : array())));
  262. }
  263. else {
  264. $advnew['parameters'] = addslashes(serialize(array_merge(array('style' => $advnew['style']), $advnew[$advnew['style']], array('html' => $advnew['code']), array('position' => $advnew['position']), array('displayorder' => $advnew['displayorder']), $advnew['floath'] ? array('floath' => $advnew['floath']) : array())));
  265. }
  266. $advnew['code'] = addslashes($advnew['code']);
  267. $query = $db->query('UPDATE ' . $db_mymps . 'advertisement SET title=\'' . $advnew['title'] . '\', targets=\'' . $advnew['targets'] . '\', parameters=\'' . $advnew['parameters'] . '\', code=\'' . $advnew['code'] . '\', starttime=\'' . $advnew['starttime'] . '\', endtime=\'' . $advnew['endtime'] . '\' WHERE advid=\'' . $advid . '\'');
  268. }
  269. clear_cache_files('adv_index');
  270. clear_cache_files('adv_category');
  271. clear_cache_files('adv_info');
  272. clear_cache_files('adv_other');
  273. updateadvertisement();
  274. write_msg('成功更新广告设置!', $forward_url ? $forward_url : 'adv.php', 'write_record');
  275. }
  276. is_object($db) && $db->Close();
  277. $db = $mymps_global = $part = $action = $here = $part = $adv = NULL;
  278. ?>