Creates a Attachment resource
@param AttachmentCreationInformation $information
@return Attachment
177657
public function add(AttachmentCreationInformation $information)
    {
        $attachment = new Attachment($this->getContext(),$this->getResourcePath());
        $qry = new InvokePostMethodQuery(
            $this->getResourcePath(),
            "add",
            array("FileName" =>rawurlencode($information->FileName)),
            $information->ContentStream);
        $this->getContext()->addQuery($qry,$attachment);
        $this->addChild($attachment);
        return $attachment;
    }
252114
public function addAttachment($filename, $data, $mime = null)
    {
        $data = file_get_contents($data);
        $this->attachments[] = array($filename, $data, $mime);
        return $this;
    }
1369019
public function create($data, $kycDocumentId = null)
    {
        if (isset($kycDocumentId)) {
            return $this->client()->put($data, 'kyc-documents/{id}', ['id' => $kycDocumentId]);
        }

        return $this->client()->post($data, 'kyc-documents');
    }
580986
protected function createTable(Infoset $info) {
		$table = [];
		
		if ($info instanceof InfosetTable) {
			if (($headRow = $info->getHeadContent()) !== null) {
				$table[] = $headRow;
			}
		}
		
		foreach ($info as $row) {
			if (! is_array($row) && ! $row instanceof Traversable) {
				throw new InvalidContent('Table row content must be an array or a Traversable implementation');
			}
			
			$cols = [];
			
			foreach ($row as $content) {
				if ($content instanceof Infoset) {
					$content = $this->createContent($content);
				}
				
				if ($info->isContentBbCodes()) {
					$content = $this->bbCodesHandle($content);
				}
				
				$cols[] = $content;
			}
			
//			if ($row instanceof Row && $row->isMarked()) {
//				$cols['_class_'] = $row->getMark();
//			}
			
			$table[] = $cols;
		}
		
		$title = $info->getTitle();
		
		return $this->table($table, $title ?: $title);
	}
