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


PHP ImageHelper::IScan方法代码示例

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


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

示例1: updateImageName_callback

 public static function updateImageName_callback()
 {
     global $wpdb;
     $postID = (int) $_POST['post_id'];
     $name = trim($_POST['meta_value']);
     $iname = preg_replace('/(\\s{1,})/', '-', $name);
     $img_meta = get_post_meta($postID, '_wp_attachment_metadata', TRUE);
     $linkold = $img_meta['file'];
     $response = new stdClass();
     $response->updated = FALSE;
     $response->msg = __('There is a problem when update image name', 'wp-meta-seo');
     $upload_dirs = wp_upload_dir();
     $upload_dir = $upload_dirs['basedir'];
     $oldpart = ImageHelper::IGetPart($linkold);
     $old_name = $oldpart->name;
     if ($name !== "") {
         if (file_exists($upload_dir . "/" . $linkold)) {
             $newFileName = $oldpart->base_path . $iname . $oldpart->ext;
             #if ((!file_exists($upload_dir . "/" . $newFileName)) && $check==0) {
             if (!file_exists($upload_dir . "/" . $newFileName)) {
                 if (rename($upload_dir . "/" . $linkold, $upload_dir . "/" . $newFileName)) {
                     $post_title = get_the_title($postID);
                     $data_post = array('ID' => $postID, 'post_name' => $name);
                     //if (wp_update_post($data_post)) {
                     $where = array('ID' => $postID);
                     $guid = $upload_dirs['baseurl'] . "/" . $newFileName;
                     if (!$post_title) {
                         $id = $wpdb->update($wpdb->posts, array('guid' => $guid, 'post_title' => $name, 'post_name' => strtolower($iname)), $where);
                     } else {
                         $id = $wpdb->update($wpdb->posts, array('guid' => $guid), $where);
                     }
                     if ($id) {
                         $attached_metadata = get_post_meta($postID, "_wp_attachment_metadata", true);
                         $attached_metadata["file"] = $newFileName;
                         $images_to_rename = array($oldpart->name . $oldpart->ext => $iname . $oldpart->ext);
                         $old_path = $upload_dir . "/" . $linkold;
                         foreach ($attached_metadata['sizes'] as &$clone) {
                             $clone_file_new = ImageHelper::IReplace($iname, $clone['file']);
                             $clone_path = $upload_dir . '/' . $oldpart->base_path . $clone['file'];
                             $clone_path_new = $upload_dir . '/' . $oldpart->base_path . $clone_file_new;
                             if (@rename($clone_path, $clone_path_new)) {
                                 $images_to_rename[$clone['file']] = $clone_file_new;
                                 $clone['file'] = $clone_file_new;
                             }
                         }
                         /** Update source of this image or its clones in post contains them **/
                         $query = "SELECT `ID`,`post_title`,`post_content`,`post_type`,`post_date`\n\t\t\t\t\t\t\t\t\tFROM {$wpdb->posts}\n\t\t\t\t\t\t\t\t\tWHERE (`post_type` = 'post' or `post_type` = 'page')\n\t\t\t\t\t\t\t\t\tAND `post_content` <> ''\n\t\t\t\t\t\t\t\t\tAND `post_content` LIKE '%<img%>%' \n\t\t\t\t\t\t\t\t\tORDER BY ID";
                         $posts = $wpdb->get_results($query);
                         $imgs = array($old_name . $oldpart->ext => $postID);
                         $posts_contain_img = array();
                         foreach ($posts as $post) {
                             $ifound = ImageHelper::IScan($imgs, $post->post_content);
                             if (count($ifound) > 0) {
                                 $posts_contain_img[] = $post->ID;
                             }
                         }
                         foreach ($posts_contain_img as $id) {
                             if ($post = get_post($id)) {
                                 foreach ($images_to_rename as $src_before => $src_after) {
                                     $src_before = '/' . $src_before;
                                     $src_after = '/' . $src_after;
                                     $post->post_content = str_replace($src_before, $src_after, $post->post_content);
                                 }
                                 wp_update_post(array('ID' => $post->ID, 'post_content' => $post->post_content));
                                 unset($post, $posts_contain_img);
                                 //---------------------------------
                             }
                         }
                         /*****************************************************/
                         /** Update Image registered to Attachment sizes on Add media page**/
                         $sizeOptional = get_post_meta($postID, '_metaseo_sizes_optional', true);
                         $newOptional = array();
                         if (!empty($sizeOptional) && is_array($sizeOptional)) {
                             foreach ($sizeOptional as $key => $detail) {
                                 $pattern = '/^' . strtolower($old_name) . '(-metaseo\\d+)$/';
                                 $key = preg_replace($pattern, strtolower($iname) . '${1}', $key);
                                 $detail['url'] = ImageHelper::IReplace($iname, $detail['url']);
                                 $newOptional[$key] = $detail;
                             }
                             update_post_meta($postID, '_metaseo_sizes_optional', $newOptional);
                             unset($sizeOptional, $newOptional);
                         }
                         /****************************************************/
                         //Need to update optimization info of this image
                         ImageHelper::IScanPosts(array($iname . $oldpart->ext => $postID), true);
                         update_post_meta($postID, '_wp_attached_file', $newFileName);
                         update_post_meta($postID, '_wp_attachment_metadata', $attached_metadata);
                         $response->updated = true;
                         $response->msg = __('Image name was changed', 'wp-meta-seo');
                     } else {
                         $response->iname = $old_name;
                         $response->msg = __('There is a problem when update image name', 'wp-meta-seo');
                     }
                 }
             } else {
                 $response->msg = __('Name is existing', 'wp-meta-seo');
                 $response->iname = $old_name;
             }
         } else {
             $response->iname = $old_name;
//.........这里部分代码省略.........
开发者ID:rainevincent,项目名称:wp-meta-seo,代码行数:101,代码来源:class.metaseo-image-list-table.php


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