1
0

Remove 3.1 dir - we're nowhere close to 3.1 and this is just causing confusion.

This commit is contained in:
Bharat Mediratta 2012-02-27 09:50:35 -08:00
parent 8c0ec05c1e
commit a113a0a2e1
1860 changed files with 0 additions and 135955 deletions

Binary file not shown.

View File

@ -1,50 +0,0 @@
import java.util.ArrayList;
import java.util.List;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import com.google.gson.Gson;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.cookie.Cookie;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
public class Demo {
public static final String BASE_URL = "http://example.com/gallery3/index.php";
public static final String USERNAME = "admin";
public static final String PASSWORD = "admin";
public static void main(String[] argv) throws java.io.UnsupportedEncodingException, java.io.IOException {
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpResponse response;
Gson gson = new Gson();
// Get the REST API key
HttpPost post = new HttpPost(BASE_URL + "/rest");
ArrayList<NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("user", USERNAME));
nvps.add(new BasicNameValuePair("password", USERNAME));
post.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
response = httpclient.execute(post);
String api_key = gson.fromJson(new BufferedReader(
new InputStreamReader(response.getEntity().getContent())).readLine(), String.class);
System.out.println("API Key:" + api_key);
// Get the JSON representation of the root album, which we know has id 1
HttpGet get = new HttpGet(BASE_URL + "/rest/item/1");
get.setHeader("X-Gallery-Request-Method", "GET");
get.setHeader("X-Gallery-Request-Key", api_key);
response = httpclient.execute(get);
System.out.println(
"Response: " + new BufferedReader(new InputStreamReader(response.getEntity().getContent())).readLine());
}
}

View File

@ -1,10 +0,0 @@
This is very, very rough sample code for how to do some Java REST
requests. To run this code:
1) Edit Demo.java and set the BASE_URL to your Gallery3 install.
2) Edit USERNAME and PASSWORD as appropriate
3) In a shell, do "sh build.sh"
4) In a shell, do "sh run.sh"
Note that there is NO error checking, so if something goes wrong
you'll have to debug it.

View File

@ -1 +0,0 @@
javac -classpath lib/httpclient-4.0.1.jar:lib/httpcore-4.0.1.jar:lib/gson-1.4.jar Demo.java

Binary file not shown.

View File

@ -1 +0,0 @@
java -classpath lib/httpclient-4.0.1.jar:lib/httpcore-4.0.1.jar:lib/commons-logging-api-1.1.1.jar:lib/gson-1.4.jar:. Demo

View File

@ -1,2 +0,0 @@
# local file to provide configuration for the client code. See README.
local_config.php

View File

@ -1,205 +0,0 @@
<?php
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2011 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.
*/
include("Mail.php");
include("Mail/mime.php");
include("HTTP/Request.php");
class Gallery3 {
var $url;
var $token;
var $data;
var $file;
protected $original_entity;
/**
* Connect to a remote Gallery3 instance
*
* @param string Gallery 3 API url, eg http://example.com/gallery3/index.php/rest
* @param string username
* @param string password
* @return string authentication token
*/
static function login($url, $user, $pass) {
$response = Gallery3_Helper::request(
"post", $url, null, array("user" => $user, "password" => $pass));
return $response;
}
/**
* Construct a new Gallery3 instance associated with a remote resource
* @param string remote url
* @param string authentication token
* @return object Gallery3
*/
static function factory($url=null, $token=null) {
$obj = new Gallery3();
$obj->token = $token;
$obj->url = $url;
if ($url && $token) {
$obj->load();
}
return $obj;
}
/**
* Constructor.
*/
public function __construct() {
$this->data = new stdClass();
$this->token = null;
$this->url = null;
}
/**
* Set a value on the remote resource's entity. You must call save for it to take effect.
*
* @param string key
* @param string value
* @return object Gallery3
* @chainable
*/
public function set($key, $value) {
$this->data->entity->$key = $value;
return $this;
}
/**
* Replace the members for the remote resource
*
* @param array members
* @return object Gallery3
* @chainable
*/
public function set_members($members) {
$this->data->members = $members;
return $this;
}
/**
* Attach a file to the remote resource.
*
* @param string path to a local file (eg: /tmp/foo.jpg)
* @return object Gallery3
*/
public function set_file($file) {
$this->file = $file;
return $this;
}
/**
* Save any local changes made to this resource. If this is an existing resource, we'll return
* the resource itself. If we're creating a new resource, return the newly created resource.
*
* @return object Gallery3
*/
public function create($url, $token) {
if (!is_string($url)) {
throw new Gallery3_Exception("Invalid url: " . var_export($url));
}
$response = Gallery3_Helper::request(
"post", $url, $token, array("entity" => $this->data->entity), $this->file);
$this->url = $response->url;
$this->token = $token;
return $this->load();
}
/**
* Save any local changes made to this resource. If this is an existing resource, we'll return
* the resource itself. If we're creating a new resource, return the newly created resource.
*
* @return object Gallery3
*/
public function save() {
$data = array();
$data["entity"] = array_diff((array)$this->data->entity, $this->original_entity);
if (isset($this->data->members)) {
$data["members"] = $this->data->members;
}
if ($this->file) {
$response = Gallery3_Helper::request("put", $this->url, $this->token, $data, $this->file);
} else {
$response = Gallery3_Helper::request("put", $this->url, $this->token, $data);
}
return $this->load();
}
/**
* Delete the remote resource.
*
* @return object Gallery3
*/
public function delete() {
Gallery3_Helper::request("delete", $this->url, $this->token);
$this->data = array();
$this->url = null;
return $this;
}
/**
* Reload the resource from a given url. This is useful after the remote resource has been
* modified.
*
* @return object Gallery3
*/
public function load() {
$response = Gallery3_Helper::request("get", $this->url, $this->token);
$this->data = $response;
$this->original_entity = isset($response->entity) ? (array)$response->entity : null;
return $this;
}
}
class Gallery3_Helper {
static function request($method, $url, $token=null, $params=array(), $file=null) {
$req = new HTTP_Request($url);
$req->setMethod($method == "get" ? HTTP_REQUEST_METHOD_GET : HTTP_REQUEST_METHOD_POST);
$req->addHeader("X-Gallery-Request-Method", $method);
if ($token) {
$req->addHeader("X-Gallery-Request-Key", $token);
}
foreach ($params as $key => $value) {
$req->addPostData($key, is_string($value) ? $value : json_encode($value));
}
if ($file) {
$req->addFile("file", $file, mime_content_type($file));
}
$req->sendRequest();
switch ($req->getResponseCode()) {
case 200:
case 201:
return json_decode($req->getResponseBody());
case 403:
throw new Gallery3_Forbidden_Exception($req->getResponseBody());
default:
throw new Gallery3_Exception($req->getResponseBody());
}
}
}
class Gallery3_Exception extends Exception {
}
class Gallery3_Forbidden_Exception extends Gallery3_Exception {
}

View File

@ -1,4 +0,0 @@
# Create a local file called local_config.php and add the following content:
$SITE_URL = "http://<your domain>/gallery3/index.php/rest";
$USER = "<user admin Id>";
$PASSWORD = "<user admin password>";

View File

@ -1,112 +0,0 @@
<?
include("Gallery3.php");
$SITE_URL = "http://example.com/gallery3/index.php/rest";
$USER = "admin";
$PASSWORD = "admin";
if (file_exists("local_config.php")) {
include("local_config.php");
}
alert("Connect to $SITE_URL");
$auth = Gallery3::login($SITE_URL, $USER, $PASSWORD);
$root = Gallery3::factory("$SITE_URL/item/1", $auth);
$tags = Gallery3::factory("$SITE_URL/tags", $auth);
$comments = Gallery3::factory("$SITE_URL/comments", $auth);
$tag = Gallery3::factory()
->set("name", "My Tag")
->create($tags->url, $auth);
alert("Created tag: <b>{$tag->url}</b>");
$album = Gallery3::factory()
->set("type", "album")
->set("name", "Sample Album")
->set("title", "This is my Sample Album")
->create($root->url, $auth);
alert("Created album: <b>{$album->url} {$album->data->entity->title}</b>");
alert("Modify the album");
$album
->set("title", "This is the new title")
->save();
alert("New title: <b>{$album->data->entity->title}</b>");
for ($i = 0; $i < 2; $i++) {
$photo = Gallery3::factory()
->set("type", "photo")
->set("name", "Sample Photo.png")
->set("title", "Sample Photo")
->set_file("test1.png")
->create($album->url, $auth);
alert("Uploaded photo: <b>{$photo->url}</b>");
}
$album->load();
alert("Album members: <b>" . join(", ", $album->data->members) . "</b>");
alert("Replace the data file");
$photo->set_file("test2.png")
->save();
$comment = Gallery3::factory()
->set("item", $album->data->members[0])
->set("type", "comment")
->set("text", "This is a random comment-- whee!")
->create($comments->url, $auth);
alert("Comment: <b>{$comment->url}</b>");
alert("Reorder the album");
$album
->set_members(array($album->data->members[1], $album->data->members[0]))
->set("sort_column", "weight")
->save();
alert("New order: <b>" . join(", ", $album->data->members) . "</b>");
alert("Search for the photo");
$photos = Gallery3::factory($root->url, $auth)
->set("name", "Sample")
->load();
alert("Found: {$photos->data->members[0]}");
alert("Grab a random photo");
$photos = Gallery3::factory("{$root->url}?random=true", $auth)
->load();
alert("Found: {$photos->data->members[0]}");
alert("Tag the album (using the album's relationships: {$album->data->relationships->tags->url})");
$tag_relationship1 = Gallery3::factory()
->set("tag", $tag->url)
->set("item", $root->url)
->create($album->data->relationships->tags->url, $auth);
alert("Tag: {$tag_relationship1->url}");
alert("Tag the photo (using the tag's relationships: {$tag->data->relationships->items->url})");
$tag_relationship2 = Gallery3::factory()
->set("tag", $tag->url)
->set("item", $photo->url)
->create($tag->data->relationships->items->url, $auth);
alert("Tag: {$tag_relationship2->url}");
alert("Un-tag the photo");
$tag_relationship2->delete();
$tag->load();
alert("1 remaining tag: <b>{$tag->data->relationships->items->members[0]}</b>");
alert("Delete the album and tag");
$album->delete();
$tag->delete();
alert("Done!");
function alert($msg) {
print "$msg <br/>\n";
flush();
}
?>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.3 KiB

View File

@ -1,76 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2011 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 about_this_album_block_Core {
static function get_site_list() {
return array("aboutthisalbum" => t("About This Album"));
}
static function get($block_id, $theme) {
switch ($block_id) {
case "aboutthisalbum":
$item = $theme->item;
if ((!$item) or (!$theme->item->is_album())) {
return "";
}
if ($theme->item->is_album()) {
$block = new Block();
$block->css_id = "g-about-this-album";
$block->content = new View("about_this_album.html");
if ($theme->item()->id == item::root()->id) {
$block->title = t("About this Site");
$block->content->album_count = ORM::factory("item")->where("type", "=", "album")->where("id", "<>", 1)->count_all();
$block->content->photo_count = ORM::factory("item")->where("type", "=", "photo")->count_all();
$block->content->vcount = Database::instance()->query("SELECT SUM({items}.view_count) as c FROM {items} WHERE type=\"photo\"")->current()->c;
} Else {
$block->title = t("About this Album");
$block->content->album_count = $item->descendants_count(array(array("type", "=", "album")));
$block->content->photo_count = $item->descendants_count(array(array("type", "=", "photo")));
// $block->content->vcount= $theme->item()->view_count;
$descds = $item->descendants();
$descds_view = 0;
foreach ($descds as $descd) {
if ($descd->is_photo()) {
$descds_view += $descd->view_count;
}
}
$block->content->vcount = $descds_view;
if ($item->description) {
$block->content->description = html::clean($item->description);
}
}
$all_tags = ORM::factory("tag")
->join("items_tags", "items_tags.tag_id", "tags.id")
->join("items", "items.id", "items_tags.item_id", "LEFT")
->where("items.parent_id", "=", $item->id)
->order_by("tags.id", "ASC")
->find_all();
if (count($all_tags) > 0) {
$block->content->all_tags = $all_tags;
}
}
break;
}
return $block;
}
}

View File

@ -1,7 +0,0 @@
name = "About this Album"
description = "Show some simple, specific and useful info about a given album"
version = 1
author_name = ""
author_url = ""
info_url = "http://codex.gallery2.org/Gallery3:Modules:about_this_album"
discuss_url = "http://gallery.menalto.com/forum_module_about_this_album"

View File

@ -1,68 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<? date_default_timezone_set('Australia/ACT'); ?>
<div class="g-metadata">
<span class="g-about-this">
<table cellspacing="0" cellpadding="0" border="0">
<? if ($album_count > 0): ?>
<tr>
<td><strong class="caption"><?= t("Albums:&nbsp;") ?></strong></td>
<td><?= $album_count ?></td>
</tr>
<? endif ?>
<tr>
<td><strong class="caption"><?= t("Images:&nbsp;") ?></strong></td>
<td><?= $photo_count ?></td>
</tr>
<tr>
<td><strong class="caption"><?= t("Views:&nbsp;") ?></strong></td>
<td><?= $vcount ?></td>
</tr>
</table>
<span >
<!--This Div will insert a margin either side of the desciption if there are tags to display-->
<? if (count($all_tags) > 0): ?>
<div style="margin-top: 10px; margin-bottom: 10px;">
<? endif ?>
<? if ($description <> ""): ?>
<strong class="caption"><?= t("Details:&nbsp;") ?></strong>
<?= $description ?>
</span ><br>
<? endif ?>
<? if (count($all_tags) > 0): ?>
</div>
<span >
<strong class=="caption"><?= t("Tags:&nbsp;") ?></strong>
</span >
<?
// Create an array to store the tag names and urls in.
$display_tags = array();
// Loop through all tags in the album, copying their
// names and urls into the array and skipping duplicates.
$last_tagid = "";
foreach ($all_tags as $one_tag) {
if ($last_tagid != $one_tag->id) {
$tag = ORM::factory("tag", $one_tag->id);
$display_tags[] = array(html::clean($tag->name), $tag->url());
$last_tagid = $one_tag->id;
}
}
// Sort the array.
asort($display_tags);
// Print out the list of tags as clickable links.
$not_first = 0;
foreach ($display_tags as $one_tag) {
if ($not_first++ > 0) {
print ", ";
}
print "<a href=\"" . $one_tag[1] . "\">" . $one_tag[0] . "</a>";
}
?>
<? endif ?>
</span>
</div>

View File

@ -1,71 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2011 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 about_this_photo_block_Core {
static function get_site_list() {
return array("simple" => t("About This Photo"));
}
static function get($block_id, $theme) {
$block = new Block();
switch ($block_id) {
case "simple":
$item = $theme->item;
if ((!$item) or (!$item->is_photo())) {
return "";
}
$block->css_id = "g-about-this-photo";
$block->title = t("About this photo");
$block->content = new View("about_this_photo.html");
// exif API doesn't give easy access to individual keys, so do this the hard way
if (module::is_active("exif")) {
$exif = ORM::factory("exif_record")->where("item_id", "=", $theme->item()->id)->find();
if ($exif->loaded()) {
$exif = unserialize($exif->data);
$timestamp = strtotime($exif["DateTime"]);
//$block->content->date = gallery::date($timestamp);
$block->content->date = date('D j M Y', $timestamp);
$block->content->time = gallery::time($timestamp);
}
}
$block->content->vcount = $theme->item()->view_count;
// IPTC - copied more or less from iptc.php
if (module::is_active("iptc")) {
$record = ORM::factory("iptc_record")->where("item_id", "=", $theme->item()->id)->find();
if ($record->loaded()) {
$record = unserialize($record->data);
$block->content->name = $record["ObjectName"];
$block->content->caption = $record["Caption"];
}
}
if (module::is_active("tag")) {
$block->content->tags = tag::item_tags($theme->item());
}
break;
}
return $block;
}
}

View File

@ -1,7 +0,0 @@
name = "About this Photo"
description = "Show some simple, specific and useful info about a given photo"
version = 3
author_name = ""
author_url = ""
info_url = "http://codex.gallery2.org/Gallery3:Modules:about_this_photo"
discuss_url = "http://gallery.menalto.com/forum_module_about_this_photo"

View File

@ -1,34 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<? date_default_timezone_set('Australia/ACT'); ?>
<div class="g-metadata">
<span class="g-about-this">
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td><strong class="caption"><?= t("Date:&nbsp;") ?></strong></td>
<td><?= $date ?></td>
</tr>
<tr>
<td><strong class="caption"><?= t("Time:&nbsp;") ?></strong></td>
<td><?= $time ?></td>
</tr>
<tr>
<td><strong class="caption"><?= t("Views:&nbsp;") ?></strong></td>
<td><?= $vcount ?></td>
</tr>
<tr>
<td><strong class="caption"><?= t("Name:&nbsp;") ?></strong></td>
<td><?= $name ?></td>
</tr>
</table>
<div style="margin-top: 10px; margin-bottom: 10px;">
<strong class="caption"><?= t("Caption:&nbsp;") ?></strong>
<?= $caption ?>
</div >
<span >
<strong class=="caption"><?= t("Tags: &nbsp;&nbsp;") ?></strong>
<? foreach ($tags as $tag): ?>
<a href="<?= $tag->url() ?>"><?= html::clean($tag->name) ?></a>,
<? endforeach?>
</span ><br>
</span>
</div>

View File

@ -1,57 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2011 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 Admin_adsense_Controller extends Admin_Controller {
public function index() {
$view = new Admin_View("admin.html");
$view->page_title = t("Adsense settings");
$view->content = new View("admin_adsense.html");
$view->content->form = $this->_get_admin_form();
print $view;
}
public function save() {
access::verify_csrf();
$form = $this->_get_admin_form();
if ($form->validate()) {
module::set_var("adsense", "code", $form->adsense->code->value);
module::set_var("adsense", "location", $form->adsense->location->value);
message::success(t("Adsense settings updated"));
url::redirect("admin/adsense");
} else {
print $form;
}
}
private function _get_admin_form() {
$form = new Forge("admin/adsense/save", "", "post", array("id" => "g-adsense-admin-form"));
$adsense_settings = $form->group("adsense")->label(t("Adsense settings"));
$adsense_settings->textarea("code")->label(t("Adsense code"))
->value(module::get_var("adsense", "code"));
$adsense_settings->dropdown("location")
->label(t("Where should the ads be displayed?"))
->options(array("header" => t("In the header"),
"sidebar" => t("In the sidebar"),
"footer" => t("In the footer")))
->selected(module::get_var("adsense", "location"));
$adsense_settings->submit("save")->value(t("Save"));
return $form;
}
}

View File

@ -1,39 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2009 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 adsense_block_Core {
static function get_site_list() {
return array("adsense" => t("Adsense"));
}
static function get($block_id, $theme) {
$block = "";
switch ($block_id) {
case "adsense":
if (module::get_var("adsense", "location") == "sidebar") {
$block = new Block();
$block->css_id = "g-adsense";
$block->title = t("Adsense");
$block->content = new View("adsense_block.html");
}
break;
}
return $block;
}
}

View File

@ -1,28 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2011 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 adsense_event_Core {
static function admin_menu($menu, $theme) {
$menu->get("settings_menu")
->append(Menu::factory("link")
->id("adsense_menu")
->label(t("Adsense"))
->url(url::site("admin/adsense")));
}
}

View File

@ -1,54 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2011 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.
*/
//header_bottom or footer
class adsense_theme {
static function header_bottom($theme) {
if(module::get_var("adsense","location") == "header") {
$code = module::get_var("adsense", "code");
if (!$code) {
return;
}
$google_code = '
<script type="text/javascript">' . $code . '</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>';
return $google_code;
}
}
static function footer($theme) {
if(module::get_var("adsense","location") == "footer") {
$code = module::get_var("adsense", "code");
if (!$code) {
return;
}
$google_code = '
<script type="text/javascript">' . $code . '</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>';
return $google_code;
}
}
}

View File

@ -1,7 +0,0 @@
name = "Adsense"
description = "Display Google Adsense ads"
version = 1
author_name = ""
author_url = ""
info_url = "http://codex.gallery2.org/Gallery3:Modules:adsense"
discuss_url = "http://gallery.menalto.com/forum_module_adsense"

View File

@ -1,7 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<div class="g-block">
<h1> <?= t("Adsense settings") ?> </h1>
<div class="g-block-content">
<?= $form ?>
</div>
</div>

View File

@ -1,17 +0,0 @@
<?php
defined("SYSPATH") or die("No direct script access.");
if(module::get_var("adsense","location") == "sidebar") {
$code = module::get_var("adsense", "code");
if (!$code) {
return;
}
$google_code = '
<script type="text/javascript">' . $code . '</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>';
echo $google_code;
}
?>

View File

@ -1,69 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2011 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 Admin_Albumpassword_Controller extends Admin_Controller {
public function index() {
// Generate a new admin page.
$view = new Admin_View("admin.html");
$view->content = new View("admin_albumpassword.html");
// Generate a form for controlling the admin section.
$view->content->albumpassword_form = $this->_get_admin_form();
// Display the page.
print $view;
}
private function _get_admin_form() {
// Make a new form for changing admin settings for this module.
$form = new Forge("admin/albumpassword/saveprefs", "", "post",
array("id" => "g-album-password-admin-form"));
// Should protected items be hidden, or completely in-accessable?
$albumpassword_group = $form->group("album_password_group");
$albumpassword_group->checkbox("hideonly")
->label(t("Do not require passwords"))
->checked(module::get_var("albumpassword", "hideonly"));
// Add a save button to the form.
$albumpassword_group->submit("save_settings")->value(t("Save"));
// Return the newly generated form.
return $form;
}
public function saveprefs() {
// Save user specified preferences.
// Prevent Cross Site Request Forgery
access::verify_csrf();
// Retrieve submitted form data.
if (Input::instance()->post("hideonly") == false) {
module::set_var("albumpassword", "hideonly", false);
} else {
module::set_var("albumpassword", "hideonly", true);
}
// Display a success message and redirect back to the TagsMap admin page.
message::success(t("Your settings have been saved."));
url::redirect("admin/albumpassword");
}
}

View File

@ -1,181 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2011 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 albumpassword_Controller extends Controller {
public function assign($id) {
// Display prompt for assigning a new password.
// Make sure user has view/edit access for this item.
$item = ORM::factory("item", $id);
access::required("view", $item);
access::required("edit", $item);
// Create the page.
$view = new View("assignpassword.html");
$view->form = $this->_get_password_form($id);
print $view;
}
public function login() {
// Display prompt to allow visitors to use their passwords.
// Create the page.
$view = new View("loginpassword.html");
$view->form = $this->_get_login_form();
print $view;
}
public function remove($id) {
// Remove a password from an album
// Make sure user has view/edit privileges for this item
$item = ORM::factory("item", $id);
access::required("view", $item);
access::required("edit", $item);
// Check for and delete the password and any cached ids assigned to it.
$existing_password = ORM::factory("items_albumpassword")->where("album_id", "=", $id)->find_all();
if (count($existing_password) > 0) {
foreach ($existing_password as $one_password) {
db::build()->delete("albumpassword_idcaches")->where("password_id", "=", $one_password->id)->execute();
}
db::build()->delete("items_albumpasswords")->where("album_id", "=", $id)->execute();
message::success(t("Password Removed."));
}
// Redirect the user back to the album.
url::redirect(url::abs_site("albums/" . $id));
}
public function savepassword() {
// Save a newly assigned password.
// Prevent Cross Site Request Forgery
access::verify_csrf();
// Convert submitted data to local variables.
$album_id = Input::instance()->post("item_id");
$album_password = strtolower(Input::instance()->post("assignpassword_password"));
// Check for, and remove, any existing passwords and cached ids.
$existing_password = ORM::factory("items_albumpassword")->where("album_id", "=", $album_id)->find_all();
if (count($existing_password) > 0) {
foreach ($existing_password as $one_password) {
db::build()->delete("albumpassword_idcaches")->where("password_id", "=", $one_password->id)->execute();
}
db::build()->delete("items_albumpasswords")->where("album_id", "=", $album_id)->execute();
}
// Save the new password.
$new_password = ORM::factory("items_albumpassword");
$new_password->album_id = $album_id;
$new_password->password = $album_password;
$new_password->save();
// Add the album to the id cache.
$cached_album = ORM::factory("albumpassword_idcache");
$cached_album->password_id = $new_password->id;
$cached_album->item_id = $album_id;
$cached_album->save();
// Check for any sub-items within the album, add all of them to the id cache.
$items = ORM::factory("item", $album_id)
->viewable()
->descendants();
if (count($items) > 0) {
foreach ($items as $one_item) {
$cached_item = ORM::factory("albumpassword_idcache");
$cached_item->password_id = $new_password->id;
$cached_item->item_id = $one_item->id;
$cached_item->save();
}
}
// Display a success message and close the dialog.
message::success(t("Password saved."));
json::reply(array("result" => "success"));
}
public function logout() {
// Delete a stored password cookie.
cookie::delete("g3_albumpassword");
cookie::delete("g3_albumpassword_id");
url::redirect(url::abs_site("albums/1"));
}
public function checkpassword() {
// Check that a password is valid, then store in a browser cookie.
// Prevent Cross Site Request Forgery
access::verify_csrf();
// Convert submitted data to local variables.
$album_password = strtolower(Input::instance()->post("albumpassword_password"));
// See if the submitted password matches any in the database.
$existing_password = ORM::factory("items_albumpassword")
->where("password", "=", $album_password)
->find_all();
if (count($existing_password) > 0) {
// If the password if valid, then store it, and display a success message.
// If not, close the dialog and display a rejected message.
cookie::delete("g3_albumpassword_id");
cookie::set("g3_albumpassword", $album_password);
message::success(t("Password Accepted."));
json::reply(array("result" => "success"));
} else {
message::error(t("Password Rejected."));
json::reply(array("result" => "success"));
}
}
private function _get_password_form($id) {
// Generate a form for assigning a new password.
$form = new Forge("albumpassword/savepassword", "", "post",
array("id" => "g-assign-password-form"));
$assignpassword_group = $form->group("Enter Password")
->label(t("Enter Password:"));
$assignpassword_group->hidden("item_id")->value($id);
$assignpassword_group->input("assignpassword_password")
->id('assignpassword_password')
->label(t("Password:"));
$assignpassword_group->submit("save_password")->value(t("Save"));
// Return the newly generated form.
return $form;
}
private function _get_login_form($id) {
// Generate a form for allowing visitors to enter in their passwords.
$form = new Forge("albumpassword/checkpassword", "", "post",
array("id" => "g-login-password-form"));
$assignpassword_group = $form->group("Enter Password")
->label(t("Enter Password:"));
$assignpassword_group->password("albumpassword_password")
->id('albumpassword_password')
->label(t("Password:"));
$assignpassword_group->submit("")->value(t("Login"));
// Return the newly generated form.
return $form;
}
}