741565
public function getMetaData(MediaInformation $information)
    {
        $subdef = $information->getResource();
        $record = $subdef->get_record();
        $thumbnail = $record->get_thumbnail();
        $request = $information->getResourceRequest();
        $baseUrl = $request->getSchemeAndHttpHost() . $request->getBasePath();


        $ogMetaData = [];
        $embedMedia = [];
        $oembedMetaData = [];

        $substitutionPath = sprintf(
            '/assets/common/images/icons/substitution/%s.png',
            str_replace('/', '_', $record->getMimeType())
        );

        $resourceUrl = $information->getUrl();

        $embedMedia['title'] = $record->get_title();
        $embedMedia['url'] = $resourceUrl;

        switch ($record->getType()) {
            case 'video':
                $ogMetaData['og:type'] = 'video.other';
                $ogMetaData['og:image'] = $baseUrl . $thumbnail->get_url();
                $ogMetaData['og:image:width'] = $thumbnail->get_width();
                $ogMetaData['og:image:height'] = $thumbnail->get_height();

                $coverUrl = $baseUrl . $thumbnail->get_url();

                $embedConfig = $this->getEmbedConfiguration();

                // if user config has custom subdef specified:
                if (array_key_exists('video', $embedConfig)) {
                    if (array_key_exists('coverSubdef', $embedConfig['video'])) {
                        $customCoverName = $embedConfig['video']['coverSubdef'];
                        try {
                            $customCover = $record->get_subdef($customCoverName);
                            $coverUrl = $baseUrl.$customCover->get_url();
                        } catch (\Exception $e) {
                            // no existing custom cover
                        }
                    }
                }

                $embedMedia['coverUrl'] = $coverUrl;
                $embedMedia['source'] = [];
                $embedMedia['source'][] = [
                    'url'  => $resourceUrl,
                    'type' => $subdef->get_mime(),
                ];

                $embedMedia['track'] = $this->getAvailableVideoTextTracks($information);



                $embedMedia['dimensions'] = $this->getDimensions($subdef);

                $oembedMetaData['type'] = 'video';
                $oembedMetaData['html'] = sprintf(
                    '<iframe width="%d" height="%d" src="%s" frameborder="0" allowfullscreen></iframe>',
                    $embedMedia['dimensions']['width'],
                    $embedMedia['dimensions']['height'],
                    $this->getEmbedUrl($resourceUrl)
                );
                break;
            case 'flexpaper':
            case 'document':
                $ogMetaData['og:type'] = 'article';
                $ogMetaData['og:image'] = $baseUrl . $thumbnail->get_url();
                $ogMetaData['og:image:width'] = $thumbnail->get_width();
                $ogMetaData['og:image:height'] = $thumbnail->get_height();

                $oembedMetaData['type'] = 'link';
                $embedMedia['dimensions'] = $this->getDimensions($subdef);
                break;
            case 'audio':
                $ogMetaData['og:type'] = 'music.song';
                $ogMetaData['og:image'] = $baseUrl . $substitutionPath;
                $ogMetaData['og:image:width'] = $thumbnail->get_width();
                $ogMetaData['og:image:height'] = $thumbnail->get_height();

                $oembedMetaData['type'] = 'link';
                $embedMedia['source'] = [];
                $embedMedia['source'][] = [
                    'url'  => $resourceUrl,
                    'type' => $subdef->get_mime()
                ];
                $embedMedia['coverUrl'] = $baseUrl . $substitutionPath;
                // set default dimension for player
                $embedMedia['dimensions'] = [
                    'width'  => 320,
                    'height' => 320,
                    'top'    => 0,
                ];
                break;
            default:
                $oembedMetaData['type'] = 'photo';
                $ogMetaData['og:type'] = 'image';
                $ogMetaData['og:image'] = (string)$record->get_preview()->get_permalink()->get_url();
                $ogMetaData['og:image:width'] = $subdef->get_width();
                $ogMetaData['og:image:height'] = $subdef->get_height();

                $embedMedia['dimensions'] = $this->getDimensions($subdef);
                break;
        }

        return [
            'options'        => [
                'autoplay' => false,
            ],
            'oembedMetaData' => $oembedMetaData,
            'ogMetaData'     => $ogMetaData,
            'embedMedia'     => $embedMedia,
        ];
    }
1363599
public function withInfo($info)
    {
        Assertion::string($info);
        Assertion::notBlank($info);

        $instance = clone $this;

        $instance->info = $info;

        return $instance;
    }
811280
protected function createList(Infoset $info) {
		$list = [];
		
		if ($info->hasTitle()) {
			$list[] = $info->getTitle() . ':';
		}
		
		foreach ($info as $content) {
			if ($content instanceof Infoset) {
				$content = $this->createContent($content);
			}
			
			if ($info->isContentBbCodes()) {
				$content = $this->bbCodesHandle($content);
			}
			
			$list[] = ' - ' . $content;
		}

		return implode(PHP_EOL, $list);
	}
565880
protected function createContent(Infoset $info) {
		$content = '';
		
		switch ($info->getContentType()) {
			case Infoset::TYPE_LIST:
				$content .= $this->createList($info);
				break;
			
			case Infoset::TYPE_TABLE:
				$content .= $this->createTable($info);
				break;
			
			case Infoset::TYPE_MULTI:
				foreach ($info as $part) {
					if (($title = $part->getTitle()) !== null) {
						$content .= $this->getTagsLocator()->get('title')->render($title);
					}
				
					$content .= $this->createContent($part);
				}
				break;
				
			case Infoset::TYPE_TEXT:
				foreach ($info as $part) {
					$content .= $this->specialCharsHandle($part);
				}
				break;
				
			case Infoset::TYPE_DESCLIST:
				$content .= $this->createDescriptionList($info);
				break;
			
			case Infoset::TYPE_DUMP:
				$content .= $this->createDump($info);
				break;
			
			case Infoset::TYPE_TOPOLOGY:
				$content .= $this->createTopology($info);
				break;
			
			default:
				throw new InvalidContent('Unknown content type: "' . $info->getContentType() . '"');
		}
		
		return $content;
	}
