'; } /* width: width of the gallery height: height of the gallery size: thumbnail width in pixels order_by: 'timestamp' or 'rate' designer: show only designs of this user click: 'details', 'order', 'customize', 'view', 'none' : action performed when the user clicks on the design */ function shortcode_sculpteo_gallery($attr) { if ( !$attr['width'] && !$attr['height'] ) { $attr['width'] = 640; } if ( !$attr['height'] ) { $attr['height'] = intval($attr['width'] * 3 / 4); } if ( !$attr['width'] ) { $attr['width'] = intval($attr['height'] * 4 / 3); } if ( !$attr['size'] ) { $attr['size'] = 130; } $extras = 'nav="box"'; // $extras = 'size='.$attr['size']; if ( !empty($attr['order_by']) ) { $extras .= ' order_by='.$attr['order_by']; } if ( !empty($attr['designer']) ) { $extras .= ' designer='.$attr['designer']; } if ( !empty($attr['click']) ) { $extras .= ' click="' . $attr['click'] . '"'; } // return ''; //return ''; return ''; } /* size: thumbnail width in pixels designer|shop: show only designs of this user click: 'details', 'order', 'customize', 'view', 'none' : action performed when the user clicks on the design */ function shortcode_sculpteo_shop($attr) { $extras = 'nav="box"'; // $extras = 'size='.$attr['size']; if ( !$attr['width'] && !$attr['height'] ) { $attr['width'] = 640; } if ( !$attr['height'] ) { $attr['height'] = intval($attr['width'] * 3 / 4); } if ( !$attr['width'] ) { $attr['width'] = intval($attr['height'] * 4 / 3); } if ( !empty($attr['size']) ) { $extras .= ' size='.$attr['size']; } if ( !empty($attr['designer']) ) { $extras .= ' designer='.$attr['designer']; } if ( !empty($attr['shop']) ) { $extras .= ' designer='.$attr['shop']; } if ( !empty($attr['click']) ) { $extras .= ' click="' . $attr['click'] . '"'; } return '
'; } function sculpteo3d_media_upload_sculpteo3d() { if ( isset($_POST['html-upload']) && !empty($_FILES) ) { // Upload File button was clicked $id = media_handle_upload('async-upload', $_REQUEST['post_id']); unset($_FILES); if ( is_wp_error($id) ) { $errors['upload_error'] = $id; $id = false; } } if ( !empty($_POST['insertonlybutton']) ) { $src = $_POST['insertonly']['src']; $title = stripslashes( htmlspecialchars ($_POST['insertonly']['post_title'], ENT_QUOTES)); $alt = $_POST['insertonly']['post_content']; if ( !empty($src) && !strpos($src, '://') ) { $src = "http://$src"; } // append any additional properties passed to the object. // I don't like that I'm doing the same thing here in two places // TODO: Need to make this so it only happens in one location. $extras = ''; if ( !empty($_POST['insertonly']['width']) && intval($_POST['insertonly']['width']) ) { $extras .= ' width="'.stripslashes( htmlspecialchars ($_POST['insertonly']['width'], ENT_QUOTES)).'"'; } if ( !empty($_POST['insertonly']['height']) && intval($_POST['insertonly']['height']) ) { $extras .= ' height="'.stripslashes( htmlspecialchars ($_POST['insertonly']['height'], ENT_QUOTES)).'"'; } if ( !empty($src) ) { $html = '[sculpteo_viewer src="'.$src.'"'.$extras.'] '; } return media_send_to_editor($html); } if ( !empty($_POST) ) { $return = media_upload_form_handler(); if ( is_string($return) ) return $return; if ( is_array($return) ) $errors = $return; } if ( isset($_POST['save']) ) { $errors['upload_notice'] = __('Saved.'); } if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' ) { return wp_iframe( 'media_upload_type_url_form', 'sculpteo3d', $errors, $id ); } return wp_iframe( 'media_upload_type_form', 'sculpteo3d', $errors, $id ); } function type_url_form_sculpteo3d() { return '
*
'; } function sculpteo3d_add_media_button() { global $post_ID, $temp_ID; $uploading_iframe_ID = (int) (0 == $post_ID ? $temp_ID : $post_ID); $media_upload_iframe_src = "media-upload.php?post_id=$uploading_iframe_ID&type=sculpteo3d"; $media_upload_title = __('Add 3D content', 'sculpteo3d'); echo ''.$media_upload_title.''; } function sculpteo3d_attachment_fields_to_edit($form_fields, $post) { if ( $post->post_mime_type == 'application/x-sculpteo3d' ) { // TODO: handle zip unset( $form_fields['post_title'] ); unset( $form_fields['post_excerpt'] ); unset( $form_fields['post_content'] ); $form_fields['size'] = array( 'label' => __('Size').' '.__('width/height').'', 'input' => 'html', 'html' => ' ' ); } return $form_fields; } function sculpteo3d_media_send_to_editor($html, $attachment_id, $attachment) { $post =& get_post($attachment_id); if ( $post->post_mime_type == 'application/x-sculpteo3d' ) { // TODO: handle zip $obj = $attachment; $src = wp_get_attachment_url($attachment_id); // append any additional properties passed to the object. $extras = ''; if ( !empty($obj['width']) && intval($obj['width']) ) { $extras .= ' width="'.stripslashes( htmlspecialchars ($obj['width'], ENT_QUOTES)).'"'; } if ( !empty($obj['height']) && intval($obj['height']) ) { $extras .= ' height="'.stripslashes( htmlspecialchars ($obj['height'], ENT_QUOTES)).'"'; } $html = '[sculpteo_viewer src="'.$src.'"'.$extras.'] '; } return $html; } function sculpteo3d_upload_mimes ( $existing_mimes=array() ) { // add 3D extensions to mime type array $existing_mimes['obj'] = 'application/x-sculpteo3d'; $existing_mimes['ply'] = 'application/x-sculpteo3d'; $existing_mimes['stl'] = 'application/x-sculpteo3d'; $existing_mimes['off'] = 'application/x-sculpteo3d'; $existing_mimes['skp'] = 'application/x-sculpteo3d'; $existing_mimes['kmz'] = 'application/x-sculpteo3d'; $existing_mimes['3ds'] = 'application/x-sculpteo3d'; $existing_mimes['ac'] = 'application/x-sculpteo3d'; $existing_mimes['ase'] = 'application/x-sculpteo3d'; $existing_mimes['dae'] = 'application/x-sculpteo3d'; $existing_mimes['md2'] = 'application/x-sculpteo3d'; $existing_mimes['md3'] = 'application/x-sculpteo3d'; $existing_mimes['q3o'] = 'application/x-sculpteo3d'; $existing_mimes['cob'] = 'application/x-sculpteo3d'; $existing_mimes['dxf'] = 'application/x-sculpteo3d'; $existing_mimes['lwo'] = 'application/x-sculpteo3d'; $existing_mimes['igs'] = 'application/x-sculpteo3d'; $existing_mimes['stp'] = 'application/x-sculpteo3d'; $existing_mimes['wrl'] = 'application/x-sculpteo3d'; return $existing_mimes; } function sculpteo3d_post_mime_types($post_mime_types) { $post_mime_types['application/x-sculpteo3d'] = array(__('3D Models'), __('Manage 3D Models'), _n_noop('3D Model (%s)', '3D Models (%s)')); return $post_mime_types; } add_filter('media_send_to_editor', 'sculpteo3d_media_send_to_editor', 10, 3); add_filter('post_mime_types', 'sculpteo3d_post_mime_types'); add_filter('upload_mimes', 'sculpteo3d_upload_mimes'); add_filter('attachment_fields_to_edit', 'sculpteo3d_attachment_fields_to_edit', 10, 2); add_action('media_buttons', 'sculpteo3d_add_media_button', 20); add_action('media_upload_sculpteo3d', 'sculpteo3d_media_upload_sculpteo3d'); add_action('wp_enqueue_scripts', 'sculpteo_init_method' ); add_shortcode( 'sculpteo_viewer', 'shortcode_sculpteo_viewer' ); add_shortcode( 'sculpteo_gallery', 'shortcode_sculpteo_gallery' ); add_shortcode( 'sculpteo_shop', 'shortcode_sculpteo_shop' ); ?>