prefix . "aparg_flexslider"; $options_table_name = $wpdb->prefix . "aparg_flexslider_options"; $sliders_table_name = $wpdb->prefix . "aparg_flexslider_sliders"; $MSQL = "show tables like '" . $table_name; $mSQL = "show tables like '" . $options_table_name; $msql = "show tables like '" . $sliders_table_name; require_once(ABSPATH . "wp-admin/includes/upgrade.php"); if ($wpdb->get_var($MSQL) != $table_name) { $sql = "CREATE TABLE IF NOT EXISTS `" . $table_name . "` ( `id` int(3) NOT NULL AUTO_INCREMENT, `slide_id` int(3) NOT NULL, `slide_url` varchar(255) NOT NULL, `slide_title` varchar(255) NOT NULL, `description` text NOT NULL, `youtubelink` varchar(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; /* Including dbDelta function for working with DB */ dbDelta($sql); } if ($wpdb->get_var($mSQL) != $options_table_name) { $Sql = "CREATE TABLE IF NOT EXISTS `" . $options_table_name . "` ( `id` int(9) NOT NULL AUTO_INCREMENT, `slider_id` int(3) NOT NULL, `slider_option_name` varchar(30) NOT NULL, `slider_option` varchar(30) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; /* Including dbDelta function for working with DB */ dbDelta($Sql); } if ($wpdb->get_var($msql) != $sliders_table_name) { $SQl = "CREATE TABLE IF NOT EXISTS `" . $sliders_table_name . "` ( `slider_id` int(3) NOT NULL, `slider_name` varchar(255) NOT NULL, PRIMARY KEY (`slider_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8"; /* Including dbDelta function for working with DB */ dbDelta($SQl); } add_option('youtubedb', 1); } register_activation_hook(__FILE__, 'aparg_addmyplugin'); function add_youtube_db() { global $wpdb; $table_name = $wpdb->prefix . "aparg_flexslider"; if (!get_option('youtubedb')) { $sq = "ALTER TABLE `" . $table_name . "` ADD `youtubelink` VARCHAR(255) NOT NULL"; $wpdb->query($sq); add_option('youtubedb', 1); } } add_action('admin_init', 'add_youtube_db'); /* Creating Menus */ function aparg_slider_menu() { /* Adding menus */ add_menu_page('APARG Slider', 'APARG Slider', 8, 'apargslider', 'aparg_flex_slider', plugins_url('aparg-slider/images/logo.png')); } add_action('admin_init', 'aparg_my_plugin_scripts'); add_action('admin_menu', 'aparg_slider_menu'); // **** // function apargslider_contextual_help($contextual_help) { global $current_screen; $cont_help = "

Hi, this is a APARG Slider help.

" . "

To use our slider plugin at first you should add a slider by clicking on the '+' tab.

" . "

Then you'll see default slider settings on right side and blank area on the left side where you can add slides(click 'Add Images') with their descriptions('Add Description').

" . "

After that save current slide information

" . "Our slider plugin advantages" . "
    " . "
  1. Add 4 descriptions to each slide.
  2. " . "
  3. Change slide images by clicking on them
  4. " . "
  5. Delete descriptions, slides, entire sliders
  6. " . "
" . "

Note: If all descriptions are empty their options(background and text color) are inactive.

