Merge branch 'master' of git@github.com:rledisez/gallery3-contrib
This commit is contained in:
commit
fe74247fd2
BIN
client/Java/Demo.class
Normal file
BIN
client/Java/Demo.class
Normal file
Binary file not shown.
50
client/Java/Demo.java
Normal file
50
client/Java/Demo.java
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
10
client/Java/README
Normal file
10
client/Java/README
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
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.
|
1
client/Java/build.sh
Normal file
1
client/Java/build.sh
Normal file
@ -0,0 +1 @@
|
|||||||
|
javac -classpath lib/httpclient-4.0.1.jar:lib/httpcore-4.0.1.jar:lib/gson-1.4.jar Demo.java
|
BIN
client/Java/lib/commons-logging-api-1.1.1.jar
Normal file
BIN
client/Java/lib/commons-logging-api-1.1.1.jar
Normal file
Binary file not shown.
BIN
client/Java/lib/gson-1.4.jar
Normal file
BIN
client/Java/lib/gson-1.4.jar
Normal file
Binary file not shown.
BIN
client/Java/lib/httpclient-4.0.1.jar
Normal file
BIN
client/Java/lib/httpclient-4.0.1.jar
Normal file
Binary file not shown.
BIN
client/Java/lib/httpcore-4.0.1.jar
Normal file
BIN
client/Java/lib/httpcore-4.0.1.jar
Normal file
Binary file not shown.
1
client/Java/run.sh
Normal file
1
client/Java/run.sh
Normal file
@ -0,0 +1 @@
|
|||||||
|
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
|
@ -129,10 +129,16 @@ class Gallery3 {
|
|||||||
* @return object Gallery3
|
* @return object Gallery3
|
||||||
*/
|
*/
|
||||||
public function save() {
|
public function save() {
|
||||||
$response = Gallery3_Helper::request(
|
$data = array();
|
||||||
"put", $this->url, $this->token,
|
$data["entity"] = array_diff((array)$this->data->entity, $this->original_entity);
|
||||||
array("entity" => array_diff((array)$this->data->entity, $this->original_entity),
|
if (isset($this->data->members)) {
|
||||||
"members" => $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();
|
return $this->load();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,6 +186,7 @@ class Gallery3_Helper {
|
|||||||
|
|
||||||
switch ($req->getResponseCode()) {
|
switch ($req->getResponseCode()) {
|
||||||
case 200:
|
case 200:
|
||||||
|
case 201:
|
||||||
return json_decode($req->getResponseBody());
|
return json_decode($req->getResponseBody());
|
||||||
|
|
||||||
case 403:
|
case 403:
|
@ -39,13 +39,19 @@ for ($i = 0; $i < 2; $i++) {
|
|||||||
->set("type", "photo")
|
->set("type", "photo")
|
||||||
->set("name", "Sample Photo.png")
|
->set("name", "Sample Photo.png")
|
||||||
->set("title", "Sample Photo")
|
->set("title", "Sample Photo")
|
||||||
->set_file("gallery.png")
|
->set_file("test1.png")
|
||||||
->create($album->url, $auth);
|
->create($album->url, $auth);
|
||||||
alert("Uploaded photo: <b>{$photo->url}</b>");
|
alert("Uploaded photo: <b>{$photo->url}</b>");
|
||||||
}
|
}
|
||||||
$album->load();
|
$album->load();
|
||||||
alert("Album members: <b>" . join(", ", $album->data->members) . "</b>");
|
alert("Album members: <b>" . join(", ", $album->data->members) . "</b>");
|
||||||
|
|
||||||
|
|
||||||
|
alert("Replace the data file");
|
||||||
|
$photo->set_file("test2.png")
|
||||||
|
->save();
|
||||||
|
|
||||||
|
|
||||||
$comment = Gallery3::factory()
|
$comment = Gallery3::factory()
|
||||||
->set("item", $album->data->members[0])
|
->set("item", $album->data->members[0])
|
||||||
->set("type", "comment")
|
->set("type", "comment")
|
||||||
@ -93,7 +99,6 @@ $tag_relationship2->delete();
|
|||||||
$tag->load();
|
$tag->load();
|
||||||
alert("1 remaining tag: <b>{$tag->data->relationships->items->members[0]}</b>");
|
alert("1 remaining tag: <b>{$tag->data->relationships->items->members[0]}</b>");
|
||||||
|
|
||||||
|
|
||||||
alert("Delete the album and tag");
|
alert("Delete the album and tag");
|
||||||
$album->delete();
|
$album->delete();
|
||||||
$tag->delete();
|
$tag->delete();
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
BIN
client/PHP/test2.png
Normal file
BIN
client/PHP/test2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.3 KiB |
57
modules/adsense/controllers/admin_adsense.php
Normal file
57
modules/adsense/controllers/admin_adsense.php
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
|
/**
|
||||||
|
* Gallery - a web based photo album viewer and editor
|
||||||
|
* Copyright (C) 2000-2010 Bharat Mediratta
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
39
modules/adsense/helpers/adsense_block.php
Normal file
39
modules/adsense/helpers/adsense_block.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?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;
|
||||||
|
}
|
||||||
|
}
|
28
modules/adsense/helpers/adsense_event.php
Normal file
28
modules/adsense/helpers/adsense_event.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
|
/**
|
||||||
|
* Gallery - a web based photo album viewer and editor
|
||||||
|
* Copyright (C) 2000-2010 Bharat Mediratta
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
class 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")));
|
||||||
|
}
|
||||||
|
}
|
54
modules/adsense/helpers/adsense_theme.php
Normal file
54
modules/adsense/helpers/adsense_theme.php
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
|
/**
|
||||||
|
* Gallery - a web based photo album viewer and editor
|
||||||
|
* Copyright (C) 2000-2010 Bharat Mediratta
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
3
modules/adsense/module.info
Normal file
3
modules/adsense/module.info
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
name = "Adsense"
|
||||||
|
description = "Display Google Adsense ads"
|
||||||
|
version = 1
|
7
modules/adsense/views/admin_adsense.html.php
Normal file
7
modules/adsense/views/admin_adsense.html.php
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?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>
|
17
modules/adsense/views/adsense_block.html.php
Normal file
17
modules/adsense/views/adsense_block.html.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?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;
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
68
modules/autorotate/helpers/autorotate.php
Normal file
68
modules/autorotate/helpers/autorotate.php
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
|
/**
|
||||||
|
* Gallery - a web based photo album viewer and editor
|
||||||
|
* Copyright (C) 2000-2010 Bharat Mediratta
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
class 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));
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
}
|
32
modules/autorotate/helpers/autorotate_event.php
Normal file
32
modules/autorotate/helpers/autorotate_event.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
|
/**
|
||||||
|
* Gallery - a web based photo album viewer and editor
|
||||||
|
* Copyright (C) 2000-2010 Bharat Mediratta
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
class 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 add_photos_form_completed($item, $form) {
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
42
modules/autorotate/helpers/autorotate_installer.php
Normal file
42
modules/autorotate/helpers/autorotate_installer.php
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
|
/**
|
||||||
|
* Gallery - a web based photo album viewer and editor
|
||||||
|
* Copyright (C) 2000-2010 Bharat Mediratta
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
class autorotate_installer {
|
||||||
|
static function install() {
|
||||||
|
module::set_version("autorotate", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static function upgrade($version) {
|
||||||
|
if ($version == 1) {
|
||||||
|
module::set_version("autorotate", $version = 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
337
modules/autorotate/lib/pel/Pel.php
Normal file
337
modules/autorotate/lib/pel/Pel.php
Normal file
@ -0,0 +1,337 @@
|
|||||||
|
<?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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
397
modules/autorotate/lib/pel/PelConvert.php
Normal file
397
modules/autorotate/lib/pel/PelConvert.php
Normal file
@ -0,0 +1,397 @@
|
|||||||
|
<?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");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
525
modules/autorotate/lib/pel/PelDataWindow.php
Normal file
525
modules/autorotate/lib/pel/PelDataWindow.php
Normal file
@ -0,0 +1,525 @@
|
|||||||
|
<?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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
382
modules/autorotate/lib/pel/PelEntry.php
Normal file
382
modules/autorotate/lib/pel/PelEntry.php
Normal file
@ -0,0 +1,382 @@
|
|||||||
|
<?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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
482
modules/autorotate/lib/pel/PelEntryAscii.php
Normal file
482
modules/autorotate/lib/pel/PelEntryAscii.php
Normal file
@ -0,0 +1,482 @@
|
|||||||
|
<?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 '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
275
modules/autorotate/lib/pel/PelEntryByte.php
Normal file
275
modules/autorotate/lib/pel/PelEntryByte.php
Normal file
@ -0,0 +1,275 @@
|
|||||||
|
<?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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
182
modules/autorotate/lib/pel/PelEntryLong.php
Normal file
182
modules/autorotate/lib/pel/PelEntryLong.php
Normal file
@ -0,0 +1,182 @@
|
|||||||
|
<?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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
309
modules/autorotate/lib/pel/PelEntryNumber.php
Normal file
309
modules/autorotate/lib/pel/PelEntryNumber.php
Normal file
@ -0,0 +1,309 @@
|
|||||||
|
<?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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
290
modules/autorotate/lib/pel/PelEntryRational.php
Normal file
290
modules/autorotate/lib/pel/PelEntryRational.php
Normal file
@ -0,0 +1,290 @@
|
|||||||
|
<?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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
599
modules/autorotate/lib/pel/PelEntryShort.php
Normal file
599
modules/autorotate/lib/pel/PelEntryShort.php
Normal file
@ -0,0 +1,599 @@
|
|||||||
|
<?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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
416
modules/autorotate/lib/pel/PelEntryUndefined.php
Normal file
416
modules/autorotate/lib/pel/PelEntryUndefined.php
Normal file
@ -0,0 +1,416 @@
|
|||||||
|
<?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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
87
modules/autorotate/lib/pel/PelException.php
Normal file
87
modules/autorotate/lib/pel/PelException.php
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
<?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 {}
|
||||||
|
|
||||||
|
?>
|
175
modules/autorotate/lib/pel/PelExif.php
Normal file
175
modules/autorotate/lib/pel/PelExif.php
Normal file
@ -0,0 +1,175 @@
|
|||||||
|
<?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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
225
modules/autorotate/lib/pel/PelFormat.php
Normal file
225
modules/autorotate/lib/pel/PelFormat.php
Normal file
@ -0,0 +1,225 @@
|
|||||||
|
<?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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
1200
modules/autorotate/lib/pel/PelIfd.php
Normal file
1200
modules/autorotate/lib/pel/PelIfd.php
Normal file
File diff suppressed because it is too large
Load Diff
599
modules/autorotate/lib/pel/PelJpeg.php
Normal file
599
modules/autorotate/lib/pel/PelJpeg.php
Normal file
@ -0,0 +1,599 @@
|
|||||||
|
<?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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
121
modules/autorotate/lib/pel/PelJpegComment.php
Normal file
121
modules/autorotate/lib/pel/PelJpegComment.php
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
<?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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
82
modules/autorotate/lib/pel/PelJpegContent.php
Normal file
82
modules/autorotate/lib/pel/PelJpegContent.php
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
<?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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
435
modules/autorotate/lib/pel/PelJpegMarker.php
Normal file
435
modules/autorotate/lib/pel/PelJpegMarker.php
Normal file
@ -0,0 +1,435 @@
|
|||||||
|
<?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: PelJpegMarker.php 432 2006-09-05 22:13:00Z mgeisler $ */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Classes for dealing with JPEG markers.
|
||||||
|
*
|
||||||
|
* @author Martin Geisler <mgeisler@users.sourceforge.net>
|
||||||
|
* @version $Revision: 432 $
|
||||||
|
* @date $Date: 2006-09-06 00:13:00 +0200 (Wed, 06 Sep 2006) $
|
||||||
|
* @license http://www.gnu.org/licenses/gpl.html GNU General Public
|
||||||
|
* License (GPL)
|
||||||
|
* @package PEL
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**#@+ Required class definitions. */
|
||||||
|
require_once('Pel.php');
|
||||||
|
/**#@-*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class with static methods for JPEG markers.
|
||||||
|
*
|
||||||
|
* This class defines the constants to be used whenever one refers to
|
||||||
|
* a JPEG marker. All the methods defined are static, and they all
|
||||||
|
* operate on one argument which should be one of the class constants.
|
||||||
|
* They will all be denoted by PelJpegMarker in the documentation.
|
||||||
|
*
|
||||||
|
* @author Martin Geisler <mgeisler@users.sourceforge.net>
|
||||||
|
* @package PEL
|
||||||
|
*/
|
||||||
|
class PelJpegMarker {
|
||||||
|
|
||||||
|
/** Encoding (baseline) */
|
||||||
|
const SOF0 = 0xC0;
|
||||||
|
/** Encoding (extended sequential) */
|
||||||
|
const SOF1 = 0xC1;
|
||||||
|
/** Encoding (progressive) */
|
||||||
|
const SOF2 = 0xC2;
|
||||||
|
/** Encoding (lossless) */
|
||||||
|
const SOF3 = 0xC3;
|
||||||
|
/** Define Huffman table */
|
||||||
|
const DHT = 0xC4;
|
||||||
|
/** Encoding (differential sequential) */
|
||||||
|
const SOF5 = 0xC5;
|
||||||
|
/** Encoding (differential progressive) */
|
||||||
|
const SOF6 = 0xC6;
|
||||||
|
/** Encoding (differential lossless) */
|
||||||
|
const SOF7 = 0xC7;
|
||||||
|
/** Extension */
|
||||||
|
const JPG = 0xC8;
|
||||||
|
/** Encoding (extended sequential, arithmetic) */
|
||||||
|
const SOF9 = 0xC9;
|
||||||
|
/** Encoding (progressive, arithmetic) */
|
||||||
|
const SOF10 = 0xCA;
|
||||||
|
/** Encoding (lossless, arithmetic) */
|
||||||
|
const SOF11 = 0xCB;
|
||||||
|
/** Define arithmetic coding conditioning */
|
||||||
|
const DAC = 0xCC;
|
||||||
|
/** Encoding (differential sequential, arithmetic) */
|
||||||
|
const SOF13 = 0xCD;
|
||||||
|
/** Encoding (differential progressive, arithmetic) */
|
||||||
|
const SOF14 = 0xCE;
|
||||||
|
/** Encoding (differential lossless, arithmetic) */
|
||||||
|
const SOF15 = 0xCF;
|
||||||
|
/** Restart 0 */
|
||||||
|
const RST0 = 0xD0;
|
||||||
|
/** Restart 1 */
|
||||||
|
const RST1 = 0xD1;
|
||||||
|
/** Restart 2 */
|
||||||
|
const RST2 = 0xD2;
|
||||||
|
/** Restart 3 */
|
||||||
|
const RST3 = 0xD3;
|
||||||
|
/** Restart 4 */
|
||||||
|
const RST4 = 0xD4;
|
||||||
|
/** Restart 5 */
|
||||||
|
const RST5 = 0xD5;
|
||||||
|
/** Restart 6 */
|
||||||
|
const RST6 = 0xD6;
|
||||||
|
/** Restart 7 */
|
||||||
|
const RST7 = 0xD7;
|
||||||
|
/** Start of image */
|
||||||
|
const SOI = 0xD8;
|
||||||
|
/** End of image */
|
||||||
|
const EOI = 0xD9;
|
||||||
|
/** Start of scan */
|
||||||
|
const SOS = 0xDA;
|
||||||
|
/** Define quantization table */
|
||||||
|
const DQT = 0xDB;
|
||||||
|
/** Define number of lines */
|
||||||
|
const DNL = 0xDC;
|
||||||
|
/** Define restart interval */
|
||||||
|
const DRI = 0xDD;
|
||||||
|
/** Define hierarchical progression */
|
||||||
|
const DHP = 0xDE;
|
||||||
|
/** Expand reference component */
|
||||||
|
const EXP = 0xDF;
|
||||||
|
/** Application segment 0 */
|
||||||
|
const APP0 = 0xE0;
|
||||||
|
/**
|
||||||
|
* Application segment 1
|
||||||
|
*
|
||||||
|
* When a JPEG image contains Exif data, the data will normally be
|
||||||
|
* stored in this section and a call to {@link PelJpeg::getExif()}
|
||||||
|
* will return a {@link PelExif} object representing it.
|
||||||
|
*/
|
||||||
|
const APP1 = 0xE1;
|
||||||
|
/** Application segment 2 */
|
||||||
|
const APP2 = 0xE2;
|
||||||
|
/** Application segment 3 */
|
||||||
|
const APP3 = 0xE3;
|
||||||
|
/** Application segment 4 */
|
||||||
|
const APP4 = 0xE4;
|
||||||
|
/** Application segment 5 */
|
||||||
|
const APP5 = 0xE5;
|
||||||
|
/** Application segment 6 */
|
||||||
|
const APP6 = 0xE6;
|
||||||
|
/** Application segment 7 */
|
||||||
|
const APP7 = 0xE7;
|
||||||
|
/** Application segment 8 */
|
||||||
|
const APP8 = 0xE8;
|
||||||
|
/** Application segment 9 */
|
||||||
|
const APP9 = 0xE9;
|
||||||
|
/** Application segment 10 */
|
||||||
|
const APP10 = 0xEA;
|
||||||
|
/** Application segment 11 */
|
||||||
|
const APP11 = 0xEB;
|
||||||
|
/** Application segment 12 */
|
||||||
|
const APP12 = 0xEC;
|
||||||
|
/** Application segment 13 */
|
||||||
|
const APP13 = 0xED;
|
||||||
|
/** Application segment 14 */
|
||||||
|
const APP14 = 0xEE;
|
||||||
|
/** Application segment 15 */
|
||||||
|
const APP15 = 0xEF;
|
||||||
|
/** Extension 0 */
|
||||||
|
const JPG0 = 0xF0;
|
||||||
|
/** Extension 1 */
|
||||||
|
const JPG1 = 0xF1;
|
||||||
|
/** Extension 2 */
|
||||||
|
const JPG2 = 0xF2;
|
||||||
|
/** Extension 3 */
|
||||||
|
const JPG3 = 0xF3;
|
||||||
|
/** Extension 4 */
|
||||||
|
const JPG4 = 0xF4;
|
||||||
|
/** Extension 5 */
|
||||||
|
const JPG5 = 0xF5;
|
||||||
|
/** Extension 6 */
|
||||||
|
const JPG6 = 0xF6;
|
||||||
|
/** Extension 7 */
|
||||||
|
const JPG7 = 0xF7;
|
||||||
|
/** Extension 8 */
|
||||||
|
const JPG8 = 0xF8;
|
||||||
|
/** Extension 9 */
|
||||||
|
const JPG9 = 0xF9;
|
||||||
|
/** Extension 10 */
|
||||||
|
const JPG10 = 0xFA;
|
||||||
|
/** Extension 11 */
|
||||||
|
const JPG11 = 0xFB;
|
||||||
|
/** Extension 12 */
|
||||||
|
const JPG12 = 0xFC;
|
||||||
|
/** Extension 13 */
|
||||||
|
const JPG13 = 0xFD;
|
||||||
|
/** Comment */
|
||||||
|
const COM = 0xFE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a byte is a valid JPEG marker.
|
||||||
|
*
|
||||||
|
* @param PelJpegMarker the byte that will be checked.
|
||||||
|
*
|
||||||
|
* @return boolean if the byte is recognized true is returned,
|
||||||
|
* otherwise false will be returned.
|
||||||
|
*/
|
||||||
|
static function isValid($m) {
|
||||||
|
return ($m >= self::SOF0 && $m <= self::COM);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Turn a JPEG marker into bytes.
|
||||||
|
*
|
||||||
|
* @param PelJpegMarker the marker.
|
||||||
|
*
|
||||||
|
* @return string the marker as a string. This will be a string
|
||||||
|
* with just a single byte since all JPEG markers are simply single
|
||||||
|
* bytes.
|
||||||
|
*/
|
||||||
|
static function getBytes($m) {
|
||||||
|
return chr($m);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the short name for a marker.
|
||||||
|
*
|
||||||
|
* @param PelJpegMarker the marker.
|
||||||
|
*
|
||||||
|
* @return string the name of the marker, e.g., 'SOI' for the Start
|
||||||
|
* of Image marker.
|
||||||
|
*/
|
||||||
|
static function getName($m) {
|
||||||
|
switch ($m) {
|
||||||
|
case self::SOF0: return 'SOF0';
|
||||||
|
case self::SOF1: return 'SOF1';
|
||||||
|
case self::SOF2: return 'SOF2';
|
||||||
|
case self::SOF3: return 'SOF3';
|
||||||
|
case self::SOF5: return 'SOF5';
|
||||||
|
case self::SOF6: return 'SOF6';
|
||||||
|
case self::SOF7: return 'SOF7';
|
||||||
|
case self::SOF9: return 'SOF9';
|
||||||
|
case self::SOF10: return 'SOF10';
|
||||||
|
case self::SOF11: return 'SOF11';
|
||||||
|
case self::SOF13: return 'SOF13';
|
||||||
|
case self::SOF14: return 'SOF14';
|
||||||
|
case self::SOF15: return 'SOF15';
|
||||||
|
case self::SOI: return 'SOI';
|
||||||
|
case self::EOI: return 'EOI';
|
||||||
|
case self::SOS: return 'SOS';
|
||||||
|
case self::COM: return 'COM';
|
||||||
|
case self::DHT: return 'DHT';
|
||||||
|
case self::JPG: return 'JPG';
|
||||||
|
case self::DAC: return 'DAC';
|
||||||
|
case self::RST0: return 'RST0';
|
||||||
|
case self::RST1: return 'RST1';
|
||||||
|
case self::RST2: return 'RST2';
|
||||||
|
case self::RST3: return 'RST3';
|
||||||
|
case self::RST4: return 'RST4';
|
||||||
|
case self::RST5: return 'RST5';
|
||||||
|
case self::RST6: return 'RST6';
|
||||||
|
case self::RST7: return 'RST7';
|
||||||
|
case self::DQT: return 'DQT';
|
||||||
|
case self::DNL: return 'DNL';
|
||||||
|
case self::DRI: return 'DRI';
|
||||||
|
case self::DHP: return 'DHP';
|
||||||
|
case self::EXP: return 'EXP';
|
||||||
|
case self::APP0: return 'APP0';
|
||||||
|
case self::APP1: return 'APP1';
|
||||||
|
case self::APP2: return 'APP2';
|
||||||
|
case self::APP3: return 'APP3';
|
||||||
|
case self::APP4: return 'APP4';
|
||||||
|
case self::APP5: return 'APP5';
|
||||||
|
case self::APP6: return 'APP6';
|
||||||
|
case self::APP7: return 'APP7';
|
||||||
|
case self::APP8: return 'APP8';
|
||||||
|
case self::APP9: return 'APP9';
|
||||||
|
case self::APP10: return 'APP10';
|
||||||
|
case self::APP11: return 'APP11';
|
||||||
|
case self::APP12: return 'APP12';
|
||||||
|
case self::APP13: return 'APP13';
|
||||||
|
case self::APP14: return 'APP14';
|
||||||
|
case self::APP15: return 'APP15';
|
||||||
|
case self::JPG0: return 'JPG0';
|
||||||
|
case self::JPG1: return 'JPG1';
|
||||||
|
case self::JPG2: return 'JPG2';
|
||||||
|
case self::JPG3: return 'JPG3';
|
||||||
|
case self::JPG4: return 'JPG4';
|
||||||
|
case self::JPG5: return 'JPG5';
|
||||||
|
case self::JPG6: return 'JPG6';
|
||||||
|
case self::JPG7: return 'JPG7';
|
||||||
|
case self::JPG8: return 'JPG8';
|
||||||
|
case self::JPG9: return 'JPG9';
|
||||||
|
case self::JPG10: return 'JPG10';
|
||||||
|
case self::JPG11: return 'JPG11';
|
||||||
|
case self::JPG12: return 'JPG12';
|
||||||
|
case self::JPG13: return 'JPG13';
|
||||||
|
case self::COM: return 'COM';
|
||||||
|
default: return Pel::fmt('Unknown marker: 0x%02X', $m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a description of a JPEG marker.
|
||||||
|
*
|
||||||
|
* @param PelJpegMarker the marker.
|
||||||
|
*
|
||||||
|
* @return string the description of the marker.
|
||||||
|
*/
|
||||||
|
static function getDescription($m) {
|
||||||
|
switch ($m) {
|
||||||
|
case self::SOF0:
|
||||||
|
return Pel::tra('Encoding (baseline)');
|
||||||
|
case self::SOF1:
|
||||||
|
return Pel::tra('Encoding (extended sequential)');
|
||||||
|
case self::SOF2:
|
||||||
|
return Pel::tra('Encoding (progressive)');
|
||||||
|
case self::SOF3:
|
||||||
|
return Pel::tra('Encoding (lossless)');
|
||||||
|
case self::SOF5:
|
||||||
|
return Pel::tra('Encoding (differential sequential)');
|
||||||
|
case self::SOF6:
|
||||||
|
return Pel::tra('Encoding (differential progressive)');
|
||||||
|
case self::SOF7:
|
||||||
|
return Pel::tra('Encoding (differential lossless)');
|
||||||
|
case self::SOF9:
|
||||||
|
return Pel::tra('Encoding (extended sequential, arithmetic)');
|
||||||
|
case self::SOF10:
|
||||||
|
return Pel::tra('Encoding (progressive, arithmetic)');
|
||||||
|
case self::SOF11:
|
||||||
|
return Pel::tra('Encoding (lossless, arithmetic)');
|
||||||
|
case self::SOF13:
|
||||||
|
return Pel::tra('Encoding (differential sequential, arithmetic)');
|
||||||
|
case self::SOF14:
|
||||||
|
return Pel::tra('Encoding (differential progressive, arithmetic)');
|
||||||
|
case self::SOF15:
|
||||||
|
return Pel::tra('Encoding (differential lossless, arithmetic)');
|
||||||
|
case self::SOI:
|
||||||
|
return Pel::tra('Start of image');
|
||||||
|
case self::EOI:
|
||||||
|
return Pel::tra('End of image');
|
||||||
|
case self::SOS:
|
||||||
|
return Pel::tra('Start of scan');
|
||||||
|
case self::COM:
|
||||||
|
return Pel::tra('Comment');
|
||||||
|
case self::DHT:
|
||||||
|
return Pel::tra('Define Huffman table');
|
||||||
|
case self::JPG:
|
||||||
|
return Pel::tra('Extension');
|
||||||
|
case self::DAC:
|
||||||
|
return Pel::tra('Define arithmetic coding conditioning');
|
||||||
|
case self::RST0:
|
||||||
|
return Pel::fmt('Restart %d', 0);
|
||||||
|
case self::RST1:
|
||||||
|
return Pel::fmt('Restart %d', 1);
|
||||||
|
case self::RST2:
|
||||||
|
return Pel::fmt('Restart %d', 2);
|
||||||
|
case self::RST3:
|
||||||
|
return Pel::fmt('Restart %d', 3);
|
||||||
|
case self::RST4:
|
||||||
|
return Pel::fmt('Restart %d', 4);
|
||||||
|
case self::RST5:
|
||||||
|
return Pel::fmt('Restart %d', 5);
|
||||||
|
case self::RST6:
|
||||||
|
return Pel::fmt('Restart %d', 6);
|
||||||
|
case self::RST7:
|
||||||
|
return Pel::fmt('Restart %d', 7);
|
||||||
|
case self::DQT:
|
||||||
|
return Pel::tra('Define quantization table');
|
||||||
|
case self::DNL:
|
||||||
|
return Pel::tra('Define number of lines');
|
||||||
|
case self::DRI:
|
||||||
|
return Pel::tra('Define restart interval');
|
||||||
|
case self::DHP:
|
||||||
|
return Pel::tra('Define hierarchical progression');
|
||||||
|
case self::EXP:
|
||||||
|
return Pel::tra('Expand reference component');
|
||||||
|
case self::APP0:
|
||||||
|
return Pel::fmt('Application segment %d', 0);
|
||||||
|
case self::APP1:
|
||||||
|
return Pel::fmt('Application segment %d', 1);
|
||||||
|
case self::APP2:
|
||||||
|
return Pel::fmt('Application segment %d', 2);
|
||||||
|
case self::APP3:
|
||||||
|
return Pel::fmt('Application segment %d', 3);
|
||||||
|
case self::APP4:
|
||||||
|
return Pel::fmt('Application segment %d', 4);
|
||||||
|
case self::APP5:
|
||||||
|
return Pel::fmt('Application segment %d', 5);
|
||||||
|
case self::APP6:
|
||||||
|
return Pel::fmt('Application segment %d', 6);
|
||||||
|
case self::APP7:
|
||||||
|
return Pel::fmt('Application segment %d', 7);
|
||||||
|
case self::APP8:
|
||||||
|
return Pel::fmt('Application segment %d', 8);
|
||||||
|
case self::APP9:
|
||||||
|
return Pel::fmt('Application segment %d', 9);
|
||||||
|
case self::APP10:
|
||||||
|
return Pel::fmt('Application segment %d', 10);
|
||||||
|
case self::APP11:
|
||||||
|
return Pel::fmt('Application segment %d', 11);
|
||||||
|
case self::APP12:
|
||||||
|
return Pel::fmt('Application segment %d', 12);
|
||||||
|
case self::APP13:
|
||||||
|
return Pel::fmt('Application segment %d', 13);
|
||||||
|
case self::APP14:
|
||||||
|
return Pel::fmt('Application segment %d', 14);
|
||||||
|
case self::APP15:
|
||||||
|
return Pel::fmt('Application segment %d', 15);
|
||||||
|
case self::JPG0:
|
||||||
|
return Pel::fmt('Extension %d', 0);
|
||||||
|
case self::JPG1:
|
||||||
|
return Pel::fmt('Extension %d', 1);
|
||||||
|
case self::JPG2:
|
||||||
|
return Pel::fmt('Extension %d', 2);
|
||||||
|
case self::JPG3:
|
||||||
|
return Pel::fmt('Extension %d', 3);
|
||||||
|
case self::JPG4:
|
||||||
|
return Pel::fmt('Extension %d', 4);
|
||||||
|
case self::JPG5:
|
||||||
|
return Pel::fmt('Extension %d', 5);
|
||||||
|
case self::JPG6:
|
||||||
|
return Pel::fmt('Extension %d', 6);
|
||||||
|
case self::JPG7:
|
||||||
|
return Pel::fmt('Extension %d', 7);
|
||||||
|
case self::JPG8:
|
||||||
|
return Pel::fmt('Extension %d', 8);
|
||||||
|
case self::JPG9:
|
||||||
|
return Pel::fmt('Extension %d', 9);
|
||||||
|
case self::JPG10:
|
||||||
|
return Pel::fmt('Extension %d', 10);
|
||||||
|
case self::JPG11:
|
||||||
|
return Pel::fmt('Extension %d', 11);
|
||||||
|
case self::JPG12:
|
||||||
|
return Pel::fmt('Extension %d', 12);
|
||||||
|
case self::JPG13:
|
||||||
|
return Pel::fmt('Extension %d', 13);
|
||||||
|
case self::COM:
|
||||||
|
return Pel::tra('Comment');
|
||||||
|
default:
|
||||||
|
return Pel::fmt('Unknown marker: 0x%02X', $m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
1969
modules/autorotate/lib/pel/PelTag.php
Normal file
1969
modules/autorotate/lib/pel/PelTag.php
Normal file
File diff suppressed because it is too large
Load Diff
296
modules/autorotate/lib/pel/PelTiff.php
Normal file
296
modules/autorotate/lib/pel/PelTiff.php
Normal file
@ -0,0 +1,296 @@
|
|||||||
|
<?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: PelTiff.php 458 2006-11-18 21:22:58Z mgeisler $ */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Classes for dealing with TIFF data.
|
||||||
|
*
|
||||||
|
* @author Martin Geisler <mgeisler@users.sourceforge.net>
|
||||||
|
* @version $Revision: 458 $
|
||||||
|
* @date $Date: 2006-11-18 22:22:58 +0100 (Sat, 18 Nov 2006) $
|
||||||
|
* @license http://www.gnu.org/licenses/gpl.html GNU General Public
|
||||||
|
* License (GPL)
|
||||||
|
* @package PEL
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**#@+ Required class definitions. */
|
||||||
|
require_once('PelDataWindow.php');
|
||||||
|
require_once('PelIfd.php');
|
||||||
|
require_once('Pel.php');
|
||||||
|
/**#@-*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class for handling TIFF data.
|
||||||
|
*
|
||||||
|
* Exif data is actually an extension of the TIFF file format. TIFF
|
||||||
|
* images consist of a number of {@link PelIfd Image File Directories}
|
||||||
|
* (IFDs), each containing a number of {@link PelEntry entries}. The
|
||||||
|
* IFDs are linked to each other --- one can get hold of the first one
|
||||||
|
* with the {@link getIfd()} method.
|
||||||
|
*
|
||||||
|
* To parse a TIFF image for Exif data one would do:
|
||||||
|
*
|
||||||
|
* <code>
|
||||||
|
* $tiff = new PelTiff($data);
|
||||||
|
* $ifd0 = $tiff->getIfd();
|
||||||
|
* $exif = $ifd0->getSubIfd(PelIfd::EXIF);
|
||||||
|
* $ifd1 = $ifd0->getNextIfd();
|
||||||
|
* </code>
|
||||||
|
*
|
||||||
|
* Should one have some image data of an unknown type, then the {@link
|
||||||
|
* PelTiff::isValid()} function is handy: it will quickly test if the
|
||||||
|
* data could be valid TIFF data. The {@link PelJpeg::isValid()}
|
||||||
|
* function does the same for JPEG images.
|
||||||
|
*
|
||||||
|
* @author Martin Geisler <mgeisler@users.sourceforge.net>
|
||||||
|
* @package PEL
|
||||||
|
*/
|
||||||
|
class PelTiff {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TIFF header.
|
||||||
|
*
|
||||||
|
* This must follow after the two bytes indicating the byte order.
|
||||||
|
*/
|
||||||
|
const TIFF_HEADER = 0x002A;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The first Image File Directory, if any.
|
||||||
|
*
|
||||||
|
* If set, then the type of the IFD must be {@link PelIfd::IFD0}.
|
||||||
|
*
|
||||||
|
* @var PelIfd
|
||||||
|
*/
|
||||||
|
private $ifd = null;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a new object for holding TIFF data.
|
||||||
|
*
|
||||||
|
* The new object will be empty (with no {@link PelIfd}) unless an
|
||||||
|
* argument is given from which it can initialize itself. This can
|
||||||
|
* either be the filename of a TIFF image or a {@link PelDataWindow}
|
||||||
|
* object.
|
||||||
|
*
|
||||||
|
* Use {@link setIfd()} to explicitly set the IFD.
|
||||||
|
*/
|
||||||
|
function __construct($data = false) {
|
||||||
|
if ($data === false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (is_string($data)) {
|
||||||
|
Pel::debug('Initializing PelTiff object from %s', $data);
|
||||||
|
$this->loadFile($data);
|
||||||
|
} elseif ($data instanceof PelDataWindow) {
|
||||||
|
Pel::debug('Initializing PelTiff object from PelDataWindow.');
|
||||||
|
$this->load($data);
|
||||||
|
} else {
|
||||||
|
throw new PelInvalidArgumentException('Bad type for $data: %s',
|
||||||
|
gettype($data));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load TIFF data.
|
||||||
|
*
|
||||||
|
* The data given will be parsed and an internal tree representation
|
||||||
|
* will be built. If the data cannot be parsed correctly, a {@link
|
||||||
|
* PelInvalidDataException} is thrown, explaining the problem.
|
||||||
|
*
|
||||||
|
* @param PelDataWindow the data from which the object will be
|
||||||
|
* constructed. This should be valid TIFF data, coming either
|
||||||
|
* directly from a TIFF image or from the Exif data in a JPEG image.
|
||||||
|
*/
|
||||||
|
function load(PelDataWindow $d) {
|
||||||
|
Pel::debug('Parsing %d bytes of TIFF data...', $d->getSize());
|
||||||
|
|
||||||
|
/* There must be at least 8 bytes available: 2 bytes for the byte
|
||||||
|
* order, 2 bytes for the TIFF header, and 4 bytes for the offset
|
||||||
|
* to the first IFD. */
|
||||||
|
if ($d->getSize() < 8)
|
||||||
|
throw new PelInvalidDataException('Expected at least 8 bytes of TIFF ' .
|
||||||
|
'data, found just %d bytes.',
|
||||||
|
$d->getSize());
|
||||||
|
|
||||||
|
/* Byte order */
|
||||||
|
if ($d->strcmp(0, 'II')) {
|
||||||
|
Pel::debug('Found Intel byte order');
|
||||||
|
$d->setByteOrder(PelConvert::LITTLE_ENDIAN);
|
||||||
|
} elseif ($d->strcmp(0, 'MM')) {
|
||||||
|
Pel::debug('Found Motorola byte order');
|
||||||
|
$d->setByteOrder(PelConvert::BIG_ENDIAN);
|
||||||
|
} else {
|
||||||
|
throw new PelInvalidDataException('Unknown byte order found in TIFF ' .
|
||||||
|
'data: 0x%2X%2X',
|
||||||
|
$d->getByte(0), $d->getByte(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Verify the TIFF header */
|
||||||
|
if ($d->getShort(2) != self::TIFF_HEADER)
|
||||||
|
throw new PelInvalidDataException('Missing TIFF magic value.');
|
||||||
|
|
||||||
|
/* IFD 0 offset */
|
||||||
|
$offset = $d->getLong(4);
|
||||||
|
Pel::debug('First IFD at offset %d.', $offset);
|
||||||
|
|
||||||
|
if ($offset > 0) {
|
||||||
|
/* Parse the first IFD, this will automatically parse the
|
||||||
|
* following IFDs and any sub IFDs. */
|
||||||
|
$this->ifd = new PelIfd(PelIfd::IFD0);
|
||||||
|
$this->ifd->load($d, $offset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load data from a file into a TIFF object.
|
||||||
|
*
|
||||||
|
* @param string the filename. This must be a readable file.
|
||||||
|
*/
|
||||||
|
function loadFile($filename) {
|
||||||
|
$this->load(new PelDataWindow(file_get_contents($filename)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the first IFD.
|
||||||
|
*
|
||||||
|
* @param PelIfd the new first IFD, which must be of type {@link
|
||||||
|
* PelIfd::IFD0}.
|
||||||
|
*/
|
||||||
|
function setIfd(PelIfd $ifd) {
|
||||||
|
if ($ifd->getType() != PelIfd::IFD0)
|
||||||
|
throw new PelInvalidDataException('Invalid type of IFD: %d, expected %d.',
|
||||||
|
$ifd->getType(), PelIfd::IFD0);
|
||||||
|
|
||||||
|
$this->ifd = $ifd;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the first IFD.
|
||||||
|
*
|
||||||
|
* @return PelIfd the first IFD contained in the TIFF data, if any.
|
||||||
|
* If there is no IFD null will be returned.
|
||||||
|
*/
|
||||||
|
function getIfd() {
|
||||||
|
return $this->ifd;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Turn this object into bytes.
|
||||||
|
*
|
||||||
|
* TIFF images can have {@link PelConvert::LITTLE_ENDIAN
|
||||||
|
* little-endian} or {@link PelConvert::BIG_ENDIAN big-endian} byte
|
||||||
|
* order, and so this method takes an argument specifying that.
|
||||||
|
*
|
||||||
|
* @param PelByteOrder the desired byte order of the TIFF data.
|
||||||
|
* This should be one of {@link PelConvert::LITTLE_ENDIAN} or {@link
|
||||||
|
* PelConvert::BIG_ENDIAN}.
|
||||||
|
*
|
||||||
|
* @return string the bytes representing this object.
|
||||||
|
*/
|
||||||
|
function getBytes($order = PelConvert::LITTLE_ENDIAN) {
|
||||||
|
if ($order == PelConvert::LITTLE_ENDIAN)
|
||||||
|
$bytes = 'II';
|
||||||
|
else
|
||||||
|
$bytes = 'MM';
|
||||||
|
|
||||||
|
/* TIFF magic number --- fixed value. */
|
||||||
|
$bytes .= PelConvert::shortToBytes(self::TIFF_HEADER, $order);
|
||||||
|
|
||||||
|
if ($this->ifd != null) {
|
||||||
|
/* IFD 0 offset. We will always start IDF 0 at an offset of 8
|
||||||
|
* bytes (2 bytes for byte order, another 2 bytes for the TIFF
|
||||||
|
* header, and 4 bytes for the IFD 0 offset make 8 bytes
|
||||||
|
* together).
|
||||||
|
*/
|
||||||
|
$bytes .= PelConvert::longToBytes(8, $order);
|
||||||
|
|
||||||
|
/* The argument specifies the offset of this IFD. The IFD will
|
||||||
|
* use this to calculate offsets from the entries to their data,
|
||||||
|
* all those offsets are absolute offsets counted from the
|
||||||
|
* beginning of the data. */
|
||||||
|
$bytes .= $this->ifd->getBytes(8, $order);
|
||||||
|
} else {
|
||||||
|
$bytes .= PelConvert::longToBytes(0, $order);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a string representation of this object.
|
||||||
|
*
|
||||||
|
* @return string a string describing this object. This is mostly useful
|
||||||
|
* for debugging.
|
||||||
|
*/
|
||||||
|
function __toString() {
|
||||||
|
$str = Pel::fmt("Dumping TIFF data...\n");
|
||||||
|
if ($this->ifd != null)
|
||||||
|
$str .= $this->ifd->__toString();
|
||||||
|
|
||||||
|
return $str;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if data is valid TIFF data.
|
||||||
|
*
|
||||||
|
* This will read just enough data from the data window to determine
|
||||||
|
* if the data could be a valid TIFF data. This means that the
|
||||||
|
* check is more like a heuristic than a rigorous check.
|
||||||
|
*
|
||||||
|
* @param PelDataWindow the bytes that will be examined.
|
||||||
|
*
|
||||||
|
* @return boolean true if the data looks like valid TIFF data,
|
||||||
|
* false otherwise.
|
||||||
|
*
|
||||||
|
* @see PelJpeg::isValid()
|
||||||
|
*/
|
||||||
|
static function isValid(PelDataWindow $d) {
|
||||||
|
/* First check that we have enough data. */
|
||||||
|
if ($d->getSize() < 8)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/* Byte order */
|
||||||
|
if ($d->strcmp(0, 'II')) {
|
||||||
|
$d->setByteOrder(PelConvert::LITTLE_ENDIAN);
|
||||||
|
} elseif ($d->strcmp(0, 'MM')) {
|
||||||
|
Pel::debug('Found Motorola byte order');
|
||||||
|
$d->setByteOrder(PelConvert::BIG_ENDIAN);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Verify the TIFF header */
|
||||||
|
return $d->getShort(2) == self::TIFF_HEADER;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
3
modules/autorotate/module.info
Normal file
3
modules/autorotate/module.info
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
name = "Autorotate"
|
||||||
|
description = "Rotate an image automatically on upload based on EXIF data"
|
||||||
|
version = 2
|
@ -1,7 +1,7 @@
|
|||||||
<?php defined("SYSPATH") or die("No direct script access.");
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
/**
|
/**
|
||||||
* Gallery - a web based photo album viewer and editor
|
* Gallery - a web based photo album viewer and editor
|
||||||
* Copyright (C) 2000-2010 Bharat Mediratta
|
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -27,14 +27,12 @@ class Admin_Configure_Controller extends Controller
|
|||||||
{
|
{
|
||||||
$form = basket::get_configure_form();
|
$form = basket::get_configure_form();
|
||||||
if (request::method() == "post") {
|
if (request::method() == "post") {
|
||||||
// @todo move the "save" part of this into a separate controller function
|
|
||||||
access::verify_csrf();
|
access::verify_csrf();
|
||||||
|
|
||||||
if ($form->validate()) {
|
if ($form->validate()) {
|
||||||
|
|
||||||
basket::extractForm($form);
|
basket::extractForm($form);
|
||||||
message::success(t("Basket Module Configured!"));
|
message::success(t("Basket Module Configured!"));
|
||||||
//url::redirect("admin/recaptcha");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -45,11 +43,121 @@ class Admin_Configure_Controller extends Controller
|
|||||||
$view = new Admin_View("admin.html");
|
$view = new Admin_View("admin.html");
|
||||||
$view->content = new View("admin_configure.html");
|
$view->content = new View("admin_configure.html");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$view->content->form = $form;
|
$view->content->form = $form;
|
||||||
//$view->content->products = ORM::factory("product")->order_by("name")->find_all();
|
|
||||||
|
|
||||||
print $view;
|
print $view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the index page of the user homes admin
|
||||||
|
*/
|
||||||
|
public function templates()
|
||||||
|
{
|
||||||
|
$form = basket::get_template_form();
|
||||||
|
if (request::method() == "post") {
|
||||||
|
access::verify_csrf();
|
||||||
|
|
||||||
|
if ($form->validate()) {
|
||||||
|
|
||||||
|
basket::extractTemplateForm($form);
|
||||||
|
message::success(t("Basket Module Configured!"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
basket::populateTemplateForm($form);
|
||||||
|
}
|
||||||
|
|
||||||
|
$view = new Admin_View("admin.html");
|
||||||
|
$view->content = new View("admin_templates.html");
|
||||||
|
|
||||||
|
$view->content->form = $form;
|
||||||
|
|
||||||
|
print $view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function paypal_encrypt_wizard_step1()
|
||||||
|
{
|
||||||
|
$view = new Admin_View("admin.html");
|
||||||
|
$view->content = new View("pew1.html");
|
||||||
|
|
||||||
|
$view->content->form = self::keyGenerationForm();
|
||||||
|
|
||||||
|
print $view;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function paypal_encrypt_wizard_step2()
|
||||||
|
{
|
||||||
|
access::verify_csrf();
|
||||||
|
|
||||||
|
$form = self::keyGenerationForm();
|
||||||
|
|
||||||
|
if (!$form->validate()) {
|
||||||
|
|
||||||
|
self::paypal_encrypt_wizard_step1();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$ssldir = str_replace('\\','/',VARPATH.'certificate');
|
||||||
|
$ssldir= rtrim($ssldir, '/').'/';
|
||||||
|
|
||||||
|
if ( ! is_dir($ssldir))
|
||||||
|
{
|
||||||
|
// Create the upload directory
|
||||||
|
mkdir($ssldir, 0777, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
$prkeyfile = $ssldir . "myprvkey.pem";
|
||||||
|
$pubcertfile = $ssldir . "mypubcert.pem";
|
||||||
|
$certreqfile = $ssldir . "mycertreq.pem";
|
||||||
|
|
||||||
|
$dn = array("countryName" => $form->encrypt->countryName->value,
|
||||||
|
"stateOrProvinceName" => $form->encrypt->stateOrProvinceName->value,
|
||||||
|
"localityName" => $form->encrypt->localityName->value,
|
||||||
|
"organizationName" => $form->encrypt->organizationName->value,
|
||||||
|
"organizationalUnitName" => $form->encrypt->organizationalUnitName->value,
|
||||||
|
"commonName" => $form->encrypt->commonName->value,
|
||||||
|
"emailAddress" => $form->encrypt->emailAddress->value);
|
||||||
|
$privkeypass = $form->encrypt->privKeyPass->value;
|
||||||
|
$numberofdays = 365;
|
||||||
|
$config = array(
|
||||||
|
"private_key_bits" => 1024
|
||||||
|
);
|
||||||
|
|
||||||
|
$privkey = openssl_pkey_new($config);
|
||||||
|
$csr = openssl_csr_new($dn, $privkey);
|
||||||
|
$sscert = openssl_csr_sign($csr, null, $privkey, $numberofdays);
|
||||||
|
openssl_x509_export($sscert, $publickey);
|
||||||
|
openssl_pkey_export($privkey, $privatekey, $privkeypass);
|
||||||
|
openssl_csr_export($csr, $csrStr);
|
||||||
|
|
||||||
|
openssl_x509_export_to_file($sscert, $pubcertfile);
|
||||||
|
openssl_pkey_export_to_file ($privkey, $prkeyfile, $privkeypass);
|
||||||
|
openssl_csr_export_to_file($csr, $certreqfile);
|
||||||
|
|
||||||
|
//echo "Your Public Certificate has been saved to " . $pubcertfile . "<br><br>";
|
||||||
|
//echo "Your Private Key has been saved to " . $prkeyfile . "<br><br>";
|
||||||
|
//echo "Your Certificate Request has been saved to " . $certreqfile . "<br><br>";
|
||||||
|
|
||||||
|
//echo $privatekey; // Will hold the exported PriKey
|
||||||
|
//echo $publickey; // Will hold the exported PubKey
|
||||||
|
//echo $csrStr; // Will hold the exported Certificate
|
||||||
|
}
|
||||||
|
|
||||||
|
private function keyGenerationForm()
|
||||||
|
{
|
||||||
|
$form = new Forge("admin/configure/paypal_encrypt_wizard_step2", "", "post", array("id" => "generateKeys", "name" =>"generateKeys"));
|
||||||
|
$group = $form->group("encrypt")->label(t("Key Generation Details"));
|
||||||
|
$group->input("countryName")->label(t("Country Name"))->id("countryName");
|
||||||
|
$group->input("stateOrProvinceName")->label(t("State or Province Name"))->id("stateOrProvinceName");
|
||||||
|
$group->input("localityName")->label(t("Locality Name"))->id("localityName");
|
||||||
|
$group->input("organizationName")->label(t("Organization Name"))->id("organizationName");
|
||||||
|
$group->input("organizationalUnitName")->label(t("Organizational Unit Name"))->id("organizationalUnitName");
|
||||||
|
$group->input("commonName")->label(t("Common Name"))->id("commonName");
|
||||||
|
$group->input("emailAddress")->label(t("E-Mail Address"))->id("emailAddress");
|
||||||
|
$group->input("privKeyPass")->label(t("Private Key Pass"))->id("privkeypass");
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php defined("SYSPATH") or die("No direct script access.");
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
/**
|
/**
|
||||||
* Gallery - a web based photo album viewer and editor
|
* Gallery - a web based photo album viewer and editor
|
||||||
* Copyright (C) 2000-2010 Bharat Mediratta
|
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -41,35 +41,34 @@ class Admin_Postage_Bands_Controller extends Controller
|
|||||||
access::verify_csrf();
|
access::verify_csrf();
|
||||||
|
|
||||||
$form = postage_band::get_add_form_admin();
|
$form = postage_band::get_add_form_admin();
|
||||||
try {
|
$valid = $form->validate();
|
||||||
$valid = $form->validate();
|
$name = $form->add_postage->inputs["name"]->value;
|
||||||
$postage_band = ORM::factory("postage_band");
|
$postage = ORM::factory("postage_band")->where("name","=", $name)->find();
|
||||||
$postage_band->name = $form->add_postage->inputs["name"]->value;
|
if ($postage->loaded()) {
|
||||||
$postage_band->flat_rate = $form->add_postage->flat_rate->value;
|
$form->add_postage->inputs["name"]->add_error("in_use", 1);
|
||||||
$postage_band->per_item = $form->add_postage->per_item->value;
|
|
||||||
$postage_band->validate();
|
|
||||||
} catch (ORM_Validation_Exception $e) {
|
|
||||||
// Translate ORM validation errors into form error messages
|
|
||||||
foreach ($e->validation->errors() as $key => $error) {
|
|
||||||
$form->add_postage->inputs[$key]->add_error($error, 1);
|
|
||||||
}
|
|
||||||
$valid = false;
|
$valid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($valid) {
|
if ($valid) {
|
||||||
$postage_band->save();
|
$postage = postage_band::create(
|
||||||
|
$name,
|
||||||
|
$form->add_postage->flat_rate->value,
|
||||||
|
$form->add_postage->per_item->value
|
||||||
|
);
|
||||||
|
|
||||||
|
$postage->save();
|
||||||
message::success(t("Created postage band %postage_name", array(
|
message::success(t("Created postage band %postage_name", array(
|
||||||
"postage_name" => html::clean($postage_band->name))));
|
"postage_name" => html::clean($postage->name))));
|
||||||
print json_encode(array("result" => "success"));
|
print json::reply(array("result" => "success"));
|
||||||
} else {
|
} else {
|
||||||
print json_encode(array("result" => "error", "form" => (string)$form));
|
print $form;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delete_postage_band_form($id) {
|
public function delete_postage_band_form($id) {
|
||||||
$postage = ORM::factory("postage_band", $id);
|
$postage = ORM::factory("postage_band", $id);
|
||||||
if (!$postage->loaded()) {
|
if (!$postage->loaded()) {
|
||||||
throw new Kohana_404_Exception();
|
kohana::show_404();
|
||||||
}
|
}
|
||||||
print postage_band::get_delete_form_admin($postage);
|
print postage_band::get_delete_form_admin($postage);
|
||||||
}
|
}
|
||||||
@ -77,13 +76,9 @@ class Admin_Postage_Bands_Controller extends Controller
|
|||||||
public function delete_postage_band($id) {
|
public function delete_postage_band($id) {
|
||||||
access::verify_csrf();
|
access::verify_csrf();
|
||||||
|
|
||||||
if ($id == user::active()->id || $id == user::guest()->id) {
|
|
||||||
access::forbidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
$postage = ORM::factory("postage_band", $id);
|
$postage = ORM::factory("postage_band", $id);
|
||||||
if (!$postage->loaded()) {
|
if (!$postage->loaded()) {
|
||||||
throw new Kohana_404_Exception();
|
kohana::show_404();
|
||||||
}
|
}
|
||||||
|
|
||||||
$form = postage_band::get_delete_form_admin($postage);
|
$form = postage_band::get_delete_form_admin($postage);
|
||||||
@ -91,13 +86,13 @@ class Admin_Postage_Bands_Controller extends Controller
|
|||||||
$name = $postage->name;
|
$name = $postage->name;
|
||||||
$postage->delete();
|
$postage->delete();
|
||||||
} else {
|
} else {
|
||||||
print json_encode(array("result" => "error", "form" => (string)$form));
|
print $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
$message = t("Deleted user %postage_band", array("postage_band" => html::clean($name)));
|
$message = t("Deleted user %postage_band", array("postage_band" => html::clean($name)));
|
||||||
log::success("user", $message);
|
log::success("user", $message);
|
||||||
message::success($message);
|
message::success($message);
|
||||||
print json_encode(array("result" => "success"));
|
print json::reply(array("result" => "success"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function edit_postage_band($id) {
|
public function edit_postage_band($id) {
|
||||||
@ -105,38 +100,43 @@ class Admin_Postage_Bands_Controller extends Controller
|
|||||||
|
|
||||||
$postage = ORM::factory("postage_band", $id);
|
$postage = ORM::factory("postage_band", $id);
|
||||||
if (!$postage->loaded()) {
|
if (!$postage->loaded()) {
|
||||||
throw new Kohana_404_Exception();
|
kohana::show_404();
|
||||||
}
|
}
|
||||||
|
|
||||||
$form = postage_band::get_edit_form_admin($postage);
|
$form = postage_band::get_edit_form_admin($postage);
|
||||||
try {
|
$valid = $form->validate();
|
||||||
$valid = $form->validate();
|
if ($valid) {
|
||||||
$postage->name = $form->edit_postage->inputs["name"]->value;
|
$new_name = $form->edit_postage->inputs["name"]->value;
|
||||||
$postage->flat_rate = $form->edit_postage->flat_rate->value;
|
if ($new_name != $postage->name &&
|
||||||
$postage->per_item = $form->edit_postage->per_item->value;
|
ORM::factory("postage_band")
|
||||||
$postage->validate();
|
->where("name", "=", $new_name)
|
||||||
} catch (ORM_Validation_Exception $e) {
|
->where("id","!=", $postage->id)
|
||||||
// Translate ORM validation errors into form error messages
|
->find()
|
||||||
foreach ($e->validation->errors() as $key => $error) {
|
->loaded()) {
|
||||||
$form->edit_postage->inputs[$key]->add_error($error, 1);
|
$form->edit_postage->inputs["name"]->add_error("in_use", 1);
|
||||||
|
$valid = false;
|
||||||
|
} else {
|
||||||
|
$postage->name = $new_name;
|
||||||
}
|
}
|
||||||
$valid = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($valid) {
|
if ($valid) {
|
||||||
|
$postage->flat_rate = $form->edit_postage->flat_rate->value;
|
||||||
|
$postage->per_item = $form->edit_postage->per_item->value;
|
||||||
$postage->save();
|
$postage->save();
|
||||||
|
|
||||||
message::success(t("Changed postage band %postage_name",
|
message::success(t("Changed postage band %postage_name",
|
||||||
array("postage_name" => html::clean($postage->name))));
|
array("postage_name" => html::clean($postage->name))));
|
||||||
print json_encode(array("result" => "success"));
|
print json::reply(array("result" => "success"));
|
||||||
} else {
|
} else {
|
||||||
print json_encode(array("result" => "error", "form" => (string)$form));
|
print $form;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function edit_postage_band_form($id) {
|
public function edit_postage_band_form($id) {
|
||||||
$postage = ORM::factory("postage_band", $id);
|
$postage = ORM::factory("postage_band", $id);
|
||||||
if (!$postage->loaded()) {
|
if (!$postage->loaded()) {
|
||||||
throw new Kohana_404_Exception();
|
kohana::show_404();
|
||||||
}
|
}
|
||||||
|
|
||||||
$form = postage_band::get_edit_form_admin($postage);
|
$form = postage_band::get_edit_form_admin($postage);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php defined("SYSPATH") or die("No direct script access.");
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
/**
|
/**
|
||||||
* Gallery - a web based photo album viewer and editor
|
* Gallery - a web based photo album viewer and editor
|
||||||
* Copyright (C) 2000-2010 Bharat Mediratta
|
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -41,35 +41,35 @@ class Admin_Product_Lines_Controller extends Controller
|
|||||||
access::verify_csrf();
|
access::verify_csrf();
|
||||||
|
|
||||||
$form = product::get_add_form_admin();
|
$form = product::get_add_form_admin();
|
||||||
try {
|
$valid = $form->validate();
|
||||||
$valid = $form->validate();
|
$name = $form->add_product->inputs["name"]->value;
|
||||||
$product = ORM::factory("product");
|
$product = ORM::factory("product")->where("name", "=", $name)->find();
|
||||||
$product->name = $form->add_product->inputs["name"]->value;
|
if ($product->loaded()) {
|
||||||
$product->description = $form->add_product->description->value;
|
$form->add_product->inputs["name"]->add_error("in_use", 1);
|
||||||
$product->postage_band_id = $form->add_product->postage_band->value;
|
|
||||||
$product->validate();
|
|
||||||
} catch (ORM_Validation_Exception $e) {
|
|
||||||
// Translate ORM validation errors into form error messages
|
|
||||||
foreach ($e->validation->errors() as $key => $error) {
|
|
||||||
$form->add_product->inputs[$key]->add_error($error, 1);
|
|
||||||
}
|
|
||||||
$valid = false;
|
$valid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($valid) {
|
if ($valid) {
|
||||||
|
$product = product::create(
|
||||||
|
$name,
|
||||||
|
$form->add_product->cost->value,
|
||||||
|
$form->add_product->description->value,
|
||||||
|
$form->add_product->postage_band->value
|
||||||
|
);
|
||||||
|
|
||||||
$product->save();
|
$product->save();
|
||||||
message::success(t("Created product %product_name", array(
|
message::success(t("Created product %product_name", array(
|
||||||
"product_name" => html::clean($product->name))));
|
"product_name" => html::clean($product->name))));
|
||||||
print json_encode(array("result" => "success"));
|
print json::reply(array("result" => "success"));
|
||||||
} else {
|
} else {
|
||||||
print json_encode(array("result" => "error", "form" => (string)$form));
|
print $form;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delete_product_form($id) {
|
public function delete_product_form($id) {
|
||||||
$product = ORM::factory("product", $id);
|
$product = ORM::factory("product", $id);
|
||||||
if (!$product->loaded()) {
|
if (!$product->loaded()) {
|
||||||
throw new Kohana_404_Exception();
|
kohana::show_404();
|
||||||
}
|
}
|
||||||
print product::get_delete_form_admin($product);
|
print product::get_delete_form_admin($product);
|
||||||
}
|
}
|
||||||
@ -77,13 +77,9 @@ class Admin_Product_Lines_Controller extends Controller
|
|||||||
public function delete_product($id) {
|
public function delete_product($id) {
|
||||||
access::verify_csrf();
|
access::verify_csrf();
|
||||||
|
|
||||||
if ($id == user::active()->id || $id == user::guest()->id) {
|
|
||||||
access::forbidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
$product = ORM::factory("product", $id);
|
$product = ORM::factory("product", $id);
|
||||||
if (!$product->loaded()) {
|
if (!$product->loaded()) {
|
||||||
throw new Kohana_404_Exception();
|
kohana::show_404();
|
||||||
}
|
}
|
||||||
|
|
||||||
$form = product::get_delete_form_admin($product);
|
$form = product::get_delete_form_admin($product);
|
||||||
@ -91,14 +87,13 @@ class Admin_Product_Lines_Controller extends Controller
|
|||||||
$name = $product->name;
|
$name = $product->name;
|
||||||
$product->delete();
|
$product->delete();
|
||||||
} else {
|
} else {
|
||||||
print json_encode(array("result" => "error",
|
print $form;
|
||||||
"form" => $form->__toString()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$message = t("Deleted user %product_name", array("product_name" => html::clean($name)));
|
$message = t("Deleted user %product_name", array("product_name" => html::clean($name)));
|
||||||
log::success("user", $message);
|
log::success("user", $message);
|
||||||
message::success($message);
|
message::success($message);
|
||||||
print json_encode(array("result" => "success"));
|
print json::reply(array("result" => "success"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function edit_product($id) {
|
public function edit_product($id) {
|
||||||
@ -106,39 +101,44 @@ class Admin_Product_Lines_Controller extends Controller
|
|||||||
|
|
||||||
$product = ORM::factory("product", $id);
|
$product = ORM::factory("product", $id);
|
||||||
if (!$product->loaded()) {
|
if (!$product->loaded()) {
|
||||||
throw new Kohana_404_Exception();
|
kohana::show_404();
|
||||||
}
|
}
|
||||||
|
|
||||||
$form = product::get_edit_form_admin($product);
|
$form = product::get_edit_form_admin($product);
|
||||||
try {
|
$valid = $form->validate();
|
||||||
$valid = $form->validate();
|
if ($valid) {
|
||||||
$product->name = $form->edit_product->inputs["name"]->value;
|
$new_name = $form->edit_product->inputs["name"]->value;
|
||||||
$product->cost = $form->edit_product->cost->value;
|
if ($new_name != $product->name &&
|
||||||
$product->description = $form->edit_product->description->value;
|
ORM::factory("product")
|
||||||
$product->postage_band_id = $form->edit_product->postage_band->value;
|
->where("name", "=", $new_name)
|
||||||
$product->validate();
|
->where("id","!=", $product->id)
|
||||||
} catch (ORM_Validation_Exception $e) {
|
->find()
|
||||||
// Translate ORM validation errors into form error messages
|
->loaded()) {
|
||||||
foreach ($e->validation->errors() as $key => $error) {
|
$form->edit_product->inputs["name"]->add_error("in_use", 1);
|
||||||
$form->edit_product->inputs[$key]->add_error($error, 1);
|
$valid = false;
|
||||||
|
} else {
|
||||||
|
$product->name = $new_name;
|
||||||
}
|
}
|
||||||
$valid = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($valid) {
|
if ($valid) {
|
||||||
|
$product->cost = $form->edit_product->cost->value;
|
||||||
|
$product->description = $form->edit_product->description->value;
|
||||||
|
$product->postage_band_id = $form->edit_product->postage_band->value;
|
||||||
$product->save();
|
$product->save();
|
||||||
|
|
||||||
message::success(t("Changed product %product_name",
|
message::success(t("Changed product %product_name",
|
||||||
array("product_name" => html::clean($product->name))));
|
array("product_name" => html::clean($product->name))));
|
||||||
print json_encode(array("result" => "success"));
|
print json::reply(array("result" => "success"));
|
||||||
} else {
|
} else {
|
||||||
print json_encode(array("result" => "error", "form" => (string)$form));
|
print $form;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function edit_product_form($id) {
|
public function edit_product_form($id) {
|
||||||
$product = ORM::factory("product", $id);
|
$product = ORM::factory("product", $id);
|
||||||
if (!$product->loaded()) {
|
if (!$product->loaded()) {
|
||||||
throw new Kohana_404_Exception();
|
kohana::show_404();
|
||||||
}
|
}
|
||||||
|
|
||||||
$form = product::get_edit_form_admin($product);
|
$form = product::get_edit_form_admin($product);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php defined("SYSPATH") or die("No direct script access.");
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
/**
|
/**
|
||||||
* Gallery - a web based photo album viewer and editor
|
* Gallery - a web based photo album viewer and editor
|
||||||
* Copyright (C) 2000-2010 Bharat Mediratta
|
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -19,19 +19,173 @@
|
|||||||
*/
|
*/
|
||||||
class Basket_Controller extends Controller {
|
class Basket_Controller extends Controller {
|
||||||
|
|
||||||
public function view_basket() {
|
public function temp(){
|
||||||
|
$db = Database::instance();
|
||||||
|
$db->query("ALTER TABLE {orders} ADD COLUMN `method` int(9) DEFAULT 0;");
|
||||||
|
}
|
||||||
|
public function view_basket($pp="") {
|
||||||
|
|
||||||
$template = new Theme_View("page.html", "other", "basket");
|
$template = new Theme_View("page.html", "basket");
|
||||||
|
|
||||||
|
$basket = Session_Basket::get();
|
||||||
|
if (isset($pp)){
|
||||||
|
if ($pp=="nopp"){
|
||||||
|
$basket->disablepp();
|
||||||
|
}
|
||||||
|
elseif ($pp=="ppon"){
|
||||||
|
$basket->enablepp();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$view = new View("view_basket.html");
|
$view = new View("view_basket.html");
|
||||||
$view->basket = Session_Basket::get();
|
$view->basket = $basket;
|
||||||
|
|
||||||
|
|
||||||
$template->content = $view;
|
$template->content = $view;
|
||||||
|
|
||||||
print $template;
|
print $template;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getCheckoutForm(){
|
public function preview($id) {
|
||||||
|
$item = ORM::factory("item", $id);
|
||||||
|
|
||||||
|
print "<img src='".$item->resize_url()."'></img>";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function view_orders() {
|
||||||
|
self::check_view_orders();
|
||||||
|
$template = new Theme_View("page.html", "basket");
|
||||||
|
|
||||||
|
$incomplete_orders = ORM::factory("order")->where('status',"<",20)->find_all();
|
||||||
|
|
||||||
|
$view = new View("view_orders.html");
|
||||||
|
|
||||||
|
$view->orders = $incomplete_orders;
|
||||||
|
|
||||||
|
$template->content = $view;
|
||||||
|
|
||||||
|
print $template;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function view_ipn($orderid){
|
||||||
|
self::check_view_orders();
|
||||||
|
|
||||||
|
$template = new Theme_View("page.html", "basket");
|
||||||
|
|
||||||
|
$order = ORM::factory("order")->where("id","=",$orderid)->find();
|
||||||
|
$ipn_messages = ORM::factory("ipn_message")->where("key","=",$orderid)->find_all();
|
||||||
|
//$ipn_messages = ORM::factory("ipn_message")->find_all();
|
||||||
|
|
||||||
|
$view = new View("view_ipn.html");
|
||||||
|
|
||||||
|
$view->order = $order;
|
||||||
|
$view->ipn_messages = $ipn_messages;
|
||||||
|
|
||||||
|
$template->content = $view;
|
||||||
|
|
||||||
|
print $template;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function check_view_orders() {
|
||||||
|
if (!basket::can_view_orders()){
|
||||||
|
die("Invalid access.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function print_order($id){
|
||||||
|
|
||||||
|
access::verify_csrf();
|
||||||
|
self::check_view_orders();
|
||||||
|
|
||||||
|
|
||||||
|
$prefix = basket::getOrderPrefix();
|
||||||
|
$length = strlen($prefix);
|
||||||
|
if (strlen($id)>$length ){
|
||||||
|
if ($prefix === strtolower(substr($id,0,$length ))){
|
||||||
|
$id = substr($id,$length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$order = ORM::factory("order", $id);
|
||||||
|
$view = new View("print_order.html");
|
||||||
|
|
||||||
|
if ($order->loaded()){
|
||||||
|
$view->order = str_replace(array("\r\n", "\n", "\r"),"<br/>",$order->text);
|
||||||
|
}else{
|
||||||
|
$view->order = "Order ".$id." not found.";
|
||||||
|
}
|
||||||
|
print $view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show_order($id){
|
||||||
|
|
||||||
|
access::verify_csrf();
|
||||||
|
self::check_view_orders();
|
||||||
|
$prefix = basket::getOrderPrefix();
|
||||||
|
$length = strlen($prefix);
|
||||||
|
if (strlen($id)>$length ){
|
||||||
|
if ($prefix === strtolower(substr($id,0,$length ))){
|
||||||
|
$id = substr($id,$length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$order = ORM::factory("order", $id);
|
||||||
|
|
||||||
|
if ($order->loaded()){
|
||||||
|
$view = new View("view_order.html");
|
||||||
|
$view->order = $order;
|
||||||
|
print $view;
|
||||||
|
}else{
|
||||||
|
print "Order ".$id." not found.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show_ipn($id){
|
||||||
|
access::verify_csrf();
|
||||||
|
self::check_view_orders();
|
||||||
|
$ipn_message = ORM::factory("ipn_message", $id);
|
||||||
|
|
||||||
|
if ($ipn_message->loaded()){
|
||||||
|
print $ipn_message->text;
|
||||||
|
}else{
|
||||||
|
print "IPN Message ".$id." not found.";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function confirm_order_delivery($id){
|
||||||
|
access::verify_csrf();
|
||||||
|
self::check_view_orders();
|
||||||
|
$order = ORM::factory("order", $id);
|
||||||
|
|
||||||
|
if ($order->loaded()){
|
||||||
|
if ($order->status == 2)
|
||||||
|
{
|
||||||
|
$order->status = 20;
|
||||||
|
$order->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
url::redirect("basket/view_orders");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function confirm_order_payment($id){
|
||||||
|
access::verify_csrf();
|
||||||
|
self::check_view_orders();
|
||||||
|
$order = ORM::factory("order", $id);
|
||||||
|
|
||||||
|
if ($order->loaded()){
|
||||||
|
if ($order->status == 1)
|
||||||
|
{
|
||||||
|
$order->status = 2;
|
||||||
|
$order->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
url::redirect("basket/view_orders");
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getCheckoutForm(){
|
||||||
$form = new Forge("basket/confirm", "", "post", array("id" => "checkout", "name" =>"checkout"));
|
$form = new Forge("basket/confirm", "", "post", array("id" => "checkout", "name" =>"checkout"));
|
||||||
$group = $form->group("contact")->label(t("Contact Details"));
|
$group = $form->group("contact")->label(t("Contact Details"));
|
||||||
$group->input("fullname")->label(t("Name"))->id("fullname");
|
$group->input("fullname")->label(t("Name"))->id("fullname");
|
||||||
@ -42,13 +196,14 @@ class Basket_Controller extends Controller {
|
|||||||
$group->input("postcode")->label(t("Postcode"))->id("postcode");
|
$group->input("postcode")->label(t("Postcode"))->id("postcode");
|
||||||
$group->input("email")->label(t("E-Mail Address"))->id("email");
|
$group->input("email")->label(t("E-Mail Address"))->id("email");
|
||||||
$group->input("phone")->label(t("Telephone Number"))->id("phone");
|
$group->input("phone")->label(t("Telephone Number"))->id("phone");
|
||||||
|
$group->hidden("paypal")->id("paypal");
|
||||||
|
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function checkout () {
|
public function checkout () {
|
||||||
|
|
||||||
$template = new Theme_View("page.html", "other", "basket");
|
$template = new Theme_View("page.html", "basket");
|
||||||
|
|
||||||
$view = new View("checkout.html");
|
$view = new View("checkout.html");
|
||||||
|
|
||||||
@ -80,6 +235,12 @@ class Basket_Controller extends Controller {
|
|||||||
|
|
||||||
if ($valid){
|
if ($valid){
|
||||||
$basket = Session_Basket::get();
|
$basket = Session_Basket::get();
|
||||||
|
|
||||||
|
if (!isset($basket->contents ) || count($basket->contents) == 0) {
|
||||||
|
self::view_basket();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$basket->name = $form->contact->fullname->value;
|
$basket->name = $form->contact->fullname->value;
|
||||||
$basket->house = $form->contact->house->value;
|
$basket->house = $form->contact->house->value;
|
||||||
$basket->street = $form->contact->street->value;
|
$basket->street = $form->contact->street->value;
|
||||||
@ -89,14 +250,33 @@ class Basket_Controller extends Controller {
|
|||||||
$basket->email = $form->contact->email->value;
|
$basket->email = $form->contact->email->value;
|
||||||
$basket->phone = $form->contact->phone->value;
|
$basket->phone = $form->contact->phone->value;
|
||||||
|
|
||||||
$template = new Theme_View("page.html", "other", "basket");
|
$paypal=$form->contact->paypal->value=="true";
|
||||||
|
$template = new Theme_View("page.html", "basket");
|
||||||
|
|
||||||
$form = new Forge("basket/complete", "", "post", array("id" => "confirm", "name" =>"confirm"));
|
if ($paypal){
|
||||||
$view = new View("confirm_order.html");
|
// create a prelimary order
|
||||||
$view->basket = $basket;
|
$order = basket::createOrder($basket, Order_Model::PAYMENT_PAYPAL);
|
||||||
$template->content = $view;
|
$paypal = new Paypal();
|
||||||
$view->form = $form;
|
|
||||||
print $template;
|
// create the order first
|
||||||
|
$view = new View("paypal_redirect.html");
|
||||||
|
$view ->form = $paypal->process($basket,
|
||||||
|
url::site("basket/paypal_complete/$order->id", "http"),
|
||||||
|
url::site("basket/paypal_cancel/$order->id", "http"),
|
||||||
|
url::site("basket/paypal_ipn/$order->id", "http"));
|
||||||
|
$template->content = $view;
|
||||||
|
print $template;
|
||||||
|
|
||||||
|
// redirect to paypal
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
$form = new Forge("basket/complete", "", "post", array("id" => "confirm", "name" =>"confirm"));
|
||||||
|
$view = new View("confirm_order.html");
|
||||||
|
$view->basket = $basket;
|
||||||
|
$template->content = $view;
|
||||||
|
$view->form = $form;
|
||||||
|
print $template;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -105,65 +285,92 @@ class Basket_Controller extends Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function complete () {
|
function paypal_ipn($id){
|
||||||
access::verify_csrf();
|
$order = ORM::factory("order")->where("id","=",$id)->find();
|
||||||
|
if ($order->loaded()){
|
||||||
|
|
||||||
|
$paypal = new Paypal();
|
||||||
|
|
||||||
|
if ($paypal->validate_ipn($id)){
|
||||||
|
if ($paypal->ipn_data['payment_status'] == "Completed"){
|
||||||
|
|
||||||
|
$order->status = Order_Model::PAYMENT_CONFIRMED;
|
||||||
|
|
||||||
|
// send e-mails
|
||||||
|
basket::send_order($order);
|
||||||
|
basket::send_invoice($order);
|
||||||
|
|
||||||
|
$order->save();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
print "invalid access. tut tut!";
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function paypal_complete($id) {
|
||||||
|
$order = ORM::factory("order")->where("id","=",$id)->find();
|
||||||
$basket = Session_Basket::get();
|
$basket = Session_Basket::get();
|
||||||
|
$basket->clear();
|
||||||
|
$this->_complete($order);
|
||||||
|
}
|
||||||
|
|
||||||
//$admin_address = basket::getEmailAddress();
|
public function paypal_cancel($id){
|
||||||
$postage = $basket->postage_cost();
|
$order = ORM::factory("order")->where("id","=",$id)->find();
|
||||||
$product_cost = $basket->cost();
|
|
||||||
|
|
||||||
$admin_email = "Order for :
|
if ($order->loaded()){
|
||||||
".$basket->name."
|
$order->delete();
|
||||||
".$basket->house."
|
|
||||||
".$basket->street."
|
|
||||||
".$basket->suburb."
|
|
||||||
".$basket->town."
|
|
||||||
".$basket->postcode."
|
|
||||||
".$basket->email."
|
|
||||||
".$basket->phone."
|
|
||||||
Placed at ".date("d F Y - H:i" ,time())."
|
|
||||||
Cost of Ordered Products = ".$product_cost."
|
|
||||||
Postage and Packaging Costs + ".$postage."
|
|
||||||
Total Owed ".($product_cost+$postage)." Total in ".basket::getCurrency()."
|
|
||||||
|
|
||||||
Items Ordered:
|
|
||||||
|
|
||||||
";
|
|
||||||
|
|
||||||
// create the order items
|
|
||||||
foreach ($basket->contents as $basket_item){
|
|
||||||
$item = $basket_item->getItem();
|
|
||||||
$prod = ORM::factory("product", $basket_item->product);
|
|
||||||
$admin_email = $admin_email."
|
|
||||||
".$item->title." - ".$item->url()."
|
|
||||||
".$prod->name." - ".$prod->description."
|
|
||||||
".$basket_item->quantity." @ ".$prod->cost."
|
|
||||||
|
|
||||||
";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->checkout();
|
||||||
|
}
|
||||||
|
|
||||||
$from = "From: ".basket::getEmailAddress();
|
public function complete () {
|
||||||
mail(basket::getEmailAddress(), "Order from ".$basket->name, $admin_email, $from);
|
access::verify_csrf();
|
||||||
|
|
||||||
|
$basket = Session_Basket::get();
|
||||||
|
|
||||||
|
if (!isset($basket->contents ) || count($basket->contents) == 0) {
|
||||||
|
self::view_basket();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// create order
|
||||||
|
$order = basket::createOrder($basket, Order_Model::PAYMENT_OFFLINE);
|
||||||
$basket->clear();
|
$basket->clear();
|
||||||
|
|
||||||
$template = new Theme_View("page.html", "other", "basket");
|
// send e-mails
|
||||||
|
basket::send_order($order);
|
||||||
|
basket::send_invoice($order);
|
||||||
|
|
||||||
|
|
||||||
|
$this->_complete($order);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function _complete($order){
|
||||||
|
$template = new Theme_View("page.html", "basket");
|
||||||
$view = new View("order_complete.html");
|
$view = new View("order_complete.html");
|
||||||
|
$ordernumber = basket::getOrderPrefix().$order->id;
|
||||||
|
$view->ordernumber = $ordernumber;
|
||||||
|
$view->order = $order;
|
||||||
|
$view->total_cost = $order->cost;
|
||||||
|
|
||||||
$template->content = $view;
|
$template->content = $view;
|
||||||
|
|
||||||
print $template;
|
print $template;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getAddToBasketForm($id){
|
private function getAddToBasketForm($id){
|
||||||
|
|
||||||
$form = new Forge("basket/add_to_basket", "", "post", array("id" => "g-add-to-basket-form"));
|
$form = new Forge("basket/add_to_basket", "", "post", array("id" => "gAddToBasketForm"));
|
||||||
$group = $form->group("add_to_basket")->label(t("Add To Basket"));
|
$group = $form->group("add_to_basket")->label(t("Add To Basket"));
|
||||||
$group->hidden("id");
|
$group->hidden("id");
|
||||||
$group->dropdown("product")
|
$group->dropdown("product")
|
||||||
->label(t("Product"))
|
->label(t("Product"))
|
||||||
->options(product::getProductArray($id));
|
->options(product::getProductArray($id));
|
||||||
$group->input("quantity")->label(t("Quantity"))->id("g-quantity");
|
$group->input("quantity")->label(t("Quantity"))->id("gQuantity");
|
||||||
$group->submit("")->value(t("Add"));
|
$group->submit("")->value(t("Add"));
|
||||||
//$group->submit("proceedToCheckout")->value(t("Proceed To Checkout"));
|
//$group->submit("proceedToCheckout")->value(t("Proceed To Checkout"));
|
||||||
|
|
||||||
@ -189,7 +396,11 @@ Items Ordered:
|
|||||||
$form->add_to_basket->product->value,
|
$form->add_to_basket->product->value,
|
||||||
$form->add_to_basket->quantity->value);
|
$form->add_to_basket->quantity->value);
|
||||||
|
|
||||||
print json_encode(array("result" => "success"));
|
$item = ORM::factory("item", $form->add_to_basket->id->value);
|
||||||
|
|
||||||
|
Session::instance()->set("redirect_home", $item->parent_id);
|
||||||
|
|
||||||
|
print json::reply(array("result" => "success"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,17 @@
|
|||||||
#basket {float:right;}
|
#basket {float:right;}
|
||||||
#add_to_basket {float:right}
|
#add_to_basket {float:right}
|
||||||
#basketForm {max-width:200px}
|
#basketForm {max-width:200px;float:left;}
|
||||||
#basketThumb {float:left; padding:10px 10px 0 0;}
|
#basketThumb {float:left; padding:10px;}
|
||||||
#basketThumb img{max-width:100px;}
|
#basketThumb img{max-width:100px;}
|
||||||
|
#payment {float:right; width:50%}
|
||||||
|
#checkout input,
|
||||||
|
#checkout select,
|
||||||
|
#checkout textarea {
|
||||||
|
display: block;
|
||||||
|
clear: both;
|
||||||
|
padding: .2em;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
#sidebar-basket {max-height:300px; overflow-y:auto; overflow-x:hidden;}
|
||||||
|
.order-status-1 a{color:#AA0000 !important}
|
||||||
|
.order-status-2 a{color:#00AA00 !important}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Gallery - a web based photo album viewer and editor
|
* Gallery - a web based photo album viewer and editor
|
||||||
* Copyright (C) 2000-2010 Bharat Mediratta
|
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -40,6 +40,26 @@ class basket_Core {
|
|||||||
"MXN" => "Mexican Peso");
|
"MXN" => "Mexican Peso");
|
||||||
|
|
||||||
static $format= array(
|
static $format= array(
|
||||||
|
"AUD" => "$",
|
||||||
|
"CAD" => "$",
|
||||||
|
"EUR" => "€",
|
||||||
|
"GBP" => "£",
|
||||||
|
"JPY" => "¥",
|
||||||
|
"USD" => "$",
|
||||||
|
"NZD" => "$",
|
||||||
|
"CHF" => "",
|
||||||
|
"HKD" => "$",
|
||||||
|
"SGD" => "$",
|
||||||
|
"SEK" => "",
|
||||||
|
"DKK" => "",
|
||||||
|
"PLN" => "",
|
||||||
|
"NOK" => "",
|
||||||
|
"HUF" => "",
|
||||||
|
"CZK" => "",
|
||||||
|
"ILS" => "",
|
||||||
|
"MXN" => "");
|
||||||
|
|
||||||
|
static $formatweb= array(
|
||||||
"AUD" => "$",
|
"AUD" => "$",
|
||||||
"CAD" => "$",
|
"CAD" => "$",
|
||||||
"EUR" => "€",
|
"EUR" => "€",
|
||||||
@ -60,37 +80,108 @@ class basket_Core {
|
|||||||
"MXN" => "");
|
"MXN" => "");
|
||||||
|
|
||||||
|
|
||||||
static function get_configure_form() {
|
static public function can_view_orders()
|
||||||
|
{
|
||||||
|
if (identity::active_user()->admin){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
print identity::active_user();
|
||||||
|
foreach (identity::active_user()->groups() as $group){
|
||||||
|
if ($group->name == 'shop'){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static function get_configure_form() {
|
||||||
$form = new Forge("admin/configure", "", "post", array("id" => "g-configure-form"));
|
$form = new Forge("admin/configure", "", "post", array("id" => "g-configure-form"));
|
||||||
$group = $form->group("configure")->label(t("Configure Basket"));
|
$group = $form->group("configure")->label(t("Configure Basket"));
|
||||||
$group->input("email")->label(t("Offline Paying Email Address"))->id("g-order-email-address");
|
$group->input("email")->label(t("Offline Paying Email Address"))->id("g-order-email-address");
|
||||||
$group->dropdown("currency")
|
$group->dropdown("currency")
|
||||||
->label(t("Currency"))
|
->label(t("Currency"))
|
||||||
->options(self::$currencies);
|
->options(self::$currencies);
|
||||||
|
|
||||||
|
$group->checkbox("side_bar")->label(t("Use only side bar"))->id("g-side-bar-only");
|
||||||
|
|
||||||
$group->checkbox("paypal")->label(t("Use Paypal"))->id("g-paypal");
|
$group->checkbox("paypal")->label(t("Use Paypal"))->id("g-paypal");
|
||||||
$group->input("paypal_account")->label(t("Paypal E-Mail Address"))->id("g-paypal-address");
|
$group->input("paypal_account")->label(t("Paypal E-Mail Address"))->id("g-paypal-address");
|
||||||
|
$group->checkbox("allow_pickup")->label(t("Allow Product Pickup"))->id("g-allow-pickup");
|
||||||
|
$group->input("order_prefix")->label(t("Order Number Prefix"))->id("g-order-prefix");
|
||||||
|
$group->submit("")->value(t("Save"));
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
|
||||||
|
static function get_template_form() {
|
||||||
|
$form = new Forge("admin/configure/templates", "", "post", array("id" => "g-configure-form"));
|
||||||
|
$group = $form->group("configure")->label(t("Configure Basket"));
|
||||||
|
$group->textarea("payment_details")->label(t("Payment Details Description"))->id("g-payment-details");
|
||||||
|
$group->textarea("order_complete_page")->label(t("Order Complete Page"))->id("g-order-complete_page");
|
||||||
|
$group->input("order_complete_email_subject")->label(t("Order Complete Email Subject"))->id("g-order-complete_email_subject");
|
||||||
|
$group->textarea("order_complete_email")->label(t("Order Complete Email"))->id("g-order-complete_email");
|
||||||
$group->submit("")->value(t("Save"));
|
$group->submit("")->value(t("Save"));
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function populateForm($form){
|
static function populateForm($form){
|
||||||
$form->configure->email->value(basket::getEmailAddress());
|
$form->configure->email->value(basket::getEmailAddress());
|
||||||
$form->configure->paypal->checked(basket::isPaypal());
|
$form->configure->side_bar->checked(basket::is_side_bar_only());
|
||||||
$form->configure->paypal_account->value(basket::getPaypalAccount());
|
$form->configure->paypal->checked(basket::isPaypal());
|
||||||
$form->configure->currency->selected(basket::getCurrency());
|
$form->configure->paypal_account->value(basket::getPaypalAccount());
|
||||||
|
$form->configure->currency->selected(basket::getCurrency());
|
||||||
|
$form->configure->allow_pickup->checked(basket::isAllowPickup());
|
||||||
|
$form->configure->order_prefix->value(basket::getOrderPrefix());
|
||||||
|
}
|
||||||
|
|
||||||
|
static function populateTemplateForm($form){
|
||||||
|
$form->configure->payment_details->value(basket::getPaymentDetails());
|
||||||
|
$form->configure->order_complete_page->value(basket::getOrderCompletePage());
|
||||||
|
$form->configure->order_complete_email_subject->value(basket::getOrderCompleteEmailSubject());
|
||||||
|
$form->configure->order_complete_email->value(basket::getOrderCompleteEmail());
|
||||||
}
|
}
|
||||||
|
|
||||||
static function extractForm($form){
|
static function extractForm($form){
|
||||||
$email = $form->configure->email->value;
|
$email = $form->configure->email->value;
|
||||||
$isPaypal = $form->configure->paypal->value;
|
$is_side_bar = $form->configure->side_bar->value;
|
||||||
$paypal_account = $form->configure->paypal_account->value;
|
$isPaypal = $form->configure->paypal->value;
|
||||||
$currency = $form->configure->currency->selected;
|
$paypal_account = $form->configure->paypal_account->value;
|
||||||
basket::setEmailAddress($email);
|
$currency = $form->configure->currency->selected;
|
||||||
basket::setPaypal($isPaypal);
|
$allow_pickup = $form->configure->allow_pickup->value;
|
||||||
basket::setPaypalAccount($paypal_account);
|
$order_prefix = $form->configure->order_prefix->value;
|
||||||
basket::setCurrency($currency);
|
basket::setEmailAddress($email);
|
||||||
|
basket::set_side_bar_only($is_side_bar);
|
||||||
|
basket::setPaypal($isPaypal);
|
||||||
|
basket::setPaypalAccount($paypal_account);
|
||||||
|
basket::setCurrency($currency);
|
||||||
|
basket::setAllowPickup($allow_pickup);
|
||||||
|
basket::setOrderPrefix($order_prefix);
|
||||||
}
|
}
|
||||||
|
static function extractTemplateForm($form){
|
||||||
|
$payment_details = $form->configure->payment_details->value;
|
||||||
|
$order_complete_page = $form->configure->order_complete_page->value;
|
||||||
|
$order_complete_email_subject = $form->configure->order_complete_email_subject->value;
|
||||||
|
$order_complete_email = $form->configure->order_complete_email->value;
|
||||||
|
basket::setPaymentDetails($payment_details);
|
||||||
|
basket::setOrderCompletePage($order_complete_page);
|
||||||
|
basket::setOrderCompleteEmailSubject($order_complete_email_subject);
|
||||||
|
basket::setOrderCompleteEmail($order_complete_email);
|
||||||
|
}
|
||||||
|
|
||||||
|
static public function is_side_bar_only()
|
||||||
|
{
|
||||||
|
return module::get_var("basket","is_side_bar_only");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static public function set_side_bar_only($value)
|
||||||
|
{
|
||||||
|
module::set_var("basket","is_side_bar_only",$value);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static function getEmailAddress(){
|
static function getEmailAddress(){
|
||||||
return module::get_var("basket","email");
|
return module::get_var("basket","email");
|
||||||
@ -113,10 +204,51 @@ class basket_Core {
|
|||||||
return $cur;
|
return $cur;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function getPaymentDetails(){
|
||||||
|
return module::get_var("basket","payment_details");
|
||||||
|
}
|
||||||
|
|
||||||
|
static function getOrderPrefix(){
|
||||||
|
return module::get_var("basket","order_prefix");
|
||||||
|
}
|
||||||
|
|
||||||
|
static function isAllowPickup(){
|
||||||
|
return module::get_var("basket","allow_pickup");
|
||||||
|
}
|
||||||
|
|
||||||
|
static function getOrderCompletePage(){
|
||||||
|
return module::get_var("basket","order_complete_page");
|
||||||
|
}
|
||||||
|
|
||||||
|
static function getOrderCompleteEmail(){
|
||||||
|
return module::get_var("basket","order_complete_email");
|
||||||
|
}
|
||||||
|
|
||||||
|
static function getOrderCompleteEmailSubject(){
|
||||||
|
return module::get_var("basket","order_complete_email_subject");
|
||||||
|
}
|
||||||
|
|
||||||
static function formatMoney($money){
|
static function formatMoney($money){
|
||||||
return self::$format[self::getCurrency()].number_format($money,2);
|
return self::$format[self::getCurrency()].number_format($money,2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function formatMoneyForWeb($money){
|
||||||
|
return self::$formatweb[self::getCurrency()].number_format($money,2);
|
||||||
|
}
|
||||||
|
|
||||||
|
static function replaceStrings($string, $key_values) {
|
||||||
|
// Replace x_y before replacing x.
|
||||||
|
krsort($key_values, SORT_STRING);
|
||||||
|
|
||||||
|
$keys = array();
|
||||||
|
$values = array();
|
||||||
|
foreach ($key_values as $key => $value) {
|
||||||
|
$keys[] = "%$key";
|
||||||
|
$values[] = $value;
|
||||||
|
}
|
||||||
|
return str_replace($keys, $values, $string);
|
||||||
|
}
|
||||||
|
|
||||||
static function setEmailAddress($email){
|
static function setEmailAddress($email){
|
||||||
module::set_var("basket","email",$email);
|
module::set_var("basket","email",$email);
|
||||||
}
|
}
|
||||||
@ -133,32 +265,129 @@ class basket_Core {
|
|||||||
module::set_var("basket","currency",$currency);
|
module::set_var("basket","currency",$currency);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function generatePaypalForm($session_basket){
|
static function setPaymentDetails($details){
|
||||||
$form = "
|
module::set_var("basket","payment_details",$details);
|
||||||
<form action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\" name=\"paypal_form\">
|
}
|
||||||
<input type=\"hidden\" name=\"cmd\" value=\"_cart\"/>
|
|
||||||
<input type=\"hidden\" name=\"upload\" value=\"1\"/>
|
|
||||||
<input type=\"hidden\" name=\"currency_code\" value=\"".self::getCurrency()."\">
|
|
||||||
<input type=\"hidden\" name=\"business\" value=\"".self::getPaypalAccount()."\"/>";
|
|
||||||
|
|
||||||
$postage = $session_basket->postage_cost();
|
static function setAllowPickup($allow_pickup){
|
||||||
if ($postage > 0) {
|
module::set_var("basket","allow_pickup",$allow_pickup);
|
||||||
$form = $form."
|
}
|
||||||
<input type=\"hidden\" name=\"shipping_1\" value=\"".$postage."\">";
|
|
||||||
|
static function setOrderPrefix($order_prefix){
|
||||||
|
module::set_var("basket","order_prefix",strtolower($order_prefix));
|
||||||
|
}
|
||||||
|
|
||||||
|
static function setOrderCompletePage($details){
|
||||||
|
module::set_var("basket","order_complete_page",$details);
|
||||||
|
}
|
||||||
|
|
||||||
|
static function setOrderCompleteEmail($details){
|
||||||
|
module::set_var("basket","order_complete_email",$details);
|
||||||
|
}
|
||||||
|
|
||||||
|
static function setOrderCompleteEmailSubject($details){
|
||||||
|
module::set_var("basket","order_complete_email_subject",$details);
|
||||||
|
}
|
||||||
|
|
||||||
|
static function createOrder($basket, $method){
|
||||||
|
|
||||||
|
$order = ORM::factory("order");
|
||||||
|
$order->text = "processing";
|
||||||
|
$order->save();
|
||||||
|
|
||||||
|
$ordernumber = basket::getOrderPrefix().$order->id;
|
||||||
|
|
||||||
|
//$admin_address = basket::getEmailAddress();
|
||||||
|
$postage = $basket->postage_cost();
|
||||||
|
$product_cost = $basket->cost();
|
||||||
|
$ppon = $basket->ispp();
|
||||||
|
|
||||||
|
$text = "
|
||||||
|
Order Number : ".$ordernumber."
|
||||||
|
|
||||||
|
for :
|
||||||
|
".$basket->name."
|
||||||
|
".$basket->house."
|
||||||
|
".$basket->street."
|
||||||
|
".$basket->suburb."
|
||||||
|
".$basket->town."
|
||||||
|
".$basket->postcode."
|
||||||
|
".$basket->email."
|
||||||
|
".$basket->phone."
|
||||||
|
Placed at ".date("d F Y - H:i" ,time())."
|
||||||
|
Cost of Ordered Products = ".$product_cost;
|
||||||
|
if ($ppon){
|
||||||
|
$text = $text."
|
||||||
|
Postage and Packaging Costs + ".$postage."
|
||||||
|
Total Owed ".($product_cost+$postage)." Total in ".basket::getCurrency();
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$text = $text."
|
||||||
|
Person has chosen to pick up product.
|
||||||
|
Total Owed ".($product_cost)." Total in ".basket::getCurrency();
|
||||||
|
}
|
||||||
|
$text = $text."
|
||||||
|
|
||||||
|
Items Ordered:
|
||||||
|
|
||||||
|
";
|
||||||
|
|
||||||
|
// create the order items
|
||||||
|
foreach ($basket->contents as $basket_item){
|
||||||
|
$item = $basket_item->getItem();
|
||||||
|
$prod = ORM::factory("product", $basket_item->product);
|
||||||
|
$text = $text."
|
||||||
|
".$item->title." - ".$item->url()."
|
||||||
|
".$prod->name." - ".$prod->description."
|
||||||
|
".$basket_item->quantity." @ ".$prod->cost."
|
||||||
|
|
||||||
|
";
|
||||||
}
|
}
|
||||||
|
|
||||||
$id = 1;
|
if ($ppon){
|
||||||
foreach ($session_basket->contents as $key => $basket_item){
|
$total_cost = ($product_cost+$postage);
|
||||||
$form = $form."
|
}
|
||||||
<input type=\"hidden\" name=\"item_name_$id\" value=\"".$basket_item->getCode()."\"/>
|
else{
|
||||||
<input type=\"hidden\" name=\"amount_$id\" value=\"$basket_item->cost_per\"/>
|
$total_cost = $product_cost;
|
||||||
<input type=\"hidden\" name=\"quantity_$id\" value=\"$basket_item->quantity\"/>";
|
|
||||||
$id++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$form = $form."</form>";
|
$order->name = $basket->name;
|
||||||
|
$order->email = $basket->email;
|
||||||
|
$order->cost = $total_cost;
|
||||||
|
$order->text = $text;
|
||||||
|
$order->status = Order_Model::WAITING_PAYMENT;
|
||||||
|
$order->method = $method;
|
||||||
|
$order->save();
|
||||||
|
|
||||||
|
//$basket->clear();
|
||||||
|
|
||||||
|
return $order;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function send_order($order){
|
||||||
|
|
||||||
|
$from = "From: ".basket::getEmailAddress();
|
||||||
|
$ordernumber = basket::getOrderPrefix().$order->id;
|
||||||
|
|
||||||
|
mail(basket::getEmailAddress(), "Order ".$ordernumber." from ".$order->name, $order->text, $from);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function send_invoice($order)
|
||||||
|
{
|
||||||
|
|
||||||
|
$from = "From: ".basket::getEmailAddress();
|
||||||
|
$ordernumber = basket::getOrderPrefix().$order->id;
|
||||||
|
$invoice_email = basket::replaceStrings(basket::getOrderCompleteEmail(),Array(
|
||||||
|
"name"=>$order->name,
|
||||||
|
"order_number"=> $ordernumber,
|
||||||
|
"total_cost" =>basket::formatMoney($order->cost),
|
||||||
|
"order_details"=>$order->text));
|
||||||
|
|
||||||
|
mail($order->email,
|
||||||
|
basket::replaceStrings(basket::getOrderCompleteEmailSubject(),Array("order_number"=>$ordernumber)),
|
||||||
|
$invoice_email, $from);
|
||||||
|
|
||||||
return $form;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
21
modules/basket/helpers/basket_block.php
Normal file
21
modules/basket/helpers/basket_block.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
|
|
||||||
|
class basket_block_Core {
|
||||||
|
static function get_site_list() {
|
||||||
|
return array("shopping" => t("Basket"));
|
||||||
|
}
|
||||||
|
|
||||||
|
static function get($block_id, $theme) {
|
||||||
|
$block = "";
|
||||||
|
switch ($block_id) {
|
||||||
|
case "shopping":
|
||||||
|
$block = new Block();
|
||||||
|
$block->css_id = "g-view-basket";
|
||||||
|
$block->title = t("Basket");
|
||||||
|
$block->content = new View("basket-side-bar.html");
|
||||||
|
$block->content->basket = Session_Basket::get();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return $block;
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
<?php defined("SYSPATH") or die("No direct script access.");
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
/**
|
/**
|
||||||
* Gallery - a web based photo album viewer and editor
|
* Gallery - a web based photo album viewer and editor
|
||||||
* Copyright (C) 2000-2010 Bharat Mediratta
|
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -34,6 +34,11 @@ class basket_event_Core{
|
|||||||
->label(t("Configure"))
|
->label(t("Configure"))
|
||||||
->url(url::site("admin/configure")));
|
->url(url::site("admin/configure")));
|
||||||
$basket_menu->append(
|
$basket_menu->append(
|
||||||
|
Menu::factory("link")
|
||||||
|
->id("templates")
|
||||||
|
->label(t("Templates"))
|
||||||
|
->url(url::site("admin/configure/templates")));
|
||||||
|
$basket_menu->append(
|
||||||
Menu::factory("link")
|
Menu::factory("link")
|
||||||
->id("product_line")
|
->id("product_line")
|
||||||
->label(t("Product Lines"))
|
->label(t("Product Lines"))
|
||||||
@ -43,6 +48,11 @@ class basket_event_Core{
|
|||||||
->id("postage_bands")
|
->id("postage_bands")
|
||||||
->label(t("Postage Bands"))
|
->label(t("Postage Bands"))
|
||||||
->url(url::site("admin/postage_bands")));
|
->url(url::site("admin/postage_bands")));
|
||||||
|
$basket_menu->append(
|
||||||
|
Menu::factory("link")
|
||||||
|
->id("view_orders")
|
||||||
|
->label(t("View Orders"))
|
||||||
|
->url(url::site("basket/view_orders")));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,8 +75,8 @@ class basket_event_Core{
|
|||||||
|
|
||||||
if ($product_override->loaded()){
|
if ($product_override->loaded()){
|
||||||
$item_product = ORM::factory("item_product")
|
$item_product = ORM::factory("item_product")
|
||||||
->where('product_override_id', "=", $product_override->id)
|
->where('product_override_id', "=", $product_override->id)
|
||||||
->where('product_id', "=", $product->id)->find();
|
->where('product_id', "=", $product->id)->find();
|
||||||
if ($item_product->loaded()){
|
if ($item_product->loaded()){
|
||||||
$checked = $item_product->include;
|
$checked = $item_product->include;
|
||||||
if ($item_product->cost != -1){
|
if ($item_product->cost != -1){
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php defined("SYSPATH") or die("No direct script access.");
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
/**
|
/**
|
||||||
* Gallery - a web based photo album viewer and editor
|
* Gallery - a web based photo album viewer and editor
|
||||||
* Copyright (C) 2000-2010 Bharat Mediratta
|
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -23,6 +23,7 @@ class basket_installer
|
|||||||
static function install(){
|
static function install(){
|
||||||
|
|
||||||
$db = Database::instance();
|
$db = Database::instance();
|
||||||
|
|
||||||
$db->query("CREATE TABLE IF NOT EXISTS {products} (
|
$db->query("CREATE TABLE IF NOT EXISTS {products} (
|
||||||
`id` int(9) NOT NULL auto_increment,
|
`id` int(9) NOT NULL auto_increment,
|
||||||
`name` TEXT NOT NULL,
|
`name` TEXT NOT NULL,
|
||||||
@ -30,14 +31,14 @@ class basket_installer
|
|||||||
`description` varchar(1024),
|
`description` varchar(1024),
|
||||||
`postage_band_id` int(9) default 1,
|
`postage_band_id` int(9) default 1,
|
||||||
PRIMARY KEY (`id`))
|
PRIMARY KEY (`id`))
|
||||||
DEFAULT CHARSET=utf8;");
|
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
|
||||||
|
|
||||||
$db->query("CREATE TABLE IF NOT EXISTS {product_overrides} (
|
$db->query("CREATE TABLE IF NOT EXISTS {product_overrides} (
|
||||||
`id` int(9) NOT NULL auto_increment,
|
`id` int(9) NOT NULL auto_increment,
|
||||||
`item_id` int(9) NOT NULL,
|
`item_id` int(9) NOT NULL,
|
||||||
`none` BOOLEAN default false,
|
`none` BOOLEAN default false,
|
||||||
PRIMARY KEY (`id`))
|
PRIMARY KEY (`id`))
|
||||||
DEFAULT CHARSET=utf8;");
|
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
|
||||||
|
|
||||||
$db->query("CREATE TABLE IF NOT EXISTS {item_products} (
|
$db->query("CREATE TABLE IF NOT EXISTS {item_products} (
|
||||||
`id` int(9) NOT NULL auto_increment,
|
`id` int(9) NOT NULL auto_increment,
|
||||||
@ -54,34 +55,72 @@ class basket_installer
|
|||||||
`flat_rate` DECIMAL(10,2) default 0,
|
`flat_rate` DECIMAL(10,2) default 0,
|
||||||
`per_item` DECIMAL(10,2) default 0,
|
`per_item` DECIMAL(10,2) default 0,
|
||||||
PRIMARY KEY (`id`))
|
PRIMARY KEY (`id`))
|
||||||
DEFAULT CHARSET=utf8;");
|
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
|
||||||
|
|
||||||
$postage_band = ORM::factory("postage_band");
|
$db->query("CREATE TABLE IF NOT EXISTS {orders} (
|
||||||
$postage_band->name = "No Postage";
|
`id` int(9) NOT NULL auto_increment,
|
||||||
$postage_band->save();
|
`status` int(9) DEFAULT 0,
|
||||||
|
`name` varchar(1024),
|
||||||
|
`email` varchar(1024),
|
||||||
|
`cost` DECIMAL(10,2) default 0,
|
||||||
|
`method` int(9) DEFAULT 0,
|
||||||
|
`text` TEXT NOT NULL,
|
||||||
|
PRIMARY KEY (`id`))
|
||||||
|
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
|
||||||
|
|
||||||
$product = ORM::factory("product");
|
$db->query("CREATE TABLE IF NOT EXISTS `ipn_messages` (
|
||||||
$product->name = "4x6";
|
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
$product->cost = 5;
|
`date` int(11) NOT NULL,
|
||||||
$product->description = "4\"x6\" print";
|
`key` varchar(20) NOT NULL,
|
||||||
$product->postage_band_id = 1;
|
`txn_id` varchar(20) NOT NULL,
|
||||||
$product->save();
|
`status` varchar(20) NOT NULL,
|
||||||
|
`success` bool default false,
|
||||||
|
`text` text,
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
|
||||||
|
|
||||||
$product = ORM::factory("product");
|
|
||||||
$product->name = "8x10";
|
|
||||||
$product->cost = 25;
|
|
||||||
$product->description = "8\"x10\" print";
|
|
||||||
$product->postage_band_id = 1;
|
|
||||||
$product->save();
|
|
||||||
|
|
||||||
$product = ORM::factory("product");
|
postage_band::create("No Postage",0,0);
|
||||||
$product->name = "8x12";
|
|
||||||
$product->cost = 30;
|
product::create("4x6",5,"4\"x6\" print",1);
|
||||||
$product->description = "8\"x12\" print";
|
product::create("8x10",25,"8\"x10\" print",1);
|
||||||
$product->postage_band_id = 1;
|
product::create("8x12",30,"8\"x12\" print",1);
|
||||||
$product->save();
|
|
||||||
|
basket::setPaymentDetails(
|
||||||
|
"<p>Use the following options to pay for this order.</p>
|
||||||
|
<p>Send a chequre to..</p>
|
||||||
|
<p>Visit the shop..</p>
|
||||||
|
<p>By using internet banking..</p>"
|
||||||
|
);
|
||||||
|
basket::setOrderPrefix("ORDER");
|
||||||
|
basket::setOrderCompletePage(
|
||||||
|
"<p>Your order number is %order_number. To pay for this order please either:</p>
|
||||||
|
<p> - Send a cheque for %total_cost to with reference %order_number..</p>
|
||||||
|
<p> - Visit the shop and quote the order %order_number..</p>
|
||||||
|
<p> - Transfer %total_cost using internet banking with reference %order_number..</p>
|
||||||
|
<p>Order will be processed as soon as payment is received. You should receive an e-mail with your order details shortly.</p>"
|
||||||
|
);
|
||||||
|
basket::setOrderCompleteEmail(
|
||||||
|
"Hi %name,
|
||||||
|
|
||||||
|
Thank you for your order the order details are below. To pay for this order please either:
|
||||||
|
|
||||||
|
- Send a cheque for %total_cost to with reference %order_number..
|
||||||
|
- Visit the shop and quote the order %order_number..
|
||||||
|
- Transfer %total_cost using internet banking with reference %order_number..
|
||||||
|
|
||||||
|
Order will be processed as soon as payment is received. For order pick-ups please visit..
|
||||||
|
|
||||||
|
Order Details
|
||||||
|
-------------
|
||||||
|
%order_details
|
||||||
|
|
||||||
|
Thanks");
|
||||||
|
basket::setOrderCompleteEmailSubject(
|
||||||
|
"Photography Order %order_number");
|
||||||
|
|
||||||
|
module::set_version("basket", 4);
|
||||||
|
|
||||||
module::set_version("basket", 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static function upgrade($version) {
|
static function upgrade($version) {
|
||||||
@ -101,12 +140,77 @@ class basket_installer
|
|||||||
`per_item` DECIMAL(10,2) default 0,
|
`per_item` DECIMAL(10,2) default 0,
|
||||||
PRIMARY KEY (`id`))
|
PRIMARY KEY (`id`))
|
||||||
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
|
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
|
||||||
$postage_band = ORM::factory("postage_band");
|
postage_band::create("No Postage",0,0);
|
||||||
$postage_band->name = "No Postage";
|
|
||||||
$postage_band->save();
|
|
||||||
|
|
||||||
module::set_version("basket", $version = 2);
|
module::set_version("basket", $version = 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($version == 2) {
|
||||||
|
$db->query("CREATE TABLE IF NOT EXISTS {orders} (
|
||||||
|
`id` int(9) NOT NULL auto_increment,
|
||||||
|
`text` TEXT NOT NULL,
|
||||||
|
PRIMARY KEY (`id`))
|
||||||
|
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
|
||||||
|
basket::setPaymentDetails(
|
||||||
|
"<p>Use the following options to pay for this order.</p>
|
||||||
|
<p>Send a chequre to..</p>
|
||||||
|
<p>Visit the shop..</p>
|
||||||
|
<p>By using internet banking..</p>"
|
||||||
|
);
|
||||||
|
basket::setOrderPrefix("ORDER");
|
||||||
|
basket::setOrderCompletePage(
|
||||||
|
"<p>Your order number is %order_number. To pay for this order please either:</p>
|
||||||
|
<p> - Send a cheque for %total_cost to with reference %order_number..</p>
|
||||||
|
<p> - Visit the shop and quote the order %order_number..</p>
|
||||||
|
<p> - Transfer %total_cost using internet banking with reference %order_number..</p>
|
||||||
|
<p>Order will be processed as soon as payment is received. You should receive an e-mail with your order details shortly.</p>"
|
||||||
|
);
|
||||||
|
basket::setOrderCompleteEmail(
|
||||||
|
"Hi %name,
|
||||||
|
|
||||||
|
Thank you for your order the order details are below. To pay for this order please either:
|
||||||
|
|
||||||
|
- Send a cheque for %total_cost to with reference %order_number..
|
||||||
|
- Visit the shop and quote the order %order_number..
|
||||||
|
- Transfer %total_cost using internet banking with reference %order_number..
|
||||||
|
|
||||||
|
Order will be processed as soon as payment is received. For order pick-ups please visit..
|
||||||
|
|
||||||
|
Order Details
|
||||||
|
-------------
|
||||||
|
%order_details
|
||||||
|
|
||||||
|
Thanks");
|
||||||
|
basket::setOrderCompleteEmailSubject(
|
||||||
|
"Photography Order %order_number");
|
||||||
|
|
||||||
|
module::set_version("basket", $version = 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($version ==3 ){
|
||||||
|
$db->query("ALTER TABLE {orders} ADD COLUMN `status` int(9) DEFAULT 0;");
|
||||||
|
|
||||||
|
$db->query("CREATE TABLE IF NOT EXISTS {ipn_messages} (
|
||||||
|
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
`date` int(11) NOT NULL,
|
||||||
|
`key` varchar(20) NOT NULL,
|
||||||
|
`txn_id` varchar(20) NOT NULL,
|
||||||
|
`status` varchar(20) NOT NULL,
|
||||||
|
`success` bool default false,
|
||||||
|
`text` text,
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
|
||||||
|
module::set_version("basket", $version = 4);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($version==4){
|
||||||
|
$db->query("ALTER TABLE {orders} ADD COLUMN `name` varchar(1024);");
|
||||||
|
$db->query("ALTER TABLE {orders} ADD COLUMN `email` varchar(1024);");
|
||||||
|
$db->query("ALTER TABLE {orders} ADD COLUMN `method` int(9) DEFAULT 0;");
|
||||||
|
$db->query("ALTER TABLE {orders} ADD COLUMN `cost` DECIMAL(10,2) default 0");
|
||||||
|
module::set_version("basket", $version = 5);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static function uninstall(){
|
static function uninstall(){
|
||||||
@ -115,5 +219,6 @@ class basket_installer
|
|||||||
$db->query("DROP TABLE IF EXISTS {product_overrides}");
|
$db->query("DROP TABLE IF EXISTS {product_overrides}");
|
||||||
$db->query("DROP TABLE IF EXISTS {item_products}");
|
$db->query("DROP TABLE IF EXISTS {item_products}");
|
||||||
$db->query("DROP TABLE IF EXISTS {postage_bands}");
|
$db->query("DROP TABLE IF EXISTS {postage_bands}");
|
||||||
|
$db->query("DROP TABLE IF EXISTS {orders}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php defined("SYSPATH") or die("No direct script access.");
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
/**
|
/**
|
||||||
* Gallery - a web based photo album viewer and editor
|
* Gallery - a web based photo album viewer and editor
|
||||||
* Copyright (C) 2000-2010 Bharat Mediratta
|
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -24,10 +24,15 @@ class basket_theme_Core {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static function header_top($theme) {
|
static function header_top($theme) {
|
||||||
$view = new View("basket.html");
|
|
||||||
|
|
||||||
$view->basket = Session_Basket::get();
|
if (!basket::is_side_bar_only())
|
||||||
return $view->render();
|
{
|
||||||
|
$view = new View("basket.html");
|
||||||
|
|
||||||
|
$view->basket = Session_Basket::get();
|
||||||
|
return $view->render();
|
||||||
|
}
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
static function admin_head($theme) {
|
static function admin_head($theme) {
|
||||||
@ -36,12 +41,15 @@ class basket_theme_Core {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
static function photo_top($theme){
|
static function photo_top($theme){
|
||||||
if ( product::isForSale($theme->item()->id)){
|
if (!basket::is_side_bar_only())
|
||||||
$view = new View("add_to_basket.html");
|
{
|
||||||
|
if ( product::isForSale($theme->item()->id)){
|
||||||
|
$view = new View("add_to_basket.html");
|
||||||
|
|
||||||
$view->item = $theme->item();
|
$view->item = $theme->item();
|
||||||
|
|
||||||
return $view->render();
|
return $view->render();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php defined("SYSPATH") or die("No direct script access.");
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
/**
|
/**
|
||||||
* Gallery - a web based photo album viewer and editor
|
* Gallery - a web based photo album viewer and editor
|
||||||
* Copyright (C) 2000-2010 Bharat Mediratta
|
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -56,6 +56,28 @@ class postage_band_Core {
|
|||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new postage band
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @param string $full_name
|
||||||
|
* @param string $password
|
||||||
|
* @return User_Model
|
||||||
|
*/
|
||||||
|
static function create($name, $flatrate, $peritemcost) {
|
||||||
|
$postage = ORM::factory("postage_band")->where("name", "=", $name)->find();
|
||||||
|
if ($postage->loaded()) {
|
||||||
|
throw new Exception("@todo postage already EXISTS $name");
|
||||||
|
}
|
||||||
|
|
||||||
|
$postage->name = $name;
|
||||||
|
$postage->flat_rate = $flatrate;
|
||||||
|
$postage->per_item = $peritemcost;
|
||||||
|
|
||||||
|
$postage->save();
|
||||||
|
return $postage;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns the array of postage bands
|
* returns the array of postage bands
|
||||||
* @return an array of postage bands
|
* @return an array of postage bands
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php defined("SYSPATH") or die("No direct script access.");
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
/**
|
/**
|
||||||
* Gallery - a web based photo album viewer and editor
|
* Gallery - a web based photo album viewer and editor
|
||||||
* Copyright (C) 2000-2010 Bharat Mediratta
|
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -20,28 +20,30 @@
|
|||||||
class product_Core {
|
class product_Core {
|
||||||
|
|
||||||
static function get_add_form_admin() {
|
static function get_add_form_admin() {
|
||||||
$form = new Forge("admin/product_lines/add_product", "", "post", array("id" => "g-add-product-form"));
|
$form = new Forge("admin/product_lines/add_product", "", "post", array("id" => "gAddProductForm"));
|
||||||
$group = $form->group("add_product")->label(t("Add Product"));
|
$group = $form->group("add_product")->label(t("Add Product"));
|
||||||
$group->input("name")->label(t("Name"))->id("g-product-name")
|
$group->input("name")->label(t("Name"))->id("gProductName")
|
||||||
->error_messages("in_use", t("There is already a product with that name"));
|
->error_messages("in_use", t("There is already a product with that name"));
|
||||||
$group->input("cost")->label(t("Cost"))->id("gCost");
|
$group->input("cost")->label(t("Cost"))->id("gCost");
|
||||||
$group->input("description")->label(t("Description"))->id("g-description");
|
$group->input("description")->label(t("Description"))->id("gDescription");
|
||||||
$group->dropdown("postage_band")
|
$group->dropdown("postage_band")
|
||||||
->label(t("Postage Band"))
|
->label(t("Postage Band"))
|
||||||
->options(postage_band::getPostageArray());
|
->options(postage_band::getPostageArray());
|
||||||
$group->submit("")->value(t("Add Product"));
|
$group->submit("")->value(t("Add Product"));
|
||||||
|
$product = ORM::factory("product");
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function get_edit_form_admin($product) {
|
static function get_edit_form_admin($product) {
|
||||||
|
|
||||||
$form = new Forge("admin/product_lines/edit_product/$product->id", "", "post",
|
$form = new Forge("admin/product_lines/edit_product/$product->id", "", "post",
|
||||||
array("id" => "g-edit-product-form"));
|
array("id" => "gEditProductForm"));
|
||||||
$group = $form->group("edit_product")->label(t("Edit Product"));
|
$group = $form->group("edit_product")->label(t("Edit Product"));
|
||||||
$group->input("name")->label(t("Name"))->id("g-product-name")->value($product->name);
|
$group->input("name")->label(t("Name"))->id("gProductName")->value($product->name);
|
||||||
$group->inputs["name"]->error_messages(
|
$group->inputs["name"]->error_messages(
|
||||||
"in_use", t("There is already a product with that name"));
|
"in_use", t("There is already a product with that name"));
|
||||||
$group->input("cost")->label(t("Cost"))->id("g-cost")->value($product->cost);
|
$group->input("cost")->label(t("Cost"))->id("gCost")->value($product->cost);
|
||||||
$group->input("description")->label(t("Description"))->id("g-description")->
|
$group->input("description")->label(t("Description"))->id("gDescription")->
|
||||||
value($product->description);
|
value($product->description);
|
||||||
$group->dropdown("postage_band")
|
$group->dropdown("postage_band")
|
||||||
->label(t("Postage Band"))
|
->label(t("Postage Band"))
|
||||||
@ -55,17 +57,39 @@ class product_Core {
|
|||||||
|
|
||||||
static function get_delete_form_admin($product) {
|
static function get_delete_form_admin($product) {
|
||||||
$form = new Forge("admin/product_lines/delete_product/$product->id", "", "post",
|
$form = new Forge("admin/product_lines/delete_product/$product->id", "", "post",
|
||||||
array("id" => "g-delete-product-form"));
|
array("id" => "gDeleteProductForm"));
|
||||||
$group = $form->group("delete_product")->label(
|
$group = $form->group("delete_product")->label(
|
||||||
t("Are you sure you want to delete product %name?", array("name" => $product->name)));
|
t("Are you sure you want to delete product %name?", array("name" => $product->name)));
|
||||||
$group->submit("")->value(t("Delete product %name", array("name" => $product->name)));
|
$group->submit("")->value(t("Delete product %name", array("name" => $product->name)));
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new product
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @param string $full_name
|
||||||
|
* @param string $password
|
||||||
|
* @return User_Model
|
||||||
|
*/
|
||||||
|
static function create($name, $cost, $description, $postage_band) {
|
||||||
|
$product = ORM::factory("product")->where("name", "=", $name)->find();
|
||||||
|
if ($product->loaded()) {
|
||||||
|
throw new Exception("@todo USER_ALREADY_EXISTS $name");
|
||||||
|
}
|
||||||
|
|
||||||
|
$product->name = $name;
|
||||||
|
$product->cost = $cost;
|
||||||
|
$product->description = $description;
|
||||||
|
$product->postage_band_id = $postage_band;
|
||||||
|
$product->save();
|
||||||
|
return $product;
|
||||||
|
}
|
||||||
|
|
||||||
static function getProductArray($id){
|
static function getProductArray($id){
|
||||||
$producta = array();
|
$producta = array();
|
||||||
// check for product override
|
// check for product override
|
||||||
$product_override = ORM::factory("product_override")->where('item_id', "=", $id)->find();
|
$product_override = ORM::factory("product_override")->where('item_id', "=", $id)->find();
|
||||||
|
|
||||||
if (!$product_override->loaded()){
|
if (!$product_override->loaded()){
|
||||||
// no override found so check parents
|
// no override found so check parents
|
||||||
@ -75,11 +99,12 @@ class product_Core {
|
|||||||
$parents = $item->parents();
|
$parents = $item->parents();
|
||||||
foreach ($parents as $parent){
|
foreach ($parents as $parent){
|
||||||
// check for product override
|
// check for product override
|
||||||
$product_override = ORM::factory("product_override")->where('item_id', "=", $parent->id)->find();
|
$temp_override = ORM::factory("product_override")->where('item_id', "=", $parent->id)->find();
|
||||||
if ($product_override->loaded()){
|
if ($temp_override ->loaded()){
|
||||||
break;
|
$product_override = $temp_override;
|
||||||
|
//break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$products = ORM::factory("product")->find_all();
|
$products = ORM::factory("product")->find_all();
|
||||||
@ -89,8 +114,8 @@ class product_Core {
|
|||||||
if ($product_override->loaded()){
|
if ($product_override->loaded()){
|
||||||
$show = !$product_override->none;
|
$show = !$product_override->none;
|
||||||
$item_product = ORM::factory("item_product")
|
$item_product = ORM::factory("item_product")
|
||||||
->where('product_override_id', "=", $product_override->id)
|
->where('product_override_id', "=", $product_override->id)
|
||||||
->where('product_id', "=", $product->id)->find();
|
->where('product_id', "=", $product->id)->find();
|
||||||
|
|
||||||
if ($item_product->loaded()){
|
if ($item_product->loaded()){
|
||||||
$cost = $item_product->cost;
|
$cost = $item_product->cost;
|
||||||
@ -102,7 +127,7 @@ class product_Core {
|
|||||||
|
|
||||||
if ($show)
|
if ($show)
|
||||||
{
|
{
|
||||||
$producta[$product->id] = $product->description." (".basket::formatMoney($cost).")";
|
$producta[$product->id] = html::clean($product->description)." (".basket::formatMoneyForWeb($cost).")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,6 +136,8 @@ class product_Core {
|
|||||||
|
|
||||||
static function isForSale($id){
|
static function isForSale($id){
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
// check for product override
|
// check for product override
|
||||||
$product_override = ORM::factory("product_override")->where('item_id', "=", $id)->find();
|
$product_override = ORM::factory("product_override")->where('item_id', "=", $id)->find();
|
||||||
|
|
||||||
@ -122,9 +149,10 @@ class product_Core {
|
|||||||
$parents = $item->parents();
|
$parents = $item->parents();
|
||||||
foreach ($parents as $parent){
|
foreach ($parents as $parent){
|
||||||
// check for product override
|
// check for product override
|
||||||
$product_override = ORM::factory("product_override")->where('item_id', "=", $parent->id)->find();
|
$temp_override = ORM::factory("product_override")->where('item_id', "=", $parent->id)->find();
|
||||||
if ($product_override->loaded()){
|
if ($temp_override ->loaded()){
|
||||||
break;
|
$product_override = $temp_override;
|
||||||
|
//break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -136,8 +164,8 @@ class product_Core {
|
|||||||
foreach ($products as $product){
|
foreach ($products as $product){
|
||||||
|
|
||||||
$item_product = ORM::factory("item_product")
|
$item_product = ORM::factory("item_product")
|
||||||
->where('product_override_id', "=", $product_override->id)
|
->where('product_override_id', "=", $product_override->id)
|
||||||
->where('product_id', "=", $product->id)->find();
|
->where('product_id', "=", $product->id)->find();
|
||||||
|
|
||||||
if ($item_product->loaded()){
|
if ($item_product->loaded()){
|
||||||
|
|
||||||
@ -152,5 +180,10 @@ class product_Core {
|
|||||||
} else {
|
} else {
|
||||||
return count($products) > 0;
|
return count($products) > 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (Exception $e)
|
||||||
|
{
|
||||||
|
echo $e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
330
modules/basket/libraries/Paypal.php
Normal file
330
modules/basket/libraries/Paypal.php
Normal file
@ -0,0 +1,330 @@
|
|||||||
|
<?php
|
||||||
|
/*******************************************************************************
|
||||||
|
* PHP Paypal IPN Integration Class
|
||||||
|
*******************************************************************************
|
||||||
|
* Author: Micah Carrick
|
||||||
|
* Email: email@micahcarrick.com
|
||||||
|
* Website: http://www.micahcarrick.com
|
||||||
|
*
|
||||||
|
* File: paypal.class.php
|
||||||
|
* Version: 1.3.0
|
||||||
|
* Copyright: (c) 2005 - Micah Carrick
|
||||||
|
* You are free to use, distribute, and modify this software
|
||||||
|
* under the terms of the GNU General Public License. See the
|
||||||
|
* included license.txt file.
|
||||||
|
*
|
||||||
|
*******************************************************************************
|
||||||
|
* VERION HISTORY:
|
||||||
|
* v1.3.0 [10.10.2005] - Fixed it so that single quotes are handled the
|
||||||
|
* right way rather than simple stripping them. This
|
||||||
|
* was needed because the user could still put in
|
||||||
|
* quotes.
|
||||||
|
*
|
||||||
|
* v1.2.1 [06.05.2005] - Fixed typo from previous fix :)
|
||||||
|
*
|
||||||
|
* v1.2.0 [05.31.2005] - Added the optional ability to remove all quotes
|
||||||
|
* from the paypal posts. The IPN will come back
|
||||||
|
* invalid sometimes when quotes are used in certian
|
||||||
|
* fields.
|
||||||
|
*
|
||||||
|
* v1.1.0 [05.15.2005] - Revised the form output in the submit_paypal_post
|
||||||
|
* method to allow non-javascript capable browsers
|
||||||
|
* to provide a means of manual form submission.
|
||||||
|
*
|
||||||
|
* v1.0.0 [04.16.2005] - Initial Version
|
||||||
|
*
|
||||||
|
*******************************************************************************
|
||||||
|
* DESCRIPTION:
|
||||||
|
*
|
||||||
|
* NOTE: See www.micahcarrick.com for the most recent version of this class
|
||||||
|
* along with any applicable sample files and other documentaion.
|
||||||
|
*
|
||||||
|
* This file provides a neat and simple method to interface with paypal and
|
||||||
|
* The paypal Instant Payment Notification (IPN) interface. This file is
|
||||||
|
* NOT intended to make the paypal integration "plug 'n' play". It still
|
||||||
|
* requires the developer (that should be you) to understand the paypal
|
||||||
|
* process and know the variables you want/need to pass to paypal to
|
||||||
|
* achieve what you want.
|
||||||
|
*
|
||||||
|
* This class handles the submission of an order to paypal aswell as the
|
||||||
|
* processing an Instant Payment Notification.
|
||||||
|
*
|
||||||
|
* This code is based on that of the php-toolkit from paypal. I've taken
|
||||||
|
* the basic principals and put it in to a class so that it is a little
|
||||||
|
* easier--at least for me--to use. The php-toolkit can be downloaded from
|
||||||
|
* http://sourceforge.net/projects/paypal.
|
||||||
|
*
|
||||||
|
* To submit an order to paypal, have your order form POST to a file with:
|
||||||
|
*
|
||||||
|
* $p = new paypal_class;
|
||||||
|
* $p->add_field('business', 'somebody@domain.com');
|
||||||
|
* $p->add_field('first_name', $_POST['first_name']);
|
||||||
|
* ... (add all your fields in the same manor)
|
||||||
|
* $p->submit_paypal_post();
|
||||||
|
*
|
||||||
|
* To process an IPN, have your IPN processing file contain:
|
||||||
|
*
|
||||||
|
* $p = new paypal_class;
|
||||||
|
* if ($p->validate_ipn()) {
|
||||||
|
* ... (IPN is verified. Details are in the ipn_data() array)
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* In case you are new to paypal, here is some information to help you:
|
||||||
|
*
|
||||||
|
* 1. Download and read the Merchant User Manual and Integration Guide from
|
||||||
|
* http://www.paypal.com/en_US/pdf/integration_guide.pdf. This gives
|
||||||
|
* you all the information you need including the fields you can pass to
|
||||||
|
* paypal (using add_field() with this class) aswell as all the fields
|
||||||
|
* that are returned in an IPN post (stored in the ipn_data() array in
|
||||||
|
* this class). It also diagrams the entire transaction process.
|
||||||
|
*
|
||||||
|
* 2. Create a "sandbox" account for a buyer and a seller. This is just
|
||||||
|
* a test account(s) that allow you to test your site from both the
|
||||||
|
* seller and buyer perspective. The instructions for this is available
|
||||||
|
* at https://developer.paypal.com/ as well as a great forum where you
|
||||||
|
* can ask all your paypal integration questions. Make sure you follow
|
||||||
|
* all the directions in setting up a sandbox test environment, including
|
||||||
|
* the addition of fake bank accounts and credit cards.
|
||||||
|
*
|
||||||
|
*******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
class Paypal_Core {
|
||||||
|
|
||||||
|
var $last_error; // holds the last error encountered
|
||||||
|
|
||||||
|
var $ipn_response; // holds the IPN response from paypal
|
||||||
|
public $ipn_data = array(); // array contains the POST values for IPN
|
||||||
|
|
||||||
|
var $fields = array(); // array holds the fields to submit to paypal
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
// initialization constructor. Called when class is created.
|
||||||
|
|
||||||
|
// sandbox paypal
|
||||||
|
|
||||||
|
//$this->paypal_url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
|
||||||
|
//$this->secure_url = "ssl://www.sandbox.paypal.com";
|
||||||
|
|
||||||
|
// normal paypal
|
||||||
|
$this->paypal_url = "https://www.paypal.com/cgi-bin/webscr";
|
||||||
|
$this->secure_url = "ssl://www.paypal.com";
|
||||||
|
|
||||||
|
$this->last_error = '';
|
||||||
|
|
||||||
|
//$this->ipn_log_file = Kohana::log_directory().Kohana::config('paypal.ipn_logfile');
|
||||||
|
//$this->ipn_log = true;
|
||||||
|
$this->ipn_response = '';
|
||||||
|
|
||||||
|
// populate $fields array with a few default values. See the paypal
|
||||||
|
// documentation for a list of fields and their data types. These defaul
|
||||||
|
// values can be overwritten by the calling script.
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function add_field($field, $value) {
|
||||||
|
|
||||||
|
// adds a key=>value pair to the fields array, which is what will be
|
||||||
|
// sent to paypal as POST variables. If the value is already in the
|
||||||
|
// array, it will be overwritten.
|
||||||
|
|
||||||
|
$this->fields["$field"] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function process($session_basket, $return_url, $cancel_url, $notify_url){
|
||||||
|
|
||||||
|
$this->add_field('rm','2');
|
||||||
|
$this->add_field('cmd','_cart');
|
||||||
|
$this->add_field('upload','1');
|
||||||
|
|
||||||
|
$this->add_field('currency_code', basket::getCurrency());
|
||||||
|
$this->add_field('business', basket::getPaypalAccount());
|
||||||
|
|
||||||
|
// IPN stuff
|
||||||
|
$this->add_field('return', $return_url);
|
||||||
|
$this->add_field('cancel_return', $cancel_url);
|
||||||
|
$this->add_field('notify_url', $notify_url);
|
||||||
|
|
||||||
|
// postage
|
||||||
|
if ($session_basket->ispp()){
|
||||||
|
$postage = $session_basket->postage_cost();
|
||||||
|
if ($postage > 0) {
|
||||||
|
$this->add_field('shipping_1',$postage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// basket contents
|
||||||
|
$id = 1;
|
||||||
|
foreach ($session_basket->contents as $key => $basket_item){
|
||||||
|
$this->add_field("item_name_$id", $basket_item->getCode());
|
||||||
|
$this->add_field("amount_$id", $basket_item->cost_per);
|
||||||
|
$this->add_field("quantity_$id",$basket_item->quantity);
|
||||||
|
$id++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// shipping address
|
||||||
|
$this->add_field("payer_email", $session_basket->email);
|
||||||
|
$this->add_field("address_name", $session_basket->name);
|
||||||
|
$this->add_field("address_street", $session_basket->house." ".$session_basket->street);
|
||||||
|
$this->add_field("address_city", $session_basket->town);
|
||||||
|
$this->add_field("address_zip", $session_basket->postcode);
|
||||||
|
$this->add_field("contact_phone", $session_basket->phone);
|
||||||
|
|
||||||
|
$string = "<form method=\"post\" name=\"paypal_form\" "
|
||||||
|
."action=\"".$this->paypal_url."\">\n";
|
||||||
|
|
||||||
|
foreach ($this->fields as $name => $value) {
|
||||||
|
$string = $string."<input type=\"hidden\" name=\"$name\" value=\"$value\"/>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
$string = $string."</form><script>function s_f(){document.forms[\"paypal_form\"].submit();}; window.setTimeout(s_f,20);</script>";
|
||||||
|
return $string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function validate_ipn($key) {
|
||||||
|
|
||||||
|
// parse the paypal URL
|
||||||
|
$url_parsed=parse_url($this->paypal_url);
|
||||||
|
|
||||||
|
// generate the post string from the _POST vars aswell as load the
|
||||||
|
// _POST vars into an arry so we can play with them from the calling
|
||||||
|
// script.
|
||||||
|
$post_string = 'cmd=_notify-validate';
|
||||||
|
foreach ($_POST as $field=>$value) {
|
||||||
|
$this->ipn_data["$field"] = $value;
|
||||||
|
$value = urlencode(stripslashes($value));
|
||||||
|
$value = preg_replace('/(.*[^%^0^D])(%0A)(.*)/i','${1}%0D%0A${3}',$value);
|
||||||
|
$post_string .= '&'.$field.'='.$value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// open the connection to paypal
|
||||||
|
|
||||||
|
$fp = fsockopen($this->secure_url,443,$err_num,$err_str,30);
|
||||||
|
if(!$fp) {
|
||||||
|
|
||||||
|
// could not open the connection. If loggin is on, the error message
|
||||||
|
// will be in the log.
|
||||||
|
$this->last_error = "fsockopen error no. $errnum: $errstr";
|
||||||
|
$this->log_ipn_results($key,false);
|
||||||
|
return false;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// Post the data back to paypal
|
||||||
|
fputs($fp, "POST ".$url_parsed['path']." HTTP/1.1\r\n");
|
||||||
|
fputs($fp, "Host: ".$url_parsed['host']."\r\n");
|
||||||
|
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
|
||||||
|
|
||||||
|
fputs($fp, "Content-length: ".strlen($post_string)."\r\n\r\n");
|
||||||
|
//fputs($fp, "Connection: close\r\n\r\n");
|
||||||
|
fputs($fp, $post_string . "\r\n\r\n");
|
||||||
|
|
||||||
|
// loop through the response from the server and append to variable
|
||||||
|
while(!feof($fp)) {
|
||||||
|
$this->ipn_response .= fgets($fp, 1024);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose($fp); // close connection
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stristr($this->ipn_response,"VERIFIED")===false)
|
||||||
|
{
|
||||||
|
// Invalid IPN transaction. Check the log for details.
|
||||||
|
$this->last_error = 'IPN Validation Failed. '.$url_parsed['host'].'\\'.$url_parsed['path'];
|
||||||
|
$this->log_ipn_results($key,false);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
|
||||||
|
// Valid IPN transaction.
|
||||||
|
|
||||||
|
// check recievers e-mail
|
||||||
|
$business = basket::getPaypalAccount();
|
||||||
|
|
||||||
|
if ($this->ipn_data['receiver_email']!=$business)
|
||||||
|
{
|
||||||
|
$this->last_error = 'receivers e-mail did not match '.$business;
|
||||||
|
$this->log_ipn_results($key,false);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if confirmed check message has not been received already
|
||||||
|
if ($this->ipn_data['payment_status'] == "Completed"){
|
||||||
|
|
||||||
|
$message = ORM::factory("ipn_message")
|
||||||
|
->where('key',"=",$key)
|
||||||
|
->where('status',"=",'completed')
|
||||||
|
->where('txn_id',"=",$this->ipn_data['txn_id'])->find();
|
||||||
|
|
||||||
|
if ($message->loaded()){
|
||||||
|
$this->last_error = 'Message alread received.';
|
||||||
|
$this->log_ipn_results($key,false);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->log_ipn_results($key,true);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function log_ipn_results($key, $success) {
|
||||||
|
|
||||||
|
// Timestamp
|
||||||
|
$text = '['.date('m/d/Y g:i A').'] - ';
|
||||||
|
|
||||||
|
$message = ORM::factory("ipn_message");
|
||||||
|
$message->date = time();
|
||||||
|
$message->key = $key;
|
||||||
|
$message->txn_id = $this->ipn_data['txn_id'];
|
||||||
|
$message->status = $this->ipn_data['payment_status'];
|
||||||
|
$message->success = $success;
|
||||||
|
|
||||||
|
// Success or failure being logged?
|
||||||
|
if ($success) $text .= "SUCCESS!\n";
|
||||||
|
else $text .= 'FAIL: '.$this->last_error."\n";
|
||||||
|
|
||||||
|
// Log the POST variables
|
||||||
|
$text .= "IPN POST Vars from Paypal:\n";
|
||||||
|
foreach ($this->ipn_data as $key=>$value) {
|
||||||
|
$text .= "$key=$value \n";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log the response from the paypal server
|
||||||
|
$text .= "\nIPN Response from Paypal Server:\n ".$this->ipn_response;
|
||||||
|
|
||||||
|
$message->text = $text;
|
||||||
|
$message->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
function dump_fields() {
|
||||||
|
|
||||||
|
// Used for debugging, this function will output all the field/value pairs
|
||||||
|
// that are currently defined in the instance of the class using the
|
||||||
|
// add_field() function.
|
||||||
|
|
||||||
|
echo "<h3>paypal_class->dump_fields() Output:</h3>";
|
||||||
|
echo "<table width=\"95%\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\">
|
||||||
|
<tr>
|
||||||
|
<td bgcolor=\"black\"><b><font color=\"white\">Field Name</font></b></td>
|
||||||
|
<td bgcolor=\"black\"><b><font color=\"white\">Value</font></b></td>
|
||||||
|
</tr>";
|
||||||
|
|
||||||
|
ksort($this->fields);
|
||||||
|
foreach ($this->fields as $key => $value) {
|
||||||
|
echo "<tr><td>$key</td><td>".urldecode($value)." </td></tr>";
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "</table><br>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
|||||||
<?php defined("SYSPATH") or die("No direct script access.");
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
/**
|
/**
|
||||||
* Gallery - a web based photo album viewer and editor
|
* Gallery - a web based photo album viewer and editor
|
||||||
* Copyright (C) 2000-2010 Bharat Mediratta
|
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -90,14 +90,32 @@ class Session_Basket_Core {
|
|||||||
public $email = "";
|
public $email = "";
|
||||||
public $phone = "";
|
public $phone = "";
|
||||||
|
|
||||||
|
public $ppenabled = true;
|
||||||
|
|
||||||
public function clear(){
|
public function clear(){
|
||||||
if (isset($this->contents)){
|
if (isset($this->contents)){
|
||||||
foreach ($this->contents as $key => $item){
|
foreach ($this->contents as $key => $item){
|
||||||
unset($this->contents[$key]);
|
unset($this->contents[$key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$this->ppenabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function enablepp()
|
||||||
|
{
|
||||||
|
$this->ppenabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function disablepp()
|
||||||
|
{
|
||||||
|
$this->ppenabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function ispp(){
|
||||||
|
return $this->ppenabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private function create_key($product, $id){
|
private function create_key($product, $id){
|
||||||
return "$product _ $id";
|
return "$product _ $id";
|
||||||
}
|
}
|
||||||
@ -116,7 +134,7 @@ class Session_Basket_Core {
|
|||||||
|
|
||||||
$key = $this->create_key($product, $id);
|
$key = $this->create_key($product, $id);
|
||||||
if (isset($this->contents[$key])){
|
if (isset($this->contents[$key])){
|
||||||
$this->contents[$key]->add($id, $quantity);
|
$this->contents[$key]->add($quantity);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$this->contents[$key] = new basket_item($product, $id, $quantity);
|
$this->contents[$key] = new basket_item($product, $id, $quantity);
|
||||||
|
16
modules/basket/models/ipn_message.php
Normal file
16
modules/basket/models/ipn_message.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
|
|
||||||
|
class Ipn_message_Model extends ORM {
|
||||||
|
|
||||||
|
public function formatedTime(){
|
||||||
|
return date("D jS F H:i", $this->date);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function json_encode(){
|
||||||
|
$toReturn = array(
|
||||||
|
'id' => $this->id,
|
||||||
|
'date' => $this->formatedTime(),
|
||||||
|
'text' => text::convertText($this->text));
|
||||||
|
return $toReturn;
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
d<?php defined("SYSPATH") or die("No direct script access.");
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
/**
|
/**
|
||||||
* Gallery - a web based photo album viewer and editor
|
* Gallery - a web based photo album viewer and editor
|
||||||
* Copyright (C) 2000-2010 Bharat Mediratta
|
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
56
modules/basket/models/order.php
Normal file
56
modules/basket/models/order.php
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
<?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 Order_Model extends ORM {
|
||||||
|
const WAITING_PAYMENT = 1;
|
||||||
|
const PAYMENT_CONFIRMED= 2;
|
||||||
|
|
||||||
|
const PAYMENT_PAYPAL = 1;
|
||||||
|
const PAYMENT_OFFLINE = 2;
|
||||||
|
|
||||||
|
public function title(){
|
||||||
|
return basket::getOrderPrefix().$this->id." ".$this->name." ".$this->status();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function status(){
|
||||||
|
switch ($this->status){
|
||||||
|
case 1:
|
||||||
|
return "Waiting Payment";
|
||||||
|
case 2:
|
||||||
|
return "Payment Confirmed";
|
||||||
|
case 20:
|
||||||
|
return "Complete";
|
||||||
|
|
||||||
|
default:
|
||||||
|
return "Unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function payment_method(){
|
||||||
|
switch ($this->method){
|
||||||
|
case 1:
|
||||||
|
return "through Paypal";
|
||||||
|
case 2:
|
||||||
|
return "offline";
|
||||||
|
|
||||||
|
default:
|
||||||
|
return "Unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
<?php defined("SYSPATH") or die("No direct script access.");
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
/**
|
/**
|
||||||
* Gallery - a web based photo album viewer and editor
|
* Gallery - a web based photo album viewer and editor
|
||||||
* Copyright (C) 2000-2010 Bharat Mediratta
|
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -18,32 +18,9 @@
|
|||||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
class Postage_Band_Model extends ORM {
|
class Postage_Band_Model extends ORM {
|
||||||
protected $has_many = array("products");
|
var $rules = array(
|
||||||
|
"name" => "length[1,32]");
|
||||||
|
|
||||||
/**
|
protected $has_many=array('products');
|
||||||
* Specify our rules here so that we have access to the instance of this model.
|
|
||||||
*/
|
|
||||||
public function validate($array=null) {
|
|
||||||
if (!$array) {
|
|
||||||
$this->rules = array(
|
|
||||||
"name" => array("rules" => array("required", "length[1,32]"),
|
|
||||||
"callbacks" => array(array($this, "valid_name"))),
|
|
||||||
"flat_rate" => array("rules" => array("required", "decimal")),
|
|
||||||
"per_item" => array("rules" => array("required")));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
parent::validate($array);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate the item name. It can't conflict with other names, can't contain slashes or
|
|
||||||
* trailing periods.
|
|
||||||
*/
|
|
||||||
public function valid_name(Validation $v, $field) {
|
|
||||||
$postage_band = ORM::factory("postage_band")->where("name", "=", $this->name)->find();
|
|
||||||
if ($postage_band->loaded() && $postage_band->id != $this->id) {
|
|
||||||
$v->add_error("name", "in_use");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php defined("SYSPATH") or die("No direct script access.");
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
/**
|
/**
|
||||||
* Gallery - a web based photo album viewer and editor
|
* Gallery - a web based photo album viewer and editor
|
||||||
* Copyright (C) 2000-2010 Bharat Mediratta
|
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -18,32 +18,9 @@
|
|||||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
class Product_Model extends ORM {
|
class Product_Model extends ORM {
|
||||||
protected $belongs_to = array("postage_band");
|
var $rules = array(
|
||||||
|
"name" => "length[1,32]",
|
||||||
|
"description" => "length[0,255]");
|
||||||
|
protected $belongs_to=array('postage_band');
|
||||||
|
|
||||||
/**
|
|
||||||
* Specify our rules here so that we have access to the instance of this model.
|
|
||||||
*/
|
|
||||||
public function validate($array=null) {
|
|
||||||
if (!$array) {
|
|
||||||
$this->rules = array(
|
|
||||||
"name" => array("rules" => array("required", "length[1,32]"),
|
|
||||||
"callbacks" => array(array($this, "valid_name"))),
|
|
||||||
"description" => array("rules" => array("required", "length[0,255]")),
|
|
||||||
"cost" => array("rules" => array("required", "decimal")));
|
|
||||||
}
|
|
||||||
|
|
||||||
parent::validate($array);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate the item name. It can't conflict with other names, can't contain slashes or
|
|
||||||
* trailing periods.
|
|
||||||
*/
|
|
||||||
public function valid_name(Validation $v, $field) {
|
|
||||||
Kohana_Log::add("error",print_r("valid_name!",1));
|
|
||||||
$product = ORM::factory("product")->where("name", "=", $this->name)->find();
|
|
||||||
if ($product->loaded() && $product->id != $this->id) {
|
|
||||||
$v->add_error("name", "in_use");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php defined("SYSPATH") or die("No direct script access.");
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
/**
|
/**
|
||||||
* Gallery - a web based photo album viewer and editor
|
* Gallery - a web based photo album viewer and editor
|
||||||
* Copyright (C) 2000-2010 Bharat Mediratta
|
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
name = "Shopping Basket"
|
name = "Shopping Basket"
|
||||||
description = "Provides a simple shopping basket and checkout with paypal integration"
|
description = "Provides a simple shopping basket and checkout with paypal integration"
|
||||||
version = 2
|
version = 5
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
<?php defined("SYSPATH") or die("No direct script access.") ?>
|
<?php defined("SYSPATH") or die("No direct script access.") ?>
|
||||||
|
|
||||||
<div id="add_to_basket">
|
<div id="add_to_basket">
|
||||||
<a href="<?= url::site("basket/add_to_basket_ajax/$item->id") ?>"
|
<a href="<?= url::site("basket/add_to_basket_ajax/$item->id") ?>" title="<?= t("Add To basket") ?>" class="g-dialog-link">
|
||||||
title="<?= t("Add To Basket") ?>"
|
<?= t("Add To basket") ?></a>
|
||||||
class="g-dialog-link">
|
|
||||||
Add To Basket</a>
|
|
||||||
</div>
|
</div>
|
@ -1,8 +1,7 @@
|
|||||||
<?php defined("SYSPATH") or die("No direct script access.") ?>
|
<?php defined("SYSPATH") or die("No direct script access.") ?>
|
||||||
<div id="g-admin-configure">
|
<div id="g-admin-configure">
|
||||||
<h1> <?= t("Configure Shopping Basket") ?> </h1>
|
<h1> <?= t("Configure Shopping Basket") ?> </h1>
|
||||||
<p>
|
<p> <?= t("Use this page to configure the shopping basket. If you have paypal you can use this to processs the final payments.") ?>
|
||||||
<?= t("Use this page to configure the shopping basket. If you have paypal you can use this to processs the final payments.") ?>
|
</p>
|
||||||
</p>
|
<?= $form ?>
|
||||||
<?= $form ?>
|
|
||||||
</div>
|
</div>
|
@ -1,7 +1,7 @@
|
|||||||
<?php defined("SYSPATH") or die("No direct script access.")
|
<?php defined("SYSPATH") or die("No direct script access.")
|
||||||
/**
|
/**
|
||||||
* Gallery - a web based photo album viewer and editor
|
* Gallery - a web based photo album viewer and editor
|
||||||
* Copyright (C) 2000-2010 Bharat Mediratta
|
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -21,8 +21,8 @@
|
|||||||
<div class="gBlock">
|
<div class="gBlock">
|
||||||
|
|
||||||
<a href="<?= url::site("admin/postage_bands/add_postage_band_form") ?>"
|
<a href="<?= url::site("admin/postage_bands/add_postage_band_form") ?>"
|
||||||
class="g-dialog-link g-button-link right ui-icon-left ui-state-default ui-corner-all"
|
class="g-dialog-link g-button right ui-icon-left ui-state-default ui-corner-all"
|
||||||
title="<?= t("Create a new Postage Band") ?>">
|
title="<?= t("Create a new Postage Band") ?>">
|
||||||
<span class="ui-icon ui-icon-circle-plus"></span>
|
<span class="ui-icon ui-icon-circle-plus"></span>
|
||||||
<?= t("Add a new Postage Band") ?>
|
<?= t("Add a new Postage Band") ?>
|
||||||
</a>
|
</a>
|
||||||
@ -31,44 +31,41 @@
|
|||||||
<?= t("Postage Bands") ?>
|
<?= t("Postage Bands") ?>
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
<div class="gBlockContent">
|
<div class="g-block-content">
|
||||||
<table id="gPostageAdminList">
|
<table id="g-postage-admin-list">
|
||||||
<tr>
|
<tr>
|
||||||
<th><?= t("Name") ?></th>
|
<th><?= t("Name") ?></th>
|
||||||
<th><?= t("Flat Rate") ?></th>
|
<th><?= t("Flat Rate") ?></th>
|
||||||
<th><?= t("Per Item") ?></th>
|
<th><?= t("Per Item") ?></th>
|
||||||
<th><?= t("Actions") ?></th>
|
<th><?= t("Actions") ?></th>
|
||||||
|
|
||||||
</tr>
|
</tr>
|
||||||
<? foreach ($postage_bands as $i => $postage_band): ?>
|
<? foreach ($postage_bands as $i => $postage_band): ?>
|
||||||
<tr id="gProduct-<?= $postage_band->id ?>" class="<?= text::alternate("gOddRow", "gEvenRow") ?>">
|
<tr id="g-product-<?= $postage_band->id ?>" class="<?= text::alternate("gOddRow", "gEvenRow") ?>">
|
||||||
<td id="product-<?= $postage_band->id ?>" class="core-info ">
|
<td id="product-<?= $postage_band->id ?>" class="core-info ">
|
||||||
<?= html::clean($postage_band->name) ?>
|
<?= html::clean($postage_band->name) ?>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<?= basket::formatMoneyForWeb($postage_band->flat_rate) ?>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<?= basket::formatMoney($postage_band->flat_rate) ?>
|
<?= basket::formatMoneyForWeb($postage_band->per_item) ?>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td class="g-actions">
|
||||||
<?= basket::formatMoney($postage_band->per_item) ?>
|
<a href="<?= url::site("admin/postage_bands/edit_postage_band_form/$postage_band->id") ?>"
|
||||||
</td>
|
open_text="<?= t("close") ?>"
|
||||||
<td class="gActions">
|
class="g-panel-link g-button ui-state-default ui-corner-all ui-icon-left">
|
||||||
<a href="<?= url::site("admin/postage_bands/edit_postage_band_form/$postage_band->id") ?>"
|
<span class="ui-icon ui-icon-pencil"></span><?= t("edit") ?></a>
|
||||||
open_text="<?= t("close") ?>"
|
|
||||||
class="g-panel-link g-button-link ui-state-default ui-corner-all ui-icon-left">
|
|
||||||
<span class="ui-icon ui-icon-pencil"></span>
|
|
||||||
<?= t("edit") ?>
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<a href="<?= url::site("admin/postage_bands/delete_postage_band_form/$postage_band->id") ?>"
|
<a href="<?= url::site("admin/postage_bands/delete_postage_band_form/$postage_band->id") ?>"
|
||||||
class="g-dialog-link g-button-link ui-state-default ui-corner-all ui-icon-left">
|
class="g-dialog-link g-button ui-state-default ui-corner-all ui-icon-left">
|
||||||
<span class="ui-icon ui-icon-trash"></span>
|
<span class="ui-icon ui-icon-trash"></span><?= t("delete") ?></a>
|
||||||
<?= t("delete") ?>
|
|
||||||
</a>
|
|
||||||
</td>
|
|
||||||
|
|
||||||
</tr>
|
</td>
|
||||||
|
|
||||||
|
</tr>
|
||||||
<? endforeach ?>
|
<? endforeach ?>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
@ -1,7 +1,7 @@
|
|||||||
<?php defined("SYSPATH") or die("No direct script access.")
|
<?php defined("SYSPATH") or die("No direct script access.")
|
||||||
/**
|
/**
|
||||||
* Gallery - a web based photo album viewer and editor
|
* Gallery - a web based photo album viewer and editor
|
||||||
* Copyright (C) 2000-2010 Bharat Mediratta
|
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -21,7 +21,7 @@
|
|||||||
<div class="g-block">
|
<div class="g-block">
|
||||||
|
|
||||||
<a href="<?= url::site("admin/product_lines/add_product_form") ?>"
|
<a href="<?= url::site("admin/product_lines/add_product_form") ?>"
|
||||||
class="g-dialog-link g-button g-right ui-icon-left ui-state-default ui-corner-all"
|
class="g-dialog-link g-button right ui-icon-left ui-state-default ui-corner-all"
|
||||||
title="<?= t("Create a new Product") ?>">
|
title="<?= t("Create a new Product") ?>">
|
||||||
<span class="ui-icon ui-icon-circle-plus"></span>
|
<span class="ui-icon ui-icon-circle-plus"></span>
|
||||||
<?= t("Add a new Product") ?>
|
<?= t("Add a new Product") ?>
|
||||||
@ -42,12 +42,12 @@
|
|||||||
|
|
||||||
</tr>
|
</tr>
|
||||||
<? foreach ($products as $i => $product): ?>
|
<? foreach ($products as $i => $product): ?>
|
||||||
<tr id="g-product-<?= $product->id ?>" class="<?= text::alternate("g-odd", "g-even") ?>">
|
<tr id="gProduct-<?= $product->id ?>" class="<?= text::alternate("gOddRow", "gEvenRow") ?>">
|
||||||
<td id="product-<?= $product->id ?>" class="core-info ">
|
<td id="product-<?= $product->id ?>" class="core-info ">
|
||||||
<?= html::clean($product->name) ?>
|
<?= html::clean($product->name) ?>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<?= basket::formatMoney($product->cost) ?>
|
<?= basket::formatMoneyForWeb($product->cost) ?>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<?= html::clean($product->description) ?>
|
<?= html::clean($product->description) ?>
|
||||||
@ -57,11 +57,11 @@
|
|||||||
</td>
|
</td>
|
||||||
|
|
||||||
|
|
||||||
<td>
|
<td class="g-actions">
|
||||||
<a href="<?= url::site("admin/product_lines/edit_product_form/$product->id") ?>"
|
<a href="<?= url::site("admin/product_lines/edit_product_form/$product->id") ?>"
|
||||||
open_text="<?= t("close") ?>"
|
open_text="<?= t("close") ?>"
|
||||||
class="g-panel-link g-button ui-state-default ui-corner-all ui-icon-left">
|
class="g-panel-link g-button ui-state-default ui-corner-all ui-icon-left">
|
||||||
<span class="ui-icon ui-icon-pencil"></span><span class="g-button-text"><?= t("edit") ?></span></a>
|
<span class="ui-icon ui-icon-pencil"></span><span class="gButtonText"><?= t("edit") ?></span></a>
|
||||||
|
|
||||||
<a href="<?= url::site("admin/product_lines/delete_product_form/$product->id") ?>"
|
<a href="<?= url::site("admin/product_lines/delete_product_form/$product->id") ?>"
|
||||||
class="g-dialog-link g-button ui-state-default ui-corner-all ui-icon-left">
|
class="g-dialog-link g-button ui-state-default ui-corner-all ui-icon-left">
|
||||||
|
8
modules/basket/views/admin_templates.html.php
Normal file
8
modules/basket/views/admin_templates.html.php
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?php defined("SYSPATH") or die("No direct script access.") ?>
|
||||||
|
<div id="g-admin-configure">
|
||||||
|
<h1> <?= t("Configure Templates used for Offline Payment.") ?> </h1>
|
||||||
|
<p>
|
||||||
|
<?= t("The following can be edited to control what the user see during offline payment. Please read the documentation for more information about variables you can use in the templates") ?>
|
||||||
|
</p>
|
||||||
|
<?= $form ?>
|
||||||
|
</div>
|
42
modules/basket/views/basket-side-bar.html.php
Normal file
42
modules/basket/views/basket-side-bar.html.php
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?
|
||||||
|
if ($theme->page_type != 'basket'){
|
||||||
|
if (basket::can_view_orders()){
|
||||||
|
?><a class="g-button ui-icon-left ui-state-default ui-corner-all ui-state-hover" href="<?= url::site("basket/view_Orders") ?>" title="<?= t("View Orders") ?>"><span class="ui-icon ui-icon-clipboard"></span><?= t("View Orders")?></a><?
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$item = $theme->item();
|
||||||
|
if ($item->is_photo() && product::isForSale($theme->item()->id)){
|
||||||
|
?><p>
|
||||||
|
<a class="g-dialog-link g-button ui-icon-left ui-state-default ui-corner-all ui-state-hover" href="<?= url::site("basket/add_to_basket_ajax/$item->id") ?>"
|
||||||
|
title="<?= t("Add To Basket")?>"><span class="ui-icon ui-icon-plusthick"></span><?= t("Add To Basket") ?></a></p>
|
||||||
|
<?
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (isset($basket) && isset($basket->contents) && ($basket->size() > 0)) {
|
||||||
|
?><div id="sidebar-basket"><table id="gBasketList"><tr><th><?= t("Product") ?></th><th><?= t("Cost") ?></th><th></th></tr><?
|
||||||
|
|
||||||
|
$total=0;
|
||||||
|
foreach ($basket->contents as $key => $prod_details){
|
||||||
|
|
||||||
|
?><tr id="" class="<?= text::alternate("gOddRow", "gEvenRow") ?>"><td id="item-<?= $prod_details->item ?>" class="core-info"><?
|
||||||
|
|
||||||
|
$item = $prod_details->getItem();
|
||||||
|
|
||||||
|
?><img src="<?= $item->thumb_url()?>" title="<?= $item->title?>" alt="<?= $item->title?>" style="max-width:90px;"/><br/>
|
||||||
|
<?= html::clean($prod_details->quantity) ?> x <?= html::clean($prod_details->product_description()) ?></td>
|
||||||
|
<td><? $total += $prod_details->cost?><?= basket::formatMoneyForWeb($prod_details->cost); ?></td>
|
||||||
|
<td class="g-actions"><a href="<?= url::site("basket/remove_item/$key") ?>" class="g-button ui-state-default ui-corner-all ui-icon-left"><span class="ui-icon ui-icon-trash"></span></a></td>
|
||||||
|
</tr><?
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
<tr class="<?= text::alternate("gOddRow", "gEvenRow") ?>">
|
||||||
|
<td>Total</td><td id="total"><?= $basket->ispp()?basket::formatMoneyForWeb($total + $postage):basket::formatMoneyForWeb($total)?></td><td></td>
|
||||||
|
</tr></table></div><br/>
|
||||||
|
<p><a class="g-button right ui-icon-left ui-state-default ui-corner-all ui-state-hover" href="<?= url::site("basket/view_basket") ?>" title="<?= t("Checkout") ?>"><span class="ui-icon ui-icon-cart"></span><?= t("Checkout") ?></a></p><?
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
<?php defined("SYSPATH") or die("No direct script access.")
|
<?php defined("SYSPATH") or die("No direct script access.")
|
||||||
/**
|
/**
|
||||||
* Gallery - a web based photo album viewer and editor
|
* Gallery - a web based photo album viewer and editor
|
||||||
* Copyright (C) 2000-2010 Bharat Mediratta
|
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -18,7 +18,12 @@
|
|||||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
?>
|
?>
|
||||||
<? if ($theme->page_subtype != 'basket'): ?>
|
|
||||||
|
<? if ($theme->page_type != 'basket'): ?>
|
||||||
|
<? if (basket::can_view_orders()): ?>
|
||||||
|
<a href="<?= url::site("basket/view_Orders") ?>"
|
||||||
|
title="<?= t("View Orders") ?>">View Orders</a>
|
||||||
|
<? endif?>
|
||||||
<? if (isset($basket) && isset($basket->contents) && ($basket->size() > 0)): ?>
|
<? if (isset($basket) && isset($basket->contents) && ($basket->size() > 0)): ?>
|
||||||
<div id="basket">
|
<div id="basket">
|
||||||
<a href="<?= url::site("basket/view_basket") ?>"
|
<a href="<?= url::site("basket/view_basket") ?>"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php defined("SYSPATH") or die("No direct script access.")
|
<?php defined("SYSPATH") or die("No direct script access.")
|
||||||
/**
|
/**
|
||||||
* Gallery - a web based photo album viewer and editor
|
* Gallery - a web based photo album viewer and editor
|
||||||
* Copyright (C) 2000-2010 Bharat Mediratta
|
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -41,7 +41,7 @@ function ci(v)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function so(){
|
function so(g){
|
||||||
var p=true;
|
var p=true;
|
||||||
var d=document.checkout;
|
var d=document.checkout;
|
||||||
if(!ci(d.fullname)){p=false;}
|
if(!ci(d.fullname)){p=false;}
|
||||||
@ -49,16 +49,38 @@ function so(){
|
|||||||
if(!ci(d.phone)){p=false;}
|
if(!ci(d.phone)){p=false;}
|
||||||
if (p)
|
if (p)
|
||||||
{
|
{
|
||||||
|
d.paypal.value=g;
|
||||||
d.submit();
|
d.submit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</SCRIPT>
|
</SCRIPT>
|
||||||
<div class="g-block">
|
<div class="g-block">
|
||||||
<?= $form ?>
|
<?
|
||||||
|
$payment_details = basket::getPaymentDetails();
|
||||||
|
if ($payment_details):
|
||||||
|
?>
|
||||||
|
<div class="basket-right" id="payment">
|
||||||
<h2>Payment Details</h2>
|
<h2>Payment Details</h2>
|
||||||
<p>After you have confirmed the order we will get in contact with you to arrange payment.</p>
|
<?= $payment_details; ?>
|
||||||
|
</div>
|
||||||
|
<? endif; ?>
|
||||||
|
<?= $form ?>
|
||||||
|
<div class="basketbuttons">
|
||||||
<a href="<?= url::site("basket/view_basket") ?>" class="left g-button ui-state-default ui-corner-all ui-icon-left">
|
<a href="<?= url::site("basket/view_basket") ?>" class="left g-button ui-state-default ui-corner-all ui-icon-left">
|
||||||
<span class="ui-icon ui-icon-arrow-1-w"></span><?= t("Back to Basket") ?></a>
|
<span class="ui-icon ui-icon-arrow-1-w"></span><?= t("Back to Basket") ?></a>
|
||||||
<a href="javascript: so()" class="g-right g-button ui-state-default ui-corner-all ui-icon-right">
|
|
||||||
|
<? if (basket::isPaypal()): ?>
|
||||||
|
<a href="javascript: so(true)"
|
||||||
|
class="right g-button ui-state-default ui-corner-all ui-icon-right">
|
||||||
|
<span class="ui-icon ui-icon-arrow-1-e"></span><?= t("Pay with Credit Card or Paypal") ?></a>
|
||||||
|
<a href="javascript: so(false)"
|
||||||
|
class="right g-button ui-state-default ui-corner-all ui-icon-right">
|
||||||
|
<span class="ui-icon ui-icon-arrow-1-e"></span><?= t("Pay off line") ?></a>
|
||||||
|
<? else: ?>
|
||||||
|
|
||||||
|
<a href="javascript: so(false)" class="right g-button ui-state-default ui-corner-all ui-icon-right">
|
||||||
<span class="ui-icon ui-icon-arrow-1-e"></span><?= t("Proceed to Confirmation") ?></a>
|
<span class="ui-icon ui-icon-arrow-1-e"></span><?= t("Proceed to Confirmation") ?></a>
|
||||||
|
<? endif?>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php defined("SYSPATH") or die("No direct script access.")
|
<?php defined("SYSPATH") or die("No direct script access.")
|
||||||
/**
|
/**
|
||||||
* Gallery - a web based photo album viewer and editor
|
* Gallery - a web based photo album viewer and editor
|
||||||
* Copyright (C) 2000-2010 Bharat Mediratta
|
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -22,9 +22,9 @@
|
|||||||
function so(){document.confirm.submit();}
|
function so(){document.confirm.submit();}
|
||||||
</SCRIPT>
|
</SCRIPT>
|
||||||
<?= $form ?>
|
<?= $form ?>
|
||||||
<div class="g-block">
|
<div class="gBlock">
|
||||||
<h2>Basket Summary</h2>
|
<h2>Basket Summary</h2>
|
||||||
<div class="g-block-content">
|
<div class="g-block-content scrollables">
|
||||||
<table id="g-basket-list">
|
<table id="g-basket-list">
|
||||||
<tr>
|
<tr>
|
||||||
<th><?= t("Name") ?></th>
|
<th><?= t("Name") ?></th>
|
||||||
@ -33,7 +33,8 @@ function so(){document.confirm.submit();}
|
|||||||
<th><?= t("Cost") ?></th>
|
<th><?= t("Cost") ?></th>
|
||||||
</tr>
|
</tr>
|
||||||
<? foreach ($basket->contents as $key => $prod_details): ?>
|
<? foreach ($basket->contents as $key => $prod_details): ?>
|
||||||
<tr id="" class="<?= text::alternate("g-odd", "g-even") ?>">
|
<tr id="" class="<?= text::alternate("gOddRow", "gEvenRow") ?>">
|
||||||
|
|
||||||
<td id="item-<?= $prod_details->item ?>" class="core-info ">
|
<td id="item-<?= $prod_details->item ?>" class="core-info ">
|
||||||
<? $item = $prod_details->getItem(); ?>
|
<? $item = $prod_details->getItem(); ?>
|
||||||
<div>
|
<div>
|
||||||
@ -47,19 +48,20 @@ function so(){document.confirm.submit();}
|
|||||||
<?= html::clean($prod_details->quantity) ?>
|
<?= html::clean($prod_details->quantity) ?>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<?= html::clean(basket::formatMoney($prod_details->cost)) ?>
|
<?= basket::formatMoneyForWeb($prod_details->cost) ?>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<? endforeach ?>
|
<? endforeach ?>
|
||||||
<? $postage = $basket->postage_cost();?>
|
<? $postage = $basket->postage_cost();?>
|
||||||
<? if ($postage > 0):?>
|
<? if ($postage > 0):?>
|
||||||
<tr id="" class="<?= text::alternate("g-odd", "g-even") ?>">
|
<tr id="" class="<?= text::alternate("gOddRow", "gEvenRow") ?>">
|
||||||
<td></td><td></td><td>Postage and Packaging</td><td><?= html::clean(basket::formatMoney($postage))?></td><td></td>
|
<td></td><td></td><td <?=$basket->ispp()?"":"style=\"text-decoration:line-through\""; ?>>Postage and Packaging</td><td <?=$basket->ispp()?"":"style=\"text-decoration:line-through\""; ?>><?= basket::formatMoneyForWeb($postage)?></td>
|
||||||
</tr>
|
</tr>
|
||||||
<? endif;?>
|
<? endif;?>
|
||||||
<tr id="" class="<?= text::alternate("g-odd", "g-even") ?>">
|
<tr id="" class="<?= text::alternate("gOddRow", "gEvenRow") ?>">
|
||||||
<td></td><td></td><td>Total Cost</td><td><?= html::clean(basket::formatMoney($basket->cost() + $postage))?></td>
|
<td></td><td></td><td>Total Cost</td><td><?= $basket->ispp()?basket::formatMoneyForWeb($basket->cost() + $postage):basket::formatMoneyForWeb($basket->cost()); ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<table>
|
<table>
|
||||||
@ -78,9 +80,10 @@ E-mail : <?= $basket->email ?><br/>
|
|||||||
Telephone : <?= $basket->phone ?>
|
Telephone : <?= $basket->phone ?>
|
||||||
</td></tr>
|
</td></tr>
|
||||||
</table>
|
</table>
|
||||||
<a href="<?= url::site("basket/checkout") ?>" class="g-left g-button ui-state-default ui-corner-all ui-icon-left">
|
<div class="basketbuttons">
|
||||||
|
<a href="<?= url::site("basket/checkout") ?>" class="left g-button ui-state-default ui-corner-all ui-icon-left">
|
||||||
<span class="ui-icon ui-icon-arrow-1-w"></span><?= t("Back to Checkout") ?></a>
|
<span class="ui-icon ui-icon-arrow-1-w"></span><?= t("Back to Checkout") ?></a>
|
||||||
<a href="javascript: so()" class="g-right g-button ui-state-default ui-corner-all ui-icon-right">
|
<a href="javascript: so()" class="right g-button ui-state-default ui-corner-all ui-icon-right">
|
||||||
<span class="ui-icon ui-icon-arrow-1-e"></span><?= t("Confirm Order") ?></a>
|
<span class="ui-icon ui-icon-arrow-1-e"></span><?= t("Confirm Order") ?></a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php defined("SYSPATH") or die("No direct script access.")
|
<?php defined("SYSPATH") or die("No direct script access.")
|
||||||
/**
|
/**
|
||||||
* Gallery - a web based photo album viewer and editor
|
* Gallery - a web based photo album viewer and editor
|
||||||
* Copyright (C) 2000-2010 Bharat Mediratta
|
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -19,6 +19,12 @@
|
|||||||
*/
|
*/
|
||||||
?>
|
?>
|
||||||
<div class="g-block">
|
<div class="g-block">
|
||||||
|
<div id="b-complete">
|
||||||
<h2>Thankyou for your order</h2>
|
<h2>Thankyou for your order</h2>
|
||||||
You will be contacted soon to arrange payment and delivery.
|
<? if ($order->method == Order_Model::PAYMENT_PAYPAL){
|
||||||
|
?>Your order will be confirmed when Paypal has finished processing your order.<?
|
||||||
|
}else {
|
||||||
|
?><?= basket::replaceStrings(basket::getOrderCompletePage(),Array("order_number"=>$ordernumber, "total_cost"=>basket::formatMoneyForWeb($total_cost)));?><?
|
||||||
|
|
||||||
|
}?></div>
|
||||||
</div>
|
</div>
|
4
modules/basket/views/paypal_redirect.html.php
Normal file
4
modules/basket/views/paypal_redirect.html.php
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<?= $form?>
|
||||||
|
<h1>Processing</h1><h3>If you are not automatically redirected to
|
||||||
|
paypal within 5 seconds <a href='javascript:s_f();'>Click Here</a>.</h3>
|
||||||
|
|
16
modules/basket/views/pew1.html.php
Normal file
16
modules/basket/views/pew1.html.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php defined("SYSPATH") or die("No direct script access.") ?>
|
||||||
|
<div id="gAdminConfigure">
|
||||||
|
<SCRIPT language="JavaScript">function so(){document.generateKeys.submit();}</SCRIPT>
|
||||||
|
<h1> <?= t("Paypal Encryption Wizard - Step 1") ?> </h1>
|
||||||
|
<p>
|
||||||
|
<?= t("The first step is to fill in some details about yourself. These details are used to create a set of encryption keys that will be used to communicate with paypal.") ?>
|
||||||
|
</p>
|
||||||
|
<?= $form ?>
|
||||||
|
<a href="<?= url::site("admin/configure") ?>"
|
||||||
|
class="left gButtonLink ui-state-default ui-corner-all ui-icon-left">
|
||||||
|
<span class="ui-icon ui-icon-arrow-1-w"></span><?= t("Cancel") ?></a>
|
||||||
|
|
||||||
|
<a href="<?= url::site("javascript: so();") ?>"
|
||||||
|
class="right gButtonLink ui-state-default ui-corner-all ui-icon-right">
|
||||||
|
<span class="ui-icon ui-icon-arrow-1-e"></span><?= t("Next") ?></a>
|
||||||
|
</div>
|
17
modules/basket/views/pew2.html.php
Normal file
17
modules/basket/views/pew2.html.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php defined("SYSPATH") or die("No direct script access.") ?>
|
||||||
|
<div id="gAdminConfigure">
|
||||||
|
<SCRIPT language="JavaScript">function so(){document.paypalKey.submit();}</SCRIPT>
|
||||||
|
<h1> <?= t("Paypal Encryption Wizard - Step 2") ?> </h1>
|
||||||
|
<p>
|
||||||
|
<?= t("Open your paypal account on a seperate window and navigate to My account / profile / Selling Preferences - Encrypted Payment Settings.") ?>
|
||||||
|
<?= t("From this page press the download button to donwload paypals public certificate. Then paste the documents contents into the edit box below.") ?>
|
||||||
|
</p>
|
||||||
|
<?= $form ?>
|
||||||
|
<a href="<?= url::site("admin/configure") ?>"
|
||||||
|
class="left gButtonLink ui-state-default ui-corner-all ui-icon-left">
|
||||||
|
<span class="ui-icon ui-icon-arrow-1-w"></span><?= t("Cancel") ?></a>
|
||||||
|
|
||||||
|
<a href="<?= url::site("javascript: so();") ?>"
|
||||||
|
class="right gButtonLink ui-state-default ui-corner-all ui-icon-right">
|
||||||
|
<span class="ui-icon ui-icon-arrow-1-e"></span><?= t("Next") ?></a>
|
||||||
|
</div>
|
20
modules/basket/views/print_order.html.php
Normal file
20
modules/basket/views/print_order.html.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>Print Order</title>
|
||||||
|
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
|
||||||
|
<script language="javascript">
|
||||||
|
$(document).ready(function(){
|
||||||
|
window.print();
|
||||||
|
window.close();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<tt>
|
||||||
|
<?= $order ?>
|
||||||
|
</tt>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
@ -1,7 +1,7 @@
|
|||||||
<?php defined("SYSPATH") or die("No direct script access.")
|
<?php defined("SYSPATH") or die("No direct script access.")
|
||||||
/**
|
/**
|
||||||
* Gallery - a web based photo album viewer and editor
|
* Gallery - a web based photo album viewer and editor
|
||||||
* Copyright (C) 2000-2010 Bharat Mediratta
|
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -18,35 +18,53 @@
|
|||||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
?>
|
?>
|
||||||
|
<script>
|
||||||
|
var b,d;
|
||||||
|
function previewImage(element)
|
||||||
|
{
|
||||||
|
var ele=$(element),i=$(document.createElement('div')),img=$(new Image());
|
||||||
|
img.load(function(){
|
||||||
|
var o=$('<div></div>').appendTo(document.body).addClass('ui-widget-overlay').css({width:d.width(),height:d.height()});
|
||||||
|
i.css({'position':'absolute',left:(b.width()/2)-(this.width / 2),top:(b.height()/2)-(this.height/2)}).click(function(){i.remove();o.remove();}).append(img);
|
||||||
|
|
||||||
|
$("body").append(i);
|
||||||
|
}).attr('src',ele.attr('href'));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$(window).load(function(){
|
||||||
|
b=$("body");d=$("document");
|
||||||
|
$("#gBasketList").find(".preview-image").bind("click",function(){return previewImage(this)});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
<div class="g-block">
|
<div class="g-block">
|
||||||
|
<div class="basketbuttons">
|
||||||
<? if (isset($basket->contents ) && count($basket->contents) > 0): ?>
|
<? if (isset($basket->contents ) && count($basket->contents) > 0): ?>
|
||||||
|
|
||||||
<? if (basket::isPaypal()): ?>
|
|
||||||
<?= basket::generatePaypalForm($basket) ?>
|
|
||||||
<script language="JavaScript">
|
<script language="JavaScript">
|
||||||
function co(){
|
|
||||||
var d=document.paypal_form.submit();
|
|
||||||
}</script>
|
|
||||||
<a href="javascript:co();"
|
|
||||||
class="g-right g-button ui-state-default ui-corner-all ui-icon-right">
|
|
||||||
<span class="ui-icon ui-icon-arrow-1-e"></span><?= t("Pay with Credit Card or Paypal") ?></a>
|
|
||||||
<a href="<?= url::site("basket/checkout") ?>"
|
|
||||||
class="g-right g-button ui-state-default ui-corner-all ui-icon-right">
|
|
||||||
<span class="ui-icon ui-icon-arrow-1-e"></span><?= t("Pay off line") ?></a>
|
|
||||||
<? else: ?>
|
|
||||||
<a href="<?= url::site("basket/checkout") ?>"
|
|
||||||
class="g-right g-button ui-state-default ui-corner-all ui-icon-right">
|
|
||||||
<span class="ui-icon ui-icon-arrow-1-e"></span><?= t("Proceed to Checkout") ?></a>
|
|
||||||
<? endif; ?>
|
|
||||||
<? endif; ?>
|
|
||||||
<h2>
|
|
||||||
<?= t("Shopping Basket") ?>
|
|
||||||
</h2>
|
|
||||||
|
|
||||||
<div class="g-block-content">
|
$(document).ready(function(){
|
||||||
|
$("#pickup").click(function(){
|
||||||
|
if (this.checked)
|
||||||
|
{
|
||||||
|
window.location = "<?= url::site("basket/view_basket/nopp") ?>";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
window.location = "<?= url::site("basket/view_basket/ppon") ?>";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<a href="<?= url::site("basket/checkout") ?>"
|
||||||
|
class="right g-button ui-state-default ui-corner-all ui-icon-right">
|
||||||
|
<span class="ui-icon ui-icon-arrow-1-e"></span><?= t("Proceed to Checkout") ?></a>
|
||||||
|
<? endif; ?>
|
||||||
|
</div>
|
||||||
|
<div class="g-block-content scrollable">
|
||||||
<? if (isset($basket->contents ) && count($basket->contents) > 0): ?>
|
<? if (isset($basket->contents ) && count($basket->contents) > 0): ?>
|
||||||
|
|
||||||
<table id="g-basket-list">
|
<table id="gBasketList">
|
||||||
<tr>
|
<tr>
|
||||||
<th><?= t("Picture") ?></th>
|
<th><?= t("Picture") ?></th>
|
||||||
<th><?= t("Product") ?></th>
|
<th><?= t("Product") ?></th>
|
||||||
@ -58,12 +76,14 @@
|
|||||||
<? $total=0;?>
|
<? $total=0;?>
|
||||||
|
|
||||||
<? foreach ($basket->contents as $key => $prod_details): ?>
|
<? foreach ($basket->contents as $key => $prod_details): ?>
|
||||||
<tr id="" class="<?= text::alternate("g-odd", "g-even") ?>">
|
<tr id="" class="<?= text::alternate("gOddRow", "gEvenRow") ?>">
|
||||||
|
|
||||||
<td id="item-<?= $prod_details->item ?>" class="core-info ">
|
<td id="item-<?= $prod_details->item ?>" class="core-info ">
|
||||||
<? $item = $prod_details->getItem(); ?>
|
<? $item = $prod_details->getItem(); ?>
|
||||||
<div id="basketThumb">
|
<div id="basketThumb">
|
||||||
|
<a href="<?= $item->resize_url()?>" class="preview-image">
|
||||||
<img src="<?= $item->thumb_url()?>" title="<?= $item->title?>" alt="<?= $item->title?>" />
|
<img src="<?= $item->thumb_url()?>" title="<?= $item->title?>" alt="<?= $item->title?>" />
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
@ -74,13 +94,9 @@
|
|||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<? $total += $prod_details->cost?>
|
<? $total += $prod_details->cost?>
|
||||||
<?= html::clean(basket::formatMoney($prod_details->cost)) ?>
|
<?= basket::formatMoneyForWeb($prod_details->cost); ?>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td class="g-actions">
|
||||||
<!-- a href="<?= url::site("admin/product_lines/edit_product_form/") ?>"
|
|
||||||
open_text="<?= t("close") ?>"
|
|
||||||
class="g-panel-link g-button ui-state-default ui-corner-all ui-icon-left">
|
|
||||||
<span class="ui-icon ui-icon-pencil"></span><span class="g-button-text"><?= t("edit") ?></span></a-->
|
|
||||||
|
|
||||||
<a href="<?= url::site("basket/remove_item/$key") ?>"
|
<a href="<?= url::site("basket/remove_item/$key") ?>"
|
||||||
class="g-button ui-state-default ui-corner-all ui-icon-left">
|
class="g-button ui-state-default ui-corner-all ui-icon-left">
|
||||||
@ -90,34 +106,32 @@
|
|||||||
<? endforeach ?>
|
<? endforeach ?>
|
||||||
<? $postage = $basket->postage_cost();?>
|
<? $postage = $basket->postage_cost();?>
|
||||||
<? if ($postage > 0):?>
|
<? if ($postage > 0):?>
|
||||||
<tr id="" class="<?= text::alternate("g-odd", "g-even") ?>">
|
<tr class="<?= text::alternate("gOddRow", "gEvenRow") ?>">
|
||||||
<td></td><td></td><td>Postage and Packaging</td><td><?= html::clean(basket::formatMoney($postage))?></td><td></td>
|
<td></td><td></td><td <?=$basket->ispp()?"":"style=\"text-decoration:line-through\""; ?>>Postage and Packaging</td><td <?=$basket->ispp()?"":"style=\"text-decoration:line-through\""; ?>><?= basket::formatMoneyForWeb($postage)?></td><td>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<? if (basket::isAllowPickup()):?>
|
||||||
|
<tr class="<?= text::alternate("gOddRow", "gEvenRow") ?>"><td colspan="5"><input id="pickup" type="checkbox" <?=$basket->ispp()?"":"checked"; ?>/> Select if you wish to pick up the photos.</td></tr>
|
||||||
<? endif;?>
|
<? endif;?>
|
||||||
<tr id="" class="<?= text::alternate("g-odd", "g-even") ?>">
|
<? endif;?>
|
||||||
<td></td><td></td><td>Total Cost</td><td><?= html::clean(basket::formatMoney($total + $postage))?></td><td></td>
|
<tr class="<?= text::alternate("gOddRow", "gEvenRow") ?>">
|
||||||
|
<td></td><td></td><td>Total Cost</td><td id="total"><?= $basket->ispp()?basket::formatMoneyForWeb($total + $postage):basket::formatMoneyForWeb($total)?></td><td></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<? else: ?>
|
<? else: ?>
|
||||||
Shopping Basket is Empty
|
Shopping Basket is Empty
|
||||||
<? endif; ?>
|
<? endif; ?>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="basketbuttons">
|
||||||
<? if (isset($basket->contents ) && count($basket->contents) > 0): ?>
|
<? if (isset($basket->contents ) && count($basket->contents) > 0): ?>
|
||||||
|
|
||||||
<? if (basket::isPaypal()): ?>
|
|
||||||
<a href="javascript:co();"
|
|
||||||
class="g-right g-button ui-state-default ui-corner-all ui-icon-right">
|
|
||||||
<span class="ui-icon ui-icon-arrow-1-e"></span><?= t("Pay with Credit Card or Paypal") ?></a>
|
|
||||||
<a href="<?= url::site("basket/checkout") ?>"
|
<a href="<?= url::site("basket/checkout") ?>"
|
||||||
class="g-right g-button ui-state-default ui-corner-all ui-icon-right">
|
class="right g-button ui-state-default ui-corner-all ui-icon-right">
|
||||||
<span class="ui-icon ui-icon-arrow-1-e"></span><?= t("Pay off line") ?></a>
|
|
||||||
<? else: ?>
|
|
||||||
<a href="<?= url::site("basket/checkout") ?>"
|
|
||||||
class="g-right g-button ui-state-default ui-corner-all ui-icon-right">
|
|
||||||
<span class="ui-icon ui-icon-arrow-1-e"></span><?= t("Proceed to Checkout") ?></a>
|
<span class="ui-icon ui-icon-arrow-1-e"></span><?= t("Proceed to Checkout") ?></a>
|
||||||
<? endif; ?>
|
<? endif; ?>
|
||||||
<? endif; ?>
|
</div>
|
||||||
</div>
|
</div>
|
46
modules/basket/views/view_ipn.html.php
Normal file
46
modules/basket/views/view_ipn.html.php
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?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.
|
||||||
|
*/
|
||||||
|
?>
|
||||||
|
<h1>IPN Messages for <?= $order->title()?></h1>
|
||||||
|
<a href="<?=url::site("basket/view_orders");?>">Back to orders</a>
|
||||||
|
<div class="left" style="width:150px;float:left;font-size:10px;">
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<?
|
||||||
|
foreach ($ipn_messages as $i => $ipn_message){
|
||||||
|
?><li><a href="javascript:ld(<?=$ipn_message->id?>)"><?= $ipn_message->date." ".$ipn_message->status ?></a></li><?
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="scrollable" style="text-align:left;float:left;padding:0;font-size:12px;display:block;"><pre id="ipn_text"></pre>
|
||||||
|
</div>
|
||||||
|
<SCRIPT language="JavaScript">
|
||||||
|
var ot,csrf;
|
||||||
|
$(window).load(new function(){ot=$("#ipn_text");csrf="?csrf=<?= $csrf ?>"});
|
||||||
|
function ld(n){
|
||||||
|
ot.html("Loading...");
|
||||||
|
ot.load('<?=url::site("basket/show_ipn")?>/'+n+csrf,
|
||||||
|
function (responseText, textStatus, XMLHttpRequest) {
|
||||||
|
if (textStatus == "error") {ot.html(responseText);}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
</SCRIPT>
|
18
modules/basket/views/view_order.html.php
Normal file
18
modules/basket/views/view_order.html.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
<h2><?= $order->title()?></h2>
|
||||||
|
Payment is <?= $order->payment_method()?><?
|
||||||
|
|
||||||
|
if ($order->status==Order_Model::WAITING_PAYMENT){
|
||||||
|
?><br/><a href="<?= url::site("basket/confirm_order_payment/".$order->id)."?csrf=$csrf";?>">Confirm Order Payment</a> <?
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($order->status==Order_Model::PAYMENT_CONFIRMED){
|
||||||
|
?><br/><a href="<?= url::site("basket/confirm_order_delivery/".$order->id)."?csrf=$csrf";?>">Confirm Order Delivery</a> <?
|
||||||
|
}
|
||||||
|
if ($order->method==Order_Model::PAYMENT_PAYPAL){
|
||||||
|
?><br/><a href="<?= url::site("basket/view_ipn/".$order->id);?>">View Paypal IPN Messages</a><?
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
?><br/>
|
||||||
|
<?= str_replace(array("\r\n", "\n", "\r"),"<br/>",$order->text);?>
|
67
modules/basket/views/view_orders.html.php
Normal file
67
modules/basket/views/view_orders.html.php
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
<?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.
|
||||||
|
*/
|
||||||
|
?>
|
||||||
|
<div class="basketbuttons">
|
||||||
|
<form action="javascript: so()" method="post" id="show_order" name="show_order">
|
||||||
|
<input type="hidden" name="csrf" value="<?= $csrf ?>" />
|
||||||
|
<label for="orderno" >Order Number</label>
|
||||||
|
<input type="text" id="orderno" name="orderno" value="" class="textbox" />
|
||||||
|
<a href="javascript: so()" class="g-button ui-state-default ui-icon-right">
|
||||||
|
<span class="ui-icon ui-icon-arrow-1-e"></span><?= t("Search") ?></a>
|
||||||
|
<a style="display:none" id="print_button" href="" class="g-button ui-state-default ui-icon-right">
|
||||||
|
<span class="ui-icon ui-icon-arrow-1-e"></span><?= t("Print") ?></a>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="left" style="width:150px;float:left;font-size:10px;display:block;">
|
||||||
|
<ul>
|
||||||
|
<?
|
||||||
|
foreach ($orders as $i => $order){
|
||||||
|
?><li class="order-status-<?=$order->status?>"><a href="javascript:ld(<?=$order->id?>)"><?= $order->title()?></a></li><?
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="scrollable" style="text-align:left;float:left;padding:0;font-size:12px;display:block;"><pre id="order_text"></pre>
|
||||||
|
</div>
|
||||||
|
<SCRIPT language="JavaScript">
|
||||||
|
var d,pb,ot,csrf;
|
||||||
|
$(window).load(new function(){d=document.show_order;pb=$("#print_button");ot=$("#order_text");csrf="?csrf="+d.csrf.value});
|
||||||
|
|
||||||
|
function se(v){v.style.backgroundColor="#FAA";}
|
||||||
|
|
||||||
|
function re(v){v.style.backgroundColor="#FFF";}
|
||||||
|
|
||||||
|
function ci(v){if ((!v.value)||(v.value.length==0)){se(v);return false;}re(v);return true;}
|
||||||
|
|
||||||
|
function ld(n){
|
||||||
|
pb.css({display:'none'});
|
||||||
|
ot.html("Loading...");
|
||||||
|
ot.load('<?=url::site("basket/show_order")?>/'+n+csrf,
|
||||||
|
function (responseText, textStatus, XMLHttpRequest) {
|
||||||
|
if (textStatus == "success") {d.orderno.value=n;pb.css({display:'inline-block'});
|
||||||
|
pb.attr({target: "_blank",href : '<?=url::site("basket/print_order")?>/'+n+csrf});}
|
||||||
|
if (textStatus == "error") {ot.html(responseText);pb.css({display:'none'});}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function so(){
|
||||||
|
pb.css({display:'none'});
|
||||||
|
if(ci(d.orderno)){ld(d.orderno.value);}}
|
||||||
|
</SCRIPT>
|
@ -68,16 +68,15 @@ class Admin_Developer_Controller extends Admin_Controller {
|
|||||||
$task_context = array("step" => 0, "success_msg" => $success_msg, "error_msg" => $error_msg);
|
$task_context = array("step" => 0, "success_msg" => $success_msg, "error_msg" => $error_msg);
|
||||||
$task = task::create($task_def, array_merge($task_context, $post->as_array()));
|
$task = task::create($task_def, array_merge($task_context, $post->as_array()));
|
||||||
|
|
||||||
print json_encode(array("result" => "started",
|
json::reply(array("result" => "started",
|
||||||
"max_iterations" => 15,
|
"max_iterations" => 15,
|
||||||
"url" => url::site("admin/developer/run_task/{$task->id}?csrf=" .
|
"url" => url::site("admin/developer/run_task/{$task->id}?csrf=" .
|
||||||
access::csrf_token()),
|
access::csrf_token()),
|
||||||
"task" => $task->as_array()));
|
"task" => $task->as_array()));
|
||||||
} else {
|
} else {
|
||||||
$v = $this->_get_module_create_content(arr::overwrite($form, $post->as_array()),
|
$v = $this->_get_module_create_content(arr::overwrite($form, $post->as_array()),
|
||||||
arr::overwrite($errors, $post->errors()));
|
arr::overwrite($errors, $post->errors()));
|
||||||
print json_encode(array("result" => "error",
|
json::reply(array("result" => "error", "html" => (string)$v));
|
||||||
"form" => $v->__toString()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,16 +118,15 @@ class Admin_Developer_Controller extends Admin_Controller {
|
|||||||
"comments" => $post->comments, "tags" => $post->tags));
|
"comments" => $post->comments, "tags" => $post->tags));
|
||||||
batch::start();
|
batch::start();
|
||||||
|
|
||||||
print json_encode(array("result" => "started",
|
json::reply(array("result" => "started",
|
||||||
"max_iterations" => $total + 5,
|
"max_iterations" => $total + 5,
|
||||||
"url" => url::site("admin/developer/run_task/{$task->id}?csrf=" .
|
"url" => url::site("admin/developer/run_task/{$task->id}?csrf=" .
|
||||||
access::csrf_token()),
|
access::csrf_token()),
|
||||||
"task" => $task->as_array()));
|
"task" => $task->as_array()));
|
||||||
} else {
|
} else {
|
||||||
$v = $this->_get_test_data_view(arr::overwrite($form, $post->as_array()),
|
$v = $this->_get_test_data_view(arr::overwrite($form, $post->as_array()),
|
||||||
arr::overwrite($errors, $post->errors()));
|
arr::overwrite($errors, $post->errors()));
|
||||||
print json_encode(array("result" => "error",
|
json::reply(array("result" => "error", "html" => (string)$v));
|
||||||
"form" => $v->__toString()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,12 +150,10 @@ class Admin_Developer_Controller extends Admin_Controller {
|
|||||||
message::success(empty($error_msg) ? $context["error_msg"] : $error_msg);
|
message::success(empty($error_msg) ? $context["error_msg"] : $error_msg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
print json_encode(array("result" => "success",
|
json::reply(array("result" => "success", "task" => $task->as_array()));
|
||||||
"task" => $task->as_array()));
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
print json_encode(array("result" => "in_progress",
|
json::reply(array("result" => "in_progress", "task" => $task->as_array()));
|
||||||
"task" => $task->as_array()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,6 @@ class developer_task_Core {
|
|||||||
|
|
||||||
static function create_module($task) {
|
static function create_module($task) {
|
||||||
$context = unserialize($task->context);
|
$context = unserialize($task->context);
|
||||||
Kohana_Log::add("error", "task context:\n" . Kohana::debug($context));
|
|
||||||
|
|
||||||
if (empty($context["module"])) {
|
if (empty($context["module"])) {
|
||||||
$context["class_name"] = strtr($context["name"], " ", "_");
|
$context["class_name"] = strtr($context["name"], " ", "_");
|
||||||
|
@ -32,15 +32,12 @@ class <?= $class_name ?>_Controller extends Controller {
|
|||||||
|
|
||||||
message::success(t("<?= $name ?> Processing Successfully"));
|
message::success(t("<?= $name ?> Processing Successfully"));
|
||||||
|
|
||||||
print json_encode(
|
json::reply(array("result" => "success"));
|
||||||
array("result" => "success"));
|
|
||||||
} else {
|
} else {
|
||||||
print json_encode(
|
json::reply(array("result" => "error", "html" => (string)$form));
|
||||||
array("result" => "error",
|
|
||||||
"form" => $form->__toString()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function _get_form() {
|
private function _get_form() {
|
||||||
$form = new Forge("<?= $module ?>/handler", "", "post",
|
$form = new Forge("<?= $module ?>/handler", "", "post",
|
||||||
array("id" => "g-<?= $css_id ?>-form"));
|
array("id" => "g-<?= $css_id ?>-form"));
|
||||||
@ -50,4 +47,4 @@ class <?= $class_name ?>_Controller extends Controller {
|
|||||||
|
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
73
modules/ecard/controllers/admin_ecard.php
Normal file
73
modules/ecard/controllers/admin_ecard.php
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
|
/**
|
||||||
|
* Gallery - a web based photo album viewer and editor
|
||||||
|
* Copyright (C) 2000-2010 Bharat Mediratta
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
class Admin_ecard_Controller extends Admin_Controller {
|
||||||
|
public function index() {
|
||||||
|
$view = new Admin_View("admin.html");
|
||||||
|
$view->page_title = t("eCard settings");
|
||||||
|
$view->content = new View("admin_ecard.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("ecard", "sender", $form->ecard->sender->value);
|
||||||
|
module::set_var("ecard", "bcc", $form->ecard->bcc->value);
|
||||||
|
module::set_var("ecard", "subject", $form->ecard->subject->value);
|
||||||
|
module::set_var("ecard", "message", $form->ecard->message->value);
|
||||||
|
module::set_var("ecard", "access_permissions", $form->ecard->access_permissions->value);
|
||||||
|
module::set_var("ecard", "location", $form->ecard->location->value);
|
||||||
|
message::success(t("eCard settings updated"));
|
||||||
|
url::redirect("admin/ecard");
|
||||||
|
} else {
|
||||||
|
print $form;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function _get_admin_form() {
|
||||||
|
$form = new Forge("admin/ecard/save", "", "post", array("id" => "g-ecard-admin-form"));
|
||||||
|
$ecard_settings = $form->group("ecard")->label(t("eCard settings"));
|
||||||
|
$ecard_settings->input("sender")
|
||||||
|
->label(t("E-mail sender (leave blank for a user-defined address)"))
|
||||||
|
->value(module::get_var("ecard", "sender", ""));
|
||||||
|
$ecard_settings->input("bcc")
|
||||||
|
->label(t("BCC (optional)"))
|
||||||
|
->value(module::get_var("ecard", "bcc", ""));
|
||||||
|
$ecard_settings->input("subject")->label(t("E-mail subject"))
|
||||||
|
->value(module::get_var("ecard", "subject"));
|
||||||
|
$ecard_settings->textarea("message")->label(t("E-mail message. Valid keywords are \"%toname\" (recipient's name) and \"%fromname\" (sender's name))"))
|
||||||
|
->value(module::get_var("ecard", "message"));
|
||||||
|
$ecard_settings->dropdown("access_permissions")
|
||||||
|
->label(t("Who can send eCards?"))
|
||||||
|
->options(array("everybody" => t("Everybody"),
|
||||||
|
"registered_users" => t("Only registered users")))
|
||||||
|
->selected(module::get_var("ecard", "access_permissions"));
|
||||||
|
$ecard_settings->dropdown("location")
|
||||||
|
->label(t("Where should the eCard link be displayed?"))
|
||||||
|
->options(array("top" => t("At the top of the sidebar as an icon"),
|
||||||
|
"sidebar" => t("In the sidebar as a button")))
|
||||||
|
->selected(module::get_var("ecard", "location"));
|
||||||
|
$ecard_settings->submit("save")->value(t("Save"));
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
95
modules/ecard/controllers/ecard.php
Normal file
95
modules/ecard/controllers/ecard.php
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
|
/**
|
||||||
|
* Gallery - a web based photo album viewer and editor
|
||||||
|
* Copyright (C) 2000-2010 Bharat Mediratta
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class Ecard_Controller extends Controller {
|
||||||
|
/**
|
||||||
|
* Send the ecard.
|
||||||
|
*/
|
||||||
|
public function send($id) {
|
||||||
|
$item = ORM::factory("item", $id);
|
||||||
|
access::required("view", $item);
|
||||||
|
if (!ecard::can_send_ecard()) {
|
||||||
|
access::forbidden();
|
||||||
|
}
|
||||||
|
$form = ecard::get_send_form($item);
|
||||||
|
try {
|
||||||
|
$valid = $form->validate();
|
||||||
|
} catch (ORM_Validation_Exception $e) {
|
||||||
|
// Translate ORM validation errors into form error messages
|
||||||
|
foreach ($e->validation->errors() as $key => $error) {
|
||||||
|
$form->edit_item->inputs[$key]->add_error($error, 1);
|
||||||
|
}
|
||||||
|
$valid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($valid) {
|
||||||
|
$v = new View("ecard_email.html");
|
||||||
|
$v->item = $item;
|
||||||
|
$v->subject = module::get_var("ecard", "subject");
|
||||||
|
$to_name = $form->send_ecard->to_name->value;
|
||||||
|
$from_name = $form->send_ecard->from_name->value;
|
||||||
|
$bcc = module::get_var("ecard", "bcc");
|
||||||
|
$v->message = t(module::get_var("ecard", "message"), array("toname" => $to_name, "fromname" => $from_name));
|
||||||
|
$v->custom_message = $form->send_ecard->text->value;
|
||||||
|
$v->image = $item->name;
|
||||||
|
$to = $form->send_ecard->inputs["to_email"]->value;
|
||||||
|
$from = $form->send_ecard->inputs["from_email"]->value;
|
||||||
|
$headers = array("from" => $from_name."<".$from.">", "to" => $to, "subject" => module::get_var("ecard", "subject"));
|
||||||
|
require_once(MODPATH. "ecard/lib/mime.php");
|
||||||
|
$mime = new Mail_mime("\n");
|
||||||
|
$mime->setHTMLBody($v->render());
|
||||||
|
$mime->addHTMLImage($item->resize_path(),$item->mime_type,$item->name);
|
||||||
|
$body = $mime->get(array('html_charset' => 'UTF-8', 'text_charset' => 'UTF-8','text_encoding' => '8bit','head_charset' => 'UTF-8'));
|
||||||
|
self::_notify($headers['to'], $headers['from'], $headers['subject'], $item, $body, $mime->headers(), $bcc);
|
||||||
|
message::success("eCard successfully sent");
|
||||||
|
json::reply(array("result" => "success"));
|
||||||
|
} else {
|
||||||
|
json::reply(array("result" => "error", "html" => (string) $form));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Present a form for sending a new ecard.
|
||||||
|
*/
|
||||||
|
public function form_send($item_id) {
|
||||||
|
$item = ORM::factory("item", $item_id);
|
||||||
|
access::required("view", $item);
|
||||||
|
if (!ecard::can_send_ecard()) {
|
||||||
|
access::forbidden();
|
||||||
|
}
|
||||||
|
print ecard::prefill_send_form(ecard::get_send_form($item));
|
||||||
|
}
|
||||||
|
private static function _notify($to, $from, $subject, $item, $text, $headers, $bcc) {
|
||||||
|
$sendmail = Sendmail::factory();
|
||||||
|
$sendmail
|
||||||
|
->to($to)
|
||||||
|
->from($from)
|
||||||
|
->subject($subject);
|
||||||
|
if(isset($bcc)) {
|
||||||
|
$sendmail->header("bcc",$bcc);
|
||||||
|
}
|
||||||
|
foreach($headers as $key => $value) {
|
||||||
|
$sendmail->header($key,$value);
|
||||||
|
}
|
||||||
|
$sendmail
|
||||||
|
->message($text)
|
||||||
|
->send();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
7
modules/ecard/css/ecard.css
Normal file
7
modules/ecard/css/ecard.css
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
.ui-icon-ecard {
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
float: left;
|
||||||
|
margin-right: .2em;
|
||||||
|
background-image: url(../images/email_go.png);
|
||||||
|
}
|
80
modules/ecard/helpers/ecard.php
Normal file
80
modules/ecard/helpers/ecard.php
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
|
/**
|
||||||
|
* Gallery - a web based photo album viewer and editor
|
||||||
|
* Copyright (C) 2000-2010 Bharat Mediratta
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the API for handling ecards.
|
||||||
|
*
|
||||||
|
* Note: by design, this class does not do any permission checking.
|
||||||
|
*/
|
||||||
|
class ecard_Core {
|
||||||
|
static function get_send_form($item) {
|
||||||
|
$form = new Forge("ecard/send/{$item->id}", "", "post", array("id" => "g-ecard-form"));
|
||||||
|
$group = $form->group("send_ecard")->label(t("Send eCard"));
|
||||||
|
$group->input("from_name")
|
||||||
|
->label(t("Your name"))
|
||||||
|
->id("g-author")
|
||||||
|
->rules("required")
|
||||||
|
->error_messages("required", t("You must enter a name for yourself"));
|
||||||
|
$group->input("from_email")
|
||||||
|
->label(t("Your e-mail"))
|
||||||
|
->id("g-email")
|
||||||
|
->rules("required|valid_email")
|
||||||
|
->error_messages("required", t("You must enter a valid email address"))
|
||||||
|
->error_messages("invalid", t("You must enter a valid email address"));
|
||||||
|
$group->input("to_name")
|
||||||
|
->label(t("Recipient's Name"))
|
||||||
|
->id("g-recipient")
|
||||||
|
->rules("required")
|
||||||
|
->error_messages("required", t("You must enter a recipient's name"));
|
||||||
|
$group->input("to_email")
|
||||||
|
->label(t("Recipient's e-mail"))
|
||||||
|
->id("g-recip-email")
|
||||||
|
->rules("required|valid_email")
|
||||||
|
->error_messages("required", t("You must enter a valid email address"))
|
||||||
|
->error_messages("invalid", t("You must enter a valid email address"));
|
||||||
|
$group->textarea("text")
|
||||||
|
->label(t("Message"))
|
||||||
|
->id("g-text")
|
||||||
|
->rules("required")
|
||||||
|
->error_messages("required", t("You must enter a message"));
|
||||||
|
$group->hidden("item_id")->value($item->id);
|
||||||
|
module::event("ecard_send_form", $form);
|
||||||
|
module::event("captcha_protect_form", $form);
|
||||||
|
$group->submit("")->value(t("Send"))->class("ui-state-default ui-corner-all");
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
|
||||||
|
static function prefill_send_form($form) {
|
||||||
|
$active = identity::active_user();
|
||||||
|
if (!$active->guest) {
|
||||||
|
$group = $form->send_ecard;
|
||||||
|
$group->inputs["from_name"]->value($active->full_name);
|
||||||
|
$group->from_email->value($active->email);
|
||||||
|
}
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
|
||||||
|
static function can_send_ecard() {
|
||||||
|
return !identity::active_user()->guest ||
|
||||||
|
module::get_var("ecard", "access_permissions") == "everybody";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
39
modules/ecard/helpers/ecard_block.php
Normal file
39
modules/ecard/helpers/ecard_block.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
|
/**
|
||||||
|
* Gallery - a web based photo album viewer and editor
|
||||||
|
* Copyright (C) 2000-2010 Bharat Mediratta
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
class ecard_block_Core {
|
||||||
|
static function get_site_list() {
|
||||||
|
return array("ecard" => t("eCard"));
|
||||||
|
}
|
||||||
|
|
||||||
|
static function get($block_id, $theme) {
|
||||||
|
$block = "";
|
||||||
|
switch ($block_id) {
|
||||||
|
case "ecard":
|
||||||
|
if ($theme->item() && $theme->item()->is_photo() && module::get_var("ecard", "location") == "sidebar") {
|
||||||
|
$block = new Block();
|
||||||
|
$block->css_id = "g-send-ecard";
|
||||||
|
$block->title = t("eCard");
|
||||||
|
$block->content = new View("ecard_block.html");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return $block;
|
||||||
|
}
|
||||||
|
}
|
40
modules/ecard/helpers/ecard_event.php
Normal file
40
modules/ecard/helpers/ecard_event.php
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
|
/**
|
||||||
|
* Gallery - a web based photo album viewer and editor
|
||||||
|
* Copyright (C) 2000-2010 Bharat Mediratta
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
class ecard_event_Core {
|
||||||
|
static function admin_menu($menu, $theme) {
|
||||||
|
$menu->get("settings_menu")
|
||||||
|
->append(Menu::factory("link")
|
||||||
|
->id("ecard")
|
||||||
|
->label(t("eCard settings"))
|
||||||
|
->url(url::site("admin/ecard")));
|
||||||
|
}
|
||||||
|
|
||||||
|
static function photo_menu($menu, $theme) {
|
||||||
|
if (module::get_var("ecard", "location") == "top") {
|
||||||
|
$item = $theme->item();
|
||||||
|
$menu->append(Menu::factory("link")
|
||||||
|
->id("ecard")
|
||||||
|
->label(t("Send as eCard"))
|
||||||
|
->url(url::site("ecard/form_send/{$item->id}"))
|
||||||
|
->css_class("g-dialog-link ui-icon-ecard")
|
||||||
|
->css_id("g-send-ecard"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
30
modules/ecard/helpers/ecard_installer.php
Normal file
30
modules/ecard/helpers/ecard_installer.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
|
/**
|
||||||
|
* Gallery - a web based photo album viewer and editor
|
||||||
|
* Copyright (C) 2000-2010 Bharat Mediratta
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
class ecard_installer {
|
||||||
|
static function install() {
|
||||||
|
module::set_var("ecard", "subject", "You have been sent an eCard");
|
||||||
|
module::set_var("ecard", "message",
|
||||||
|
"Hello %toname, \r\n%fromname has sent you an eCard. " .
|
||||||
|
"Click the image to be taken to the gallery.");
|
||||||
|
module::set_var("ecard", "bcc", "");
|
||||||
|
module::set_var("ecard", "access_permissions", "everybody");
|
||||||
|
module::set_version("ecard", 3);
|
||||||
|
}
|
||||||
|
}
|
24
modules/ecard/helpers/ecard_theme.php
Normal file
24
modules/ecard/helpers/ecard_theme.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
|
/**
|
||||||
|
* Gallery - a web based photo album viewer and editor
|
||||||
|
* Copyright (C) 2000-2010 Bharat Mediratta
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
class ecard_theme_Core {
|
||||||
|
static function head($theme) {
|
||||||
|
$theme->css("ecard.css");
|
||||||
|
}
|
||||||
|
}
|
BIN
modules/ecard/images/email_go.png
Normal file
BIN
modules/ecard/images/email_go.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 754 B |
912
modules/ecard/lib/mime.php
Normal file
912
modules/ecard/lib/mime.php
Normal file
@ -0,0 +1,912 @@
|
|||||||
|
<?php
|
||||||
|
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||||
|
// +-----------------------------------------------------------------------+
|
||||||
|
// | Copyright (c) 2002-2003 Richard Heyes |
|
||||||
|
// | Copyright (c) 2003-2005 The PHP Group |
|
||||||
|
// | All rights reserved. |
|
||||||
|
// | |
|
||||||
|
// | Redistribution and use in source and binary forms, with or without |
|
||||||
|
// | modification, are permitted provided that the following conditions |
|
||||||
|
// | are met: |
|
||||||
|
// | |
|
||||||
|
// | o Redistributions of source code must retain the above copyright |
|
||||||
|
// | notice, this list of conditions and the following disclaimer. |
|
||||||
|
// | o Redistributions in binary form must reproduce the above copyright |
|
||||||
|
// | notice, this list of conditions and the following disclaimer in the |
|
||||||
|
// | documentation and/or other materials provided with the distribution.|
|
||||||
|
// | o The names of the authors may not be used to endorse or promote |
|
||||||
|
// | products derived from this software without specific prior written |
|
||||||
|
// | permission. |
|
||||||
|
// | |
|
||||||
|
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
||||||
|
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
||||||
|
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
||||||
|
// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
||||||
|
// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
||||||
|
// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
||||||
|
// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
||||||
|
// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
||||||
|
// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
||||||
|
// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
||||||
|
// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||||
|
// | |
|
||||||
|
// +-----------------------------------------------------------------------+
|
||||||
|
// | Author: Richard Heyes <richard@phpguru.org> |
|
||||||
|
// | Tomas V.V.Cox <cox@idecnet.com> (port to PEAR) |
|
||||||
|
// +-----------------------------------------------------------------------+
|
||||||
|
//
|
||||||
|
|
||||||
|
if (!class_exists('Mail_mimePart')) {
|
||||||
|
require_once(MODPATH . "ecard/lib/mimePart.php");
|
||||||
|
}
|
||||||
|
if (class_exists('Mail_mime')) return;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mime mail composer class. Can handle: text and html bodies, embedded html
|
||||||
|
* images and attachments.
|
||||||
|
* Documentation and examples of this class are avaible here:
|
||||||
|
* http://pear.php.net/manual/
|
||||||
|
*
|
||||||
|
* @notes This class is based on HTML Mime Mail class from
|
||||||
|
* Richard Heyes <richard@phpguru.org> which was based also
|
||||||
|
* in the mime_mail.class by Tobias Ratschiller <tobias@dnet.it> and
|
||||||
|
* Sascha Schumann <sascha@schumann.cx>
|
||||||
|
*
|
||||||
|
* @author Richard Heyes <richard.heyes@heyes-computing.net>
|
||||||
|
* @author Tomas V.V.Cox <cox@idecnet.com>
|
||||||
|
* @package Mail
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
class Mail_mime
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Contains the plain text part of the email
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
var $_txtbody;
|
||||||
|
/**
|
||||||
|
* Contains the html part of the email
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
var $_htmlbody;
|
||||||
|
/**
|
||||||
|
* contains the mime encoded text
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
var $_mime;
|
||||||
|
/**
|
||||||
|
* contains the multipart content
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
var $_multipart;
|
||||||
|
/**
|
||||||
|
* list of the attached images
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
var $_html_images = array();
|
||||||
|
/**
|
||||||
|
* list of the attachements
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
var $_parts = array();
|
||||||
|
/**
|
||||||
|
* Build parameters
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
var $_build_params = array();
|
||||||
|
/**
|
||||||
|
* Headers for the mail
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
var $_headers = array();
|
||||||
|
/**
|
||||||
|
* End Of Line sequence (for serialize)
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
var $_eol;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor function
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function Mail_mime($crlf = "\r\n")
|
||||||
|
{
|
||||||
|
$this->_setEOL($crlf);
|
||||||
|
$this->_build_params = array(
|
||||||
|
'head_encoding' => 'quoted-printable',
|
||||||
|
'text_encoding' => '7bit',
|
||||||
|
'html_encoding' => 'quoted-printable',
|
||||||
|
'7bit_wrap' => 998,
|
||||||
|
'html_charset' => 'ISO-8859-1',
|
||||||
|
'text_charset' => 'ISO-8859-1',
|
||||||
|
'head_charset' => 'ISO-8859-1'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wakeup (unserialize) - re-sets EOL constant
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
function __wakeup()
|
||||||
|
{
|
||||||
|
$this->_setEOL($this->_eol);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accessor function to set the body text. Body text is used if
|
||||||
|
* it's not an html mail being sent or else is used to fill the
|
||||||
|
* text/plain part that emails clients who don't support
|
||||||
|
* html should show.
|
||||||
|
*
|
||||||
|
* @param string $data Either a string or
|
||||||
|
* the file name with the contents
|
||||||
|
* @param bool $isfile If true the first param should be treated
|
||||||
|
* as a file name, else as a string (default)
|
||||||
|
* @param bool $append If true the text or file is appended to
|
||||||
|
* the existing body, else the old body is
|
||||||
|
* overwritten
|
||||||
|
* @return mixed true on success or PEAR_Error object
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function setTXTBody($data, $isfile = false, $append = false)
|
||||||
|
{
|
||||||
|
if (!$isfile) {
|
||||||
|
if (!$append) {
|
||||||
|
$this->_txtbody = $data;
|
||||||
|
} else {
|
||||||
|
$this->_txtbody .= $data;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$cont = $this->_file2str($data);
|
||||||
|
if (!isset($cont) /*PEAR::isError($cont)*/) {
|
||||||
|
return $cont;
|
||||||
|
}
|
||||||
|
if (!$append) {
|
||||||
|
$this->_txtbody = $cont;
|
||||||
|
} else {
|
||||||
|
$this->_txtbody .= $cont;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a html part to the mail
|
||||||
|
*
|
||||||
|
* @param string $data Either a string or the file name with the
|
||||||
|
* contents
|
||||||
|
* @param bool $isfile If true the first param should be treated
|
||||||
|
* as a file name, else as a string (default)
|
||||||
|
* @return mixed true on success or PEAR_Error object
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function setHTMLBody($data, $isfile = false)
|
||||||
|
{
|
||||||
|
if (!$isfile) {
|
||||||
|
$this->_htmlbody = $data;
|
||||||
|
} else {
|
||||||
|
$cont = $this->_file2str($data);
|
||||||
|
if (!isset($cont) /*PEAR::isError($cont)*/) {
|
||||||
|
return $cont;
|
||||||
|
}
|
||||||
|
$this->_htmlbody = $cont;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an image to the list of embedded images.
|
||||||
|
*
|
||||||
|
* @param string $file The image file name OR image data itself
|
||||||
|
* @param string $c_type The content type
|
||||||
|
* @param string $name The filename of the image.
|
||||||
|
* Only use if $file is the image data
|
||||||
|
* @param bool $isfilename Whether $file is a filename or not
|
||||||
|
* Defaults to true
|
||||||
|
* @return mixed true on success or PEAR_Error object
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function addHTMLImage($file, $c_type='application/octet-stream',
|
||||||
|
$name = '', $isfilename = true)
|
||||||
|
{
|
||||||
|
$filedata = ($isfilename === true) ? $this->_file2str($file)
|
||||||
|
: $file;
|
||||||
|
if ($isfilename === true) {
|
||||||
|
$filename = ($name == '' ? $file : $name);
|
||||||
|
} else {
|
||||||
|
$filename = $name;
|
||||||
|
}
|
||||||
|
if (!isset($filedata) /*PEAR::isError($filedata)*/) {
|
||||||
|
return $filedata;
|
||||||
|
}
|
||||||
|
$this->_html_images[] = array(
|
||||||
|
'body' => $filedata,
|
||||||
|
'name' => $filename,
|
||||||
|
'c_type' => $c_type,
|
||||||
|
'cid' => md5(uniqid(time()))
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a file to the list of attachments.
|
||||||
|
*
|
||||||
|
* @param string $file The file name of the file to attach
|
||||||
|
* OR the file contents itself
|
||||||
|
* @param string $c_type The content type
|
||||||
|
* @param string $name The filename of the attachment
|
||||||
|
* Only use if $file is the contents
|
||||||
|
* @param bool $isFilename Whether $file is a filename or not
|
||||||
|
* Defaults to true
|
||||||
|
* @param string $encoding The type of encoding to use.
|
||||||
|
* Defaults to base64.
|
||||||
|
* Possible values: 7bit, 8bit, base64,
|
||||||
|
* or quoted-printable.
|
||||||
|
* @param string $disposition The content-disposition of this file
|
||||||
|
* Defaults to attachment.
|
||||||
|
* Possible values: attachment, inline.
|
||||||
|
* @param string $charset The character set used in the filename
|
||||||
|
* of this attachment.
|
||||||
|
* @return mixed true on success or PEAR_Error object
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function addAttachment($file, $c_type = 'application/octet-stream',
|
||||||
|
$name = '', $isfilename = true,
|
||||||
|
$encoding = 'base64',
|
||||||
|
$disposition = 'attachment', $charset = '')
|
||||||
|
{
|
||||||
|
$filedata = ($isfilename === true) ? $this->_file2str($file)
|
||||||
|
: $file;
|
||||||
|
if ($isfilename === true) {
|
||||||
|
// Force the name the user supplied, otherwise use $file
|
||||||
|
$filename = (!empty($name)) ? $name : $file;
|
||||||
|
} else {
|
||||||
|
$filename = $name;
|
||||||
|
}
|
||||||
|
if (empty($filename)) {
|
||||||
|
$err = null; /*PEAR::raiseError(
|
||||||
|
"The supplied filename for the attachment can't be empty"
|
||||||
|
);*/
|
||||||
|
return $err;
|
||||||
|
}
|
||||||
|
$filename = basename($filename);
|
||||||
|
if (!isset($filedata) /*PEAR::isError($filedata)*/) {
|
||||||
|
return $filedata;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->_parts[] = array(
|
||||||
|
'body' => $filedata,
|
||||||
|
'name' => $filename,
|
||||||
|
'c_type' => $c_type,
|
||||||
|
'encoding' => $encoding,
|
||||||
|
'charset' => $charset,
|
||||||
|
'disposition' => $disposition
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the contents of the given file name as string
|
||||||
|
*
|
||||||
|
* @param string $file_name path of file to process
|
||||||
|
* @return string contents of $file_name
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
function &_file2str($file_name)
|
||||||
|
{
|
||||||
|
if (!is_readable($file_name)) {
|
||||||
|
$err = null; //PEAR::raiseError('File is not readable ' . $file_name);
|
||||||
|
return $err;
|
||||||
|
}
|
||||||
|
if (!$fd = fopen($file_name, 'rb')) {
|
||||||
|
$err = null; //PEAR::raiseError('Could not open ' . $file_name);
|
||||||
|
return $err;
|
||||||
|
}
|
||||||
|
$filesize = filesize($file_name);
|
||||||
|
if ($filesize == 0){
|
||||||
|
$cont = "";
|
||||||
|
}else{
|
||||||
|
if ($magic_quote_setting = get_magic_quotes_runtime()){
|
||||||
|
@set_magic_quotes_runtime(0);
|
||||||
|
}
|
||||||
|
$cont = fread($fd, $filesize);
|
||||||
|
if ($magic_quote_setting){
|
||||||
|
@set_magic_quotes_runtime($magic_quote_setting);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose($fd);
|
||||||
|
return $cont;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a text subpart to the mimePart object and
|
||||||
|
* returns it during the build process.
|
||||||
|
*
|
||||||
|
* @param mixed The object to add the part to, or
|
||||||
|
* null if a new object is to be created.
|
||||||
|
* @param string The text to add.
|
||||||
|
* @return object The text mimePart object
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
function &_addTextPart(&$obj, $text)
|
||||||
|
{
|
||||||
|
$params['content_type'] = 'text/plain';
|
||||||
|
$params['encoding'] = $this->_build_params['text_encoding'];
|
||||||
|
$params['charset'] = $this->_build_params['text_charset'];
|
||||||
|
if (is_object($obj)) {
|
||||||
|
$ret = $obj->addSubpart($text, $params);
|
||||||
|
return $ret;
|
||||||
|
} else {
|
||||||
|
$ret = new Mail_mimePart($text, $params);
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a html subpart to the mimePart object and
|
||||||
|
* returns it during the build process.
|
||||||
|
*
|
||||||
|
* @param mixed The object to add the part to, or
|
||||||
|
* null if a new object is to be created.
|
||||||
|
* @return object The html mimePart object
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
function &_addHtmlPart(&$obj)
|
||||||
|
{
|
||||||
|
$params['content_type'] = 'text/html';
|
||||||
|
$params['encoding'] = $this->_build_params['html_encoding'];
|
||||||
|
$params['charset'] = $this->_build_params['html_charset'];
|
||||||
|
if (is_object($obj)) {
|
||||||
|
$ret = $obj->addSubpart($this->_htmlbody, $params);
|
||||||
|
return $ret;
|
||||||
|
} else {
|
||||||
|
$ret = new Mail_mimePart($this->_htmlbody, $params);
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new mimePart object, using multipart/mixed as
|
||||||
|
* the initial content-type and returns it during the
|
||||||
|
* build process.
|
||||||
|
*
|
||||||
|
* @return object The multipart/mixed mimePart object
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
function &_addMixedPart()
|
||||||
|
{
|
||||||
|
$params['content_type'] = 'multipart/mixed';
|
||||||
|
$ret = new Mail_mimePart('', $params);
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a multipart/alternative part to a mimePart
|
||||||
|
* object (or creates one), and returns it during
|
||||||
|
* the build process.
|
||||||
|
*
|
||||||
|
* @param mixed The object to add the part to, or
|
||||||
|
* null if a new object is to be created.
|
||||||
|
* @return object The multipart/mixed mimePart object
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
function &_addAlternativePart(&$obj)
|
||||||
|
{
|
||||||
|
$params['content_type'] = 'multipart/alternative';
|
||||||
|
if (is_object($obj)) {
|
||||||
|
return $obj->addSubpart('', $params);
|
||||||
|
} else {
|
||||||
|
$ret = new Mail_mimePart('', $params);
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a multipart/related part to a mimePart
|
||||||
|
* object (or creates one), and returns it during
|
||||||
|
* the build process.
|
||||||
|
*
|
||||||
|
* @param mixed The object to add the part to, or
|
||||||
|
* null if a new object is to be created
|
||||||
|
* @return object The multipart/mixed mimePart object
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
function &_addRelatedPart(&$obj)
|
||||||
|
{
|
||||||
|
$params['content_type'] = 'multipart/related';
|
||||||
|
if (is_object($obj)) {
|
||||||
|
return $obj->addSubpart('', $params);
|
||||||
|
} else {
|
||||||
|
$ret = new Mail_mimePart('', $params);
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an html image subpart to a mimePart object
|
||||||
|
* and returns it during the build process.
|
||||||
|
*
|
||||||
|
* @param object The mimePart to add the image to
|
||||||
|
* @param array The image information
|
||||||
|
* @return object The image mimePart object
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
function &_addHtmlImagePart(&$obj, $value)
|
||||||
|
{
|
||||||
|
$params['content_type'] = $value['c_type'] . '; ' .
|
||||||
|
'name="' . $value['name'] . '"';
|
||||||
|
$params['encoding'] = 'base64';
|
||||||
|
$params['disposition'] = 'inline';
|
||||||
|
$params['dfilename'] = $value['name'];
|
||||||
|
$params['cid'] = $value['cid'];
|
||||||
|
$ret = $obj->addSubpart($value['body'], $params);
|
||||||
|
return $ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an attachment subpart to a mimePart object
|
||||||
|
* and returns it during the build process.
|
||||||
|
*
|
||||||
|
* @param object The mimePart to add the image to
|
||||||
|
* @param array The attachment information
|
||||||
|
* @return object The image mimePart object
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
function &_addAttachmentPart(&$obj, $value)
|
||||||
|
{
|
||||||
|
$params['dfilename'] = $value['name'];
|
||||||
|
$params['encoding'] = $value['encoding'];
|
||||||
|
if ($value['disposition'] != "inline") {
|
||||||
|
$fname = array("fname" => $value['name']);
|
||||||
|
$fname_enc = $this->_encodeHeaders($fname);
|
||||||
|
$params['dfilename'] = $fname_enc['fname'];
|
||||||
|
}
|
||||||
|
if ($value['charset']) {
|
||||||
|
$params['charset'] = $value['charset'];
|
||||||
|
}
|
||||||
|
$params['content_type'] = $value['c_type'] . '; ' .
|
||||||
|
'name="' . $params['dfilename'] . '"';
|
||||||
|
$params['disposition'] = isset($value['disposition']) ?
|
||||||
|
$value['disposition'] : 'attachment';
|
||||||
|
$ret = $obj->addSubpart($value['body'], $params);
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the complete e-mail, ready to send using an alternative
|
||||||
|
* mail delivery method. Note that only the mailpart that is made
|
||||||
|
* with Mail_Mime is created. This means that,
|
||||||
|
* YOU WILL HAVE NO TO: HEADERS UNLESS YOU SET IT YOURSELF
|
||||||
|
* using the $xtra_headers parameter!
|
||||||
|
*
|
||||||
|
* @param string $separation The separation etween these two parts.
|
||||||
|
* @param array $build_params The Build parameters passed to the
|
||||||
|
* &get() function. See &get for more info.
|
||||||
|
* @param array $xtra_headers The extra headers that should be passed
|
||||||
|
* to the &headers() function.
|
||||||
|
* See that function for more info.
|
||||||
|
* @param bool $overwrite Overwrite the existing headers with new.
|
||||||
|
* @return string The complete e-mail.
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function getMessage($separation = null, $build_params = null, $xtra_headers = null, $overwrite = false)
|
||||||
|
{
|
||||||
|
if ($separation === null)
|
||||||
|
{
|
||||||
|
$separation = MAIL_MIME_CRLF;
|
||||||
|
}
|
||||||
|
$body = $this->get($build_params);
|
||||||
|
$head = $this->txtHeaders($xtra_headers, $overwrite);
|
||||||
|
$mail = $head . $separation . $body;
|
||||||
|
return $mail;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the multipart message from the list ($this->_parts) and
|
||||||
|
* returns the mime content.
|
||||||
|
*
|
||||||
|
* @param array Build parameters that change the way the email
|
||||||
|
* is built. Should be associative. Can contain:
|
||||||
|
* head_encoding - What encoding to use for the headers.
|
||||||
|
* Options: quoted-printable or base64
|
||||||
|
* Default is quoted-printable
|
||||||
|
* text_encoding - What encoding to use for plain text
|
||||||
|
* Options: 7bit, 8bit, base64, or quoted-printable
|
||||||
|
* Default is 7bit
|
||||||
|
* html_encoding - What encoding to use for html
|
||||||
|
* Options: 7bit, 8bit, base64, or quoted-printable
|
||||||
|
* Default is quoted-printable
|
||||||
|
* 7bit_wrap - Number of characters before text is
|
||||||
|
* wrapped in 7bit encoding
|
||||||
|
* Default is 998
|
||||||
|
* html_charset - The character set to use for html.
|
||||||
|
* Default is iso-8859-1
|
||||||
|
* text_charset - The character set to use for text.
|
||||||
|
* Default is iso-8859-1
|
||||||
|
* head_charset - The character set to use for headers.
|
||||||
|
* Default is iso-8859-1
|
||||||
|
* @return string The mime content
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function &get($build_params = null)
|
||||||
|
{
|
||||||
|
if (isset($build_params)) {
|
||||||
|
while (list($key, $value) = each($build_params)) {
|
||||||
|
$this->_build_params[$key] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($this->_html_images) AND isset($this->_htmlbody)) {
|
||||||
|
foreach ($this->_html_images as $key => $value) {
|
||||||
|
$regex = array();
|
||||||
|
$regex[] = '#(\s)((?i)src|background|href(?-i))\s*=\s*(["\']?)' .
|
||||||
|
preg_quote($value['name'], '#') . '\3#';
|
||||||
|
$regex[] = '#(?i)url(?-i)\(\s*(["\']?)' .
|
||||||
|
preg_quote($value['name'], '#') . '\1\s*\)#';
|
||||||
|
$rep = array();
|
||||||
|
$rep[] = '\1\2=\3cid:' . $value['cid'] .'\3';
|
||||||
|
$rep[] = 'url(\1cid:' . $value['cid'] . '\2)';
|
||||||
|
$this->_htmlbody = preg_replace($regex, $rep,
|
||||||
|
$this->_htmlbody
|
||||||
|
);
|
||||||
|
$this->_html_images[$key]['name'] = basename($this->_html_images[$key]['name']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$null = null;
|
||||||
|
$attachments = !empty($this->_parts) ? true : false;
|
||||||
|
$html_images = !empty($this->_html_images) ? true : false;
|
||||||
|
$html = !empty($this->_htmlbody) ? true : false;
|
||||||
|
$text = (!$html AND !empty($this->_txtbody)) ? true : false;
|
||||||
|
|
||||||
|
switch (true) {
|
||||||
|
case $text AND !$attachments:
|
||||||
|
$message =& $this->_addTextPart($null, $this->_txtbody);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case !$text AND !$html AND $attachments:
|
||||||
|
$message =& $this->_addMixedPart();
|
||||||
|
for ($i = 0; $i < count($this->_parts); $i++) {
|
||||||
|
$this->_addAttachmentPart($message, $this->_parts[$i]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case $text AND $attachments:
|
||||||
|
$message =& $this->_addMixedPart();
|
||||||
|
$this->_addTextPart($message, $this->_txtbody);
|
||||||
|
for ($i = 0; $i < count($this->_parts); $i++) {
|
||||||
|
$this->_addAttachmentPart($message, $this->_parts[$i]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case $html AND !$attachments AND !$html_images:
|
||||||
|
if (isset($this->_txtbody)) {
|
||||||
|
$message =& $this->_addAlternativePart($null);
|
||||||
|
$this->_addTextPart($message, $this->_txtbody);
|
||||||
|
$this->_addHtmlPart($message);
|
||||||
|
} else {
|
||||||
|
$message =& $this->_addHtmlPart($null);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case $html AND !$attachments AND $html_images:
|
||||||
|
if (isset($this->_txtbody)) {
|
||||||
|
$message =& $this->_addAlternativePart($null);
|
||||||
|
$this->_addTextPart($message, $this->_txtbody);
|
||||||
|
$related =& $this->_addRelatedPart($message);
|
||||||
|
} else {
|
||||||
|
$message =& $this->_addRelatedPart($null);
|
||||||
|
$related =& $message;
|
||||||
|
}
|
||||||
|
$this->_addHtmlPart($related);
|
||||||
|
for ($i = 0; $i < count($this->_html_images); $i++) {
|
||||||
|
$this->_addHtmlImagePart($related, $this->_html_images[$i]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case $html AND $attachments AND !$html_images:
|
||||||
|
$message =& $this->_addMixedPart();
|
||||||
|
if (isset($this->_txtbody)) {
|
||||||
|
$alt =& $this->_addAlternativePart($message);
|
||||||
|
$this->_addTextPart($alt, $this->_txtbody);
|
||||||
|
$this->_addHtmlPart($alt);
|
||||||
|
} else {
|
||||||
|
$this->_addHtmlPart($message);
|
||||||
|
}
|
||||||
|
for ($i = 0; $i < count($this->_parts); $i++) {
|
||||||
|
$this->_addAttachmentPart($message, $this->_parts[$i]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case $html AND $attachments AND $html_images:
|
||||||
|
$message =& $this->_addMixedPart();
|
||||||
|
if (isset($this->_txtbody)) {
|
||||||
|
$alt =& $this->_addAlternativePart($message);
|
||||||
|
$this->_addTextPart($alt, $this->_txtbody);
|
||||||
|
$rel =& $this->_addRelatedPart($alt);
|
||||||
|
} else {
|
||||||
|
$rel =& $this->_addRelatedPart($message);
|
||||||
|
}
|
||||||
|
$this->_addHtmlPart($rel);
|
||||||
|
for ($i = 0; $i < count($this->_html_images); $i++) {
|
||||||
|
$this->_addHtmlImagePart($rel, $this->_html_images[$i]);
|
||||||
|
}
|
||||||
|
for ($i = 0; $i < count($this->_parts); $i++) {
|
||||||
|
$this->_addAttachmentPart($message, $this->_parts[$i]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($message)) {
|
||||||
|
$output = $message->encode();
|
||||||
|
$this->_headers = array_merge($this->_headers,
|
||||||
|
$output['headers']);
|
||||||
|
$body = $output['body'];
|
||||||
|
return $body;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$ret = false;
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array with the headers needed to prepend to the email
|
||||||
|
* (MIME-Version and Content-Type). Format of argument is:
|
||||||
|
* $array['header-name'] = 'header-value';
|
||||||
|
*
|
||||||
|
* @param array $xtra_headers Assoc array with any extra headers.
|
||||||
|
* Optional.
|
||||||
|
* @param bool $overwrite Overwrite already existing headers.
|
||||||
|
* @return array Assoc array with the mime headers
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function &headers($xtra_headers = null, $overwrite = false)
|
||||||
|
{
|
||||||
|
// Content-Type header should already be present,
|
||||||
|
// So just add mime version header
|
||||||
|
$headers['MIME-Version'] = '1.0';
|
||||||
|
if (isset($xtra_headers)) {
|
||||||
|
$headers = array_merge($headers, $xtra_headers);
|
||||||
|
}
|
||||||
|
if ($overwrite){
|
||||||
|
$this->_headers = array_merge($this->_headers, $headers);
|
||||||
|
}else{
|
||||||
|
$this->_headers = array_merge($headers, $this->_headers);
|
||||||
|
}
|
||||||
|
|
||||||
|
$encodedHeaders = $this->_encodeHeaders($this->_headers);
|
||||||
|
return $encodedHeaders;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the text version of the headers
|
||||||
|
* (usefull if you want to use the PHP mail() function)
|
||||||
|
*
|
||||||
|
* @param array $xtra_headers Assoc array with any extra headers.
|
||||||
|
* Optional.
|
||||||
|
* @param bool $overwrite Overwrite the existing heaers with new.
|
||||||
|
* @return string Plain text headers
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function txtHeaders($xtra_headers = null, $overwrite = false)
|
||||||
|
{
|
||||||
|
$headers = $this->headers($xtra_headers, $overwrite);
|
||||||
|
$ret = '';
|
||||||
|
foreach ($headers as $key => $val) {
|
||||||
|
$ret .= "$key: $val" . MAIL_MIME_CRLF;
|
||||||
|
}
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the Subject header
|
||||||
|
*
|
||||||
|
* @param string $subject String to set the subject to
|
||||||
|
* access public
|
||||||
|
*/
|
||||||
|
function setSubject($subject)
|
||||||
|
{
|
||||||
|
$this->_headers['Subject'] = $subject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set an email to the From (the sender) header
|
||||||
|
*
|
||||||
|
* @param string $email The email direction to add
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function setFrom($email)
|
||||||
|
{
|
||||||
|
$this->_headers['From'] = $email;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an email to the Cc (carbon copy) header
|
||||||
|
* (multiple calls to this method are allowed)
|
||||||
|
*
|
||||||
|
* @param string $email The email direction to add
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function addCc($email)
|
||||||
|
{
|
||||||
|
if (isset($this->_headers['Cc'])) {
|
||||||
|
$this->_headers['Cc'] .= ", $email";
|
||||||
|
} else {
|
||||||
|
$this->_headers['Cc'] = $email;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an email to the Bcc (blank carbon copy) header
|
||||||
|
* (multiple calls to this method are allowed)
|
||||||
|
*
|
||||||
|
* @param string $email The email direction to add
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function addBcc($email)
|
||||||
|
{
|
||||||
|
if (isset($this->_headers['Bcc'])) {
|
||||||
|
$this->_headers['Bcc'] .= ", $email";
|
||||||
|
} else {
|
||||||
|
$this->_headers['Bcc'] = $email;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Since the PHP send function requires you to specifiy
|
||||||
|
* recipients (To: header) separately from the other
|
||||||
|
* headers, the To: header is not properly encoded.
|
||||||
|
* To fix this, you can use this public method to
|
||||||
|
* encode your recipients before sending to the send
|
||||||
|
* function
|
||||||
|
*
|
||||||
|
* @param string $recipients A comma-delimited list of recipients
|
||||||
|
* @return string Encoded data
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function encodeRecipients($recipients)
|
||||||
|
{
|
||||||
|
$input = array("To" => $recipients);
|
||||||
|
$retval = $this->_encodeHeaders($input);
|
||||||
|
return $retval["To"] ;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encodes a header as per RFC2047
|
||||||
|
*
|
||||||
|
* @param array $input The header data to encode
|
||||||
|
* @return array Encoded data
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
function _encodeHeaders($input)
|
||||||
|
{
|
||||||
|
foreach ($input as $hdr_name => $hdr_value) {
|
||||||
|
if (function_exists('iconv_mime_encode') && preg_match('#[\x80-\xFF]{1}#', $hdr_value)){
|
||||||
|
$imePref = array();
|
||||||
|
if ($this->_build_params['head_encoding'] == 'base64'){
|
||||||
|
$imePrefs['scheme'] = 'B';
|
||||||
|
}else{
|
||||||
|
$imePrefs['scheme'] = 'Q';
|
||||||
|
}
|
||||||
|
$imePrefs['input-charset'] = $this->_build_params['head_charset'];
|
||||||
|
$imePrefs['output-charset'] = $this->_build_params['head_charset'];
|
||||||
|
$hdr_value = iconv_mime_encode($hdr_name, $hdr_value, $imePrefs);
|
||||||
|
$hdr_value = preg_replace("#^{$hdr_name}\:\ #", "", $hdr_value);
|
||||||
|
}elseif (preg_match('#[\x80-\xFF]{1}#', $hdr_value)){
|
||||||
|
//This header contains non ASCII chars and should be encoded.
|
||||||
|
switch ($this->_build_params['head_encoding']) {
|
||||||
|
case 'base64':
|
||||||
|
//Base64 encoding has been selected.
|
||||||
|
|
||||||
|
//Generate the header using the specified params and dynamicly
|
||||||
|
//determine the maximum length of such strings.
|
||||||
|
//75 is the value specified in the RFC. The -2 is there so
|
||||||
|
//the later regexp doesn't break any of the translated chars.
|
||||||
|
$prefix = '=?' . $this->_build_params['head_charset'] . '?B?';
|
||||||
|
$suffix = '?=';
|
||||||
|
$maxLength = 75 - strlen($prefix . $suffix) - 2;
|
||||||
|
$maxLength1stLine = $maxLength - strlen($hdr_name);
|
||||||
|
|
||||||
|
//Base64 encode the entire string
|
||||||
|
$hdr_value = base64_encode($hdr_value);
|
||||||
|
|
||||||
|
//This regexp will break base64-encoded text at every
|
||||||
|
//$maxLength but will not break any encoded letters.
|
||||||
|
$reg1st = "|.{0,$maxLength1stLine}[^\=][^\=]|";
|
||||||
|
$reg2nd = "|.{0,$maxLength}[^\=][^\=]|";
|
||||||
|
break;
|
||||||
|
case 'quoted-printable':
|
||||||
|
default:
|
||||||
|
//quoted-printable encoding has been selected
|
||||||
|
|
||||||
|
//Generate the header using the specified params and dynamicly
|
||||||
|
//determine the maximum length of such strings.
|
||||||
|
//75 is the value specified in the RFC. The -2 is there so
|
||||||
|
//the later regexp doesn't break any of the translated chars.
|
||||||
|
$prefix = '=?' . $this->_build_params['head_charset'] . '?Q?';
|
||||||
|
$suffix = '?=';
|
||||||
|
$maxLength = 75 - strlen($prefix . $suffix) - 2;
|
||||||
|
$maxLength1stLine = $maxLength - strlen($hdr_name);
|
||||||
|
|
||||||
|
//Replace all special characters used by the encoder.
|
||||||
|
$search = array("=", "_", "?", " ");
|
||||||
|
$replace = array("=3D", "=5F", "=3F", "_");
|
||||||
|
$hdr_value = str_replace($search, $replace, $hdr_value);
|
||||||
|
|
||||||
|
//Replace all extended characters (\x80-xFF) with their
|
||||||
|
//ASCII values.
|
||||||
|
$hdr_value = preg_replace(
|
||||||
|
'#([\x80-\xFF])#e',
|
||||||
|
'"=" . strtoupper(dechex(ord("\1")))',
|
||||||
|
$hdr_value
|
||||||
|
);
|
||||||
|
//This regexp will break QP-encoded text at every $maxLength
|
||||||
|
//but will not break any encoded letters.
|
||||||
|
$reg1st = "|(.{0,$maxLength})[^\=]|";
|
||||||
|
$reg2nd = "|(.{0,$maxLength})[^\=]|";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//Begin with the regexp for the first line.
|
||||||
|
$reg = $reg1st;
|
||||||
|
$output = "";
|
||||||
|
while ($hdr_value) {
|
||||||
|
//Split translated string at every $maxLength
|
||||||
|
//But make sure not to break any translated chars.
|
||||||
|
$found = preg_match($reg, $hdr_value, $matches);
|
||||||
|
|
||||||
|
//After this first line, we need to use a different
|
||||||
|
//regexp for the first line.
|
||||||
|
$reg = $reg2nd;
|
||||||
|
|
||||||
|
//Save the found part and encapsulate it in the
|
||||||
|
//prefix & suffix. Then remove the part from the
|
||||||
|
//$hdr_value variable.
|
||||||
|
if ($found){
|
||||||
|
$part = $matches[0];
|
||||||
|
$hdr_value = substr($hdr_value, strlen($matches[0]));
|
||||||
|
}else{
|
||||||
|
$part = $hdr_value;
|
||||||
|
$hdr_value = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
//RFC 2047 specifies that any split header should be seperated
|
||||||
|
//by a CRLF SPACE.
|
||||||
|
if ($output){
|
||||||
|
$output .= "\r\n ";
|
||||||
|
}
|
||||||
|
$output .= $prefix . $part . $suffix;
|
||||||
|
}
|
||||||
|
$hdr_value = $output;
|
||||||
|
}
|
||||||
|
$input[$hdr_name] = $hdr_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $input;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the object's end-of-line and define the constant if applicable
|
||||||
|
*
|
||||||
|
* @param string $eol End Of Line sequence
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
function _setEOL($eol)
|
||||||
|
{
|
||||||
|
$this->_eol = $eol;
|
||||||
|
if (!defined('MAIL_MIME_CRLF')) {
|
||||||
|
define('MAIL_MIME_CRLF', $this->_eol, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // End of class
|
||||||
|
?>
|
351
modules/ecard/lib/mimePart.php
Normal file
351
modules/ecard/lib/mimePart.php
Normal file
@ -0,0 +1,351 @@
|
|||||||
|
<?php
|
||||||
|
// +-----------------------------------------------------------------------+
|
||||||
|
// | Copyright (c) 2002-2003 Richard Heyes |
|
||||||
|
// | All rights reserved. |
|
||||||
|
// | |
|
||||||
|
// | Redistribution and use in source and binary forms, with or without |
|
||||||
|
// | modification, are permitted provided that the following conditions |
|
||||||
|
// | are met: |
|
||||||
|
// | |
|
||||||
|
// | o Redistributions of source code must retain the above copyright |
|
||||||
|
// | notice, this list of conditions and the following disclaimer. |
|
||||||
|
// | o Redistributions in binary form must reproduce the above copyright |
|
||||||
|
// | notice, this list of conditions and the following disclaimer in the |
|
||||||
|
// | documentation and/or other materials provided with the distribution.|
|
||||||
|
// | o The names of the authors may not be used to endorse or promote |
|
||||||
|
// | products derived from this software without specific prior written |
|
||||||
|
// | permission. |
|
||||||
|
// | |
|
||||||
|
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
||||||
|
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
||||||
|
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
||||||
|
// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
||||||
|
// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
||||||
|
// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
||||||
|
// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
||||||
|
// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
||||||
|
// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
||||||
|
// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
||||||
|
// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||||
|
// | |
|
||||||
|
// +-----------------------------------------------------------------------+
|
||||||
|
// | Author: Richard Heyes <richard@phpguru.org> |
|
||||||
|
// +-----------------------------------------------------------------------+
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Raw mime encoding class
|
||||||
|
*
|
||||||
|
* What is it?
|
||||||
|
* This class enables you to manipulate and build
|
||||||
|
* a mime email from the ground up.
|
||||||
|
*
|
||||||
|
* Why use this instead of mime.php?
|
||||||
|
* mime.php is a userfriendly api to this class for
|
||||||
|
* people who aren't interested in the internals of
|
||||||
|
* mime mail. This class however allows full control
|
||||||
|
* over the email.
|
||||||
|
*
|
||||||
|
* Eg.
|
||||||
|
*
|
||||||
|
* // Since multipart/mixed has no real body, (the body is
|
||||||
|
* // the subpart), we set the body argument to blank.
|
||||||
|
*
|
||||||
|
* $params['content_type'] = 'multipart/mixed';
|
||||||
|
* $email = new Mail_mimePart('', $params);
|
||||||
|
*
|
||||||
|
* // Here we add a text part to the multipart we have
|
||||||
|
* // already. Assume $body contains plain text.
|
||||||
|
*
|
||||||
|
* $params['content_type'] = 'text/plain';
|
||||||
|
* $params['encoding'] = '7bit';
|
||||||
|
* $text = $email->addSubPart($body, $params);
|
||||||
|
*
|
||||||
|
* // Now add an attachment. Assume $attach is
|
||||||
|
* the contents of the attachment
|
||||||
|
*
|
||||||
|
* $params['content_type'] = 'application/zip';
|
||||||
|
* $params['encoding'] = 'base64';
|
||||||
|
* $params['disposition'] = 'attachment';
|
||||||
|
* $params['dfilename'] = 'example.zip';
|
||||||
|
* $attach =& $email->addSubPart($body, $params);
|
||||||
|
*
|
||||||
|
* // Now build the email. Note that the encode
|
||||||
|
* // function returns an associative array containing two
|
||||||
|
* // elements, body and headers. You will need to add extra
|
||||||
|
* // headers, (eg. Mime-Version) before sending.
|
||||||
|
*
|
||||||
|
* $email = $message->encode();
|
||||||
|
* $email['headers'][] = 'Mime-Version: 1.0';
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Further examples are available at http://www.phpguru.org
|
||||||
|
*
|
||||||
|
* TODO:
|
||||||
|
* - Set encode() to return the $obj->encoded if encode()
|
||||||
|
* has already been run. Unless a flag is passed to specifically
|
||||||
|
* re-build the message.
|
||||||
|
*
|
||||||
|
* @author Richard Heyes <richard@phpguru.org>
|
||||||
|
* @version $Revision: 1.13 $
|
||||||
|
* @package Mail
|
||||||
|
*/
|
||||||
|
|
||||||
|
class Mail_mimePart {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The encoding type of this part
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
var $_encoding;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An array of subparts
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
var $_subparts;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The output of this part after being built
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
var $_encoded;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Headers for this part
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
var $_headers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The body of this part (not encoded)
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
var $_body;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* Sets up the object.
|
||||||
|
*
|
||||||
|
* @param $body - The body of the mime part if any.
|
||||||
|
* @param $params - An associative array of parameters:
|
||||||
|
* content_type - The content type for this part eg multipart/mixed
|
||||||
|
* encoding - The encoding to use, 7bit, 8bit, base64, or quoted-printable
|
||||||
|
* cid - Content ID to apply
|
||||||
|
* disposition - Content disposition, inline or attachment
|
||||||
|
* dfilename - Optional filename parameter for content disposition
|
||||||
|
* description - Content description
|
||||||
|
* charset - Character set to use
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function Mail_mimePart($body = '', $params = array())
|
||||||
|
{
|
||||||
|
if (!defined('MAIL_MIMEPART_CRLF')) {
|
||||||
|
define('MAIL_MIMEPART_CRLF', defined('MAIL_MIME_CRLF') ? MAIL_MIME_CRLF : "\r\n", TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($params as $key => $value) {
|
||||||
|
switch ($key) {
|
||||||
|
case 'content_type':
|
||||||
|
$headers['Content-Type'] = $value . (isset($charset) ? '; charset="' . $charset . '"' : '');
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'encoding':
|
||||||
|
$this->_encoding = $value;
|
||||||
|
$headers['Content-Transfer-Encoding'] = $value;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'cid':
|
||||||
|
$headers['Content-ID'] = '<' . $value . '>';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'disposition':
|
||||||
|
$headers['Content-Disposition'] = $value . (isset($dfilename) ? '; filename="' . $dfilename . '"' : '');
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'dfilename':
|
||||||
|
if (isset($headers['Content-Disposition'])) {
|
||||||
|
$headers['Content-Disposition'] .= '; filename="' . $value . '"';
|
||||||
|
} else {
|
||||||
|
$dfilename = $value;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'description':
|
||||||
|
$headers['Content-Description'] = $value;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'charset':
|
||||||
|
if (isset($headers['Content-Type'])) {
|
||||||
|
$headers['Content-Type'] .= '; charset="' . $value . '"';
|
||||||
|
} else {
|
||||||
|
$charset = $value;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default content-type
|
||||||
|
if (!isset($headers['Content-Type'])) {
|
||||||
|
$headers['Content-Type'] = 'text/plain';
|
||||||
|
}
|
||||||
|
|
||||||
|
//Default encoding
|
||||||
|
if (!isset($this->_encoding)) {
|
||||||
|
$this->_encoding = '7bit';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assign stuff to member variables
|
||||||
|
$this->_encoded = array();
|
||||||
|
$this->_headers = $headers;
|
||||||
|
$this->_body = $body;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* encode()
|
||||||
|
*
|
||||||
|
* Encodes and returns the email. Also stores
|
||||||
|
* it in the encoded member variable
|
||||||
|
*
|
||||||
|
* @return An associative array containing two elements,
|
||||||
|
* body and headers. The headers element is itself
|
||||||
|
* an indexed array.
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function encode()
|
||||||
|
{
|
||||||
|
$encoded =& $this->_encoded;
|
||||||
|
|
||||||
|
if (!empty($this->_subparts)) {
|
||||||
|
srand((double)microtime()*1000000);
|
||||||
|
$boundary = '=_' . md5(rand() . microtime());
|
||||||
|
$this->_headers['Content-Type'] .= ';' . MAIL_MIMEPART_CRLF . "\t" . 'boundary="' . $boundary . '"';
|
||||||
|
|
||||||
|
// Add body parts to $subparts
|
||||||
|
for ($i = 0; $i < count($this->_subparts); $i++) {
|
||||||
|
$headers = array();
|
||||||
|
$tmp = $this->_subparts[$i]->encode();
|
||||||
|
foreach ($tmp['headers'] as $key => $value) {
|
||||||
|
$headers[] = $key . ': ' . $value;
|
||||||
|
}
|
||||||
|
$subparts[] = implode(MAIL_MIMEPART_CRLF, $headers) . MAIL_MIMEPART_CRLF . MAIL_MIMEPART_CRLF . $tmp['body'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$encoded['body'] = '--' . $boundary . MAIL_MIMEPART_CRLF .
|
||||||
|
implode('--' . $boundary . MAIL_MIMEPART_CRLF, $subparts) .
|
||||||
|
'--' . $boundary.'--' . MAIL_MIMEPART_CRLF;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$encoded['body'] = $this->_getEncodedData($this->_body, $this->_encoding) . MAIL_MIMEPART_CRLF;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add headers to $encoded
|
||||||
|
$encoded['headers'] =& $this->_headers;
|
||||||
|
|
||||||
|
return $encoded;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* &addSubPart()
|
||||||
|
*
|
||||||
|
* Adds a subpart to current mime part and returns
|
||||||
|
* a reference to it
|
||||||
|
*
|
||||||
|
* @param $body The body of the subpart, if any.
|
||||||
|
* @param $params The parameters for the subpart, same
|
||||||
|
* as the $params argument for constructor.
|
||||||
|
* @return A reference to the part you just added. It is
|
||||||
|
* crucial if using multipart/* in your subparts that
|
||||||
|
* you use =& in your script when calling this function,
|
||||||
|
* otherwise you will not be able to add further subparts.
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function &addSubPart($body, $params)
|
||||||
|
{
|
||||||
|
$this->_subparts[] = new Mail_mimePart($body, $params);
|
||||||
|
return $this->_subparts[count($this->_subparts) - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* _getEncodedData()
|
||||||
|
*
|
||||||
|
* Returns encoded data based upon encoding passed to it
|
||||||
|
*
|
||||||
|
* @param $data The data to encode.
|
||||||
|
* @param $encoding The encoding type to use, 7bit, base64,
|
||||||
|
* or quoted-printable.
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
function _getEncodedData($data, $encoding)
|
||||||
|
{
|
||||||
|
switch ($encoding) {
|
||||||
|
case '8bit':
|
||||||
|
case '7bit':
|
||||||
|
return $data;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'quoted-printable':
|
||||||
|
return $this->_quotedPrintableEncode($data);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'base64':
|
||||||
|
return rtrim(chunk_split(base64_encode($data), 76, MAIL_MIMEPART_CRLF));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* quoteadPrintableEncode()
|
||||||
|
*
|
||||||
|
* Encodes data to quoted-printable standard.
|
||||||
|
*
|
||||||
|
* @param $input The data to encode
|
||||||
|
* @param $line_max Optional max line length. Should
|
||||||
|
* not be more than 76 chars
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
function _quotedPrintableEncode($input , $line_max = 76)
|
||||||
|
{
|
||||||
|
$lines = preg_split("/\r?\n/", $input);
|
||||||
|
$eol = MAIL_MIMEPART_CRLF;
|
||||||
|
$escape = '=';
|
||||||
|
$output = '';
|
||||||
|
|
||||||
|
while(list(, $line) = each($lines)){
|
||||||
|
|
||||||
|
$linlen = strlen($line);
|
||||||
|
$newline = '';
|
||||||
|
|
||||||
|
for ($i = 0; $i < $linlen; $i++) {
|
||||||
|
$char = substr($line, $i, 1);
|
||||||
|
$dec = ord($char);
|
||||||
|
|
||||||
|
if (($dec == 32) AND ($i == ($linlen - 1))){ // convert space at eol only
|
||||||
|
$char = '=20';
|
||||||
|
|
||||||
|
} elseif(($dec == 9) AND ($i == ($linlen - 1))) { // convert tab at eol only
|
||||||
|
$char = '=09';
|
||||||
|
} elseif($dec == 9) {
|
||||||
|
; // Do nothing if a tab.
|
||||||
|
} elseif(($dec == 61) OR ($dec < 32 ) OR ($dec > 126)) {
|
||||||
|
$char = $escape . strtoupper(sprintf('%02s', dechex($dec)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((strlen($newline) + strlen($char)) >= $line_max) { // MAIL_MIMEPART_CRLF is not counted
|
||||||
|
$output .= $newline . $escape . $eol; // soft line break; " =\r\n" is okay
|
||||||
|
$newline = '';
|
||||||
|
}
|
||||||
|
$newline .= $char;
|
||||||
|
} // end of for
|
||||||
|
$output .= $newline . $eol;
|
||||||
|
}
|
||||||
|
$output = substr($output, 0, -1 * strlen($eol)); // Don't want last crlf
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
} // End of class
|
||||||
|
?>
|
4
modules/ecard/module.info
Normal file
4
modules/ecard/module.info
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
name = "E-Card"
|
||||||
|
description = "Send a photo as a postcard"
|
||||||
|
version = 3
|
||||||
|
|
7
modules/ecard/views/admin_ecard.html.php
Normal file
7
modules/ecard/views/admin_ecard.html.php
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?php defined("SYSPATH") or die("No direct script access.") ?>
|
||||||
|
<div class="g-block">
|
||||||
|
<h1> <?= t("eCard settings") ?> </h1>
|
||||||
|
<div class="g-block-content">
|
||||||
|
<?= $form ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user