Merge branch 'master' of git://github.com/bowlesjd/gallery3-contrib
This commit is contained in:
commit
552f0c3988
138
modules/embed_videos/controllers/embedded_videos.php
Normal file
138
modules/embed_videos/controllers/embedded_videos.php
Normal file
@ -0,0 +1,138 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2010 Bharat Mediratta
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
class Embedded_videos_Controller extends Controller {
|
||||
public function create($id) {
|
||||
$album = ORM::factory("item", $id);
|
||||
access::required("view", $album);
|
||||
access::required("add", $album);
|
||||
access::verify_csrf();
|
||||
$form = embed_videos::get_add_form($album);
|
||||
$temp_filename = "";
|
||||
|
||||
// Yes, this is a mess.
|
||||
$youtubeUrlPattern="youtube";
|
||||
$youtubeThumbnailUrl="http://img.youtube.com/vi/";
|
||||
// End mess
|
||||
|
||||
batch::start();
|
||||
try {
|
||||
$valid = $form->validate();
|
||||
if ($form->add_embedded_video->inputs['video_url']->value != "") {
|
||||
$title = $form->add_embedded_video->inputs['title']->value;
|
||||
$description = $form->add_embedded_video->inputs['description']->value;
|
||||
$valid_url=false;
|
||||
$embedded_video = ORM::factory("embedded_video");
|
||||
$item = ORM::factory("item");
|
||||
$item->type = "photo";
|
||||
$url = $form->add_embedded_video->inputs['video_url']->value;
|
||||
if(preg_match("/$youtubeUrlPattern/",$url)) {
|
||||
$video_id = 0;
|
||||
if (preg_match("/watch\?v=(.*?)(&\S+=\S+)/",$url,$matches)) {
|
||||
$video_id = $matches[1];
|
||||
} else if (preg_match("/watch\?v=(.*)/",$url,$matches)) {
|
||||
$video_id = $matches[1];
|
||||
} else if (preg_match("/v\/(.*)/",$url,$matches)) {
|
||||
$video_id = $matches[1];
|
||||
}
|
||||
if ($video_id) {
|
||||
$video_id = $matches[1];
|
||||
$embedded_video->embed_code = '<iframe class="youtube-player" type="text/html" width="640" height="385" src="http://www.youtube.com/embed/' . $video_id . '" frameborder="0"></iframe>';
|
||||
$embedded_video->source = "YouTube";
|
||||
$content = file_get_contents("http://img.youtube.com/vi/" . $video_id . "/0.jpg");
|
||||
$itemname = "youtube_" . $video_id . ".jpg";
|
||||
$temp_filename = VARPATH . "tmp/$itemname";
|
||||
if ($content) {
|
||||
$valid_url = true;
|
||||
$sxml = simplexml_load_file("http://gdata.youtube.com/feeds/api/videos/$video_id");
|
||||
if ($sxml) {
|
||||
if ($title == '') {
|
||||
$title = (string)$sxml->title;
|
||||
}
|
||||
if ($description == '') {
|
||||
$description = (string)$sxml->content;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//$item->validate();
|
||||
//$content = file_get_contents("http://img.youtube.com/vi/" . $form->add_embedded_video->inputs['name']->value . "/0.jpg");
|
||||
if ($valid_url) {
|
||||
$file = fopen($temp_filename, "wb");
|
||||
fwrite($file, $content);
|
||||
fclose($file);
|
||||
gallery_graphics::composite($temp_filename, $temp_filename, array("file" => "modules/embed_videos/images/embed_video_icon.png", "position" => "center", "transparency" => 95));
|
||||
$item->set_data_file($temp_filename);
|
||||
$item->name = basename($itemname);
|
||||
$item->title = $title;
|
||||
$item->parent_id = $album->id;
|
||||
$item->description = $description;
|
||||
$item->slug = $form->add_embedded_video->inputs['slug']->value;
|
||||
$path_info = @pathinfo($temp_filename);
|
||||
$item->save();
|
||||
$embedded_video->item_id = $item->id;
|
||||
$embedded_video->validate();
|
||||
$embedded_video->save();
|
||||
log::success("content", t("Added a embedded video"), html::anchor("embeds/$item->id", t("view video")));
|
||||
module::event("add_event_form_completed", $item, $form);
|
||||
} else {
|
||||
$form->add_embedded_video->inputs['video_url']->add_error('invalid_id', 1);
|
||||
$valid = false;
|
||||
}
|
||||
} else {
|
||||
$form->add_embedded_video->inputs['video_url']->add_error('invalid_id', 1);
|
||||
$valid = false;
|
||||
}
|
||||
}
|
||||
catch(Exception $e) {
|
||||
// Lame error handling for now. Just record the exception and move on
|
||||
Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString());
|
||||
// Ugh. I hate to use instanceof, But this beats catching the exception separately since
|
||||
// we mostly want to treat it the same way as all other exceptions
|
||||
if ($e instanceof ORM_Validation_Exception) {
|
||||
Kohana_Log::add("error", "Validation errors: " . print_r($e->validation->errors(), 1));
|
||||
foreach($e->validation->errors() as $key => $error) {
|
||||
$form->add_embed->inputs[$key]->add_error($error, 1);
|
||||
}
|
||||
$valid = false;
|
||||
}
|
||||
if (file_exists($temp_filename)) {
|
||||
unlink($temp_filename);
|
||||
}
|
||||
}
|
||||
if (file_exists($temp_filename)) {
|
||||
unlink($temp_filename);
|
||||
}
|
||||
batch::stop();
|
||||
if ($valid) {
|
||||
//print json_encode(array("result" => "success"));
|
||||
json::reply(array("result" => "success", "location" => $item->url()));
|
||||
} else {
|
||||
//json::reply(array("result" => "error", "form" => (string)$form));
|
||||
print $form;
|
||||
}
|
||||
}
|
||||
public function form_add($album_id) {
|
||||
$album = ORM::factory("item", $album_id);
|
||||
access::required("view", $album);
|
||||
access::required("add", $album);
|
||||
print embed_videos::get_add_form($album);
|
||||
}
|
||||
}
|
57
modules/embed_videos/helpers/embed_videos.php
Normal file
57
modules/embed_videos/helpers/embed_videos.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2010 Bharat Mediratta
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This is the API for handling embedded videos.
|
||||
*
|
||||
* Note: by design, this class does not do any permission checking.
|
||||
*/
|
||||
class embed_videos_Core {
|
||||
|
||||
static function get_add_form($album) {
|
||||
$form = new Forge("embedded_videos/create/{$album->id}", "", "post", array("id" => "g-add-embed-form"));
|
||||
$group = $form->group("add_embedded_video")
|
||||
->label(t("Add embedded video to %album_title", array("album_title" => $album->title)));
|
||||
$group->input("title")->label(t("Title"))
|
||||
->error_messages("required", t("You must provide a title"))
|
||||
->error_messages("length", t("Your title is too long"));
|
||||
$group->input("video_url")->label(t("Video URL"))
|
||||
->error_messages(
|
||||
"conflict", t("There is already a movie with this ID"))
|
||||
->error_messages("required", t("You must provide a URL"))
|
||||
->error_messages("invalid_id", t("Invalid URL"));
|
||||
$group->textarea("description")->label(t("Description"));
|
||||
$group->input("slug")->label(t("Internet Address"))
|
||||
->error_messages(
|
||||
"conflict", t("There is already a movie, photo or album with this internet address"))
|
||||
->error_messages(
|
||||
"not_url_safe",
|
||||
t("The internet address should contain only letters, numbers, hyphens and underscores"))
|
||||
->error_messages("required", t("You must provide an internet address"))
|
||||
->error_messages("length", t("Your internet address is too long"));
|
||||
|
||||
module::event("item_add_form", $album, $form);
|
||||
|
||||
$group = $form->group("buttons")->label("");
|
||||
$group->submit("")->value(t("Add"));
|
||||
|
||||
return $form;
|
||||
}
|
||||
}
|
38
modules/embed_videos/helpers/embed_videos_event.php
Normal file
38
modules/embed_videos/helpers/embed_videos_event.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2010 Bharat Mediratta
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
class embed_videos_event_Core {
|
||||
static function item_deleted($item) {
|
||||
ORM::factory("embedded_video")
|
||||
->where("item_id", "=", $item->id)
|
||||
->find()
|
||||
->delete();
|
||||
}
|
||||
static function site_menu($menu, $theme) {
|
||||
$item = $theme->item();
|
||||
if ($can_add = $item && access::can("add", $item)) {
|
||||
$menu->get("add_menu")
|
||||
->append(Menu::factory("dialog")
|
||||
->id("embed_add")
|
||||
->label(t("Embed Video"))
|
||||
->url(url::site("form/add/embedded_videos/$item->id")));
|
||||
}
|
||||
}
|
||||
}
|
44
modules/embed_videos/helpers/embed_videos_installer.php
Normal file
44
modules/embed_videos/helpers/embed_videos_installer.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2010 Bharat Mediratta
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
class embed_videos_installer {
|
||||
static function install() {
|
||||
$db = Database::instance();
|
||||
$db->query("CREATE TABLE {embedded_videos} (
|
||||
`id` int(9) NOT NULL auto_increment,
|
||||
`embed_code` varchar(2048) DEFAULT NULL,
|
||||
`source` varchar(64) DEFAULT NULL,
|
||||
`item_id` int(9) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY (`item_id`, `id`))
|
||||
DEFAULT CHARSET=utf8;");
|
||||
module::set_version("embed_videos", 2);
|
||||
//exec("cd modules/gallery/controllers/; ln -s ../../embed/controllers/embeds.php embeds.php");
|
||||
}
|
||||
|
||||
static function deactivate() {
|
||||
|
||||
}
|
||||
static function uninstall() {
|
||||
$db = Database::instance();
|
||||
$db->query("DROP TABLE IF EXISTS {embedded_videos};");
|
||||
module::delete("embed_videos");
|
||||
}
|
||||
}
|
34
modules/embed_videos/helpers/embed_videos_theme.php
Normal file
34
modules/embed_videos/helpers/embed_videos_theme.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2010 Bharat Mediratta
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
class embed_videos_theme_Core {
|
||||
static function head($theme) {
|
||||
$item = $theme->item();
|
||||
if ($item && $item->is_photo()) {
|
||||
$embedded_video = ORM::factory("embedded_video")
|
||||
->where("item_id", "=", $item->id)
|
||||
->find();
|
||||
if ($embedded_video->loaded()) {
|
||||
$view = new View("embed_video_js.html");
|
||||
$view->embed_code = addslashes($embedded_video->embed_code);
|
||||
return $view;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
BIN
modules/embed_videos/images/embed_video_icon.png
Normal file
BIN
modules/embed_videos/images/embed_video_icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.7 KiB |
25
modules/embed_videos/models/embedded_video.php
Normal file
25
modules/embed_videos/models/embedded_video.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2010 Bharat Mediratta
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
class Embedded_video_Model extends ORM {
|
||||
public function __construct($id=null) {
|
||||
parent::__construct($id);
|
||||
}
|
||||
}
|
3
modules/embed_videos/module.info
Normal file
3
modules/embed_videos/module.info
Normal file
@ -0,0 +1,3 @@
|
||||
name = "Embed Videos"
|
||||
description = "Allows users to embed videos"
|
||||
version = 2
|
27
modules/embed_videos/views/embed_video_js.html.php
Normal file
27
modules/embed_videos/views/embed_video_js.html.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.")
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2010 Bharat Mediratta
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
?>
|
||||
<? if (isset($embed_code)): ?>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
$("#g-photo").replaceWith("<div id=\"g-movie\" class=\"ui-helper-clearfix\"><?= $embed_code ?></div>");
|
||||
});
|
||||
</script>
|
||||
<? endif ?>
|
Reference in New Issue
Block a user