blogid; // Get all blog ids $blogids = $wpdb->get_col($wpdb->prepare("SELECT blog_id FROM $wpdb->blogs")); foreach ($blogids as $blog_id) { switch_to_blog($blog_id); _aa_install(); } switch_to_blog($old_blog); return; } } _aa_install(); } function _aa_install() { $aaopt = array ( 'mp3_listen' => 'Files to Listen', 'video_watch' => 'Files to Watch', 'before_title' => 'Here is the attachments of this Post', 'show_b_title' => 'yes', 'showmp3info' => 'yes', 'showvideoinfo' => 'yes', 'galeri' => 'yes', 'thw' => '100', 'thh' => '100', 'tbhw' => '800', 'tbhh' => '600', 'fhw' => '48', 'fhh' => '48', 'jhw' => '470', 'jhh' => '325', 'page_ok' => 'no', 'category_ok' => 'no', 'use_colorbox' => 'no', 'homepage_ok' => 'no', 'listview' => 'no', 'newwindow' => 'no', 'jwskin' => '', 'slimstyle' => 'light', 'galstyle' => 'light' ); // if old options exist, update to new system foreach( $aaopt as $key => $value ) { if( $existing = get_option($key) ) { $aaopt[$key] = $existing; delete_option($key); } } add_option('auto_attachments_options', $aaopt); } //DeACTIVATE (MULTISITES) register_deactivation_hook(__FILE__, 'aa_uninstall'); function aa_uninstall( ) { global $wpdb; if (function_exists('is_multisite') && is_multisite()) { // check if it is a network activation - if so, run the activation function for each blog id if (isset($_GET['networkwide']) && ($_GET['networkwide'] == 1)) { $old_blog = $wpdb->blogid; // Get all blog ids $blogids = $wpdb->get_col($wpdb->prepare("SELECT blog_id FROM $wpdb->blogs")); foreach ($blogids as $blog_id) { switch_to_blog($blog_id); _aa_uninstall(); } switch_to_blog($old_blog); return; } } _aa_uninstall(); } function _aa_uninstall( ) { delete_option('auto_attachments_options'); } //Admin Area Accordion function admin_aa_scripts( ) { $urlp = plugins_url('/auto-attachments/includes'); wp_register_script('auto-attachments1', '' . $urlp . '/js/ui.ms.js', __FILE__); wp_register_script('auto-attachments2', '' . $urlp . '/js/aa.js', __FILE__); wp_enqueue_script('auto-attachments1'); wp_enqueue_script('auto-attachments2'); } function admin_aa_styles( ) { $urlp = plugins_url('/auto-attachments/includes'); wp_enqueue_style('customcss', '' . $urlp . '/js/css/custom/ui.css'); } //Admin Area Accordion //Add Css into Header (Header Text Options (added with v0.2.6)) add_action('wp_head', 'addHeaderCode'); function addHeaderCode( ) { $opts = get_option('auto_attachments_options'); $urlp = plugins_url('/auto-attachments'); echo '' . "\n"; //With 0.2.6 you can decide show or hide :) if ($opts['showmp3info'] == 'no') { echo ''; } if ($opts['showvideoinfo'] == 'no') { echo ''; } } $opts = get_option('auto_attachments_options'); //Colorbox usage (added with 0.2.7) if ($opts['use_colorbox'] == 'yes') { add_action('wp_print_scripts', 'enqueue_aa_scripts'); add_action('wp_print_styles', 'enqueue_aa_styles'); function enqueue_aa_scripts( ) { $urlp = plugins_url('/auto-attachments/includes'); wp_enqueue_script('jquery'); wp_enqueue_script('tinybox_script', '' . $urlp . '/js/slimbox2.js', array( 'jquery' )); } function enqueue_aa_styles() { $opts = get_option('auto_attachments_options'); $urlp = plugins_url('/auto-attachments/includes'); if ($opts['slimstyle'] == 'dark' ){ wp_enqueue_style('slimbox_css_dark', '' . $urlp . '/js/slimbox/slimbox-dark.css'); } else { wp_enqueue_style('slimbox_css', '' . $urlp . '/js/slimbox/slimbox.css'); } } } //Admin Area //Custom Admin Area Settinngs add_action('admin_menu', 'aa_admin_page'); function aa_admin_page( ) { $page = add_menu_page(__('Auto Attachments', 'autoa'), __('Auto Attachments', 'autoa'), '10', 'auto_attachments', 'aa_settings', plugins_url('auto-attachments/includes/images/aamenu.png')); add_action('admin_print_scripts-'.$page , 'admin_aa_scripts'); add_action('admin_print_styles', 'admin_aa_styles'); } function aa_settings( ) { global $_POST, $wpdb; //Update Option (Changed with 0.5 [Multisite Supp.]) if ($_POST['serkoup'] == 'uppo') { //Form data sent $a_new = $_POST['autoa']; $a_old = get_option('auto_attachments_options'); $check_opt = array ('mp3_listen','video_watch','before_title','show_b_title','showmp3info','showvideoinfo','galeri','thw','thh','tbhw','tbhh','fhw','fhh','jhw','jhh','page_ok','category_ok','use_colorbox','homepage_ok','listview','newwindow','jwskin','slimstyle','galstyle'); foreach ($check_opt as $aa) { $a_old[$aa] = $a_new[$aa] ? $a_old[$aa] : $a_new[$aa]; } update_option( 'auto_attachments_options', $a_new); echo '

' . __('Settings saved.') . '

'; } //Start to write admin area include 'admin/admin-area.php'; //I included because HTML Codes too Mainstream :) //Admin area finish } $opts = get_option('auto_attachments_options'); add_image_size('aa_big', $opts['tbhw'], $opts['tbhh']); add_image_size('aa_thumb', $opts['thw'], $opts['thh'], TRUE); class aARebuild { function aARebuild() { add_action( 'admin_menu', array($this, 'rebuildmenu') ); } function rebuildmenu() { add_submenu_page('auto_attachments', __('Regen. Thumbnails', 'autoa'), __('Regen. Thumbnails', 'autoa'), 'manage_options', 'aa_regen_thumb', array($this, 'rebuildpage')); } function rebuildpage() { $opts = get_option('auto_attachments_options'); $urlp = plugins_url('/auto-attachments'); ?>

:



'attachment', 'post_mime_type' => 'image', 'numberposts' => -1, 'post_status' => null, 'post_parent' => null, // any parent 'output' => 'object', ) ); foreach ( $attachments as $attachment ) { $res[] = array('id' => $attachment->ID, 'title' => $attachment->post_title); } die( json_encode($res) ); } else if ($action == "regen") { $id = $_POST["id"]; $fullsizepath = get_attached_file( $id ); if ( FALSE !== $fullsizepath && @file_exists($fullsizepath) ) { set_time_limit( 30 ); wp_update_attachment_metadata( $id, wp_generate_attachment_metadata_custom( $id, $fullsizepath, $thumbnails ) ); } die( wp_get_attachment_thumb_url( $id )); } } add_action('wp_ajax_ajax_thumbnail_rebuild', 'ajax_thumbnail_rebuild_ajax'); add_action( 'plugins_loaded', create_function( '', 'global $aARebuild; $aARebuild = new aARebuild();' ) ); function ajax_thumbnail_rebuild_get_sizes() { global $_wp_additional_image_sizes; foreach ( get_intermediate_image_sizes() as $s ) { $sizes[$s] = array( 'name' => '', 'width' => '', 'height' => '', 'crop' => FALSE ); /* Read theme added sizes or fall back to default sizes set in options... */ $sizes[$s]['name'] = $s; if ( isset( $_wp_additional_image_sizes[$s]['width'] ) ) $sizes[$s]['width'] = intval( $_wp_additional_image_sizes[$s]['width'] ); else $sizes[$s]['width'] = get_option( "{$s}_size_w" ); if ( isset( $_wp_additional_image_sizes[$s]['height'] ) ) $sizes[$s]['height'] = intval( $_wp_additional_image_sizes[$s]['height'] ); else $sizes[$s]['height'] = get_option( "{$s}_size_h" ); if ( isset( $_wp_additional_image_sizes[$s]['crop'] ) ) $sizes[$s]['crop'] = intval( $_wp_additional_image_sizes[$s]['crop'] ); else $sizes[$s]['crop'] = get_option( "{$s}_crop" ); } return $sizes; } function wp_generate_attachment_metadata_custom( $attachment_id, $file, $thumbnails = NULL ) { $attachment = get_post( $attachment_id ); $metadata = array(); if ( preg_match('!^image/!', get_post_mime_type( $attachment )) && file_is_displayable_image($file) ) { $imagesize = getimagesize( $file ); $metadata['width'] = $imagesize[0]; $metadata['height'] = $imagesize[1]; list($uwidth, $uheight) = wp_constrain_dimensions($metadata['width'], $metadata['height'], 128, 96); $metadata['hwstring_small'] = "height='$uheight' width='$uwidth'"; // Make the file path relative to the upload dir $metadata['file'] = _wp_relative_upload_path($file); $sizes = ajax_thumbnail_rebuild_get_sizes(); $sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes ); foreach ($sizes as $size => $size_data ) { if( isset( $thumbnails ) && !in_array( $size, $thumbnails )) $intermediate_size = image_get_intermediate_size( $attachment_id, $size_data['name'] ); else $intermediate_size = image_make_intermediate_size( $file, $size_data['width'], $size_data['height'], $size_data['crop'] ); if ($intermediate_size) $metadata['sizes'][$size] = $intermediate_size; } // fetch additional metadata from exif/iptc $image_meta = wp_read_image_metadata( $file ); if ( $image_meta ) $metadata['image_meta'] = $image_meta; } return apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id ); } // Function Area function get_attachment_icons( ) { $opts = get_option('auto_attachments_options'); $urlp = plugins_url('/auto-attachments/includes'); $before_title_text = $opts['before_title']; $b_title = $opts['show_b_title']; $aa_string = "
"; if ($b_title == 'yes') { $aa_string .= "$before_title_text
"; } else { } if ($opts['listview'] == 'yes') { $aa_string .= ""; } $aa_string .= "
"; //Audio Files $mp3s = get_children(array( //do only if there are attachments of these qualifications 'post_parent' => get_the_ID(), 'post_type' => 'attachment', 'numberposts' => -1, 'post_mime_type' => 'audio' //MIME Type condition )); if (!empty($mp3s)): $skin = $opts['jwskin']; $jhw = $opts['jhw']; $aa_string .= "
" . $opts['mp3_listen'] . "
"; endif; //Video Support flv, mp4, etc. added with 0.2 $videoss = get_children(array( //do only if there are attachments of these qualifications 'post_parent' => get_the_ID(), 'post_type' => 'attachment', 'numberposts' => -1, 'post_mime_type' => 'video' //MIME Type condition )); if (!empty($videoss)): $jhw = $opts['jhw']; $jhh = $opts['jhh']; $aa_string .= "
" . $opts['video_watch'] . "
"; endif; if ($opts['galeri'] == 'yes') { global $blog_id, $current_site; $thumb_ID = get_post_thumbnail_id( get_the_ID()); if ($galeriresim = get_children(array( //do only if there are attachments of these qualifications 'post_parent' => get_the_ID(), 'post_type' => 'attachment', 'numberposts' => -1, 'post_mime_type' => 'image', //MIME Type condition 'exclude' => $thumb_ID ))) { $aa_string .= "
"; foreach ($galeriresim as $galerir) //setup array for more than one file attachment { $file_link = wp_get_attachment_url($galerir->ID); //get the url for linkage $file_name_array = explode("/", $galrerir_link); $aath = wp_get_attachment_image_src($galerir->ID, 'aa_thumb'); $aabg = wp_get_attachment_image_src($galerir->ID, 'aa_big'); $aa_string .= ""; if (isset($blog_id) && $blog_id > 1) //fix for TimThumb { $image_link_parts = explode("/files/", $galerir->guid); //fix for TimThumb $aa_string .= ""; $aa_string .= ""; } else { $aa_string .= ""; $aa_string .= ""; } } $aa_string .= "
"; } } $aa_string .= "
"; // Last Check for attachments (Needed After "Before Title option") Thanks Kris! :) $aargu = get_children(array( 'post_parent' => get_the_ID(), 'post_type' => 'attachment', 'numberposts' => -1 )); if (!empty($aargu)): return $aa_string; endif; } //Insert code after the_content (!important) Changed into 3 parts with 0.5 (after this suggestion http://wordpress.org/support/topic/plugin-auto-attachments-does-not-show-attachments-for-posts-on-the-home-page?replies=2#post-2627965 ) add_filter('the_content', 'insertintoContent'); function insertintoContent($content) { if (is_single()) { $content .= get_attachment_icons(); } return $content; } // Home Page Function Corrected with 0.5.2 if ($opts['homepage_ok'] == 'yes') { function insertintoHome($content) { if (is_home()) { $content .= get_attachment_icons(); } return $content; } add_filter('the_content', 'insertintoHome'); } if ($opts['category_ok'] == 'yes') { function insertintoCategory($content) { if (is_category()&&is_archive()) { $content .= get_attachment_icons(); } return $content; } add_filter('the_content', 'insertintoCategory'); } function insertintoPage($content) { if (is_page()) { $post_id = get_the_ID(); $aa_show_page = get_post_meta($post_id, 'aa_page_meta', TRUE); if ($aa_show_page['show'] == 'yes'){ $content .= get_attachment_icons(); } } return $content; } add_filter('the_content', 'insertintoPage'); //Show Plugin Version into Admin Page function plugin_get_version( ) { if (!function_exists('get_plugins')) require_once(ABSPATH . 'wp-admin/includes/plugin.php'); $plugin_folder = get_plugins('/' . plugin_basename(dirname(__FILE__))); $plugin_file = basename((__FILE__)); return $plugin_folder[$plugin_file]['Version']; } ?>