public function prepareParams($params) { $htmlKeys = $this->getHtmlOptionsList(); $htmlOpts = array(); foreach ($htmlKeys as $k) { $htmlOpts[$k] = isset($params[$k]) ? $params[$k] : null; } $mapOptKeys = $this->getParamsList(); $mapOpts = array(); foreach ($mapOptKeys as $k) { $mapOpts[$k] = isset($params[$k]) ? $params[$k] : null; } $insert = array('title' => trim($params['title']), 'description' => $params['description'], 'html_options' => utilsGmp::serialize($htmlOpts), 'params' => utilsGmp::serialize($mapOpts), 'create_date' => date('Y-m-d H:i:s')); return $insert; }
public function save($marker = array(), &$update = false) { $id = isset($marker['id']) ? (int) $marker['id'] : 0; $marker['title'] = isset($marker['title']) ? trim($marker['title']) : ''; $marker['coord_x'] = isset($marker['coord_x']) ? (double) $marker['coord_x'] : 0; $marker['coord_y'] = isset($marker['coord_y']) ? (double) $marker['coord_y'] : 0; $update = (bool) $id; if (!empty($marker['title'])) { if (!isset($marker['marker_group_id'])) { $marker['marker_group_id'] = 0; } if (!isset($marker['icon']) || !frameGmp::_()->getModule('icons')->getModel()->iconExists($marker['icon'])) { $marker['icon'] = 1; } $marker['map_id'] = isset($marker['map_id']) ? (int) $marker['map_id'] : 0; if (!$update) { $marker['create_date'] = date('Y-m-d H:i:s'); if ($marker['map_id']) { $maxSortOrder = (int) dbGmp::get('SELECT MAX(sort_order) FROM @__markers WHERE map_id = "' . $marker['map_id'] . '"', 'one'); $marker['sort_order'] = ++$maxSortOrder; } } $marker['params'] = isset($marker['params']) ? utilsGmp::serialize($marker['params']) : ''; if ($update) { dispatcherGmp::doAction('beforeMarkerUpdate', $id, $marker); $dbRes = frameGmp::_()->getTable('marker')->update($marker, array('id' => $id)); dispatcherGmp::doAction('afterMarkerUpdate', $id, $marker); } else { dispatcherGmp::doAction('beforeMarkerInsert', $marker); $dbRes = frameGmp::_()->getTable('marker')->insert($marker); dispatcherGmp::doAction('afterMarkerInsert', $dbRes, $marker); } if ($dbRes) { if (!$update) { $id = $dbRes; } return $id; } else { $this->pushError(frameGmp::_()->getTable('marker')->getErrors()); } } else { $this->pushError(__('Please enter marker name'), 'marker_opts[title]', GMP_LANG_CODE); } return false; }
public static function init() { global $wpdb; $wpPrefix = $wpdb->prefix; /* add to 0.0.3 Versiom */ require_once ABSPATH . 'wp-admin/includes/upgrade.php'; $current_version = get_option($wpPrefix . GMP_DB_PREF . 'db_version', 0); $installed = (int) get_option($wpPrefix . GMP_DB_PREF . 'db_installed', 0); /** * modules */ if (!dbGmp::exist($wpPrefix . GMP_DB_PREF . "modules")) { dbDelta("CREATE TABLE IF NOT EXISTS `" . $wpPrefix . GMP_DB_PREF . "modules` (\r\n\t\t\t `id` int(11) NOT NULL AUTO_INCREMENT,\r\n\t\t\t `code` varchar(64) NOT NULL,\r\n\t\t\t `active` tinyint(1) NOT NULL DEFAULT '0',\r\n\t\t\t `type_id` smallint(3) NOT NULL DEFAULT '0',\r\n\t\t\t `params` text,\r\n\t\t\t `has_tab` tinyint(1) NOT NULL DEFAULT '0',\r\n\t\t\t `label` varchar(128) DEFAULT NULL,\r\n\t\t\t `description` text,\r\n\t\t\t `ex_plug_dir` varchar(255) DEFAULT NULL,\r\n\t\t\t PRIMARY KEY (`id`),\r\n\t\t\t UNIQUE INDEX `code` (`code`)\r\n\t\t\t) DEFAULT CHARSET=utf8;"); dbGmp::query("INSERT INTO `" . $wpPrefix . GMP_DB_PREF . "modules` (id, code, active, type_id, params, has_tab, label, description) VALUES\r\n\t\t\t\t(NULL, 'adminmenu',1,1,'',0,'Admin Menu',''),\r\n\t\t\t\t(NULL, 'options',1,1,'',1,'Options',''),\r\n\t\t\t\t(NULL, 'user',1,1,'',1,'Users',''),\r\n\t\t\t\t(NULL, 'templates',1,1,'',1,'Templates for Plugin',''),\r\n\r\n\t\t\t\t(NULL, 'shortcodes', 1, 6, '', 0, 'Shortcodes', 'Shortcodes data'),\r\n\t\t\t\t(NULL, 'gmap', 1, 1, '',1, 'Gmap', 'Gmap'),\r\n\t\t\t\t(NULL, 'marker', 1, 1, '', 0, 'Markers', 'Google Maps Markers'),\r\n\t\t\t\t(NULL, 'marker_groups', 1, 1, '', 0, 'Marker Gropus', 'Marker Groups'), \r\n\t\t\t\t(NULL, 'supsystic_promo', 1, 1, '', 0, 'Promo', 'Promo'),\r\n\t\t\t\t(NULL, 'icons', 1, 1, '', 1, 'Marker Icons', 'Marker Icons'),\r\n\t\t\t\t(NULL, 'mail', 1, 1, '', 1, 'mail', 'mail');"); } if (dbGmp::exist('@__modules', 'code', 'promo')) { dbGmp::query('UPDATE @__modules SET code = "supsystic_promo" WHERE code = "promo"'); } if (!dbGmp::exist('@__modules', 'code', 'mail')) { dbGmp::query("INSERT INTO `" . $wpPrefix . GMP_DB_PREF . "modules` (id, code, active, type_id, params, has_tab, label, description) VALUES\r\n\t\t\t\t(NULL, 'mail', 1, 1, '', 1, 'mail', 'mail');"); } if (!dbGmp::exist('@__modules', 'code', 'supsystic_promo')) { dbGmp::query("INSERT INTO `@__modules` (id, code, active, type_id, params, has_tab, label, description) VALUES\r\n\t\t\t\t(NULL, 'supsystic_promo', 1, 1, '', 1, 'supsystic_promo', 'supsystic_promo');"); } /** * modules_type */ if (!dbGmp::exist($wpPrefix . GMP_DB_PREF . "modules_type")) { dbDelta("CREATE TABLE IF NOT EXISTS `" . $wpPrefix . GMP_DB_PREF . "modules_type` (\r\n\t\t\t `id` int(11) NOT NULL AUTO_INCREMENT,\r\n\t\t\t `label` varchar(64) NOT NULL,\r\n\t\t\t PRIMARY KEY (`id`)\r\n\t\t\t) AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;"); dbGmp::query("INSERT INTO `" . $wpPrefix . GMP_DB_PREF . "modules_type` VALUES\r\n\t\t\t (1,'system'),\r\n\t\t\t (4,'widget'),\r\n\t\t\t (6,'addons'),\r\n\t\t\t (7,'template')"); } /** * options */ if (!dbGmp::exist($wpPrefix . GMP_DB_PREF . "options")) { dbDelta("CREATE TABLE IF NOT EXISTS `" . $wpPrefix . GMP_DB_PREF . "options` (\r\n\t\t\t `id` int(11) NOT NULL AUTO_INCREMENT,\r\n\t\t\t `code` varchar(64) CHARACTER SET latin1 NOT NULL,\r\n\t\t\t `value` text NULL,\r\n\t\t\t `label` varchar(128) CHARACTER SET latin1 DEFAULT NULL,\r\n\t\t\t `description` text CHARACTER SET latin1,\r\n\t\t\t `htmltype_id` smallint(2) NOT NULL DEFAULT '1',\r\n\t\t\t `params` text NULL,\r\n\t\t\t `cat_id` mediumint(3) DEFAULT '0',\r\n\t\t\t `sort_order` mediumint(3) DEFAULT '0',\r\n\t\t\t `value_type` varchar(16) CHARACTER SET latin1 DEFAULT NULL,\r\n\t\t\t PRIMARY KEY (`id`),\r\n\t\t\t KEY `id` (`id`),\r\n\t\t\t UNIQUE INDEX `code` (`code`)\r\n\t\t\t) DEFAULT CHARSET=utf8"); dbGmp::query("insert into `" . $wpPrefix . GMP_DB_PREF . "options` ( `code` , `value` , `label` ) \r\n\t\t\t\t\tVALUES ( 'save_statistic', '0', 'Send statistic')"); dbGmp::query("insert into `@__options` (`code`,`value`,`label`) VALUES\r\n\t\t\t('infowindow_size','" . utilsGmp::serialize(array('width' => '100', 'height' => '100')) . "','Info Window Size')"); } /* options categories */ if (!dbGmp::exist($wpPrefix . GMP_DB_PREF . "options_categories")) { dbDelta("CREATE TABLE IF NOT EXISTS `" . $wpPrefix . GMP_DB_PREF . "options_categories` (\r\n\t\t\t `id` int(11) NOT NULL AUTO_INCREMENT,\r\n\t\t\t `label` varchar(128) NOT NULL,\r\n\t\t\t PRIMARY KEY (`id`),\r\n\t\t\t KEY `id` (`id`)\r\n\t\t\t) DEFAULT CHARSET=utf8"); dbGmp::query("INSERT INTO `" . $wpPrefix . GMP_DB_PREF . "options_categories` VALUES\r\n\t\t\t\t(1, 'General'),\r\n\t\t\t\t(2, 'Template'),\r\n\t\t\t\t(3, 'Subscribe'),\r\n\t\t\t\t(4, 'Social');"); } /* * Create table for map */ if (!dbGmp::exist($wpPrefix . GMP_DB_PREF . "maps")) { dbDelta("CREATE TABLE IF NOT EXISTS `" . $wpPrefix . GMP_DB_PREF . "maps` (\r\n\t\t\t\t`id` int(11) NOT NULL AUTO_INCREMENT,\r\n\t\t\t\t`title` varchar(125) CHARACTER SET utf8 NOT NULL,\r\n\t\t\t\t`description` text CHARACTER SET utf8 NULL,\r\n\t\t\t\t`params` text NULL,\r\n\t\t\t\t`html_options` text NOT NULL,\r\n\t\t\t\t`create_date` datetime,\r\n\t\t\t\tPRIMARY KEY (`id`),\r\n\t\t\t\tUNIQUE INDEX `id` (`id`)\r\n\t\t\t ) DEFAULT CHARSET=utf8"); } /** * Create table for markers */ if (!dbGmp::exist($wpPrefix . GMP_DB_PREF . "markers")) { dbDelta("CREATE TABLE IF NOT EXISTS `" . $wpPrefix . GMP_DB_PREF . "markers" . "` (\r\n\t\t\t\t\t`id` int(11) NOT NULL AUTO_INCREMENT,\r\n\t\t\t\t\t`title` varchar(125) CHARACTER SET utf8 NOT NULL,\r\n\t\t\t\t\t`description` text CHARACTER SET utf8 NULL,\r\n\t\t\t\t\t`coord_x` varchar(30) CHARACTER SET utf8 NOT NULL,\r\n\t\t\t\t\t`coord_y` varchar(30) CHARACTER SET utf8 NOT NULL,\r\n\t\t\t\t\t`icon` int(11),\r\n\t\t\t\t\t`map_id` int(11),\r\n\t\t\t\t\t`marker_group_id` int(11),\r\n\t\t\t\t\t`address` text CHARACTER SET utf8,\r\n\t\t\t\t\t`animation` int(1),\r\n\t\t\t\t\t`create_date` datetime,\r\n\t\t\t\t\t`params` text CHARACTER SET utf8 NOT NULL,\r\n\t\t\t\t\t`sort_order` tinyint(1) NOT NULL DEFAULT '0',\r\n\t\t\t\t\tPRIMARY KEY (`id`)\r\n\t\t\t\t) DEFAULT CHARSET=utf8"); } if (!dbGmp::exist($wpPrefix . GMP_DB_PREF . "markers", 'sort_order')) { dbGmp::query("ALTER TABLE `@__markers` ADD COLUMN `sort_order` tinyint(1) NOT NULL DEFAULT '0';"); } /** * Create table for marker Icons */ if (!dbGmp::exist($wpPrefix . GMP_DB_PREF . "icons")) { dbDelta("CREATE TABLE IF NOT EXISTS `" . $wpPrefix . GMP_DB_PREF . "icons" . "` (\r\n\t\t\t\t`id` int(11) NOT NULL AUTO_INCREMENT,\r\n\t\t\t\t`title` varchar(100) CHARACTER SET utf8, \r\n\t\t\t\t`description` text CHARACTER SET utf8, \r\n\t\t\t\t`path` varchar(250) CHARACTER SET utf8, \r\n\t\t\t\t PRIMARY KEY (`id`)\r\n\t\t\t) DEFAULT CHARSET=utf8"); } /** * Create table for marker groups */ if (!dbGmp::exist($wpPrefix . GMP_DB_PREF . "marker_groups")) { dbDelta("CREATE TABLE IF NOT EXISTS `" . $wpPrefix . GMP_DB_PREF . "marker_groups" . "` (\r\n\t\t\t\t\t`id` int(11) NOT NULL AUTO_INCREMENT,\r\n\t\t\t\t\t`title` varchar(250) CHARACTER SET utf8,\r\n\t\t\t\t\t`description` text CHARACTER SET utf8,\r\n\t\t\t\t PRIMARY KEY (`id`)\r\n\t\t\t\t ) DEFAULT CHARSET=utf8"); } $markerGroupsClearedInvalid = get_option($wpPrefix . GMP_DB_PREF . 'mg_cleared_inv', 0); if (!$markerGroupsClearedInvalid) { dbGmp::query('UPDATE @__markers SET marker_group_id = 0 WHERE marker_group_id = 1'); // This was wrong update in markers table before - fix this one time before update plugin update_option($wpPrefix . GMP_DB_PREF . 'mg_cleared_inv', 1); } /** * Plugin usage statistics */ if (!dbGmp::exist($wpPrefix . GMP_DB_PREF . "usage_stat")) { dbDelta("CREATE TABLE `" . $wpPrefix . GMP_DB_PREF . "usage_stat` (\r\n\t\t\t `id` int(11) NOT NULL AUTO_INCREMENT,\r\n\t\t\t `code` varchar(64) NOT NULL,\r\n\t\t\t `visits` int(11) NOT NULL DEFAULT '0',\r\n\t\t\t `spent_time` int(11) NOT NULL DEFAULT '0',\r\n\t\t\t `modify_timestamp` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,\r\n\t\t\t UNIQUE INDEX `code` (`code`),\r\n\t\t\t PRIMARY KEY (`id`)\r\n\t\t\t) DEFAULT CHARSET=utf8"); dbGmp::query("INSERT INTO `" . $wpPrefix . GMP_DB_PREF . "usage_stat` (code, visits) VALUES ('installed', 1)"); } update_option($wpPrefix . GMP_DB_PREF . 'db_version', GMP_VERSION_PLUGIN); add_option($wpPrefix . GMP_DB_PREF . 'db_installed', 1); installerDbUpdaterGmp::runUpdate(); }
public function updateMarker($marker) { $insert = array('marker_group_id' => $marker['goup_id'], 'title' => $marker['title'], 'address' => $marker['address'], 'description' => $marker['desc'], 'coord_x' => $marker['position']['coord_x'], 'coord_y' => $marker['position']['coord_y'], 'animation' => $marker['animation'], 'icon' => $marker['icon']['id'], 'params' => utilsGmp::serialize(array('titleLink' => $marker['titleLink']))); return self::$tableObj->update($insert, " `id`='" . $marker['id'] . "'"); }
public function updateInfoWindowSize($sizeParams) { return frameGmp::_()->getTable('options')->update(array('value' => utilsGmp::serialize($sizeParams)), "`code`='infowindow_size'"); }
public static function update_05() { dbGmp::query("ALTER TABLE `@__markers` ADD column `params` text;"); dbGmp::query("insert into `@__options` (`code`,`value`,`label`) VALUES('save_statistic','0','Save Statistic')"); dbGmp::query("insert into `@__options` (`code`,`value`,`label`) VALUES\n\t\t\t('infowindow_size','" . utilsGmp::serialize(array('width' => '100', 'height' => '100')) . "','Info Window Size')"); }
public function importData() { $res = new responseGmp(); if (!isset($_FILES['BackupFileCsv'])) { $res->addError(langGmp::_("Cannot Upload File")); return $res->ajaxExec(); } $fileData = $_FILES['BackupFileCsv']; $uplDir = wp_upload_dir(); $filePath = $uplDir['path']; $source = $fileData['tmp_name']; $dest = $filePath . DS . $fileData['name']; if (!copy($source, $dest)) { $res->addError(langRpw::_("Cannot Copy File")); return $res->ajaxExec(); } $backupInfoCsv = file_get_contents($dest); $backupInfo = utilsGmp::unserialize($backupInfoCsv); if (empty($backupInfo)) { $res->addError(langRpw::_("Wrong Format")); return $res->ajaxExec(); } $mapsKeys = array(); $mapModel = frameGmp::_()->getModule("gmap")->getModel(); $groupModule = frameGmp::_()->getModule("marker_groups"); $markerModule = FrameGmp::_()->getModule("marker"); $group_params = array(); $groupKeys = array(); $markersArr = array(); foreach ($backupInfo as $map) { $map_params = array("title" => $map["title"], "description" => $map["description"], "params" => utilsGmp::serialize($map["params"]), "html_options" => utilsGmp::serialize($map["html_options"]), "create_date" => $map["create_date"]); //outeGmp($map_params); $map_new_id = frameGmp::_()->getTable("maps")->store($map_params); $mapsKeys[$map['id']] = $map_new_id; foreach ($map['markers'] as $marker) { if (isset($marker['groupObj']) && !empty($marker['groupObj'])) { $group_params[$marker['groupObj']['id']] = $marker['groupObj']; } $markersArr[] = $marker; } } foreach ($group_params as $oldId => $groupInfo) { $gParams = array("title" => $groupInfo['title'], "description" => $groupInfo['description'], "mode" => "insert"); $groupKeys[$oldId] = $groupModule->getModel()->saveGroup($gParams); } foreach ($markersArr as $marker) { $mParams = array("title" => $marker['title'], "description" => $marker['description'], "coord_x" => $marker['coord_x'], "coord_y" => $marker['coord_y'], "map_id" => $mapsKeys[$marker['map_id']], "marker_group_id" => $groupKeys[$marker['marker_group_id']], "address" => $marker['address'], "animation" => (int) $marker['animation'], "create_date" => $marker['create_date'], "params" => $marker['params'], "titleLink" => utilsGmp::serialize($marker['titleLink'])); if (is_array($marker['icon'])) { $mParams['icon'] = $marker['icon']['id']; } elseif (is_string($marker['icon'])) { $mParams['icon'] = $marker['icon']; } $markerModule->getModel()->saveMarker($mParams); } outGmp($mapsKeys); outeGmp($groupKeys); }