Regenerates an image's thumbnails and re-uploads them to the storage service.

@param $postId
@return bool|string
189166
public function regenerateFile($postId) {
	    @set_time_limit(120);

	    $fullsizepath = get_attached_file( $postId );
	    if (!file_exists($fullsizepath)) {
	        if (function_exists('_load_image_to_edit_path')) {
                $fullsizepath = _load_image_to_edit_path($postId);
            } else {
	            Logger::warning("The function '_load_image_to_edit_path' does not exist, using internal implementation.");
	            $fullsizepath = $this->loadImageToEditPath($postId);
                Logger::warning("$postId => $fullsizepath");
            }
	    }

	    if (!file_exists($fullsizepath)) {
		    if (strpos($fullsizepath, 'http') === 0) {
			    $path = parse_url($fullsizepath, PHP_URL_PATH);
			    $pathParts = explode('/', $path);
			    $file = array_pop($pathParts);

			    $uploadDirInfo = wp_upload_dir();

			    $filepath = $uploadDirInfo['path'].'/'.$file;
			    Logger::startTiming("Downloading fullsize '$fullsizepath' to '$filepath'");
			    file_put_contents($filepath, file_get_contents($fullsizepath));
			    Logger::endTiming("Finished downloading fullsize '$fullsizepath' to '$filepath'");

			    if (!file_exists($filepath)) {
			        return "File '$fullsizepath' could not be downloaded.";
                }

			    $fullsizepath = $filepath;
		    } else {
		        return "Local file '$fullsizepath' does not exist and is not a URL.";
		    }
	    }

	    Logger::startTiming('Regenerating metadata ...', ['id' => $postId]);
	    $metadata = wp_generate_attachment_metadata( $postId, $fullsizepath );
	    Logger::endTiming('Regenerating metadata ...', ['id' => $postId]);

	    wp_update_attachment_metadata($postId, $metadata);

	    return true;
    }
1081464
public function callbackAddImageToIndex($fileId)
    {
        $image = Yii::$app->storage->addImage($fileId);
        
        if (!$image) {
            return $this->sendError("Unable to create image from given file Id.");
        }

        Yii::$app->db->createCommand()->insert($this->refTableName, $this->prepareInsertFields([
            $this->imageIdFieldName => (int) $image->id,
            $this->refFieldName => (int) $this->itemId,
        ]))->execute();

        return $this->getImageArray($image->id);
    }
1250053
public function image($mediaid = '')
    {
        $msg = array(
            'ToUserName'   => $this->getRevFrom(),
            'FromUserName' => $this->getRevTo(),
            'MsgType'      => self::MSGTYPE_IMAGE,
            'Image'        => array('MediaId' => $mediaid),
            'CreateTime'   => time(),
        );
        $this->Message($msg);
        return $this;
    }
529646
public function addAttachmentFromUrl(string $url, int $post_id)
    {
        require_once ABSPATH.'wp-admin/includes/file.php';
        require_once ABSPATH.'wp-admin/includes/media.php';
        require_once ABSPATH.'wp-admin/includes/image.php';

        if (!$url || !$post_id) { // Must have.
            return $this->c::error('bad_request', __('Bad request.', 'wp-sharks-core'));
        }
        $mime = wp_check_filetype(basename($url));

        if (empty($mime['type']) || empty($mime['ext'])) {
            return $this->c::error('unknown_mime_type', __('Unknown MIME type.', 'wp-sharks-core'));
            //
        } elseif (is_wp_error($tmp_name = download_url($url))) {
            return $this->s::wpErrorConvert($tmp_name);
        }
        if (!preg_match('/\.'.$this->c::escRegex($mime['ext']).'$/ui', $tmp_name)) {
            rename($tmp_name, $tmp_name .= '.'.$mime['ext']);
        }
        $file = [
            'tmp_name' => $tmp_name,
            'type'     => $mime['type'],
            'name'     => $this->c::uniqueId('', false).'.'.$mime['ext'],
        ];
        if (is_wp_error($attachment_id = media_handle_sideload($file, $post_id))) {
            @unlink($tmp_name); // Ditch temporary file.
            return $this->s::wpErrorConvert($attachment_id);
        }
        return $attachment_id;
    }
1056551
public function get_from_user_id_and_post_ids(int $userid, array $postids) {
        $alias = $this->get_table_alias();
        [$postidinsql, $params] = $this->get_db()->get_in_or_equal($postids);
        $params[] = $userid;

        $wheresql = "{$alias}.postid {$postidinsql}";
        $wheresql .= " AND {$alias}.userid = ?";
        $sql = $this->generate_get_records_sql($wheresql);
        $records = $this->get_db()->get_records_sql($sql, $params);

        return $this->transform_db_records_to_entities($records);
    }
1185190
private function getPost($postid)
    {
        $post = $this->getDoctrine()->getManager()->getRepository('VeonikBlogBundle:AbstractPost')
            ->createQueryBuilder('p')
            ->addSelect('c')
            ->leftJoin('p.comments', 'c')
            ->where('p.id = :post_id')
            ->setParameters(array(
                'post_id' => $postid
            ))
            ->getQuery()
            ->getOneOrNullResult();

        if (!$post) {
            throw $this->createNotFoundException('Unable to locate Post');
        }

        return $post;
    }
