1
0

It works! Cleaning up source and making tweaks. Will now concentrate making the input form more robust and adding support for more video sites.

This commit is contained in:
John Bowles 2010-08-26 21:52:15 -07:00
parent 83493c95d6
commit a2975fe6d7
6 changed files with 39 additions and 1188 deletions

View File

@ -18,77 +18,6 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class Embedded_videos_Controller extends Controller {
public function show($movie) {
if (!is_object($movie)) {
// show() must be public because we route to it in url::parse_url(), so make
// sure that we're actually receiving an object
throw new Kohana_404_Exception();
}
access::required("view", $movie);
$where = array(array("type", "!=", "album"));
$position = $movie->parent()->get_position($movie, $where);
if ($position > 1) {
list($previous_item, $ignore, $next_item) = $movie->parent()->children(3, $position - 2, $where);
} else {
$previous_item = null;
list($next_item) = $movie->parent()->viewable()->children(1, $position, $where);
}
$embedded_video = ORM::factory("embedded_video")->where("item_id", "=", $movie->id)->find();
//$db = Database::instance();
//$result = $db->from('embedded_videos')->select('embed_code')->where('item_id',$movie->id)->get();
$template = new Theme_View("page.html", "item", "embedded_video");
$template->set_global("item", $movie);
$template->set_global("embedded_video", $embedded_video->embed_code);
$template->set_global("children", array());
$template->set_global("children_count", 0);
$template->set_global("parents", $movie->parents());
$template->set_global("next_item", $next_item);
$template->set_global("previous_item", $previous_item);
$template->set_global("sibling_count", $movie->parent()->viewable()->children_count($where));
$template->set_global("position", $position);
$template->content = new View("embedded_video.html");
db::query("UPDATE {items} SET `view_count` = `view_count` + 1 WHERE `id` = $movie->id")->execute();
//$movie->view_count++;
//$movie->save();
print $template;
}
public function update($movie_id) {
access::verify_csrf();
$movie = ORM::factory("item", $movie_id);
access::required("view", $movie);
access::required("edit", $movie);
$form = embed_videos::get_edit_form($movie);
try {
$valid = $form->validate();
$movie->title = $form->edit_item->title->value;
$movie->description = $form->edit_item->description->value;
$movie->slug = $form->edit_item->slug->value;
//$movie->name = $form->edit_item->inputs["name"]->value;
$movie->validate();
}
catch(ORM_Validation_Exception $e) {
// Translate ORM validation errors into form error messages
foreach($e->validation->errors() as $key => $error) {
$form->edit_item->inputs[$key]->add_error($error, 1);
}
$valid = false;
}
if ($valid) {
$movie->save();
module::event("item_edit_form_completed", $movie, $form);
log::success("content", "Updated embed", "<a href=\"{$movie->url() }\">view</a>");
message::success(t("Saved embed %movie_title", array("movie_title" => $movie->title)));
if ($form->from_id->value == $movie->id) {
// Use the new url; it might have changed.
print json_encode(array("result" => "success", "location" => $movie->url()));
} else {
// Stay on the same page
print json_encode(array("result" => "success"));
}
} else {
print json_encode(array("result" => "error", "form" => (string)$form));
}
}
public function create($id) {
$album = ORM::factory("item", $id);
access::required("view", $album);
@ -138,7 +67,7 @@ class Embedded_videos_Controller extends Controller {
$item->slug = $form->add_embedded_video->slug->value;
$path_info = @pathinfo($temp_filename);
$item->save();
db::query("UPDATE {items} SET `type` = 'embedded_video' WHERE `id` = $item->id")->execute();
//db::query("UPDATE {items} SET `type` = 'embedded_video' WHERE `id` = $item->id")->execute();
$embedded_video->item_id = $item->id;
$embedded_video->validate();
$embedded_video->save();
@ -187,10 +116,4 @@ class Embedded_videos_Controller extends Controller {
access::required("add", $album);
print embed_videos::get_add_form($album);
}
public function form_edit($id) {
$embed = ORM::factory("item", $id);
access::required("view", $embed);
access::required("edit", $embed);
print embed_videos::get_edit_form($embed);
}
}

View File

@ -55,52 +55,4 @@ class embed_videos_Core {
return $form;
}
static function get_edit_form($photo) {
$form = new Forge("embedded_videos/update/$photo->id", "", "post", array("id" => "g-edit-embed-form"));
$form->hidden("from_id")->value($photo->id);
$group = $form->group("edit_item")->label(t("Edit Embedded Video"));
$group->input("title")->label(t("Title"))->value($photo->title)
->error_messages("required", t("You must provide a title"))
->error_messages("length", t("Your title is too long"));
$group->textarea("description")->label(t("Description"))->value($photo->description);
$group->input("slug")->label(t("Internet Address"))->value($photo->slug)
->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_edit_form", $photo, $form);
$group = $form->group("buttons")->label("");
$group->submit("")->value(t("Modify"));
return $form;
}
/**
* Return scaled width and height.
*
* @param integer $width
* @param integer $height
* @param integer $max the target size for the largest dimension
* @param string $format the output format using %d placeholders for width and height
*/
static function img_dimensions($width, $height, $max, $format="width=\"%d\" height=\"%d\"") {
if (!$width || !$height) {
return "";
}
if ($width > $height) {
$new_width = $max;
$new_height = (int)$max * ($height / $width);
} else {
$new_height = $max;
$new_width = (int)$max * ($width / $height);
}
return sprintf($format, $new_width, $new_height);
}
}
}

View File

@ -19,27 +19,6 @@
*/
class embed_videos_event_Core {
static function item_created($item) {
if ($item->type == "embedded_video") {
// Build our thumbnail/resizes.
try {
graphics::generate($item);
} catch (Exception $e) {
log::error("graphics", t("Couldn't create a thumbnail or resize for %item_title",
array("item_title" => $item->title)),
html::anchor($item->abs_url(), t("details")));
Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString());
}
// If the parent has no cover item, make this it.
$parent = $item->parent();
if (access::can("edit", $parent) && $parent->album_cover_item_id == null) {
item::make_album_cover($item);
}
}
}
static function item_deleted($item) {
ORM::factory("embedded_video")
->where("item_id", "=", $item->id)
@ -48,7 +27,6 @@ class embed_videos_event_Core {
}
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")

View File

@ -18,12 +18,17 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class embed_videos_theme_Core {
static function head($theme) {
static function photo_bottom($theme) {
$item = $theme->item();
if ($item) {
$view = new View("embed_video_js.html");
$view->item = $item;
return $view;
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;
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1 +1,27 @@
ohi
<?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("<?= $embed_code ?>");
//});
</script>
<? endif ?>