20dc8bc3968111c538d9760507f0fb72610d7e07
[yaffs-website] / vendor / lsolesen / pel / src / PelEntryUserComment.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 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 data for Exif tags of format undefined.
29  *
30  * This file contains the base class {@link PelEntryUndefined} and
31  * the subclasses {@link PelEntryUserComment} which should be used
32  * to manage the {@link PelTag::USER_COMMENT} tag, and {@link
33  * PelEntryVersion} which is used to manage entries with version
34  * information.
35  *
36  * @author Martin Geisler <mgeisler@users.sourceforge.net>
37  * @license http://www.gnu.org/licenses/gpl.html GNU General Public
38  *          License (GPL)
39  * @package PEL
40  */
41
42 /**
43  * Class for a user comment.
44  *
45  * This class is used to hold user comments, which can come in several
46  * different character encodings. The Exif standard specifies a
47  * certain format of the {@link PelTag::USER_COMMENT user comment
48  * tag}, and this class will make sure that the format is kept.
49  *
50  * The most basic use of this class simply stores an ASCII encoded
51  * string for later retrieval using {@link getValue}:
52  *
53  * <code>
54  * $entry = new PelEntryUserComment('An ASCII string');
55  * echo $entry->getValue();
56  * </code>
57  *
58  * The string can be encoded with a different encoding, and if so, the
59  * encoding must be given using the second argument. The Exif
60  * standard specifies three known encodings: 'ASCII', 'JIS', and
61  * 'Unicode'. If the user comment is encoded using a character
62  * encoding different from the tree known encodings, then the empty
63  * string should be passed as encoding, thereby specifying that the
64  * encoding is undefined.
65  *
66  * @author Martin Geisler <mgeisler@users.sourceforge.net>
67  * @package PEL
68  */
69 class PelEntryUserComment extends PelEntryUndefined
70 {
71
72     /**
73      * The user comment.
74      *
75      * @var string
76      */
77     private $comment;
78
79     /**
80      * The encoding.
81      *
82      * This should be one of 'ASCII', 'JIS', 'Unicode', or ''.
83      *
84      * @var string
85      */
86     private $encoding;
87
88     /**
89      * Make a new entry for holding a user comment.
90      *
91      * @param
92      *            string the new user comment.
93      *
94      * @param
95      *            string the encoding of the comment. This should be either
96      *            'ASCII', 'JIS', 'Unicode', or the empty string specifying an
97      *            undefined encoding.
98      */
99     public function __construct($comment = '', $encoding = 'ASCII')
100     {
101         parent::__construct(PelTag::USER_COMMENT);
102         $this->setValue($comment, $encoding);
103     }
104
105     /**
106      * Set the user comment.
107      *
108      * @param
109      *            string the new user comment.
110      *
111      * @param
112      *            string the encoding of the comment. This should be either
113      *            'ASCII', 'JIS', 'Unicode', or the empty string specifying an
114      *            unknown encoding.
115      */
116     public function setValue($comment = '', $encoding = 'ASCII')
117     {
118         $this->comment = $comment;
119         $this->encoding = $encoding;
120         parent::setValue(str_pad($encoding, 8, chr(0)) . $comment);
121     }
122
123     /**
124      * Returns the user comment.
125      *
126      * The comment is returned with the same character encoding as when
127      * it was set using {@link setValue} or {@link __construct the
128      * constructor}.
129      *
130      * @return string the user comment.
131      */
132     public function getValue()
133     {
134         return $this->comment;
135     }
136
137     /**
138      * Returns the encoding.
139      *
140      * @return string the encoding of the user comment.
141      */
142     public function getEncoding()
143     {
144         return $this->encoding;
145     }
146
147     /**
148      * Returns the user comment.
149      *
150      * @return string the user comment.
151      */
152     public function getText($brief = false)
153     {
154         return $this->comment;
155     }
156 }