Example #1
0
 public static function get_preview_from_url($url)
 {
     $preview = '';
     $images = array('jpg', 'jpeg', 'bmp', 'gif', 'png');
     if (filter_var($url, FILTER_VALIDATE_URL) !== FALSE) {
         // check for extension, if it has extension then use it
         $info = pathinfo($url);
         if (isset($info['extension'])) {
             if (in_array($info['extension'], $images)) {
                 $preview = $url;
             } else {
                 $type = wp_ext2type($info['extension']);
                 if (is_null($type)) {
                     $type = 'default';
                 }
                 $preview = includes_url() . 'images/crystal/' . $type . '.png';
             }
         } else {
             // if no extension, try to discover from mime
             $mime = wp_remote_head($url);
             if (!is_wp_error($mime)) {
                 $mime = $mime['headers']['content-type'];
                 if (strpos($mime, 'image') === 0) {
                     $preview = $url;
                 } else {
                     $preview = wp_mime_type_icon($mime);
                 }
             } else {
                 $preview = includes_url() . 'images/crystal/' . 'default' . '.png';
             }
         }
     }
     return $preview;
 }
 /**
  * Return the file type for an attachment which corresponds with a context label
  *
  * @param object $file_uri URI of the attachment
  *
  * @return string A file type which corresponds with a context label
  */
 public function get_attachment_type($file_uri)
 {
     $extension = pathinfo($file_uri, PATHINFO_EXTENSION);
     $extension_type = wp_ext2type($extension);
     if (empty($extension_type)) {
         $extension_type = 'document';
     }
     $context_labels = $this->get_context_labels();
     if (!isset($context_labels[$extension_type])) {
         $extension_type = 'document';
     }
     return $extension_type;
 }
    function eshop_downloads($_POST, $images, $content)
    {
        global $wpdb, $eshopoptions;
        //cache
        eshop_cache();
        $table = $wpdb->prefix . "eshop_downloads";
        $ordertable = $wpdb->prefix . "eshop_download_orders";
        $dir_upload = eshop_download_directory();
        $echo = '';
        //download is handled via cart functions as it needs to
        //be accessible before anything is printed on the page
        if (isset($_POST['code']) && isset($_POST['email'])) {
            /*
            Need to add in check about number of downloads here, including unlimited!
            */
            $code = $wpdb->escape($_POST['code']);
            $email = $wpdb->escape($_POST['email']);
            $dlcount = $wpdb->get_var("SELECT COUNT(id) FROM {$ordertable} where email='{$email}' && code='{$code}' && downloads!='0'");
            if ($dlcount > 0) {
                $echo .= $content;
                $tsize = 0;
                $x = 0;
                if ($dlcount > 1 && $eshopoptions['downloads_hideall'] != 'yes') {
                    $echo .= '<p class="jdl"><a href="#dlall">' . __('Download all files', 'eshop') . '</a></p>';
                }
                $dlresult = $wpdb->get_results("Select * from {$ordertable} where email='{$email}' && code='{$code}' && downloads!='0'");
                foreach ($dlresult as $dlrow) {
                    //download single items.
                    $filepath = $dir_upload . $dlrow->files;
                    $dlfilesize = eshop_filesize($dlrow->files);
                    $tsize = $tsize + $dlfilesize;
                    if ($dlrow->downloads == 1) {
                        $dlword = __('download', 'eshop');
                    } else {
                        $dlword = __('downloads', 'eshop');
                    }
                    $imagetoadd = '';
                    if ($images == 'add') {
                        $checkit = wp_check_filetype($filepath);
                        $eshopext = wp_ext2type($checkit['ext']);
                        $eshopfiletypeimgurl = wp_mime_type_icon($eshopext);
                        $eshophead = wp_remote_head($eshopfiletypeimgurl);
                        $eshophresult = wp_remote_retrieve_response_code($eshophead);
                        if ($eshophresult == '200' || $eshophresult == '302') {
                            $dims = getimagesize($eshopfiletypeimgurl);
                        }
                        if (is_array($dims)) {
                            $dimensions = $dims[3];
                        } else {
                            $dimensions = '';
                        }
                        $imagetoadd = apply_filters('eshop_download_imgs', '<img class="eshop-download-icon" src="' . $eshopfiletypeimgurl . '" ' . $dimensions . ' alt="" />', $checkit['ext']);
                    }
                    $dltitle = strlen($dlrow->title) >= 20 ? substr($dlrow->title, 0, 20) . "&#8230;" : $dlrow->title;
                    $echo .= '
					<form method="post" action="" class="eshop dlproduct"><fieldset>
					<legend>' . $dltitle . ' (' . check_filesize($dlfilesize) . ')</legend>
					' . $imagetoadd . '
					<input name="email" type="hidden" value="' . $_POST['email'] . '" />
					<input name="code" type="hidden" value="' . $_POST['code'] . '" />
					<input name="id" type="hidden" value="' . $dlrow->id . '" />
					<input name="eshoplongdownloadname" type="hidden" value="yes" />
					<label for="ro' . $x . '">' . __('Number of downloads remaining', 'eshop') . '</label>
					<input type="text" readonly="readonly" name="ro" class="ro" id="ro' . $x . '" value="' . $dlrow->downloads . '" />
					<span class="buttonwrap"><input type="submit" class="button" id="submit' . $x . '" name="Submit" value="' . __('Download', 'eshop') . ' ' . $dltitle . '" /></span>
					</fieldset></form>';
                    $x++;
                    $size = 0;
                }
                if ($dlcount > 1 && $eshopoptions['downloads_hideall'] != 'yes') {
                    //download all form.
                    $echo .= '
					<form method="post" action="" id="dlall" class="eshop"><fieldset>
					<legend>' . __('Download all files', 'eshop') . ' (' . check_filesize($tsize) . ') ' . __('in one zip file.', 'eshop') . '</legend>
					<input name="email" type="hidden" value="' . $_POST['email'] . '" />
					<input name="code" type="hidden" value="' . $_POST['code'] . '" />
					<input name="id" type="hidden" value="all" />
					<input name="eshoplongdownloadname" type="hidden" value="yes" />
					<p><span class="buttonwrap"><input class="button" type="submit" id="submit" name="Submit" value="' . __('Download All Files', 'eshop') . '" /></span></p>
					</fieldset></form>
					';
                }
                //allow plugin to change output, validated email/passcode already
                $echo = apply_filters('eshop_download_page', $echo, $code, $email);
            } else {
                $prevdlcount = $wpdb->get_var("SELECT COUNT(id) FROM {$ordertable} where email='{$email}' && code='{$code}'");
                if ($dlcount == $prevdlcount) {
                    $error = '<p class="eshoperror error">' . __('Either your email address or code is incorrect, please try again.', 'eshop') . '</p>';
                } else {
                    $error = '<p class="eshoperror error">' . __('Your email address and code are correct, however you have no downloads remaining.', 'eshop') . '</p>';
                }
                $echo .= eshop_dloadform($email, $code, $error);
            }
        } else {
            $echo .= eshop_dloadform('', '');
        }
        return $echo;
    }
 /**
  * @ticket 35987
  */
 public function test_wp_ext2type()
 {
     $extensions = wp_get_ext_types();
     foreach ($extensions as $type => $extensionList) {
         foreach ($extensionList as $extension) {
             $this->assertEquals($type, wp_ext2type($extension));
             $this->assertEquals($type, wp_ext2type(strtoupper($extension)));
         }
     }
     $this->assertNull(wp_ext2type('unknown_format'));
 }
Example #5
0
 /**
  * Get an HTML img element representing an image attachment
  * @see  add_image_size()
  * @see  wp_get_attachment_image()
  * @uses apply_filters() Calls 'gm_get_attachment_image_attributes' hook on attributes array
  *
  * @param int|object  $item    Image object.
  * @param string      $size    Optional, default is empty string, could be 'thumb', 'web', 'original'
  * @param bool        $cover   Optional, try to get cover url
  * @param bool|string $default Optional, return if no cover and if $size != 'all'
  *
  * @return string|array img url for chosen size
  */
 function gm_get_media_image($item, $size = '', $cover = true, $default = false)
 {
     global $gmDB, $gmGallery;
     if (!is_object($item)) {
         $item = $gmDB->get_gmedia($item);
     }
     if (!$size) {
         $size = 'web';
     }
     if (empty($item)) {
         $image = $default ? $default : $this->gmedia_url . '/admin/assets/img/blank.gif';
         $images = apply_filters('gm_get_media_image', array('thumb' => $image, 'web' => $image, 'original' => $image));
         if ('all' == $size) {
             return $images;
         } else {
             return $images[$size];
         }
     }
     $type = explode('/', $item->mime_type);
     if ('image' == $type[0]) {
         $images = array('thumb' => "{$this->upload['url']}/{$gmGallery->options['folder']['image_thumb']}/{$item->gmuid}", 'web' => "{$this->upload['url']}/{$gmGallery->options['folder']['image']}/{$item->gmuid}", 'original' => "{$this->upload['url']}/{$gmGallery->options['folder']['image_original']}/{$item->gmuid}");
         if ('all' == $size || 'original' == $size) {
             $original_path = "{$this->upload['path']}/{$gmGallery->options['folder']['image_original']}/{$item->gmuid}";
             if (!is_file($original_path)) {
                 $images['original'] = $images['web'];
             }
         }
     } else {
         $ext = ltrim(strrchr($item->gmuid, '.'), '.');
         if (!($type = wp_ext2type($ext))) {
             $type = 'application';
         }
         $image = "{$this->gmedia_url}/admin/assets/img/{$type}.png";
         $images = array('thumb' => $image, 'web' => $image, 'original' => $image);
         if ($cover) {
             $cover = $gmDB->get_metadata('gmedia', $item->ID, '_cover', true);
             if (!empty($cover)) {
                 if ($this->is_digit($cover)) {
                     $images = $this->gm_get_media_image((int) $cover, 'all', false);
                 }
             } elseif ($default !== false && $size !== 'all') {
                 return $default;
             }
         }
     }
     if ('all' == $size) {
         return $images;
     } else {
         return $images[$size];
     }
 }
