/** * Dissect the URL and route the request. */ function callHook() { $controller = CShell::id(); $action = 'home'; $queryString = array(); try { //Remove all get parameters $URI = preg_replace('/\\?(.*)/', '', $_SERVER['REQUEST_URI']); $urlArray = explode("/", str_replace('-', '_', $URI)); //The first segment will always be empty if (count($urlArray) > 0) { array_shift($urlArray); } if (count($urlArray) > 0 && $urlArray[0] != '') { //Ignore the sub-folder if it exists. if (PageTool::getSubFolder() != '') { array_shift($urlArray); } /** * If an exception is triggered or the dc is set to false set the controller. */ if (count($urlArray) > 0 && (in_array($urlArray[0], CShell::exceptions()) || in_array($urlArray[0], CShell::system()) || !CShell::default_controller())) { $controller = $urlArray[0]; array_shift($urlArray); } //Set the action. if (count($urlArray) > 0) { //If GoLink skip assignment of action. if ($controller != CShell::GO) { $action = $urlArray[0]; array_shift($urlArray); } //Set the arguments if (count($urlArray) > 0) { $queryString = $urlArray; } } } $controllerName = $controller; $controller = ucwords($controller); $controller .= 'Controller'; if (file_exists(ROOT . DS . 'app' . DS . 'controllers' . DS . $controller . '.php')) { require_once ROOT . DS . 'app' . DS . 'controllers' . DS . $controller . '.php'; } elseif (file_exists(ROOT . DS . 'app' . DS . 'controllers' . DS . 'system' . DS . $controller . '.php')) { require_once ROOT . DS . 'app' . DS . 'controllers' . DS . 'system' . DS . $controller . '.php'; } if (class_exists($controller) && method_exists($controller, $action)) { $dispatch = new $controller($controllerName, $action); } else { header('HTTP/1.0 404 Not Found'); exit; } call_user_func_array(array($dispatch, $action), $queryString); } catch (Exception $e) { SystemTool::sendException($e->getFile(), $e->getMessage(), $e->getTraceAsString()); } }
public function opt_in() { $this->setCache(false); $this->_return = self::PROCESS; //Redirect if no post data if (!isset($_POST) || count($_POST) < 1) { header("Location: " . PageTool::getSiteRoot()); exit; } $anchor = ''; if (isset($_POST["anchor"])) { $anchor = $_POST["anchor"]; } $backto = ''; if (isset($_POST["backto"])) { $backto = $_POST["backto"]; } $from = ''; if (isset($_POST["from"])) { $from = $_POST["from"]; } $sprott = 0; if (isset($_POST["sprott"]) && $_POST["sprott"] == "on") { $sprott = 1; } //Redirect with error if bad email $email = SystemTool::sanitize($_POST["email"], 2); if (!SystemTool::validate($email)) { header("Location: " . PageTool::getSiteRoot() . $backto . "?e=no" . $anchor); exit; } //Ensure we are in a session, if we are not then set up DynamoDB SystemTool::ensureSession(); //Initialize client library Casey_Client::init(SystemTool::getAPIHost(), CShell::entity(), ENV, SystemTool::getAPIUser(), SystemTool::getAPIPass()); Linkserver_Client::init(SystemTool::getLinkServerHost(), ENV, SystemTool::getLinkServerUser(), SystemTool::getLinkServerPass()); //Set the product sku $skus = CShell::skus(); if ($from == "cr") { $sku = $skus['cr']; } else { $sku = $skus['primary']; } //Assemble tracking data $url = TrackingTool::getURL(); $user_tracking_id = !empty($_SESSION['user_tracking_id']) ? $_SESSION['user_tracking_id'] : null; $session_tracking_id = !empty($_SESSION['session_tracking_id']) ? $_SESSION['session_tracking_id'] : null; $client_tracking_id = !empty($_SESSION['client_tracking_id']) ? $_SESSION['client_tracking_id'] : null; $affiliate_source = !empty($_SESSION['affiliate_source']) ? $_SESSION['affiliate_source'] : null; $affiliate_id = !empty($_SESSION['affid']) ? $_SESSION['affid'] : null; if (empty($affiliate_id)) { $affiliate_id = !empty($_COOKIE['affid']) ? $_COOKIE['affid'] : null; $affiliate_source = 'cookie'; if (empty($affiliate_id)) { $affiliate_id = null; $affiliate_source = null; } } if (empty($user_tracking_id)) { $user_tracking_id = !empty($_COOKIE['user_tracking_id']) ? $_COOKIE['user_tracking_id'] : null; } $ppref = ''; if (strlen($affiliate_id) > 2) { $ppref = strtoupper(substr($affiliate_id, 0, 3)) . "999" . "ZZ" . "9999" . "Z"; } //Track product purchase. try { CC_Product_Access::recordProductAccessRegistration($email, $sku, $ppref, $affiliate_id, $affiliate_source, $user_tracking_id, $session_tracking_id, $client_tracking_id, $url); if ($sprott) { $pubIDs = CShell::pubIDs(); $EOM = new Email_optsModel(); $EOM->addRecord($email, $pubIDs['sprott'], $affiliate_id, $affiliate_source, $user_tracking_id, $session_tracking_id, $client_tracking_id, $url, SystemTool::getTimestamp()); } } catch (Exception $e) { SystemTool::sendException($e->getFile(), $e->getMessage(), $e->getTraceAsString()); header("Location: " . PageTool::getSiteRoot() . $backto . "?e=no" . $anchor); exit; } //set cookie to recognize return users! setcookie(SystemTool::getCookieName(), base64_encode($email), PageTool::getCookieLength(), '/', CShell::cookieDomain()); // 1yr cookie setcookie(CShell::GA_CONV, '1', PageTool::getCookieLength(), CShell::cookiePath(), CShell::cookieDomain()); // 1yr cookie //Set up and render the email HTML. $eTemplate = new Template('email_sign_up'); if ($from == "cr") { $eTemplate->set('cr', true); } $body = $eTemplate->render(false); $alt = strip_tags($body); //Send the email. $PHPEmails = CShell::emails(); SystemTool::sendEmail($PHPEmails["registration"], $email, $body, $alt); //Redirect to the correct page. header("Location: " . PageTool::getSiteRoot() . $backto); exit; }