View File

@ -1,49 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2011 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 access extends access_Core {
static function required($perm_name, $item) {
// Original code from the required function in modules/gallery/helpers/access.php.
if (!access::can($perm_name, $item)) {
if ($perm_name == "view") {
// Treat as if the item didn't exist, don't leak any information.
throw new Kohana_404_Exception();
} else {
access::forbidden();
}
// Begin rWatcher modifications.
// Throw a 404 error when a user attempts to access a protected item,
// unless the password has been provided, or the user is the item's owner.
} elseif (module::get_var("albumpassword", "hideonly") == false) {
$item_protected = ORM::factory("albumpassword_idcache")->where("item_id", "=", $item->id)->order_by("cache_id")->find_all();
if (count($item_protected) > 0) {
$existing_password = ORM::factory("items_albumpassword")->where("id", "=", $item_protected[0]->password_id)->find();
if ($existing_password->loaded()) {
if ((cookie::get("g3_albumpassword") != $existing_password->password) &&
(identity::active_user()->id != $item->owner_id) &&
(!identity::active_user()->admin)) {
throw new Kohana_404_Exception();
}
}
}
}
}
}

View File

@ -1,71 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2011 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 item extends item_Core {
static function viewable($model) {
// Hide password protected albums until the correct password is entered,
// unless the current user is an admin, or the albums owner.
$model = item_Core::viewable($model);
// If the user is an admin, don't hide anything anything.
// If not, hide whatever is restricted by an album password
// that the current user is not the owner of.
if (!identity::active_user()->admin) {
// Display items that are not in idcaches.
$model->and_open()->join("albumpassword_idcaches", "items.id", "albumpassword_idcaches.item_id", "LEFT OUTER")
->and_where("albumpassword_idcaches.item_id", "IS", NULL);
// If in hide only mode, check and see if the current item is protected.
// If it is, log the user in with the password to view it.
if (module::get_var("albumpassword", "hideonly") == true) {
$existing_cacheditem = ORM::factory("albumpassword_idcache")->where("item_id", "=", $model->id)->order_by("cache_id")->find_all();
if (count($existing_cacheditem) > 0) {
$existing_cacheditem_password = ORM::factory("items_albumpassword")->where("id", "=", $existing_cacheditem[0]->password_id)->find_all();
if (cookie::get("g3_albumpassword") != $existing_cacheditem_password[0]->password) {
cookie::set("g3_albumpassword", $existing_cacheditem_password[0]->password);
cookie::set("g3_albumpassword_id", $existing_cacheditem_password[0]->id);
$model->or_where("albumpassword_idcaches.password_id", "=", $existing_cacheditem_password[0]->id);
}
}
}
// ... Unless their password id corresponds with a valid password.
$existing_password = ORM::factory("items_albumpassword")->where("password", "=", cookie::get("g3_albumpassword"))->find_all();
if (count($existing_password) > 0) {
foreach ($existing_password as $one_password) {
if (cookie::get("g3_albumpassword_id") != "") {
if (cookie::get("g3_albumpassword_id") == $one_password->id) {
$model->or_where("albumpassword_idcaches.password_id", "=", $one_password->id);
}
} else {
$model->or_where("albumpassword_idcaches.password_id", "=", $one_password->id);
}
}
}
// Or the current user is the owner of the item.
$model->or_where("items.owner_id", "=", identity::active_user()->id)->close();
}
return $model;
}
}

View File

@ -1,158 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2011 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 albumpassword_event_Core {
static function site_menu($menu, $theme) {
// Add menu options for Adding / Removing / Using passwords to the menu.
// If this page doesn't belong to an item, don't display the menu.
if (!$theme->item()) {
return;
}
$item = $theme->item();
// If there isn't currently a password stored in the cookie,
// then display the enter password link.
if (cookie::get("g3_albumpassword") == "") {
$menu->append(Menu::factory("dialog")
->id("albumpassword_login")
->css_id("g-album-password-login")
->url(url::site("albumpassword/login"))
->label(t("Unlock albums")));
} else {
// If a password has been entered already
// display the log out link, and links to the protected albums
$menu->append(Menu::factory("submenu")
->id("albumpassword_protected")
->css_id("g-album-password-protected")
->label(t("Protected albums")));
$menu->get("albumpassword_protected")
->append(Menu::factory("link")
->id("albumpassword_logout")
->css_id("g-album-password-logout")
->url(url::site("albumpassword/logout"))
->label(t("Clear password")));
$existing_password = "";
if (cookie::get("g3_albumpassword_id") != "") {
$existing_password = ORM::factory("items_albumpassword")
->where("password", "=", cookie::get("g3_albumpassword"))
->where("id", "=", cookie::get("g3_albumpassword_id"))
->find_all();
} else {
$existing_password = ORM::factory("items_albumpassword")
->where("password", "=", cookie::get("g3_albumpassword"))
->find_all();
}
if (count($existing_password) > 0) {
$counter = 0;
while ($counter < count($existing_password)) {
$item_album = ORM::factory("item")->where("id", "=", $existing_password[$counter]->album_id)->find();
$menu->get("albumpassword_protected")
->append(Menu::factory("link")
->id("albumpassword_album" . $counter)
->label(html::purify($item_album->title))
->css_id("g-album-password-album" . $counter)
->url(url::abs_site("{$item_album->type}s/{$item_album->id}")));
$counter++;
}
}
}
// If this is an album without a password, display a link for assigning one.
// If this is an album with a password, display a link to remove it.
if ($item->is_album()) {
if ((access::can("view", $item)) && (access::can("edit", $item))) {
$existing_password = ORM::factory("items_albumpassword")
->where("album_id", "=", $item->id)
->find_all();
if (count($existing_password) > 0) {
$menu->get("options_menu")
->append(Menu::factory("link")
->id("albumpassword_remove")
->label(t("Remove password"))
->css_id("g-album-password-remove")
->url(url::site("albumpassword/remove/" . $item->id)));
} elseif ($item->id != 1) {
$passworded_subitems = ORM::factory("item", $item->id)
->and_open()->join("albumpassword_idcaches", "items.id", "albumpassword_idcaches.item_id", "LEFT OUTER")
->where("albumpassword_idcaches.item_id", "IS NOT", NULL)->close()
->descendants();
$existing_cacheditem = ORM::factory("albumpassword_idcache")->where("item_id", "=", $item->id)->order_by("cache_id")->find_all();
if ((count($existing_cacheditem) == 0) && count($passworded_subitems) == 0) {
$menu->get("options_menu")
->append(Menu::factory("dialog")
->id("albumpassword_assign")
->label(t("Assign password"))
->css_id("g-album-password-assign")
->url(url::site("albumpassword/assign/" . $item->id)));
}
}
}
}
}
static function item_deleted($item) {
// Check for and delete the password and any cached ids assigned to it.
$existing_password = ORM::factory("items_albumpassword")->where("album_id", "=", $item->id)->find_all();
if (count($existing_password) > 0) {
foreach ($existing_password as $one_password) {
db::build()->delete("albumpassword_idcaches")->where("password_id", "=", $one_password->id)->execute();
}
db::build()->delete("items_albumpasswords")->where("album_id", "=", $item->id)->execute();
message::success(t("Password Removed."));
} else {
db::build()->delete("albumpassword_idcaches")->where("item_id", "=", $item->id)->execute();
}
}
static function item_created($item) {
// Check for any already existing password on parent album(s), if found, generate cache data for the new item.
$existing_password = ORM::factory("albumpassword_idcache")->where("item_id", "=", $item->parent_id)->order_by("cache_id")->find_all();
if (count($existing_password) > 0) {
$new_cachedid = ORM::factory("albumpassword_idcache");
$new_cachedid->password_id = $existing_password[0]->password_id;
$new_cachedid->item_id = $item->id;
$new_cachedid->save();
}
}
static function item_moved($item, $old_parent) {
// Delete any existing cache data.
db::build()->delete("albumpassword_idcaches")->where("item_id", "=", $item->id)->execute();
// Check for a password on the new parent, generate cache data if necessary.
$existing_password = ORM::factory("albumpassword_idcache")->where("item_id", "=", $item->parent_id)->order_by("cache_id")->find_all();
if (count($existing_password) > 0) {
$new_cachedid = ORM::factory("albumpassword_idcache");
$new_cachedid->password_id = $existing_password[0]->password_id;
$new_cachedid->item_id = $item->id;
$new_cachedid->save();
}
}
static function admin_menu($menu, $theme) {
// Add a link to the Album Password admin page to the Content menu.
$menu->get("settings_menu")
->append(Menu::factory("link")
->id("albumpassword")
->label(t("Album Password Settings"))
->url(url::site("admin/albumpassword")));
}
}

View File

@ -1,72 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2011 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 albumpassword_installer {
static function install() {
// Create a table to store passwords in.
$db = Database::instance();
$db->query("CREATE TABLE IF NOT EXISTS {items_albumpasswords} (
`id` int(9) NOT NULL auto_increment,
`album_id` int(9) NOT NULL,
`password` varchar(64) NOT NULL,
PRIMARY KEY (`id`))
DEFAULT CHARSET=utf8;");
// Create a table to store a list of all protected items in.
$db->query("CREATE TABLE IF NOT EXISTS {albumpassword_idcaches} (
`cache_id` int(9) NOT NULL auto_increment,
`password_id` int(9) NOT NULL,
`item_id` int(9) NOT NULL,
PRIMARY KEY (`cache_id`))
DEFAULT CHARSET=utf8;");
// Set the default value for this module's behavior.
module::set_var("albumpassword", "hideonly", true);
// Set the module's version number.
module::set_version("albumpassword", 3);
}
static function upgrade($version) {
$db = Database::instance();
if ($version == 1) {
// Set the default value for this module's behavior.
module::set_var("albumpassword", "hideonly", true);
module::set_version("albumpassword", $version = 2);
}
if ($version == 2) {
// Create a table to store a list of all protected items in.
$db->query("CREATE TABLE IF NOT EXISTS {albumpassword_idcaches} (
`cache_id` int(9) NOT NULL auto_increment,
`password_id` int(9) NOT NULL,
`item_id` int(9) NOT NULL,
PRIMARY KEY (`cache_id`))
DEFAULT CHARSET=utf8;");
module::set_version("albumpassword", $version = 3);
}
}
static function uninstall() {
// Delete the password table before uninstalling.
$db = Database::instance();
$db->query("DROP TABLE IF EXISTS {items_albumpasswords};");
$db->query("DROP TABLE IF EXISTS {albumpassword_idcaches};");
module::delete("albumpassword");
}
}

View File

@ -1,197 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2011 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 albumpassword_task_Core {
static function available_tasks() {
// Check for any albums listed in albumpasswords but not idcaches.
// If found, set the severity for this task to warning, as there's
// obviously something missing from idcaches.
$bad_albums = ORM::factory("items_albumpassword")
->join("albumpassword_idcaches", "items_albumpasswords.id", "albumpassword_idcaches.password_id", "LEFT OUTER")
->and_where("albumpassword_idcaches.password_id", "IS", NULL)->count_all();
$tasks = array();
$tasks[] = Task_Definition::factory()
->callback("albumpassword_task::update_idcaches")
->name(t("Rebuild Album Password ID Caches DB"))
->description(t("Logs the contents of all protected albums into the db."))
->severity($bad_albums ? log::WARNING : log::SUCCESS);
$tasks[] = Task_Definition::factory()
->callback("albumpassword_task::lowercase_passwords")
->name(t("Fix Password DB Casing"))
->description(t("Fixes case sensitivity issues."))
->severity(log::SUCCESS);
return $tasks;
}
static function lowercase_passwords($task) {
// Converts all passwords to lower case.
$start = microtime(true);
$total = $task->get("total");
$existing_passwords = ORM::factory("items_albumpassword")->find_all();
if (empty($total)) {
// Set the initial values for all variables.
$task->set("total", count($existing_passwords));
$total = $task->get("total");
$task->set("last_password_id", 0);
$task->set("completed_passwords", 0);
}
// Retrieve the values for variables from the last time this
// function was run.
$last_password_id = $task->get("last_password_id");
$completed_passwords = $task->get("completed_passwords");
foreach (ORM::factory("items_albumpassword")
->where("id", ">", $last_password_id)
->order_by("id")
->find_all(100) as $one_password) {
$one_password->password = strtolower($one_password->password);
$one_password->save();
$last_password_id = $one_password->id;
$completed_passwords++;
if ($completed_passwords == count($existing_passwords) || microtime(true) - $start > 1.5) {
break;
}
}
$task->set("last_password_id", $last_password_id);
$task->set("completed_passwords", $completed_passwords);
if ($completed_passwords == count($existing_passwords)) {
$task->done = true;
$task->state = "success";
$task->percent_complete = 100;
} else {
$task->percent_complete = round(100 * $completed_passwords / count($existing_passwords));
}
$task->status = t2("One password fixed", "%count / %total passwords fixed", $completed_passwords,
array("total" => count($existing_passwords)));
}
static function update_idcaches($task) {
// Populate the idcaches table with the contents of all protected albums.
$start = microtime(true);
$total = $task->get("total");
$existing_passwords = ORM::factory("items_albumpassword")->find_all();
// If this is the first time this function has been run,
// delete and re-create the idcaches table, and set up
// some initial variables.
if (empty($total)) {
// Delete the idcache table and make a new one.
$db = Database::instance();
$db->query("DROP TABLE IF EXISTS {albumpassword_idcaches};");
$db->query("CREATE TABLE IF NOT EXISTS {albumpassword_idcaches} (
`cache_id` int(9) NOT NULL auto_increment,
`password_id` int(9) NOT NULL,
`item_id` int(9) NOT NULL,
PRIMARY KEY (`cache_id`))
DEFAULT CHARSET=utf8;");
// Set the initial values for all variables.
$task->set("total", count($existing_passwords));
$total = $task->get("total");
$task->set("last_album_counter", 0);
$task->set("last_id", 0);
$task->set("completed_albums", 0);
$task->set("completed_items", 0);
$task->set("total_items", 0);
}
// Retrieve the values for variables from the last time this
// function was run.
$last_album_counter = $task->get("last_album_counter");
$completed_albums = $task->get("completed_albums");
$completed_items = $task->get("completed_items");
$total_items = $task->get("total_items");
$last_id = $task->get("last_id");
// If completed_items is 0, then we're just starting to process this
// album. Add the album to idcaches before adding it's contents.
if ($completed_items == 0) {
// Add the album to the id cache.
$cached_album = ORM::factory("albumpassword_idcache");
$cached_album->password_id = $existing_passwords[$last_album_counter]->id;
$cached_album->item_id = $existing_passwords[$last_album_counter]->album_id;
$cached_album->save();
// Set total_items to the number of items in this album.
$total_items = ORM::factory("item", $existing_passwords[$last_album_counter]->album_id)
->descendants_count();
$task->set("total_items", $total_items);
}
// Add each item in the album to idcaches.
foreach (ORM::factory("item", $existing_passwords[$last_album_counter]->album_id)
->where("id", ">", $last_id)
->order_by("id")
->descendants(100) as $item) {
$cached_item = ORM::factory("albumpassword_idcache");
$cached_item->password_id =$existing_passwords[$last_album_counter]->id;
$cached_item->item_id = $item->id;
$cached_item->save();
$last_id = $item->id;
$completed_items++;
// Set a time limit so the script doesn't time out.
if (microtime(true) - $start > 1.5) {
break;
}
} // end foreach
// If completed_items equals total_items, then we've
// processed everything in the current album.
// Increase variables and set everything up for the
// next album.
if ($completed_items == $total_items) {
$completed_items = 0;
$last_album_counter++;
$completed_albums++;
$last_id = 0;
}
// Store the current values of the variables for the next
// time this function is called.
$task->set("last_album_counter", $last_album_counter);
$task->set("last_id", $last_id);
$task->set("completed_albums", $completed_albums);
$task->set("completed_items", $completed_items);
// Display the number of albums that have been completed before exiting.
if ($total == $completed_albums) {
$task->done = true;
$task->state = "success";
$task->percent_complete = 100;
$task->status = t("Scanning Protected Album $completed_albums of $total");
} else {
$task->percent_complete = round(100 * $completed / $total);
$task->status = t("Scanning Protected Album $completed_albums of $total -- $completed_items / $total_items files");
}
}
}

View File

@ -1,21 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2011 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 Albumpassword_Idcache_Model extends ORM {
}

View File

@ -1,21 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2011 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 Items_Albumpassword_Model extends ORM {
}

View File

@ -1,7 +0,0 @@
name = "Album Password"
description = "Restrict access to individual albums."
version = 3
author_name = "rWatcher"
author_url = "http://codex.gallery2.org/User:RWatcher"
info_url = "http://codex.gallery2.org/Gallery3:Modules:albumpassword"
discuss_url = "http://gallery.menalto.com/node/98856"

View File

@ -1,9 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<h2>
<?= t("Album Password Admin") ?>
</h2>
<br />
<div class="g-block">
<?= $albumpassword_form ?>
<?= t("If this box is checked, accessing a protected album/photo/video will automatically log the visitor in with that items password.") ?><br /><br />
</div>

View File

@ -1,7 +0,0 @@
<div id="g-assign-password">
<ul>
<li id="g-assign-password-form">
<?= $form ?>
</li>
</ul>
</div>

View File

@ -1,7 +0,0 @@
<div id="g-login-password">
<ul>
<li id="g-login-password-form">
<?= $form ?>
</li>
</ul>
</div>

View File

@ -1,38 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2011 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 albumtree_block_Core {
static function get_site_list() {
return array("albumtree" => t("Album tree"));
}
static function get($block_id) {
$block = new Block();
switch ($block_id) {
case "albumtree":
$style = module::get_var("albumtree", "style", "select");
$block->css_id = "g-albumtree";
$block->title = t("Album Tree");
$block->content = new View("albumtree_block_{$style}.html");
$block->content->root = item::root();
break;
}
return $block;
}
}

View File