Example #6
0
 function GetType()
 {
     $ext = substr($this->GetExtension(), 1);
     if ($type = wp_ext2type($ext)) {
         return $type;
     }
     return $ext;
 }
Example #7
0
/**
 * Finds an audio file in a post by looking for the first embedded <a> tags. This can be used to pull external audio files from the post,
 * though it would work even for internal files.
 *
 * @return string
 */
function suffusion_get_audio_from_embedded_url()
{
    global $post;
    $audios = array();
    preg_match_all('|<a.*?href=[\'"](.*?)[\'"].*?>|i', $post->post_content, $links);
    if (isset($links) && isset($links[1]) && is_array($links[1])) {
        foreach ($links[1] as $link) {
            $dot_pos = strrpos($link, '.');
            if ($dot_pos < strlen($link)) {
                $extension = substr($link, $dot_pos + 1);
                if (wp_ext2type($extension) == 'audio') {
                    $audios[] = $link;
                }
            }
        }
    }
    return $audios;
}
 /**
  * Add an MLA Upload MIME Type object
  *
  * @since 1.40
  *
  * @param	array	Query variables for a single object, including slug
  *
  * @return	array	Message(s) reflecting the results of the operation
  */
 public static function mla_add_upload_mime($request)
 {
     if (self::_get_upload_mime_templates()) {
         $errors = '';
     } else {
         return array('message' => __('ERROR', 'media-library-assistant') . ': ' . __('Cannot load Upload MIME Types', 'media-library-assistant'), 'body' => '');
     }
     $messages = '';
     /*
      * Sanitize slug value
      */
     if (empty($request['slug'])) {
         $errors .= '<br>' . __('ERROR', 'media-library-assistant') . ': ' . __('Extension is required', 'media-library-assistant');
     } else {
         $slug = pathinfo('X.' . strtolower(trim($request['slug'])), PATHINFO_EXTENSION);
         if ($slug != $request['slug']) {
             /* translators: 1: element name 2: bad_value 3: good_value */
             $messages .= sprintf(__('<br>' . 'Changing %1$s "%2$s" to valid value "%3$s"', 'media-library-assistant'), __('Extension', 'media-library-assistant'), $request['slug'], $slug);
         }
         /*
          * Make sure new slug is unique
          */
         if (isset(self::$mla_upload_mime_templates[$slug])) {
             /* translators: 1: ERROR tag 2: slug */
             $errors .= '<br>' . sprintf(__('%1$s: Could not add extension "%2$s"; value already exists', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), $slug);
         }
     }
     /*
      * Validate mime_type
      */
     if (empty($request['mime_type'])) {
         $errors .= '<br>' . __('ERROR', 'media-library-assistant') . ': ' . __('MIME type is required', 'media-library-assistant');
     } else {
         $clean_mime_type = sanitize_mime_type($request['mime_type']);
         if ($clean_mime_type != $request['mime_type']) {
             /* translators: 1: ERROR tag 2: clean_mime_type */
             $errors .= '<br>' . sprintf(__('%1$s: Bad MIME type; try "%2$s"', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), $clean_mime_type);
         }
     }
     if (!empty($errors)) {
         return array('message' => substr($errors . $messages, 4), 'body' => '');
     }
     if ('.none.' == $request['icon_type']) {
         if (NULL == ($icon_type = wp_ext2type($slug))) {
             $icon_type = 'default';
         }
     } else {
         $icon_type = $request['icon_type'];
     }
     $new_type = array();
     $new_type['post_ID'] = ++self::$mla_upload_mime_highest_ID;
     $new_type['mime_type'] = $clean_mime_type;
     $new_type['core_type'] = '';
     $new_type['mla_type'] = '';
     $new_type['source'] = 'custom';
     $new_type['standard_source'] = '';
     $new_type['disabled'] = isset($request['disabled']) ? $request['disabled'] : false;
     $new_type['description'] = isset($request['description']) ? sanitize_text_field($request['description']) : '';
     $new_type['icon_type'] = $icon_type;
     $new_type['wp_icon_type'] = $icon_type;
     $new_type['mla_icon_type'] = $icon_type;
     $new_type['core_icon_type'] = self::mla_get_core_icon_type($slug);
     self::$mla_upload_mime_templates[$slug] = $new_type;
     if (self::_put_upload_mime_templates()) {
         return array('message' => substr($messages . '<br>' . sprintf(__('Upload MIME Type "%1$s"; added', 'media-library-assistant'), $slug), 4), 'body' => '');
     }
     return array('message' => __('ERROR', 'media-library-assistant') . ': ' . __('Cannot update Upload MIME Types', 'media-library-assistant'), 'body' => '');
 }
Example #9
0
 /**
  * @group bp_attachments
  */
 public function test_bp_attachments_get_allowed_types()
 {
     $supported = array('jpeg', 'gif', 'png');
     $avatar = bp_attachments_get_allowed_types('avatar');
     $this->assertSame($supported, $avatar);
     $cover_image = bp_attachments_get_allowed_types('cover_image');
     $this->assertSame($supported, $cover_image);
     $images = bp_attachments_get_allowed_types('image/');
     foreach ($images as $image) {
         if ('image' !== wp_ext2type($image)) {
             $not_image = $image;
         }
     }
     $this->assertTrue(empty($not_image));
 }
 function _process($dom)
 {
     // Scan all the array elements, top to bottom
     $total = count($dom);
     for ($d = 0; $d < $total; ++$d) {
         $processed = FALSE;
         $element = $dom[$d];
         if (!is_array($element)) {
             continue;
         }
         $element_key = key($element);
         if ($element_key != 'text') {
             $element_val = $element[$element_key];
             /**
              * Special elements are: 
              * img, embed, object, a tags are special since they are used as placeholders for 
              * plugins, providing them with a nice fallback, so we are checking them as well
              */
             if (strtolower($element_key) == 'img') {
                 $GLOBALS['WiziappProfiler']->write("Handling IMG", "WiziappMediaExtractor._process");
                 $processed = $this->_handleImage($element_val, $element);
                 $GLOBALS['WiziappProfiler']->write("Done Handling IMG", "WiziappMediaExtractor._process");
             } elseif (strtolower($element_key) == 'object' || strtolower($element_key) == 'embed') {
                 $GLOBALS['WiziappProfiler']->write("Handling Flash Object", "WiziappMediaExtractor._process");
                 $processed = $this->_handleFlashObjects($element_val, '', $element);
                 $GLOBALS['WiziappProfiler']->write("Done Handling Flash Object", "WiziappMediaExtractor._process");
                 // vimeo might be loaded as an iframe
             } elseif (strtolower($element_key) == 'iframe') {
                 //                    $GLOBALS['WiziappLog']->write('info', ">>> Found iframe::" . print_r($element_val, TRUE), '_process');
                 $GLOBALS['WiziappProfiler']->write("Handling Iframe as Flash Object", "WiziappMediaExtractor._process");
                 $processed = $this->_handleFlashObjects($element_val, '', $element);
                 $GLOBALS['WiziappProfiler']->write("Done Handling Iframe as Flash Object", "WiziappMediaExtractor._process");
             } elseif (strtolower($element_key) == 'a') {
                 /**
                  * Some plugins uses a tags to include sounds and videos, use the built-in
                  * wordpress function to tell us which file it is by it's ext
                  */
                 $GLOBALS['WiziappProfiler']->write("Handling link", "WiziappMediaExtractor._process");
                 $pos = strrpos($element_val['attributes']['href'], '.');
                 if ($pos !== FALSE) {
                     $ext = substr($element_val['attributes']['href'], $pos + 1);
                     $type = wp_ext2type($ext);
                     if ($type == 'audio') {
                         $GLOBALS['WiziappProfiler']->write("Handling audio link", "WiziappMediaExtractor._process");
                         $processed = $this->_handleAudio($element_val['attributes']['href'], $element_val, $element);
                         $GLOBALS['WiziappProfiler']->write("Done Handling audio link", "WiziappMediaExtractor._process");
                     }
                 }
                 $GLOBALS['WiziappProfiler']->write("Done Handling link", "WiziappMediaExtractor._process");
                 // Use the main parsing method
                 /**if ( !$processed ){ - Removing the support for video embed via links
                        $processed = $this->_handleFlashObjects($element_val, $element_val['attributes']['href'], $element);    
                    }*/
             }
             // The childs of this array can be: text, attributes, childs
             if (!empty($element_val['childs']) && !$processed) {
                 //$this->_process($element_val['childs']);
                 $childs = $element_val['childs'];
                 $this->_process($childs);
             }
         }
     }
 }
