1: <?php
2: /*
3: You may not change or alter any portion of this comment or credits
4: of supporting developers from this source code or any supporting source code
5: which is considered copyrighted (c) material of the original comment or credit authors.
6:
7: This program is distributed in the hope that it will be useful,
8: but WITHOUT ANY WARRANTY; without even the implied warranty of
9: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: */
11:
12: /**
13: * banners module
14: *
15: * @copyright XOOPS Project (http://xoops.org)
16: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
17: * @package banners
18: * @since 2.6.0
19: * @author Mage Gregory (AKA Mage)
20: * @version $Id: $
21: */
22:
23: /**
24: * banner module install suplement
25: *
26: * @param XoopsModule &$module module being installed
27: *
28: * @return boolean true if no error
29: */
30: function xoops_module_install_banners(&$module)
31: {
32: $xoops = Xoops::getInstance();
33: //$xoops->db();
34: //global $xoopsDB;
35: XoopsLoad::addMap(array('banners' => dirname(__DIR__) . '/class/helper.php'));
36: $helper = Banners::getInstance();
37: // Get handler
38: $banner_Handler = $helper->getHandlerBanner();
39: $client_Handler = $helper->getHandlerBannerclient();
40: // update client
41: /*$sql = "SHOW COLUMNS FROM " . $xoopsDB->prefix("bannerclient");
42: $result = $xoopsDB->queryF($sql);
43: if (($rows = $xoopsDB->getRowsNum($result)) == 7) {
44: $sql = "SELECT * FROM " . $xoopsDB->prefix("bannerclient");
45: $result = $xoopsDB->query($sql);
46: while ($myrow = $xoopsDB->fetchArray($result)) {
47: $extrainfo = $myrow['contact'] . ' - ' . $myrow['email'] . ' - ' . $myrow['login'] . ' - ' . $myrow['passwd'] . ' - ' . $myrow['extrainfo'];
48: $sql = "UPDATE `" . $xoopsDB->prefix("bannerclient") . "` SET `extrainfo` = '" . $extrainfo . "' WHERE `cid` = " . $myrow['cid'];
49: $xoopsDB->queryF($sql);
50: }
51: $sql = "ALTER TABLE " . $xoopsDB->prefix("bannerclient") . " DROP contact, DROP email, DROP login, DROP passwd";
52: $xoopsDB->queryF($sql);
53: $sql = "ALTER TABLE " . $xoopDB->prefix("bannerclient") . " ADD `uid` MEDIUMINT( 8 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `cid`";
54: $xoopsDB->queryF($sql);
55: }*/
56: // update banner
57: /*$sql = "SHOW COLUMNS FROM " . $xoopsDB->prefix("banner");
58: $result = $xoopsDB->queryF($sql);
59: if (($rows = $xoopsDB->getRowsNum($result)) == 10) {
60: $sql = "ALTER TABLE " . $xoopsDB->prefix("banner") . " CHANGE `date` `datestart` INT( 10 ) NOT NULL DEFAULT '0'";
61: $xoopsDB->queryF($sql);
62: $sql = "ALTER TABLE " . $xoopsDB->prefix("banner") . " ADD `dateend` INT( 10 ) NOT NULL DEFAULT '0' AFTER `datestart`";
63: $xoopsDB->queryF($sql);
64: $sql = "ALTER TABLE " . $xoopsDB->prefix("banner") . " ADD `status` TINYINT( 1 ) NOT NULL DEFAULT '1' AFTER `htmlcode`";
65: $xoopsDB->queryF($sql);
66: }*/
67: // update bannerfinish
68: /*$sql = "SHOW COLUMNS FROM " . $xoopsDB->prefix("bannerfinish");
69: $result = $xoopsDB->queryF($sql);
70: if (($rows = $xoopsDB->getRowsNum($result)) == 6) {
71: $sql = "SELECT * FROM " . $xoopsDB->prefix("bannerfinish");
72: $result = $xoopsDB->query($sql);
73: while ($myrow = $xoopsDB->fetchArray($result)) {
74: $sql = "INSERT INTO `" . $xoopsDB->prefix("banner") . "` (`cid`, `imptotal`, `impmade`, `clicks`, `imageurl`, `clickurl`, `datestart`, `dateend`, `htmlbanner`, `htmlcode`, `status`) VALUES (" . $myrow['cid'] . ", 0, " . $myrow['impressions'] . ", " . $myrow['clicks'] . ", 0, '', " . $myrow['datestart'] . ", " . $myrow['dateend'] . ", 0, '', 0)";
75: $xoopsDB->queryF($sql);
76: }
77: }*/
78:
79: /* this should be in system upgrade, not module install
80: TODO: Add to upgrade script and remove from here
81: // delete banners and my_ip
82: $sql = "DELETE FROM " . $xoopsDB->prefix("config") . " WHERE `conf_name` = 'banners'";
83: $xoopsDB->queryF($sql);
84: $sql = "DELETE FROM " . $xoopsDB->prefix("config") . " WHERE `conf_name` = 'my_ip'";
85: $xoopsDB->queryF($sql);
86: */
87: $xoops_root_path = \XoopsBaseConfig::get('root-path');
88: $xoops_upload_url = \XoopsBaseConfig::get('uploads-url');
89:
90: // create folder "banners"
91: $dir = $xoops_root_path . "/uploads/banners";
92: if (!is_dir($dir)) {
93: mkdir($dir, 0777);
94: chmod($dir, 0777);
95: }
96: //Copy index.html
97: $file = $xoops_root_path . "/uploads/banners/index.html";
98: if (!is_file($file)) {
99: copy($xoops_root_path . "/modules/banners/images/index.html", $file);
100: }
101: //Copy blank.gif
102: $file = $xoops_root_path . "/uploads/banners/blank.gif";
103: if (!is_file($file)) {
104: copy($xoops_root_path . "/uploads/blank.gif", $file);
105: }
106: //Copy .htaccess
107: $file = $xoops_root_path . "/uploads/banners/.htaccess";
108: if (!is_file($file)) {
109: copy($xoops_root_path . "/uploads/.htaccess", $file);
110: }
111:
112: /* this should be in system upgrade, not module install
113: TODO: Add to upgrade script and remove from here
114: // Copy banner to banners_banner
115: $dbManager = new XoopsDatabaseManager();
116: $map = array(
117: 'bid' => 'banner_bid',
118: 'cid' => 'banner_cid',
119: 'imptotal' => 'banner_imptotal',
120: 'impmade' => 'banner_impmade',
121: 'clicks' => 'banner_clicks',
122: 'imageurl' => 'banner_imageurl',
123: 'clickurl' => 'banner_clickurl',
124: 'date' => 'banner_datestart',
125: 'htmlbanner' => 'banner_htmlbanner',
126: 'htmlcode' => 'banner_htmlcode',
127: );
128: $dbManager->copyFields($map, 'banner', 'banners_banner', false);
129:
130: // Copy bannerclient to banners_bannerclient
131: $dbManager = new XoopsDatabaseManager();
132: $map = array(
133: 'cid' => 'bannerclient_cid',
134: 'name' => 'bannerclient_name',
135: 'extrainfo' => 'bannerclient_extrainfo',
136: );
137: $dbManager->copyFields($map, 'bannerclient', 'banners_bannerclient', false);
138:
139: // Modification of imported banners below xoops 2.6
140: $banner_arr = $banner_Handler->getall();
141: foreach (array_keys($banner_arr) as $i) {
142: $namefile = substr_replace($banner_arr[$i]->getVar('banner_imageurl'),'',0,strlen(\XoopsBaseConfig::get('url') . '/images/banners/'));
143: $pathfile_image = $xoops_root_path . '/images/banners/' . $namefile;
144: $pathfile_upload = $xoops_root_path . '/uploads/banners/' . $namefile;
145: $obj = $banner_Handler->get($banner_arr[$i]->getVar('banner_bid'));
146: if (is_file($pathfile_image)){
147: copy($pathfile_image, $pathfile_upload);
148: unlink($pathfile_image);
149: $obj->setVar("banner_imageurl", \XoopsBaseConfig::get('uploads-url') . '/banners/' . $namefile);
150: }
151: $obj->setVar("banner_status", 1);
152: $banner_Handler->insert($obj);
153: }
154: */
155:
156: // create XOOPS client
157: $client_name = 'XOOPS';
158: $criteria = new CriteriaCompo();
159: $criteria->add(new Criteria('bannerclient_name', $client_name));
160: $criteria->setLimit(1);
161: $client_arr = $client_Handler->getAll($criteria);
162: if (count($client_arr) == 0) {
163: $obj = $client_Handler->create();
164: $obj->setVar("bannerclient_uid", 0);
165: $obj->setVar("bannerclient_name", $client_name);
166: $obj->setVar("bannerclient_extrainfo", 'XOOPS Dev Team');
167: $newclient_id = $client_Handler->insert($obj);
168: } else {
169: foreach (array_keys($client_arr) as $i) {
170: $newclient_id = $client_arr[$i]->getVar("bannerclient_cid");
171: }
172: }
173:
174: // create banner in XOOPS client
175: $banners = array(
176: "xoops_flashbanner2.swf" => "http://www.xoops.org/",
177: "xoops_banner_2.gif" => "http://www.xoops.org/",
178: "banner.swf" => "http://www.xoops.org/"
179: );
180: foreach ($banners as $k => $v) {
181: //Copy banner
182: $file = $xoops_root_path . "/uploads/banners/" . $k;
183: $copy_file = $xoops_root_path . "/modules/banners/images/" . $k;
184: if (!is_file($file) && is_file($copy_file)) {
185: copy($copy_file, $file);
186: }
187: $obj = $banner_Handler->create();
188: $obj->setVar("banner_cid", $newclient_id);
189: $obj->setVar("banner_clickurl", $v);
190: $obj->setVar("banner_imageurl", $xoops_upload_url . '/banners/' . $k);
191: $obj->setVar("banner_datestart", time());
192: $obj->setVar("banner_dateend", 0);
193: $obj->setVar("banner_status", 1);
194: $obj->setVar("banner_imptotal", 0);
195: $obj->setVar("banner_htmlbanner", 0);
196: $obj->setVar("banner_htmlcode", '');
197: $banner_Handler->insert($obj);
198: }
199: return true;
200: }
201: