array( 'name' => __( 'Theme Options Media', 'cyberchimps_core' ), ), 'public' => true, 'show_ui' => false, 'capability_type' => 'post', 'hierarchical' => false, 'rewrite' => false, 'supports' => array( 'title', 'editor' ), 'query_var' => false, 'can_export' => true, 'show_in_nav_menus' => false, 'public' => false ) ); } } /** * Adds the Thickbox CSS file and specific loading and button images to the header * on the pages where this function is called. */ if( !function_exists( 'cyberchimps_mlu_css' ) ) { function cyberchimps_mlu_css() { $_html = ''; $_html .= '' . "\n"; $_html .= '' . "\n"; echo $_html; } } /** * Registers and enqueues (loads) the necessary JavaScript file for working with the * Media Library-driven AJAX File Uploader Module. */ if( !function_exists( 'cyberchimps_mlu_js' ) ) { function cyberchimps_mlu_js() { // Registers custom scripts for the Media Library AJAX uploader. wp_register_script( 'cyberchimps-medialibrary-uploader', dirname( __FILE__ ) . '/lib/js/options-medialibrary-uploader.js', array( 'jquery', 'thickbox' ) ); wp_enqueue_script( 'cyberchimps-medialibrary-uploader' ); wp_enqueue_script( 'media-upload' ); } } /** * Media Uploader Using the WordPress Media Library. * * Parameters: * - string $_id - A token to identify this field (the name). * - string $_value - The value of the field, if present. * - string $_mode - The display mode of the field. * - string $_desc - An optional description of the field. * - int $_postid - An optional post id (used in the meta boxes). * * Dependencies: * - optionsframework_mlu_get_silentpost() */ if( !function_exists( 'cyberchimps_medialibrary_uploader' ) ) { function cyberchimps_medialibrary_uploader( $_class, $_id, $_value, $_mode = 'full', $_desc = '', $_postid = 0, $_name = '' ) { $output = ''; $id = ''; $class = ''; $container_class = ''; $int = ''; $value = ''; $name = ''; $id = strip_tags( strtolower( $_id ) ); $container_class = strip_tags( strtolower( $_class ) ); // Change for each field, using a "silent" post. If no post is present, one will be created. $int = cyberchimps_mlu_get_silentpost( $id ); // If a value is passed and we don't have a stored value, use the value that's passed through. if( $_value != '' && $value == '' ) { $value = $_value; } if( $_name != '' ) { $name = '[' . $id . '][' . $_name . ']'; } else { $name = '[' . $id . ']'; } if( $value ) { $class = ' has-file'; } $output .= '
' . "\n"; $output .= '
' . "\n"; if( $_desc != '' ) { $output .= '' . $_desc . '' . "\n"; } $output .= '
' . "\n"; if( $value != '' ) { $remove = 'Remove'; $image = ( strpos( $value, 'gravatar' ) ) ? $value : preg_match( '/(^.*\.jpg|jpeg|png|gif|ico*)/i', $value ); if( $image ) { $output .= '' . $remove . ''; } else { $parts = explode( "/", $value ); for( $i = 0; $i < sizeof( $parts ); ++$i ) { $title = $parts[$i]; } // No output preview if it's not an image. $output .= ''; // Standard generic output if it's not an image. $title = __( 'View File', 'cyberchimps_core' ); $output .= '
' . $title . '' . $remove . '
'; } } $output .= '
' . "\n"; return $output; } } /** * Uses "silent" posts in the database to store relationships for images. * This also creates the facility to collect galleries of, for example, logo images. * * Return: $_postid. * * If no "silent" post is present, one will be created with the type "optionsframework" * and the post_name of "of-$_token". * * Example Usage: * optionsframework_mlu_get_silentpost ( 'cyberchimps_logo' ); */ if( !function_exists( 'cyberchimps_mlu_get_silentpost' ) ) { function cyberchimps_mlu_get_silentpost( $_token ) { global $wpdb; $_id = 0; $_token = strtolower( str_replace( ' ', '_', $_token ) ); if( $_token ) { // Tell the function what to look for in a post. $_args = array( 'post_type' => 'cybrchmpsthmoption', 'post_name' => 'of-' . $_token, 'post_status' => 'draft', 'comment_status' => 'closed', 'ping_status' => 'closed' ); // Look in the database for a "silent" post that meets our criteria. $query = 'SELECT ID FROM ' . $wpdb->posts . ' WHERE post_parent = 0'; foreach( $_args as $k => $v ) { $query .= ' AND ' . $k . ' = "' . $v . '"'; } // End FOREACH Loop $query .= ' LIMIT 1'; $_posts = $wpdb->get_row( $query ); // If we've got a post, loop through and get it's ID. if( count( $_posts ) ) { $_id = $_posts->ID; } else { // If no post is present, insert one. // Prepare some additional data to go with the post insertion. $_words = explode( '_', $_token ); $_title = join( ' ', $_words ); $_title = ucwords( $_title ); $_post_data = array( 'post_title' => $_title ); $_post_data = array_merge( $_post_data, $_args ); $_id = wp_insert_post( $_post_data ); } } return $_id; } } /** * Trigger code inside the Media Library popup. */ if( !function_exists( 'cyberchimps_mlu_insidepopup' ) ) { function cyberchimps_mlu_insidepopup() { if( isset( $_REQUEST['is_cybrchmpsthmoption'] ) && $_REQUEST['is_cybrchmpsthmoption'] == 'yes' ) { add_action( 'admin_head', 'cyberchimps_mlu_js_popup' ); add_filter( 'media_upload_tabs', 'cyberchimps_mlu_modify_tabs' ); } } } if( !function_exists( 'cyberchimps_mlu_js_popup' ) ) { function cyberchimps_mlu_js_popup() { $_cyberchimps_title = $_REQUEST['cyberchimps_title']; if( !$_cyberchimps_title ) { $_cyberchimps_title = 'file'; } // End IF Statement ?>