-
Notifications
You must be signed in to change notification settings - Fork 60
/
preview.php
188 lines (150 loc) · 6.94 KB
/
preview.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?PHP
/**
* Licensed to The Apereo Foundation under one or more contributor license
* agreements. See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
* The Apereo Foundation licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
*
* preview page, allows the site to make a preview page for a xerte module
*
* @author Patrick Lockley
* @version 1.0
* @params array row_play - The array from the last mysql query
* @package
*/
require_once(dirname(__FILE__) . '/../../website_code/php/xmlInspector.php');
/**
*
* Function show_preview_code
* This function creates folders needed when creating a template
* @param array $row - an array from a mysql query for the template
* @param array $row_username - an array from a mysql query for the username
* @version 1.0
* @author Patrick Lockley
*/
require_once(dirname(__FILE__) . "/play.php");
function show_preview_code($row)
{
global $xerte_toolkits_site;
$template_dir = $xerte_toolkits_site->users_file_area_full . $row['template_id'] . "-" . $row['username'] . "-" . $row['template_name'] . "/";
if(!file_exists($template_dir .'/preview.xml')) {
$buffer = file_get_contents($template_dir . '/data.xml');
$fp = fopen($template_dir . '/preview.xml','x');
fwrite($fp, $buffer);
fclose($fp);
}
$preview_filename = "preview.xml";
//************ TEMPORARY ****************
//if (file_exists($template_dir . '/preview2.xml')) {
// $preview_filename = "preview2.xml";
//}
//***************************************
echo show_template_page($row, $preview_filename);
}
function show_preview_code2($row, $row_username){
global $xerte_toolkits_site, $youtube_api_key;
_load_language_file("/modules/xerte/preview.inc");
$template_dir = $xerte_toolkits_site->users_file_area_full . $row['template_id'] . "-" . $row['username'] . "-" . $row['template_name'] . "/";
/*
* Format the XML strings to provide data to the engine
*/
if(!file_exists($template_dir . '/preview.xml')) {
$buffer = file_get_contents($template_dir . "/data.xml");
$fp = fopen($template_dir . "/preview.xml","x");
fwrite($fp, $buffer);
fclose($fp);
}
$string_for_flash = $xerte_toolkits_site->users_file_area_short . $row['template_id'] . "-" . $row_username['username'] . "-" . $row['template_name'] . "/";
$xmlfile = $string_for_flash . "preview.xml";
$xmlFixer = new XerteXMLInspector();
$xmlFixer->loadTemplateXML($xmlfile, true);
if (strlen($xmlFixer->getName()) > 0)
{
$title = $xmlFixer->getName();
}
else
{
$title = XERTE_PREVIEW_TITLE;
}
$string_for_flash_xml = $xmlfile . "?time=" . time();
$flash_js_dir = "modules/" . $row['template_framework'] . "/";
$template_path = "modules/" . $row['template_framework'] . "/parent_templates/" . $row['template_name'] . "/";
$rlo_file = $template_path . $row['template_name'] . ".rlt";
list($x, $y) = explode("~",get_template_screen_size($row['template_name'],$row['template_framework']));
// determine the correct engine to use
$engine = 'flash';
$extra_flags = explode(";", $row['extra_flags']);
foreach($extra_flags as $flag)
{
$parameter = explode("=", $flag);
switch($parameter[0])
{
case 'engine':
$engine = $parameter[1];
break;
}
}
// If given as a parameter, force this engine
// If given as a parameter, force this engine
if (isset($_REQUEST['engine']))
{
if ($_REQUEST['engine'] == 'other')
{
if ($engine == 'flash')
$engine = 'javascript';
else
$engine = 'flash';
}
else
{
$engine=$_REQUEST['engine'];
}
}
if ($engine == 'flash')
{
$page_content = file_get_contents($xerte_toolkits_site->basic_template_path . $row['template_framework'] . "/player/rloObject.htm");
$page_content = str_replace("%WIDTH%", $x, $page_content);
$page_content = str_replace("%HEIGHT%", $y, $page_content);
$page_content = str_replace("%TITLE%", $title , $page_content);
$page_content = str_replace("%RLOFILE%", $rlo_file, $page_content);
$page_content = str_replace("%JSDIR%", $flash_js_dir, $page_content);
$page_content = str_replace("%XMLPATH%", $string_for_flash, $page_content);
$page_content = str_replace("%XMLFILE%", $string_for_flash_xml, $page_content);
$page_content = str_replace("%SITE%",$xerte_toolkits_site->site_url,$page_content);
$tracking = "<script type=\"text/javascript\" src=\"" . $template_path . "common_html5/js/xttracking_noop.js?version=" . $version . "\"></script>";
$page_content = str_replace("%TRACKING_SUPPORT%", $tracking, $page_content);
}
else
{
$version = getVersion();
// $engine is assumed to be javascript if flash is NOT set
$page_content = file_get_contents($xerte_toolkits_site->basic_template_path . $row['template_framework'] . "/player_html5/rloObject.htm");
$page_content = str_replace("%VERSION%", $version , $page_content); // $engine is assumed to be html5 if flash is NOT set
$page_content = str_replace("%VERSION_PARAM%", "?version=" . $version , $page_content); // $engine is assumed to be html5 if flash is NOT set
$page_content = str_replace("%TITLE%", $title , $page_content);
$page_content = str_replace("%TEMPLATEPATH%", $template_path, $page_content);
$page_content = str_replace("%XMLPATH%", $string_for_flash, $page_content);
$page_content = str_replace("%XMLFILE%", $string_for_flash_xml, $page_content);
$page_content = str_replace("%THEMEPATH%", "themes/" . $row['template_name'] . "/",$page_content);
// Handle offline variables
$page_content = str_replace("%OFFLINESCRIPTS%", "", $page_content);
$page_content = str_replace("%OFFLINEINCLUDES%", "", $page_content);
$page_content = str_replace("%MATHJAXPATH%", "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/", $page_content);
$tracking = "<script type=\"text/javascript\" src=\"" . $template_path . "common_html5/js/xttracking_noop.js?version=" . $version . "\"></script>";
$page_content = str_replace("%TRACKING_SUPPORT%", $tracking, $page_content);
$page_content = str_replace("%YOUTUBEAPIKEY%", $youtube_api_key, $page_content);
}
echo $page_content;
}