library/SimplePie/Enclosure.php Quellcode

Enclosure.php
gehe zur Dokumentation dieser Datei
1 <?php
56 {
61  var $bitrate;
62 
67  var $captions;
68 
74 
79  var $channels;
80 
86 
91  var $credits;
92 
98 
104 
110 
116 
121  var $handler;
122 
127  var $hashes;
128 
133  var $height;
134 
140 
146 
151  var $lang;
152 
157  var $length;
158 
163  var $link;
164 
169  var $medium;
170 
175  var $player;
176 
181  var $ratings;
182 
188 
194 
200 
205  var $title;
206 
211  var $type;
212 
217  var $width;
218 
227  public function __construct($link = null, $type = null, $length = null, $javascript = null, $bitrate = null, $captions = null, $categories = null, $channels = null, $copyright = null, $credits = null, $description = null, $duration = null, $expression = null, $framerate = null, $hashes = null, $height = null, $keywords = null, $lang = null, $medium = null, $player = null, $ratings = null, $restrictions = null, $samplingrate = null, $thumbnails = null, $title = null, $width = null)
228  {
229  $this->bitrate = $bitrate;
230  $this->captions = $captions;
231  $this->categories = $categories;
232  $this->channels = $channels;
233  $this->copyright = $copyright;
234  $this->credits = $credits;
235  $this->description = $description;
236  $this->duration = $duration;
237  $this->expression = $expression;
238  $this->framerate = $framerate;
239  $this->hashes = $hashes;
240  $this->height = $height;
241  $this->keywords = $keywords;
242  $this->lang = $lang;
243  $this->length = $length;
244  $this->link = $link;
245  $this->medium = $medium;
246  $this->player = $player;
247  $this->ratings = $ratings;
248  $this->restrictions = $restrictions;
249  $this->samplingrate = $samplingrate;
250  $this->thumbnails = $thumbnails;
251  $this->title = $title;
252  $this->type = $type;
253  $this->width = $width;
254 
255  if (class_exists('idna_convert'))
256  {
257  $idn = new idna_convert();
258  $parsed = SimplePie_Misc::parse_url($link);
259  $this->link = SimplePie_Misc::compress_parse_url($parsed['scheme'], $idn->encode($parsed['authority']), $parsed['path'], $parsed['query'], $parsed['fragment']);
260  }
261  $this->handler = $this->get_handler(); // Needs to load last
262  }
263 
269  public function __toString()
270  {
271  // There is no $this->data here
272  return md5(serialize($this));
273  }
274 
280  public function get_bitrate()
281  {
282  if ($this->bitrate !== null)
283  {
284  return $this->bitrate;
285  }
286  else
287  {
288  return null;
289  }
290  }
291 
298  public function get_caption($key = 0)
299  {
300  $captions = $this->get_captions();
301  if (isset($captions[$key]))
302  {
303  return $captions[$key];
304  }
305  else
306  {
307  return null;
308  }
309  }
310 
316  public function get_captions()
317  {
318  if ($this->captions !== null)
319  {
320  return $this->captions;
321  }
322  else
323  {
324  return null;
325  }
326  }
327 
334  public function get_category($key = 0)
335  {
336  $categories = $this->get_categories();
337  if (isset($categories[$key]))
338  {
339  return $categories[$key];
340  }
341  else
342  {
343  return null;
344  }
345  }
346 
352  public function get_categories()
353  {
354  if ($this->categories !== null)
355  {
356  return $this->categories;
357  }
358  else
359  {
360  return null;
361  }
362  }
363 
369  public function get_channels()
370  {
371  if ($this->channels !== null)
372  {
373  return $this->channels;
374  }
375  else
376  {
377  return null;
378  }
379  }
380 
386  public function get_copyright()
387  {
388  if ($this->copyright !== null)
389  {
390  return $this->copyright;
391  }
392  else
393  {
394  return null;
395  }
396  }
397 
404  public function get_credit($key = 0)
405  {
406  $credits = $this->get_credits();
407  if (isset($credits[$key]))
408  {
409  return $credits[$key];
410  }
411  else
412  {
413  return null;
414  }
415  }
416 
422  public function get_credits()
423  {
424  if ($this->credits !== null)
425  {
426  return $this->credits;
427  }
428  else
429  {
430  return null;
431  }
432  }
433 
439  public function get_description()
440  {
441  if ($this->description !== null)
442  {
443  return $this->description;
444  }
445  else
446  {
447  return null;
448  }
449  }
450 
457  public function get_duration($convert = false)
458  {
459  if ($this->duration !== null)
460  {
461  if ($convert)
462  {
463  $time = SimplePie_Misc::time_hms($this->duration);
464  return $time;
465  }
466  else
467  {
468  return $this->duration;
469  }
470  }
471  else
472  {
473  return null;
474  }
475  }
476 
482  public function get_expression()
483  {
484  if ($this->expression !== null)
485  {
486  return $this->expression;
487  }
488  else
489  {
490  return 'full';
491  }
492  }
493 
499  public function get_extension()
500  {
501  if ($this->link !== null)
502  {
503  $url = SimplePie_Misc::parse_url($this->link);
504  if ($url['path'] !== '')
505  {
506  return pathinfo($url['path'], PATHINFO_EXTENSION);
507  }
508  }
509  return null;
510  }
511 
517  public function get_framerate()
518  {
519  if ($this->framerate !== null)
520  {
521  return $this->framerate;
522  }
523  else
524  {
525  return null;
526  }
527  }
528 
534  public function get_handler()
535  {
536  return $this->get_real_type(true);
537  }
538 
546  public function get_hash($key = 0)
547  {
548  $hashes = $this->get_hashes();
549  if (isset($hashes[$key]))
550  {
551  return $hashes[$key];
552  }
553  else
554  {
555  return null;
556  }
557  }
558 
564  public function get_hashes()
565  {
566  if ($this->hashes !== null)
567  {
568  return $this->hashes;
569  }
570  else
571  {
572  return null;
573  }
574  }
575 
581  public function get_height()
582  {
583  if ($this->height !== null)
584  {
585  return $this->height;
586  }
587  else
588  {
589  return null;
590  }
591  }
592 
599  public function get_language()
600  {
601  if ($this->lang !== null)
602  {
603  return $this->lang;
604  }
605  else
606  {
607  return null;
608  }
609  }
610 
617  public function get_keyword($key = 0)
618  {
619  $keywords = $this->get_keywords();
620  if (isset($keywords[$key]))
621  {
622  return $keywords[$key];
623  }
624  else
625  {
626  return null;
627  }
628  }
629 
635  public function get_keywords()
636  {
637  if ($this->keywords !== null)
638  {
639  return $this->keywords;
640  }
641  else
642  {
643  return null;
644  }
645  }
646 
652  public function get_length()
653  {
654  if ($this->length !== null)
655  {
656  return $this->length;
657  }
658  else
659  {
660  return null;
661  }
662  }
663 
669  public function get_link()
670  {
671  if ($this->link !== null)
672  {
673  return urldecode($this->link);
674  }
675  else
676  {
677  return null;
678  }
679  }
680 
687  public function get_medium()
688  {
689  if ($this->medium !== null)
690  {
691  return $this->medium;
692  }
693  else
694  {
695  return null;
696  }
697  }
698 
705  public function get_player()
706  {
707  if ($this->player !== null)
708  {
709  return $this->player;
710  }
711  else
712  {
713  return null;
714  }
715  }
716 
723  public function get_rating($key = 0)
724  {
725  $ratings = $this->get_ratings();
726  if (isset($ratings[$key]))
727  {
728  return $ratings[$key];
729  }
730  else
731  {
732  return null;
733  }
734  }
735 
741  public function get_ratings()
742  {
743  if ($this->ratings !== null)
744  {
745  return $this->ratings;
746  }
747  else
748  {
749  return null;
750  }
751  }
752 
759  public function get_restriction($key = 0)
760  {
761  $restrictions = $this->get_restrictions();
762  if (isset($restrictions[$key]))
763  {
764  return $restrictions[$key];
765  }
766  else
767  {
768  return null;
769  }
770  }
771 
777  public function get_restrictions()
778  {
779  if ($this->restrictions !== null)
780  {
781  return $this->restrictions;
782  }
783  else
784  {
785  return null;
786  }
787  }
788 
794  public function get_sampling_rate()
795  {
796  if ($this->samplingrate !== null)
797  {
798  return $this->samplingrate;
799  }
800  else
801  {
802  return null;
803  }
804  }
805 
811  public function get_size()
812  {
813  $length = $this->get_length();
814  if ($length !== null)
815  {
816  return round($length/1048576, 2);
817  }
818  else
819  {
820  return null;
821  }
822  }
823 
830  public function get_thumbnail($key = 0)
831  {
832  $thumbnails = $this->get_thumbnails();
833  if (isset($thumbnails[$key]))
834  {
835  return $thumbnails[$key];
836  }
837  else
838  {
839  return null;
840  }
841  }
842 
848  public function get_thumbnails()
849  {
850  if ($this->thumbnails !== null)
851  {
852  return $this->thumbnails;
853  }
854  else
855  {
856  return null;
857  }
858  }
859 
865  public function get_title()
866  {
867  if ($this->title !== null)
868  {
869  return $this->title;
870  }
871  else
872  {
873  return null;
874  }
875  }
876 
883  public function get_type()
884  {
885  if ($this->type !== null)
886  {
887  return $this->type;
888  }
889  else
890  {
891  return null;
892  }
893  }
894 
900  public function get_width()
901  {
902  if ($this->width !== null)
903  {
904  return $this->width;
905  }
906  else
907  {
908  return null;
909  }
910  }
911 
920  public function native_embed($options='')
921  {
922  return $this->embed($options, true);
923  }
924 
970  public function embed($options = '', $native = false)
971  {
972  // Set up defaults
973  $audio = '';
974  $video = '';
975  $alt = '';
976  $altclass = '';
977  $loop = 'false';
978  $width = 'auto';
979  $height = 'auto';
980  $bgcolor = '#ffffff';
981  $mediaplayer = '';
982  $widescreen = false;
983  $handler = $this->get_handler();
984  $type = $this->get_real_type();
985 
986  // Process options and reassign values as necessary
987  if (is_array($options))
988  {
989  extract($options);
990  }
991  else
992  {
993  $options = explode(',', $options);
994  foreach($options as $option)
995  {
996  $opt = explode(':', $option, 2);
997  if (isset($opt[0], $opt[1]))
998  {
999  $opt[0] = trim($opt[0]);
1000  $opt[1] = trim($opt[1]);
1001  switch ($opt[0])
1002  {
1003  case 'audio':
1004  $audio = $opt[1];
1005  break;
1006 
1007  case 'video':
1008  $video = $opt[1];
1009  break;
1010 
1011  case 'alt':
1012  $alt = $opt[1];
1013  break;
1014 
1015  case 'altclass':
1016  $altclass = $opt[1];
1017  break;
1018 
1019  case 'loop':
1020  $loop = $opt[1];
1021  break;
1022 
1023  case 'width':
1024  $width = $opt[1];
1025  break;
1026 
1027  case 'height':
1028  $height = $opt[1];
1029  break;
1030 
1031  case 'bgcolor':
1032  $bgcolor = $opt[1];
1033  break;
1034 
1035  case 'mediaplayer':
1036  $mediaplayer = $opt[1];
1037  break;
1038 
1039  case 'widescreen':
1040  $widescreen = $opt[1];
1041  break;
1042  }
1043  }
1044  }
1045  }
1046 
1047  $mime = explode('/', $type, 2);
1048  $mime = $mime[0];
1049 
1050  // Process values for 'auto'
1051  if ($width === 'auto')
1052  {
1053  if ($mime === 'video')
1054  {
1055  if ($height === 'auto')
1056  {
1057  $width = 480;
1058  }
1059  elseif ($widescreen)
1060  {
1061  $width = round((intval($height)/9)*16);
1062  }
1063  else
1064  {
1065  $width = round((intval($height)/3)*4);
1066  }
1067  }
1068  else
1069  {
1070  $width = '100%';
1071  }
1072  }
1073 
1074  if ($height === 'auto')
1075  {
1076  if ($mime === 'audio')
1077  {
1078  $height = 0;
1079  }
1080  elseif ($mime === 'video')
1081  {
1082  if ($width === 'auto')
1083  {
1084  if ($widescreen)
1085  {
1086  $height = 270;
1087  }
1088  else
1089  {
1090  $height = 360;
1091  }
1092  }
1093  elseif ($widescreen)
1094  {
1095  $height = round((intval($width)/16)*9);
1096  }
1097  else
1098  {
1099  $height = round((intval($width)/4)*3);
1100  }
1101  }
1102  else
1103  {
1104  $height = 376;
1105  }
1106  }
1107  elseif ($mime === 'audio')
1108  {
1109  $height = 0;
1110  }
1111 
1112  // Set proper placeholder value
1113  if ($mime === 'audio')
1114  {
1115  $placeholder = $audio;
1116  }
1117  elseif ($mime === 'video')
1118  {
1119  $placeholder = $video;
1120  }
1121 
1122  $embed = '';
1123 
1124  // Flash
1125  if ($handler === 'flash')
1126  {
1127  if ($native)
1128  {
1129  $embed .= "<embed src=\"" . $this->get_link() . "\" pluginspage=\"http://adobe.com/go/getflashplayer\" type=\"$type\" quality=\"high\" width=\"$width\" height=\"$height\" bgcolor=\"$bgcolor\" loop=\"$loop\"></embed>";
1130  }
1131  else
1132  {
1133  $embed .= "<script type='text/javascript'>embed_flash('$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$loop', '$type');</script>";
1134  }
1135  }
1136 
1137  // Flash Media Player file types.
1138  // Preferred handler for MP3 file types.
1139  elseif ($handler === 'fmedia' || ($handler === 'mp3' && $mediaplayer !== ''))
1140  {
1141  $height += 20;
1142  if ($native)
1143  {
1144  $embed .= "<embed src=\"$mediaplayer\" pluginspage=\"http://adobe.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" quality=\"high\" width=\"$width\" height=\"$height\" wmode=\"transparent\" flashvars=\"file=" . rawurlencode($this->get_link().'?file_extension=.'.$this->get_extension()) . "&autostart=false&repeat=$loop&showdigits=true&showfsbutton=false\"></embed>";
1145  }
1146  else
1147  {
1148  $embed .= "<script type='text/javascript'>embed_flv('$width', '$height', '" . rawurlencode($this->get_link().'?file_extension=.'.$this->get_extension()) . "', '$placeholder', '$loop', '$mediaplayer');</script>";
1149  }
1150  }
1151 
1152  // QuickTime 7 file types. Need to test with QuickTime 6.
1153  // Only handle MP3's if the Flash Media Player is not present.
1154  elseif ($handler === 'quicktime' || ($handler === 'mp3' && $mediaplayer === ''))
1155  {
1156  $height += 16;
1157  if ($native)
1158  {
1159  if ($placeholder !== '')
1160  {
1161  $embed .= "<embed type=\"$type\" style=\"cursor:hand; cursor:pointer;\" href=\"" . $this->get_link() . "\" src=\"$placeholder\" width=\"$width\" height=\"$height\" autoplay=\"false\" target=\"myself\" controller=\"false\" loop=\"$loop\" scale=\"aspect\" bgcolor=\"$bgcolor\" pluginspage=\"http://apple.com/quicktime/download/\"></embed>";
1162  }
1163  else
1164  {
1165  $embed .= "<embed type=\"$type\" style=\"cursor:hand; cursor:pointer;\" src=\"" . $this->get_link() . "\" width=\"$width\" height=\"$height\" autoplay=\"false\" target=\"myself\" controller=\"true\" loop=\"$loop\" scale=\"aspect\" bgcolor=\"$bgcolor\" pluginspage=\"http://apple.com/quicktime/download/\"></embed>";
1166  }
1167  }
1168  else
1169  {
1170  $embed .= "<script type='text/javascript'>embed_quicktime('$type', '$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$placeholder', '$loop');</script>";
1171  }
1172  }
1173 
1174  // Windows Media
1175  elseif ($handler === 'wmedia')
1176  {
1177  $height += 45;
1178  if ($native)
1179  {
1180  $embed .= "<embed type=\"application/x-mplayer2\" src=\"" . $this->get_link() . "\" autosize=\"1\" width=\"$width\" height=\"$height\" showcontrols=\"1\" showstatusbar=\"0\" showdisplay=\"0\" autostart=\"0\"></embed>";
1181  }
1182  else
1183  {
1184  $embed .= "<script type='text/javascript'>embed_wmedia('$width', '$height', '" . $this->get_link() . "');</script>";
1185  }
1186  }
1187 
1188  // Everything else
1189  else $embed .= '<a href="' . $this->get_link() . '" class="' . $altclass . '">' . $alt . '</a>';
1190 
1191  return $embed;
1192  }
1193 
1205  public function get_real_type($find_handler = false)
1206  {
1207  // Mime-types by handler.
1208  $types_flash = array('application/x-shockwave-flash', 'application/futuresplash'); // Flash
1209  $types_fmedia = array('video/flv', 'video/x-flv','flv-application/octet-stream'); // Flash Media Player
1210  $types_quicktime = array('audio/3gpp', 'audio/3gpp2', 'audio/aac', 'audio/x-aac', 'audio/aiff', 'audio/x-aiff', 'audio/mid', 'audio/midi', 'audio/x-midi', 'audio/mp4', 'audio/m4a', 'audio/x-m4a', 'audio/wav', 'audio/x-wav', 'video/3gpp', 'video/3gpp2', 'video/m4v', 'video/x-m4v', 'video/mp4', 'video/mpeg', 'video/x-mpeg', 'video/quicktime', 'video/sd-video'); // QuickTime
1211  $types_wmedia = array('application/asx', 'application/x-mplayer2', 'audio/x-ms-wma', 'audio/x-ms-wax', 'video/x-ms-asf-plugin', 'video/x-ms-asf', 'video/x-ms-wm', 'video/x-ms-wmv', 'video/x-ms-wvx'); // Windows Media
1212  $types_mp3 = array('audio/mp3', 'audio/x-mp3', 'audio/mpeg', 'audio/x-mpeg'); // MP3
1213 
1214  if ($this->get_type() !== null)
1215  {
1216  $type = strtolower($this->type);
1217  }
1218  else
1219  {
1220  $type = null;
1221  }
1222 
1223  // If we encounter an unsupported mime-type, check the file extension and guess intelligently.
1224  if (!in_array($type, array_merge($types_flash, $types_fmedia, $types_quicktime, $types_wmedia, $types_mp3)))
1225  {
1226  switch (strtolower($this->get_extension()))
1227  {
1228  // Audio mime-types
1229  case 'aac':
1230  case 'adts':
1231  $type = 'audio/acc';
1232  break;
1233 
1234  case 'aif':
1235  case 'aifc':
1236  case 'aiff':
1237  case 'cdda':
1238  $type = 'audio/aiff';
1239  break;
1240 
1241  case 'bwf':
1242  $type = 'audio/wav';
1243  break;
1244 
1245  case 'kar':
1246  case 'mid':
1247  case 'midi':
1248  case 'smf':
1249  $type = 'audio/midi';
1250  break;
1251 
1252  case 'm4a':
1253  $type = 'audio/x-m4a';
1254  break;
1255 
1256  case 'mp3':
1257  case 'swa':
1258  $type = 'audio/mp3';
1259  break;
1260 
1261  case 'wav':
1262  $type = 'audio/wav';
1263  break;
1264 
1265  case 'wax':
1266  $type = 'audio/x-ms-wax';
1267  break;
1268 
1269  case 'wma':
1270  $type = 'audio/x-ms-wma';
1271  break;
1272 
1273  // Video mime-types
1274  case '3gp':
1275  case '3gpp':
1276  $type = 'video/3gpp';
1277  break;
1278 
1279  case '3g2':
1280  case '3gp2':
1281  $type = 'video/3gpp2';
1282  break;
1283 
1284  case 'asf':
1285  $type = 'video/x-ms-asf';
1286  break;
1287 
1288  case 'flv':
1289  $type = 'video/x-flv';
1290  break;
1291 
1292  case 'm1a':
1293  case 'm1s':
1294  case 'm1v':
1295  case 'm15':
1296  case 'm75':
1297  case 'mp2':
1298  case 'mpa':
1299  case 'mpeg':
1300  case 'mpg':
1301  case 'mpm':
1302  case 'mpv':
1303  $type = 'video/mpeg';
1304  break;
1305 
1306  case 'm4v':
1307  $type = 'video/x-m4v';
1308  break;
1309 
1310  case 'mov':
1311  case 'qt':
1312  $type = 'video/quicktime';
1313  break;
1314 
1315  case 'mp4':
1316  case 'mpg4':
1317  $type = 'video/mp4';
1318  break;
1319 
1320  case 'sdv':
1321  $type = 'video/sd-video';
1322  break;
1323 
1324  case 'wm':
1325  $type = 'video/x-ms-wm';
1326  break;
1327 
1328  case 'wmv':
1329  $type = 'video/x-ms-wmv';
1330  break;
1331 
1332  case 'wvx':
1333  $type = 'video/x-ms-wvx';
1334  break;
1335 
1336  // Flash mime-types
1337  case 'spl':
1338  $type = 'application/futuresplash';
1339  break;
1340 
1341  case 'swf':
1342  $type = 'application/x-shockwave-flash';
1343  break;
1344  }
1345  }
1346 
1347  if ($find_handler)
1348  {
1349  if (in_array($type, $types_flash))
1350  {
1351  return 'flash';
1352  }
1353  elseif (in_array($type, $types_fmedia))
1354  {
1355  return 'fmedia';
1356  }
1357  elseif (in_array($type, $types_quicktime))
1358  {
1359  return 'quicktime';
1360  }
1361  elseif (in_array($type, $types_wmedia))
1362  {
1363  return 'wmedia';
1364  }
1365  elseif (in_array($type, $types_mp3))
1366  {
1367  return 'mp3';
1368  }
1369  else
1370  {
1371  return null;
1372  }
1373  }
1374  else
1375  {
1376  return $type;
1377  }
1378  }
1379 }
1380 




Korrekturen, Hinweise und Ergänzungen

Bitte scheuen Sie sich nicht und melden Sie, was auf dieser Seite sachlich falsch oder irreführend ist, was ergänzt werden sollte, was fehlt usw. Dazu bitte oben aus dem Menü Seite den Eintrag Support Forum wählen. Es ist eine kostenlose Anmeldung erforderlich, um Anmerkungen zu posten. Unpassende Postings, Spam usw. werden kommentarlos entfernt.