@ -1,33 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2011 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 albumtree_installer {
static function install() {
module::set_var("albumtree", "style", "select");
module::set_version("albumtree", 3);
}
static function upgrade($version) {
$db = Database::instance();
if ($version == 1) {
module::set_var("albumtree", "style", "select");
module::set_version("albumtree", $version = 2);
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 372 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 376 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 622 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 69 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 67 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 64 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 65 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 86 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 86 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 85 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 85 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 861 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 870 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 89 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 89 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 88 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 88 B

View File

@ -1,7 +0,0 @@
name = "Album Tree"
description = "Provides a block in the sidebar with quick links to all other albums."
version = 3
author_name = ""
author_url = ""
info_url = "http://codex.gallery2.org/Gallery3:Modules:albumtree"
discuss_url = "http://gallery.menalto.com/forum_module_albumtree"

View File

@ -1,24 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<select onchange="window.location='<?= url::site("items/__ID__")?>'.replace('__ID__', this.value)">
<? // We'll keep track of the list of items that we want to display in a stack ?>
<? $stack = array(array(0, $root)) ?>
<? // While there are still items to show, pick the next one and show it ?>
<? while ($stack): ?>
<? list($level, $album) = array_pop($stack) ?>
<option value="<?= $album->id ?>"><?= str_repeat("&nbsp;&nbsp;", $level) ?><?= $album->title ?></option>
<? // Then take all of that album's children and put them next on the stack. ?>
<? $tmp = array(); ?>
<? foreach ($album->viewable()->children(null, null, array(array("type", "=", "album"))) as $child): ?>
<? $tmp[] = array($level + 1, $child) ?>
<? endforeach ?>
<? // Since we'll pull them off the stack in the opposite order that we put them on, ?>
<? // and the order that we put them on is the order in which we want to display them, ?>
<? // We need to reverse the order of the children on the stack ?>
<? if ($tmp): ?>
<? $stack = array_merge($stack, array_reverse($tmp)) ?>
<? endif ?>
<? endwhile ?>
</select>

View File

@ -1,414 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<script type="text/javascript">
/*--------------------------------------------------|
| dTree 2.05 | www.destroydrop.com/javascript/tree/ |
|---------------------------------------------------|
| Copyright (c) 2002-2003 Geir Landrö |
| |
| This script can be used freely as long as all |
| copyright messages are intact. |
| |
| Updated: 17.04.2003 |
|--------------------------------------------------*/
// Node object
function Node(id, pid, name, url, title, target, icon, iconOpen, open) {
this.id = id;
this.pid = pid;
this.name = name;
this.url = url;
this.title = title;
this.target = target;
this.icon = icon;
this.iconOpen = iconOpen;
this._io = open || false;
this._is = false;
this._ls = false;
this._hc = false;
this._ai = 0;
this._p;
};
// Tree object
function dTree(objName) {
this.config = {
target : null,
folderLinks : true,
useSelection : true,
useCookies : true,
useLines : true,
useIcons : false,
useStatusText : false,
closeSameLevel : false,
inOrder : false,
cookiePath : null,
cookieDomain : null
}
this.obj = objName;
this.aNodes = [];
this.aIndent = [];
this.root = new Node(-1);
this.selectedNode = null;
this.selectedFound = false;
this.completed = false;
};
// Adds a new node to the node array
dTree.prototype.add = function(id, pid, name, url, title, target, icon, iconOpen, open) {
this.aNodes[this.aNodes.length] = new Node(id, pid, name, url, title, target, icon, iconOpen, open);
};
// Open/close all nodes
dTree.prototype.openAll = function() {
this.oAll(true);
};
dTree.prototype.closeAll = function() {
this.oAll(false);
};
// Outputs the tree to the page
dTree.prototype.toString = function() {
var str = '<div class="dtree">\n';
if (document.getElementById) {
if (this.config.useCookies) this.selectedNode = this.getSelected();
str += this.addNode(this.root);
} else str += 'Browser not supported.';
str += '</div>';
if (!this.selectedFound) this.selectedNode = null;
this.completed = true;
return str;
};
// Creates the tree structure
dTree.prototype.addNode = function(pNode) {
var str = '';
var n=0;
if (this.config.inOrder) n = pNode._ai;
for (n; n<this.aNodes.length; n++) {
if (this.aNodes[n].pid == pNode.id) {
var cn = this.aNodes[n];
cn._p = pNode;
cn._ai = n;
this.setCS(cn);
if (!cn.target && this.config.target) cn.target = this.config.target;
if (cn._hc && !cn._io && this.config.useCookies) cn._io = this.isOpen(cn.id);
if (!this.config.folderLinks && cn._hc) cn.url = null;
if (this.config.useSelection && cn.id == this.selectedNode && !this.selectedFound) {
cn._is = true;
this.selectedNode = n;
this.selectedFound = true;
}
str += this.node(cn, n);
if (cn._ls) break;
}
}
return str;
};
// Creates the node icon, url and text
dTree.prototype.node = function(node, nodeId) {
var str = '<div class="dTreeNode" title="' + node.name + '">' + this.indent(node, nodeId);
if (this.config.useIcons) {
if (!node.icon) node.icon = (this.root.id == node.pid) ? this.icon.root : ((node._hc) ? this.icon.folder : this.icon.node);
if (!node.iconOpen) node.iconOpen = (node._hc) ? this.icon.folderOpen : this.icon.node;
if (this.root.id == node.pid) {
node.icon = this.icon.root;
node.iconOpen = this.icon.root;
}
str += '<img id="i' + this.obj + nodeId + '" src="' + ((node._io) ? node.iconOpen : node.icon) + '" alt="" />';
}
if (node.url) {
str += '<a id="s' + this.obj + nodeId + '" class="' + ((this.config.useSelection) ? ((node._is ? 'nodeSel' : 'node')) : 'node') + '" href="' + node.url + '"';
if (node.title) str += ' title="' + node.title + '"';
if (node.target) str += ' target="' + node.target + '"';
if (this.config.useStatusText) str += ' onmouseover="window.status=\'' + node.name + '\';return true;" onmouseout="window.status=\'\';return true;" ';
if (this.config.useSelection && ((node._hc && this.config.folderLinks) || !node._hc))
str += ' onclick="' + this.obj + '.s(' + nodeId + ');"';
str += '>';
}
else if ((!this.config.folderLinks || !node.url) && node._hc && node.pid != this.root.id)
str += '<a href="javascript: ' + this.obj + '.o(' + nodeId + ');" class="node">';
str += node.name;
if (node.url || ((!this.config.folderLinks || !node.url) && node._hc)) str += '</a>';
str += '</div>';
if (node._hc) {
str += '<div id="d' + this.obj + nodeId + '" class="clip" style="display:' + ((this.root.id == node.pid || node._io) ? 'block' : 'none') + ';">';
str += this.addNode(node);
str += '</div>';
}
this.aIndent.pop();
return str;
};
// Adds the empty and line icons
dTree.prototype.indent = function(node, nodeId) {
var str = '';
if (this.root.id != node.pid) {
for (var n=0; n<this.aIndent.length; n++)
str += '<img src="' + ( (this.aIndent[n] == 1 && this.config.useLines) ? this.icon.line : this.icon.empty ) + '" alt="" />';
(node._ls) ? this.aIndent.push(0) : this.aIndent.push(1);
if (node._hc) {
str += '<a href="javascript: ' + this.obj + '.o(' + nodeId + ');"><img id="j' + this.obj + nodeId + '" src="';
if (!this.config.useLines) str += (node._io) ? this.icon.nlMinus : this.icon.nlPlus;
else str += ( (node._io) ? ((node._ls && this.config.useLines) ? this.icon.minusBottom : this.icon.minus) : ((node._ls && this.config.useLines) ? this.icon.plusBottom : this.icon.plus ) );
str += '" alt="" /></a>';
} else str += '<img src="' + ( (this.config.useLines) ? ((node._ls) ? this.icon.joinBottom : this.icon.join ) : this.icon.empty) + '" alt="" />';
}
return str;
};
// Checks if a node has any children and if it is the last sibling
dTree.prototype.setCS = function(node) {
var lastId;
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n].pid == node.id) node._hc = true;
if (this.aNodes[n].pid == node.pid) lastId = this.aNodes[n].id;
}
if (lastId==node.id) node._ls = true;
};
// Returns the selected node
dTree.prototype.getSelected = function() {
var sn = this.getCookie('cs' + this.obj);
return (sn) ? sn : null;
};
// Highlights the selected node
dTree.prototype.s = function(id) {
if (!this.config.useSelection) return;
var cn = this.aNodes[id];
if (cn._hc && !this.config.folderLinks) return;
if (this.selectedNode != id) {
if (this.selectedNode || this.selectedNode==0) {
eOld = document.getElementById("s" + this.obj + this.selectedNode);
eOld.className = "node";
}
eNew = document.getElementById("s" + this.obj + id);
eNew.className = "nodeSel";
this.selectedNode = id;
if (this.config.useCookies) this.setCookie('cs' + this.obj, cn.id);
}
};
// Toggle Open or close
dTree.prototype.o = function(id) {
var cn = this.aNodes[id];
this.nodeStatus(!cn._io, id, cn._ls);
cn._io = !cn._io;
if (this.config.closeSameLevel) this.closeLevel(cn);
if (this.config.useCookies) this.updateCookie();
};
// Open or close all nodes
dTree.prototype.oAll = function(status) {
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n]._hc && this.aNodes[n].pid != this.root.id) {
this.nodeStatus(status, n, this.aNodes[n]._ls)
this.aNodes[n]._io = status;
}
}
if (this.config.useCookies) this.updateCookie();
};
// Opens the tree to a specific node
dTree.prototype.openTo = function(nId, bSelect, bFirst) {
if (!bFirst) {
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n].id == nId) {
nId=n;
break;
}
}
}
var cn=this.aNodes[nId];
if (cn.pid==this.root.id || !cn._p) return;
cn._io = true;
cn._is = bSelect;
if (this.completed && cn._hc) this.nodeStatus(true, cn._ai, cn._ls);
if (this.completed && bSelect) this.s(cn._ai);
else if (bSelect) this._sn=cn._ai;
this.openTo(cn._p._ai, false, true);
};
// Closes all nodes on the same level as certain node
dTree.prototype.closeLevel = function(node) {
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n].pid == node.pid && this.aNodes[n].id != node.id && this.aNodes[n]._hc) {
this.nodeStatus(false, n, this.aNodes[n]._ls);
this.aNodes[n]._io = false;
this.closeAllChildren(this.aNodes[n]);
}
}
}
// Closes all children of a node
dTree.prototype.closeAllChildren = function(node) {
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n].pid == node.id && this.aNodes[n]._hc) {
if (this.aNodes[n]._io) this.nodeStatus(false, n, this.aNodes[n]._ls);
this.aNodes[n]._io = false;
this.closeAllChildren(this.aNodes[n]);
}
}
}
// Change the status of a node(open or closed)
dTree.prototype.nodeStatus = function(status, id, bottom) {
eDiv = document.getElementById('d' + this.obj + id);
eJoin = document.getElementById('j' + this.obj + id);
if (this.config.useIcons) {
eIcon = document.getElementById('i' + this.obj + id);
eIcon.src = (status) ? this.aNodes[id].iconOpen : this.aNodes[id].icon;
}
eJoin.src = (this.config.useLines)?
((status)?((bottom)?this.icon.minusBottom:this.icon.minus):((bottom)?this.icon.plusBottom:this.icon.plus)):
((status)?this.icon.nlMinus:this.icon.nlPlus);
eDiv.style.display = (status) ? 'block': 'none';
};
// [Cookie] Clears a cookie
dTree.prototype.clearCookie = function() {
var now = new Date();
var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);
this.setCookie('co'+this.obj, 'cookieValue', yesterday);
this.setCookie('cs'+this.obj, 'cookieValue', yesterday);
};
// [Cookie] Sets value in a cookie
dTree.prototype.setCookie = function(cookieName, cookieValue, expires, path, domain, secure) {
path = path || this.config.cookiePath;
domain = domain || this.config.cookieDomain;
document.cookie =
escape(cookieName) + '=' + escape(cookieValue)
+ (expires ? '; expires=' + expires.toGMTString() : '')
+ (path ? '; path=' + path : '')
+ (domain ? '; domain=' + domain : '')
+ (secure ? '; secure' : '');
};
// [Cookie] Gets a value from a cookie
dTree.prototype.getCookie = function(cookieName) {
var cookieValue = '';
var posName = document.cookie.indexOf(escape(cookieName) + '=');
if (posName != -1) {
var posValue = posName + (escape(cookieName) + '=').length;
var endPos = document.cookie.indexOf(';', posValue);
if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos));
else cookieValue = unescape(document.cookie.substring(posValue));
}
return (cookieValue);
};
// [Cookie] Returns ids of open nodes as a string
dTree.prototype.updateCookie = function() {
var str = '';
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n]._io && this.aNodes[n].pid != this.root.id) {
if (str) str += '.';
str += this.aNodes[n].id;
}
}
this.setCookie('co' + this.obj, str);
};
// [Cookie] Checks if a node id is in a cookie
dTree.prototype.isOpen = function(id) {
var aOpen = this.getCookie('co' + this.obj).split('.');
for (var n=0; n<aOpen.length; n++)
if (aOpen[n] == id) return true;
return false;
};
// If Push and pop is not implemented by the browser
if (!Array.prototype.push) {
Array.prototype.push = function array_push() {
for(var i=0;i<arguments.length;i++)
this[this.length]=arguments[i];
return this.length;
}
};
if (!Array.prototype.pop) {
Array.prototype.pop = function array_pop() {
lastElement = this[this.length-1];
this.length = Math.max(this.length-1,0);
return lastElement;
}
};
</script>
<style type="text/css">
/*--------------------------------------------------|
| dTree 2.05 | www.destroydrop.com/javascript/tree/ |
|---------------------------------------------------|
| Copyright (c) 2002-2003 Geir Landrö |
|--------------------------------------------------*/
.dtree {
font-size: 1.05em;
white-space: nowrap;
}
.dtree img {
border: 0px;
vertical-align: middle;
}
.dtree a.node, .dtree a.nodeSel {
white-space: nowrap;
padding: 1px 2px 1px 2px;
}
.dtree a.nodeSel {
font-style: italic;
}
.dtree .clip {
overflow: hidden;
}
</style>
<div class="block-albumselect-AlbumTree gbBlock">
<div class="dtree">
<script type="text/javascript">
// <![CDATA[
function albumSelect_goToNode(nodeId) {
document.location = new String('main.php?g2_itemId=__ID__').replace('__ID__', nodeId);
}
var albumTree = new dTree('albumTree');
var albumTree_images = '<?= item::root()->url() ?>modules/albumtree/images/'
albumTree.icon = {
root : albumTree_images + 'base.gif',
folder : albumTree_images + 'folder.gif',
folderOpen : albumTree_images + 'imgfolder.gif',
node : albumTree_images + 'imgfolder.gif',
empty : albumTree_images + 'empty.gif',
line : albumTree_images + 'line.gif',
join : albumTree_images + 'join.gif',
joinBottom : albumTree_images + 'joinbottom.gif',
plus : albumTree_images + 'plus.gif',
plusBottom : albumTree_images + 'plusbottom.gif',
minus : albumTree_images + 'minus.gif',
minusBottom : albumTree_images + 'minusbottom.gif',
nlPlus : albumTree_images + 'nolines_plus.gif',
nlMinus : albumTree_images + 'nolines_minus.gif'
};
albumTree.config.useLines = true;
albumTree.config.useIcons = false;
albumTree.config.useCookies = false;
albumTree.config.closeSameLevel = false;
albumTree.config.cookiePath = '<?= item::root()->url() ?>';
albumTree.config.cookieDomain = '';
{ var pf = '<?= item::root()->url() ?>';
<?
function addtree($album){
?>
albumTree.add(<?= $album->id -1 ?>, <?= $album->parent_id -1 ?>, "<?= $album->title ?>", pf+'<?= $album->relative_url_cache ?>');
<?
foreach ($album->viewable()->children(null, null, array(array("type", "=", "album"))) as $child){
addtree($child);
}
}
addtree($root);
?>
}
document.write(albumTree);
// ]]>
</script>
</div>
</div>

View File

@ -1,30 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<style type="text/css">
ul.treealbumnav {
height: 225px;
width: 190px;
overflow: auto;
border: 1px solid #666;
padding: 2px;
}
</style>
<ul class="treealbumnav">
<?
function makelist($album,$level){
//print out the list item
?>
<li>
<a href="<?= item::root()->url() ?><?= $album->relative_url_cache ?>"><?= str_repeat("&nbsp;&nbsp;", $level) ?><?= $album->title ?></a>
</li>
<?
//recurse over the children, and print their list items as well
foreach ($album->viewable()->children(null, null, array(array("type", "=", "album"))) as $child){
makelist($child,$level+1);
}
}
makelist($root,0);
?>
</ul>

View File

@ -1,16 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<select onchange="window.location=this.value">
<?
function makeselect($album, $level){
//print out the list item as a select option
?>
<option value="<?= item::root()->url() ?><?= $album->relative_url_cache ?>"><?= str_repeat("&nbsp;&nbsp;", $level) ?><?= $album->title ?></option>
<?
//recurse over the children, and print their list items as well
foreach ($album->viewable()->children(null, null, array(array("type", "=", "album"))) as $child){
makeselect($child,$level+1);
}
}
makeselect($root,0);
?>
</select>

View File

@ -1,36 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2008 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 atom_Core {
/**
* Converts a Unix timestamp to an Internet timestamp as defined in RFC3339.
* http://www.ietf.org/rfc/rfc3339.txt
*
* @todo Check if time zone is correct.
* @todo Write test.
*
* @param int Unix timestamp
* @return string Internet timestamp
*/
static function unix_to_internet_timestamp($timestamp) {
return sprintf("%sZ", date("Y-m-d\TH:i:s", $timestamp));
}
}

View File

@ -1,36 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2008 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 Atom_Author_Core extends Atom_Base {
public function name($name) {
$this->element->appendChild($this->dom->createElement("name", $name));
return $this;
}
public function email($email) {
$this->element->appendChild($this->dom->createElement("email", $email));
return $this;
}
public function uri($uri) {
$this->element->appendChild($this->dom->createElement("uri", $uri));
return $this;
}
}

View File

@ -1,76 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2008 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 Atom_Base_Core {
protected $dom;
protected $element;
protected $children = array();
protected $element_name;
function __construct($element_name, $dom=null) {
if ($dom) {
$this->dom = $dom;
$this->element = $dom->createElement($element_name);
} else {
$this->dom = new DOMDocument('1.0', 'utf-8');
$this->element = $this->dom->createElementNS("http://www.w3.org/2005/Atom", $element_name);
}
$this->dom->appendChild($this->element);
$this->element_name = $element_name;
return $this;
}
public function get_element() {
$this->add_children_to_base_element();
return $this->element;
}
public function as_xml() {
$this->add_children_to_base_element();
$this->dom->formatOutput = true;
return $this->dom->saveXML();
}
public function as_json() {
$this->add_children_to_base_element();
/* Both Google and Yahoo generate their JSON from XML. We could do that, too. */
return null;
}
public function load_xml($xml) {
/* Load XML into our DOM. We can also validate against the RELAX NG schema from the Atom RFC. */
}
protected function add_child($element_type, $element_name) {
// @todo check if element_type is of Atom_Base; this can also be done with no magic
$element = new $element_type($element_name, $this->dom);
$this->children[$element_name][] = $element;
return end($this->children[$element_name]);
}
protected function add_children_to_base_element() {
foreach ($this->children as $element_type => $elements) {
$base_element = $this->element;
foreach ($elements as $id => $element) {
$base_element->appendChild($element->get_element());
}
}
}
}

View File

@ -1,52 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2008 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 Atom_Entry_Core extends Atom_Base {
public function id($id) {
$this->element->appendChild($this->dom->createElement("id", $id));
return $this;
}
public function updated($timestamp) {
$this->element->appendChild(
$this->dom->createElement("updated", atom::unix_to_internet_timestamp($timestamp)));
return $this;
}
public function title($title) {
$this->element->appendChild($this->dom->createElement("title", $title));
return $this;
}
public function content($text, $type="html") {
$content = $this->dom->createElement("content", html::chars($text));
$content->setAttribute("type", $type);
$this->element->appendChild($content);
return $this;
}
public function author() {
return $this->add_child("Atom_Author", "author");
}
public function link() {
return $this->add_child("Atom_Link", "link");
}
}

View File

@ -1,47 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2008 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 Atom_Feed_Core extends Atom_Base {
public function id($id) {
$this->element->appendChild($this->dom->createElement("id", $id));
return $this;
}
public function title($title) {
/* @todo Add optional type argument that defaults to "text" */
$this->element->appendChild($this->dom->createElement("title", $title));
return $this;
}
public function updated($timestamp) {
$this->element->appendChild(
$this->dom->createElement("updated", atom::unix_to_internet_timestamp($timestamp)));
return $this;
}
public function link() {
return $this->add_child("Atom_Link", "link");
}
public function entry() {
/* Create new empty entry. */
return $this->add_child("Atom_Entry", "entry");
}
}

View File

@ -1,41 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2008 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 Atom_Link_Core extends Atom_Base {
public function rel($rel) {
$this->element->setAttribute("rel", $rel);
return $this;
}
public function type($type) {
$this->element->setAttribute("type", $type);
return $this;
}
public function title($title) {
$this->element->setAttribute("title", $title);
return $this;
}
public function href($href) {
$this->element->setAttribute("href", $href);
return $this;
}
}

View File

@ -1,39 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2008 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 class implements Gallery's specific needs for Atom entries.
*
*/
class Gallery_Atom_Entry_Core extends Atom_Entry {
function __construct() {
parent::__construct("entry");
/* Set feed ID and self link. */
$this->id(html::chars(url::abs_current()));
$this->link()
->rel("self")
->href(url::abs_current());
}
public function link() {
return $this->add_child("Gallery_Atom_Link", "link");
}
}

View File

@ -1,39 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2008 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 class implements Gallery's specific needs for Atom feeds.
*
*/
class Gallery_Atom_Feed_Core extends Atom_Feed {
function __construct() {
parent::__construct("feed");
/* Set feed ID and self link. */
$this->id(html::chars(url::abs_current()));
$this->link()
->rel("self")
->href(url::abs_current());
}
public function link() {
return $this->add_child("Gallery_Atom_Link", "link");
}
}

View File

@ -1,45 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2008 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 Gallery_Atom_Link_Core extends Atom_Link {
public function related_atom($relative_uri, $title="") {
if (empty($title)) {
$title = t("Get related meta data");
}
$this->rel("related")
->type(rest::ATOM)
->title($title)
->href(sprintf("%s%s", url::base(true, "http"), $relative_uri));
return $this;
}
public function related_image($relative_uri, $title="", $image_type="jpeg") {
if (empty($title)) {
$title = t("Get related image");
}
$this->rel("related")
->type("image/" . $image_type)
->title($title)
->href(sprintf("%s%s", url::base(true, "http"), $relative_uri));
return $this;
}
}

View File

@ -1,7 +0,0 @@
name = "Atom"
description = "Enable Atom feeds in your Gallery"
version = 1
author_name = ""
author_url = ""
info_url = "http://codex.gallery2.org/Gallery3:Modules:atom"
discuss_url = "http://gallery.menalto.com/forum_module_atom"

View File

@ -1,68 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2011 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 autorotate {
static function rotate_item($item) {
require_once(MODPATH . 'autorotate/lib/pel/PelDataWindow.php');
require_once(MODPATH . 'autorotate/lib/pel/PelJpeg.php');
require_once(MODPATH . 'autorotate/lib/pel/PelTiff.php');
// Only try to rotate photos based on EXIF
if ($item->is_photo() && $item->mime_type == "image/jpeg") {
require_once(MODPATH . "exif/lib/exif.php");
$exif_raw = read_exif_data_raw($item->file_path(), false);
if (isset($exif_raw['ValidEXIFData'])) {
$orientation = $exif_raw["IFD0"]["Orientation"];
$degrees = 0;
if ($orientation == '3: Upside-down') {
$degrees = 180;
}
else if ($orientation == '8: 90 deg CW') {
$degrees = -90;
}
else if ($orientation == '6: 90 deg CCW') {
$degrees = 90;
}
if($degrees) {
$tmpfile = tempnam(TMPPATH, "rotate");
gallery_graphics::rotate($item->file_path(), $tmpfile, array("degrees" => $degrees), $item);
// Update EXIF info
$data = new PelDataWindow(file_get_contents($tmpfile));
if (PelJpeg::isValid($data)) {
$jpeg = $file = new PelJpeg();
$jpeg->load($data);
$exif = $jpeg->getExif();
if($exif !== null) {
$tiff = $exif->getTiff();
$ifd0 = $tiff->getIfd();
$orientation = $ifd0->getEntry(PelTag::ORIENTATION);
$orientation->setValue(1);
file_put_contents($tmpfile, $file->getBytes());
}
}
$item->set_data_file($tmpfile);
$item->save();
unlink($tmpfile);
}
}
}
return;
}
}

View File

@ -1,32 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2011 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 autorotate_event_Core {
// The assumption is that the exception was logged at a lower level, but we
// don't want to screw up the processing that was generating the notification
// so we don't pass the exception up the call stack
static function item_created($item) {
try {
autorotate::rotate_item($item);
} catch (Exception $e) {
Kohana_Log::add("error", "@todo autorotate_event::item_created() failed");
Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString());
}
}
}

View File

@ -1,42 +0,0 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2011 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 autorotate_installer {
static function install() {
module::set_version("autorotate", 2);
}
static function upgrade($version) {
if ($version == 1) {
module::set_version("autorotate", $version = 2);
}
}
static function deactivate() {
site_status::clear("autorotate_needs_exif");
}
static function can_activate() {
$messages = array();
if (!module::is_active("exif")) {
$messages["warn"][] = t("The autorotate module requires the EXIF module.");
}
return $messages;
}
}

View File

@ -1,337 +0,0 @@
<?php
/* PEL: PHP Exif Library. A library with support for reading and
* writing all Exif headers in JPEG and TIFF images using PHP.
*
* Copyright (C) 2004, 2005, 2006 Martin Geisler.
*
* 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 in the file COPYING; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/* $Id: Pel.php 463 2006-11-18 22:25:24Z mgeisler $ */
/**
* Miscellaneous stuff for the overall behavior of PEL.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @version $Revision: 463 $
* @date $Date: 2006-11-18 23:25:24 +0100 (Sat, 18 Nov 2006) $
* @license http://www.gnu.org/licenses/gpl.html GNU General Public
* License (GPL)
* @package PEL
*/
/* Initialize Gettext, if available. This must be done before any
* part of PEL calls Pel::tra() or Pel::fmt() --- this is ensured if
* every piece of code using those two functions require() this file.
*
* If Gettext is not available, wrapper functions will be created,
* allowing PEL to function, but without any translations.
*
* The PEL translations are stored in './locale'. It is important to
* use an absolute path here because the lookups will be relative to
* the current directory. */
if (function_exists('dgettext')) {
bindtextdomain('pel', dirname(__FILE__) . '/locale');
} else {
/**
* Pretend to lookup a message in a specific domain.
*
* This is just a stub which will return the original message
* untranslated. The function will only be defined if the Gettext
* extension has not already defined it.
*
* @param string $domain the domain.
*
* @param string $str the message to be translated.
*
* @return string the original, untranslated message.
*/
function dgettext($domain, $str) {
return $str;
}
}
/**
* Class with miscellaneous static methods.
*
* This class will contain various methods that govern the overall
* behavior of PEL.
*
* Debugging output from PEL can be turned on and off by assigning
* true or false to {@link Pel::$debug}.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @package PEL
*/
class Pel {
/**
* Flag for controlling debug information.
*
* The methods producing debug information ({@link debug()} and
* {@link warning()}) will only output something if this variable is
* set to true.
*
* @var boolean
*/
private static $debug = false;
/**
* Flag for strictness of parsing.
*
* If this variable is set to true, then most errors while loading
* images will result in exceptions being thrown. Otherwise a
* warning will be emitted (using {@link Pel::warning}) and the
* exceptions will be appended to {@link Pel::$exceptions}.
*
* Some errors will still be fatal and result in thrown exceptions,
* but an effort will be made to skip over as much garbage as
* possible.
*
* @var boolean
*/
private static $strict = false;
/**
* Stored exceptions.
*
* When {@link Pel::$strict} is set to false exceptions will be
* accumulated here instead of being thrown.
*/
private static $exceptions = array();
/**
* Return list of stored exceptions.
*
* When PEL is parsing in non-strict mode, it will store most
* exceptions instead of throwing them. Use this method to get hold
* of them when a call returns.
*
* Code for using this could look like this:
*
* <code>
* Pel::setStrictParsing(true);
* Pel::clearExceptions();
*
* $jpeg = new PelJpeg($file);
*
* // Check for exceptions.
* foreach (Pel::getExceptions() as $e) {
* printf("Exception: %s\n", $e->getMessage());
* if ($e instanceof PelEntryException) {
* // Warn about entries that couldn't be loaded.
* printf("Warning: Problem with %s.\n",
* PelTag::getName($e->getType(), $e->getTag()));
* }
* }
* </code>
*
* This gives applications total control over the amount of error
* messages shown and (hopefully) provides the necessary information
* for proper error recovery.
*
* @return array the exceptions.
*/
static function getExceptions() {
return self::$exceptions;
}
/**
* Clear list of stored exceptions.
*
* Use this function before a call to some method if you intend to
* check for exceptions afterwards.
*/
static function clearExceptions() {
self::$exceptions = array();
}
/**
* Conditionally throw an exception.
*
* This method will throw the passed exception when strict parsing
* in effect (see {@link setStrictParsing()}). Otherwise the
* exception is stored (it can be accessed with {@link
* getExceptions()}) and a warning is issued (with {@link
* Pel::warning}).
*
* @param PelException $e the exceptions.
*/
static function maybeThrow(PelException $e) {
if (self::$strict) {
throw $e;
} else {
self::$exceptions[] = $e;
self::warning('%s (%s:%s)', $e->getMessage(),
basename($e->getFile()), $e->getLine());
}
}
/**
* Enable/disable strict parsing.
*
* If strict parsing is enabled, then most errors while loading
* images will result in exceptions being thrown. Otherwise a
* warning will be emitted (using {@link Pel::warning}) and the
* exceptions will be stored for later use via {@link
* getExceptions()}.
*
* Some errors will still be fatal and result in thrown exceptions,
* but an effort will be made to skip over as much garbage as
* possible.
*
* @param boolean $flag use true to enable strict parsing, false to
* diable.
*/
function setStrictParsing($flag) {
self::$strict = $flag;
}
/**
* Get current setting for strict parsing.
*
* @return boolean true if strict parsing is in effect, false
* otherwise.
*/
function getStrictParsing() {
return self::$strict;
}
/**
* Enable/disable debugging output.
*
* @param boolean $flag use true to enable debug output, false to
* diable.
*/
function setDebug($flag) {
self::$debug = $flag;
}
/**
* Get current setting for debug output.
*
* @return boolean true if debug is enabled, false otherwise.
*/
function getDebug() {
return self::$debug;
}
/**
* Conditionally output debug information.
*
* This method works just like printf() except that it always
* terminates the output with a newline, and that it only outputs
* something if the {@link Pel::$debug} is true.
*
* @param string $format the format string.
*
* @param mixed $args,... any number of arguments can be given. The
* arguments will be available for the format string as usual with
* sprintf().
*/
static function debug() {
if (self::$debug) {
$args = func_get_args();
$str = array_shift($args);
vprintf($str . "\n", $args);
}
}
/**
* Conditionally output a warning.
*
* This method works just like printf() except that it prepends the
* output with the string 'Warning: ', terminates the output with a
* newline, and that it only outputs something if the PEL_DEBUG
* defined to some true value.
*
* @param string $format the format string.
*
* @param mixed $args,... any number of arguments can be given. The
* arguments will be available for the format string as usual with
* sprintf().
*/
static function warning() {
if (self::$debug) {
$args = func_get_args();
$str = array_shift($args);
vprintf('Warning: ' . $str . "\n", $args);
}
}
/**
* Translate a string.
*
* This static function will use Gettext to translate a string. By
* always using this function for static string one is assured that
* the translation will be taken from the correct text domain.
* Dynamic strings should be passed to {@link fmt} instead.
*
* @param string the string that should be translated.
*
* @return string the translated string, or the original string if
* no translation could be found.
*/
static function tra($str) {
return dgettext('pel', $str);
}
/**
* Translate and format a string.
*
* This static function will first use Gettext to translate a format
* string, which will then have access to any extra arguments. By
* always using this function for dynamic string one is assured that
* the translation will be taken from the correct text domain. If
* the string is static, use {@link tra} instead as it will be
* faster.
*
* @param string $format the format string. This will be translated
* before being used as a format string.
*
* @param mixed $args,... any number of arguments can be given. The
* arguments will be available for the format string as usual with
* sprintf().
*
* @return string the translated string, or the original string if
* no translation could be found.
*/
static function fmt() {
$args = func_get_args();
$str = array_shift($args);
return vsprintf(dgettext('pel', $str), $args);
}
}
?>

