/** * Initialize the app metadata store, especially the APP_PATH and APP_URL * * @return AppMetadata **/ public static function createAppMetadata() { global $secrets; // FIXME grown-ups don't program like this global $sql; // FIXME grown-ups don't program like this global $metadata; // FIXME grown-ups don't program like this global $smarty; // FIXME grown-ups don't program like this if (AppMetadata::prepareDatabase($sql)) { $smarty->addMessage('App metadata database tables created', 'Database tables to store application metadata, which is used to build the <code>config.xml</code> file, have been created in your MySQL database.', NotificationMessage::GOOD); } else { $smarty->addMessage('App metadata database tables exist', 'Database tables to store application metadata already exist and have not been re-created.'); } $metadata = initAppMetadata(); $metadata['APP_PATH'] = preg_replace('/\\/classes$/', '', __DIR__); $metadata['APP_URL'] = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on' ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . preg_replace("|^{$_SERVER['DOCUMENT_ROOT']}(.*)\$|", '$1', $metadata['APP_PATH']); $metadata['APP_NAME'] = (string) $secrets->app->name; $metadata['APP_ID'] = (string) $secrets->app->id; $metadata['CANVAS_INSTANCE_URL_PLACEHOLDER'] = 'https://canvas.instructure.com'; $smarty->assign('metadata', $metadata); $smarty->addMessage('App metadata initialized', 'Basic application metadata has been updated, including APP_PATH and APP_URL', NotificationMessage::GOOD); return $metadata; }
* * *****************************************************************************/ /* assume everything's going to be fine... */ $ready = true; /* preliminary interactive only initialization */ if (php_sapi_name() != 'cli') { session_start(); /* fire up the templating engine for interactive scripts */ $smarty = StMarksSmarty::getSmarty(true, __DIR__ . '/templates'); } /* initialization that needs to happen for interactive and CLI scripts */ try { /* initialize global variables */ $secrets = initSecrets(); $sql = initMySql(); $metadata = initAppMetadata(); } catch (CanvasAPIviaLTI_Exception $e) { $smarty->addMessage('Initialization Failure', $e->getMessage(), NotificationMessage::ERROR); $smarty->display(); exit; } /* interactive initialization only */ if ($ready && php_sapi_name() != 'cli') { /* allow web apps to use common.inc.php without LTI authentication */ if (!defined('IGNORE_LTI')) { try { if (midLaunch()) { $ready = false; } elseif (isset($_SESSION['toolProvider'])) { $toolProvider = $_SESSION['toolProvider']; } else {
/** * Initialize the app metadata store, especially the APP_PATH and APP_URL * * @return AppMetadata **/ public static function createAppMetadata() { global $secrets; // FIXME grown-ups don't program like this global $sql; // FIXME grown-ups don't program like this global $metadata; // FIXME grown-ups don't program like this global $smarty; // FIXME grown-ups don't program like this $metadata = initAppMetadata(); $metadata['APP_PATH'] = preg_replace('/\\/classes$/', '', __DIR__); $metadata['APP_URL'] = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on' ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . preg_replace("|^{$_SERVER['DOCUMENT_ROOT']}(.*)\$|", '$1', $metadata['APP_PATH']); $metadata['APP_NAME'] = (string) $secrets->app->name; $metadata['APP_ID'] = (string) $secrets->app->id; $metadata['CANVAS_INSTANCE_URL_PLACEHOLDER'] = 'https://canvas.instructure.com'; $smarty->assign('metadata', $metadata); $smarty->addMessage('App metadata initialized', 'Basic application metadata has been updated, including APP_PATH and APP_URL', NotificationMessage::GOOD); return $metadata; }