';
- }
- }
-
- ////////////////////////////
- // Unsupported URL to embed
- ////////////////////////////
- else {
- return array(GalleryCoreApi::error(ERROR_UNSUPPORTED_FILE_TYPE,__FILE__,__LINE__,
- "Unable to embed video from: $url"),null,null);
- }
+ /* Extract the summary from the webpage contents */
+ preg_match('//i',
+ $contents, $matches);
+ $summary=$matches[1];
-
- ////////////////////////////
- // Add the video to Gallery
- ////////////////////////////
-
- // Get a local tmp file to save the thumbnail to
- $tmpDir = $gallery->getConfig('data.gallery.tmp');
- $tmpFile = $platform->tempnam($tmpDir, 'add');
- $tmpFile.= ".jpg";
+ /* Extract the title from the webpage contents */
+ preg_match('/(.+?)\s+- Google Video<\/title>/i',
+ $contents, $matches);
+ $title=$matches[1];
- if($debug) {
- print "thumbnail: $thumbnail ";
- }
-
- // Fetch the thumbnail and save it to a local file
- if (empty($extraHeaders)) {
- $extraHeaders = array('Referer' => str_replace('&', '&', $url));
- }
+ /* Extract the thumbnail URL from the webpage contents */
+ preg_match('/ ';
+ $description.= '';
+ $description.= " $summary";
+
+ /*
+ **********************************
+ * Embed a remote .flv file
+ **********************************
+ */
+ } else if(preg_match("/.*\/(.+?)\.flv/i",$url,$matches)) {
- // Obtain the mimeType of the thumbnail
- list ($ret, $mimeType) = GalleryCoreApi::getMimeType($tmpFile);
+ /* Set the title and summary to the name of the file */
+ $title = $matches[1];
+ $summary = $matches[1];
+
+ /*
+ * Set the thumbnail to some generic jpg image,
+ * since we can't extract it from the remote flv file.
+ * If no parameter is set, set it to a default value.
+ */
+ if(preg_match("/\w+/", $flvThumbnail)) {
+ $thumbnail = $flvThumbnail;
+ } else {
+ $thumbnail = $gallery2_url.$gallery2_flv_thumbnail;
+ }
- // Set the filename for the item we want to add
- $fileName = $title;
- $fileName = preg_replace("/\s+/","_",$fileName);
- $fileName = preg_replace("/'/","",$fileName);
- $fileName = preg_replace("/\"/","",$fileName);
- $fileName = preg_replace("/\d+;/","",$fileName);
-
- // DEBUG OUTPUT
- if($debug) {
- print "
";
- print "thumbnail: $tmpFile ";
- print "mimeType: $mimeType ";
- print "fileName: $fileName ";
- }
-
- list ($ret, $newItem) = GalleryCoreApi::addItemToAlbum($tmpFile,
- $fileName,
- $title,
- $summary,
- $description,
- $mimeType,
- $item->getId());
-
- if ($ret) {
- return array($ret, null, null);
- }
-
- $status['addedFiles'][] = array('fileName' => $url,
- 'id' => $newItem->getId(),
- 'warnings' => array());
- }
- @$platform->unlink($tmpFile);
- }
-
- return array(null, $error, $status);
- }
+ /*
+ * Check to make sure the URL to the remote flv file is valid
+ * (That the file exists at the URL given)
+ */
+ if (empty($extraHeaders)) {
+ $extraHeaders = array('Referer' => str_replace('&', '&', $url));
+ }
+ list ($successfullyCopied, $response, $headers) =
+ GalleryCoreApi::fetchWebPage($url, $extraHeaders);
+ if (!$successfullyCopied) {
+ return array(GalleryCoreApi::error(ERROR_BAD_PATH,__FILE__,__LINE__,
+ "Unable to locate a video at url: $url"),null,null);
+ }
+
+ /*
+ * Format the description to hold a reference to the embedded video
+ * This reference will be embedded using the G2 internal player,
+ * or an external player if provided by the user.
+ */
+ if(!$useInternalFlvPlayer) {
-/**
- * @see ItemAdd:loadTemplate
- */
-function loadTemplate(&$template, &$form, $item) {
- global $gallery;
-
- if ($form['formName'] != 'ItemAddEmbedVideo') {
- /* First time around, load the form with item data */
- $form['webPage'] = '';
- $form['formName'] = 'ItemAddEmbedVideo';
- }
-
- $session =& $gallery->getSession();
-
- $template->setVariable('ItemAddEmbedVideo', $ItemAddEmbedVideo);
-
- return array(null,
- 'modules/embedvideo/templates/ItemAddEmbedVideo.tpl',
- 'modules_embedvideo');
-}
+ /*
+ * The user has indicated they want to use an external flv player
+ * Make sure one is defined!
+ */
+ if(!preg_match("/\w+/",$externalFlvPlayer)) {
+ return array(GalleryCoreApi::error(ERROR_CONFIGURATION_REQUIRED,__FILE__,__LINE__,
+ "Invalid/missing external player parameter"),null,null);
+ }
-/**
- * @see ItemAddPlugin::getTitle
- */
- function getTitle() {
- list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'embedvideo');
- if ($ret) {
- return array($ret, null);
+ /* Format the description to hold a reference to the embedded video */
+ $description =' ';
+
+ /* Internal FLV player */
+ } else {
+ /* Format the description to hold a reference to the embedded video */
+ $macromedia_url = "http://download.macromedia.com/pub/shockwave/cabs/flash/";
+ $description = ''."\n";
+ $description.= '
'."\n";
+ $description.= '
';
+ }
+
+ /*
+ **********************************
+ * Unsupported URL to embed
+ **********************************
+ */
+ } else {
+ return array(GalleryCoreApi::error(ERROR_UNSUPPORTED_FILE_TYPE,__FILE__,__LINE__,
+ "Unable to embed video from: $url"),null,null);
+ }
+
+
+ /*
+ **********************************
+ * Add the video to Gallery
+ **********************************
+ */
+
+ /* Get a local tmp file to save the thumbnail URL to */
+ $tmpDir = $gallery->getConfig('data.gallery.tmp');
+ $tmpFile = $platform->tempnam($tmpDir, 'add');
+ $tmpFile.= ".jpg";
+
+ if($debugOutput) {
+ print "thumbnail: $thumbnail ";
+ }
+
+ /* Fetch the thumbnail and save it to a local file */
+ if (empty($extraHeaders)) {
+ $extraHeaders = array('Referer' => str_replace('&', '&', $url));
+ }
+ list ($successfullyCopied, $response, $headers) =
+ GalleryCoreApi::fetchWebFile($thumbnail, $tmpFile, $extraHeaders);
+ if (!$successfullyCopied) {
+ return array(GalleryCoreApi::error(ERROR_STORAGE_FAILURE,__FILE__,__LINE__,
+ "Unable to copy thumbnail from url: $url"),null,null);
+ }
+
+ /* Obtain the mimeType of the thumbnail */
+ list ($ret, $mimeType) = GalleryCoreApi::getMimeType($tmpFile);
+
+ /* Set the filename for the item we want to add */
+ $fileName = $title;
+ $fileName = preg_replace("/\s+/","_",$fileName);
+ $fileName = preg_replace("/'/","",$fileName);
+ $fileName = preg_replace("/\"/","",$fileName);
+ $fileName = preg_replace("/\d+;/","",$fileName);
+
+ /* General debug output */
+ if($debugOutput) {
+ print "
";
+ print "thumbnail: $tmpFile ";
+ print "mimeType: $mimeType ";
+ print "fileName: $fileName ";
+ }
+
+ /* Make the gallery2 call to add this item to the album */
+ list ($ret, $newItem) = GalleryCoreApi::addItemToAlbum($tmpFile,
+ $fileName,
+ $title,
+ $summary,
+ $description,
+ $mimeType,
+ $item->getId());
+
+ if ($ret) {
+ return array($ret, null, null);
+ }
+
+ $status['addedFiles'][] = array('fileName' => $url,
+ 'id' => $newItem->getId(),
+ 'warnings' => array());
+ }
+ @$platform->unlink($tmpFile);
}
- return array(null, $module->translate('Embed Video'));
+ return array(null, $error, $status);
+ }
+
+ /**
+ * @see ItemAdd:loadTemplate
+ */
+ function loadTemplate(&$template, &$form, $item) {
+ global $gallery;
+
+ if ($form['formName'] != 'ItemAddEmbedVideo') {
+ /* First time around, load the form with item data */
+ $form['webPage'] = '';
+ $form['formName'] = 'ItemAddEmbedVideo';
+ }
+
+ $session =& $gallery->getSession();
+
+ $template->setVariable('ItemAddEmbedVideo', $ItemAddEmbedVideo);
+
+ return array(null,
+ 'modules/embedvideo/templates/ItemAddEmbedVideo.tpl',
+ 'modules_embedvideo');
+ }
+
+ /**
+ * @see ItemAddPlugin::getTitle
+ */
+ function getTitle() {
+ list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'embedvideo');
+ if ($ret) {
+ return array($ret, null);
+ }
+
+ return array(null, $module->translate('Embed Video'));
}
-}
-function get_feed($feed){
-
- //Open and return Feed with cURL for parsing
- $ch = curl_init();
- $timeout = 0;
- curl_setopt ($ch, CURLOPT_URL, $feed);
- curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
- $xml = curl_exec($ch);
- curl_close($ch);
+ /**
+ * ItemAddEmbedVideo::_getFeed
+ */
+ function _getFeed($feed) {
- return $xml;
-
-}
-
+ /* Open and return Feed with cURL for parsing */
+ $ch = curl_init();
+ $timeout = 0;
+ curl_setopt ($ch, CURLOPT_URL, $feed);
+ curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
+ $xml = curl_exec($ch);
+ curl_close($ch);
+
+ return $xml;
+ }
+
+}
?>
diff --git a/templates/EmbedVideoSiteAdmin.tpl b/templates/EmbedVideoSiteAdmin.tpl
index 74df8d2..c580ed5 100644
--- a/templates/EmbedVideoSiteAdmin.tpl
+++ b/templates/EmbedVideoSiteAdmin.tpl
@@ -1,5 +1,5 @@
{*
- * $Revision: 15342 $
+ * $Revision: 1 $
* If you want to customize this file, do not edit it directly since future upgrades
* may overwrite it. Instead, copy it into a new directory called "local" and edit that
* version. Gallery will look for that file first and use it if it exists.
@@ -130,6 +130,12 @@
height
240
{g->text text="specify the height dimension of the embedded video player"}
+
debugOutput
true|false
+
{g->text text="turn on module debug output"}
+
+
flvThumbnail
URL path
+
{g->text text="URL path to a jpg to use as a thumbnail for all directly linked/embedded flv files."}
+
diff --git a/templates/ItemAddEmbedVideo.tpl b/templates/ItemAddEmbedVideo.tpl
index 4c2c7ac..2180a76 100644
--- a/templates/ItemAddEmbedVideo.tpl
+++ b/templates/ItemAddEmbedVideo.tpl
@@ -1,5 +1,5 @@
{*
- * $Revision: 15342 $
+ * $Revision: 1 $
* If you want to customize this file, do not edit it directly since future upgrades
* may overwrite it. Instead, copy it into a new directory called "local" and edit that
* version. Gallery will look for that file first and use it if it exists.
--
2.34.1