Explorar el Código

Evolution #78: Remplacer VideoEmbed: Suppression de VideoEmbed

bastien hace 13 años
padre
commit
ddc220ebff

+ 0 - 61
src/Muzich/CoreBundle/ElementFactory/Site/base/VideoSiteFactory.php Ver fichero

@@ -1,61 +0,0 @@
1
-<?php
2
-
3
-namespace Muzich\CoreBundle\ElementFactory\Site\base;
4
-
5
-use Muzich\CoreBundle\Entity\Element;
6
-use Symfony\Component\DependencyInjection\Container;
7
-use Muzich\CoreBundle\ElementFactory\Site\base\BaseFactory;
8
-use Muzich\CoreBundle\ElementFactory\lib\VideoEmbed;
9
-
10
-/**
11
- * 
12
- *
13
- * @author bux
14
- */
15
-class VideoSiteFactory extends BaseFactory
16
-{
17
-  
18
-  protected $video_engine = null;
19
-  
20
-  public function __construct(Element $element, Container $container)
21
-  {
22
-    parent::__construct($element, $container);
23
-    
24
-    //if ($container->getParameter('env') != 'test')
25
-    //{
26
-      // Configuration de VideoEmbed
27
-      if (!defined('SITEBASE')) 
28
-      {
29
-        define('SITEBASE', $container->getParameter('sitebase'));
30
-      }
31
-    //}
32
-      if (!defined('VIDEO_EMBED_CONFIG_FILE')) 
33
-      {
34
-      define('VIDEO_EMBED_CONFIG_FILE', SITEBASE.$container->getParameter('video_embed_config_file'));
35
-      }
36
-      //to activate debug mode and false for production usage. it will write 
37
-      //to a log file when something goes wrong but should not produce 
38
-      //exceptions in production enviroment
39
-      if (!defined('DEBUG')) 
40
-      {
41
-        define('DEBUG', $container->getParameter('video_embed_debug')); 
42
-      }
43
-    try {
44
-      $this->video_engine =  new VideoEmbed($this->element->getUrl());
45
-    } catch (Exception $exc) {
46
-      
47
-    }
48
-  }
49
-  
50
-  public function getEmbedCode()
51
-  {
52
-    if ($this->video_engine)
53
-    {
54
-      return $this->video_engine->embed;
55
-    }
56
-    return null;
57
-  }
58
-  
59
-}
60
-
61
-?>

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 0 - 1049
src/Muzich/CoreBundle/ElementFactory/lib/Spyc.php


+ 0 - 365
src/Muzich/CoreBundle/ElementFactory/lib/VideoEmbed.php Ver fichero