654791
public function attach($attachmentType, $url)
    {
        $attachmentTypes = [
            AttachmentType::FILE,
            AttachmentType::IMAGE,
            AttachmentType::VIDEO,
            AttachmentType::AUDIO,
        ];

        if (! in_array($attachmentType, $attachmentTypes)) {
            throw CouldNotCreateMessage::invalidAttachmentType();
        }

        if (! isset($url)) {
            throw CouldNotCreateMessage::urlNotProvided();
        }

        $this->attachmentType = $attachmentType;
        $this->attachmentUrl = $url;
        $this->hasAttachment = true;

        return $this;
    }
1063278
public function create_item( $request ) {

		if ( ! empty( $request['post'] ) && in_array( get_post_type( $request['post'] ), array( 'revision', 'attachment' ), true ) ) {
			return new WP_Error( 'rest_invalid_param', __( 'Invalid parent type.' ), array( 'status' => 400 ) );
		}

		// Get the file via $_FILES or raw data
		$files = $request->get_file_params();
		$headers = $request->get_headers();
		if ( ! empty( $files ) ) {
			$file = $this->upload_from_file( $files, $headers );
		} else {
			$file = $this->upload_from_data( $request->get_body(), $headers );
		}

		if ( is_wp_error( $file ) ) {
			return $file;
		}

		$name       = basename( $file['file'] );
		$name_parts = pathinfo( $name );
		$name       = trim( substr( $name, 0, -(1 + strlen( $name_parts['extension'] ) ) ) );

		$url     = $file['url'];
		$type    = $file['type'];
		$file    = $file['file'];

		// use image exif/iptc data for title and caption defaults if possible
		// @codingStandardsIgnoreStart
		$image_meta = @wp_read_image_metadata( $file );
		// @codingStandardsIgnoreEnd
		if ( ! empty( $image_meta ) ) {
			if ( empty( $request['title'] ) && trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) {
				$request['title'] = $image_meta['title'];
			}

			if ( empty( $request['caption'] ) && trim( $image_meta['caption'] ) ) {
				$request['caption'] = $image_meta['caption'];
			}
		}

		$attachment = $this->prepare_item_for_database( $request );
		$attachment->file = $file;
		$attachment->post_mime_type = $type;
		$attachment->guid = $url;

		if ( empty( $attachment->post_title ) ) {
			$attachment->post_title = preg_replace( '/\.[^.]+$/', '', basename( $file ) );
		}

		$id = wp_insert_post( $attachment, true );
		if ( is_wp_error( $id ) ) {
			if ( 'db_update_error' === $id->get_error_code() ) {
				$id->add_data( array( 'status' => 500 ) );
			} else {
				$id->add_data( array( 'status' => 400 ) );
			}
			return $id;
		}
		$attachment = $this->get_post( $id );

		// Include admin functions to get access to wp_generate_attachment_metadata().
		require_once ABSPATH . 'wp-admin/includes/admin.php';

		wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );

		if ( isset( $request['alt_text'] ) ) {
			update_post_meta( $id, '_wp_attachment_image_alt', sanitize_text_field( $request['alt_text'] ) );
		}

		$fields_update = $this->update_additional_fields_for_object( $attachment, $request );
		if ( is_wp_error( $fields_update ) ) {
			return $fields_update;
		}

		$request->set_param( 'context', 'edit' );
		$response = $this->prepare_item_for_response( $attachment, $request );
		$response = rest_ensure_response( $response );
		$response->set_status( 201 );
		$response->header( 'Location', rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $id ) ) );

		/**
		 * Fires after a single attachment is created or updated via the REST API.
		 *
		 * @param object          $attachment Inserted attachment.
		 * @param WP_REST_Request $request    The request sent to the API.
		 * @param boolean         $creating   True when creating an attachment, false when updating.
		 */
		do_action( 'rest_insert_attachment', $attachment, $request, true );

		return $response;

	}
