Example #1
0
 public static function open_stack()
 {
     global $config;
     // hack for now...
     $_REQUEST['stack'] = $config->stacks_url . $_REQUEST['stack'];
     /* check request variables */
     try {
         Util::check_request_vars(array('stack' => Util::REQUIRED));
     } catch (Exception $err) {
         Util::respond_with_http_error(400, 'Bad Request', 'Error: ' . $err->getMessage() . "\nTrace: " . $err->getTraceAsString());
     }
     /* sanitise input */
     try {
         $parts = explode(';', $_REQUEST['stack']);
         if (count($parts) >= 1) {
             $in_stack = Util::safe_stack_id($parts[0]);
         }
         if (count($parts) >= 2) {
             $in_card = Util::safe_card_ref($parts[1]);
         } else {
             $in_card = null;
         }
         $in_layer_art = '';
         if (count($parts) >= 3) {
             if ($parts[2] == 'card.png') {
                 $in_layer_art = 'card';
             } else {
                 if ($parts[2] == 'bkgnd.png') {
                     $in_layer_art = 'bkgnd';
                 } else {
                     Util::respond_with_http_error(400, 'Bad Request');
                 }
             }
         }
     } catch (Exception $err) {
         Util::respond_with_http_error($err->getCode(), $err->getMessage(), 'Error: ' . $err->getMessage() . "\nTrace: " . $err->getTraceAsString());
     }
     /* check if the input is a directory */
     if ($in_card == null && is_dir($in_stack)) {
         Application::do_dir_list($in_stack);
         exit;
     }
     /* try to open the specified stack and load the specified card */
     $stack_handle = null;
     $stack = null;
     $card = null;
     $bkgnd = null;
     try {
         $stack_handle = new Stack($in_stack);
         $stack = $stack_handle->stack_load();
         if ($in_card === null) {
             $in_card = $stack_handle->stack_get_nth_card_id(1);
         }
         $card = $stack_handle->stack_load_card($in_card);
         if ($card === null) {
             throw new Exception('Card Not Found', 404);
         }
         $bkgnd = $stack_handle->stack_load_bkgnd($card['bkgnd_id']);
         if (!$stack_handle) {
             throw new Exception('Stack Not Found', 404);
         }
     } catch (Exception $err) {
         /* there was a problem opening the stack or card;
         			return an appropriate HTTP response */
         $code = $err->getCode();
         $msg = $err->getMessage();
         $extra = '';
         if ($code == 0) {
             $code = 500;
             $msg = 'Internal Application Error';
             $extra = 'Error: ' . $err->getMessage() . "\nTrace: " . $err->getTraceAsString();
         }
         Util::respond_with_http_error($code, $msg, $extra);
         exit;
     }
     /* if a resource has been requested, provide it instead of the card */
     if ($in_layer_art != '') {
         if ($in_layer_art == 'card') {
             Application::layer_art($card, false);
         } else {
             Application::layer_art($card, true);
         }
         exit;
     }
     /* prepare the response for the loaded stack and card */
     Util::response_is_html();
     /* load the basic page template */
     $page = file_get_contents($config->base . 'html/stack.html');
     /* populate the template with the static card and appropriate meta information */
     $page = str_replace('js/', $config->url . 'js/', $page);
     $page = str_replace('icon/', $config->url . 'icon/', $page);
     $page = str_replace('?browser-warning=1', $config->url . '?browser-warning=1', $page);
     $page = str_replace('<!-- INSERT STATIC CARD -->', Application::static_page($stack, $card), $page);
     $page = str_replace('<!-- INSERT META -->', Application::meta($stack, $card), $page);
     /* compute the stack URL */
     //$stack['url'] = substr($stack['path'], strlen($config->url . 'stacks/'));
     /* populate the template with stack and card data sufficient to start the
     		web application environment on the client */
     $one = 1;
     $client_param_block = array('base' => $config->url, 'icon_collections' => Application::list_icon_collections(), 'plugin_commands' => Plugin::get_commands_list(), 'stack' => $stack, 'card' => $card, 'bkgnd' => $bkgnd);
     $page = str_replace('<!-- INSERT CLIENT LOAD SCRIPT -->', '<script type="text/javascript">' . 'CinsImp.init(' . json_encode($client_param_block, JSON_PRETTY_PRINT) . ');' . '</script>', $page, $one);
     /* send the static response page */
     print $page;
 }
