function store_slide() { global $url_tail, $wp_session, $wpdb; if (!empty($_POST) && check_admin_referer('store_slide', '_alfw_nonce')) { $file = new alfw_manage_files(); $wpdb->show_errors(); $user_data = prepare_data($_POST); $create_slide = false; if (empty($_POST['slide_id'])) { /** * Insert */ if ($wpdb->insert($wpdb->prefix . SLIDES_TABLE, $user_data['data'], $user_data['format'])) { $error_statuses[] = __('Information saved'); } else { $error_statuses[] = __('Information not saved'); } $slide_id = $wpdb->insert_id; $create_slide = true; } else { /** * Update */ if ($wpdb->update($wpdb->prefix . SLIDES_TABLE, $user_data['data'], array('id' => $_POST['slide_id']), $user_data['format'], array('%d'))) { $error_statuses[] = __('Information saved'); } else { $error_statuses[] = __('Information not saved'); } $slide_id = $_POST['slide_id']; } if ($_POST['tmp_picture']) { /** * Get slider options */ $slider_options = $wpdb->get_results($wpdb->prepare("SELECT\n id, deny_resize_img, width, height, thumb_width, thumb_height\n FROM\n `" . $wpdb->prefix . SLIDER_TABLE . "`\n WHERE\n id = %d\n ", $user_data['data']['slider_id']), ARRAY_A); $upload_dir_info = wp_upload_dir(); $upload_dir_info = $upload_dir_info['basedir']; /** * Store original image */ $file->create_folder_recursive(FULL_UPLOAD_PATH_ORIG . "/" . $slider_options[0]['id'], 0755); //$picture_name = $file->modif_file_name(FULL_UPLOAD_PATH_ORIG . "/" . $slider_options[0]['id'] . "/", $_POST['tmp_picture_name']); $picture_name = $file->copy_file($upload_dir_info . "/" . $_POST['tmp_picture'], FULL_UPLOAD_PATH_ORIG . "/" . $slider_options[0]['id'] . "/", $_POST['tmp_picture_name']); /* if (!copy($upload_dir_info . "/" . $_POST['tmp_picture'], FULL_UPLOAD_PATH_ORIG . "/" . $slider_options[0]['id'] . "/" . $_POST['tmp_picture_name'])){ throw new Exception('File can\'t copyed to destination folder!'); } */ /** * Work with thumb */ $thumb_width = $slider_options[0]['thumb_width']; $thumb_height = $slider_options[0]['thumb_height']; /** * Check orientation */ $thumb_check_result = $file->check_orientation($thumb_width, $thumb_height, $upload_dir_info . "/" . $_POST['tmp_picture']); $force_resize_flag = true; /** * Different orientation */ $need_places_thmb = false; if (!$thumb_check_result['check']) { $force_resize_flag = false; $thumb_height = $thumb_check_result['resize_height']; $thumb_width = $thumb_check_result['resize_width']; $need_places_thmb = true; } $file->resize_upload_img($upload_dir_info . "/" . $_POST['tmp_picture'], $picture_name, $thumb_height, $thumb_width, FULL_UPLOAD_PATH_THUMB . "/" . $slider_options[0]['id'] . "/", $force_resize_flag); /** * Centered image on canvas */ if ($need_places_thmb) { $file->center_place_img_to_canvas($slider_options[0]['thumb_width'], $slider_options[0]['thumb_height'], $thumb_check_result['frame_orient'], FULL_UPLOAD_PATH_THUMB . "/" . $slider_options[0]['id'] . "/" . $picture_name); } /** * Work with main picture */ /** * Check orientation */ $check_result = $file->check_orientation($slider_options[0]['width'], $slider_options[0]['height'], $upload_dir_info . "/" . $_POST['tmp_picture']); if ($slider_options[0]['deny_resize_img']) { /** * No resize image */ if ($check_result['check']) { $file->copy_file($upload_dir_info . "/" . $_POST['tmp_picture'], FULL_UPLOAD_PATH . "/" . $slider_options[0]['id'] . "/", $picture_name); } else { /** * however needs correction */ $file->resize_upload_img($upload_dir_info . "/" . $_POST['tmp_picture'], $picture_name, $check_result['resize_height'], $check_result['resize_width'], FULL_UPLOAD_PATH . "/" . $slider_options[0]['id'] . "/", false); $file->center_place_img_to_canvas($slider_options[0]['width'], $slider_options[0]['height'], $check_result['frame_orient'], FULL_UPLOAD_PATH . "/" . $slider_options[0]['id'] . "/" . $picture_name); } } else { /** * Needs resize */ if ($check_result['check']) { $file->resize_upload_img($upload_dir_info . "/" . $_POST['tmp_picture'], $picture_name, $slider_options[0]['height'], $slider_options[0]['width'], FULL_UPLOAD_PATH . "/" . $slider_options[0]['id'] . "/", true); } else { $file->resize_upload_img($upload_dir_info . "/" . $_POST['tmp_picture'], $picture_name, $check_result['resize_height'], $check_result['resize_width'], FULL_UPLOAD_PATH . "/" . $slider_options[0]['id'] . "/", false); $file->center_place_img_to_canvas($slider_options[0]['width'], $slider_options[0]['height'], $check_result['frame_orient'], FULL_UPLOAD_PATH . "/" . $slider_options[0]['id'] . "/" . $picture_name); } } /** * Update picture field */ $wpdb->update($wpdb->prefix . SLIDES_TABLE, array('picture' => $picture_name), array('id' => $slide_id), array('%s'), array('%d')); /** * Delete old picture */ if (!empty($_POST['old_picture']) && $picture_name) { $file->delete_file(FULL_UPLOAD_PATH . "/" . $slider_options[0]['id'] . "/" . $_POST['old_picture']); $file->delete_file(FULL_UPLOAD_PATH_THUMB . "/" . $slider_options[0]['id'] . "/" . $_POST['old_picture']); $file->delete_file(FULL_UPLOAD_PATH_ORIG . "/" . $slider_options[0]['id'] . "/" . $_POST['old_picture']); } /** * Delete tmp picture */ $file->delete_file($upload_dir_info . "/" . $_POST['tmp_picture']); $file->delete_file($upload_dir_info . "/preview_" . $_POST['tmp_picture']); } $wp_session->s_set('errors', $error_statuses); } }
function lookbook_install() { global $wpdb; global $lookbook_settings_fields; $table_name = $wpdb->prefix . SLIDER_TABLE; if ($wpdb->get_var("show tables like '{$table_name}'") != $table_name) { $sql = "CREATE TABLE IF NOT EXISTS `" . $table_name . "` (\n `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n `name` varchar(255) NOT NULL,\n `width` smallint(5) unsigned NOT NULL,\n `height` smallint(5) unsigned NOT NULL,\n `slider_effect` text,\n `show_navigation` tinyint(1) unsigned NOT NULL,\n `navigation_on_hover_state_only` tinyint(1) unsigned NOT NULL,\n `show_thumbnails` tinyint(1) unsigned NOT NULL,\n `deny_resize_img` tinyint(1) unsigned NOT NULL,\n `pause` smallint(5) unsigned NOT NULL,\n `transition_duration` smallint(5) unsigned NOT NULL,\n `content_before` longtext NOT NULL,\n `content_after` longtext NOT NULL,\n `status` tinyint(1) unsigned NOT NULL,\n `show_slide_caption` tinyint(1) NOT NULL,\n `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n `created` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',\n `thumb_width` smallint(5) unsigned NOT NULL,\n `thumb_height` smallint(5) unsigned NOT NULL,\n PRIMARY KEY (`id`)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"; dbDelta($sql); $wpdb->query('INSERT INTO `' . $table_name . '` (`id`, `name`, `width`, `height`, `slider_effect`, `show_navigation`, `navigation_on_hover_state_only`, `show_thumbnails`, `deny_resize_img`, `pause`, `transition_duration`, `content_before`, `content_after`, `status`, `show_slide_caption`, `updated`, `created`, `thumb_width`, `thumb_height`) VALUES (1, \'Slide 1\', 1024, 500, \'a:1:{i:0;s:4:"fade";}\', 0, 0, 1, 0, 4000, 1500, \'\', \'\', 1, 0, \'0000-00-00 00:00:00\', \'0000-00-00 00:00:00\', 150, 100);'); } $table_name = $wpdb->prefix . SLIDES_TABLE; if ($wpdb->get_var("show tables like '{$table_name}'") != $table_name) { $sql = "CREATE TABLE IF NOT EXISTS `" . $table_name . "` (\n `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n `slider_id` int(10) unsigned NOT NULL,\n `name` varchar(255) NOT NULL,\n `caption` text NOT NULL,\n `order_flag` tinyint(127) unsigned NOT NULL,\n `link` varchar(255) NOT NULL,\n `status` tinyint(1) unsigned NOT NULL DEFAULT '0',\n `picture` varchar(255) NOT NULL,\n `hotsposts` text NOT NULL,\n `order` tinyint(3) unsigned NOT NULL,\n `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n `created` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',\n PRIMARY KEY (`id`)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"; dbDelta($sql); } /** * Store defaults options */ foreach ($lookbook_settings_fields as $key => $val) { $result = $wpdb->get_results("SELECT\n option_id\n FROM\n `" . $wpdb->prefix . "options" . "`\n WHERE\n option_name = '{$key}'", ARRAY_A); if (empty($result)) { $wpdb->insert($wpdb->prefix . 'options', array('option_name' => $key, 'option_value' => $val), array('%s', '%s')); } } /** * Create default folder for picture */ $file = new alfw_manage_files(); $file->create_folder_recursive(FULL_UPLOAD_PATH); $file->create_folder_recursive(FULL_UPLOAD_PATH_THUMB); $file->create_folder_recursive(FULL_UPLOAD_PATH_ORIG); }