Example #11
0
function medialink_func($atts, $html = NULL)
{
    include_once MEDIALINK_PLUGIN_BASE_DIR . '/inc/MediaLink.php';
    $medialink = new MediaLink();
    extract(shortcode_atts(array('set' => '', 'sort' => '', 'suffix' => '', 'suffix_exclude' => '', 'suffix_2' => '', 'display' => '', 'image_show_size' => '', 'thumbnail' => '', 'generate_rssfeed' => '', 'rssname' => '', 'rssmax' => '', 'filesize_show' => '', 'stamptime_show' => '', 'exif_show' => '', 'archiveslinks_show' => '', 'pagelinks_show' => '', 'sortlinks_show' => '', 'searchbox_show' => '', 'rssicon_show' => '', 'credit_show' => ''), $atts));
    $wp_uploads = wp_upload_dir();
    $wp_uploads_baseurl = $wp_uploads['baseurl'];
    $document_root = $wp_uploads['basedir'];
    $topurl = $wp_uploads['baseurl'];
    if (empty($set)) {
        $set = 'all';
    }
    $medialink->set = $set;
    $medialink_album = get_option('medialink_album');
    $medialink_all = get_option('medialink_all');
    $medialink_document = get_option('medialink_document');
    $medialink_movie = get_option('medialink_movie');
    $medialink_music = get_option('medialink_music');
    $medialink_slideshow = get_option('medialink_slideshow');
    $medialink_css = get_option('medialink_css');
    $rssdef = false;
    if ($set === 'all') {
        if (empty($sort)) {
            $sort = $medialink_all['sort'];
        }
        if (empty($suffix_exclude)) {
            $suffix_exclude = $medialink_all['suffix_exclude'];
        }
        $suffix_pattern = $medialink->extpattern($suffix_exclude);
        $suffix_pattern .= ',' . strtoupper($medialink_movie['suffix']) . ',' . strtolower($medialink_movie['suffix']);
        $suffix_pattern .= ',' . strtoupper($medialink_music['suffix']) . ',' . strtolower($medialink_music['suffix']);
        if (empty($display)) {
            $display = intval($medialink_all['display']);
        }
        if (empty($image_show_size)) {
            $image_show_size = $medialink_all['image_show_size'];
        }
        if (empty($generate_rssfeed)) {
            $generate_rssfeed = $medialink_all['generate_rssfeed'];
        }
        if (empty($rssname)) {
            $rssname = $medialink_all['rssname'];
            $rssdef = true;
        }
        if (empty($rssmax)) {
            $rssmax = intval($medialink_all['rssmax']);
        }
        if (empty($filesize_show)) {
            $filesize_show = $medialink_all['filesize_show'];
        }
        if (empty($stamptime_show)) {
            $stamptime_show = $medialink_all['stamptime_show'];
        }
        if (empty($exif_show) && !empty($medialink_all['exif_show'])) {
            $exif_show = $medialink_all['exif_show'];
        }
        if (empty($archiveslinks_show)) {
            $archiveslinks_show = $medialink_all['archiveslinks_show'];
        }
        if (empty($pagelinks_show)) {
            $pagelinks_show = $medialink_all['pagelinks_show'];
        }
        if (empty($sortlinks_show)) {
            $sortlinks_show = $medialink_all['sortlinks_show'];
        }
        if (empty($searchbox_show)) {
            $searchbox_show = $medialink_all['searchbox_show'];
        }
        if (empty($rssicon_show)) {
            $rssicon_show = $medialink_all['rssicon_show'];
        }
        if (empty($credit_show)) {
            $credit_show = $medialink_all['credit_show'];
        }
    } else {
        if ($set === 'album') {
            if (empty($sort)) {
                $sort = $medialink_album['sort'];
            }
            if (empty($suffix_exclude)) {
                $suffix_exclude = $medialink_album['suffix_exclude'];
            }
            if (empty($suffix)) {
                if ($medialink_album['suffix'] === 'all') {
                    $suffix_pattern = $medialink->extpattern($suffix_exclude);
                } else {
                    $suffix_pattern = strtoupper($medialink_album['suffix']) . ',' . strtolower($medialink_album['suffix']);
                }
            } else {
                if ($suffix === 'all') {
                    $suffix_pattern = $medialink->extpattern($suffix_exclude);
                } else {
                    $suffix_pattern = strtoupper($suffix) . ',' . strtolower($suffix);
                }
            }
            if (empty($display)) {
                $display = intval($medialink_album['display']);
            }
            if (empty($image_show_size)) {
                $image_show_size = $medialink_album['image_show_size'];
            }
            if (empty($generate_rssfeed)) {
                $generate_rssfeed = $medialink_album['generate_rssfeed'];
            }
            if (empty($rssname)) {
                $rssname = $medialink_album['rssname'];
                $rssdef = true;
            }
            if (empty($rssmax)) {
                $rssmax = intval($medialink_album['rssmax']);
            }
            if (empty($filesize_show)) {
                $filesize_show = $medialink_album['filesize_show'];
            }
            if (empty($stamptime_show)) {
                $stamptime_show = $medialink_album['stamptime_show'];
            }
            if (empty($exif_show) && !empty($medialink_album['exif_show'])) {
                $exif_show = $medialink_album['exif_show'];
            }
            if (empty($archiveslinks_show)) {
                $archiveslinks_show = $medialink_album['archiveslinks_show'];
            }
            if (empty($pagelinks_show)) {
                $pagelinks_show = $medialink_album['pagelinks_show'];
            }
            if (empty($sortlinks_show)) {
                $sortlinks_show = $medialink_album['sortlinks_show'];
            }
            if (empty($searchbox_show)) {
                $searchbox_show = $medialink_album['searchbox_show'];
            }
            if (empty($rssicon_show)) {
                $rssicon_show = $medialink_album['rssicon_show'];
            }
            if (empty($credit_show)) {
                $credit_show = $medialink_album['credit_show'];
            }
        } else {
            if ($set === 'movie') {
                if (empty($sort)) {
                    $sort = $medialink_movie['sort'];
                }
                if (empty($suffix)) {
                    $suffix_pattern = strtoupper($medialink_movie['suffix']) . ',' . strtolower($medialink_movie['suffix']);
                } else {
                    $suffix_pattern = strtoupper($suffix) . ',' . strtolower($suffix);
                }
                if (empty($suffix_2)) {
                    $suffix_2 = $medialink_movie['suffix_2'];
                }
                if (empty($display)) {
                    $display = intval($medialink_movie['display']);
                }
                if (empty($thumbnail)) {
                    $thumbnail = $medialink_movie['thumbnail'];
                }
                if (empty($generate_rssfeed)) {
                    $generate_rssfeed = $medialink_movie['generate_rssfeed'];
                }
                if (empty($rssname)) {
                    $rssname = $medialink_movie['rssname'];
                    $rssdef = true;
                }
                if (empty($rssmax)) {
                    $rssmax = intval($medialink_movie['rssmax']);
                }
                if (empty($filesize_show)) {
                    $filesize_show = $medialink_movie['filesize_show'];
                }
                if (empty($stamptime_show)) {
                    $stamptime_show = $medialink_movie['stamptime_show'];
                }
                if (empty($archiveslinks_show)) {
                    $archiveslinks_show = $medialink_movie['archiveslinks_show'];
                }
                if (empty($pagelinks_show)) {
                    $pagelinks_show = $medialink_movie['pagelinks_show'];
                }
                if (empty($sortlinks_show)) {
                    $sortlinks_show = $medialink_movie['sortlinks_show'];
                }
                if (empty($searchbox_show)) {
                    $searchbox_show = $medialink_movie['searchbox_show'];
                }
                if (empty($rssicon_show)) {
                    $rssicon_show = $medialink_movie['rssicon_show'];
                }
                if (empty($credit_show)) {
                    $credit_show = $medialink_movie['credit_show'];
                }
            } else {
                if ($set === 'music') {
                    if (empty($sort)) {
                        $sort = $medialink_music['sort'];
                    }
                    if (empty($suffix)) {
                        $suffix_pattern = strtoupper($medialink_music['suffix']) . ',' . strtolower($medialink_music['suffix']);
                    } else {
                        $suffix_pattern = strtoupper($suffix) . ',' . strtolower($suffix);
                    }
                    if (empty($suffix_2)) {
                        $suffix_2 = $medialink_music['suffix_2'];
                    }
                    if (empty($display)) {
                        $display = intval($medialink_music['display']);
                    }
                    if (empty($thumbnail)) {
                        $thumbnail = $medialink_music['thumbnail'];
                    }
                    if (empty($generate_rssfeed)) {
                        $generate_rssfeed = $medialink_music['generate_rssfeed'];
                    }
                    if (empty($rssname)) {
                        $rssname = $medialink_music['rssname'];
                        $rssdef = true;
                    }
                    if (empty($rssmax)) {
                        $rssmax = intval($medialink_music['rssmax']);
                    }
                    if (empty($filesize_show)) {
                        $filesize_show = $medialink_music['filesize_show'];
                    }
                    if (empty($stamptime_show)) {
                        $stamptime_show = $medialink_music['stamptime_show'];
                    }
                    if (empty($archiveslinks_show)) {
                        $archiveslinks_show = $medialink_music['archiveslinks_show'];
                    }
                    if (empty($pagelinks_show)) {
                        $pagelinks_show = $medialink_music['pagelinks_show'];
                    }
                    if (empty($sortlinks_show)) {
                        $sortlinks_show = $medialink_music['sortlinks_show'];
                    }
                    if (empty($searchbox_show)) {
                        $searchbox_show = $medialink_music['searchbox_show'];
                    }
                    if (empty($rssicon_show)) {
                        $rssicon_show = $medialink_music['rssicon_show'];
                    }
                    if (empty($credit_show)) {
                        $credit_show = $medialink_music['credit_show'];
                    }
                } else {
                    if ($set === 'slideshow') {
                        if (empty($sort)) {
                            $sort = $medialink_slideshow['sort'];
                        }
                        if (empty($suffix_exclude)) {
                            $suffix_exclude = $medialink_slideshow['suffix_exclude'];
                        }
                        if (empty($suffix)) {
                            if ($medialink_slideshow['suffix'] === 'all') {
                                $suffix_pattern = $medialink->extpattern($suffix_exclude);
                            } else {
                                $suffix_pattern = strtoupper($medialink_slideshow['suffix']) . ',' . strtolower($medialink_slideshow['suffix']);
                            }
                        } else {
                            if ($suffix === 'all') {
                                $suffix_pattern = $medialink->extpattern($suffix_exclude);
                            } else {
                                $suffix_pattern = strtoupper($suffix) . ',' . strtolower($suffix);
                            }
                        }
                        if (empty($display)) {
                            $display = intval($medialink_slideshow['display']);
                        }
                        if (empty($image_show_size)) {
                            $image_show_size = $medialink_slideshow['image_show_size'];
                        }
                        if (empty($generate_rssfeed)) {
                            $generate_rssfeed = $medialink_slideshow['generate_rssfeed'];
                        }
                        if (empty($rssname)) {
                            $rssname = $medialink_slideshow['rssname'];
                            $rssdef = true;
                        }
                        if (empty($rssmax)) {
                            $rssmax = intval($medialink_slideshow['rssmax']);
                        }
                        if (empty($filesize_show)) {
                            $filesize_show = $medialink_slideshow['filesize_show'];
                        }
                        if (empty($stamptime_show)) {
                            $stamptime_show = $medialink_slideshow['stamptime_show'];
                        }
                        if (empty($exif_show) && !empty($medialink_slideshow['exif_show'])) {
                            $exif_show = $medialink_slideshow['exif_show'];
                        }
                        if (empty($archiveslinks_show)) {
                            $archiveslinks_show = $medialink_slideshow['archiveslinks_show'];
                        }
                        if (empty($pagelinks_show)) {
                            $pagelinks_show = $medialink_slideshow['pagelinks_show'];
                        }
                        if (empty($sortlinks_show)) {
                            $sortlinks_show = $medialink_slideshow['sortlinks_show'];
                        }
                        if (empty($searchbox_show)) {
                            $searchbox_show = $medialink_slideshow['searchbox_show'];
                        }
                        if (empty($rssicon_show)) {
                            $rssicon_show = $medialink_slideshow['rssicon_show'];
                        }
                        if (empty($credit_show)) {
                            $credit_show = $medialink_slideshow['credit_show'];
                        }
                    } else {
                        if ($set === 'document') {
                            if (empty($sort)) {
                                $sort = $medialink_document['sort'];
                            }
                            if (empty($suffix_exclude)) {
                                $suffix_exclude = $medialink_document['suffix_exclude'];
                            }
                            if (empty($suffix)) {
                                if ($medialink_document['suffix'] === 'all') {
                                    $suffix_pattern = $medialink->extpattern($suffix_exclude);
                                } else {
                                    $suffix_pattern = strtoupper($medialink_document['suffix']) . ',' . strtolower($medialink_document['suffix']);
                                }
                            } else {
                                if ($suffix === 'all') {
                                    $suffix_pattern = $medialink->extpattern($suffix_exclude);
                                } else {
                                    $suffix_pattern = strtoupper($suffix) . ',' . strtolower($suffix);
                                }
                            }
                            if (empty($display)) {
                                $display = intval($medialink_document['display']);
                            }
                            if (empty($thumbnail)) {
                                $thumbnail = $medialink_document['thumbnail'];
                            }
                            if (empty($generate_rssfeed)) {
                                $generate_rssfeed = $medialink_document['generate_rssfeed'];
                            }
                            if (empty($rssname)) {
                                $rssname = $medialink_document['rssname'];
                                $rssdef = true;
                            }
                            if (empty($rssmax)) {
                                $rssmax = intval($medialink_document['rssmax']);
                            }
                            if (empty($filesize_show)) {
                                $filesize_show = $medialink_document['filesize_show'];
                            }
                            if (empty($stamptime_show)) {
                                $stamptime_show = $medialink_document['stamptime_show'];
                            }
                            if (empty($archiveslinks_show)) {
                                $archiveslinks_show = $medialink_document['archiveslinks_show'];
                            }
                            if (empty($pagelinks_show)) {
                                $pagelinks_show = $medialink_document['pagelinks_show'];
                            }
                            if (empty($sortlinks_show)) {
                                $sortlinks_show = $medialink_document['sortlinks_show'];
                            }
                            if (empty($searchbox_show)) {
                                $searchbox_show = $medialink_document['searchbox_show'];
                            }
                            if (empty($rssicon_show)) {
                                $rssicon_show = $medialink_document['rssicon_show'];
                            }
                            if (empty($credit_show)) {
                                $credit_show = $medialink_document['credit_show'];
                            }
                        }
                    }
                }
            }
        }
    }
    $mode = NULL;
    $suffix = NULL;
    $suffix_pattern = $suffix_pattern;
    if ($set === 'movie' || $set === 'music') {
        $suffix_2 = '.' . $suffix_2;
    }
    $archiveparam = NULL;
    $fparam = NULL;
    $page = NULL;
    $search = NULL;
    if (!empty($_GET['mlacv'])) {
        $archiveparam = $_GET['mlacv'];
        //archives
    }
    if (!empty($_GET['f'])) {
        $fparam = $_GET['f'];
        //files
    }
    if (!empty($_GET['mlp'])) {
        $page = $_GET['mlp'];
        //pages
    }
    if (!empty($_GET['mls'])) {
        $search = $_GET['mls'];
        //search word
    }
    if (!empty($_GET['sort'])) {
        $sort = $_GET['sort'];
        //sort
    }
    $medialink->thumbnail = $thumbnail;
    $medialink->image_show_size = $image_show_size;
    $medialink->generate_rssfeed = $generate_rssfeed;
    $medialink->search = $search;
    $medialink->archiveparam = $archiveparam;
    $medialink->topurl = $topurl;
    $medialink->wp_uploads_baseurl = $wp_uploads_baseurl;
    $medialink->document_root = $document_root;
    $medialink->mode = $mode;
    $medialink->rssname = $rssname;
    $medialink->rssmax = $rssmax;
    $medialink->sort = $sort;
    $medialink->filesize_show = $filesize_show;
    $medialink->stamptime_show = $stamptime_show;
    $medialink->exif_show = $exif_show;
    $files = array();
    $titles = array();
    $rssfiles = array();
    $sort_key = NULL;
    $sort_order = NULL;
    if ($sort === 'new' || empty($sort)) {
        $sort_key = 'date';
        $sort_order = 'DESC';
    } else {
        if ($sort === 'old') {
            $sort_key = 'date';
            $sort_order = 'ASC';
        } else {
            if ($sort === 'des') {
                $sort_key = 'title';
                $sort_order = 'DESC';
            } else {
                if ($sort === 'asc') {
                    $sort_key = 'title';
                    $sort_order = 'ASC';
                }
            }
        }
    }
    $medialink->sort_order = $sort_order;
    $suffix_patterns = explode(',', $suffix_pattern);
    foreach ($suffix_patterns as $suffix) {
        $postmimes[] = $medialink->mime_type('.' . $suffix);
    }
    $postmimes = array_unique($postmimes);
    $mimepattern_count = 0;
    $postmimepattern = NULL;
    foreach ($postmimes as $postmime) {
        if ($mimepattern_count == 0) {
            $postmimepattern .= $postmime;
        } else {
            $postmimepattern .= ',' . $postmime;
        }
        ++$mimepattern_count;
    }
    unset($suffix_patterns, $postmimes);
    $args = array('post_type' => 'attachment', 'post_mime_type' => $postmimepattern, 'numberposts' => -1, 'orderby' => $sort_key, 'order' => $sort_order, 's' => $search);
    $attachments = get_posts($args);
    list($files, $archives, $rssfiles, $rsscount) = $medialink->scan_media($attachments);
    unset($attachments);
    $maxpage = ceil(count($files) / $display);
    if (empty($page)) {
        $page = 1;
    }
    $medialink->page = $page;
    $medialink->maxpage = $maxpage;
    $beginfiles = 0;
    $endfiles = 0;
    if ($page == $maxpage) {
        $beginfiles = $display * ($page - 1);
        $endfiles = count($files) - 1;
    } else {
        $beginfiles = $display * ($page - 1);
        $endfiles = $display * $page - 1;
    }
    $linkfiles = NULL;
    $selectedfilename = NULL;
    if ($files) {
        for ($i = $beginfiles; $i <= $endfiles; $i++) {
            $linkfile = $medialink->print_file($files[$i]['file'], $files[$i]['title'], $files[$i]['thumblink'], $files[$i]['largemediumlink'], $files[$i]['metadata']);
            $linkfiles = $linkfiles . $linkfile;
            if ($files[$i]['file'] === '/' . $fparam) {
                $selectedfilename = $files[$i]['title'];
            }
        }
    }
    $archives = array_unique($archives);
    $linkarchives = NULL;
    foreach ($archives as $linkarchive) {
        if ($archiveparam === $linkarchive) {
            $linkarchive = '<option value="' . $linkarchive . '" selected>' . $linkarchive . '</option>';
        } else {
            $linkarchive = '<option value="' . $linkarchive . '">' . $linkarchive . '</option>';
        }
        $linkarchives = $linkarchives . $linkarchive;
    }
    if (empty($archiveparam)) {
        $linkarchive = '<option value="" selected>' . __('all', 'medialink') . '</option>';
    } else {
        $linkarchive = '<option value="">' . __('all', 'medialink') . '</option>';
    }
    $linkarchives = $linkarchives . $linkarchive;
    $linkpages = NULL;
    $linkpages = $medialink->print_pages();
    $scriptname = get_permalink();
    $permlinkstrform = $medialink->permlink_form();
    $prevfile = "";
    if (!empty($fparam)) {
        $prevfile = $topurl . '/' . str_replace("%2F", "/", urlencode($fparam));
    }
    $prevfiles = explode('.', $prevfile);
    $prevfile_nosuffix = str_replace('.' . end($prevfiles), "", $prevfile);
    $sortlinks = $medialink->sort_pages();
    $archiveselectbox = <<<ARCHIVESELECTBOX
<form method="get" action="{$scriptname}">
{$permlinkstrform}
<select name="mlacv" onchange="submit(this.form)">
{$linkarchives}
</select>
</form>
ARCHIVESELECTBOX;
    $searchbutton = __('Search', 'medialink');
    $searchform = <<<SEARCHFORM
<form method="get" action="{$scriptname}">
{$permlinkstrform}
<input type="text" name="mls" value="{$search}">
<input type="submit" value="{$searchbutton}">
</form>
SEARCHFORM;
    //MoviePlayerContainer
    $movieplayercontainer = <<<MOVIEPLAYERCONTAINER
<div id="PlayerContainer-medialink">
<video controls autoplay style="width: 100%;">
<source src="{$prevfile}">
<source src="{$prevfile_nosuffix}{$suffix_2}">
</video>
</div>
MOVIEPLAYERCONTAINER;
    //MusicPlayerContainer
    $musicplayercontainer = <<<MUSICPLAYERCONTAINER
<div id="PlayerContainer-medialink">
<audio controls autoplay>
<source src="{$prevfile}">
<source src="{$prevfile_nosuffix}{$suffix_2}">
<div id="FlashContainer"></div>
</audio>
</div>
MUSICPLAYERCONTAINER;
    wp_enqueue_style('for medialink', MEDIALINK_PLUGIN_URL . '/css/medialink.css');
    if ($set === 'all') {
        if (!empty($selectedfilename)) {
            $html .= '<h2>' . $selectedfilename . '</h2>';
        }
    } else {
        if ($set != 'document' && !empty($selectedfilename)) {
            $html .= '<h2>' . $selectedfilename . '</h2>';
        }
    }
    $fparamexts = explode('.', $fparam);
    $fparamext = end($fparamexts);
    if (!empty($fparam)) {
        if (wp_ext2type($fparamext) === 'video') {
            $html .= $movieplayercontainer;
        } else {
            if (wp_ext2type($fparamext) === 'audio') {
                $html .= $musicplayercontainer;
            }
        }
    }
    $linkfiles_begin = NULL;
    $linkfiles_end = NULL;
    $archiveselectbox_begin = NULL;
    $archiveselectbox_end = NULL;
    $linkpages_begin = NULL;
    $linkpages_end = NULL;
    $sortlink_begin = NULL;
    $sortlink_end = NULL;
    $searchform_begin = NULL;
    $searchform_end = NULL;
    $rssfeeds_icon = NULL;
    if ($set === 'album' || $set === 'slideshow') {
        $linkfiles_begin = '<div class = "medialink">';
        $linkfiles_end = '</div><br clear=all>';
    } else {
        $linkfiles_begin = '<div class="medialink-list"><ul>';
        $linkfiles_end = '</ul></div>';
    }
    $archiveselectbox_begin = '<div align="right">';
    $archiveselectbox_end = '</div>';
    $linkpages_begin = '<p><div class="medialink-pages"><span class="medialink-links">';
    $linkpages_end = '</span></div></p>';
    $sortlink_begin = '<p><div class="medialink-pages"><span class="medialink-links">';
    $sortlink_end = '</span></div></p>';
    $searchform_begin = '<div align="center">';
    $searchform_end = '</div>';
    $simplemasonry_apply = get_post_meta(get_the_ID(), 'simplemasonry_apply');
    if ($set === 'album' && class_exists('SimpleMasonry') && !empty($simplemasonry_apply) && $simplemasonry_apply[0] === 'true') {
        // for Simple Masonry Gallery http://wordpress.org/plugins/simple-masonry-gallery/
        $html = apply_filters('album_medialink', $linkfiles);
    } else {
        if ($set === 'slideshow') {
            $html = apply_filters('slideshow_medialink', $linkfiles);
        } else {
            $html .= $linkfiles_begin;
            $html .= $linkfiles;
            $html .= $linkfiles_end;
        }
    }
    if ($archiveslinks_show === 'Show') {
        $html .= $archiveselectbox_begin;
        $html .= $archiveselectbox;
        $html .= $archiveselectbox_end;
    }
    if ($pagelinks_show === 'Show') {
        $html .= $linkpages_begin;
        $html .= $linkpages;
        $html .= $linkpages_end;
    }
    if ($sortlinks_show === 'Show') {
        $html .= $sortlink_begin;
        $html .= $sortlinks;
        $html .= $sortlink_end;
    }
    if ($searchbox_show === 'Show') {
        $html .= $searchform_begin;
        $html .= $searchform;
        $html .= $searchform_end;
    }
    // RSS Feeds
    if ($generate_rssfeed === 'on') {
        $xml_title = get_bloginfo('name') . ' | ' . get_the_title();
        $rssfeed_url = $topurl . '/' . $rssname . '.xml';
        $rssfeeds_icon = '<div align="right"><a href="' . $rssfeed_url . '" class="dashicons dashicons-rss" style="text-decoration: none;"></a></div>';
        if ($rssicon_show === 'Show') {
            $html .= $rssfeeds_icon;
        }
        if ($rssdef === false) {
            $html .= '<link rel="alternate" type="application/rss+xml" href="' . $rssfeed_url . '" title="' . $xml_title . '" />';
        }
        if (!empty($rssfiles)) {
            $medialink->rss_wirte($xml_title, $rssfiles, $rsscount);
        }
    }
    if ($credit_show === 'Show') {
        $html .= '<div align = "right"><a href="http://wordpress.org/plugins/medialink/"><span style="font-size : xx-small">by MediaLink</span></a></div>';
    }
    $html = apply_filters('post_medialink', $html);
    return $html;
}
Example #12
0
 function extpattern($suffix_exclude)
 {
     if ($this->set === 'all') {
         $searchtype = 'image|document|spreadsheet|interactive|text|archive|code';
     } else {
         if ($this->set === 'album' || $this->set === 'slideshow') {
             $searchtype = 'image';
         } else {
             if ($this->set === 'document') {
                 $searchtype = 'document|spreadsheet|interactive|text|archive|code';
             }
         }
     }
     $mimes = wp_get_mime_types();
     $extpattern = NULL;
     foreach ($mimes as $ext => $mime) {
         if (strpos($ext, '|')) {
             $exts = explode('|', $ext);
             foreach ($exts as $ext2) {
                 if (preg_match("/" . $searchtype . "/", wp_ext2type($ext2))) {
                     if (!empty($suffix_exclude) && preg_match("/" . $suffix_exclude . "/i", $ext2)) {
                     } else {
                         $extpattern .= $ext2 . ',' . strtoupper($ext2) . ',';
                     }
                 }
             }
         } else {
             if (preg_match("/" . $searchtype . "/", wp_ext2type($ext))) {
                 if (!empty($suffix_exclude) && preg_match("/" . $suffix_exclude . "/i", $ext)) {
                 } else {
                     $extpattern .= $ext . ',' . strtoupper($ext) . ',';
                 }
             }
         }
     }
     $extpattern = substr($extpattern, 0, -1);
     return $extpattern;
 }