View File

@ -1,397 +0,0 @@
<?php
/* PEL: PHP Exif Library. A library with support for reading and
* writing all Exif headers in JPEG and TIFF images using PHP.
*
* Copyright (C) 2004, 2005 Martin Geisler.
*
* 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 in the file COPYING; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/* $Id: PelConvert.php 387 2005-10-05 11:02:52Z mgeisler $ */
/**
* Routines for converting back and forth between bytes and integers.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @version $Revision: 387 $
* @date $Date: 2005-10-05 13:02:52 +0200 (Wed, 05 Oct 2005) $
* @license http://www.gnu.org/licenses/gpl.html GNU General Public
* License (GPL)
* @package PEL
*/
/**
* Conversion functions to and from bytes and integers.
*
* The functions found in this class are used to convert bytes into
* integers of several sizes ({@link bytesToShort}, {@link
* bytesToLong}, and {@link bytesToRational}) and convert integers of
* several sizes into bytes ({@link shortToBytes} and {@link
* longToBytes}).
*
* All the methods are static and they all rely on an argument that
* specifies the byte order to be used, this must be one of the class
* constants {@link LITTLE_ENDIAN} or {@link BIG_ENDIAN}. These
* constants will be referred to as the pseudo type PelByteOrder
* throughout the documentation.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @package PEL
*/
class PelConvert {
/**
* Little-endian (Intel) byte order.
*
* Data stored in little-endian byte order store the least
* significant byte first, so the number 0x12345678 becomes 0x78
* 0x56 0x34 0x12 when stored with little-endian byte order.
*/
const LITTLE_ENDIAN = true;
/**
* Big-endian (Motorola) byte order.
*
* Data stored in big-endian byte order store the most significant
* byte first, so the number 0x12345678 becomes 0x12 0x34 0x56 0x78
* when stored with big-endian byte order.
*/
const BIG_ENDIAN = false;
/**
* Convert an unsigned short into two bytes.
*
* @param int the unsigned short that will be converted. The lower
* two bytes will be extracted regardless of the actual size passed.
*
* @param PelByteOrder one of {@link LITTLE_ENDIAN} and {@link
* BIG_ENDIAN}.
*
* @return string the bytes representing the unsigned short.
*/
static function shortToBytes($value, $endian) {
if ($endian == self::LITTLE_ENDIAN)
return chr($value) . chr($value >> 8);
else
return chr($value >> 8) . chr($value);
}
/**
* Convert a signed short into two bytes.
*
* @param int the signed short that will be converted. The lower
* two bytes will be extracted regardless of the actual size passed.
*
* @param PelByteOrder one of {@link LITTLE_ENDIAN} and {@link
* BIG_ENDIAN}.
*
* @return string the bytes representing the signed short.
*/
static function sShortToBytes($value, $endian) {
/* We can just use shortToBytes, since signed shorts fits well
* within the 32 bit signed integers used in PHP. */
return self::shortToBytes($value, $endian);
}
/**
* Convert an unsigned long into four bytes.
*
* Because PHP limits the size of integers to 32 bit signed, one
* cannot really have an unsigned integer in PHP. But integers
* larger than 2^31-1 will be promoted to 64 bit signed floating
* point numbers, and so such large numbers can be handled too.
*
* @param int the unsigned long that will be converted. The
* argument will be treated as an unsigned 32 bit integer and the
* lower four bytes will be extracted. Treating the argument as an
* unsigned integer means that the absolute value will be used. Use
* {@link sLongToBytes} to convert signed integers.
*
* @param PelByteOrder one of {@link LITTLE_ENDIAN} and {@link
* BIG_ENDIAN}.
*
* @return string the bytes representing the unsigned long.
*/
static function longToBytes($value, $endian) {
/* We cannot convert the number to bytes in the normal way (using
* shifts and modulo calculations) because the PHP operator >> and
* function chr() clip their arguments to 2^31-1, which is the
* largest signed integer known to PHP. But luckily base_convert
* handles such big numbers. */
$hex = str_pad(base_convert($value, 10, 16), 8, '0', STR_PAD_LEFT);
if ($endian == self::LITTLE_ENDIAN)
return (chr(hexdec($hex{6} . $hex{7})) .
chr(hexdec($hex{4} . $hex{5})) .
chr(hexdec($hex{2} . $hex{3})) .
chr(hexdec($hex{0} . $hex{1})));
else
return (chr(hexdec($hex{0} . $hex{1})) .
chr(hexdec($hex{2} . $hex{3})) .
chr(hexdec($hex{4} . $hex{5})) .
chr(hexdec($hex{6} . $hex{7})));
}
/**
* Convert a signed long into four bytes.
*
* @param int the signed long that will be converted. The argument
* will be treated as a signed 32 bit integer, from which the lower
* four bytes will be extracted.
*
* @param PelByteOrder one of {@link LITTLE_ENDIAN} and {@link
* BIG_ENDIAN}.
*
* @return string the bytes representing the signed long.
*/
static function sLongToBytes($value, $endian) {
/* We can convert the number into bytes in the normal way using
* shifts and modulo calculations here (in contrast with
* longToBytes) because PHP automatically handles 32 bit signed
* integers for us. */
if ($endian == self::LITTLE_ENDIAN)
return (chr($value) .
chr($value >> 8) .
chr($value >> 16) .
chr($value >> 24));
else
return (chr($value >> 24) .
chr($value >> 16) .
chr($value >> 8) .
chr($value));
}
/**
* Extract an unsigned byte from a string of bytes.
*
* @param string the bytes.
*
* @param int the offset. The byte found at the offset will be
* returned as an integer. The must be at least one byte available
* at offset.
*
* @return int the unsigned byte found at offset, e.g., an integer
* in the range 0 to 255.
*/
static function bytesToByte($bytes, $offset) {
return ord($bytes{$offset});
}
/**
* Extract a signed byte from bytes.
*
* @param string the bytes.
*
* @param int the offset. The byte found at the offset will be
* returned as an integer. The must be at least one byte available
* at offset.
*
* @return int the signed byte found at offset, e.g., an integer in
* the range -128 to 127.
*/
static function bytesToSByte($bytes, $offset) {
$n = self::bytesToByte($bytes, $offset);
if ($n > 127)
return $n - 256;
else
return $n;
}
/**
* Extract an unsigned short from bytes.
*
* @param string the bytes.
*
* @param int the offset. The short found at the offset will be
* returned as an integer. There must be at least two bytes
* available beginning at the offset given.
*
* @return int the unsigned short found at offset, e.g., an integer
* in the range 0 to 65535.
*
* @param PelByteOrder one of {@link LITTLE_ENDIAN} and {@link
* BIG_ENDIAN}.
*/
static function bytesToShort($bytes, $offset, $endian) {
if ($endian == self::LITTLE_ENDIAN)
return (ord($bytes{$offset+1}) * 256 +
ord($bytes{$offset}));
else
return (ord($bytes{$offset}) * 256 +
ord($bytes{$offset+1}));
}
/**
* Extract a signed short from bytes.
*
* @param string the bytes.
*
* @param int the offset. The short found at offset will be returned
* as an integer. There must be at least two bytes available
* beginning at the offset given.
*
* @return int the signed byte found at offset, e.g., an integer in
* the range -32768 to 32767.
*
* @param PelByteOrder one of {@link LITTLE_ENDIAN} and {@link
* BIG_ENDIAN}.
*/
static function bytesToSShort($bytes, $offset, $endian) {
$n = self::bytesToShort($bytes, $offset, $endian);
if ($n > 32767)
return $n - 65536;
else
return $n;
}
/**
* Extract an unsigned long from bytes.
*
* @param string the bytes.
*
* @param int the offset. The long found at offset will be returned
* as an integer. There must be at least four bytes available
* beginning at the offset given.
*
* @return int the unsigned long found at offset, e.g., an integer
* in the range 0 to 4294967295.
*
* @param PelByteOrder one of {@link LITTLE_ENDIAN} and {@link
* BIG_ENDIAN}.
*/
static function bytesToLong($bytes, $offset, $endian) {
if ($endian == self::LITTLE_ENDIAN)
return (ord($bytes{$offset+3}) * 16777216 +
ord($bytes{$offset+2}) * 65536 +
ord($bytes{$offset+1}) * 256 +
ord($bytes{$offset}));
else
return (ord($bytes{$offset}) * 16777216 +
ord($bytes{$offset+1}) * 65536 +
ord($bytes{$offset+2}) * 256 +
ord($bytes{$offset+3}));
}
/**
* Extract a signed long from bytes.
*
* @param string the bytes.
*
* @param int the offset. The long found at offset will be returned
* as an integer. There must be at least four bytes available
* beginning at the offset given.
*
* @return int the signed long found at offset, e.g., an integer in
* the range -2147483648 to 2147483647.
*
* @param PelByteOrder one of {@link LITTLE_ENDIAN} and {@link
* BIG_ENDIAN}.
*/
static function bytesToSLong($bytes, $offset, $endian) {
$n = self::bytesToLong($bytes, $offset, $endian);
if ($n > 2147483647)
return $n - 4294967296;
else
return $n;
}
/**
* Extract an unsigned rational from bytes.
*
* @param string the bytes.
*
* @param int the offset. The rational found at offset will be
* returned as an array. There must be at least eight bytes
* available beginning at the offset given.
*
* @return array the unsigned rational found at offset, e.g., an
* array with two integers in the range 0 to 4294967295.
*
* @param PelByteOrder one of {@link LITTLE_ENDIAN} and {@link
* BIG_ENDIAN}.
*/
static function bytesToRational($bytes, $offset, $endian) {
return array(self::bytesToLong($bytes, $offset, $endian),
self::bytesToLong($bytes, $offset+4, $endian));
}
/**
* Extract a signed rational from bytes.
*
* @param string the bytes.
*
* @param int the offset. The rational found at offset will be
* returned as an array. There must be at least eight bytes
* available beginning at the offset given.
*
* @return array the signed rational found at offset, e.g., an array
* with two integers in the range -2147483648 to 2147483647.
*
* @param PelByteOrder one of {@link LITTLE_ENDIAN} and {@link
* BIG_ENDIAN}.
*/
static function bytesToSRational($bytes, $offset, $endian) {
return array(self::bytesToSLong($bytes, $offset, $endian),
self::bytesToSLong($bytes, $offset+4, $endian));
}
/**
* Format bytes for dumping.
*
* This method is for debug output, it will format a string as a
* hexadecimal dump suitable for display on a terminal. The output
* is printed directly to standard out.
*
* @param string the bytes that will be dumped.
*
* @param int the maximum number of bytes to dump. If this is left
* out (or left to the default of 0), then the entire string will be
* dumped.
*/
static function bytesToDump($bytes, $max = 0) {
$s = strlen($bytes);
if ($max > 0)
$s = min($max, $s);
$line = 24;
for ($i = 0; $i < $s; $i++) {
printf('%02X ', ord($bytes{$i}));
if (($i+1) % $line == 0)
print("\n");
}
print("\n");
}
}
?>

View File

@ -1,525 +0,0 @@
<?php
/* PEL: PHP Exif Library. A library with support for reading and
* writing all Exif headers in JPEG and TIFF images using PHP.
*
* Copyright (C) 2004, 2005 Martin Geisler.
*
* 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 in the file COPYING; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/* $Id: PelDataWindow.php 387 2005-10-05 11:02:52Z mgeisler $ */
/**
* A container for bytes with a limited window of accessible bytes.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @version $Revision: 387 $
* @date $Date: 2005-10-05 13:02:52 +0200 (Wed, 05 Oct 2005) $
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License (GPL)
* @package PEL
*/
/**#@+ Required class definitions. */
require_once('PelException.php');
require_once('PelConvert.php');
/**#@-*/
/**
* An exception thrown when an invalid offset is encountered.
*
* @package PEL
* @subpackage Exception
*/
class PelDataWindowOffsetException extends PelException {}
/**
* An exception thrown when an invalid window is encountered.
*
* @package PEL
* @subpackage Exception
*/
class PelDataWindowWindowException extends PelException {}
/**
* The window.
*
* @package PEL
*/
class PelDataWindow {
/**
* The data held by this window.
*
* The string can contain any kind of data, including binary data.
*
* @var string
*/
private $data = '';
/**
* The byte order currently in use.
*
* This will be the byte order used when data is read using the for
* example the {@link getShort} function. It must be one of {@link
* PelConvert::LITTLE_ENDIAN} and {@link PelConvert::BIG_ENDIAN}.
*
* @var PelByteOrder
* @see setByteOrder, getByteOrder
*/
private $order;
/**
* The start of the current window.
*
* All offsets used for access into the data will count from this
* offset, effectively limiting access to a window starting at this
* byte.
*
* @var int
* @see setWindowStart
*/
private $start = 0;
/**
* The size of the current window.
*
* All offsets used for access into the data will be limited by this
* variable. A valid offset must be strictly less than this
* variable.
*
* @var int
* @see setWindowSize
*/
private $size = 0;
/**
* Construct a new data window with the data supplied.
*
* @param string the data that this window will contain. The data
* will be copied into the new data window.
*
* @param boolean the initial byte order of the window. This must
* be either {@link PelConvert::LITTLE_ENDIAN} or {@link
* PelConvert::BIG_ENDIAN}. This will be used when integers are
* read from the data, and it can be changed later with {@link
* setByteOrder()}.
*/
function __construct($d = '', $e = PelConvert::LITTLE_ENDIAN) {
$this->data = $d;
$this->order = $e;
$this->size = strlen($d);
}
/**
* Get the size of the data window.
*
* @return int the number of bytes covered by the window. The
* allowed offsets go from 0 up to this number minus one.
*
* @see getBytes()
*/
function getSize() {
return $this->size;
}
/**
* Change the byte order of the data.
*
* @param PelByteOrder the new byte order. This must be either
* {@link PelConvert::LITTLE_ENDIAN} or {@link
* PelConvert::BIG_ENDIAN}.
*/
function setByteOrder($o) {
$this->order = $o;
}
/**
* Get the currently used byte order.
*
* @return PelByteOrder this will be either {@link
* PelConvert::LITTLE_ENDIAN} or {@link PelConvert::BIG_ENDIAN}.
*/
function getByteOrder() {
return $this->order;
}
/* Move the start of the window forward.
*
* @param int the new start of the window. All new offsets will be
* calculated from this new start offset, and the size of the window
* will shrink to keep the end of the window in place.
*/
function setWindowStart($start) {
if ($start < 0 || $start > $this->size)
throw new PelDataWindowWindowException('Window [%d, %d] does ' .
'not fit in window [0, %d]',
$start, $this->size, $this->size);
$this->start += $start;
$this->size -= $start;
}
/**
* Adjust the size of the window.
*
* The size can only be made smaller.
*
* @param int the desired size of the window. If the argument is
* negative, the window will be shrunk by the argument.
*/
function setWindowSize($size) {
if ($size < 0)
$size += $this->size;
if ($size < 0 || $size > $this->size)
throw new PelDataWindowWindowException('Window [0, %d] ' .
'does not fit in window [0, %d]',
$size, $this->size);
$this->size = $size;
}
/**
* Make a new data window with the same data as the this window.
*
* @param mixed if an integer is supplied, then it will be the start
* of the window in the clone. If left unspecified, then the clone
* will inherit the start from this object.
*
* @param mixed if an integer is supplied, then it will be the size
* of the window in the clone. If left unspecified, then the clone
* will inherit the size from this object.
*
* @return PelDataWindow a new window that operates on the same data
* as this window, but (optionally) with a smaller window size.
*/
function getClone($start = false, $size = false) {
$c = clone $this;
if (is_int($start))
$c->setWindowStart($start);
if (is_int($size))
$c->setWindowSize($size);
return $c;
}
/**
* Validate an offset against the current window.
*
* @param int the offset to be validated. If the offset is negative
* or if it is greater than or equal to the current window size,
* then a {@link PelDataWindowOffsetException} is thrown.
*
* @return void if the offset is valid nothing is returned, if it is
* invalid a new {@link PelDataWindowOffsetException} is thrown.
*/
private function validateOffset($o) {
if ($o < 0 || $o >= $this->size)
throw new PelDataWindowOffsetException('Offset %d not within [%d, %d]',
$o, 0, $this->size-1);
}
/**
* Return some or all bytes visible in the window.
*
* This method works just like the standard {@link substr()}
* function in PHP with the exception that it works within the
* window of accessible bytes and does strict range checking.
*
* @param int the offset to the first byte returned. If a negative
* number is given, then the counting will be from the end of the
* window. Invalid offsets will result in a {@link
* PelDataWindowOffsetException} being thrown.
*
* @param int the size of the sub-window. If a negative number is
* given, then that many bytes will be omitted from the result.
*
* @return string a subset of the bytes in the window. This will
* always return no more than {@link getSize()} bytes.
*/
function getBytes($start = false, $size = false) {
if (is_int($start)) {
if ($start < 0)
$start += $this->size;
$this->validateOffset($start);
} else {
$start = 0;
}
if (is_int($size)) {
if ($size <= 0)
$size += $this->size - $start;
$this->validateOffset($start+$size);
} else {
$size = $this->size - $start;
}
return substr($this->data, $this->start + $start, $size);
}
/**
* Return an unsigned byte from the data.
*
* @param int the offset into the data. An offset of zero will
* return the first byte in the current allowed window. The last
* valid offset is equal to {@link getSize()}-1. Invalid offsets
* will result in a {@link PelDataWindowOffsetException} being
* thrown.
*
* @return int the unsigned byte found at offset.
*/
function getByte($o = 0) {
/* Validate the offset --- this throws an exception if offset is
* out of range. */
$this->validateOffset($o);
/* Translate the offset into an offset into the data. */
$o += $this->start;
/* Return an unsigned byte. */
return PelConvert::bytesToByte($this->data, $o);
}
/**
* Return a signed byte from the data.
*
* @param int the offset into the data. An offset of zero will
* return the first byte in the current allowed window. The last
* valid offset is equal to {@link getSize()}-1. Invalid offsets
* will result in a {@link PelDataWindowOffsetException} being
* thrown.
*
* @return int the signed byte found at offset.
*/
function getSByte($o = 0) {
/* Validate the offset --- this throws an exception if offset is
* out of range. */
$this->validateOffset($o);
/* Translate the offset into an offset into the data. */
$o += $this->start;
/* Return a signed byte. */
return PelConvert::bytesToSByte($this->data, $o);
}
/**
* Return an unsigned short read from the data.
*
* @param int the offset into the data. An offset of zero will
* return the first short available in the current allowed window.
* The last valid offset is equal to {@link getSize()}-2. Invalid
* offsets will result in a {@link PelDataWindowOffsetException}
* being thrown.
*
* @return int the unsigned short found at offset.
*/
function getShort($o = 0) {
/* Validate the offset+1 to see if we can safely get two bytes ---
* this throws an exception if offset is out of range. */
$this->validateOffset($o);
$this->validateOffset($o+1);
/* Translate the offset into an offset into the data. */
$o += $this->start;
/* Return an unsigned short. */
return PelConvert::bytesToShort($this->data, $o, $this->order);
}
/**
* Return a signed short read from the data.
*
* @param int the offset into the data. An offset of zero will
* return the first short available in the current allowed window.
* The last valid offset is equal to {@link getSize()}-2. Invalid
* offsets will result in a {@link PelDataWindowOffsetException}
* being thrown.
*
* @return int the signed short found at offset.
*/
function getSShort($o = 0) {
/* Validate the offset+1 to see if we can safely get two bytes ---
* this throws an exception if offset is out of range. */
$this->validateOffset($o);
$this->validateOffset($o+1);
/* Translate the offset into an offset into the data. */
$o += $this->start;
/* Return a signed short. */
return PelConvert::bytesToSShort($this->data, $o, $this->order);
}
/**
* Return an unsigned long read from the data.
*
* @param int the offset into the data. An offset of zero will
* return the first long available in the current allowed window.
* The last valid offset is equal to {@link getSize()}-4. Invalid
* offsets will result in a {@link PelDataWindowOffsetException}
* being thrown.
*
* @return int the unsigned long found at offset.
*/
function getLong($o = 0) {
/* Validate the offset+3 to see if we can safely get four bytes
* --- this throws an exception if offset is out of range. */
$this->validateOffset($o);
$this->validateOffset($o+3);
/* Translate the offset into an offset into the data. */
$o += $this->start;
/* Return an unsigned long. */
return PelConvert::bytesToLong($this->data, $o, $this->order);
}
/**
* Return a signed long read from the data.
*
* @param int the offset into the data. An offset of zero will
* return the first long available in the current allowed window.
* The last valid offset is equal to {@link getSize()}-4. Invalid
* offsets will result in a {@link PelDataWindowOffsetException}
* being thrown.
*
* @return int the signed long found at offset.
*/
function getSLong($o = 0) {
/* Validate the offset+3 to see if we can safely get four bytes
* --- this throws an exception if offset is out of range. */
$this->validateOffset($o);
$this->validateOffset($o+3);
/* Translate the offset into an offset into the data. */
$o += $this->start;
/* Return a signed long. */
return PelConvert::bytesToSLong($this->data, $o, $this->order);
}
/**
* Return an unsigned rational read from the data.
*
* @param int the offset into the data. An offset of zero will
* return the first rational available in the current allowed
* window. The last valid offset is equal to {@link getSize()}-8.
* Invalid offsets will result in a {@link
* PelDataWindowOffsetException} being thrown.
*
* @return array the unsigned rational found at offset. A rational
* number is represented as an array of two numbers: the enumerator
* and denominator. Both of these numbers will be unsigned longs.
*/
function getRational($o = 0) {
return array($this->getLong($o), $this->getLong($o+4));
}
/**
* Return a signed rational read from the data.
*
* @param int the offset into the data. An offset of zero will
* return the first rational available in the current allowed
* window. The last valid offset is equal to {@link getSize()}-8.
* Invalid offsets will result in a {@link
* PelDataWindowOffsetException} being thrown.
*
* @return array the signed rational found at offset. A rational
* number is represented as an array of two numbers: the enumerator
* and denominator. Both of these numbers will be signed longs.
*/
function getSRational($o = 0) {
return array($this->getSLong($o), $this->getSLong($o+4));
}
/**
* String comparison on substrings.
*
* @param int the offset into the data. An offset of zero will make
* the comparison start with the very first byte available in the
* window. The last valid offset is equal to {@link getSize()}
* minus the length of the string. If the string is too long, then
* a {@link PelDataWindowOffsetException} will be thrown.
*
* @param string the string to compare with.
*
* @return boolean true if the string given matches the data in the
* window, at the specified offset, false otherwise. The comparison
* will stop as soon as a mismatch if found.
*/
function strcmp($o, $str) {
/* Validate the offset of the final character we might have to
* check. */
$s = strlen($str);
$this->validateOffset($o);
$this->validateOffset($o + $s - 1);
/* Translate the offset into an offset into the data. */
$o += $this->start;
/* Check each character, return as soon as the answer is known. */
for ($i = 0; $i < $s; $i++) {
if ($this->data{$o + $i} != $str{$i})
return false;
}
/* All characters matches each other, return true. */
return true;
}
/**
* Return a string representation of the data window.
*
* @return string a description of the window with information about
* the number of bytes accessible, the total number of bytes, and
* the window start and stop.
*/
function __toString() {
return Pel::fmt('DataWindow: %d bytes in [%d, %d] of %d bytes',
$this->size,
$this->start, $this->start + $this->size,
strlen($this->data));
}
}
?>

View File

