HEX
Server: Apache
System: Linux web15f74.uni5.net 5.4.282-1.el8.elrepo.x86_64 #1 SMP Mon Aug 19 18:33:22 EDT 2024 x86_64
User: lucendi (859622)
PHP: 7.4.33
Disabled: apache_child_terminate,c99_buff_prepare,c99_sess_put,dl,exec,leak,link,myshellexec,openlog,passthru,pclose,pcntl_exec,php_check_syntax,php_strip_whitespace,popen,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,show_source,symlink,system,socket_listen,socket_create_listen,putenv
Upload Files
File: /home/lucendi/www/wp-content/plugins/official-facebook-pixel/FacebookAds/Object/AdImage.php
<?php
 /*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 * All rights reserved.
 *
 * This source code is licensed under the license found in the
 * LICENSE file in the root directory of this source tree.
 */

namespace FacebookPixelPlugin\FacebookAds\Object;

use FacebookPixelPlugin\FacebookAds\ApiRequest;
use FacebookPixelPlugin\FacebookAds\Cursor;
use FacebookPixelPlugin\FacebookAds\Http\RequestInterface;
use FacebookPixelPlugin\FacebookAds\TypeChecker;
use FacebookPixelPlugin\FacebookAds\Object\Fields\AdImageFields;
use FacebookPixelPlugin\FacebookAds\Object\Values\AdImageStatusValues;

/**
 * This class is auto-generated.
 *
 * For any issues or feature requests related to this class, please let us know
 * on github and we'll fix in our codegen framework. We'll not be able to accept
 * pull request for this class.
 *
 */

class AdImage extends AbstractCrudObject {

  /**
   * @deprecated getEndpoint function is deprecated
   */
  protected function getEndpoint() {
    return 'adimages';
  }

  /**
   * @return AdImageFields
   */
  public static function getFieldsEnum() {
    return AdImageFields::getInstance();
  }

  protected static function getReferencedEnums() {
    $ref_enums = array();
    $ref_enums['Status'] = AdImageStatusValues::getInstance()->getValues();
    return $ref_enums;
  }


  public function getSelf(array $fields = array(), array $params = array(), $pending = false) {
    $this->assureId();

    $param_types = array(
    );
    $enums = array(
    );

    $request = new ApiRequest(
      $this->api,
      $this->data['id'],
      RequestInterface::METHOD_GET,
      '/',
      new AdImage(),
      'NODE',
      AdImage::getFieldsEnum()->getValues(),
      new TypeChecker($param_types, $enums)
    );
    $request->addParams($params);
    $request->addFields($fields);
    return $pending ? $request : $request->execute();
  }

  /**
   * Uploads images from a zip file and returns a cursor of results
   *
   * @param string $file_path
   * @param string $account_id
   * @param array $params
   * @param Api $api
   * @return array
   */
  public static function createFromZip(
    $file_path, $account_id, array $params = array(), ?Api $api = null) {

    $image = new AdImage(null, $account_id, $api);
    $image->{AdImageFields::FILENAME} = $file_path;
    return $image->arrayFromZip($params);
  }

  /**
   * @return string
   */
  protected function getNodePath() {
    return '/'.$this->assureParentId().'/'.$this->getEndpoint();
  }

  /**
   * Create function for the object.
   *
   * @param array $params Additional parameters to include in the request
   * @return $this
   * @throws \Exception
   * @throws \RuntimeException
   */
  public function create(array $params = array()) {
    if ($this->data[static::FIELD_ID]) {
      throw new \Exception("Object has already an ID");
    }

    if ($this->isZipFile($this->data[AdImageFields::FILENAME])) {
      throw new \RuntimeException(
        "use AdImage::createFromZip to create zip files");
    }

    $data = $this->exportData();
    $filename = $data[AdImageFields::FILENAME];
    unset($data[AdImageFields::FILENAME]);
    $params = array_merge($data, $params);

    $request = $this->getApi()->prepareRequest(
      '/'.$this->assureParentId().'/'.$this->getEndpoint(),
      RequestInterface::METHOD_POST,
      $params
    );

    $request->getFileParams()->offsetSet(AdImageFields::FILENAME, $filename);
    $response = $this->getApi()->executeRequest($request);

    $this->clearHistory();
    $content = $response->getContent();
    $data = $content['images'][basename($this->{AdImageFields::FILENAME})];

    $this->data[AdImageFields::HASH] = $data[AdImageFields::HASH];

    $this->data[static::FIELD_ID]
      = substr($this->getParentId(), 4).':'.$this->data[AdImageFields::HASH];

    return $this;
  }

  /**
   * Uploads images from a zip file and returns a cursor of results
   *
   * @param array $params
   * @return array
   * @throws \RuntimeException
   */
  protected function arrayFromZip($params = array()) {
    if (!$this->isZipFile($this->data[AdImageFields::FILENAME])) {
      throw new \RuntimeException(
        $this->data[AdImageFields::FILENAME]." doesn't resolve to a zip file");
    }

    $data = $this->exportData();
    $filename = $data[AdImageFields::FILENAME];
    unset($data[AdImageFields::FILENAME]);
    $params = array_merge($data, $params);

    $request = $this->getApi()->prepareRequest(
      '/'.$this->assureParentId().'/'.$this->getEndpoint(),
      RequestInterface::METHOD_POST,
      $params
    );

    $request->getFileParams()->offsetSet(AdImageFields::FILENAME, $filename);
    $response = $this->getApi()->executeRequest($request);

    $result = array();
    $content = $response->getContent();
    foreach ($content['images'] as $image) {
      $adimage = new AdImage(
        substr($this->getParentId(), 4).':'.$image[AdImageFields::HASH],
        $this->getParentId(),
        $this->getApi());

      $adimage->{AdImageFields::HASH} = $image[AdImageFields::HASH];

      $result[] = $adimage;
    }

    return $result;
  }

  /**
   * Checks if a given path is a zip file
   *
   * @param string $file_path
   * @return bool
   */
  protected function isZipFile($file_path) {
    $finfo = finfo_open(FILEINFO_MIME_TYPE);
    $file_mime_type = finfo_file($finfo, $file_path);
    return $file_mime_type == 'application/zip' ||
      $file_mime_type == 'multipart/x-zip';
  }

  /**
   * Read object data from the graph
   *
   * @param string[] $fields Fields to request
   * @param array $params Additional request parameters
   * @return $this
   */
  public function read(array $fields = array(), array $params = array()) {
    $fields = implode(',', $fields ?: static::getDefaultReadFields());
    if ($fields) {
      $params['fields'] = $fields;
    }
    $params['hashes'] = array(explode(':', $this->assureId())[1]);

    $response = $this->getApi()->call(
      $this->getNodePath(),
      RequestInterface::METHOD_GET,
      $params);

    $content = $response->getContent();
    $data = $content['data'];
    if ($data) {
      $this->setDataWithoutValidation((array) $data[0]);
    }

    $this->clearHistory();

    return $this;
  }

  /**
   * Delete this object from the graph
   *
   * @param array $params
   * @return void
   * @throws \Exception
   */
  public function deleteSelf(array $params = array()) {
    if (!$this->data[AdImageFields::HASH]) {
      throw new \Exception("AdImage hash is required to delete");
    }

    $params
      = array_merge($params, array('hash' => $this->data[AdImageFields::HASH]));

    $this->getApi()->call(
      $this->getNodePath(),
      RequestInterface::METHOD_DELETE,
      $params
    );
  }
}