Example #13
0
 /**
  * Get an HTML img element representing an image attachment
  * @see  add_image_size()
  * @see  wp_get_attachment_image()
  * @uses apply_filters() Calls 'gm_get_attachment_image_attributes' hook on attributes array
  *
  * @param int|object $item Image object.
  * @param string $size Optional, default is empty string, could be 'thumb', 'original'
  * @param bool $cover Optional, try to get cover url
  * @param bool|string $default Optional, return if no cover
  *
  * @return string img url
  */
 function gm_get_media_image($item, $size = '', $cover = true, $default = false)
 {
     global $gmDB, $gmGallery;
     if (!is_object($item)) {
         $item = $gmDB->get_gmedia($item);
     }
     $type = explode('/', $item->mime_type);
     if ('image' == $type[0]) {
         $type_folder = $this->upload['url'] . '/' . $gmGallery->options['folder'][$type[0]];
         switch ($size) {
             case 'thumb':
                 $size_folder = '/thumb/';
                 break;
             case 'original':
                 $size_folder = '/original/';
                 break;
             case 'web':
             default:
                 $size_folder = '/';
                 break;
         }
         $image = $type_folder . $size_folder . $item->gmuid;
     } else {
         $ext = ltrim(strrchr($item->gmuid, '.'), '.');
         if (!($type = wp_ext2type($ext))) {
             $type = 'application';
         }
         $image = $this->gmedia_url . '/admin/images/' . $type . '.png';
         if ($cover) {
             $cover = $gmDB->get_metadata('gmedia', $item->ID, 'cover', true);
             if (!empty($cover)) {
                 if ($this->is_digit($cover)) {
                     $image = $this->gm_get_media_image((int) $cover, $size, false);
                 } elseif (false !== filter_var($cover, FILTER_VALIDATE_URL)) {
                     return $cover;
                 }
             } elseif (false !== $default) {
                 return $default;
             }
         }
     }
     return $image;
 }
