Changeset 612343
- Timestamp:
- 10/14/2012 05:47:33 PM (13 years ago)
- Location:
- edge-suite/trunk
- Files:
-
- 2 edited
-
edge-suite.php (modified) (3 diffs)
-
includes/edge-suite-comp.inc (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
edge-suite/trunk/edge-suite.php
r609085 r612343 379 379 extract( shortcode_atts( array( 380 380 'id' => '-1', 381 'left' => null, 382 'top' => null, 381 'left' => NULL, 382 'top' => NULL, 383 'iframe' => FALSE, 383 384 ), $atts ) ); 384 385 386 // The styles that will be added to the stage div inline or to the iframe 385 387 $styles = ''; 386 388 … … 401 403 402 404 $definition_id = $id; 403 $definition_res = edge_suite_comp_render($definition_id, $styles); 404 405 $stage = $scripts = ''; 406 407 if($definition_res != NULL){ 408 // Todo: Placing scripts inline in the content really isn't pretty, but so far there 409 // doesn't seem to be an easy way around this, otherwise we need to handle shortcode 410 // before header fuctions get called. 411 $scripts = implode("\n", $definition_res['scripts']); 412 413 $stage = $definition_res['stage']; 414 } 415 416 return "\n" . $scripts . "\n" . $stage ."\n"; 405 406 // iframe rendering 407 if(isset($iframe) && $iframe){ 408 return edge_suite_comp_iframe($definition_id, $styles); 409 } 410 // Inline rendering 411 else{ 412 $definition_res = edge_suite_comp_render($definition_id, $styles); 413 414 $stage = $scripts = ''; 415 416 if($definition_res != NULL){ 417 // Todo: Placing scripts inline in the content really isn't pretty, but so far there 418 // doesn't seem to be an easy way around this, otherwise we need to handle shortcode 419 // before header fuctions get called. 420 $scripts = implode("\n", $definition_res['scripts']); 421 422 $stage = $definition_res['stage']; 423 } 424 425 return "\n" . $scripts . "\n" . $stage ."\n"; 426 } 417 427 418 428 } … … 423 433 add_filter('widget_text', 'do_shortcode'); 424 434 } 435 436 /** 437 * Callback to check and deliver a plain composition to view within an iframe 438 */ 439 function edge_suite_iframe_callback(){ 440 // Todo: make configurable? 441 $check_referer = TRUE; 442 443 // Check if compoistion id GET parameter is set 444 // Todo: allow for admins so composition can be tested? 445 if(isset($_GET['edge_suite_iframe']) && intval($_GET['edge_suite_iframe']) > 0){ 446 if($check_referer){ 447 $site_url = get_bloginfo('wpurl'); 448 if (!isset($_SERVER['HTTP_REFERER']) || substr($_SERVER['HTTP_REFERER'], 0, strlen($site_url)) != $site_url) { 449 exit; 450 } 451 } 452 453 // Todo: check permissions for the user to view the compositions? 454 $definition_id = intval($_REQUEST['edge_suite_iframe']); 455 // Get composition 456 $content = edge_suite_comp_full_page($definition_id); 457 if(!empty($content)){ 458 // Deliver composition content and exit 459 header('Content-Type: text/html; charset=utf-8'); 460 print $content; 461 exit; 462 } 463 }; 464 } 465 add_action( 'template_redirect', 'edge_suite_iframe_callback' ); -
edge-suite/trunk/includes/edge-suite-comp.inc
r608822 r612343 226 226 227 227 if(!isset($definition->project_name)){ 228 return null;228 return NULL; 229 229 } 230 230 … … 268 268 } 269 269 270 271 /** 272 * Renders an iframe with the according callback url 273 * 274 * @param $definition_id Id of the composition definition to be viewed 275 * @param string $css_iframe_style CSS styles that will be added to the iframe 276 * @return string HTML for the iframe with the specific composition url 277 */ 278 function edge_suite_comp_iframe($definition_id, $css_iframe_style = '') { 279 $frame = ''; 280 if ($definition_id > 0) { 281 $definition = edge_suite_comp_load_definition($definition_id); 282 283 $url = get_bloginfo('wpurl') . '/' . 'index.php?edge_suite_iframe=' . $definition_id; 284 // Get dimensions and set iframe. 285 $width = isset($definition->info->width) ? $definition->info->width : 0; 286 $height = isset($definition->info->height) ? $definition->info->height : 0; 287 $style = 'style="width:' . $width . ';height:' . $height . ';' . $css_iframe_style . '" '; 288 $style .= 'scrolling="no" marginheight="0" marginwidth="0" frameborder="0"'; 289 $frame = '<iframe src="' . $url . '" name="composition-' . $definition_id . '" ' . $style . '></iframe> '; 290 } 291 return $frame; 292 } 293 294 /** 295 * Renders a full HTML page for the given definition id. 296 * 297 * @param integer definition id of the composition to render. 298 * 299 * @return string 300 * Returns the full HTML document, ready to be printed. 301 * 302 */ 303 function edge_suite_comp_full_page($definition_id) { 304 305 $html = NULL; 306 307 // Render composition instance. 308 $content = edge_suite_comp_render($definition_id); 309 if($content != NULL){ 310 // Output full HTML structure. 311 if(isset($content['scripts']) && is_array($content['scripts']) && !empty($content['stage'])){ 312 $scripts = implode("\n", $content['scripts']); 313 $stage = $content['stage']; 314 $html = 315 <<<HTML 316 <!DOCTYPE html> 317 <html> 318 <head> 319 <meta http-equiv="X-UA-Compatible" content="IE=edge"/> 320 $scripts 321 </head> 322 <body> 323 $stage 324 </body> 325 </html> 326 HTML; 327 } 328 } 329 return $html; 330 }
Note: See TracChangeset
for help on using the changeset viewer.