@ -1,382 +0,0 @@
<?php
/* PEL: PHP Exif Library. A library with support for reading and
* writing all Exif headers in JPEG and TIFF images using PHP.
*
* Copyright (C) 2004, 2005, 2006 Martin Geisler.
*
* 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 in the file COPYING; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/* $Id: PelEntry.php 442 2006-09-17 12:45:10Z mgeisler $ */
/**
* Classes for dealing with Exif entries.
*
* This file defines two exception classes and the abstract class
* {@link PelEntry} which provides the basic methods that all Exif
* entries will have. All Exif entries will be represented by
* descendants of the {@link PelEntry} class --- the class itself is
* abstract and so it cannot be instantiated.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @version $Revision: 442 $
* @date $Date: 2006-09-17 14:45:10 +0200 (Sun, 17 Sep 2006) $
* @license http://www.gnu.org/licenses/gpl.html GNU General Public
* License (GPL)
* @package PEL
*/
/**#@+ Required class definitions. */
require_once('PelException.php');
require_once('PelFormat.php');
require_once('PelTag.php');
require_once('Pel.php');
/**#@-*/
/**
* Exception indicating a problem with an entry.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @package PEL
* @subpackage Exception
*/
class PelEntryException extends PelException {
/**
* The IFD type (if known).
*
* @var int
*/
protected $type;
/**
* The tag of the entry (if known).
*
* @var PelTag
*/
protected $tag;
/**
* Get the IFD type associated with the exception.
*
* @return int one of {@link PelIfd::IFD0}, {@link PelIfd::IFD1},
* {@link PelIfd::EXIF}, {@link PelIfd::GPS}, or {@link
* PelIfd::INTEROPERABILITY}. If no type is set, null is returned.
*/
function getIfdType() {
return $this->type;
}
/**
* Get the tag associated with the exception.
*
* @return PelTag the tag. If no tag is set, null is returned.
*/
function getTag() {
return $this->tag;
}
}
/**
* Exception indicating that an unexpected format was found.
*
* The documentation for each tag in {@link PelTag} will detail any
* constrains.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @package PEL
* @subpackage Exception
*/
class PelUnexpectedFormatException extends PelEntryException {
/**
* Construct a new exception indicating an invalid format.
*
* @param int the type of IFD.
*
* @param PelTag the tag for which the violation was found.
*
* @param PelFormat the format found.
*
* @param PelFormat the expected format.
*/
function __construct($type, $tag, $found, $expected) {
parent::__construct('Unexpected format found for %s tag: PelFormat::%s. ' .
'Expected PelFormat::%s instead.',
PelTag::getName($type, $tag),
strtoupper(PelFormat::getName($found)),
strtoupper(PelFormat::getName($expected)));
$this->tag = $tag;
$this->type = $type;
}
}
/**
* Exception indicating that an unexpected number of components was
* found.
*
* Some tags have strict limits as to the allowed number of
* components, and this exception is thrown if the data violates such
* a constraint. The documentation for each tag in {@link PelTag}
* explains the expected number of components.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @package PEL
* @subpackage Exception
*/
class PelWrongComponentCountException extends PelEntryException {
/**
* Construct a new exception indicating a wrong number of
* components.
*
* @param int the type of IFD.
*
* @param PelTag the tag for which the violation was found.
*
* @param int the number of components found.
*
* @param int the expected number of components.
*/
function __construct($type, $tag, $found, $expected) {
parent::__construct('Wrong number of components found for %s tag: %d. ' .
'Expected %d.',
PelTag::getName($type, $tag), $found, $expected);
$this->tag = $tag;
$this->type = $type;
}
}
/**
* Common ancestor class of all {@link PelIfd} entries.
*
* As this class is abstract you cannot instantiate objects from it.
* It only serves as a common ancestor to define the methods common to
* all entries. The most important methods are {@link getValue()} and
* {@link setValue()}, both of which is abstract in this class. The
* descendants will give concrete implementations for them.
*
* If you have some data coming from an image (some raw bytes), then
* the static method {@link newFromData()} is helpful --- it will look
* at the data and give you a proper decendent of {@link PelEntry}
* back.
*
* If you instead want to have an entry for some data which take the
* form of an integer, a string, a byte, or some other PHP type, then
* don't use this class. You should instead create an object of the
* right subclass ({@link PelEntryShort} for short integers, {@link
* PelEntryAscii} for strings, and so on) directly.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @package PEL
*/
abstract class PelEntry {
/**
* Type of IFD containing this tag.
*
* This must be one of the constants defined in {@link PelIfd}:
* {@link PelIfd::IFD0} for the main image IFD, {@link PelIfd::IFD1}
* for the thumbnail image IFD, {@link PelIfd::EXIF} for the Exif
* sub-IFD, {@link PelIfd::GPS} for the GPS sub-IFD, or {@link
* PelIfd::INTEROPERABILITY} for the interoperability sub-IFD.
*
* @var int
*/
protected $ifd_type;
/**
* The bytes representing this entry.
*
* Subclasses must either override {@link getBytes()} or, if
* possible, maintain this property so that it always contains a
* true representation of the entry.
*
* @var string
*/
protected $bytes = '';
/**
* The {@link PelTag} of this entry.
*
* @var PelTag
*/
protected $tag;
/**
* The {@link PelFormat} of this entry.
*
* @var PelFormat
*/
protected $format;
/**
* The number of components of this entry.
*
* @var int
*/
protected $components;
/**
* Return the tag of this entry.
*
* @return PelTag the tag of this entry.
*/
function getTag() {
return $this->tag;
}
/**
* Return the type of IFD which holds this entry.
*
* @return int one of the constants defined in {@link PelIfd}:
* {@link PelIfd::IFD0} for the main image IFD, {@link PelIfd::IFD1}
* for the thumbnail image IFD, {@link PelIfd::EXIF} for the Exif
* sub-IFD, {@link PelIfd::GPS} for the GPS sub-IFD, or {@link
* PelIfd::INTEROPERABILITY} for the interoperability sub-IFD.
*/
function getIfdType() {
return $this->ifd_type;
}
/**
* Update the IFD type.
*
* @param int must be one of the constants defined in {@link
* PelIfd}: {@link PelIfd::IFD0} for the main image IFD, {@link
* PelIfd::IFD1} for the thumbnail image IFD, {@link PelIfd::EXIF}
* for the Exif sub-IFD, {@link PelIfd::GPS} for the GPS sub-IFD, or
* {@link PelIfd::INTEROPERABILITY} for the interoperability
* sub-IFD.
*/
function setIfdType($type) {
$this->ifd_type = $type;
}
/**
* Return the format of this entry.
*
* @return PelFormat the format of this entry.
*/
function getFormat() {
return $this->format;
}
/**
* Return the number of components of this entry.
*
* @return int the number of components of this entry.
*/
function getComponents() {
return $this->components;
}
/**
* Turn this entry into bytes.
*
* @param PelByteOrder the desired byte order, which must be either
* {@link Convert::LITTLE_ENDIAN} or {@link Convert::BIG_ENDIAN}.
*
* @return string bytes representing this entry.
*/
function getBytes($o) {
return $this->bytes;
}
/**
* Get the value of this entry as text.
*
* The value will be returned in a format suitable for presentation,
* e.g., rationals will be returned as 'x/y', ASCII strings will be
* returned as themselves etc.
*
* @param boolean some values can be returned in a long or more
* brief form, and this parameter controls that.
*
* @return string the value as text.
*/
abstract function getText($brief = false);
/**
* Get the value of this entry.
*
* The value returned will generally be the same as the one supplied
* to the constructor or with {@link setValue()}. For a formatted
* version of the value, one should use {@link getText()} instead.
*
* @return mixed the unformatted value.
*/
abstract function getValue();
/**
* Set the value of this entry.
*
* The value should be in the same format as for the constructor.
*
* @param mixed the new value.
*
* @abstract
*/
function setValue($value) {
/* This (fake) abstract method is here to make it possible for the
* documentation to refer to PelEntry::setValue().
*
* It cannot declared abstract in the proper PHP way, for then PHP
* wont allow subclasses to define it with two arguments (which is
* what PelEntryCopyright does).
*/
throw new PelException('setValue() is abstract.');
}
/**
* Turn this entry into a string.
*
* @return string a string representation of this entry. This is
* mostly for debugging.
*/
function __toString() {
$str = Pel::fmt(" Tag: 0x%04X (%s)\n",
$this->tag, PelTag::getName($this->ifd_type, $this->tag));
$str .= Pel::fmt(" Format : %d (%s)\n",
$this->format, PelFormat::getName($this->format));
$str .= Pel::fmt(" Components: %d\n", $this->components);
if ($this->getTag() != PelTag::MAKER_NOTE &&
$this->getTag() != PelTag::PRINT_IM)
$str .= Pel::fmt(" Value : %s\n", print_r($this->getValue(), true));
$str .= Pel::fmt(" Text : %s\n", $this->getText());
return $str;
}
}
?>

View File

@ -1,482 +0,0 @@
<?php
/* PEL: PHP Exif Library. A library with support for reading and
* writing all Exif headers in JPEG and TIFF images using PHP.
*
* Copyright (C) 2004, 2005, 2006 Martin Geisler.
*
* 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 in the file COPYING; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/* $Id: PelEntryAscii.php 443 2006-09-17 18:32:04Z mgeisler $ */
/**
* Classes used to hold ASCII strings.
*
* The classes defined here are to be used for Exif entries holding
* ASCII strings, such as {@link PelTag::MAKE}, {@link
* PelTag::SOFTWARE}, and {@link PelTag::DATE_TIME}. For
* entries holding normal textual ASCII strings the class {@link
* PelEntryAscii} should be used, but for entries holding
* timestamps the class {@link PelEntryTime} would be more
* convenient instead. Copyright information is handled by the {@link
* PelEntryCopyright} class.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @version $Revision: 443 $
* @date $Date: 2006-09-17 20:32:04 +0200 (Sun, 17 Sep 2006) $
* @license http://www.gnu.org/licenses/gpl.html GNU General Public
* License (GPL)
* @package PEL
*/
/**#@+ Required class definitions. */
require_once('PelEntry.php');
/**#@-*/
/**
* Class for holding a plain ASCII string.
*
* This class can hold a single ASCII string, and it will be used as in
* <code>
* $entry = $ifd->getEntry(PelTag::IMAGE_DESCRIPTION);
* print($entry->getValue());
* $entry->setValue('This is my image. I like it.');
* </code>
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @package PEL
*/
class PelEntryAscii extends PelEntry {
/**
* The string hold by this entry.
*
* This is the string that was given to the {@link __construct
* constructor} or later to {@link setValue}, without any final NULL
* character.
*
* @var string
*/
private $str;
/**
* Make a new PelEntry that can hold an ASCII string.
*
* @param int the tag which this entry represents. This should be
* one of the constants defined in {@link PelTag}, e.g., {@link
* PelTag::IMAGE_DESCRIPTION}, {@link PelTag::MODEL}, or any other
* tag with format {@link PelFormat::ASCII}.
*
* @param string the string that this entry will represent. The
* string must obey the same rules as the string argument to {@link
* setValue}, namely that it should be given without any trailing
* NULL character and that it must be plain 7-bit ASCII.
*/
function __construct($tag, $str = '') {
$this->tag = $tag;
$this->format = PelFormat::ASCII;
$this->setValue($str);
}
/**
* Give the entry a new ASCII value.
*
* This will overwrite the previous value. The value can be
* retrieved later with the {@link getValue} method.
*
* @param string the new value of the entry. This should be given
* without any trailing NULL character. The string must be plain
* 7-bit ASCII, the string should contain no high bytes.
*
* @todo Implement check for high bytes?
*/
function setValue($str) {
$this->components = strlen($str)+1;
$this->str = $str;
$this->bytes = $str . chr(0x00);
}
/**
* Return the ASCII string of the entry.
*
* @return string the string held, without any final NULL character.
* The string will be the same as the one given to {@link setValue}
* or to the {@link __construct constructor}.
*/
function getValue() {
return $this->str;
}
/**
* Return the ASCII string of the entry.
*
* This methods returns the same as {@link getValue}.
*
* @param boolean not used with ASCII entries.
*
* @return string the string held, without any final NULL character.
* The string will be the same as the one given to {@link setValue}
* or to the {@link __construct constructor}.
*/
function getText($brief = false) {
return $this->str;
}
}
/**
* Class for holding a date and time.
*
* This class can hold a timestamp, and it will be used as
* in this example where the time is advanced by one week:
* <code>
* $entry = $ifd->getEntry(PelTag::DATE_TIME_ORIGINAL);
* $time = $entry->getValue();
* print('The image was taken on the ' . date($time, 'jS'));
* $entry->setValue($time + 7 * 24 * 3600);
* </code>
*
* The example used a standard UNIX timestamp, which is the default
* for this class.
*
* But the Exif format defines dates outside the range of a UNIX
* timestamp (about 1970 to 2038) and so you can also get access to
* the timestamp in two other formats: a simple string or a Julian Day
* Count. Please see the Calendar extension in the PHP Manual for more
* information about the Julian Day Count.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @package PEL
*/
class PelEntryTime extends PelEntryAscii {
/**
* Constant denoting a UNIX timestamp.
*/
const UNIX_TIMESTAMP = 1;
/**
* Constant denoting a Exif string.
*/
const EXIF_STRING = 2;
/**
* Constant denoting a Julian Day Count.
*/
const JULIAN_DAY_COUNT = 3;
/**
* The Julian Day Count of the timestamp held by this entry.
*
* This is an integer counting the number of whole days since
* January 1st, 4713 B.C. The fractional part of the timestamp held
* by this entry is stored in {@link $seconds}.
*
* @var int
*/
private $day_count;
/**
* The number of seconds into the day of the timestamp held by this
* entry.
*
* The number of whole days is stored in {@link $day_count} and the
* number of seconds left-over is stored here.
*
* @var int
*/
private $seconds;
/**
* Make a new entry for holding a timestamp.
*
* @param int the Exif tag which this entry represents. There are
* only three standard tags which hold timestamp, so this should be
* one of the constants {@link PelTag::DATE_TIME}, {@link
* PelTag::DATE_TIME_ORIGINAL}, or {@link
* PelTag::DATE_TIME_DIGITIZED}.
*
* @param int the timestamp held by this entry in the correct form
* as indicated by the third argument. For {@link UNIX_TIMESTAMP}
* this is an integer counting the number of seconds since January
* 1st 1970, for {@link EXIF_STRING} this is a string of the form
* 'YYYY:MM:DD hh:mm:ss', and for {@link JULIAN_DAY_COUNT} this is a
* floating point number where the integer part denotes the day
* count and the fractional part denotes the time of day (0.25 means
* 6:00, 0.75 means 18:00).
*
* @param int the type of the timestamp. This must be one of
* {@link UNIX_TIMESTAMP}, {@link EXIF_STRING}, or
* {@link JULIAN_DAY_COUNT}.
*/
function __construct($tag, $timestamp, $type = self::UNIX_TIMESTAMP) {
parent::__construct($tag);
$this->setValue($timestamp, $type);
}
/**
* Return the timestamp of the entry.
*
* The timestamp held by this entry is returned in one of three
* formats: as a standard UNIX timestamp (default), as a fractional
* Julian Day Count, or as a string.
*
* @param int the type of the timestamp. This must be one of
* {@link UNIX_TIMESTAMP}, {@link EXIF_STRING}, or
* {@link JULIAN_DAY_COUNT}.
*
* @return int the timestamp held by this entry in the correct form
* as indicated by the type argument. For {@link UNIX_TIMESTAMP}
* this is an integer counting the number of seconds since January
* 1st 1970, for {@link EXIF_STRING} this is a string of the form
* 'YYYY:MM:DD hh:mm:ss', and for {@link JULIAN_DAY_COUNT} this is a
* floating point number where the integer part denotes the day
* count and the fractional part denotes the time of day (0.25 means
* 6:00, 0.75 means 18:00).
*/
function getValue($type = self::UNIX_TIMESTAMP) {
switch ($type) {
case self::UNIX_TIMESTAMP:
$seconds = jdtounix($this->day_count);
if ($seconds === false)
/* jdtounix() return false if the Julian Day Count is outside
* the range of a UNIX timestamp. */
return false;
else
return $seconds + $this->seconds;
case self::EXIF_STRING:
list($month, $day, $year) = explode('/', jdtogregorian($this->day_count));
$hours = (int)($this->seconds / 3600);
$minutes = (int)($this->seconds % 3600 / 60);
$seconds = $this->seconds % 60;
return sprintf('%04d:%02d:%02d %02d:%02d:%02d',
$year, $month, $day, $hours, $minutes, $seconds);
case self::JULIAN_DAY_COUNT:
return $this->day_count + $this->seconds / 86400;
default:
throw new PelInvalidArgumentException('Expected UNIX_TIMESTAMP (%d), ' .
'EXIF_STRING (%d), or ' .
'JULIAN_DAY_COUNT (%d) for $type, '.
'got %d.',
self::UNIX_TIMESTAMP,
self::EXIF_STRING,
self::JULIAN_DAY_COUNT,
$type);
}
}
/**
* Update the timestamp held by this entry.
*
* @param int the timestamp held by this entry in the correct form
* as indicated by the third argument. For {@link UNIX_TIMESTAMP}
* this is an integer counting the number of seconds since January
* 1st 1970, for {@link EXIF_STRING} this is a string of the form
* 'YYYY:MM:DD hh:mm:ss', and for {@link JULIAN_DAY_COUNT} this is a
* floating point number where the integer part denotes the day
* count and the fractional part denotes the time of day (0.25 means
* 6:00, 0.75 means 18:00).
*
* @param int the type of the timestamp. This must be one of
* {@link UNIX_TIMESTAMP}, {@link EXIF_STRING}, or
* {@link JULIAN_DAY_COUNT}.
*
* @todo How to deal with timezones? Use the TimeZoneOffset tag
* 0x882A?
*/
function setValue($timestamp, $type = self::UNIX_TIMESTAMP) {
switch ($type) {
case self::UNIX_TIMESTAMP:
$this->day_count = unixtojd($timestamp);
$this->seconds = $timestamp % 86400;
break;
case self::EXIF_STRING:
/* Clean the timestamp: some timestamps are broken other
* separators than ':' and ' '. */
$d = split('[^0-9]+', $timestamp);
$this->day_count = gregoriantojd($d[1], $d[2], $d[0]);
$this->seconds = $d[3]*3600 + $d[4]*60 + $d[5];
break;
case self::JULIAN_DAY_COUNT:
$this->day_count = (int)floor($timestamp);
$this->seconds = (int)(86400 * ($timestamp - floor($timestamp)));
break;
default:
throw new PelInvalidArgumentException('Expected UNIX_TIMESTAMP (%d), ' .
'EXIF_STRING (%d), or ' .
'JULIAN_DAY_COUNT (%d) for $type, '.
'got %d.',
self::UNIX_TIMESTAMP,
self::EXIF_STRING,
self::JULIAN_DAY_COUNT,
$type);
}
/* Now finally update the string which will be used when this is
* turned into bytes. */
parent::setValue($this->getValue(self::EXIF_STRING));
}
}
/**
* Class for holding copyright information.
*
* The Exif standard specifies a certain format for copyright
* information where the one {@link PelTag::COPYRIGHT copyright
* tag} holds both the photographer and editor copyrights, separated
* by a NULL character.
*
* This class is used to manipulate that tag so that the format is
* kept to the standard. A common use would be to add a new copyright
* tag to an image, since most cameras do not add this tag themselves.
* This would be done like this:
*
* <code>
* $entry = new PelEntryCopyright('Copyright, Martin Geisler, 2004');
* $ifd0->addEntry($entry);
* </code>
*
* Here we only set the photographer copyright, use the optional
* second argument to specify the editor copyright. If there is only
* an editor copyright, then let the first argument be the empty
* string.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @package PEL
*/
class PelEntryCopyright extends PelEntryAscii {
/**
* The photographer copyright.
*
* @var string
*/
private $photographer;
/**
* The editor copyright.
*
* @var string
*/
private $editor;
/**
* Make a new entry for holding copyright information.
*
* @param string the photographer copyright. Use the empty string
* if there is no photographer copyright.
*
* @param string the editor copyright. Use the empty string if
* there is no editor copyright.
*/
function __construct($photographer = '', $editor = '') {
parent::__construct(PelTag::COPYRIGHT);
$this->setValue($photographer, $editor);
}
/**
* Update the copyright information.
*
* @param string the photographer copyright. Use the empty string
* if there is no photographer copyright.
*
* @param string the editor copyright. Use the empty string if
* there is no editor copyright.
*/
function setValue($photographer = '', $editor = '') {
$this->photographer = $photographer;
$this->editor = $editor;
if ($photographer == '' && $editor != '')
$photographer = ' ';
if ($editor == '')
parent::setValue($photographer);
else
parent::setValue($photographer . chr(0x00) . $editor);
}
/**
* Retrive the copyright information.
*
* The strings returned will be the same as the one used previously
* with either {@link __construct the constructor} or with {@link
* setValue}.
*
* @return array an array with two strings, the photographer and
* editor copyrights. The two fields will be returned in that
* order, so that the first array index will be the photographer
* copyright, and the second will be the editor copyright.
*/
function getValue() {
return array($this->photographer, $this->editor);
}
/**
* Return a text string with the copyright information.
*
* The photographer and editor copyright fields will be returned
* with a '-' in between if both copyright fields are present,
* otherwise only one of them will be returned.
*
* @param boolean if false, then the strings '(Photographer)' and
* '(Editor)' will be appended to the photographer and editor
* copyright fields (if present), otherwise the fields will be
* returned as is.
*
* @return string the copyright information in a string.
*/
function getText($brief = false) {
if ($brief) {
$p = '';
$e = '';
} else {
$p = ' ' . Pel::tra('(Photographer)');
$e = ' ' . Pel::tra('(Editor)');
}
if ($this->photographer != '' && $this->editor != '')
return $this->photographer . $p . ' - ' . $this->editor . $e;
if ($this->photographer != '')
return $this->photographer . $p;
if ($this->editor != '')
return $this->editor . $e;
return '';
}
}
?>

View File

@ -1,275 +0,0 @@
<?php
/* PEL: PHP Exif Library. A library with support for reading and
* writing all Exif headers in JPEG and TIFF images using PHP.
*
* Copyright (C) 2004, 2005, 2006 Martin Geisler.
*
* 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 in the file COPYING; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/* $Id: PelEntryByte.php 419 2006-02-20 16:22:36Z mgeisler $ */
/**
* Classes used to hold bytes, both signed and unsigned. The {@link
* PelEntryWindowsString} class is used to manipulate strings in the
* format Windows XP needs.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @version $Revision: 419 $
* @date $Date: 2006-02-20 17:22:36 +0100 (Mon, 20 Feb 2006) $
* @license http://www.gnu.org/licenses/gpl.html GNU General Public
* License (GPL)
* @package PEL
*/
/**#@+ Required class definitions. */
require_once('PelEntryNumber.php');
/**#@-*/
/**
* Class for holding unsigned bytes.
*
* This class can hold bytes, either just a single byte or an array of
* bytes. The class will be used to manipulate any of the Exif tags
* which has format {@link PelFormat::BYTE}.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @package PEL
*/
class PelEntryByte extends PelEntryNumber {
/**
* Make a new entry that can hold an unsigned byte.
*
* The method accept several integer arguments. The {@link
* getValue} method will always return an array except for when a
* single integer argument is given here.
*
* @param PelTag the tag which this entry represents. This
* should be one of the constants defined in {@link PelTag}
* which has format {@link PelFormat::BYTE}.
*
* @param int $value... the byte(s) that this entry will represent.
* The argument passed must obey the same rules as the argument to
* {@link setValue}, namely that it should be within range of an
* unsigned byte, that is between 0 and 255 (inclusive). If not,
* then a {@link PelOverflowException} will be thrown.
*/
function __construct($tag /* $value... */) {
$this->tag = $tag;
$this->min = 0;
$this->max = 255;
$this->format = PelFormat::BYTE;
$value = func_get_args();
array_shift($value);
$this->setValueArray($value);
}
/**
* Convert a number into bytes.
*
* @param int the number that should be converted.
*
* @param PelByteOrder one of {@link PelConvert::LITTLE_ENDIAN} and
* {@link PelConvert::BIG_ENDIAN}, specifying the target byte order.
*
* @return string bytes representing the number given.
*/
function numberToBytes($number, $order) {
return chr($number);
}
}
/**
* Class for holding signed bytes.
*
* This class can hold bytes, either just a single byte or an array of
* bytes. The class will be used to manipulate any of the Exif tags
* which has format {@link PelFormat::BYTE}.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @package PEL
*/
class PelEntrySByte extends PelEntryNumber {
/**
* Make a new entry that can hold a signed byte.
*
* The method accept several integer arguments. The {@link getValue}
* method will always return an array except for when a single
* integer argument is given here.
*
* @param PelTag the tag which this entry represents. This
* should be one of the constants defined in {@link PelTag}
* which has format {@link PelFormat::BYTE}.
*
* @param int $value... the byte(s) that this entry will represent.
* The argument passed must obey the same rules as the argument to
* {@link setValue}, namely that it should be within range of a
* signed byte, that is between -128 and 127 (inclusive). If not,
* then a {@link PelOverflowException} will be thrown.
*/
function __construct($tag /* $value... */) {
$this->tag = $tag;
$this->min = -128;
$this->max = 127;
$this->format = PelFormat::SBYTE;
$value = func_get_args();
array_shift($value);
$this->setValueArray($value);
}
/**
* Convert a number into bytes.
*
* @param int the number that should be converted.
*
* @param PelByteOrder one of {@link PelConvert::LITTLE_ENDIAN} and
* {@link PelConvert::BIG_ENDIAN}, specifying the target byte order.
*
* @return string bytes representing the number given.
*/
function numberToBytes($number, $order) {
return chr($number);
}
}
/**
* Class used to manipulate strings in the format Windows XP uses.
*
* When examining the file properties of an image in Windows XP one
* can fill in title, comment, author, keyword, and subject fields.
* Filling those fields and pressing OK will result in the data being
* written into the Exif data in the image.
*
* The data is written in a non-standard format and can thus not be
* loaded directly --- this class is needed to translate it into
* normal strings.
*
* It is important that entries from this class are only created with
* the {@link PelTag::XP_TITLE}, {@link PelTag::XP_COMMENT}, {@link
* PelTag::XP_AUTHOR}, {@link PelTag::XP_KEYWORD}, and {@link
* PelTag::XP_SUBJECT} tags. If another tag is used the data will no
* longer be correctly decoded when reloaded with PEL. (The data will
* be loaded as an {@link PelEntryByte} entry, which isn't as useful.)
*
* This class is to be used as in
* <code>
* $entry = $ifd->getEntry(PelTag::XP_TITLE);
* print($entry->getValue());
* $entry->setValue('My favorite cat');
* </code>
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @package PEL
*/
class PelEntryWindowsString extends PelEntry {
/**
* The string hold by this entry.
*
* This is the string that was given to the {@link __construct
* constructor} or later to {@link setValue}, without any extra NULL
* characters or any such nonsense.
*
* @var string
*/
private $str;
/**
* Make a new PelEntry that can hold a Windows XP specific string.
*
* @param int the tag which this entry represents. This should be
* one of {@link PelTag::XP_TITLE}, {@link PelTag::XP_COMMENT},
* {@link PelTag::XP_AUTHOR}, {@link PelTag::XP_KEYWORD}, and {@link
* PelTag::XP_SUBJECT} tags. If another tag is used, then this
* entry will be incorrectly reloaded as a {@link PelEntryByte}.
*
* @param string the string that this entry will represent. It will
* be passed to {@link setValue} and thus has to obey its
* requirements.
*/
function __construct($tag, $str = '') {
$this->tag = $tag;
$this->format = PelFormat::BYTE;
$this->setValue($str);
}
/**
* Give the entry a new value.
*
* This will overwrite the previous value. The value can be
* retrieved later with the {@link getValue} method.
*
* @param string the new value of the entry. This should be use the
* Latin-1 encoding and be given without any extra NULL characters.
*/
function setValue($str) {
$l = strlen($str);
$this->components = 2 * ($l + 1);
$this->str = $str;
$this->bytes = '';
for ($i = 0; $i < $l; $i++)
$this->bytes .= $str{$i} . chr(0x00);
$this->bytes .= chr(0x00) . chr(0x00);
}
/**
* Return the string of the entry.
*
* @return string the string held, without any extra NULL
* characters. The string will be the same as the one given to
* {@link setValue} or to the {@link __construct constructor}.
*/
function getValue() {
return $this->str;
}
/**
* Return the string of the entry.
*
* This methods returns the same as {@link getValue}.
*
* @param boolean not used.
*
* @return string the string held, without any extra NULL
* characters. The string will be the same as the one given to
* {@link setValue} or to the {@link __construct constructor}.
*/
function getText($brief = false) {
return $this->str;
}
}
?>