Example #14
0
 /**
  * Checks whether a file extension is among the accepted file types.
  *
  * @since 0.5.0
  * @param string $extension the file extension to check
  * @param string|array $accepted_types a string or an array of accepted types (default is 'all' to allow everything)
  * @return bool whether the file type is valid
  */
 protected function check_extension($extension, $accepted_types = 'all')
 {
     if ('all' == $accepted_types || !$accepted_types) {
         return true;
     }
     if (!is_array($accepted_types)) {
         $accepted_types = array($accepted_types);
     }
     // check the file extension
     if (in_array(strtolower($extension), $accepted_types)) {
         return true;
     }
     // check the file type (not MIME type!)
     $type = wp_ext2type($extension);
     if ($type !== null && in_array($type, $accepted_types)) {
         return true;
     }
     // check the file MIME type (and first part of MIME type)
     $allowed_mime_types = $this->get_all_mime_types();
     if (isset($allowed_mime_types[$extension])) {
         if (in_array($allowed_mime_types[$extension], $accepted_types)) {
             return true;
         }
         $general_type = explode('/', $allowed_mime_types[$extension])[0];
         if (in_array($general_type, $accepted_types)) {
             return true;
         }
     }
     return false;
 }
 /**
  * Creates array of information about file based on filename.
  * IMPORTANT - Used internally by Wonderflux.
  *
  * Filters available:
  * wflux_ext_img - array of image file extensions
  *
  * @since	1.1
  * @version	1.1
  *
  * @param	[string] $filename		REQUIRED File name with extension (no path)
  * @return	[array]					ext,type,nicetype,playable
  */
 function wf_info_file($filename = '')
 {
     if (empty($filename)) {
         return false;
     }
     $info = wp_check_filetype($filename);
     $file_ext = !empty($info) ? explode('.', $filename) : '';
     $file_nice = wp_ext2type(array_pop($file_ext));
     // wp_ext2type doesn't have functionality to detect image type file (WordPress 3.6)
     // See http://core.trac.wordpress.org/ticket/25261 for patch submitted to address this - may get fixed?!
     // TODO: Check if patch accepted and incorporated in future release of WordPress
     $img_types = apply_filters('wflux_ext_img', array('jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico'));
     $file_nice = empty($file_nice) && in_array($info['ext'], $img_types) ? 'image' : $file_nice;
     $info['nicetype'] = $file_nice;
     $info['playable'] = in_array($file_nice, array('video', 'audio')) ? 'Y' : 'N';
     return $info;
 }
