Exemplo n.º 1
0
 /**
  * Execute Embed with an url and returns the info.
  *
  * @param string
  *
  * @return AdapterInterface
  */
 protected function assertEmbed($url, array $info, array $config = array())
 {
     if (getenv('embed_resolver')) {
         $config['resolver'] = ['class' => 'Embed\\RequestResolvers\\' . getenv('embed_resolver')];
     }
     $i = Embed::create($url, $config);
     foreach ($info as $name => $value) {
         switch ($name) {
             case 'title':
             case 'description':
             case 'url':
             case 'type':
             case 'image':
             case 'imageWidth':
             case 'imageHeight':
             case 'code':
             case 'authorName':
             case 'authorUrl':
             case 'providerName':
             case 'providerUrl':
             case 'providerIcon':
                 $this->assertString($value, $i->{$name});
                 break;
             case 'width':
             case 'height':
             case 'imageWidth':
             case 'imageHeight':
                 $this->assertSame($value, $i->{$name});
                 break;
             default:
                 throw new InvalidArgumentException("No valid {$name} assertion");
         }
     }
 }
Exemplo n.º 2
0
 /**
  * decorate a bare url with the help of embed/embed
  *
  * @param string $match string to be truncated
  *
  * @return string
  */
 protected function decorateUrl($match)
 {
     $url = $match[1];
     $decorated = null;
     $xoops = \Xoops::getInstance();
     $md5 = md5($url);
     $crc = hash("crc32b", $url);
     $key = ['embed', substr($crc, -2), $md5];
     //$xoops->cache()->delete($key);
     $decorated = $xoops->cache()->cacheRead($key, function ($url) {
         $return = null;
         try {
             $info = \Embed\Embed::create($url);
         } catch (\Exception $e) {
             $info = null;
         }
         if (is_object($info)) {
             $return = $info->code;
             if (empty($return)) {
                 $return = $this->mediaBox($info->url, $info->image, $info->title, $info->description);
             }
         }
         if (empty($return)) {
             $return = $url;
         }
         return $return;
     }, $this->config['cache_time'], $url);
     return $decorated;
 }
 /**
  * @param Message $message
  */
 public function process(Message $message)
 {
     // Only process messages where ShareMonkey is mentioned
     if ($this->shareMonkeyIsMentioned($message->getText()) === false) {
         return;
     }
     $text = $message->getText();
     $urls = $text->getUrls();
     $tags = $text->getTags();
     if (count($urls) === 0) {
         $this->logger->debug('No urls found in message');
         return;
     }
     $user = $this->userRepository->findOneBySlackId($message->getUserId());
     if (!$user instanceof User) {
         $this->logger->error(sprintf('User "%s" not found', $message->getUserId()->getValue()));
         return;
     }
     foreach ($urls as $url) {
         $this->logger->debug(sprintf('processing url %s', $url));
         $info = Embed::create($url);
         $link = Link::fromSlack($message->getId(), $user, $message->getCreatedAt(), $info->getTitle() ?: $message->getText(), $url, $tags);
         $this->objectManager->persist($link);
         $this->objectManager->flush();
         $this->objectManager->clear();
         $this->logger->debug(sprintf('Saved link %s', $link->getUrl()));
     }
 }
 public function store(PostRequest $request)
 {
     if (Input::has('link')) {
         $input['link'] = Input::get('link');
         $info = Embed::create($input['link']);
         if ($info->image == null) {
             $embed_data = ['text' => $info->description];
         } else {
             if ($info->description == null) {
                 $embed_data = ['text' => ''];
             } else {
                 $orig = pathinfo($info->image, PATHINFO_EXTENSION);
                 $qmark = str_contains($orig, '?');
                 if ($qmark == false) {
                     $extension = $orig;
                 } else {
                     $extension = substr($orig, 0, strpos($orig, '?'));
                 }
                 $newName = public_path() . '/images/' . str_random(8) . ".{$extension}";
                 if (File::exists($newName)) {
                     $imageToken = substr(sha1(mt_rand()), 0, 5);
                     $newName = public_path() . '/images/' . str_random(8) . '-' . $imageToken . ".{$extension}";
                 }
                 $image = Image::make($info->image)->fit(70, 70)->save($newName);
                 $embed_data = ['text' => $info->description, 'image' => basename($newName)];
             }
         }
         Auth::user()->posts()->create(array_merge($request->all(), $embed_data));
         return redirect('/subreddit');
     }
     Auth::user()->posts()->create($request->all());
     return redirect('/subreddit');
 }