Example #2
0
 public static function open_stack()
 {
     global $config;
     /* check request variables */
     try {
         Util::check_request_vars(array('stack' => Util::REQUIRED));
     } catch (Exception $err) {
         Util::respond_with_http_error(400, 'Bad Request', 'Error: ' . $err->getMessage() . "\nTrace: " . $err->getTraceAsString());
     }
     /* sanitise input */
     try {
         $parts = explode(';', $_REQUEST['stack']);
         if (count($parts) >= 1) {
             $in_stack = Util::safe_stack_id($parts[0]);
         }
         if (count($parts) >= 2) {
             $in_card = Util::safe_card_ref($parts[1]);
         } else {
             $in_card = null;
         }
         $in_layer_art = '';
         if (count($parts) >= 3) {
             if ($parts[2] == 'card.png') {
                 $in_layer_art = 'card';
             } else {
                 if ($parts[2] == 'bkgnd.png') {
                     $in_layer_art = 'bkgnd';
                 } else {
                     Util::respond_with_http_error(400, 'Bad Request');
                 }
             }
         }
     } catch (Exception $err) {
         Util::respond_with_http_error($err->getCode(), $err->getMessage(), 'Error: ' . $err->getMessage() . "\nTrace: " . $err->getTraceAsString());
     }
     /* check if the input is a directory */
     if ($in_card == null && is_dir($in_stack)) {
         Application::do_dir_list($in_stack);
         exit;
     }
     /* try to open the specified stack and load the specified card */
     $stack_handle = null;
     $stack = null;
     $card = null;
     try {
         $stack_handle = new Stack($in_stack);
         $stack = $stack_handle->stack_load();
         if ($in_card === null) {
             $in_card = $stack_handle->stack_get_first_card_id();
         }
         $card = $stack_handle->stack_load_card($in_card);
         if ($card === null) {
             throw new Exception('Card Not Found', 404);
         }
         if (!$stack_handle) {
             throw new Exception('Stack Not Found', 404);
         }
     } catch (Exception $err) {
         /* there was a problem opening the stack or card;
         			return an appropriate HTTP response */
         $code = $err->getCode();
         $msg = $err->getMessage();
         $extra = '';
         if ($code == 0) {
             $code = 500;
             $msg = 'Internal Application Error';
             $extra = 'Error: ' . $err->getMessage() . "\nTrace: " . $err->getTraceAsString();
         }
         Util::respond_with_http_error($code, $msg, $extra);
         exit;
     }
     /* if a resource has been requested, provide it instead of the card */
     if ($in_layer_art != '') {
         if ($in_layer_art == 'card') {
             Application::layer_art($card, false);
         } else {
             Application::layer_art($card, true);
         }
         exit;
     }
     /* prepare the response for the loaded stack and card */
     Util::response_is_html();
     /* load the basic page template */
     $page = file_get_contents($config->base . 'html/stack.html');
     /* populate the template with the static card and appropriate meta information */
     $page = str_replace('js/', $config->url . 'js/', $page);
     $page = str_replace('icon/', $config->url . 'icon/', $page);
     $page = str_replace('?browser-warning=1', $config->url . '?browser-warning=1', $page);
     $page = str_replace('<!-- INSERT STATIC CARD -->', Application::static_page($stack, $card), $page);
     $page = str_replace('<!-- INSERT META -->', Application::meta($stack, $card), $page);
     /* populate the template with stack and card data sufficient to start the
     		web application environment on the client */
     $one = 1;
     $page = str_replace('/* INSERT PRE-LOAD SCRIPT */', 'var gBase = \'' . $config->url . "';\n" . 'var _g_init_stack = ' . json_encode($stack) . ";\n" . 'var _g_init_card = ' . json_encode($card) . ";\n" . 'var _g_icon_collections = ' . json_encode(Application::list_icon_collections()) . ";", $page, $one);
     /* send the static response page */
     print $page;
 }