eb8f20988e1073862a9b38116594227fae26dc4f
[yaffs-website] / lsolesen / pel / src / PelEntryCopyright.php
1 <?php
2
3 /**
4  * PEL: PHP Exif Library.
5  * A library with support for reading and
6  * writing all Exif headers in JPEG and TIFF images using PHP.
7  *
8  * Copyright (C) 2004, 2005, 2006, 2007 Martin Geisler.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program in the file COPYING; if not, write to the
22  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23  * Boston, MA 02110-1301 USA
24  */
25 namespace lsolesen\pel;
26
27 /**
28  * Classes used to hold ASCII strings.
29  *
30  * The classes defined here are to be used for Exif entries holding
31  * ASCII strings, such as {@link PelTag::MAKE}, {@link
32  * PelTag::SOFTWARE}, and {@link PelTag::DATE_TIME}. For
33  * entries holding normal textual ASCII strings the class {@link
34  * PelEntryAscii} should be used, but for entries holding
35  * timestamps the class {@link PelEntryTime} would be more
36  * convenient instead. Copyright information is handled by the {@link
37  * PelEntryCopyright} class.
38  *
39  * @author Martin Geisler <mgeisler@users.sourceforge.net>
40  * @license http://www.gnu.org/licenses/gpl.html GNU General Public
41  *          License (GPL)
42  * @package PEL
43  */
44
45 /**
46  * Class for holding copyright information.
47  *
48  * The Exif standard specifies a certain format for copyright
49  * information where the one {@link PelTag::COPYRIGHT copyright
50  * tag} holds both the photographer and editor copyrights, separated
51  * by a NULL character.
52  *
53  * This class is used to manipulate that tag so that the format is
54  * kept to the standard. A common use would be to add a new copyright
55  * tag to an image, since most cameras do not add this tag themselves.
56  * This would be done like this:
57  *
58  * <code>
59  * $entry = new PelEntryCopyright('Copyright, Martin Geisler, 2004');
60  * $ifd0->addEntry($entry);
61  * </code>
62  *
63  * Here we only set the photographer copyright, use the optional
64  * second argument to specify the editor copyright. If there is only
65  * an editor copyright, then let the first argument be the empty
66  * string.
67  *
68  * @author Martin Geisler <mgeisler@users.sourceforge.net>
69  * @package PEL
70  */
71 class PelEntryCopyright extends PelEntryAscii
72 {
73
74     /**
75      * The photographer copyright.
76      *
77      * @var string
78      */
79     private $photographer;
80
81     /**
82      * The editor copyright.
83      *
84      * @var string
85      */
86     private $editor;
87
88     /**
89      * Make a new entry for holding copyright information.
90      *
91      * @param
92      *            string the photographer copyright. Use the empty string
93      *            if there is no photographer copyright.
94      *
95      * @param
96      *            string the editor copyright. Use the empty string if
97      *            there is no editor copyright.
98      */
99     public function __construct($photographer = '', $editor = '')
100     {
101         parent::__construct(PelTag::COPYRIGHT);
102         $this->setValue($photographer, $editor);
103     }
104
105     /**
106      * Update the copyright information.
107      *
108      * @param
109      *            string the photographer copyright. Use the empty string
110      *            if there is no photographer copyright.
111      *
112      * @param
113      *            string the editor copyright. Use the empty string if
114      *            there is no editor copyright.
115      */
116     public function setValue($photographer = '', $editor = '')
117     {
118         $this->photographer = $photographer;
119         $this->editor = $editor;
120
121         if ($photographer == '' && $editor != '') {
122             $photographer = ' ';
123         }
124
125         if ($editor == '') {
126             parent::setValue($photographer);
127         } else {
128             parent::setValue($photographer . chr(0x00) . $editor);
129         }
130     }
131
132     /**
133      * Retrive the copyright information.
134      *
135      * The strings returned will be the same as the one used previously
136      * with either {@link __construct the constructor} or with {@link
137      * setValue}.
138      *
139      * @return array an array with two strings, the photographer and
140      *         editor copyrights. The two fields will be returned in that
141      *         order, so that the first array index will be the photographer
142      *         copyright, and the second will be the editor copyright.
143      */
144     public function getValue()
145     {
146         return array(
147             $this->photographer,
148             $this->editor
149         );
150     }
151
152     /**
153      * Return a text string with the copyright information.
154      *
155      * The photographer and editor copyright fields will be returned
156      * with a '-' in between if both copyright fields are present,
157      * otherwise only one of them will be returned.
158      *
159      * @param
160      *            boolean if false, then the strings '(Photographer)' and
161      *            '(Editor)' will be appended to the photographer and editor
162      *            copyright fields (if present), otherwise the fields will be
163      *            returned as is.
164      *
165      * @return string the copyright information in a string.
166      */
167     public function getText($brief = false)
168     {
169         if ($brief) {
170             $p = '';
171             $e = '';
172         } else {
173             $p = ' ' . Pel::tra('(Photographer)');
174             $e = ' ' . Pel::tra('(Editor)');
175         }
176
177         if ($this->photographer != '' && $this->editor != '') {
178             return $this->photographer . $p . ' - ' . $this->editor . $e;
179         }
180
181         if ($this->photographer != '') {
182             return $this->photographer . $p;
183         }
184
185         if ($this->editor != '') {
186             return $this->editor . $e;
187         }
188
189         return '';
190     }
191 }