View File

@ -1,182 +0,0 @@
<?php
/* PEL: PHP Exif Library. A library with support for reading and
* writing all Exif headers in JPEG and TIFF images using PHP.
*
* Copyright (C) 2004, 2005, 2006 Martin Geisler.
*
* 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 in the file COPYING; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/* $Id: PelEntryLong.php 419 2006-02-20 16:22:36Z mgeisler $ */
/**
* Classes used to hold longs, both signed and unsigned.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @version $Revision: 419 $
* @date $Date: 2006-02-20 17:22:36 +0100 (Mon, 20 Feb 2006) $
* @license http://www.gnu.org/licenses/gpl.html GNU General Public
* License (GPL)
* @package PEL
*/
/**#@+ Required class definitions. */
require_once('PelEntryNumber.php');
/**#@-*/
/**
* Class for holding unsigned longs.
*
* This class can hold longs, either just a single long or an array of
* longs. The class will be used to manipulate any of the Exif tags
* which can have format {@link PelFormat::LONG} like in this
* example:
* <code>
* $w = $ifd->getEntry(PelTag::EXIF_IMAGE_WIDTH);
* $w->setValue($w->getValue() / 2);
* $h = $ifd->getEntry(PelTag::EXIF_IMAGE_HEIGHT);
* $h->setValue($h->getValue() / 2);
* </code>
* Here the width and height is updated to 50% of their original
* values.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @package PEL
*/
class PelEntryLong extends PelEntryNumber {
/**
* Make a new entry that can hold an unsigned long.
*
* The method accept its arguments in two forms: several integer
* arguments or a single array argument. The {@link getValue}
* method will always return an array except for when a single
* integer argument is given here, or when an array with just a
* single integer is given.
*
* This means that one can conveniently use objects like this:
* <code>
* $a = new PelEntryLong(PelTag::EXIF_IMAGE_WIDTH, 123456);
* $b = $a->getValue() - 654321;
* </code>
* where the call to {@link getValue} will return an integer instead
* of an array with one integer element, which would then have to be
* extracted.
*
* @param PelTag the tag which this entry represents. This
* should be one of the constants defined in {@link PelTag},
* e.g., {@link PelTag::IMAGE_WIDTH}, or any other tag which can
* have format {@link PelFormat::LONG}.
*
* @param int $value... the long(s) that this entry will
* represent or an array of longs. The argument passed must obey
* the same rules as the argument to {@link setValue}, namely that
* it should be within range of an unsigned long (32 bit), that is
* between 0 and 4294967295 (inclusive). If not, then a {@link
* PelExifOverflowException} will be thrown.
*/
function __construct($tag /* $value... */) {
$this->tag = $tag;
$this->min = 0;
$this->max = 4294967295;
$this->format = PelFormat::LONG;
$value = func_get_args();
array_shift($value);
$this->setValueArray($value);
}
/**
* Convert a number into bytes.
*
* @param int the number that should be converted.
*
* @param PelByteOrder one of {@link PelConvert::LITTLE_ENDIAN} and
* {@link PelConvert::BIG_ENDIAN}, specifying the target byte order.
*
* @return string bytes representing the number given.
*/
function numberToBytes($number, $order) {
return PelConvert::longToBytes($number, $order);
}
}
/**
* Class for holding signed longs.
*
* This class can hold longs, either just a single long or an array of
* longs. The class will be used to manipulate any of the Exif tags
* which can have format {@link PelFormat::SLONG}.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @package PEL
*/
class PelEntrySLong extends PelEntryNumber {
/**
* Make a new entry that can hold a signed long.
*
* The method accept its arguments in two forms: several integer
* arguments or a single array argument. The {@link getValue}
* method will always return an array except for when a single
* integer argument is given here, or when an array with just a
* single integer is given.
*
* @param PelTag the tag which this entry represents. This
* should be one of the constants defined in {@link PelTag}
* which have format {@link PelFormat::SLONG}.
*
* @param int $value... the long(s) that this entry will represent
* or an array of longs. The argument passed must obey the same
* rules as the argument to {@link setValue}, namely that it should
* be within range of a signed long (32 bit), that is between
* -2147483648 and 2147483647 (inclusive). If not, then a {@link
* PelOverflowException} will be thrown.
*/
function __construct($tag /* $value... */) {
$this->tag = $tag;
$this->min = -2147483648;
$this->max = 2147483647;
$this->format = PelFormat::SLONG;
$value = func_get_args();
array_shift($value);
$this->setValueArray($value);
}
/**
* Convert a number into bytes.
*
* @param int the number that should be converted.
*
* @param PelByteOrder one of {@link PelConvert::LITTLE_ENDIAN} and
* {@link PelConvert::BIG_ENDIAN}, specifying the target byte order.
*
* @return string bytes representing the number given.
*/
function numberToBytes($number, $order) {
return PelConvert::sLongToBytes($number, $order);
}
}
?>

View File

@ -1,309 +0,0 @@
<?php
/* PEL: PHP Exif Library. A library with support for reading and
* writing all Exif headers in JPEG and TIFF images using PHP.
*
* Copyright (C) 2004, 2005, 2006 Martin Geisler.
*
* 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 in the file COPYING; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/* $Id: PelEntryNumber.php 419 2006-02-20 16:22:36Z mgeisler $ */
/**
* Abstract class for numbers.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @version $Revision: 419 $
* @date $Date: 2006-02-20 17:22:36 +0100 (Mon, 20 Feb 2006) $
* @license http://www.gnu.org/licenses/gpl.html GNU General Public
* License (GPL)
* @package PEL
*/
/**#@+ Required class definitions. */
require_once('PelException.php');
require_once('PelEntry.php');
/**#@-*/
/**
* Exception cast when numbers overflow.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @package PEL
* @subpackage Exception
*/
class PelOverflowException extends PelException {
/**
* Construct a new overflow exception.
*
* @param int the value that is out of range.
*
* @param int the minimum allowed value.
*
* @param int the maximum allowed value.
*/
function __construct($v, $min, $max) {
parent::__construct('Value %.0f out of range [%.0f, %.0f]',
$v, $min, $max);
}
}
/**
* Class for holding numbers.
*
* This class can hold numbers, with range checks.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @package PEL
*/
abstract class PelEntryNumber extends PelEntry {
/**
* The value held by this entry.
*
* @var array
*/
protected $value = array();
/**
* The minimum allowed value.
*
* Any attempt to change the value below this variable will result
* in a {@link PelOverflowException} being thrown.
*
* @var int
*/
protected $min;
/**
* The maximum allowed value.
*
* Any attempt to change the value over this variable will result in
* a {@link PelOverflowException} being thrown.
*
* @var int
*/
protected $max;
/**
* The dimension of the number held.
*
* Normal numbers have a dimension of one, pairs have a dimension of
* two, etc.
*
* @var int
*/
protected $dimension = 1;
/**
* Change the value.
*
* This method can change both the number of components and the
* value of the components. Range checks will be made on the new
* value, and a {@link PelOverflowException} will be thrown if the
* value is found to be outside the legal range.
*
* The method accept several number arguments. The {@link getValue}
* method will always return an array except for when a single
* number is given here.
*
* @param int|array $value... the new value(s). This can be zero or
* more numbers, that is, either integers or arrays. The input will
* be checked to ensure that the numbers are within the valid range.
* If not, then a {@link PelOverflowException} will be thrown.
*
* @see getValue
*/
function setValue(/* $value... */) {
$value = func_get_args();
$this->setValueArray($value);
}
/**
* Change the value.
*
* This method can change both the number of components and the
* value of the components. Range checks will be made on the new
* value, and a {@link PelOverflowException} will be thrown if the
* value is found to be outside the legal range.
*
* @param array the new values. The array must contain the new
* numbers.
*
* @see getValue
*/
function setValueArray($value) {
foreach ($value as $v)
$this->validateNumber($v);
$this->components = count($value);
$this->value = $value;
}
/**
* Return the numeric value held.
*
* @return int|array this will either be a single number if there is
* only one component, or an array of numbers otherwise.
*/
function getValue() {
if ($this->components == 1)
return $this->value[0];
else
return $this->value;
}
/**
* Validate a number.
*
* This method will check that the number given is within the range
* given my {@link getMin()} and {@link getMax()}, inclusive. If
* not, then a {@link PelOverflowException} is thrown.
*
* @param int|array the number in question.
*
* @return void nothing, but will throw a {@link
* PelOverflowException} if the number is found to be outside the
* legal range and {@link Pel::$strict} is true.
*/
function validateNumber($n) {
if ($this->dimension == 1) {
if ($n < $this->min || $n > $this->max)
Pel::maybeThrow(new PelOverflowException($n,
$this->min,
$this->max));
} else {
for ($i = 0; $i < $this->dimension; $i++)
if ($n[$i] < $this->min || $n[$i] > $this->max)
Pel::maybeThrow(new PelOverflowException($n[$i],
$this->min,
$this->max));
}
}
/**
* Add a number.
*
* This appends a number to the numbers already held by this entry,
* thereby increasing the number of components by one.
*
* @param int|array the number to be added.
*/
function addNumber($n) {
$this->validateNumber($n);
$this->value[] = $n;
$this->components++;
}
/**
* Convert a number into bytes.
*
* The concrete subclasses will have to implement this method so
* that the numbers represented can be turned into bytes.
*
* The method will be called once for each number held by the entry.
*
* @param int the number that should be converted.
*
* @param PelByteOrder one of {@link PelConvert::LITTLE_ENDIAN} and
* {@link PelConvert::BIG_ENDIAN}, specifying the target byte order.
*
* @return string bytes representing the number given.
*/
abstract function numberToBytes($number, $order);
/**
* Turn this entry into bytes.
*
* @param PelByteOrder the desired byte order, which must be either
* {@link PelConvert::LITTLE_ENDIAN} or {@link
* PelConvert::BIG_ENDIAN}.
*
* @return string bytes representing this entry.
*/
function getBytes($o) {
$bytes = '';
for ($i = 0; $i < $this->components; $i++) {
if ($this->dimension == 1) {
$bytes .= $this->numberToBytes($this->value[$i], $o);
} else {
for ($j = 0; $j < $this->dimension; $j++) {
$bytes .= $this->numberToBytes($this->value[$i][$j], $o);
}
}
}
return $bytes;
}
/**
* Format a number.
*
* This method is called by {@link getText} to format numbers.
* Subclasses should override this method if they need more
* sophisticated behavior than the default, which is to just return
* the number as is.
*
* @param int the number which will be formatted.
*
* @param boolean it could be that there is both a verbose and a
* brief formatting available, and this argument controls that.
*
* @return string the number formatted as a string suitable for
* display.
*/
function formatNumber($number, $brief = false) {
return $number;
}
/**
* Get the numeric value of this entry as text.
*
* @param boolean use brief output? The numbers will be separated
* by a single space if brief output is requested, otherwise a space
* and a comma will be used.
*
* @return string the numbers(s) held by this entry.
*/
function getText($brief = false) {
if ($this->components == 0)
return '';
$str = $this->formatNumber($this->value[0]);
for ($i = 1; $i < $this->components; $i++) {
$str .= ($brief ? ' ' : ', ');
$str .= $this->formatNumber($this->value[$i]);
}
return $str;
}
}
?>

View File

@ -1,290 +0,0 @@
<?php
/* PEL: PHP Exif Library. A library with support for reading and
* writing all Exif headers in JPEG and TIFF images using PHP.
*
* Copyright (C) 2004, 2005, 2006 Martin Geisler.
*
* 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 in the file COPYING; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/* $Id: PelEntryRational.php 419 2006-02-20 16:22:36Z mgeisler $ */
/**
* Classes used to manipulate rational numbers.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @version $Revision: 419 $
* @date $Date: 2006-02-20 17:22:36 +0100 (Mon, 20 Feb 2006) $
* @license http://www.gnu.org/licenses/gpl.html GNU General Public
* License (GPL)
* @package PEL
*/
/**#@+ Required class definitions. */
require_once('PelEntryLong.php');
/**#@-*/
/**
* Class for holding unsigned rational numbers.
*
* This class can hold rational numbers, consisting of a numerator and
* denominator both of which are of type unsigned long. Each rational
* is represented by an array with just two entries: the numerator and
* the denominator, in that order.
*
* The class can hold either just a single rational or an array of
* rationals. The class will be used to manipulate any of the Exif
* tags which can have format {@link PelFormat::RATIONAL} like in this
* example:
*
* <code>
* $resolution = $ifd->getEntry(PelTag::X_RESOLUTION);
* $resolution->setValue(array(1, 300));
* </code>
*
* Here the x-resolution is adjusted to 1/300, which will be 300 DPI,
* unless the {@link PelTag::RESOLUTION_UNIT resolution unit} is set
* to something different than 2 which means inches.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @package PEL
*/
class PelEntryRational extends PelEntryLong {
/**
* Make a new entry that can hold an unsigned rational.
*
* @param PelTag the tag which this entry represents. This should
* be one of the constants defined in {@link PelTag}, e.g., {@link
* PelTag::X_RESOLUTION}, or any other tag which can have format
* {@link PelFormat::RATIONAL}.
*
* @param array $value... the rational(s) that this entry will
* represent. The arguments passed must obey the same rules as the
* argument to {@link setValue}, namely that each argument should be
* an array with two entries, both of which must be within range of
* an unsigned long (32 bit), that is between 0 and 4294967295
* (inclusive). If not, then a {@link PelOverflowException} will be
* thrown.
*/
function __construct($tag /* $value... */) {
$this->tag = $tag;
$this->format = PelFormat::RATIONAL;
$this->dimension = 2;
$this->min = 0;
$this->max = 4294967295;
$value = func_get_args();
array_shift($value);
$this->setValueArray($value);
}
/**
* Format a rational number.
*
* The rational will be returned as a string with a slash '/'
* between the numerator and denominator.
*
* @param array the rational which will be formatted.
*
* @param boolean not used.
*
* @return string the rational formatted as a string suitable for
* display.
*/
function formatNumber($number, $brief = false) {
return $number[0] . '/' . $number[1];
}
/**
* Get the value of an entry as text.
*
* The value will be returned in a format suitable for presentation,
* e.g., rationals will be returned as 'x/y', ASCII strings will be
* returned as themselves etc.
*
* @param boolean some values can be returned in a long or more
* brief form, and this parameter controls that.
*
* @return string the value as text.
*/
function getText($brief = false) {
if (isset($this->value[0]))
$v = $this->value[0];
switch ($this->tag) {
case PelTag::FNUMBER:
//CC (e->components, 1, v);
return Pel::fmt('f/%.01f', $v[0]/$v[1]);
case PelTag::APERTURE_VALUE:
//CC (e->components, 1, v);
//if (!v_rat.denominator) return (NULL);
return Pel::fmt('f/%.01f', pow(2, $v[0]/$v[1]/2));
case PelTag::FOCAL_LENGTH:
//CC (e->components, 1, v);
//if (!v_rat.denominator) return (NULL);
return Pel::fmt('%.1f mm', $v[0]/$v[1]);
case PelTag::SUBJECT_DISTANCE:
//CC (e->components, 1, v);
//if (!v_rat.denominator) return (NULL);
return Pel::fmt('%.1f m', $v[0]/$v[1]);
case PelTag::EXPOSURE_TIME:
//CC (e->components, 1, v);
//if (!v_rat.denominator) return (NULL);
if ($v[0]/$v[1] < 1)
return Pel::fmt('1/%d sec.', $v[1]/$v[0]);
else
return Pel::fmt('%d sec.', $v[0]/$v[1]);
case PelTag::GPS_LATITUDE:
case PelTag::GPS_LONGITUDE:
$degrees = $this->value[0][0]/$this->value[0][1];
$minutes = $this->value[1][0]/$this->value[1][1];
$seconds = $this->value[2][0]/$this->value[2][1];
return sprintf('%s° %s\' %s" (%.2f°)',
$degrees, $minutes, $seconds,
$degrees + $minutes/60 + $seconds/3600);
default:
return parent::getText($brief);
}
}
}
/**
* Class for holding signed rational numbers.
*
* This class can hold rational numbers, consisting of a numerator and
* denominator both of which are of type unsigned long. Each rational
* is represented by an array with just two entries: the numerator and
* the denominator, in that order.
*
* The class can hold either just a single rational or an array of
* rationals. The class will be used to manipulate any of the Exif
* tags which can have format {@link PelFormat::SRATIONAL}.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @package PEL
*/
class PelEntrySRational extends PelEntrySLong {
/**
* Make a new entry that can hold a signed rational.
*
* @param PelTag the tag which this entry represents. This should
* be one of the constants defined in {@link PelTag}, e.g., {@link
* PelTag::SHUTTER_SPEED_VALUE}, or any other tag which can have
* format {@link PelFormat::SRATIONAL}.
*
* @param array $value... the rational(s) that this entry will
* represent. The arguments passed must obey the same rules as the
* argument to {@link setValue}, namely that each argument should be
* an array with two entries, both of which must be within range of
* a signed long (32 bit), that is between -2147483648 and
* 2147483647 (inclusive). If not, then a {@link
* PelOverflowException} will be thrown.
*/
function __construct($tag /* $value... */) {
$this->tag = $tag;
$this->format = PelFormat::SRATIONAL;
$this->dimension = 2;
$this->min = -2147483648;
$this->max = 2147483647;
$value = func_get_args();
array_shift($value);
$this->setValueArray($value);
}
/**
* Format a rational number.
*
* The rational will be returned as a string with a slash '/'
* between the numerator and denominator. Care is taken to display
* '-1/2' instead of the ugly but mathematically equivalent '1/-2'.
*
* @param array the rational which will be formatted.
*
* @param boolean not used.
*
* @return string the rational formatted as a string suitable for
* display.
*/
function formatNumber($number, $brief = false) {
if ($number[1] < 0)
/* Turn output like 1/-2 into -1/2. */
return (-$number[0]) . '/' . (-$number[1]);
else
return $number[0] . '/' . $number[1];
}
/**
* Get the value of an entry as text.
*
* The value will be returned in a format suitable for presentation,
* e.g., rationals will be returned as 'x/y', ASCII strings will be
* returned as themselves etc.
*
* @param boolean some values can be returned in a long or more
* brief form, and this parameter controls that.
*
* @return string the value as text.
*/
function getText($brief = false) {
if (isset($this->value[0]))
$v = $this->value[0];
switch ($this->tag) {
case PelTag::SHUTTER_SPEED_VALUE:
//CC (e->components, 1, v);
//if (!v_srat.denominator) return (NULL);
return Pel::fmt('%.0f/%.0f sec. (APEX: %d)',
$v[0], $v[1], pow(sqrt(2), $v[0]/$v[1]));
case PelTag::BRIGHTNESS_VALUE:
//CC (e->components, 1, v);
//
// TODO: figure out the APEX thing, or remove this so that it is
// handled by the default clause at the bottom.
return sprintf('%d/%d', $v[0], $v[1]);
//FIXME: How do I calculate the APEX value?
case PelTag::EXPOSURE_BIAS_VALUE:
//CC (e->components, 1, v);
//if (!v_srat.denominator) return (NULL);
return sprintf('%s%.01f', $v[0]*$v[1] > 0 ? '+' : '', $v[0]/$v[1]);
default:
return parent::getText($brief);
}
}
}
?>

View File

