readByGuid($guid); // log $logDao = new \Drive\LogDao($pdo); $logData = new \Drive\LogData(); $logData->setData($_SERVER); $logDao->create($logData); // visitor check include_once 'process/visitors.php'; // check to see if Visitor code setting is enabled $visitorCode = $settingDao->read('site-visitorcode'); if (!checkVisitors($visitorCode, $slugGenerator)) { // need login, stop here return false; } $http = HTTP; $baseDomain = $http . '://' . DOMAINNAME; $domain = [ 'assets' => 'assets/', 'files' => 'files/', 'images' => 'images/', 'pages' => $baseDomain, 'name' => DOMAINNAME, ]; // set structure to be sent to twig (at bottom of file) // this allows for exceptions to be added into structure $body = array( 'title' => '', 'subTitle' => '', 'content' => '', 'breadcrumb' => [] ); $pageTitle = ''; $pageSubTitle = ''; $pageContent = ''; $title = ''; $metaKey = ''; $metaDesc = ''; $altLang = $alternateLanguages; //always an array (sometimes empty) $altLangLink = array(); // leave blank -> processed below $canonical = ''; $author = ''; $breadcrumb = array(); $menu = array(); $submenu = array(); $routes = array(); //meta data $facebookTitle = ''; $facebookDesc = ''; $facebookImg = ''; $twitterTitle = ''; $twitterDesc = ''; $editNone = $driveContentArray->getEditNoneArray($languageIndex); $editShort = $driveContentArray->getEditShortArray($languageIndex); $editLong = $driveContentArray->getEditLongArray($languageIndex); $editPlain = $driveContentArray->getEditPlainArray($languageIndex); $siteName = $contentDao->read('site-name', $languageIndex); $twig404 = false; //assume we hit a valid page $baseUrl = '/'; if ($driveLanguages->isMultilingual()) { $baseUrl .= $languageIndex . '/'; } //set baseURl for alternate languages foreach ($altLang as $alternateLanguage) { $altLangLink[$alternateLanguage['index']] = '/'; if ($driveLanguages->isMultilingual()) { $altLangLink[$alternateLanguage['index']] = '/' . $alternateLanguage['index'] . '/'; } } // Template: values used everywhere // sets up product categories and products for the router require './controllers/_general.php'; //router $router = new \Custom\Router(); //$router->setBasePath('/drive/'); //if we are in a subfolder //add custom date regEx for blog category: e.g. 2018-05 $router->addMatchTypes(array('yearMonth' => '(19|2[0-1])\d{2}-(0[1-9]|1[0-2])')); $router->addMatchTypes(array('cte' => 'no-cte|cte')); //////////////////////////// // ADD ROUTE EXCEPTIONS HERE // http://altorouter.com/usage/mapping-routes.html //$name = 'routeName'; //needs to be unique // //$target = 'controllerName#' . $menuID . '#' . $submenuID; ////leave menu ids blank if necessary, but include the hashtags //controllerName needs to match the name of the controller file in 'controllers' // //$exceptionRoute = '[format:parameterName]' . '/'; //use as many levels/parameters as required // //$route = $baseUrl . $menuRoute . $exceptionRoute; //use menu/submenu routes as required // //$routes[] = array('GET', $route, $target, $name); // add route for sitemap.xml $routes[] = array('GET', '/sitemap.xml', 'sitemap', 'sitemap'); try { //add preview routes when user is logged in if ($admin->isLoggedIn()) { //add blog preview routes if (in_array('blog', $admin->accessIndexes, true)) { $router->addBlogPreviewRoutes($siteMenu, $baseUrl); } } //add menu routes $router->addMenuRoutes($siteMenu, $baseUrl); //add routes outside of the menu structure if necessary $router->addBlogRoutes($siteMenu, $baseUrl); //add product category $router->addProductCategoryRoutes($siteMenu, $baseUrl, $general['productCategories']); //add product routes; we have very few products and categories -> adding all routes should not take too long $router->addProductRoutes($siteMenu, $baseUrl, $general['products'], $general['productCategories']); //add recipe routes; we do no have too many recipes -> adding all routes should not take too long //if it ever does, change the router to use a placeholder for the recipe canonicalLink //and add an 'existing' check to the controller (throw 404 if recipe does not exist) $router->addRecipePageRoutes($siteMenu, $baseUrl); $router->addRecipeRoutes($siteMenu, $baseUrl, $general['recipes']); $router->addShareRecipeRoutes($siteMenu, $baseUrl); $router->addTellAFriendRoutes($siteMenu, $baseUrl); $router->addSubmitARecipeRoute($siteMenu, $baseUrl); //add exceptional routes $router->addRoutes($routes); } catch (Exception $exception) { //TODO: route to 404? Alert user? Log? } $match = $router->match(); // call closure or throw 404 status if (!empty($match)) { //get the controller and menu Ids list($controller, $menuID, $submenuID) = explode('#', $match['target']); //generate the canonical link from the match (to be used in $metaData) try { $canonical = $router->generate($match['name'], $match['params']); } catch (Exception $exception) { $canonical = ''; } include 'controllers/' . $controller . '.php'; } else { //no route was matched $match['target'] = '404'; $twig404 = true; //header( $_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found'); } if($match['name'] === 'actionShare_recipe' || $match['name'] === 'actionTell_a_friend'){ //ignore 'share recipe' route if not followed by canonical link $match['target'] = '404'; $twig404 = true; } if (empty($title)) { $title = $pageTitle; } if (empty($templateFilename)) { $templateFilename = $menuTemplateDao->readDefaultTemplate()->name; } //////////////////////////////// // write the content to the page // Country $country = [ 'index' => $settingDao->read('site-country-index'), 'name' => $contentDao->read('site-country-name', $languageIndex), ]; $meta = array( 'theme' => '#e62c3a', 'canonical' => $canonical, 'alternateLanguageLinks' => $altLangLink, 'author' => $author, 'title' => strip_tags($title), 'description' => $metaDesc, 'keywords' => $metaKey, 'opengraph' => [ // Required 'type' => '', 'title' => '', 'image' => '', 'url' => '', // Optional 'site_name' => '', 'description' => '', 'audio' => '', 'video' => '', 'determiner' => '', // a, an, the, auto or "" (blank, the default value) 'locale' => $languageIndex . '_' . $country['index'], 'locale_alternate' => ['fr_CA', 'en_US'], // displayed as locale:alternate ], 'facebook' => [ 'title' => $facebookTitle, 'description' => $facebookDesc, 'image' => $facebookImg ], 'twitter' => [ // Required 'card' => 'summary', 'title' => $twitterTitle, // Optional 'site' => $siteName, 'description' => $twitterDesc, //'image' => 'http://drivemarketing.ca/path-to-image.jpg', //'image_alt' => 'Alt text for this image', //'creator' => '@myname', ], //'google' => [ // 'link' => '', //], ); // body structure declared at top of file // this allows for exceptions $body['title'] = $pageTitle; $body['subTitle'] = $pageSubTitle; $body['content'] = $pageContent; $body['breadcrumb'] = $breadcrumb; $admin = $adminRepository->readByGuid($guid); //this is the array we send to twig $content = array( 'testMode' => TESTMODE, 'DOMAINNAME' => DOMAINNAME, 'HTTP' => HTTP, 'admin' => $admin, 'settings' => [ 'analytics' => $settingDao->readPartial('analytics-%', true), 'breakpoints' => $settingDao->readPartial('breakpoints-%', true), 'country' => $country, 'share' => $settingDao->readPartial('share-%', true), 'site' => $siteName, 'soon' => $settingDao->readPartial('soon-image-%', true), ], 'login' => [ 'enabled' => $settingDao->read('login-enabled'), ], 'baseUrl' => $baseUrl, 'http' => $http, 'domain' => $domain, 'languageIndex' => $languageIndex, 'languages' => $driveLanguages->getLanguages(), 'country' => $country, 'meta' => $meta, 'selectedMenu' => $selectedMenu ? $selectedMenu : '', 'siteMenu' => $siteMenu, 'general' => $general, 'body' => $body, 'editNone' => $editNone, 'editShort' => $editShort, 'editPlain' => $editPlain, 'editLong' => $editLong, 'multilingual' => $driveLanguages->isMultilingual(), 'timestamp' => date('U'), 'nav' => [ 'menuIndex' => isset($menu['index']) ? $menu['index'] : '', 'submenuIndex' => isset($submenu['index']) ? $submenu['index'] : '', ], ); //echo '
' . print_r($content, true) . '