function wowslider_add($folder = false, $update = 0, $delete = true) { global $wpdb, $user_ID; static $id = 0; if (!$folder) { return $id; } if (is_file($folder) && strtolower(substr($folder, -4)) == '.zip') { return wowslider_import($folder, $update, $delete); } $folder = rtrim(str_replace('\\', '/', $folder), '/') . '/'; if (is_file($folder . 'slider.html') && is_dir($folder . 'images/')) { $images = array(); $list = WOWSlider_Helpers::filesystem_dirlist($folder . (is_dir($folder . 'tooltips/') ? 'tooltips/' : 'images/')); foreach ($list as $name => $v) { if ($v['type'] != 'f') { continue; } switch (strtolower(substr($name, -4))) { case '.jpg': case '.png': $images[] = $name; break; } if (count($images) == 10) { break; } } if (count($images)) { $name = ''; if (preg_match('/<!--\\s*Name:(.+?)\\s*-->/ui', file_get_contents($folder . 'slider.html'), $match)) { $name = trim($match[1]); } $date = current_time('mysql'); $insert = array('slider_name' => mb_substr($name, 0, 200), 'slider_author' => $user_ID, 'slider_date' => $date, 'slider_date_gmt' => get_gmt_from_date($date), 'slider_public' => 1, 'slider_images' => serialize($images)); if ($update) { $insert['ID'] = $update; } foreach ($insert as $k => $v) { $insert[$k] = '"' . esc_sql($v) . '"'; } $wpdb->query('INSERT INTO ' . $wpdb->prefix . 'wowslider (' . implode(',', array_keys($insert)) . ') VALUES (' . implode(',', array_values($insert)) . ');'); $id = $update ? (int) $update : (int) $wpdb->get_var('SELECT LAST_INSERT_ID();'); if ($id) { $dest = wowslider_upload_dir() . $id . '/'; if (!is_dir(wowslider_upload_dir())) { mkdir(wowslider_upload_dir()); } if (is_dir($dest)) { WOWSlider_Helpers::filesystem_delete($dest, true); } WOWSlider_Helpers::filesystem_move($folder, $dest); if ($name == '') { $wpdb->query('UPDATE ' . $wpdb->prefix . 'wowslider SET slider_name = "' . esc_sql('Slider ' . $id) . '" WHERE ID = ' . $id . ';'); } file_put_contents($dest . 'slider.html', str_replace('%ID%', $id, file_get_contents($dest . 'slider.html'))); file_put_contents($dest . 'style.css', str_replace('%ID%', $id, file_get_contents($dest . 'style.css'))); if (file_exists($dest . 'script.js')) { file_put_contents($dest . 'script.js', str_replace('%ID%', $id, file_get_contents($dest . 'script.js'))); } return true; } else { return __('Failure when added to the table.', 'wowslider'); } } } return __('Wrong slider.', 'wowslider'); }
function wowslider_old_version() { $dir = WOWSLIDER_PLUGIN_PATH . 'sliders/'; if (is_dir($dir)) { require_once ABSPATH . 'wp-admin/includes/file.php'; if ($list = WOWSlider_Helpers::filesystem_dirlist($dir)) { foreach ($list as $item) { WOWSlider_Helpers::filesystem_move($source . $dir . $item['name'], wowslider_upload_dir() . $item['name']); } } WOWSlider_Helpers::filesystem_delete($dir, true); } }