@ -1,599 +0,0 @@
<?php
/* PEL: PHP Exif Library. A library with support for reading and
* writing all Exif headers in JPEG and TIFF images using PHP.
*
* Copyright (C) 2004, 2005, 2006 Martin Geisler.
*
* 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 in the file COPYING; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/* $Id: PelEntryShort.php 419 2006-02-20 16:22:36Z mgeisler $ */
/**
* Classes used to hold shorts, both signed and unsigned.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @version $Revision: 419 $
* @date $Date: 2006-02-20 17:22:36 +0100 (Mon, 20 Feb 2006) $
* @license http://www.gnu.org/licenses/gpl.html GNU General Public
* License (GPL)
* @package PEL
*/
/**#@+ Required class definitions. */
require_once('PelEntryNumber.php');
require_once('PelConvert.php');
require_once('Pel.php');
/**#@-*/
/**
* Class for holding signed shorts.
*
* This class can hold shorts, either just a single short or an array
* of shorts. The class will be used to manipulate any of the Exif
* tags which has format {@link PelFormat::SHORT} like in this
* example:
*
* <code>
* $w = $ifd->getEntry(PelTag::EXIF_IMAGE_WIDTH);
* $w->setValue($w->getValue() / 2);
* $h = $ifd->getEntry(PelTag::EXIF_IMAGE_HEIGHT);
* $h->setValue($h->getValue() / 2);
* </code>
*
* Here the width and height is updated to 50% of their original
* values.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @package PEL
*/
class PelEntryShort extends PelEntryNumber {
/**
* Make a new entry that can hold an unsigned short.
*
* The method accept several integer arguments. The {@link
* getValue} method will always return an array except for when a
* single integer argument is given here.
*
* This means that one can conveniently use objects like this:
* <code>
* $a = new PelEntryShort(PelTag::EXIF_IMAGE_HEIGHT, 42);
* $b = $a->getValue() + 314;
* </code>
* where the call to {@link getValue} will return an integer
* instead of an array with one integer element, which would then
* have to be extracted.
*
* @param PelTag the tag which this entry represents. This should be
* one of the constants defined in {@link PelTag}, e.g., {@link
* PelTag::IMAGE_WIDTH}, {@link PelTag::ISO_SPEED_RATINGS},
* or any other tag with format {@link PelFormat::SHORT}.
*
* @param int $value... the short(s) that this entry will
* represent. The argument passed must obey the same rules as the
* argument to {@link setValue}, namely that it should be within
* range of an unsigned short, that is between 0 and 65535
* (inclusive). If not, then a {@link PelOverFlowException} will be
* thrown.
*/
function __construct($tag /* $value... */) {
$this->tag = $tag;
$this->min = 0;
$this->max = 65535;
$this->format = PelFormat::SHORT;
$value = func_get_args();
array_shift($value);
$this->setValueArray($value);
}
/**
* Convert a number into bytes.
*
* @param int the number that should be converted.
*
* @param PelByteOrder one of {@link PelConvert::LITTLE_ENDIAN} and
* {@link PelConvert::BIG_ENDIAN}, specifying the target byte order.
*
* @return string bytes representing the number given.
*/
function numberToBytes($number, $order) {
return PelConvert::shortToBytes($number, $order);
}
/**
* Get the value of an entry as text.
*
* The value will be returned in a format suitable for presentation,
* e.g., instead of returning '2' for a {@link
* PelTag::METERING_MODE} tag, 'Center-Weighted Average' is
* returned.
*
* @param boolean some values can be returned in a long or more
* brief form, and this parameter controls that.
*
* @return string the value as text.
*/
function getText($brief = false) {
switch ($this->tag) {
case PelTag::METERING_MODE:
//CC (e->components, 1, v);
switch ($this->value[0]) {
case 0:
return Pel::tra('Unknown');
case 1:
return Pel::tra('Average');
case 2:
return Pel::tra('Center-Weighted Average');
case 3:
return Pel::tra('Spot');
case 4:
return Pel::tra('Multi Spot');
case 5:
return Pel::tra('Pattern');
case 6:
return Pel::tra('Partial');
case 255:
return Pel::tra('Other');
default:
return $this->value[0];
}
case PelTag::COMPRESSION:
//CC (e->components, 1, v);
switch ($this->value[0]) {
case 1:
return Pel::tra('Uncompressed');
case 6:
return Pel::tra('JPEG compression');
default:
return $this->value[0];
}
case PelTag::PLANAR_CONFIGURATION:
//CC (e->components, 1, v);
switch ($this->value[0]) {
case 1:
return Pel::tra('chunky format');
case 2:
return Pel::tra('planar format');
default:
return $this->value[0];
}
case PelTag::SENSING_METHOD:
//CC (e->components, 1, v);
switch ($this->value[0]) {
case 1:
return Pel::tra('Not defined');
case 2:
return Pel::tra('One-chip color area sensor');
case 3:
return Pel::tra('Two-chip color area sensor');
case 4:
return Pel::tra('Three-chip color area sensor');
case 5:
return Pel::tra('Color sequential area sensor');
case 7:
return Pel::tra('Trilinear sensor');
case 8:
return Pel::tra('Color sequential linear sensor');
default:
return $this->value[0];
}
case PelTag::LIGHT_SOURCE:
//CC (e->components, 1, v);
switch ($this->value[0]) {
case 0:
return Pel::tra('Unknown');
case 1:
return Pel::tra('Daylight');
case 2:
return Pel::tra('Fluorescent');
case 3:
return Pel::tra('Tungsten (incandescent light)');
case 4:
return Pel::tra('Flash');
case 9:
return Pel::tra('Fine weather');
case 10:
return Pel::tra('Cloudy weather');
case 11:
return Pel::tra('Shade');
case 12:
return Pel::tra('Daylight fluorescent');
case 13:
return Pel::tra('Day white fluorescent');
case 14:
return Pel::tra('Cool white fluorescent');
case 15:
return Pel::tra('White fluorescent');
case 17:
return Pel::tra('Standard light A');
case 18:
return Pel::tra('Standard light B');
case 19:
return Pel::tra('Standard light C');
case 20:
return Pel::tra('D55');
case 21:
return Pel::tra('D65');
case 22:
return Pel::tra('D75');
case 24:
return Pel::tra('ISO studio tungsten');
case 255:
return Pel::tra('Other');
default:
return $this->value[0];
}
case PelTag::FOCAL_PLANE_RESOLUTION_UNIT:
case PelTag::RESOLUTION_UNIT:
//CC (e->components, 1, v);
switch ($this->value[0]) {
case 2:
return Pel::tra('Inch');
case 3:
return Pel::tra('Centimeter');
default:
return $this->value[0];
}
case PelTag::EXPOSURE_PROGRAM:
//CC (e->components, 1, v);
switch ($this->value[0]) {
case 0:
return Pel::tra('Not defined');
case 1:
return Pel::tra('Manual');
case 2:
return Pel::tra('Normal program');
case 3:
return Pel::tra('Aperture priority');
case 4:
return Pel::tra('Shutter priority');
case 5:
return Pel::tra('Creative program (biased toward depth of field)');
case 6:
return Pel::tra('Action program (biased toward fast shutter speed)');
case 7:
return Pel::tra('Portrait mode (for closeup photos with the background out of focus');
case 8:
return Pel::tra('Landscape mode (for landscape photos with the background in focus');
default:
return $this->value[0];
}
case PelTag::ORIENTATION:
//CC (e->components, 1, v);
switch ($this->value[0]) {
case 1:
return Pel::tra('top - left');
case 2:
return Pel::tra('top - right');
case 3:
return Pel::tra('bottom - right');
case 4:
return Pel::tra('bottom - left');
case 5:
return Pel::tra('left - top');
case 6:
return Pel::tra('right - top');
case 7:
return Pel::tra('right - bottom');
case 8:
return Pel::tra('left - bottom');
default:
return $this->value[0];
}
case PelTag::YCBCR_POSITIONING:
//CC (e->components, 1, v);
switch ($this->value[0]) {
case 1:
return Pel::tra('centered');
case 2:
return Pel::tra('co-sited');
default:
return $this->value[0];
}
case PelTag::YCBCR_SUB_SAMPLING:
//CC (e->components, 2, v);
if ($this->value[0] == 2 && $this->value[1] == 1)
return 'YCbCr4:2:2';
if ($this->value[0] == 2 && $this->value[1] == 2)
return 'YCbCr4:2:0';
return $this->value[0] . ', ' . $this->value[1];
case PelTag::PHOTOMETRIC_INTERPRETATION:
//CC (e->components, 1, v);
switch ($this->value[0]) {
case 2:
return 'RGB';
case 6:
return 'YCbCr';
default:
return $this->value[0];
}
case PelTag::COLOR_SPACE:
//CC (e->components, 1, v);
switch ($this->value[0]) {
case 1:
return 'sRGB';
case 2:
return 'Adobe RGB';
case 0xffff:
return Pel::tra('Uncalibrated');
default:
return $this->value[0];
}
case PelTag::FLASH:
//CC (e->components, 1, v);
switch ($this->value[0]) {
case 0x0000:
return Pel::tra('Flash did not fire.');
case 0x0001:
return Pel::tra('Flash fired.');
case 0x0005:
return Pel::tra('Strobe return light not detected.');
case 0x0007:
return Pel::tra('Strobe return light detected.');
case 0x0009:
return Pel::tra('Flash fired, compulsory flash mode.');
case 0x000d:
return Pel::tra('Flash fired, compulsory flash mode, return light not detected.');
case 0x000f:
return Pel::tra('Flash fired, compulsory flash mode, return light detected.');
case 0x0010:
return Pel::tra('Flash did not fire, compulsory flash mode.');
case 0x0018:
return Pel::tra('Flash did not fire, auto mode.');
case 0x0019:
return Pel::tra('Flash fired, auto mode.');
case 0x001d:
return Pel::tra('Flash fired, auto mode, return light not detected.');
case 0x001f:
return Pel::tra('Flash fired, auto mode, return light detected.');
case 0x0020:
return Pel::tra('No flash function.');
case 0x0041:
return Pel::tra('Flash fired, red-eye reduction mode.');
case 0x0045:
return Pel::tra('Flash fired, red-eye reduction mode, return light not detected.');
case 0x0047:
return Pel::tra('Flash fired, red-eye reduction mode, return light detected.');
case 0x0049:
return Pel::tra('Flash fired, compulsory flash mode, red-eye reduction mode.');
case 0x004d:
return Pel::tra('Flash fired, compulsory flash mode, red-eye reduction mode, return light not detected.');
case 0x004f:
return Pel::tra('Flash fired, compulsory flash mode, red-eye reduction mode, return light detected.');
case 0x0058:
return Pel::tra('Flash did not fire, auto mode, red-eye reduction mode.');
case 0x0059:
return Pel::tra('Flash fired, auto mode, red-eye reduction mode.');
case 0x005d:
return Pel::tra('Flash fired, auto mode, return light not detected, red-eye reduction mode.');
case 0x005f:
return Pel::tra('Flash fired, auto mode, return light detected, red-eye reduction mode.');
default:
return $this->value[0];
}
case PelTag::CUSTOM_RENDERED:
//CC (e->components, 1, v);
switch ($this->value[0]) {
case 0:
return Pel::tra('Normal process');
case 1:
return Pel::tra('Custom process');
default:
return $this->value[0];
}
case PelTag::EXPOSURE_MODE:
//CC (e->components, 1, v);
switch ($this->value[0]) {
case 0:
return Pel::tra('Auto exposure');
case 1:
return Pel::tra('Manual exposure');
case 2:
return Pel::tra('Auto bracket');
default:
return $this->value[0];
}
case PelTag::WHITE_BALANCE:
//CC (e->components, 1, v);
switch ($this->value[0]) {
case 0:
return Pel::tra('Auto white balance');
case 1:
return Pel::tra('Manual white balance');
default:
return $this->value[0];
}
case PelTag::SCENE_CAPTURE_TYPE:
//CC (e->components, 1, v);
switch ($this->value[0]) {
case 0:
return Pel::tra('Standard');
case 1:
return Pel::tra('Landscape');
case 2:
return Pel::tra('Portrait');
case 3:
return Pel::tra('Night scene');
default:
return $this->value[0];
}
case PelTag::GAIN_CONTROL:
//CC (e->components, 1, v);
switch ($this->value[0]) {
case 0:
return Pel::tra('Normal');
case 1:
return Pel::tra('Low gain up');
case 2:
return Pel::tra('High gain up');
case 3:
return Pel::tra('Low gain down');
case 4:
return Pel::tra('High gain down');
default:
return $this->value[0];
}
case PelTag::SATURATION:
//CC (e->components, 1, v);
switch ($this->value[0]) {
case 0:
return Pel::tra('Normal');
case 1:
return Pel::tra('Low saturation');
case 2:
return Pel::tra('High saturation');
default:
return $this->value[0];
}
case PelTag::CONTRAST:
case PelTag::SHARPNESS:
//CC (e->components, 1, v);
switch ($this->value[0]) {
case 0:
return Pel::tra('Normal');
case 1:
return Pel::tra('Soft');
case 2:
return Pel::tra('Hard');
default:
return $this->value[0];
}
case PelTag::SUBJECT_DISTANCE_RANGE:
//CC (e->components, 1, v);
switch ($this->value[0]) {
case 0:
return Pel::tra('Unknown');
case 1:
return Pel::tra('Macro');
case 2:
return Pel::tra('Close view');
case 3:
return Pel::tra('Distant view');
default:
return $this->value[0];
}
case PelTag::SUBJECT_AREA:
switch ($this->components) {
case 2:
return Pel::fmt('(x,y) = (%d,%d)', $this->value[0], $this->value[1]);
case 3:
return Pel::fmt('Within distance %d of (x,y) = (%d,%d)',
$this->value[0], $this->value[1], $this->value[2]);
case 4:
return Pel::fmt('Within rectangle (width %d, height %d) around (x,y) = (%d,%d)',
$this->value[0], $this->value[1],
$this->value[2], $this->value[3]);
default:
return Pel::fmt('Unexpected number of components (%d, expected 2, 3, or 4).', $this->components);
}
default:
return parent::getText($brief);
}
}
}
/**
* Class for holding signed shorts.
*
* This class can hold shorts, either just a single short or an array
* of shorts. The class will be used to manipulate any of the Exif
* tags which has format {@link PelFormat::SSHORT}.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @package PEL
*/
class PelEntrySShort extends PelEntryNumber {
/**
* Make a new entry that can hold a signed short.
*
* The method accept several integer arguments. The {@link
* getValue} method will always return an array except for when a
* single integer argument is given here.
*
* @param PelTag the tag which this entry represents. This
* should be one of the constants defined in {@link PelTag}
* which has format {@link PelFormat::SSHORT}.
*
* @param int $value... the signed short(s) that this entry will
* represent. The argument passed must obey the same rules as the
* argument to {@link setValue}, namely that it should be within
* range of a signed short, that is between -32768 to 32767
* (inclusive). If not, then a {@link PelOverFlowException} will be
* thrown.
*/
function __construct($tag /* $value... */) {
$this->tag = $tag;
$this->min = -32768;
$this->max = 32767;
$this->format = PelFormat::SSHORT;
$value = func_get_args();
array_shift($value);
$this->setValueArray($value);
}
/**
* Convert a number into bytes.
*
* @param int the number that should be converted.
*
* @param PelByteOrder one of {@link PelConvert::LITTLE_ENDIAN} and
* {@link PelConvert::BIG_ENDIAN}, specifying the target byte order.
*
* @return string bytes representing the number given.
*/
function numberToBytes($number, $order) {
return PelConvert::sShortToBytes($number, $order);
}
}
?>

View File

@ -1,416 +0,0 @@
<?php
/* PEL: PHP Exif Library. A library with support for reading and
* writing all Exif headers in JPEG and TIFF images using PHP.
*
* Copyright (C) 2004, 2005 Martin Geisler.
*
* 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 in the file COPYING; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/* $Id: PelEntryUndefined.php 380 2005-10-03 12:01:28Z mgeisler $ */
/**
* Classes used to hold data for Exif tags of format undefined.
*
* This file contains the base class {@link PelEntryUndefined} and
* the subclasses {@link PelEntryUserComment} which should be used
* to manage the {@link PelTag::USER_COMMENT} tag, and {@link
* PelEntryVersion} which is used to manage entries with version
* information.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @version $Revision: 380 $
* @date $Date: 2005-10-03 14:01:28 +0200 (Mon, 03 Oct 2005) $
* @license http://www.gnu.org/licenses/gpl.html GNU General Public
* License (GPL)
* @package PEL
*/
/**#@+ Required class definitions. */
require_once('PelEntry.php');
/**#@-*/
/**
* Class for holding data of any kind.
*
* This class can hold bytes of undefined format.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @package PEL
*/
class PelEntryUndefined extends PelEntry {
/**
* Make a new PelEntry that can hold undefined data.
*
* @param PelTag the tag which this entry represents. This
* should be one of the constants defined in {@link PelTag},
* e.g., {@link PelTag::SCENE_TYPE}, {@link
* PelTag::MAKER_NOTE} or any other tag with format {@link
* PelFormat::UNDEFINED}.
*
* @param string the data that this entry will be holding. Since
* the format is undefined, no checking will be done on the data.
*/
function __construct($tag, $data = '') {
$this->tag = $tag;
$this->format = PelFormat::UNDEFINED;
$this->setValue($data);
}
/**
* Set the data of this undefined entry.
*
* @param string the data that this entry will be holding. Since
* the format is undefined, no checking will be done on the data.
*/
function setValue($data) {
$this->components = strlen($data);
$this->bytes = $data;
}
/**
* Get the data of this undefined entry.
*
* @return string the data that this entry is holding.
*/
function getValue() {
return $this->bytes;
}
/**
* Get the value of this entry as text.
*
* The value will be returned in a format suitable for presentation.
*
* @param boolean some values can be returned in a long or more
* brief form, and this parameter controls that.
*
* @return string the value as text.
*/
function getText($brief = false) {
switch ($this->tag) {
case PelTag::FILE_SOURCE:
//CC (e->components, 1, v);
switch (ord($this->bytes{0})) {
case 0x03:
return 'DSC';
default:
return sprintf('0x%02X', ord($this->bytes{0}));
}
case PelTag::SCENE_TYPE:
//CC (e->components, 1, v);
switch (ord($this->bytes{0})) {
case 0x01:
return 'Directly photographed';
default:
return sprintf('0x%02X', ord($this->bytes{0}));
}
case PelTag::COMPONENTS_CONFIGURATION:
//CC (e->components, 4, v);
$v = '';
for ($i = 0; $i < 4; $i++) {
switch (ord($this->bytes{$i})) {
case 0:
$v .= '-';
break;
case 1:
$v .= 'Y';
break;
case 2:
$v .= 'Cb';
break;
case 3:
$v .= 'Cr';
break;
case 4:
$v .= 'R';
break;
case 5:
$v .= 'G';
break;
case 6:
$v .= 'B';
break;
default:
$v .= 'reserved';
break;
}
if ($i < 3) $v .= ' ';
}
return $v;
case PelTag::MAKER_NOTE:
// TODO: handle maker notes.
return $this->components . ' bytes unknown MakerNote data';
default:
return '(undefined)';
}
}
}
/**
* Class for a user comment.
*
* This class is used to hold user comments, which can come in several
* different character encodings. The Exif standard specifies a
* certain format of the {@link PelTag::USER_COMMENT user comment
* tag}, and this class will make sure that the format is kept.
*
* The most basic use of this class simply stores an ASCII encoded
* string for later retrieval using {@link getValue}:
*
* <code>
* $entry = new PelEntryUserComment('An ASCII string');
* echo $entry->getValue();
* </code>
*
* The string can be encoded with a different encoding, and if so, the
* encoding must be given using the second argument. The Exif
* standard specifies three known encodings: 'ASCII', 'JIS', and
* 'Unicode'. If the user comment is encoded using a character
* encoding different from the tree known encodings, then the empty
* string should be passed as encoding, thereby specifying that the
* encoding is undefined.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @package PEL
*/
class PelEntryUserComment extends PelEntryUndefined {
/**
* The user comment.
*
* @var string
*/
private $comment;
/**
* The encoding.
*
* This should be one of 'ASCII', 'JIS', 'Unicode', or ''.
*
* @var string
*/
private $encoding;
/**
* Make a new entry for holding a user comment.
*
* @param string the new user comment.
*
* @param string the encoding of the comment. This should be either
* 'ASCII', 'JIS', 'Unicode', or the empty string specifying an
* undefined encoding.
*/
function __construct($comment = '', $encoding = 'ASCII') {
parent::__construct(PelTag::USER_COMMENT);
$this->setValue($comment, $encoding);
}
/**
* Set the user comment.
*
* @param string the new user comment.
*
* @param string the encoding of the comment. This should be either
* 'ASCII', 'JIS', 'Unicode', or the empty string specifying an
* unknown encoding.
*/
function setValue($comment = '', $encoding = 'ASCII') {
$this->comment = $comment;
$this->encoding = $encoding;
parent::setValue(str_pad($encoding, 8, chr(0)) . $comment);
}
/**
* Returns the user comment.
*
* The comment is returned with the same character encoding as when
* it was set using {@link setValue} or {@link __construct the
* constructor}.
*
* @return string the user comment.
*/
function getValue() {
return $this->comment;
}
/**
* Returns the encoding.
*
* @return string the encoding of the user comment.
*/
function getEncoding() {
return $this->encoding;
}
/**
* Returns the user comment.
*
* @return string the user comment.
*/
function getText($brief = false) {
return $this->comment;
}
}
/**
* Class to hold version information.
*
* There are three Exif entries that hold version information: the
* {@link PelTag::EXIF_VERSION}, {@link
* PelTag::FLASH_PIX_VERSION}, and {@link
* PelTag::INTEROPERABILITY_VERSION} tags. This class manages
* those tags.
*
* The class is used in a very straight-forward way:
* <code>
* $entry = new PelEntryVersion(PelTag::EXIF_VERSION, 2.2);
* </code>
* This creates an entry for an file complying to the Exif 2.2
* standard. It is easy to test for standards level of an unknown
* entry:
* <code>
* if ($entry->getTag() == PelTag::EXIF_VERSION &&
* $entry->getValue() > 2.0) {
* echo 'Recent Exif version.';
* }
* </code>
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @package PEL
*/
class PelEntryVersion extends PelEntryUndefined {
/**
* The version held by this entry.
*
* @var float
*/
private $version;
/**
* Make a new entry for holding a version.
*
* @param PelTag the tag. This should be one of {@link
* PelTag::EXIF_VERSION}, {@link PelTag::FLASH_PIX_VERSION},
* or {@link PelTag::INTEROPERABILITY_VERSION}.
*
* @param float the version. The size of the entries leave room for
* exactly four digits: two digits on either side of the decimal
* point.
*/
function __construct($tag, $version = 0.0) {
parent::__construct($tag);
$this->setValue($version);
}
/**
* Set the version held by this entry.
*
* @param float the version. The size of the entries leave room for
* exactly four digits: two digits on either side of the decimal
* point.
*/
function setValue($version = 0.0) {
$this->version = $version;
$major = floor($version);
$minor = ($version - $major)*100;
parent::setValue(sprintf('%02.0f%02.0f', $major, $minor));
}
/**
* Return the version held by this entry.
*
* @return float the version. This will be the same as the value
* given to {@link setValue} or {@link __construct the
* constructor}.
*/
function getValue() {
return $this->version;
}
/**
* Return a text string with the version.
*
* @param boolean controls if the output should be brief. Brief
* output omits the word 'Version' so the result is just 'Exif x.y'
* instead of 'Exif Version x.y' if the entry holds information
* about the Exif version --- the output for FlashPix is similar.
*
* @return string the version number with the type of the tag,
* either 'Exif' or 'FlashPix'.
*/
function getText($brief = false) {
$v = $this->version;
/* Versions numbers like 2.0 would be output as just 2 if we don't
* add the '.0' ourselves. */
if (floor($this->version) == $this->version)
$v .= '.0';
switch ($this->tag) {
case PelTag::EXIF_VERSION:
if ($brief)
return Pel::fmt('Exif %s', $v);
else
return Pel::fmt('Exif Version %s', $v);
case PelTag::FLASH_PIX_VERSION:
if ($brief)
return Pel::fmt('FlashPix %s', $v);
else
return Pel::fmt('FlashPix Version %s', $v);
case PelTag::INTEROPERABILITY_VERSION:
if ($brief)
return Pel::fmt('Interoperability %s', $v);
else
return Pel::fmt('Interoperability Version %s', $v);
}
if ($brief)
return $v;
else
return Pel::fmt('Version %s', $v);
}
}
?>

View File

@ -1,87 +0,0 @@
<?php
/* PEL: PHP Exif Library. A library with support for reading and
* writing all Exif headers in JPEG and TIFF images using PHP.
*
* Copyright (C) 2004, 2005 Martin Geisler.
*
* 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 in the file COPYING; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/* $Id: PelException.php 396 2005-10-23 22:36:10Z mgeisler $ */
/**
* Standard PEL exception.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @version $Revision: 396 $
* @date $Date: 2005-10-24 00:36:10 +0200 (Mon, 24 Oct 2005) $
* @license http://www.gnu.org/licenses/gpl.html GNU General Public
* License (GPL)
* @package PEL
*/
/**
* A printf() capable exception.
*
* This class is a simple extension of the standard Exception class in
* PHP, and all the methods defined there retain their original
* meaning.
*
* @package PEL
* @subpackage Exception
*/
class PelException extends Exception {
/**
* Construct a new PEL exception.
*
* @param string $fmt an optional format string can be given. It
* will be used as a format string for vprintf(). The remaining
* arguments will be available for the format string as usual with
* vprintf().
*
* @param mixed $args,... any number of arguments to be used with
* the format string.
*/
function __construct(/* fmt, args... */) {
$args = func_get_args();
$fmt = array_shift($args);
parent::__construct(vsprintf($fmt, $args));
}
}
/**
* Exception throw if invalid data is found.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @package PEL
* @subpackage Exception
*/
class PelInvalidDataException extends PelException {}
/**
* Exception throw if an invalid argument is passed.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @package PEL
* @subpackage Exception
*/
class PelInvalidArgumentException extends PelException {}
?>

View File

@ -1,175 +0,0 @@
<?php
/* PEL: PHP Exif Library. A library with support for reading and
* writing all Exif headers in JPEG and TIFF images using PHP.
*
* Copyright (C) 2004, 2005 Martin Geisler.
*
* 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 in the file COPYING; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/* $Id: PelExif.php 380 2005-10-03 12:01:28Z mgeisler $ */
/**
* Classes for dealing with Exif data.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @version $Revision: 380 $
* @date $Date: 2005-10-03 14:01:28 +0200 (Mon, 03 Oct 2005) $
* @license http://www.gnu.org/licenses/gpl.html GNU General Public
* License (GPL)
* @package PEL
*/
/**#@+ Required class definitions. */
require_once('PelJpegContent.php');
require_once('PelException.php');
require_once('PelFormat.php');
require_once('PelEntry.php');
require_once('PelTiff.php');
require_once('PelIfd.php');
require_once('PelTag.php');
require_once('Pel.php');
/**#@-*/
/**
* Class representing Exif data.
*
* Exif data resides as {@link PelJpegContent data} and consists of a
* header followed by a number of {@link PelJpegIfd IFDs}.
*
* The interesting method in this class is {@link getTiff()} which
* will return the {@link PelTiff} object which really holds the data
* which one normally think of when talking about Exif data. This is
* because Exif data is stored as an extension of the TIFF file
* format.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @package PEL
*/
class PelExif extends PelJpegContent {
/**
* Exif header.
*
* The Exif data must start with these six bytes to be considered
* valid.
*/
const EXIF_HEADER = "Exif\0\0";
/**
* The PelTiff object contained within.
*
* @var PelTiff
*/
private $tiff = null;
/**
* Construct a new Exif object.
*
* The new object will be empty --- use the {@link load()} method to
* load Exif data from a {@link PelDataWindow} object, or use the
* {@link setTiff()} to change the {@link PelTiff} object, which is
* the true holder of the Exif {@link PelEntry entries}.
*/
function __construct() {
}
/**
* Load and parse Exif data.
*
* This will populate the object with Exif data, contained as a
* {@link PelTiff} object. This TIFF object can be accessed with
* the {@link getTiff()} method.
*/
function load(PelDataWindow $d) {
Pel::debug('Parsing %d bytes of Exif data...', $d->getSize());
/* There must be at least 6 bytes for the Exif header. */
if ($d->getSize() < 6)
throw new PelInvalidDataException('Expected at least 6 bytes of Exif ' .
'data, found just %d bytes.',
$d->getSize());
/* Verify the Exif header */
if ($d->strcmp(0, self::EXIF_HEADER)) {
$d->setWindowStart(strlen(self::EXIF_HEADER));
} else {
throw new PelInvalidDataException('Exif header not found.');
}
/* The rest of the data is TIFF data. */
$this->tiff = new PelTiff();
$this->tiff->load($d);
}
/**
* Change the TIFF information.
*
* Exif data is really stored as TIFF data, and this method can be
* used to change this data from one {@link PelTiff} object to
* another.
*
* @param PelTiff the new TIFF object.
*/
function setTiff(PelTiff $tiff) {
$this->tiff = $tiff;
}
/**
* Get the underlying TIFF object.
*
* The actual Exif data is stored in a {@link PelTiff} object, and
* this method provides access to it.
*
* @return PelTiff the TIFF object with the Exif data.
*/
function getTiff() {
return $this->tiff;
}
/**
* Produce bytes for the Exif data.
*
* @return string bytes representing this object.
*/
function getBytes() {
return self::EXIF_HEADER . $this->tiff->getBytes();
}
/**
* Return a string representation of this object.
*
* @return string a string describing this object. This is mostly
* useful for debugging.
*/
function __toString() {
return Pel::tra("Dumping Exif data...\n") .
$this->tiff->__toString();
}
}
?>