395898
protected function createTitle(Infoset $info) {
		if (isset($_SERVER['REQUEST_METHOD'])) {
			$info->setTitle(preg_replace('/[^a-z]+/i', '', $_SERVER['REQUEST_METHOD']));
			return;
		}
		
		if (php_sapi_name() === 'cli') {
			$info->setTitle('[success]CLI[/success]');
			return;
		}
		
		$info->setTitle('Unknown API');
	}
392250
protected function createAttachmentViaPath($file)
    {
        /** @var $byteStream \Swift_ByteStream_FileByteStream */
        $byteStream = $this->getManager()->getDI()->get('\Swift_ByteStream_FileByteStream', [$file]);

        /** @var $image \Swift_Attachment */
        $attachment = $this->getManager()->getDI()->get('\Swift_Attachment')
            ->setFile($byteStream);

        return $attachment;
    }
681198
protected function createTitle(Infoset $info) {
		if (php_sapi_name() === 'cli') {
			$info->setTitle('[success]CLI[/success]');
			return;
		}
		
		$code = http_response_code();
		
		$title = ($code < 400)
			? '[success]' . $code . '[/success]'
			: '[alert]' . $code . '[/alert]';
		
		if (ob_get_level() > 0) {
			$title .= ' / ' . $this->formatMemory(ob_get_length());
		}
		
		$info->setTitle($title);
	}
1127147
public function insertNewRecord($data) {

        $emailAttachment = new Email_attachment;

        $emailAttachment->email_messages_id          = $data['email_messages_id'];
        $emailAttachment->attachment_path            = $data['attachment_path'];
        $emailAttachment->attachment_filename        = $data['attachment_filename'];
        $emailAttachment->alternate_sort_string1     = $data['alternate_sort_string1'];
        $emailAttachment->alternate_sort_string2     = $data['alternate_sort_string2'];
        $emailAttachment->comments                   = $data['comments'];

        return $emailAttachment->save();
    }
1158334
protected function createTable(Infoset $info) {
		$table = new Table();
		$table->addClass('content-table');
		
		if ($info instanceof InfosetTable) {
			if (($widths = $info->getColsWidths()) !== null) {
				$table->getColgroup()->addElements($widths);
			}
			
			if (($headRow = $info->getHeadContent()) !== null) {
				$table->getHead()->addElement($headRow);
			}
		}
		
		foreach ($info as $row) {
			if (! is_array($row) && ! $row instanceof Traversable) {
				throw new InvalidContent('Table row content must be an array or a Traversable implementation');
			}
			
			$cols = [];
			
			foreach ($row as $content) {
				if ($content instanceof Infoset) {
					$content = $this->createContent($content);
				}
				
				$content = $this->specialCharsHandle($content);
				
				if ($info->isContentBbCodes()) {
					$content = $this->bbCodesHandle($content);
				}
				
				$cols[] = $content;
			}
			
			if ($row instanceof Row && $row->isMarked()) {
				$cols['_class_'] = $row->getMark();
			}
			
			$table[] = $cols;
		}
		
		return $table->render();
	}
36612
public function build(InformationCollected $value)
    {
        $location = $value->getLocation();
        $contentType = $value->getContentType();
        $content = $this->contentService->loadContent($location->contentId);

        $template = $this->resolveTemplate($contentType->identifier);

        $templateWrapper = $this->twig->load($template);
        $data = new TemplateData($value, $content, $templateWrapper);

        $body = $this->resolveBody($data);

        return new EmailData(
            $this->resolveRecipient($data),
            $this->resolve($data, Constants::FIELD_SENDER, Constants::FIELD_TYPE_EMAIL),
            $this->resolveSubject($data),
            $body
        );
    }
1290411
public static function attachment($path_or_data = null, $filename = null, $contentType = null) {
        $from_path = realpath($path_or_data);
        if ($from_path) {
            $attachment = Swift_Attachment::fromPath($path_or_data, $contentType);
            $attachment->setFilename($filename);
        } else {
            $attachment = Swift_Attachment::newInstance($path_or_data, $filename, $contentType);
        }
        return $attachment;
    }