Exemplo n.º 5
0
 /**
  * ### Ortam bilgilerini alma
  *
  * @param $url
  * @return \Embed\Adapters\AdapterInterface|false
  */
 protected function parse($url)
 {
     $data = Embed::create($url);
     if ($data) {
         return $data;
     }
 }
 public function run()
 {
     // make sure a source url was provided
     if (is_null($this->url) || empty($this->url)) {
         return $this->show_errors ? 'Please pass a URL parameter to scan for a video to embed.' : false;
     }
     // include embed class
     include_once __DIR__ . '/../../../vendor/embed/embed/src/autoloader.php';
     // look up data for the supplied url
     $data = \Embed\Embed::create($this->url);
     // make sure we received a video embed code from the lookup
     if (!is_object($data) || is_null($data->code)) {
         return $this->show_errors ? "Embed code could not be generated for this URL ({$this->url})" : false;
     }
     // build the video container with custom id and class if desired
     $custom_container = !empty($this->container_id) || !empty($this->container_class);
     $video_embed = $custom_container ? '<div id="' . $this->container_id . '" class="' . $this->container_class . '">' : '';
     // also set responsiveness class (video-container) if desired
     $video_embed .= $this->responsive ? '<div class="video-container">' : '';
     // insert the embed code
     $video_embed .= $data->code;
     // close the containers
     $video_embed .= $this->responsive ? '</div>' : '';
     $video_embed .= $custom_container ? '</div>' : '';
     // return the video embed code
     return $video_embed;
 }
 /**
  * Embed shortcode parser from Oembed. This is a temporary workaround.
  * Oembed class has been replaced with the Embed external service.
  *
  * @param $arguments
  * @param $content
  * @param $parser
  * @param $shortcode
  * @param array $extra
  *
  * @return string
  */
 public static function handle_shortcode($arguments, $content, $parser, $shortcode, $extra = array())
 {
     $embed = Embed::create($content, $arguments);
     if ($embed && $embed instanceof \Embed\Adapters\Adapter) {
         return self::embedForTemplate($embed);
     } else {
         return '<a href="' . $content . '">' . $content . '</a>';
     }
 }
 public function testSoundcloud()
 {
     /** @var Webpage $result */
     $result = Embed::create(self::$test_soundcloud, array());
     self::assertEquals($result->providerName, 'SoundCloud');
     $embedded = EmbedShortcodeProvider::embedForTemplate($result);
     self::assertContains("<div class='media'", $embedded);
     self::assertContains('iframe', $embedded);
     self::assertContains('soundcloud.com', $embedded);
     self::assertContains('player', $embedded);
     self::assertContains('tracks%2F242518079', $embedded);
 }
 public function __construct($url, File $file = null)
 {
     parent::__construct($url, $file);
     $this->embed = Embed::create($url);
     if (!$this->embed) {
         $controller = Controller::curr();
         $response = $controller->getResponse();
         $response->addHeader('X-Status', rawurlencode(_t('HTMLEditorField.URLNOTANOEMBEDRESOURCE', "The URL '{url}' could not be turned into a media resource.", "The given URL is not a valid Oembed resource; the embed element couldn't be created.", array('url' => $url))));
         $response->setStatusCode(404);
         throw new HTTPResponse_Exception($response);
     }
 }
Exemplo n.º 10
0
 public function fetch($url)
 {
     $content = [];
     $info = \Embed\Embed::create($url);
     $content['title'] = $info->title;
     $content['description'] = $info->description;
     $content['images'] = $info->images;
     $content['image'] = $info->image;
     $content['code'] = $info->code;
     $content['author_name'] = $info->authorName;
     $content['publishedDate'] = $info->publishedDate;
     return $content;
 }
Exemplo n.º 11
0
 /**
  * scrape data from url
  *
  * @param $url
  *
  * @return array|null
  */
 public function fetchData($url)
 {
     try {
         $info = \Embed\Embed::create($url);
         $data = [];
         foreach ($this->adapterData as $name => $fn) {
             $data[$name] = $info->{$name};
         }
         return $data;
     } catch (\Exception $exception) {
         \Log::error('error getting data form url.' . $url, $exception);
         return null;
     }
 }