@@ -1,365 +0,0 @@
1
-<?php
2
-
3
-namespace Muzich\CoreBundle\ElementFactory\lib;
4
-
5
-//require_once (SITEBASE . '/src/Muzich/CoreBundle/ElementFactory/lib/spyc.php');
6
-use Muzich\CoreBundle\ElementFactory\lib\Spyc;
7
-use \Exception;
8
-
9
-/**
10
-* Copyright (c) 2008, AF83
11
-*   All rights reserved.
12
-*
13
-*   Redistribution and use in source and binary forms, with or without modification,
14
-*   are permitted provided that the following conditions are met:
15
-*
16
-*   1° Redistributions of source code must retain the above copyright notice,
17
-*   this list of conditions and the following disclaimer.
18
-*
19
-*   2° Redistributions in binary form must reproduce the above copyright notice,
20
-*   this list of conditions and the following disclaimer in the documentation
21
-*   and/or other materials provided with the distribution.
22
-*
23
-*   3° Neither the name of AF83 nor the names of its contributors may be used
24
-*   to endorse or promote products derived from this software without specific
25
-*   prior written permission.
26
-*
27
-*   THIS SOFTWARE IS PROVIDED BY THE COMPANY AF83 AND CONTRIBUTORS "AS IS"
28
-*   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
29
-*   THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30
-*   PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
31
-*   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32
-*   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33
-*   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34
-*   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
35
-*   OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36
-*   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
37
-*   EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
-*
39
-* @copyright 2008 AF83 http://dev.af83.com
40
-* @author Ori Pekelman
41
-* @license BSD License (3 Clause) http://www.opensource.org/licenses/bsd-license.php
42
-* @package Video
43
-* @version $Id$
44
-* @access public
45
-* @todo thumbnails should be cached locally
46
-*
47
-* VideoEmbed class  can be used to safely and cleanly embed videos from different sources
48
-*
49
-* The different sources are configured in the video_embed.yaml file
50
-*
51
-* NB: The embed code may be also a url
52
-*
53
-* Usage: set the configuration variables (refer to readme for details):
54
-*  VIDEO_EMBED_CONFIG_FILE -- path of video embed config file
55
-*
56
-*                     $videoEmbed = new VideoEmbed($embed); optional width and height may be passed to the constructor
57
-*                      //print($videoEmbed->embed);
58
-*                      $videoEmbed->width = 240; // resize
59
-*                      $videoEmbed->height = 120;
60
-*                      //print($videoEmbed->embed);
61
-*                      //print($videoEmbed->thumb);
62
-
63
-*
64
-* This class requires the SpyC library to read the cobnfiguration file. please adjust the path of the include on the first line of this file
65
-* The video services are configured in the configuration file (video_embed.conf.inc), example for youtube google and daily motion:
66
-*/
67
-
68
-class VideoEmbed {
69
-    private $_video_embed_conf = array();
70
-    private $_embedSource;
71
-    private $_embed;
72
-    private $_id;
73
-    private $_type;
74
-    private $_thumb;
75
-    private $_url;
76
-    private $_width;
77
-    private $_height;
78
-    private $_readOnly = array ('thumb', 'url', 'id', 'type');
79
-    private $_readWrite = array ('width', 'height', 'embed');
80
-
81
-    /**
82
-    * VideoEmbed::__construct() Only embed is mandatory
83
-    *
84
-    * @param mixed $embed
85
-    * @param mixed $width
86
-    * @param mixed $height
87
-    */
88
-    function __construct($embed, $width = null, $height = null)
89
-    {
90
-        // load configuration
91
-//        if (!class_exists('Spyc')) {
92
-//            throw new exception ('Could not find SpyC library ');
93
-//        }
94
-            
95
-        $this->_video_embed_conf = Spyc::YAMLLoad(VIDEO_EMBED_CONFIG_FILE);
96
-        
97
-        if (!$this->_video_embed_conf) {
98
-            debug_log ("Could not read configruation file or config file empty  " . SITE_BASE . VIDEO_EMBED_CONFIG_FILE);
99
-            if (DEBUG) {
100
-                throw new exception ("Could not read configruation file or config file empty " . SITE_BASE . VIDEO_EMBED_CONFIG_FILE);
101
-            }
102
-        }
103
-
104
-        if (!$embed) {
105
-            debug_log ('This must be instantiated with a non empty embed code');
106
-            if (DEBUG) {
107
-                throw new exception ('This must be instantiated with a non empty embed code');
108
-            }
109
-        }
110
-        
111
-        // load arguments
112
-        $this->_embedSource = $embed;
113
-        $this->_width = $width?$width: $this->_video_embed_conf['defaultWidth'];
114
-        $this->_height = $height?$height:$this->_video_embed_conf['defaultHeight'];
115
-
116
-        $this->setup();
117
-    }
118
-    /**
119
-    * VideoEmbed::__set() Make some variables read only
120
-    *
121
-    * @param mixed $n
122
-    * @param mixed $val
123
-    * @return
124
-    */
125
-    function __set($n, $val)
126
-    {
127
-        if (in_array($n, $this->_readOnly)) {
128
-            debug_log ("Trying to set a read only property $n $val");
129
-            if (DEBUG) {
130
-                throw new exception ("Trying to set  a read only property" . "$n $val");
131
-            }
132
-            return false;
133
-        } elseif (in_array($n, $this->_readWrite)) {
134
-            if ($n == "embed") {
135
-                $property = '_embedSource';
136
-            } else $property = "_" . $n;
137
-
138
-            $this->$property = $val;
139
-            $this->setup(); // recalculate stuff if we changed a RW  property
140
-            return true;
141
-        }
142
-        return false;
143
-    }
144
-
145
-    /**
146
-    * VideoEmbed::__get()
147
-    *
148
-    * @param mixed $n
149
-    * @return
150
-    */
151
-    function __get($n)
152
-    {
153
-        if (in_array($n, array_merge($this->_readOnly, $this->_readWrite))) {
154
-            $propertyName = "_$n";
155
-            return $this->$propertyName;
156
-        } else {
157
-            debug_log('Trying to get a non readble property ' . $n);
158
-            if (DEBUG) {
159
-                throw new exception ('Trying to get a non readble property ' . $n);
160
-            }
161
-            return false;
162
-        }
163
-    }
164
-
165
-    /**
166
-    * VideoEmbed::setup()
167
-    *
168
-    * @return
169
-    */
170
-    private function setup ()
171
-    {      
172
-        if (!$this->video_embed_type()) {
173
-            //debug_log ('Could not get embed type :' . $this->_embedSource);
174
-            if (DEBUG) {
175
-                throw new exception ('Could not get embed type :' . $this->_embedSource);
176
-            }
177
-        }
178
-        if (!$this->video_embed_id()) {
179
-            //debug_log ('Could not get embed id :' . $this->_embedSource);
180
-            if (DEBUG) {
181
-                throw new exception ('Could not get embed id :' . $this->_embedSource);
182
-            }
183
-        }
184
-        if (!$this->video_embed_url()) {
185
-            //debug_log ('Problem generating embed url :' . $this->_embedSource);
186
-            if (DEBUG) {
187
-                throw new exception ('Problem generating embed url :' . $this->_embedSource);
188
-            }
189
-        }
190
-        if (!$this->video_embed_thumb()) {
191
-            //debug_log ('Problem generating thumb code :' . $this->_embedSource);
192
-            if (DEBUG) {
193
-                throw new exception ('Problem generatingembed code :' . $this->_embed);
194
-            }
195
-        }
196
-        if (!$this->video_embed_embed()) {
197
-            //debug_log ('Problem generating embed code :' . $this->_embedSource);
198
-            if (DEBUG) {
199
-                throw new exception ('Problem generatingembed code :' . $this->_embedSource);
200
-            }
201
-        }
202
-    }
203
-
204
-    /**
205
-    * VideoEmbed::video_emebd_type()
206
-    *
207
-    * @param mixed $embed
208
-    * @return
209
-    */
210
-    private function video_embed_type()
211
-    {
212
-        $type = null;
213
-        $this->_type = "";
214
-        foreach($this->_video_embed_conf['services'] as $serviceName => $config) {
215
-            if (strpos(strtolower($this->_embedSource), strtolower($config['urlPattern']))) {
216
-                $type = $serviceName;
217
-            }
218
-        }
219
-        if ($type) {
220
-            $this->_type = $type;
221
-            return $this->_type;
222
-        }
223
-        return false;
224
-    }
225
-
226
-    /**
227
-    * VideoEmbed::video_embed_id()
228
-    *
229
-    * @return
230
-    */
231
-    private function video_embed_id()
232
-    {
233
-        $this->_id = "";
234
-
235
-        if (($this->_type)) {
236
-            $regexp = $this->_video_embed_conf['services'][$this->_type]['extractPattern'];
237
-            preg_match($regexp, $this->_embedSource , $match);
238
-            if (count($match))
239
-            {
240
-              if ($match[count($match)-1]) $this->_id = $match[count($match)-1];
241
-              return $this->_id;
242
-            }
243
-        }
244
-        return false;
245
-    }
246
-
247
-    /**
248
-    * VideoEmbed::video_embed_url()
249
-    *
250
-    * @return
251
-    */
252
-    private function video_embed_url()
253
-    {
254
-        $this->_url = "";
255
-        if ($this->_type) {
256
-            if ($this->_id) $url = sprintf($this->_video_embed_conf['services'][$this->_type]['embedUrlTemplate'], $this->_id);
257
-            if ($url) $this->_url = $url;
258
-            return $this->_url;
259
-        }
260
-        return false;
261
-    }
262
-
263
-    /**
264
-    * VideoEmbed::video_embed_thumb()
265
-    *
266
-    * @return
267
-    */
268
-    private function video_embed_thumb()
269
-    {
270
-        $conf = $this->_video_embed_conf['services'][$this->_type]; // just here for readability
271
-        $this->_thumb = "";
272
-        if ($this->_type && $this->_id) {
273
-            if (isset($conf['thumbnailUrlExtractPattern'])) { // if we need to parse the response:
274
-                $thumburl = $this->extractThumbUrl($conf['thumbnailUrlTemplate'], $conf['thumbnailUrlExtractPattern']);
275
-            } else $thumburl = sprintf($conf['thumbnailUrlTemplate'], $this->_id);
276
-
277
-            if ($thumburl) $this->_thumb = $thumburl;
278
-            return $this->_thumb;
279
-        }
280
-        return false;
281
-    }
282
-
283
-    /**
284
-    * VideoEmbed::video_embed_embed()
285
-    *
286
-    * @param mixed $width
287
-    * @param mixed $height
288
-    * @return
289
-    */
290
-    private function video_embed_embed()
291
-    {
292
-        if ($this->_type) {
293
-            $template = isset($this->_video_embed_conf['services'][$this->_type]['embedTemplate']) ? $this->_video_embed_conf['services'][$this->_type]['embedTemplate']:$this->_video_embed_conf['embedTemplate'];
294
-            if ($template && $this->_url) {
295
-                $width = $this->_width?$this->_width:$this->_video_embed_conf['services'][$video_type]['defaultWidth'];
296
-                $height = $this->_height?$this->_height:$this->_video_embed_conf['services'][$video_type]['defaultHeight'];
297
-                $embed = sprintf($template, $this->_url, $width, $height);
298
-                if ($embed) $this->_embed = $embed;
299
-                return $this->_embed;
300
-            }
301
-        }
302
-
303
-        return false;
304
-    }
305
-    /**
306
-    * extractThumbUrl()
307
-    *
308
-    * @param mixed $url
309
-    * @param mixed $videoid
310
-    * @param mixed $extractPattern
311
-    * @return
312
-    */
313
-    private function extractThumbUrl($url, $extractPattern)
314
-    {
315
-        $vrss = file_get_contents(sprintf($url, $this->_id));
316
-        if (!empty($vrss)) {
317
-            preg_match($extractPattern, $vrss, $thumbnail_array);
318
-            $thumbnail = $thumbnail_array[1];
319
-            // Remove amp;
320
-            $thumbnail = str_replace('amp;', '', $thumbnail);
321
-        }
322
-
323
-        return $thumbnail;
324
-    }
325
-}
326
-
327
-/**
328
-* test_VideoEmbed() test all is well
329
-*
330
-* @return
331
-*/
332
-function test_VideoEmbed()
333
-{
334
-    $embeds[] = '<div><object width="420" height="365"><param name="movie" value="http://www.dailymotion.com/swf/x3wq9a&v3=1&related=0"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed src="http://www.dailymotion.com/swf/x3wq9a&v3=1&related=0" type="application/x-shockwave-flash" width="420" height="365" allowFullScreen="true" allowScriptAccess="always"></embed></object><br /><b><a href="http://www.dailymotion.com/video/x3wq9a_defi-decorer-les-camions-de-pq_fun">Defi: décorer les camions de PQ</a></b><br /><i>Uploaded by <a href="http://www.dailymotion.com/gonzaguetv">gonzaguetv</a></i></div>';
335
-    $embeds[] = '<object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/1mXh_tyLlAY&rel=1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/1mXh_tyLlAY&rel=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>';
336
-    $embeds[] = '<embed style="width:400px; height:326px;" id="VideoPlayback" type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docId=-1182786924290841590&hl=fr" flashvars=""> </embed>';
337
-    foreach($embeds as $embed) {
338
-        $videoEmbed = new VideoEmbed($embed, 420, 365);
339
-        
340
-        // Mise en commentaire pour opasser le pre-commit:
341
-        
342
-//        echo "<h2> Type:</h2>\n";
343
-//        print ($videoEmbed->type);
344
-//        echo "<h2> ID:</h2>\n";
345
-//        print($videoEmbed->id);
346
-//        echo "<h2> Video Url:</h2>\n";
347
-//        print($videoEmbed->url);
348
-//        echo "<h2> Embed:</h2>\n";
349
-//        print($videoEmbed->embed);
350
-//        echo "<h2> Embed resized:</h2>\n";
351
-//        $videoEmbed->width = 240;
352
-//        $videoEmbed->height = 120;
353
-//        print($videoEmbed->embed);
354
-//        echo "<h2> thumb url:</h2>\n";
355
-//        print($videoEmbed->thumb);
356
-//        echo "<h2> thumb image:</h2>\n";
357
-//        print('<img src="' . $videoEmbed->thumb . '" />');
358
-        
359
-        
360
-        // this should fail
361
-        // $videoEmbed->thumb = "qsdqsdsq";
362
-        // this should fail
363
-        // print('<img src="' . $videoEmbed->image . '" />');
364
-    }
365
-}