当前位置: 首页>>代码示例>>PHP>>正文


PHP Attachments::get_mime_type方法代码示例

本文整理汇总了PHP中Attachments::get_mime_type方法的典型用法代码示例。如果您正苦于以下问题:PHP Attachments::get_mime_type方法的具体用法?PHP Attachments::get_mime_type怎么用?PHP Attachments::get_mime_type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Attachments的用法示例。


在下文中一共展示了Attachments::get_mime_type方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: array

 /**
  * Facilitates searching for Attachments
  *
  * @since 3.3
  */
 function __construct($query = null, $params = array())
 {
     parent::__construct();
     $this->apply_init_filters();
     $defaults = array('attachment_id' => null, 'instance' => 'attachments', 'post_type' => null, 'post_id' => null, 'post_status' => 'publish', 'fields' => null, 'filetype' => null);
     $query = is_null($query) ? null : sanitize_text_field($query);
     $params = array_merge($defaults, $params);
     // sanitize parameters
     $params['attachment_id'] = is_null($params['attachment_id']) ? null : intval($params['attachment_id']);
     $params['instance'] = !is_string($params['instance']) ? 'attachments' : sanitize_text_field($params['instance']);
     $params['post_type'] = is_null($params['post_type']) ? 'any' : sanitize_text_field($params['post_type']);
     $params['post_id'] = is_null($params['post_id']) ? null : intval($params['post_id']);
     $params['post_status'] = sanitize_text_field($params['post_status']);
     if (is_string($params['fields'])) {
         $params['fields'] = array($params['fields']);
     }
     // we always want an array
     if (is_string($params['filetype'])) {
         $params['filetype'] = array($params['filetype']);
     }
     // we always want an array
     // since we have an array for our fields, we need to loop through and sanitize
     for ($i = 0; $i < count($params['fields']); $i++) {
         $params['fields'][$i] = sanitize_text_field($params['fields'][$i]);
     }
     // prepare our search args
     $args = array('nopaging' => true, 'post_status' => $params['post_status'], 'meta_query' => array(array('key' => parent::get_meta_key(), 'value' => $query, 'compare' => 'LIKE')));
     // append any applicable parameters that got passed to the original method call
     if ($params['post_type']) {
         $args['post_type'] = $params['post_type'];
     }
     if ($params['post_id']) {
         $args['post__in'] = array($params['post_id']);
     }
     // avoid using 'p' or 'page_id'
     // we haven't utilized all parameters yet because they're meta-value based so we need to
     // do some parsing on our end to validate the returned results
     $possible_posts = new WP_Query($args);
     $potential_attachments = false;
     // stores valid attachments as restrictions are added
     if ($possible_posts->found_posts) {
         // we have results from the reliminary search, we need to quantify them
         while ($possible_posts->have_posts()) {
             $possible_posts->next_post();
             $possible_post_ids[] = $possible_posts->post->ID;
         }
         // now that we have our possible post IDs we can grab all Attachments for all of those posts
         foreach ($possible_post_ids as $possible_post_id) {
             $possible_attachments = parent::get_attachments($params['instance'], $possible_post_id);
             foreach ($possible_attachments as $possible_attachment) {
                 $potential_attachments[] = $possible_attachment;
             }
         }
     }
     // if there aren't even any potential attachments, we'll just short circuit
     if (!$potential_attachments) {
         return;
     }
     // first we need to make sure that our query matches each attachment
     // we need to do this because the LIKE query returned the entire meta record,
     // not necessarily tied to any specific Attachment
     $total_potentials = count($potential_attachments);
     for ($i = 0; $i < $total_potentials; $i++) {
         $valid = false;
         // if we need to limit our search to specific fields, we'll do that here
         if ($params['fields']) {
             // we only want to check certain fields
             foreach ($params['fields'] as $field) {
                 if (isset($potential_attachments[$i]->fields->{$field})) {
                     // does the field exist?
                     if (empty($query) || strpos(strtolower($potential_attachments[$i]->fields->{$field}), strtolower($query)) !== false) {
                         // does the value match?
                         if (is_null($params['filetype']) || !is_null($params['filetype']) && in_array(parent::get_mime_type($potential_attachments[$i]->id), $params['filetype'])) {
                             $valid = true;
                         }
                     }
                 }
             }
         } else {
             // we want to check all fields
             if (isset($potential_attachments[$i]->fields)) {
                 foreach ($potential_attachments[$i]->fields as $field_name => $field_value) {
                     if (empty($query) || strpos(strtolower($field_value), strtolower($query)) !== false) {
                         if (is_null($params['filetype']) || !is_null($params['filetype']) && in_array(parent::get_mime_type($potential_attachments[$i]->id), $params['filetype'])) {
                             $valid = true;
                         }
                     }
                 }
             }
         }
         if (!$valid) {
             unset($potential_attachments[$i]);
         }
         // now our potentials have been limited to each match the query based on any field
     }
//.........这里部分代码省略.........
开发者ID:santikrass,项目名称:apache,代码行数:101,代码来源:class.attachments.search.php


注:本文中的Attachments::get_mime_type方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。