"; switch ($current_screen->id) { case 'toplevel_page_apargslider' : get_current_screen()->add_help_tab(array( 'id' => 'apargslider-help-tab', 'title' => __('APARG Slider Help'), 'content' => __($cont_help) )); break; } return $contextual_help; } add_filter('contextual_help', 'apargslider_contextual_help'); // **** // function aparg_my_plugin_scripts() { if (is_admin() && isset($_GET['page']) && $_GET['page'] == 'apargslider') { global $wp_scripts; wp_enqueue_script('jquery'); wp_enqueue_script('jquery-ui-sortable'); wp_enqueue_script('jquery-ui-dialog'); $ui = $wp_scripts->query('jquery-ui-core'); wp_enqueue_style('jquery-dialog-style', plugins_url("css/jquery-ui/jquery-ui-1.10.4.css", __FILE__)); wp_enqueue_media(); wp_register_script('cpicker_scripts', plugins_url('colorpicker/js/colorpicker.js', __FILE__)); wp_enqueue_script('cpicker_scripts'); wp_register_style('cpicker_styles', plugins_url('colorpicker/css/colorpicker.css', __FILE__)); wp_enqueue_style('cpicker_styles'); wp_register_style('custom_styles', plugins_url('css/plugin_styles.css', __FILE__), false, false, 'all'); wp_enqueue_style('custom_styles'); wp_register_script('custom_scripts', plugins_url('js/main.js', __FILE__), array('jquery', 'jquery-ui-core')); wp_enqueue_script('custom_scripts'); //Add script to use alternatively media query in IE8 wp_register_script('respond_scripts', plugins_url('js/respond.min.js', __FILE__)); wp_enqueue_script('respond_scripts'); } } function aparg_make_slider_content($slider_id) { $uploadfiles = $_POST['img']; $youtubelink = $_POST['tubelink']; $slides_titles = $_POST['title']; $desc_array = array(); $settings = $_POST['slide_options']; $settings['slider_width'] = (isset($_POST['slide_options']['slider_width_def'])) ? "" : trim($_POST['slide_options']['slider_width']); $settings['slider_height'] = (isset($_POST['slide_options']['slider_height_def'])) ? "" : trim($_POST['slide_options']['slider_height']); $settings['slider_width_def'] = (isset($_POST['slide_options']['slider_width_def'])) ? 1 : 0; $settings['slider_height_def'] = (isset($_POST['slide_options']['slider_height_def'])) ? 1 : 0; $settings['carousel'] = (isset($_POST['slide_options']['carousel'])) ? 1 : 0; $settings['animation'] = (isset($_POST['slide_options']['carousel'])) ? $_POST['slide_options']['animation'] : "slide"; $settings['animation'] = (!isset($_POST['slide_options']['carousel']) && $_POST['slide_options']['animation'] == 'fade') ? $_POST['slide_options']['animation'] : "slide"; $settings['randomize'] = (isset($_POST['slide_options']['randomize'])) ? 1 : 0; $settings['controlNav'] = (isset($_POST['slide_options']['controlNav'])) ? 1 : 0; $settings['directionNav'] = (isset($_POST['slide_options']['directionNav'])) ? 1 : 0; $settings['pauseOnHover'] = (isset($_POST['slide_options']['pauseOnHover'])) ? 1 : 0; $settings['autoPlay'] = (isset($_POST['slide_options']['autoPlay'])) ? 1 : 0; if (isset($_POST['desc']) && !empty($_POST['desc'])) { foreach ($_POST['desc'] as $key => $desc) { $desc_array[$key] = implode('%APARG%', $desc); } $slider_data = array(); global $check; global $wpdb; foreach ($uploadfiles as $key => $slide_images): $slider_data[$key]["slide_url"] = str_replace(get_site_url(), "", $slide_images); $slider_data[$key]["slide_title"] = $slides_titles[$key]; $slider_data[$key]["description"] = (array_key_exists($key, $desc_array)) ? $desc_array[$key] : "NULL"; $slider_data[$key]['youtubelink'] = (isset($youtubelink[$key])) ? $youtubelink[$key] : ""; endforeach; $j = 0; foreach ($settings as $key => $slider_option): $slider_options[$j]["slider_option_name"] = $key; $slider_options[$j]["slider_option"] = $slider_option; $j++; endforeach; $get_content = get_slider_data($slider_id); add_slides($table_name = $wpdb->prefix . "aparg_flexslider", $slider_data, $slider_id); add_slider_options($tablename = $wpdb->prefix . "aparg_flexslider_options", $slider_options, $slider_id); $slider_content = aparg_show_saved_slider($slider_id); $slider_settings = get_slider_settings($slider_id); } if (isset($slider_settings) && !empty($slider_settings) && isset($slider_content) && !empty($slider_content)) { require_once("slider_form.php"); echo ""; } else { require_once("slider_form.php"); } } function aparg_show_saved_slider($slider_id) { $get_content = get_slider_data($slider_id); $slider_content = ""; if (isset($get_content) && !empty($get_content)) { foreach ($get_content as $key => $value) { $description = explode('%APARG%', $value->description); $youtubelink = $value->youtubelink; $slider_content.= ''; // **** // $slider_content.= ''; $slider_content.= ''; $slider_content.= '
Click to change image'; $slider_content.= ''; $slider_content.= '  '; $button_style = ($description[0] === "NULL") ? 'style="display:none;"' : ''; $slider_content.= ''; if ($youtubelink && $youtubelink != 'NULL') { $slider_content.= '
'; $slider_content.= ''; $slider_content.= ''; $slider_content.= '