View File

@ -1,225 +0,0 @@
<?php
/* PEL: PHP Exif Library. A library with support for reading and
* writing all Exif headers in JPEG and TIFF images using PHP.
*
* Copyright (C) 2004, 2005 Martin Geisler.
*
* 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 in the file COPYING; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/* $Id: PelFormat.php 380 2005-10-03 12:01:28Z mgeisler $ */
/**
* Namespace for functions operating on Exif formats.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @version $Revision: 380 $
* @date $Date: 2005-10-03 14:01:28 +0200 (Mon, 03 Oct 2005) $
* @license http://www.gnu.org/licenses/gpl.html GNU General Public
* License (GPL)
* @package PEL
*/
/**
* Namespace for functions operating on Exif formats.
*
* This class defines the constants that are to be used whenever one
* has to refer to the format of an Exif tag. They will be
* collectively denoted by the pseudo-type PelFormat throughout the
* documentation.
*
* All the methods defined here are static, and they all operate on a
* single argument which should be one of the class constants.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @package PEL
*/
class PelFormat {
/**
* Unsigned byte.
*
* Each component will be an unsigned 8-bit integer with a value
* between 0 and 255.
*
* Modelled with the {@link PelEntryByte} class.
*/
const BYTE = 1;
/**
* ASCII string.
*
* Each component will be an ASCII character.
*
* Modelled with the {@link PelEntryAscii} class.
*/
const ASCII = 2;
/**
* Unsigned short.
*
* Each component will be an unsigned 16-bit integer with a value
* between 0 and 65535.
*
* Modelled with the {@link PelEntryShort} class.
*/
const SHORT = 3;
/**
* Unsigned long.
*
* Each component will be an unsigned 32-bit integer with a value
* between 0 and 4294967295.
*
* Modelled with the {@link PelEntryLong} class.
*/
const LONG = 4;
/**
* Unsigned rational number.
*
* Each component will consist of two unsigned 32-bit integers
* denoting the enumerator and denominator. Each integer will have
* a value between 0 and 4294967295.
*
* Modelled with the {@link PelEntryRational} class.
*/
const RATIONAL = 5;
/**
* Signed byte.
*
* Each component will be a signed 8-bit integer with a value
* between -128 and 127.
*
* Modelled with the {@link PelEntrySByte} class.
*/
const SBYTE = 6;
/**
* Undefined byte.
*
* Each component will be a byte with no associated interpretation.
*
* Modelled with the {@link PelEntryUndefined} class.
*/
const UNDEFINED = 7;
/**
* Signed short.
*
* Each component will be a signed 16-bit integer with a value
* between -32768 and 32767.
*
* Modelled with the {@link PelEntrySShort} class.
*/
const SSHORT = 8;
/**
* Signed long.
*
* Each component will be a signed 32-bit integer with a value
* between -2147483648 and 2147483647.
*
* Modelled with the {@link PelEntrySLong} class.
*/
const SLONG = 9;
/**
* Signed rational number.
*
* Each component will consist of two signed 32-bit integers
* denoting the enumerator and denominator. Each integer will have
* a value between -2147483648 and 2147483647.
*
* Modelled with the {@link PelEntrySRational} class.
*/
const SRATIONAL = 10;
/**
* Floating point number.
*
* Entries with this format are not currently implemented.
*/
const FLOAT = 11;
/**
* Double precision floating point number.
*
* Entries with this format are not currently implemented.
*/
const DOUBLE = 12;
/**
* Returns the name of a format.
*
* @param PelFormat the format.
*
* @return string the name of the format, e.g., 'Ascii' for the
* {@link ASCII} format etc.
*/
static function getName($type) {
switch ($type) {
case self::ASCII: return 'Ascii';
case self::BYTE: return 'Byte';
case self::SHORT: return 'Short';
case self::LONG: return 'Long';
case self::RATIONAL: return 'Rational';
case self::SBYTE: return 'SByte';
case self::SSHORT: return 'SShort';
case self::SLONG: return 'SLong';
case self::SRATIONAL: return 'SRational';
case self::FLOAT: return 'Float';
case self::DOUBLE: return 'Double';
case self::UNDEFINED: return 'Undefined';
default:
return Pel::fmt('Unknown format: 0x%X', $type);
}
}
/**
* Return the size of components in a given format.
*
* @param PelFormat the format.
*
* @return the size in bytes needed to store one component with the
* given format.
*/
static function getSize($type) {
switch ($type) {
case self::ASCII: return 1;
case self::BYTE: return 1;
case self::SHORT: return 2;
case self::LONG: return 4;
case self::RATIONAL: return 8;
case self::SBYTE: return 1;
case self::SSHORT: return 2;
case self::SLONG: return 4;
case self::SRATIONAL: return 8;
case self::FLOAT: return 4;
case self::DOUBLE: return 8;
case self::UNDEFINED: return 1;
default:
return Pel::fmt('Unknown format: 0x%X', $type);
}
}
}
?>

File diff suppressed because it is too large Load Diff

View File

@ -1,599 +0,0 @@
<?php
/* PEL: PHP Exif Library. A library with support for reading and
* writing all Exif headers in JPEG and TIFF images using PHP.
*
* Copyright (C) 2004, 2005, 2006 Martin Geisler.
*
* 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 in the file COPYING; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/* $Id: PelJpeg.php 473 2006-11-23 23:12:21Z mgeisler $ */
/**
* Classes representing JPEG data.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @version $Revision: 473 $
* @date $Date: 2006-11-24 00:12:21 +0100 (Fri, 24 Nov 2006) $
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License (GPL)
* @package PEL
*/
/**#@+ Required class definitions. */
require_once('PelJpegComment.php');
require_once('PelJpegContent.php');
require_once('PelDataWindow.php');
require_once('PelJpegMarker.php');
require_once('PelException.php');
require_once('PelExif.php');
require_once('Pel.php');
/**#@-*/
/**
* Exception thrown when an invalid marker is found.
*
* This exception is thrown when PEL expects to find a {@link
* PelJpegMarker} and instead finds a byte that isn't a known marker.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @package PEL
* @subpackage Exception
*/
class PelJpegInvalidMarkerException extends PelException {
/**
* Construct a new invalid marker exception.
*
* The exception will contain a message describing the error,
* including the byte found and the offset of the offending byte.
*
* @param int the byte found.
*
* @param int the offset in the data.
*/
function __construct($marker, $offset) {
parent::__construct('Invalid marker found at offset %d: 0x%2X',
$offset, $marker);
}
}
/**
* Class for handling JPEG data.
*
* The {@link PelJpeg} class defined here provides an abstraction for
* dealing with a JPEG file. The file will be contain a number of
* sections containing some {@link PelJpegContent content} identified
* by a {@link PelJpegMarker marker}.
*
* The {@link getExif()} method is used get hold of the {@link
* PelJpegMarker::APP1 APP1} section which stores Exif data. So if
* the name of the JPEG file is stored in $filename, then one would
* get hold of the Exif data by saying:
*
* <code>
* $jpeg = new PelJpeg($filename);
* $exif = $jpeg->getExif();
* $tiff = $exif->getTiff();
* $ifd0 = $tiff->getIfd();
* $exif = $ifd0->getSubIfd(PelIfd::EXIF);
* $ifd1 = $ifd0->getNextIfd();
* </code>
*
* The $idf0 and $ifd1 variables will then be two {@link PelTiff TIFF}
* {@link PelIfd Image File Directories}, in which the data is stored
* under the keys found in {@link PelTag}.
*
* Should one have some image data (in the form of a {@link
* PelDataWindow}) of an unknown type, then the {@link
* PelJpeg::isValid()} function is handy: it will quickly test if the
* data could be valid JPEG data. The {@link PelTiff::isValid()}
* function does the same for TIFF images.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @package PEL
*/
class PelJpeg {
/**
* The sections in the JPEG data.
*
* A JPEG file is built up as a sequence of sections, each section
* is identified with a {@link PelJpegMarker}. Some sections can
* occur more than once in the JPEG stream (the {@link
* PelJpegMarker::DQT DQT} and {@link PelJpegMarker::DHT DTH}
* markers for example) and so this is an array of ({@link
* PelJpegMarker}, {@link PelJpegContent}) pairs.
*
* The content can be either generic {@link PelJpegContent JPEG
* content} or {@link PelExif Exif data}.
*
* @var array
*/
private $sections = array();
/**
* The JPEG image data.
*
* @var PelDataWindow
*/
private $jpeg_data = null;
/**
* Construct a new JPEG object.
*
* The new object will be empty unless an argument is given from
* which it can initialize itself. This can either be the filename
* of a JPEG image, a {@link PelDataWindow} object or a PHP image
* resource handle.
*
* New Exif data (in the form of a {@link PelExif} object) can be
* inserted with the {@link setExif()} method:
*
* <code>
* $jpeg = new PelJpeg($data);
* // Create container for the Exif information:
* $exif = new PelExif();
* // Now Add a PelTiff object with a PelIfd object with one or more
* // PelEntry objects to $exif... Finally add $exif to $jpeg:
* $jpeg->setExif($exif);
* </code>
*/
function __construct($data = false) {
if ($data === false)
return;
if (is_string($data)) {
Pel::debug('Initializing PelJpeg object from %s', $data);
$this->loadFile($data);
} elseif ($data instanceof PelDataWindow) {
Pel::debug('Initializing PelJpeg object from PelDataWindow.');
$this->load($data);
} elseif (is_resource($data) && get_resource_type($data) == 'gd') {
Pel::debug('Initializing PelJpeg object from image resource.');
/* The ImageJpeg() function insists on printing the bytes
* instead of returning them in a more civil way as a string, so
* we have to buffer the output... */
ob_start();
ImageJpeg($data);
$bytes = ob_get_clean();
$this->load(new PelDataWindow($bytes));
} else {
throw new PelInvalidArgumentException('Bad type for $data: %s',
gettype($data));
}
}
/**
* Load data into a JPEG object.
*
* The data supplied will be parsed and turned into an object
* structure representing the image. This structure can then be
* manipulated and later turned back into an string of bytes.
*
* This methods can be called at any time after a JPEG object has
* been constructed, also after the {@link appendSection()} has been
* called to append custom sections. Loading several JPEG images
* into one object will accumulate the sections, but there will only
* be one {@link PelJpegMarker::SOS} section at any given time.
*
* @param PelDataWindow the data that will be turned into JPEG
* sections.
*/
function load(PelDataWindow $d) {
Pel::debug('Parsing %d bytes...', $d->getSize());
/* JPEG data is stored in big-endian format. */
$d->setByteOrder(PelConvert::BIG_ENDIAN);
/* Run through the data to read the sections in the image. After
* each section is read, the start of the data window will be
* moved forward, and after the last section we'll terminate with
* no data left in the window. */
while ($d->getSize() > 0) {
/* JPEG sections start with 0xFF. The first byte that is not
* 0xFF is a marker (hopefully).
*/
for ($i = 0; $i < 7; $i++)
if ($d->getByte($i) != 0xFF)
break;
$marker = $d->getByte($i);
if (!PelJpegMarker::isValid($marker))
throw new PelJpegInvalidMarkerException($marker, $i);
/* Move window so first byte becomes first byte in this
* section. */
$d->setWindowStart($i+1);
if ($marker == PelJpegMarker::SOI || $marker == PelJpegMarker::EOI) {
$content = new PelJpegContent(new PelDataWindow());
$this->appendSection($marker, $content);
} else {
/* Read the length of the section. The length includes the
* two bytes used to store the length. */
$len = $d->getShort(0) - 2;
Pel::debug('Found %s section of length %d',
PelJpegMarker::getName($marker), $len);
/* Skip past the length. */
$d->setWindowStart(2);
if ($marker == PelJpegMarker::APP1) {
try {
$content = new PelExif();
$content->load($d->getClone(0, $len));
} catch (PelInvalidDataException $e) {
/* We store the data as normal JPEG content if it could
* not be parsed as Exif data. */
$content = new PelJpegContent($d->getClone(0, $len));
}
$this->appendSection($marker, $content);
/* Skip past the data. */
$d->setWindowStart($len);
} elseif ($marker == PelJpegMarker::COM) {
$content = new PelJpegComment();
$content->load($d->getClone(0, $len));
$this->appendSection($marker, $content);
$d->setWindowStart($len);
} else {
$content = new PelJpegContent($d->getClone(0, $len));
$this->appendSection($marker, $content);
/* Skip past the data. */
$d->setWindowStart($len);
/* In case of SOS, image data will follow. */
if ($marker == PelJpegMarker::SOS) {
/* Some images have some trailing (garbage?) following the
* EOI marker. To handle this we seek backwards until we
* find the EOI marker. Any trailing content is stored as
* a PelJpegContent object. */
$length = $d->getSize();
while ($d->getByte($length-2) != 0xFF ||
$d->getByte($length-1) != PelJpegMarker::EOI) {
$length--;
}
$this->jpeg_data = $d->getClone(0, $length-2);
Pel::debug('JPEG data: ' . $this->jpeg_data->__toString());
/* Append the EOI. */
$this->appendSection(PelJpegMarker::EOI,
new PelJpegContent(new PelDataWindow()));
/* Now check to see if there are any trailing data. */
if ($length != $d->getSize()) {
Pel::maybeThrow(new PelException('Found trailing content ' .
'after EOI: %d bytes',
$d->getSize() - $length));
$content = new PelJpegContent($d->getClone($length));
/* We don't have a proper JPEG marker for trailing
* garbage, so we just use 0x00... */
$this->appendSection(0x00, $content);
}
/* Done with the loop. */
break;
}
}
}
} /* while ($d->getSize() > 0) */
}
/**
* Load data from a file into a JPEG object.
*
* @param string the filename. This must be a readable file.
*/
function loadFile($filename) {
$this->load(new PelDataWindow(file_get_contents($filename)));
}
/**
* Set Exif data.
*
* Use this to set the Exif data in the image. This will overwrite
* any old Exif information in the image.
*
* @param PelExif the Exif data.
*/
function setExif(PelExif $exif) {
$app0_offset = 1;
$app1_offset = -1;
/* Search through all sections looking for APP0 or APP1. */
for ($i = 0; $i < count($this->sections); $i++) {
if ($this->sections[$i][0] == PelJpegMarker::APP0) {
$app0_offset = $i;
} elseif ($this->sections[$i][0] == PelJpegMarker::APP1) {
$app1_offset = $i;
break;
}
}
/* Store the Exif data at the appropriate place, either where the
* old Exif data was stored ($app1_offset) or right after APP0
* ($app0_offset+1). */
if ($app1_offset > 0)
$this->sections[$app1_offset][1] = $exif;
else
$this->insertSection(PelJpegMarker::APP1, $exif, $app0_offset+1);
}
/**
* Get Exif data.
*
* Use this to get the @{link PelExif Exif data} stored.
*
* @return PelExif the Exif data found or null if the image has no
* Exif data.
*/
function getExif() {
$exif = $this->getSection(PelJpegMarker::APP1);
if ($exif instanceof PelExif)
return $exif;
else
return null;
}
/**
* Clear any Exif data.
*
* This method will only clear the first @{link PelJpegMarker::APP1}
* section found (there should normally be just one).
*/
function clearExif() {
for ($i = 0; $i < count($this->sections); $i++) {
if ($this->sections[$i][0] == PelJpegMarker::APP1) {
unset($this->sections[$i]);
return;
}
}
}
/**
* Append a new section.
*
* Used only when loading an image. If it used again later, then the
* section will end up after the @{link PelJpegMarker::EOI EOI
* marker} and will probably not be useful.
*
* Please use @{link setExif()} instead if you intend to add Exif
* information to an image as that function will know the right
* place to insert the data.
*
* @param PelJpegMarker the marker identifying the new section.
*
* @param PelJpegContent the content of the new section.
*/
function appendSection($marker, PelJpegContent $content) {
$this->sections[] = array($marker, $content);
}
/**
* Insert a new section.
*
* Please use @{link setExif()} instead if you intend to add Exif
* information to an image as that function will know the right
* place to insert the data.
*
* @param PelJpegMarker the marker for the new section.
*
* @param PelJpegContent the content of the new section.
*
* @param int the offset where the new section will be inserted ---
* use 0 to insert it at the very beginning, use 1 to insert it
* between sections 1 and 2, etc.
*/
function insertSection($marker, PelJpegContent $content, $offset) {
array_splice($this->sections, $offset, 0, array(array($marker, $content)));
}
/**
* Get a section corresponding to a particular marker.
*
* Please use the {@link getExif()} if you just need the Exif data.
*
* This will search through the sections of this JPEG object,
* looking for a section identified with the specified {@link
* PelJpegMarker marker}. The {@link PelJpegContent content} will
* then be returned. The optional argument can be used to skip over
* some of the sections. So if one is looking for the, say, third
* {@link PelJpegMarker::DHT DHT} section one would do:
*
* <code>
* $dht3 = $jpeg->getSection(PelJpegMarker::DHT, 2);
* </code>
*
* @param PelJpegMarker the marker identifying the section.
*
* @param int the number of sections to be skipped. This must be a
* non-negative integer.
*
* @return PelJpegContent the content found, or null if there is no
* content available.
*/
function getSection($marker, $skip = 0) {
foreach ($this->sections as $s) {
if ($s[0] == $marker)
if ($skip > 0)
$skip--;
else
return $s[1];
}
return null;
}
/**
* Get all sections.
*
* @return array an array of ({@link PelJpegMarker}, {@link
* PelJpegContent}) pairs. Each pair is an array with the {@link
* PelJpegMarker} as the first element and the {@link
* PelJpegContent} as the second element, so the return type is an
* array of arrays.
*
* So to loop through all the sections in a given JPEG image do
* this:
*
* <code>
* foreach ($jpeg->getSections() as $section) {
* $marker = $section[0];
* $content = $section[1];
* // Use $marker and $content here.
* }
* </code>
*
* instead of this:
*
* <code>
* foreach ($jpeg->getSections() as $marker => $content) {
* // Does not work the way you would think...
* }
* </code>
*
* The problem is that there could be several sections with the same
* marker, and thus a simple associative array does not suffice.
*/
function getSections() {
return $this->sections;
}
/**
* Turn this JPEG object into bytes.
*
* The bytes returned by this method is ready to be stored in a file
* as a valid JPEG image.
*
* @return string bytes representing this JPEG object, including all
* its sections and their associated data.
*/
function getBytes() {
$bytes = '';
foreach ($this->sections as $section) {
$m = $section[0];
$c = $section[1];
/* Write the marker */
$bytes .= "\xFF" . PelJpegMarker::getBytes($m);
/* Skip over empty markers. */
if ($m == PelJpegMarker::SOI || $m == PelJpegMarker::EOI)
continue;
$data = $c->getBytes();
$size = strlen($data) + 2;
$bytes .= PelConvert::shortToBytes($size, PelConvert::BIG_ENDIAN);
$bytes .= $data;
/* In case of SOS, we need to write the JPEG data. */
if ($m == PelJpegMarker::SOS)
$bytes .= $this->jpeg_data->getBytes();
}
return $bytes;
}
/**
* Make a string representation of this JPEG object.
*
* This is mainly usefull for debugging. It will show the structure
* of the image, and its sections.
*
* @return string debugging information about this JPEG object.
*/
function __toString() {
$str = Pel::tra("Dumping JPEG data...\n");
for ($i = 0; $i < count($this->sections); $i++) {
$m = $this->sections[$i][0];
$c = $this->sections[$i][1];
$str .= Pel::fmt("Section %d (marker 0x%02X - %s):\n",
$i, $m, PelJpegMarker::getName($m));
$str .= Pel::fmt(" Description: %s\n",
PelJpegMarker::getDescription($m));
if ($m == PelJpegMarker::SOI ||
$m == PelJpegMarker::EOI)
continue;
if ($c instanceof PelExif) {
$str .= Pel::tra(" Content : Exif data\n");
$str .= $c->__toString() . "\n";
} elseif ($c instanceof PelJpegComment) {
$str .= Pel::fmt(" Content : %s\n", $c->getValue());
} else {
$str .= Pel::tra(" Content : Unknown\n");
}
}
return $str;
}
/**
* Test data to see if it could be a valid JPEG image.
*
* The function will only look at the first few bytes of the data,
* and try to determine if it could be a valid JPEG image based on
* those bytes. This means that the check is more like a heuristic
* than a rigorous check.
*
* @param PelDataWindow the bytes that will be checked.
*
* @return boolean true if the bytes look like the beginning of a
* JPEG image, false otherwise.
*
* @see PelTiff::isValid()
*/
static function isValid(PelDataWindow $d) {
/* JPEG data is stored in big-endian format. */
$d->setByteOrder(PelConvert::BIG_ENDIAN);
for ($i = 0; $i < 7; $i++)
if ($d->getByte($i) != 0xFF)
break;
return $d->getByte($i) == PelJpegMarker::SOI;
}
}
?>

View File

@ -1,121 +0,0 @@
<?php
/* PEL: PHP Exif Library. A library with support for reading and
* writing all Exif headers in JPEG and TIFF images using PHP.
*
* Copyright (C) 2005 Martin Geisler.
*
* 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 in the file COPYING; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/* $Id: PelJpegComment.php 397 2005-10-23 22:40:26Z mgeisler $ */
/**
* Class for dealing with JPEG comments.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @version $Revision: 397 $
* @date $Date: 2005-10-24 00:40:26 +0200 (Mon, 24 Oct 2005) $
* @license http://www.gnu.org/licenses/gpl.html GNU General Public
* License (GPL)
* @package PEL
*/
/**#@+ Required class definitions. */
require_once('PelJpegContent.php');
/**#@-*/
/**
* Class representing JPEG comments.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @package PEL
*/
class PelJpegComment extends PelJpegContent {
/**
* The comment.
*
* @var string
*/
private $comment = '';
/**
* Construct a new JPEG comment.
*
* The new comment will contain the string given.
*/
function __construct($comment = '') {
$this->comment = $comment;
}
/**
* Load and parse data.
*
* This will load the comment from the data window passed.
*/
function load(PelDataWindow $d) {
$this->comment = $d->getBytes();
}
/**
* Update the value with a new comment.
*
* Any old comment will be overwritten.
*
* @param string the new comment.
*/
function setValue($comment) {
$this->comment = $comment;
}
/**
* Get the comment.
*
* @return string the comment.
*/
function getValue() {
return $this->comment;
}
/**
* Turn this comment into bytes.
*
* @return string bytes representing this comment.
*/
function getBytes() {
$this->comment;
}
/**
* Return a string representation of this object.
*
* @return string the same as {@link getValue()}.
*/
function __toString() {
return $this->getValue();
}
}
?>

View File

@ -1,82 +0,0 @@
<?php
/* PEL: PHP Exif Library. A library with support for reading and
* writing all Exif headers in JPEG and TIFF images using PHP.
*
* Copyright (C) 2004, 2005 Martin Geisler.
*
* 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 in the file COPYING; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/* $Id: PelJpegContent.php 380 2005-10-03 12:01:28Z mgeisler $ */
/**
* Class representing content in a JPEG file.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @version $Revision: 380 $
* @date $Date: 2005-10-03 14:01:28 +0200 (Mon, 03 Oct 2005) $
* @license http://www.gnu.org/licenses/gpl.html GNU General Public
* License (GPL)
* @package PEL
*/
/**#@+ Required class definitions. */
require_once('PelDataWindow.php');
/**#@-*/
/**
* Class representing content in a JPEG file.
*
* A JPEG file consists of a sequence of each of which has an
* associated {@link PelJpegMarker marker} and some content. This
* class represents the content, and this basic type is just a simple
* holder of such content, represented by a {@link PelDataWindow}
* object. The {@link PelExif} class is an example of more
* specialized JPEG content.
*
* @author Martin Geisler <mgeisler@users.sourceforge.net>
* @package PEL
*/
class PelJpegContent {
private $data = null;
/**
* Make a new piece of JPEG content.
*
* @param PelDataWindow the content.
*/
function __construct(PelDataWindow $data) {
$this->data = $data;
}
/**
* Return the bytes of the content.
*
* @return string bytes representing this JPEG content. These bytes
* will match the bytes given to {@link __construct the
* constructor}.
*/
function getBytes() {
return $this->data->getBytes();
}
}
?>

Some files were not shown because too many files have changed in this diff Show More