Пример #1
0
 /**
  * The avia media get_custom_post function gets a custom post based on a post title. if no post cold be found it creates one
  * @param string $post_title the title of the post
  * @package 	AviaFramework
  */
 public static function get_custom_post($post_title)
 {
     $save_title = avia_backend_safe_string($post_title);
     $args = array('post_type' => 'avia_framework_post', 'post_title' => 'avia_' . $save_title, 'post_status' => 'draft', 'comment_status' => 'closed', 'ping_status' => 'closed');
     $avia_post = avia_media::get_post_by_title($args['post_title']);
     if (!isset($avia_post['ID'])) {
         $avia_post_id = wp_insert_post($args);
     } else {
         $avia_post_id = $avia_post['ID'];
     }
     return $avia_post_id;
 }
Пример #2
0
 /**
  * 
  * The upload method renders a single upload element so users can add their own pictures
  * the script first gets the id of a hidden post that should store the image. if no post is set it will create one
  * then we check if a basic url based upload should be used or a more sophisticated id based for slideshows and feauted images, which need
  * the images resized automatically
  *
  * @param array $element the array holds data like type, value, id, class, description which are necessary to render the whole option-section
  * @return string $output the string returned contains the html code generated within the method
  */
 function upload($element)
 {
     global $post_ID;
     $output = "";
     $gallery_mode = false;
     $id_generated = false;
     $image_url = $element['std'];
     if (empty($element['button-label'])) {
         $element['button-label'] = "Upload";
     }
     //get post id of the hidden post that stores the image
     if (!empty($element['attachment-prefix'])) {
         if (empty($element['std']) && empty($element['no-attachment-id'])) {
             $element['std'] = uniqid();
             $id_generated = true;
         }
         $gallery_mode = true;
         $postId = avia_media::get_custom_post($element['attachment-prefix'] . $element['std']);
     } else {
         $postId = avia_media::get_custom_post($element['name']);
         if (is_numeric($element['std'])) {
             $image_url = wp_get_attachment_image_src($element['std'], 'full');
             $image_url = $image_url[0];
         }
     }
     //switch between normal url upload and advanced image id upload
     $mode = $prevImg = "";
     //video or image, advanced or default upload?
     if (isset($element['subtype'])) {
         $mode = ' avia_advanced_upload';
         if (!is_numeric($element['std']) && $element['std'] != '') {
             $prevImg = '<a href="#" class="avia_remove_image">remove</a><img src="' . AVIA_IMG_URL . 'icons/video.png" alt="" />';
         } else {
             if ($element['std'] != '') {
                 $prevImg = '<a href="#" class="avia_remove_image">remove</a>' . wp_get_attachment_image($element['std'], array(100, 100));
             }
         }
     } else {
         if (!preg_match('!\\.jpg$|\\.jpeg$|\\.ico$|\\.png$|\\.gif$!', $image_url) && $image_url != "") {
             $prevImg = '<a href="#" class="avia_remove_image">remove</a><img src="' . AVIA_IMG_URL . 'icons/video.png" alt="" />';
         } else {
             if ($image_url != '') {
                 $prevImg = '<a href="#" class="avia_remove_image">remove</a><img src="' . $image_url . '" alt="" />';
             }
         }
     }
     if ($gallery_mode) {
         $image_url_array = array();
         $attachments = get_children(array('post_parent' => $postId, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID'));
         foreach ($attachments as $key => $attachment) {
             $image_url_array[] = avia_image_by_id($attachment->ID, array('width' => 80, 'height' => 80));
         }
         $output .= "<div class='avia_thumbnail_container'>";
         if (isset($image_url_array[0])) {
             foreach ($image_url_array as $key => $img) {
                 $output .= "<div class='avia_gallery_thumb'><div class='avia_gallery_thumb_inner'>" . $img . "</div></div>";
             }
             $output .= "<div class='avia_clear'></div>";
         }
         $output .= "</div>";
     }
     $data = "";
     $upload_class = "avia_uploader";
     global $wp_version;
     if (version_compare($wp_version, '3.5', '>=') && empty($element['force_old_media']) && empty($element['subtype'])) {
         $upload_class = "avia_uploader_35";
         if (empty($element['data'])) {
             $element['data'] = array('target' => $element['id'], 'title' => $element['name'], 'type' => 'image', 'button' => $element['label'], 'class' => 'media-frame av-media-frame-image-only', 'frame' => 'select', 'state' => 'av_select_single_image', 'fetch' => 'url');
         }
         foreach ($element['data'] as $key => $value) {
             if (is_array($value)) {
                 $value = implode(", ", $value);
             }
             $data .= " data-{$key}='{$value}' ";
         }
     }
     $output .= '<div class="avia_upload_container avia_upload_container_' . $postId . $mode . '">';
     $output .= '	<span class="avia_style_wrap avia_upload_style_wrap">';
     $output .= '	<input type="text" class="avia_upload_input ' . $element['class'] . '" value="' . $element['std'] . '" name="' . $element['id'] . '" id="' . $element['id'] . '" />';
     $output .= '	<a ' . $data . ' href="#' . $postId . '" class="avia_button ' . $upload_class . '" title="' . $element['name'] . '" id="avia_upload' . $element['id'] . '">' . $element['button-label'] . '</a>';
     $output .= '	</span>';
     $output .= '	<div class="avia_preview_pic" id="div_' . $element['id'] . '">' . $prevImg . '</div>';
     $output .= '	<input class="avia_upload_insert_label" type="hidden" value="' . $element['label'] . '" />';
     if ($gallery_mode) {
         $output .= '	<input class="avia_gallery_mode" type="hidden" value="' . $postId . '" />';
     }
     $output .= '</div>';
     return $output;
 }