Please insert a valid youtube link

'; } foreach ($description as $k => $val): if ($val != "NULL") { $slider_content.= '

'; $slider_content.= '

'; } endforeach; $slider_content.= '
'; } return $slider_content; } } function aparg_load_custom_files() { if (!is_admin()) { // **** // wp_enqueue_scripts('jquery'); // **** // wp_register_script('flexslider_scripts', plugins_url('js/jquery.flexslider.js', __FILE__), array('jquery', 'jquery-ui-core',)); wp_enqueue_script('flexslider_scripts'); wp_register_style('flexslider_style', plugins_url('css/flexslider.css', __FILE__)); wp_enqueue_style('flexslider_style'); wp_register_style('flexslider_custom_style', plugins_url('css/flexsliderstyles.css', __FILE__)); wp_enqueue_style('flexslider_custom_style'); } } // **** // add_action('get_header', 'aparg_load_custom_files'); // **** // function aparg_flex_slider() { require_once "dbase.php"; $slider_tabs = get_all_sliders(); foreach ($slider_tabs as $id => $slider) { if ($id == 0) { $first_slider_id = $slider->slider_id; } $last_tab_id = $slider->slider_id; } if ($_GET['id'] && count($slider_tabs) > 0) { $slider_id = $_GET['id']; } else if (!isset($_GET['id']) && count($slider_tabs) > 0) { $slider_id = $first_slider_id; } else if (count($slider_tabs) == 0 && $_GET['slider'] == "new") { $slider_id = 1; } else { $slider_id = 0; } if (isset($_POST["save_slider_" . $slider_id . ""])) { aparg_make_slider_content($slider_id); } else { $slider_content = aparg_show_saved_slider($slider_id); $slider_settings = get_slider_settings($slider_id); if (isset($slider_settings) && !empty($slider_settings) && isset($slider_content) && !empty($slider_content)) { require_once("slider_form.php"); echo ""; if ($_GET['slider'] == "delete") { foreach ($slider_tabs as $id => $slider) { if ($id == 0) { $first_slider_id = $slider->slider_id; } $last_tab_id = $slider->slider_id; } delete_slider($slider_id); if ($slider_id == $last_tab_id && count($tabs) != 1) { $slide_id = '&id=' . $first_slider_id; } else if (($slider_id + 1) != $last_tab_id && count($tabs) != 1) { $slide_id = '&id=' . $last_tab_id; } else if ($slider_id == $last_tab_id && count($tabs) == 1) { $slide_id = ""; } else { $slide_id = '&id=' . ($slider_id + 1); } echo ''; } } else { if ($_GET['slider'] == "new") { echo ""; addnewslider($slider_id); } else if ($_GET['slider'] == "delete") { $tabs = get_all_sliders(); foreach ($tabs as $id => $slider) { if ($id == 0) { $first_slider_id = $slider->slider_id; } $last_tab_id = $slider->slider_id; } if ($slider_id == $last_tab_id && count($tabs) != 1) { $slide_id = '&id=' . $first_slider_id; } else if (($slider_id + 1) != $last_tab_id && count($tabs) != 1) { $slide_id = '&id=' . $last_tab_id; } else if ($slider_id == $last_tab_id && count($tabs) == 1) { $slide_id = ""; } else { $slide_id = '&id=' . ($slider_id + 1); } echo ''; delete_slider($slider_id); } else { include("slider_form.php"); } } } } function aparg_slider_func($atts) { add_action('wp_head', 'load_custom_files'); require_once "dbase.php"; $sliders = get_all_sliders(); $get_slides_content = get_slider_data($atts['id']); $slide_option = get_slider_settings($atts['id']); $img = ''; $dsc = ''; $link = ''; $img_titles = array(); if (!empty($slide_option) && !empty($get_slides_content)) { foreach ($get_slides_content as $key => $value) { if ($key != count($get_slides_content) - 1) { $img.= $value->slide_url . '*'; $dsc.= $value->description . '*'; $link.=$value->youtubelink . '*'; } else { $img.= $value->slide_url; $dsc.= $value->description; $link.=$value->youtubelink; } $img_titles[$key] = $value->slide_title; } foreach ($slide_option['slider_options'] as $key => $value): $str.= '' . $key . '=' . $value . ' '; endforeach; extract(shortcode_atts(array( 'wrapper_class' => 'apargSlider', 'images' => '' . $img . '', 'desc' => '' . $dsc, 'link' => '' . $link, 'options' => '' . rtrim($str) . '', ), $atts)); $images = explode('*', $images); $descs = explode('*', $desc); $links = explode('*', $link); $opt = explode(' ', $options); $slider_settings = array(); foreach ($opt as $val) { $s = explode('=', $val); $slider_settings[$s[0]] = $s[1]; } $output.=""; $output.=""; $output.='
$image) { $tempLinks = $links[$key]; if ($tempLinks && $tempLinks !== "NULL") { $output.= '
  • ' . $img_titles[$key] . '
    '; ; } else { $output.= '
  • ' . $img_titles[$key] . '
    '; } $tempDescs = explode('%APARG%', $descs[$key]); if ($tempDescs[0] !== "NULL") { foreach ($tempDescs as $tempDesc) { if ($tempDesc != "") { $output.='

    ' . apply_filters('the_title', $tempDesc) . '

    '; } } } $output.= '
    '; if ($tempLinks && $tempLinks !== "NULL" && $slider_settings['autoPlay'] != "1") { $tempLinks = str_replace("watch?v=", "v/", $tempLinks); $output.= ''; } $output.= '
  • '; } $output.= '
    '; } if ($slider_settings['animation'] == "fade") { $output.=""; } return $output; } add_shortcode('aparg_slider', 'aparg_slider_func'); add_action('wp_ajax_my_action', 'attach_image_url'); function attach_image_url($desc = null) { require_once(ABSPATH . "wp-admin" . '/includes/image.php'); require_once(ABSPATH . "wp-admin" . '/includes/file.php'); require_once(ABSPATH . "wp-admin" . '/includes/media.php'); $file = $_POST['attachment']; if (!empty($file)) { // Download file to temp location $tmp = download_url($file); // Set variables for storage // fix file filename for query strings preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $file, $matches); $file_array['name'] = basename($matches[0]); $file_array['tmp_name'] = $tmp; // If error storing temporarily, unlink if (is_wp_error($tmp)) { @unlink($file_array['tmp_name']); $file_array['tmp_name'] = ''; } // do the validation and storage stuff $id = media_handle_sideload($file_array, $post_id, $desc); // If error storing permanently, unlink if (is_wp_error($id)) { @unlink($file_array['tmp_name']); } //add_post_meta( '_thumbnail_id', $id, true); } $img = wp_get_attachment_image_src($id, 'full'); echo $img[0]; exit(); } add_action('wp_ajax_get_youtube', 'change_image'); function change_image($desc = null) { require_once(ABSPATH . "wp-admin" . '/includes/image.php'); require_once(ABSPATH . "wp-admin" . '/includes/file.php'); require_once(ABSPATH . "wp-admin" . '/includes/media.php'); $file = $_POST['attachment']; if (!empty($file)) { // Download file to temp location $tmp = download_url($file); // Set variables for storage // fix file filename for query strings preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $file, $matches); $file_array['name'] = basename($matches[0]); $file_array['tmp_name'] = $tmp; // If error storing temporarily, unlink // do the validation and storage stuff $id = media_handle_sideload($file_array, $post_id, $desc); //add_post_meta( '_thumbnail_id', $id, true); $img = wp_get_attachment_image_src($id, 'full'); echo $img[0]; } exit(); } ?>