public static function add_store($opt = array()) { global $db; $opt = array_map('trim', $opt); if (empty($opt['name']) || empty($opt['url'])) { return false; } $stmt = $db->stmt_init(); $stmt->prepare("INSERT INTO " . DB_TABLE_PREFIX . "stores (cjID, user, category, popular, name, link, description, tags, image, visible, meta_title, meta_desc, lastupdate_by, lastupdate, date) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), NOW())"); $logo = isset($_FILES['logo']) ? \site\images::upload($_FILES['logo'], 'logo_', array('path' => DIR . '/', 'max_size' => 1024, 'max_width' => 600, 'max_height' => 400)) : $opt['logo']; if ($logo == '') { $logo = $opt['logo']; } $stmt->bind_param("iiiisssssissi", $opt['cjID'], $opt['user'], $opt['category'], $opt['popular'], $opt['name'], $opt['url'], $opt['description'], $opt['tags'], $logo, $opt['publish'], $opt['meta_title'], $opt['meta_desc'], $GLOBALS['me']->ID); $execute = $stmt->execute(); if ($execute) { $stmt->prepare("SELECT LAST_INSERT_ID() FROM " . DB_TABLE_PREFIX . "stores"); $stmt->execute(); $stmt->bind_result($id); $stmt->fetch(); $stmt->close(); return $id; } $stmt->close(); return false; }
public function install() { $stmt = $this->db->stmt_init(); $stmt->prepare("INSERT INTO " . DB_TABLE_PREFIX . "plugins (user, name, image, scope, main, options, menu, menu_ready, extend_vars, description, version, update_checker, uninstall, date) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW())"); // plugin name, the same with `name` tag from XML file $name = $this->name(); // store the image into the public upload folder $image = \site\images::upload($this->image(), 'plugin_', array('path' => DIR . '/', 'max_size' => 1024, 'max_width' => 600, 'max_height' => 400, 'current' => $this->image())); // all other informations about this plugin list($scope, $main, $options, $menu, $menu_ready, $extend, $description, $version, $update, $uninstall) = array($this->scope(), $this->main_file(), $this->options_file(), $this->menu(), $this->menu_ready(), @serialize($this->extend_vars()), $this->description(), $this->version(), $this->update_checker(), @serialize($this->uninstall())); $stmt->bind_param("isssssiissdss", $GLOBALS['me']->ID, $name, $image, $scope, $main, $options, $menu, $menu_ready, $extend, $description, $version, $update, $uninstall); $execute = $stmt->execute(); $stmt->close(); if (!$execute) { // delete image if it was inserted @unlink(DIR . '/' . $image); throw new Exception($this->lang['msg_error']); } else { /* INSTALLATION COMPLETE */ // delete installation file @unlink($this->directory . 'install.xml'); // insert tables, if plugin has tables if ($tables = $this->db_query()) { foreach ($tables as $table) { $this->db->query($table); } } // insert lines in admin head, if plugins has that $admin_head = $this->add_to_admin_head(); $theme_head = $this->add_to_head(); if ($admin_head || $theme_head) { $stmt = $this->db->stmt_init(); $stmt->prepare("INSERT INTO " . DB_TABLE_PREFIX . "head (text, admin, theme, plugin, date) VALUES (?, ?, ?, ?, NOW())"); $zero = 0; $one = 1; if ($admin_head) { foreach ($admin_head as $line) { $line = trim($line); $stmt->bind_param("siis", $line, $one, $zero, $this->dir); $stmt->execute(); } } if ($theme_head) { foreach ($theme_head as $line) { $line = trim($line); $stmt->bind_param("siis", $line, $zero, $one, $this->dir); $stmt->execute(); } } $stmt->close(); } } }
public static function edit_payment_plan($id, $opt = array()) { global $db; if (!$GLOBALS['me']->is_admin) { return false; } $opt = array_map('trim', $opt); $opt['price'] = \site\utils::make_money_format($opt['price']); if (empty($opt['name']) || $opt['price'] < 0 || $opt['credits'] <= 0) { return false; } $plan = \query\payments::plan_infos($id); $avatar = \site\images::upload(@$_FILES['logo'], 'payment_plan_', array('path' => DIR . '/', 'max_size' => 1024, 'max_width' => 500, 'max_height' => 600, 'current' => $plan->image)); $stmt = $db->stmt_init(); $stmt->prepare("UPDATE " . DB_TABLE_PREFIX . "p_plans SET name = ?, description = ?, price = ?, credits = ?, image = ?, lastupdate_by = ?, lastupdate = NOW(), visible = ? WHERE id = ?"); $stmt->bind_param("ssdisiii", $opt['name'], $opt['description'], $opt['price'], $opt['credits'], $avatar, $GLOBALS['me']->ID, $opt['publish'], $id); $execute = $stmt->execute(); $stmt->close(); if ($execute) { return true; } return false; }
public static function edit_store($id, $user, $post) { global $db, $LANG; $post = array_map('trim', $post); if (!\query\main::have_store($id, $user)) { throw new \Exception($LANG['msg_error']); // this error can appear only when user try to modify post data } else { if (!isset($post['name']) || trim($post['name']) == '') { throw new \Exception($LANG['edit_store_writename']); } else { if (!isset($post['url']) || !preg_match('/(^http(s)?:\\/\\/)([a-zA-Z0-9-]{3,100}).([a-zA-Z]{2,12})/', $post['url'])) { throw new \Exception($LANG['edit_store_wrongweb']); } else { if (!isset($post['description']) || strlen($post['description']) < 10) { throw new \Exception($LANG['edit_store_writedesc']); } else { $store = \query\main::store_infos($id); $logo = \site\images::upload($_FILES['edit_store_form_logo'], 'logo_', array('path' => '', 'max_size' => 400, 'max_width' => 600, 'max_height' => 400, 'current' => $store->image)); $stmt = $db->stmt_init(); $stmt->prepare("UPDATE " . DB_TABLE_PREFIX . "stores SET category = ?, name = ?, link = ?, description = ?, tags = ?, image = ?, lastupdate_by = ?, lastupdate = NOW() WHERE id = ?"); $tags = isset($post['tags']) ? $post['tags'] : ''; $stmt->bind_param("isssssii", $post['category'], $post['name'], $post['url'], $post['description'], $tags, $logo, $user, $id); $execute = $stmt->execute(); $stmt->close(); if ($execute) { return (object) array('image' => $logo); } else { throw new \Exception($LANG['msg_error']); } } } } } }