root/trunk/wifidog-auth/wifidog/classes/Content/EmbeddedContent.php @ 563

Revision 563, 12.1 KB (checked in by fproulx, 8 years ago)

2005-04-23 Fran��ois Proulx <francois.proulx@…>

  • Fixed bugs in File and EmbeddedContent?
  • Completed first iteration of EmbeddedContent?
  • Can now play multimedia content
  • Could not test fallback with my browser ( Safari and Firefox )
  • Need help to test content in different browser to see how it reacts...
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2
3
4/********************************************************************\
5 * This program is free software; you can redistribute it and/or    *
6 * modify it under the terms of the GNU General Public License as   *
7 * published by the Free Software Foundation; either version 2 of   *
8 * the License, or (at your option) any later version.              *
9 *                                                                  *
10 * This program is distributed in the hope that it will be useful,  *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
13 * GNU General Public License for more details.                     *
14 *                                                                  *
15 * You should have received a copy of the GNU General Public License*
16 * along with this program; if not, contact:                        *
17 *                                                                  *
18 * Free Software Foundation           Voice:  +1-617-542-5942       *
19 * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
20 * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
21 *                                                                  *
22 \********************************************************************/
23/**@file EmbeddedContent.php
24 * @author Copyright (C) 2005 François Proulx <francois.proulx@gmail.com>
25 */
26require_once BASEPATH.'classes/Content.php';
27
28/**
29 * A generic embedded content container
30 * This object supports backward compatiblity fallback
31 *
32 * Inspired by W3C WCGAG 2.0 recommendations
33 * http://www.w3.org/TR/2004/WD-WCAG20-HTML-TECHS-20041119/#embed
34 *
35 * And Macromedia recommendations for backward compatibility
36 * http://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=tn_12701
37 * */
38class EmbeddedContent extends Content
39{
40        protected function __construct($content_id)
41        {
42                parent :: __construct($content_id);
43                global $db;
44                $content_id = $db->EscapeString($content_id);
45
46                $sql = "SELECT * FROM embedded_content WHERE embedded_content_id='$content_id'";
47                $db->ExecSqlUniqueRes($sql, $row, false);
48                if ($row == null)
49                {
50                        /*Since the parent Content exists, the necessary data in content_group had not yet been created */
51                        $sql = "INSERT INTO embedded_content (embedded_content_id) VALUES ('$content_id')";
52                        $db->ExecSqlUpdate($sql, false);
53                        $sql = "SELECT * FROM embedded_content WHERE embedded_content_id='$content_id'";
54                        $db->ExecSqlUniqueRes($sql, $row, false);
55                        if ($row == null)
56                        {
57                                throw new Exception(_("The content with the following id could not be found in the database: ").$content_id);
58                        }
59
60                }
61               
62                $this->mBd = &$db;
63                $this->setIsTrivialContent(true);
64                $this->setIsPersistent(false);
65                $this->embedded_content_row = $row;
66        }
67
68        public function getAdminUI($subclass_admin_interface = null)
69        {
70                $html = '';
71                $html .= "<div class='admin_class'>EmbeddedContent (".get_class($this)." instance)</div>\n";
72
73                /* Embedded content Content */
74                $html .= "<div class='admin_section_container'>\n";
75                $html .= "<div class='admin_section_title'>"._("Embedded content")." : <br></div>\n";
76                $html .= "<div class='admin_section_data'>\n";
77                if (empty ($this->embedded_content_row['embedded_file_id']))
78                {
79                        // Mandate File
80                        $html .= self :: getNewContentUI("embedded_file_{$this->id}_new", "File");
81                        $html .= "</div>\n";
82                }
83                else
84                {
85                        $embedded_content_file = self :: getObject($this->embedded_content_row['embedded_file_id']);
86                        $html .= $embedded_content_file->getAdminUI();
87                        $html .= "</div>\n";
88                        $html .= "<div class='admin_section_tools'>\n";
89                        $name = "embeddedcontent_".$this->id."_embedded_file_erase";
90                       
91                        $html .= "<div class='admin_section_container'>\n";
92                        $html .= "<div class='admin_section_title'>"._("Attributes")." : </div>\n";
93                        $html .= "<div class='admin_section_data'>\n";
94                        $html .= "<br><i>"._("It is recommended to specify at least <b>width='x' height='y'</b> as attributes")."</i><br>\n";
95                        $html .= '<textarea name="embedded_content_attributes'.$this->getId().'" cols="60" rows="3">'.htmlspecialchars($this->getAttributes(), ENT_QUOTES, 'UTF-8').'</textarea>';
96                        $html .= "</div>\n";
97                        $html .= "</div>\n";
98                       
99                        $html .= "<div class='admin_section_container'>\n";
100                        $html .= "<div class='admin_section_title'>"._("Parameters")." : </div>\n";
101                        $html .= "<div class='admin_section_data'>\n";
102                        $html .= '<br><textarea name="embedded_content_parameters'.$this->getId().'" cols="60" rows="3">'.htmlspecialchars($this->getParameters(), ENT_QUOTES, 'UTF-8').'</textarea>';
103                        $html .= "</div>\n";
104                        $html .= "</div>\n";
105                       
106                        $html .= "<input type='submit' name='$name' value='"._("Delete")."'>"; //  onclick='submit();'
107                        $html .= "</div>\n";
108                }
109                $html .= "</div>\n";
110
111                /* Fallback content */
112                $html .= "<div class='admin_section_container'>\n";
113                $html .= "<div class='admin_section_title'>"._("Fallback content (Can be another embedded content to create a fallback hierarchy)")." : <br></div>\n";
114                $html .= "<div class='admin_section_data'>\n";
115                if (empty ($this->embedded_content_row['fallback_content_id']))
116                {
117                        $html .= self :: getNewContentUI("fallback_content_{$this->id}_new");
118                        $html .= "</div>\n";
119                }
120                else
121                {
122                        $fallback_content = self :: getObject($this->embedded_content_row['fallback_content_id']);
123                        $html .= $fallback_content->getAdminUI();
124                        $html .= "</div>\n";
125                        $html .= "<div class='admin_section_tools'>\n";
126                        $name = "fallback_content_".$this->id."_fallback_content_erase";
127                        $html .= "<input type='submit' name='$name' value='"._("Delete")."'>"; // onclick='submit();'
128                        $html .= "</div>\n";
129                }
130                $html .= "</div>\n";
131
132                $html .= $subclass_admin_interface;
133                return parent :: getAdminUI($html);
134        }
135
136        function processAdminUI()
137        {
138                parent :: processAdminUI();
139
140                global $db;
141                if (empty ($this->embedded_content_row['embedded_file_id']))
142                {
143                        $embedded_content_file = self :: processNewContentUI("embedded_file_{$this->id}_new");
144                        if ($embedded_content_file != null)
145                        {
146                                $embedded_content_file_id = $embedded_content_file->GetId();
147                                $db->ExecSqlUpdate("UPDATE embedded_content SET embedded_file_id = '$embedded_content_file_id' WHERE embedded_content_id = '$this->id'", FALSE);
148                        }
149                        else
150                        {
151                                echo _("You MUST choose a File object or any of its siblings.");
152                                $embedded_content_file->delete($errmsg);
153                        }
154                }
155                else
156                {
157                        $embedded_content_file = self :: getObject($this->embedded_content_row['embedded_file_id']);
158                        $name = "embeddedcontent_".$this->id."_embedded_file_erase";
159                        if (!empty ($_REQUEST[$name]) && $_REQUEST[$name] == true)
160                        {
161                                $db->ExecSqlUpdate("UPDATE embedded_content SET embedded_file_id = NULL WHERE embedded_content_id = '$this->id'", FALSE);
162                                $embedded_content_file->delete($errmsg);
163                        }
164                        else
165                        {
166                                $embedded_content_file->processAdminUI();
167                               
168                                $name = "embedded_content_attributes".$this->getId();
169                                $this->setAttributes($_REQUEST[$name]);
170                               
171                                $name = "embedded_content_parameters".$this->getId();
172                                $this->setParameters($_REQUEST[$name]);
173                        }
174                }
175
176                if (empty ($this->embedded_content_row['fallback_content_id']))
177                {
178                        $fallback_content = self :: processNewContentUI("fallback_content_{$this->id}_new");
179                        if ($fallback_content != null)
180                        {
181                                $fallback_content_id = $fallback_content->GetId();
182                                $db->ExecSqlUpdate("UPDATE embedded_content SET fallback_content_id = '$fallback_content_id' WHERE embedded_content_id = '$this->id'", FALSE);
183                        }
184                }
185                else
186                {
187                        $fallback_content = self :: getObject($this->embedded_content_row['fallback_content_id']);
188                        $name = "fallback_content_".$this->id."_fallback_content_erase";
189                        if (!empty ($_REQUEST[$name]) && $_REQUEST[$name] == true)
190                        {
191                                $db->ExecSqlUpdate("UPDATE embedded_content SET fallback_content_id = NULL WHERE embedded_content_id = '$this->id'", FALSE);
192                                $fallback_content->delete($errmsg);
193                        }
194                        else
195                        {
196                                $fallback_content->processAdminUI();
197                        }
198                }
199
200                $this->refresh();
201        }
202
203        /** Retreives the user interface of this object.  Anything that overrides this method should call the parent method with it's output at the END of processing.
204         * @param $subclass_admin_interface Html content of the interface element of a children
205         * @return The HTML fragment for this interface */
206        public function getUserUI()
207        {
208                $html = '';
209                $html .= "<div class='user_ui_container'>\n";
210                $html .= "<div class='user_ui_object_class'>EmbeddedContent (".get_class($this)." instance)</div>\n";
211
212                $embedded_content_file = null;
213                $fallback_content = null;
214
215                /* Get both objects if they exist */
216                if (!empty ($this->embedded_content_row['embedded_file_id']))
217                        $embedded_content_file = self :: getObject($this->embedded_content_row['embedded_file_id']);
218                if (!empty ($this->embedded_content_row['fallback_content_id']))
219                        $fallback_content = self :: getObject($this->embedded_content_row['fallback_content_id']);
220
221                /*
222                 *
223                 * <object classid="clsid:A12BCD3F-GH4I-56JK-xyz"
224                codebase="http://example.com/content.cab"
225                width="100" height="80">
226                <param name="Movie" value="moviename.swf" />
227                <embed src="moviename.swf" width="100" height="80"
228                pluginspage="http://example.com/shockwave/download/" />
229                <noembed>
230                <img alt="Still from Movie" src="moviename.gif"
231                width="100" height="80" />
232                </noembed>
233                </object>
234                 *
235                 *
236                 * <object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="400" height="316" codebase="http://www.apple.com/qtactivex/qtplugin.cab">
237                                                <param name="SRC" value="/sponsors/airborne/400.mov">
238               
239                                                <param name="QTNEXT1" value="<http://stream.qtv.apple.com/qtv/endorphin/http/hydrogen3_ref.mov> T<myself>">
240                                                <param name="AUTOPLAY" value="true">
241                                                <param name="CONTROLLER" value="true">
242                                                <embed src="/sponsors/airborne/400.mov" qtnext1="<http://stream.qtv.apple.com/qtv/endorphin/http/hydrogen3_ref.mov> T<myself>" width="400" height="316" align="left" autoplay="true" controller="true" pluginspage="http://www.apple.com/quicktime/download/">
243                                                </embed>
244                                                </object>
245                 *
246                 */
247                if ($embedded_content_file != null)
248                {
249                        $url = htmlentities($embedded_content_file->getFileUrl());
250                        $mime_type = $embedded_content_file->getMimeType();
251                        $html .= "<object type='$mime_type' data='$url' {$this->getAttributes()}>\n";
252                        $html .= "<param name='AUTOPLAY' value='false'>\n";
253                        $html .= "<param name='AUTOPLAY' value='0'>\n";
254                        $html .= "{$this->getParameters()}\n";
255                        // Spit fallback content between inside the <object> tag
256                        if ($fallback_content != null)
257                                $html .= $fallback_content->getUserUI();
258                        $html .= "<embed autoplay=FALSE src='$url'>\n";
259                        $html .= "<nobembed>\n";
260                        $html .= "<p><a href='$url'>"._("Download")." ".$embedded_content_file->getFilename()." (".$embedded_content_file->getFileSize(File :: UNIT_KILOBYTES)." "._("KB").")</a></p>";
261                        $html .= "</nobembed>\n";
262                        $html .= "</object>\n";
263                }
264
265                $html .= "</div>\n";
266                return parent :: getUserUI($html);
267        }
268
269        //TODO: Add support for attributes and parameters
270        public function getAttributes()
271        {
272                return $this->embedded_content_row['attributes'];
273        }
274
275        public function setAttributes($attributes_str)
276        {
277                $attributes_str = $this->mBd->EscapeString($attributes_str);
278                $this->mBd->ExecSqlUpdate("UPDATE embedded_content SET attributes ='".$attributes_str."' WHERE embedded_content_id='".$this->getId()."'", false);
279                $this->refresh();
280        }
281
282        public function getParameters()
283        {
284                return $this->embedded_content_row['parameters'];
285        }
286
287        public function setParameters($paramters_str)
288        {
289                $paramters_str = $this->mBd->EscapeString($paramters_str);
290                $this->mBd->ExecSqlUpdate("UPDATE embedded_content SET parameters ='".$paramters_str."' WHERE embedded_content_id='".$this->getId()."'", false);
291                $this->refresh();
292        }
293
294        /** Delete this Content from the database
295        */
296        public function delete(& $errmsg)
297        {
298                if ($this->isPersistent() == false)
299                {
300                        if (!empty ($this->embedded_content_row['embedded_file_id']))
301                        {
302                                $embedded_content_file = self :: getObject($this->embedded_content_row['embedded_file_id']);
303                                $embedded_content_file->delete($errmsg);
304                        }
305                        if (!empty ($this->embedded_content_row['fallback_content_id']))
306                        {
307                                $fallback_content = self :: getObject($this->embedded_content_row['fallback_content_id']);
308                                $fallback_content->delete($errmsg);
309                        }
310                }
311                return parent :: delete($errmsg);
312        }
313
314} // End class
315?>
Note: See TracBrowser for help on using the browser.