418170
private function maybe_do_post_thumbnail( $field, $post ) {
		if ( 'post_thumbnail' == $field || false !== strpos( $field, 'post_thumbnail.' ) ) {
			$size = 'thumbnail';
			if ( false !== ( $pos = strpos( $field, '.' ) ) ) {
				$size = substr( $field, $pos + 1);
			}

			$id = get_post_thumbnail_id( $post->ID );
			if ( 0 < absint( $id ) ) {
				$img = wp_get_attachment_image_src( $id, $size);
				if ( is_array( $img ) ) {
					return $img[0];

				}

			}

			return 0;

		}

		return false;



	}
631904
public function select($id = null)
    {
        if ($id instanceof UploadedFile) {
            if (!$id->isValid()) {
                throw new \InvalidArgumentException('Upload was not successful');
            }

            $newFile = $id->move($this->targetDirectory, $this->generateTargetFilename($id));

            $selection = new StorageSelection(
                new \SplFileInfo($newFile),
                $this->targetDirectory.'/'.$newFile->getFilename(),
                $id->getClientOriginalName());

            return $selection;
        }

        return parent::select($id);
    }
609856
public function outputColumnContent($post_id)
    {
        $meta = get_post_meta($post_id, $this->id, true);

        echo wp_get_attachment_image($meta, [100, 100]);
    }
474347
public function clearCache($postId)
    {
        if (wp_is_post_revision($postId) || get_post_status($postId) != 'publish') {
            return false;
        }

        wp_cache_delete($postId, $this->keyGroup);
        return true;
    }
674490
public static function findByID($postID, $postTypeSlug = '')
    {
        $postTypeSlug = ($postTypeSlug ? $postTypeSlug : PostType::getSlug());
        $postObj = (new Post())->setTable($postTypeSlug);
        $post = $postObj
            ->where('postID', $postID)
            ->with($postObj->getDefaultRelations(getPostType($postTypeSlug)))
            ->first();
        return $post;
    }
54192
public function processImageMeta($meta, $postID) {
		if (!$this->enabled()) {
			return $meta;
		}

        if (apply_filters('ilab_rekognition_enabled', false)) {
		    if (apply_filters('ilab_rekognition_detects_faces', false)) {
		        return $meta;
            }
        }

		if (!isset($meta['s3'])) {
			Logger::warning( "Post $postID is  missing 's3' metadata.", $meta);
			return $meta;
		}

		$url = $this->buildImgixImage($postID, 'full',['fm' => 'json','faces'=>1],false,null,null,$meta);
		if ($url && is_array($url)) {
			$jsonString = file_get_contents($url[0]);
			if (!empty($jsonString)) {
				$data = json_decode($jsonString, true);

				$pw = arrayPath($data,'PixelWidth',0);
				$ph = arrayPath($data,'PixelHeight',0);

				if (!empty($pw) && !empty($ph)) {
				    $facesData = arrayPath($data,'Faces',[]);
					$faces = [];
				    foreach($facesData as $face) {
					    $faces[] = [
						    'BoundingBox' => [
							    'Left' => floatval($face['bounds']['x']) / floatval($pw),
							    'Top' => floatval($face['bounds']['y']) / floatval($ph),
							    'Width' => floatval($face['bounds']['width']) / floatval($pw),
							    'Height' => floatval($face['bounds']['height']) / floatval($ph),
						    ]
					    ];
                    }

					if (count($faces)>0) {
						$meta['faces'] = $faces;
					}
                }
            }
		}

		return $meta;
	}
660629
public function update($fileId, $revisionId, Drive_Revision $postBody, $optParams = array())
  {
    $params = array('fileId' => $fileId, 'revisionId' => $revisionId, 'postBody' => $postBody);
    $params = array_merge($params, $optParams);
    return $this->call('update', array($params), "Drive_Revision");
  }
1100644
public function render($postId)
    {
        $meta = $this->metabox->getMeta($postId);

        $this->getField()->getManager()->renderPreview(
            Arr::get($meta, $this->path)
        );
    }
1236016
public function getComCodes($postId)
    {
        try {
            return $this->bizImpl->getComCodes($postId);
        } catch (\Throwable $throwable) {
            throw new SystemException($throwable->getMessage());
        }
    }
83033
public function saveBrokenLinks($data, $postId = null)
    {
        global $wpdb;

        $inserted = array();
        $tableName = \BrokenLinkDetector\App::$dbTable;

        if (is_numeric($postId)) {
            $wpdb->delete($tableName, array('post_id' => $postId), array('%d'));
        } elseif (is_null($postId)) {
            $wpdb->query("TRUNCATE $tableName");
        }

        if(!empty($data) && is_array($data)) {
            foreach ($data as $item) {
                $exists = $wpdb->get_row("SELECT id FROM $tableName WHERE post_id = {$item['post_id']} AND url = '{$item['url']}'");
                
                if ($exists) {
                    continue;
                }
                
                $inserted[] = $wpdb->insert($tableName, array(
                    'post_id' => $item['post_id'],
                    'url' => $item['url']
                ), array('%d', '%s'));
            }
        }
        
        return true;
    }
975415
function getCommentCount($postId)
    {
        $params = array(1, $this->username, $this->password, $postId);

        return $this->sendRequest('wp.getCommentCount', $params);
    }