/** * Get embed code * * @return sting */ public function getAjaxEmbedCode() { $result = array(); $url = !empty($_GET['url']) ? urldecode($_GET['url']) : null; if ($url) { $embedInfo = UTIL_HttpResource::getOEmbed($url); if (!empty($embedInfo['html'])) { $result = $embedInfo; } } die(json_encode($result)); }
public function addLink() { if (!OW::getRequest()->isAjax()) { throw new Redirect404Exception(); } $url = $_POST['url']; $urlInfo = parse_url($url); if (empty($urlInfo['scheme'])) { $url = 'http://' . $url; } $url = str_replace("'", '%27', $url); $oembed = UTIL_HttpResource::getOEmbed($url); $oembedCmp = new BASE_CMP_AjaxOembedAttachment($oembed); $attacmentUniqId = $oembedCmp->initJs(); unset($oembed['allImages']); $response = array('content' => $this->getMarkup($oembedCmp->render()), 'type' => 'link', 'result' => $oembed, 'attachment' => $attacmentUniqId); echo json_encode($response); exit; }
private function parsePage($url) { $content = @UTIL_HttpResource::getContents($url); $matches = array(); preg_match('/<\\s*meta\\s*[^\\>]*?http-equiv=[\'"]content-type[\'"][^\\>]*?\\s*>/i', $content, $matches); $meta = empty($matches[0]) ? null : $matches[0]; preg_match('/content=[\'"][^\'"]*?charset=([\\w-]+)(:[^\\w-][^\'"])*?[\'"]/i', $meta, $matches); $encoding = empty($matches[1]) ? 'UTF-8' : $matches[1]; preg_match('/<\\s*title\\s*>([\\s\\S]*?)<\\s*\\/\\s*title\\s*>/i', $content, $matches); $title = empty($matches[1]) ? null : mb_convert_encoding($matches[1], 'UTF-8', $encoding); $matches = array(); $meta = ""; preg_match('/<\\s*meta\\s*[^\\>]*?name=[\'"]description[\'"][^\\>]*?\\s*>/i', $content, $matches); $meta = empty($matches[0]) ? null : $matches[0]; $matches = array(); preg_match('/content=[\'"](.*?)[\'"]/i', $meta, $matches); $description = empty($matches[1]) ? null : mb_convert_encoding($matches[1], 'UTF-8', $encoding); $matches = array(); preg_match_all('/<\\s*img\\s*.*?src=[\'"](.+?)[\'"].*?>/i', $content, $matches); $images = array(); foreach ($matches[1] as $img) { $urlInfo = parse_url($url); $imgInfo = parse_url($img); if (empty($imgInfo['host'])) { $imgDir = dirname($imgInfo['path']); $urlScheme = empty($urlInfo['scheme']) ? '' : $urlInfo['scheme'] . '://'; $urlAddr = $urlScheme . $urlInfo['host']; if (strpos($imgDir, '/') === 0) { $img = $urlAddr . $imgInfo['path']; } elseif (!empty($urlInfo['path'])) { $pp = pathinfo($urlInfo['path']); $urlPath = $pp['dirname'] . (empty($pp['extension']) ? $pp['basename'] . '/' : ''); $img = $urlAddr . $urlPath . $imgInfo['path']; } else { $img = $urlAddr . '/' . $imgInfo['path']; } } $images[] = $img; } $firstImg = reset($images); $firstImg = $firstImg ? $firstImg : null; return array('type' => 'link', 'description' => $description, 'title' => $title, 'thumbnail_url' => $firstImg, 'allImages' => $images); }
private function queryLink($query) { $url = $query['link']; $urlInfo = parse_url($url); if (empty($urlInfo['scheme'])) { $url = 'http://' . $url; } $oembed = @UTIL_HttpResource::getOEmbed($url); if (empty($oembed) || isset($oembed['result']) && $oembed['result'] == false || $oembed['type'] == 'link' && empty($oembed['title']) && empty($oembed['description'])) { $response = array('type' => 'link', 'result' => false, 'href' => $url); return $response; } $attacmentUniqId = uniqid('att'); switch ($oembed['type']) { case 'video': $oembedCmp = new EQUESTIONS_CMP_AttVideoPreview($oembed); break; case 'photo': $oembedCmp = new EQUESTIONS_CMP_AttPhotoPreview($oembed['url']); break; default: $oembedCmp = new EQUESTIONS_CMP_AttLinkPreview($oembed); $attacmentUniqId = $oembedCmp->initJs($query['uniqId']); } unset($oembed['allImages']); $content = '<div class="al-result-preview">' . $oembedCmp->render() . '</div>'; $response = array('content' => $this->getMarkup($content), 'type' => 'link', 'result' => $oembed, 'attachment' => $attacmentUniqId, 'processedUrl' => $query['link']); return $response; }