Example #16
0
/**
 * Return types from file extensions ex : input array( 'png', 'jpg', 'zip' ) => output : array( 'image', 'archive' ).
 *
 * @see wp_ext2type() function.
 *
 * @param array $ext_array
 *
 * @return array
 */
function fw_multi_ext2type($ext_array = array())
{
    $type_collector = array();
    foreach ($ext_array as $ext) {
        $type = wp_ext2type($ext);
        if (!in_array($type, $type_collector)) {
            $type_collector[] = $type;
        }
    }
    return $type_collector;
}
 function add_anchor_tag_gallery($link, $id, $size, $permalink, $icon, $text)
 {
     if (preg_match_all("/\\s+href\\s*=\\s*([\"\\']?)([^\\s\"\\'>]+)(\\1)/ims", $link, $result) !== false) {
         foreach ($result[0] as $value) {
             $exts = explode('.', substr($value, 0, -1));
             $ext = end($exts);
             $ext2type = wp_ext2type($ext);
             if ($ext2type === 'image') {
                 $titlename = ' title="' . get_the_title($id) . '"';
                 if ($this->effect === 'colorbox') {
                     // colorbox
                     $class_name = 'class="boxersandswipers"';
                     $link = str_replace('<a', '<a ' . $class_name . $titlename, $link);
                 } else {
                     if ($this->effect === 'slimbox') {
                         //slimbox
                         $rel_name = 'rel="boxersandswipers"';
                         $link = str_replace('<a', '<a ' . $rel_name . $titlename, $link);
                     } else {
                         if ($this->effect === 'nivolightbox') {
                             //nivolightbox
                             $rel_name = 'data-lightbox-gallery="boxersandswipers"';
                             $link = str_replace('<a', '<a ' . $rel_name . $titlename, $link);
                         } else {
                             if ($this->effect === 'imagelightbox') {
                                 //imagelightbox
                                 $rel_name = 'data-imagelightbox="boxersandswipers"';
                                 $link = str_replace('<a', '<a ' . $rel_name . $titlename, $link);
                             } else {
                                 if ($this->effect === 'photoswipe') {
                                     //photoswipe
                                     $class_name = 'class="boxersandswipers" ';
                                     $link = str_replace('<a', '<a ' . $class_name, $link);
                                 } else {
                                     if ($this->effect === 'swipebox') {
                                         //swipebox
                                         $rel_name = 'rel="boxers-and-swipers"';
                                         $class_name = ' class="boxersandswipers"';
                                         $link = str_replace('<a', '<a ' . $rel_name . $class_name . $titlename, $link);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $link;
 }
Example #18
0
/**
 * {@internal Missing Short Description}}
 *
 * @since 2.5.0
 *
 * @return mixed
 */
function wp_media_upload_handler()
{
    $errors = array();
    $id = 0;
    if (isset($_POST['html-upload']) && !empty($_FILES)) {
        check_admin_referer('media-form');
        // 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['src'];
        if (!empty($src) && !strpos($src, '://')) {
            $src = "http://{$src}";
        }
        if (isset($_POST['media_type']) && 'image' != $_POST['media_type']) {
            $title = esc_html(wp_unslash($_POST['title']));
            if (empty($title)) {
                $title = esc_html(basename($src));
            }
            if ($title && $src) {
                $html = "<a href='" . esc_url($src) . "'>{$title}</a>";
            }
            $type = 'file';
            if (($ext = preg_replace('/^.+?\\.([^.]+)$/', '$1', $src)) && ($ext_type = wp_ext2type($ext)) && ('audio' == $ext_type || 'video' == $ext_type)) {
                $type = $ext_type;
            }
            $html = apply_filters($type . '_send_to_editor_url', $html, esc_url_raw($src), $title);
        } else {
            $align = '';
            $alt = esc_attr(wp_unslash($_POST['alt']));
            if (isset($_POST['align'])) {
                $align = esc_attr(wp_unslash($_POST['align']));
                $class = " class='align{$align}'";
            }
            if (!empty($src)) {
                $html = "<img src='" . esc_url($src) . "' alt='{$alt}'{$class} />";
            }
            $html = apply_filters('image_send_to_editor_url', $html, esc_url_raw($src), $alt, $align);
        }
        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.');
        return media_upload_gallery();
    }
    if (isset($_GET['tab']) && $_GET['tab'] == 'type_url') {
        $type = 'image';
        if (isset($_GET['type']) && in_array($_GET['type'], array('video', 'audio', 'file'))) {
            $type = $_GET['type'];
        }
        return wp_iframe('media_upload_type_url_form', $type, $errors, $id);
    }
    return wp_iframe('media_upload_type_form', 'image', $errors, $id);
}
/**
 * {@internal Missing Short Description}}
 *
 * @since 1.4.0
 *
 * @return unknown
 */
function hacklogra_upyun_media_upload_handler()
{
    global $is_iphone;
    $errors = array();
    $id = 0;
    if (isset($_GET['code']) && isset($_GET['message']) && isset($_GET['url']) && isset($_GET['time'])) {
        $id = hacklogra_upyun::handle_form_api_upload($_REQUEST['post_id'], $post_data = array());
        unset($_FILES);
        if (is_wp_error($id)) {
            $errors['upload_error'] = $id;
            $id = false;
        }
    }
    if (!empty($_POST['insertonlybutton'])) {
        $src = $_POST['src'];
        if (!empty($src) && !strpos($src, '://')) {
            $src = "http://{$src}";
        }
        if (isset($_POST['media_type']) && 'image' != $_POST['media_type']) {
            $title = esc_html(stripslashes($_POST['title']));
            if (empty($title)) {
                $title = esc_html(basename($src));
            }
            if ($title && $src) {
                $html = "<a href='" . esc_url($src) . "'>{$title}</a>";
            }
            $type = 'file';
            if (($ext = preg_replace('/^.+?\\.([^.]+)$/', '$1', $src)) && ($ext_type = wp_ext2type($ext)) && ('audio' == $ext_type || 'video' == $ext_type)) {
                $type = $ext_type;
            }
            $html = apply_filters($type . '_send_to_editor_url', $html, esc_url_raw($src), $title);
        } else {
            $align = '';
            $alt = esc_attr(stripslashes($_POST['alt']));
            if (isset($_POST['align'])) {
                $align = esc_attr(stripslashes($_POST['align']));
                $class = " class='align{$align}'";
            }
            if (!empty($src)) {
                $html = "<img src='" . esc_url($src) . "' alt='{$alt}'{$class} />";
            }
            $html = apply_filters('image_send_to_editor_url', $html, esc_url_raw($src), $alt, $align);
        }
        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.');
        return media_upload_gallery();
    }
    if (isset($_GET['tab']) && $_GET['tab'] == 'type_url') {
        $type = 'image';
        if (isset($_GET['type']) && in_array($_GET['type'], array('video', 'audio', 'file'))) {
            $type = $_GET['type'];
        }
        return wp_iframe('media_upload_type_url_form', $type, $errors, $id);
    }
    if ($is_iphone) {
        return wp_iframe('media_upload_type_url_form', 'image', $errors, $id);
    } else {
        return wp_iframe(array('hacklogra_upyun', 'media_upload_type_form_upyun'), 'file', $errors, $id);
    }
}
Example #20
0
/**
 * Retrieve the icon for a MIME type.
 *
 * @since 2.1.0
 *
 * @param string $mime MIME type
 * @return string|bool
 */
function wp_mime_type_icon($mime = 0)
{
    if (!is_numeric($mime)) {
        $icon = wp_cache_get("mime_type_icon_{$mime}");
    }
    if (empty($icon)) {
        $post_id = 0;
        $post_mimes = array();
        if (is_numeric($mime)) {
            $mime = (int) $mime;
            if ($post =& get_post($mime)) {
                $post_id = (int) $post->ID;
                $ext = preg_replace('/^.+?\\.([^.]+)$/', '$1', $post->guid);
                if (!empty($ext)) {
                    $post_mimes[] = $ext;
                    if ($ext_type = wp_ext2type($ext)) {
                        $post_mimes[] = $ext_type;
                    }
                }
                $mime = $post->post_mime_type;
            } else {
                $mime = 0;
            }
        } else {
            $post_mimes[] = $mime;
        }
        $icon_files = wp_cache_get('icon_files');
        if (!is_array($icon_files)) {
            $icon_dir = apply_filters('icon_dir', ABSPATH . WPINC . '/images/crystal');
            $icon_dir_uri = apply_filters('icon_dir_uri', includes_url('images/crystal'));
            $dirs = apply_filters('icon_dirs', array($icon_dir => $icon_dir_uri));
            $icon_files = array();
            while ($dirs) {
                $dir = array_shift($keys = array_keys($dirs));
                $uri = array_shift($dirs);
                if ($dh = opendir($dir)) {
                    while (false !== ($file = readdir($dh))) {
                        $file = basename($file);
                        if (substr($file, 0, 1) == '.') {
                            continue;
                        }
                        if (!in_array(strtolower(substr($file, -4)), array('.png', '.gif', '.jpg'))) {
                            if (is_dir("{$dir}/{$file}")) {
                                $dirs["{$dir}/{$file}"] = "{$uri}/{$file}";
                            }
                            continue;
                        }
                        $icon_files["{$dir}/{$file}"] = "{$uri}/{$file}";
                    }
                    closedir($dh);
                }
            }
            wp_cache_set('icon_files', $icon_files, 600);
        }
        // Icon basename - extension = MIME wildcard
        foreach ($icon_files as $file => $uri) {
            $types[preg_replace('/^([^.]*).*$/', '$1', basename($file))] =& $icon_files[$file];
        }
        if (!empty($mime)) {
            $post_mimes[] = substr($mime, 0, strpos($mime, '/'));
            $post_mimes[] = substr($mime, strpos($mime, '/') + 1);
            $post_mimes[] = str_replace('/', '_', $mime);
        }
        $matches = wp_match_mime_types(array_keys($types), $post_mimes);
        $matches['default'] = array('default');
        foreach ($matches as $match => $wilds) {
            if (isset($types[$wilds[0]])) {
                $icon = $types[$wilds[0]];
                if (!is_numeric($mime)) {
                    wp_cache_set("mime_type_icon_{$mime}", $icon);
                }
                break;
            }
        }
    }
    return apply_filters('wp_mime_type_icon', $icon, $mime, $post_id);
    // Last arg is 0 if function pass mime type.
}
Example #21
0
 function exts($ext2type)
 {
     $mimes = wp_get_mime_types();
     foreach ($mimes as $ext => $mime) {
         if (strpos($ext, '|') != FALSE) {
             $extstmp = explode('|', $ext);
             foreach ($extstmp as $exttmp) {
                 if (wp_ext2type($exttmp) === $ext2type) {
                     $exts[] = $exttmp;
                 }
             }
         } else {
             if (wp_ext2type($ext) === $ext2type) {
                 $exts[] = $ext;
             }
         }
     }
     return $exts;
 }
Example #22
0
/**
 * Ajax handler for sending a link to the editor.
 *
 * Generates the HTML to send a non-image embed link to the editor.
 *
 * Backwards compatible with the following filters:
 * - file_send_to_editor_url
 * - audio_send_to_editor_url
 * - video_send_to_editor_url
 *
 * @since 3.5.0
 *
 * @global WP_Post  $post
 * @global WP_Embed $wp_embed
 */
function wp_ajax_send_link_to_editor()
{
    global $post, $wp_embed;
    check_ajax_referer('media-send-to-editor', 'nonce');
    if (!($src = wp_unslash($_POST['src']))) {
        wp_send_json_error();
    }
    if (!strpos($src, '://')) {
        $src = 'http://' . $src;
    }
    if (!($src = esc_url_raw($src))) {
        wp_send_json_error();
    }
    if (!($link_text = trim(wp_unslash($_POST['link_text'])))) {
        $link_text = wp_basename($src);
    }
    $post = get_post(isset($_POST['post_id']) ? $_POST['post_id'] : 0);
    // Ping WordPress for an embed.
    $check_embed = $wp_embed->run_shortcode('[embed]' . $src . '[/embed]');
    // Fallback that WordPress creates when no oEmbed was found.
    $fallback = $wp_embed->maybe_make_link($src);
    if ($check_embed !== $fallback) {
        // TinyMCE view for [embed] will parse this
        $html = '[embed]' . $src . '[/embed]';
    } elseif ($link_text) {
        $html = '<a href="' . esc_url($src) . '">' . $link_text . '</a>';
    } else {
        $html = '';
    }
    // Figure out what filter to run:
    $type = 'file';
    if (($ext = preg_replace('/^.+?\\.([^.]+)$/', '$1', $src)) && ($ext_type = wp_ext2type($ext)) && ('audio' == $ext_type || 'video' == $ext_type)) {
        $type = $ext_type;
    }
    /** This filter is documented in wp-admin/includes/media.php */
    $html = apply_filters($type . '_send_to_editor_url', $html, $src, $link_text);
    wp_send_json_success($html);
}
Example #23
0
/**
 * Retrieve the icon for a MIME type.
 *
 * @since 2.1.0
 *
 * @param string|int $mime MIME type or attachment ID.
 * @return string|false Icon, false otherwise.
 */
function wp_mime_type_icon($mime = 0)
{
    if (!is_numeric($mime)) {
        $icon = wp_cache_get("mime_type_icon_{$mime}");
    }
    $post_id = 0;
    if (empty($icon)) {
        $post_mimes = array();
        if (is_numeric($mime)) {
            $mime = (int) $mime;
            if ($post = get_post($mime)) {
                $post_id = (int) $post->ID;
                $file = get_attached_file($post_id);
                $ext = preg_replace('/^.+?\\.([^.]+)$/', '$1', $file);
                if (!empty($ext)) {
                    $post_mimes[] = $ext;
                    if ($ext_type = wp_ext2type($ext)) {
                        $post_mimes[] = $ext_type;
                    }
                }
                $mime = $post->post_mime_type;
            } else {
                $mime = 0;
            }
        } else {
            $post_mimes[] = $mime;
        }
        $icon_files = wp_cache_get('icon_files');
        if (!is_array($icon_files)) {
            /**
             * Filter the icon directory path.
             *
             * @since 2.0.0
             *
             * @param string $path Icon directory absolute path.
             */
            $icon_dir = apply_filters('icon_dir', ABSPATH . WPINC . '/images/media');
            /**
             * Filter the icon directory URI.
             *
             * @since 2.0.0
             *
             * @param string $uri Icon directory URI.
             */
            $icon_dir_uri = apply_filters('icon_dir_uri', includes_url('images/media'));
            /**
             * Filter the list of icon directory URIs.
             *
             * @since 2.5.0
             *
             * @param array $uris List of icon directory URIs.
             */
            $dirs = apply_filters('icon_dirs', array($icon_dir => $icon_dir_uri));
            $icon_files = array();
            while ($dirs) {
                $keys = array_keys($dirs);
                $dir = array_shift($keys);
                $uri = array_shift($dirs);
                if ($dh = opendir($dir)) {
                    while (false !== ($file = readdir($dh))) {
                        $file = basename($file);
                        if (substr($file, 0, 1) == '.') {
                            continue;
                        }
                        if (!in_array(strtolower(substr($file, -4)), array('.png', '.gif', '.jpg'))) {
                            if (is_dir("{$dir}/{$file}")) {
                                $dirs["{$dir}/{$file}"] = "{$uri}/{$file}";
                            }
                            continue;
                        }
                        $icon_files["{$dir}/{$file}"] = "{$uri}/{$file}";
                    }
                    closedir($dh);
                }
            }
            wp_cache_add('icon_files', $icon_files, 'default', 600);
        }
        $types = array();
        // Icon basename - extension = MIME wildcard.
        foreach ($icon_files as $file => $uri) {
            $types[preg_replace('/^([^.]*).*$/', '$1', basename($file))] =& $icon_files[$file];
        }
        if (!empty($mime)) {
            $post_mimes[] = substr($mime, 0, strpos($mime, '/'));
            $post_mimes[] = substr($mime, strpos($mime, '/') + 1);
            $post_mimes[] = str_replace('/', '_', $mime);
        }
        $matches = wp_match_mime_types(array_keys($types), $post_mimes);
        $matches['default'] = array('default');
        foreach ($matches as $match => $wilds) {
            foreach ($wilds as $wild) {
                if (!isset($types[$wild])) {
                    continue;
                }
                $icon = $types[$wild];
                if (!is_numeric($mime)) {
                    wp_cache_add("mime_type_icon_{$mime}", $icon);
                }
                break 2;
            }
        }
    }
    /**
     * Filter the mime type icon.
     *
     * @since 2.1.0
     *
     * @param string $icon    Path to the mime type icon.
     * @param string $mime    Mime type.
     * @param int    $post_id Attachment ID. Will equal 0 if the function passed
     *                        the mime type.
     */
    return apply_filters('wp_mime_type_icon', $icon, $mime, $post_id);
}
Example #24
0
/**
 * {@internal Missing Short Description}}
 *
 * @since 2.5.0
 *
 * @return mixed
 */
function wp_media_upload_handler()
{
    $errors = array();
    $id = 0;
    if (isset($_POST['html-upload']) && !empty($_FILES)) {
        check_admin_referer('media-form');
        // 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['src'];
        if (!empty($src) && !strpos($src, '://')) {
            $src = "http://{$src}";
        }
        if (isset($_POST['media_type']) && 'image' != $_POST['media_type']) {
            $title = esc_html(wp_unslash($_POST['title']));
            if (empty($title)) {
                $title = esc_html(basename($src));
            }
            if ($title && $src) {
                $html = "<a href='" . esc_url($src) . "'>{$title}</a>";
            }
            $type = 'file';
            if (($ext = preg_replace('/^.+?\\.([^.]+)$/', '$1', $src)) && ($ext_type = wp_ext2type($ext)) && ('audio' == $ext_type || 'video' == $ext_type)) {
                $type = $ext_type;
            }
            /**
             * Filter the URL sent to the editor for a specific media type.
             *
             * The dynamic portion of the hook name, $type, refers to the type
             * of media being sent.
             *
             * @since 3.3.0
             *
             * @param string $html  HTML markup sent to the editor.
             * @param string $src   Media source URL.
             * @param string $title Media title.
             */
            $html = apply_filters($type . '_send_to_editor_url', $html, esc_url_raw($src), $title);
        } else {
            $align = '';
            $alt = esc_attr(wp_unslash($_POST['alt']));
            if (isset($_POST['align'])) {
                $align = esc_attr(wp_unslash($_POST['align']));
                $class = " class='align{$align}'";
            }
            if (!empty($src)) {
                $html = "<img src='" . esc_url($src) . "' alt='{$alt}'{$class} />";
            }
            /**
             * Filter the image URL sent to the editor.
             *
             * @since 2.8.0
             *
             * @param string $html  HTML markup sent to the editor for an image.
             * @param string $src   Image source URL.
             * @param string $alt   Image alternate, or alt, text.
             * @param string $align The image alignment. Default 'alignnone'. Possible values include
             *                      'alignleft', 'aligncenter', 'alignright', 'alignnone'.
             */
            $html = apply_filters('image_send_to_editor_url', $html, esc_url_raw($src), $alt, $align);
        }
        return media_send_to_editor($html);
    }
    if (isset($_POST['save'])) {
        $errors['upload_notice'] = __('Saved.');
        return media_upload_gallery();
    } elseif (!empty($_POST)) {
        $return = media_upload_form_handler();
        if (is_string($return)) {
            return $return;
        }
        if (is_array($return)) {
            $errors = $return;
        }
    }
    if (isset($_GET['tab']) && $_GET['tab'] == 'type_url') {
        $type = 'image';
        if (isset($_GET['type']) && in_array($_GET['type'], array('video', 'audio', 'file'))) {
            $type = $_GET['type'];
        }
        return wp_iframe('media_upload_type_url_form', $type, $errors, $id);
    }
    return wp_iframe('media_upload_type_form', 'image', $errors, $id);
}
Example #25
-1
/**
 * Generates the HTML to send a non-image embed link to the editor.
 *
 * Backwards compatible with the following filters:
 * - file_send_to_editor_url
 * - audio_send_to_editor_url
 * - video_send_to_editor_url
 *
 * @since 3.5.0
 */
function wp_ajax_send_link_to_editor()
{
    check_ajax_referer('media-send-to-editor', 'nonce');
    if (!($src = wp_unslash($_POST['src']))) {
        wp_send_json_error();
    }
    if (!strpos($src, '://')) {
        $src = 'http://' . $src;
    }
    if (!($src = esc_url_raw($src))) {
        wp_send_json_error();
    }
    if (!($title = trim(wp_unslash($_POST['title'])))) {
        $title = wp_basename($src);
    }
    $html = '';
    if ($title) {
        $html = '<a href="' . esc_url($src) . '">' . $title . '</a>';
    }
    // Figure out what filter to run:
    $type = 'file';
    if (($ext = preg_replace('/^.+?\\.([^.]+)$/', '$1', $src)) && ($ext_type = wp_ext2type($ext)) && ('audio' == $ext_type || 'video' == $ext_type)) {
        $type = $ext_type;
    }
    /** This filter is documented in wp-admin/includes/media.php */
    $html = apply_filters($type . '_send_to_editor_url', $html, $src, $title);
    wp_send_json_success($html);
}