This repository has been archived by the owner on Jan 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgetEmbedCode.php
executable file
·99 lines (84 loc) · 3.01 KB
/
getEmbedCode.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
* This is a soap endpoint for MiddMedia
*
* @package middmedia
*
* @copyright Copyright © 2005, Middlebury College
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
*
* @version $Id$
*/
/*********************************************************
* Setup stuff.
*********************************************************/
// Setup
define("MYDIR",dirname(__FILE__));
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
$protocol = 'https';
else
$protocol = 'http';
define("MYPATH", $protocol."://".$_SERVER['HTTP_HOST'].str_replace(
"\\", "/",
dirname($_SERVER['PHP_SELF'])));
define("MYURL", MYPATH."/index.php");
try {
if (!isset($_GET['directory']) || !$_GET['directory']) {
require_once(dirname(__FILE__)."/main/include/libraries.inc.php");
throw new NullArgumentException("The 'directory' parameter must be specified.");
}
if (!isset($_GET['file']) || !$_GET['file']) {
require_once(dirname(__FILE__)."/main/include/libraries.inc.php");
throw new NullArgumentException("The 'file' parameter must be specified.");
}
// Load from cache if possible
if (function_exists('apc_fetch')) {
$embedCode = apc_fetch('embed-'.$_GET['directory'].'/'.$_GET['file']);
if ($embedCode !== FALSE) {
print $embedCode;
exit;
}
}
require_once(dirname(__FILE__)."/main/include/libraries.inc.php");
require_once(dirname(__FILE__)."/main/include/setup.inc.php");
// Execution
$manager = MiddMedia_Manager_Unauthenticated::instance();
$directory = $manager->getDirectory($_GET['directory']);
$file = $directory->getFile($_GET['file']);
$plugins = MiddMedia_Embed_Plugins::instance();
foreach ($plugins->getPlugins() as $embed) {
if ($embed->isSupported($file)) {
print $embed->getMarkup($file);
break;
}
}
// Save to cache if possible
if (function_exists('apc_store')) {
apc_store('embed-'.$_GET['directory'].'/'.$_GET['file'], $embedCode, 21600);
}
// Handle certain types of uncaught exceptions specially. In particular,
// Send back HTTP Headers indicating that an error has ocurred to help prevent
// crawlers from continuing to pound invalid urls.
} catch (UnknownActionException $e) {
header('HTTP/1.1 404 Not Found');
print "<h1>404 NOT FOUND</h1>";
print "<p>".$e->getMessage()."</p>";
} catch (NullArgumentException $e) {
header('HTTP/1.1 400 Bad Request');
print "<h1>400 Bad Request</h1>";
print "<p>".$e->getMessage()."</p>";
} catch (PermissionDeniedException $e) {
header('HTTP/1.1 403 Forbidden');
print "<h1>403 Forbidden</h1>";
print "<p>".$e->getMessage()."</p>";
} catch (UnknownIdException $e) {
header('HTTP/1.1 404 Not Found');
print "<h1>404 NOT FOUND</h1>";
print "<p>".$e->getMessage()."</p>";
}
// Default
catch (Exception $e) {
header('HTTP/1.1 500 Internal Server Error');
print "<h1>500 Internal Server Error</h1>";
print "<p>".$e->getMessage()."</p>";
}