コード例 #1
0
 /**
  * Modifies lead details for uploaded files
  * The goal is to replace local URLs with remote ones within WordPress administration
  *
  * @link   https://www.gravityhelp.com/documentation/article/gform_entry_field_value/ Gravity Forms hook documentation
  * @param  array $value  Gravity Forms form
  * @param  array $field  Gravity Forms form
  * @param  array $entry  Gravity Forms form
  * @param  array $form   Gravity Forms entry
  * @return void
  */
 public function __modifyLeadDetails($value, $field, $entry, $form)
 {
     if ($field->type != 'fileupload') {
         return $value;
     }
     $config = Config::getInstance();
     $local_base_url = $config->get('local.base_url');
     $remote_base_url = Utils::getMediaBaseUrl();
     $file_url = isset($entry[$field->id]) && $entry[$field->id] ? $entry[$field->id] : null;
     if ($file_url) {
         $file_url = str_replace($local_base_url, $remote_base_url, $file_url);
         $value = preg_replace("/<a(.*)href='([^']*)'(.*)>/", '<a$1href="' . $file_url . '"$3>', $value);
     }
     return $value;
 }
コード例 #2
0
 /**
  * Used to push a local file to a remote filesystem
  * Used with the custom 'po_bebop_media.push_file_to_remote' hook
  *
  * @param  string $file Absolute or partial path to file, relative to uploads directory
  * @return void
  */
 public function __pushFileToRemote($file)
 {
     // Remove uploads base path so that we end up
     // with the "/YYYY/MM/filename.extension" format
     $path = str_replace(Config::getInstance()->get('local.base_dir'), '', Utils::getCleanAWSS3Key($file));
     // Push local file to remote filesystem
     $fs = Filesystem::getInstance();
     if ($fs->localHas($path)) {
         $fs->push($path);
     }
     // This is a hook function, so we should return $file
     return $file;
 }