Exemplo n.º 12
0
 public function getTitle(Request $request)
 {
     // $client = new Client($request->input('url'));
     // $request = $client->get('');
     // $response = $request->send();
     // $body = $response->getBody();
     // preg_match('/<title>(.*?)<\/title>/s', $body, $matches);
     // if ($matches) {
     //     return response($matches[1], 200);
     // }
     // return response('Something happened.', 500);
     $info = \Embed\Embed::create($request->input('url'));
     return response()->json(['title' => $info->title, 'image_url' => $info->image], 200);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param PostRequest|Request $request
  * @return Response
  */
 public function store(PostRequest $request)
 {
     if (Input::has('link')) {
         $input['link'] = Input::get('link');
         $info = Embed::create($input['link']);
         $image = \Image::make($info->image)->resize(120, 120)->save('C:\\xampp\\htdocs\\laravel-5\\public\\images' . '/' . str_random(8) . '.jpg');
         $embed_data = ['text' => $info->description, 'image' => $image->filename . '.jpg'];
         //Auth::user()->posts()->create(array_add($request->all(), 'image', $info->image));
         Auth::user()->posts()->create(array_merge($request->all(), $embed_data));
         return redirect('/articles');
     }
     Auth::user()->posts()->create($request->all());
     return redirect('/');
 }
Exemplo n.º 14
0
 /**
  * Return page info
  *
  * @return array|Adapter
  *
  * @throws InvalidConfigException
  */
 public function getPageInfo()
 {
     if (empty($this->content)) {
         throw new InvalidConfigException("The 'content' property is required.");
     }
     $url = $this->getUrlFromContent();
     if (!empty($url)) {
         try {
             return Embed::create($url, $this->config);
         } catch (InvalidUrlException $e) {
             // Invalid url
         }
     }
     return [];
 }
Exemplo n.º 15
0
 /**
  * Resolve meta data of present URL.
  *
  * @param Request $request
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  * @throws \Embed\Exceptions\InvalidUrlException
  */
 public function index(Request $request)
 {
     $url = $request->input('url');
     $providerData = ['title' => 'printText', 'description' => 'printText', 'url' => 'printUrl', 'type' => 'printText', 'tags' => 'printArray', 'imagesUrls' => 'printArray', 'code' => 'printCode', 'source' => 'printUrl', 'width' => 'printText', 'height' => 'printText', 'authorName' => 'printText', 'authorUrl' => 'printUrl', 'providerIconsUrls' => 'printArray', 'providerName' => 'printText', 'providerUrl' => 'printUrl', 'publishedTime' => 'printText'];
     $adapterData = ['title' => 'printText', 'description' => 'printText', 'url' => 'printUrl', 'type' => 'printText', 'tags' => 'printArray', 'image' => 'printImage', 'imageWidth' => 'printText', 'imageHeight' => 'printText', 'images' => 'printArray', 'code' => 'printCode', 'source' => 'printUrl', 'width' => 'printText', 'height' => 'printText', 'aspectRatio' => 'printText', 'authorName' => 'printText', 'authorUrl' => 'printUrl', 'providerIcon' => 'printImage', 'providerIcons' => 'printArray', 'providerName' => 'printText', 'providerUrl' => 'printUrl', 'publishedTime' => 'printText'];
     $info = '';
     if ($url) {
         try {
             $info = Embed::create($url);
         } catch (Exception $exception) {
             // :TODO: Log it
             $error = $exception->getMessage();
         }
     }
     if (!empty($info)) {
         $adapterData = $this->collectAdapterData($adapterData, $info);
     }
     return view('page-meta.index', compact('url', 'providerData', 'adapterData', 'info'));
 }
Exemplo n.º 16
0
 public function setPicture()
 {
     $pd = new \Modl\PostnDAO();
     $item = $pd->getGroupPicture($this->server, $this->node);
     if ($item) {
         $item->getAttachments();
         $p = new \Picture();
         if ($item->getPublicUrl()) {
             try {
                 $embed = \Embed\Embed::create($item->getPublicUrl());
                 // We get the icon
                 $url = false;
                 foreach ($embed->providerIcons as $icon) {
                     if ($icon['mime'] != 'image/x-icon') {
                         $url = $icon['value'];
                     }
                 }
                 // If not we take the main picture
                 if (!$url) {
                     $url = (string) $embed->image;
                 }
                 // If not we take the post picture
                 if (!$url) {
                     $url = (string) $item->picture;
                 }
                 $p->fromURL($url);
                 if ($p->set($this->server . $this->node)) {
                     $this->logo = true;
                 }
             } catch (\Exception $e) {
                 error_log($e->getMessage());
             }
         }
     }
 }
Exemplo n.º 17
0
 /**
  * @param $url
  * @return \EFrane\Letterpress\Markup\RichMedia\Lookup
  **/
 protected function lookup($url)
 {
     if (parse_url($url, PHP_URL_SCHEME) === null) {
         // if no url scheme was given, force https
         $url = sprintf('https://%s', $url);
     }
     $lookup = $this->repository->refreshLookup($url, function () use($url) {
         try {
             $adapter = Embed::create($url);
         } catch (\Exception $e) {
             // wrap exception
             throw new LetterpressException($e);
         }
         if ($adapter instanceof AdapterInterface) {
             return $adapter;
         } else {
             throw new LetterpressException('Failed to resolve embed for url: ' . $url);
         }
     });
     return $lookup;
 }
Exemplo n.º 18
0
 public function run()
 {
     $info = EmbedLibrary::create($this->url);
     return $this->render($this->pathToView, ['info' => $info]);
 }
Exemplo n.º 19
0
 /**
  * @param $url
  * @return bool
  * @throws \Embed\Exceptions\InvalidUrlException
  */
 private function get_embed($url)
 {
     $url = preg_replace("/^(http|https):\\/\\/www.instagram.com(.*)/u", "\$1://instagram.com\$2", $url);
     $obj = \Embed\Embed::create($url);
     if ($obj->code) {
         return $obj->code;
     } elseif ($obj->image) {
         return $obj->image;
     }
     return false;
 }
 /**
  * Get the HTML embed code.
  *
  * @return string
  */
 private function getEmbedCode($baseURL = null, $url)
 {
     $info = Embed::create($baseURL . $this->extractURL($url));
     return $info->code;
 }
Exemplo n.º 21
0
 public function getBasicInfomation($url)
 {
     $info = Embed::create($url);
     $BasicInformation = array("author" => $info->getAuthorName(), "title" => $info->getTitle(), "description" => $info->getDescription(), "date" => $info->getPublishedTime(), "url" => $info->getUrl());
     return $BasicInformation;
 }
Exemplo n.º 22
0
 protected function setFromEmbed(&$post)
 {
     if (!isset($post['Link'])) {
         return;
     }
     $cacheKey = $this->getCacheKey(['embed' => $post['Link']]);
     if (!($record = unserialize($this->cache()->load($cacheKey)))) {
         $record = [];
         if (class_exists('Embed\\Embed')) {
             $info = \Embed\Embed::create($post['Link']);
             $record['ObjectName'] = $info->getTitle();
             $record['ObjectURL'] = $info->getUrl();
             $record['ObjectWidth'] = $info->getWidth();
             $record['ObjectHeight'] = $info->getHeight();
             $record['ObjectThumbnail'] = $info->getImage();
             $record['ObjectDescription'] = $info->getDescription();
             $record['ObjectType'] = $info->getType();
             $record['ObjectEmbed'] = $info->getCode();
         } else {
             if ($info = \Oembed::get_oembed_from_url($post['Link'])) {
                 if ($info->hasField('title')) {
                     $record['ObjectName'] = $info->getField('title');
                 }
                 if ($info->hasField('url')) {
                     $record['ObjectURL'] = $info->getField('url');
                 }
                 if ($info->hasField('width')) {
                     $record['ObjectWidth'] = $info->getField('width');
                 }
                 if ($info->hasField('height')) {
                     $record['ObjectHeight'] = $info->getField('height');
                 }
                 if ($info->hasField('thumbnail')) {
                     $record['ObjectThumbnail'] = $info->getField('thumbnail');
                 }
                 if ($info->hasField('description')) {
                     $record['ObjectDescription'] = $this->textParser()->text($info->getField('description'));
                 }
                 if ($info->hasField('type')) {
                     $record['ObjectType'] = $info->getField('type');
                 }
                 $record['ObjectEmbed'] = $info->forTemplate();
             }
         }
         $this->cache()->save(serialize($record), $cacheKey);
     }
     foreach ($record as $key => $value) {
         $post[$key] = $value;
     }
 }
Exemplo n.º 23
0
 /**
  * Renders the widget.
  */
 public function run()
 {
     $this->info = \Embed\Embed::create($this->url, $this->embedOptions);
     echo $this->info->code;
 }
Exemplo n.º 24
0
 /**
  * Automatically generated run method
  *
  * @param Request $request
  * @return Response
  */
 public function run(Request $request)
 {
     $info = Embed::create($request->query->get('url'));
     return $this->responder->run($request, new Found(['info' => $info]));
 }