Пример #1
0
 /**
  * Sends the verification email to this user if their email addresss
  * has not already been verified.
  * @return boolean
  */
 public function sendVerificationEmail()
 {
     // Force the user to get a new verification code
     $newCode = $this->getNewEmailVerificationCode();
     // Now send it to them
     $url = APP_ABSOLUTE_URL . Routes::getControllerRelativeUrl('user#verify', array('userid' => $this->getUserId(), 'code' => $newCode));
     return $this->sendEmail('Please verify your email address', 'You can verify your email address by clicking <a href="' . $url . '">here</a>');
 }
Пример #2
0
 /**
  * Creates a new notification for a user.
  * @param User $user The user to notify.
  * @param type $message The message to deliver.
  * @return Notificaton
  * @throws Exception
  */
 public static function create(User $user, $message, $controller = '', $replacements = array(), $imageurl = '')
 {
     // Make sure the user is not a guest
     if ($user->isGuest()) {
         throw new Exception('Notifications cannot be created for guests.');
     }
     $link = '';
     if (!empty($controller)) {
         $link = Routes::getControllerRelativeUrl($controller, $replacements);
     }
     // Add the notification to the database
     $query = Database::connection()->prepare('INSERT INTO user_notification (userid, created_at, message, link, image_url) VALUES (?, ?, ?, ?, ?)');
     $query->bindValue(1, $user->getUserId(), PDO::PARAM_INT);
     $query->bindValue(2, time(), PDO::PARAM_INT);
     $query->bindValue(3, $message, PDO::PARAM_STR);
     $query->bindValue(4, $link, PDO::PARAM_STR);
     $query->bindValue(5, $imageurl, PDO::PARAM_STR);
     if (!$query->execute()) {
         throw new Exception('Notification could not be created.');
     }
     // Let's send an email right away
     return Notification::fromId(Database::connection()->lastInsertId());
 }
Пример #3
0
 /**
  * Initializes the templating system.
  */
 private static function initialize()
 {
     // Make sure it's not already initialized
     if (self::$initialized) {
         return;
     }
     // Load up and register Twig
     require_once APP_VENDOR_PATH . '/Twig/Autoloader.php';
     Twig_Autoloader::register();
     // Greate the environment
     $loader = new Twig_Loader_Filesystem(APP_VIEWS_PATH);
     $loader->addPath(APP_VIEWS_PATH . '/shared');
     $loader->addPath(APP_VIEWS_PATH_CORE);
     $loader->addPath(APP_VIEWS_PATH_CORE . '/shared');
     $twig = new Twig_Environment($loader, array('auto_reload' => true));
     // Add in the custom twig functions
     // The getPath function turns controller endpoints into relative
     // urls that can be used in the interface.
     $getPathFunction = new Twig_SimpleFunction("get_path", function () {
         $args = func_get_args();
         if (count($args) == 0) {
             return;
         }
         $controller = $args[0];
         array_shift($args);
         return Routes::getControllerRelativeUrl($controller, $args);
     });
     $twig->addFunction($getPathFunction);
     // Used to make images square with no distortion
     $avatarFunction = new Twig_SimpleFunction("avatar", function () {
         $args = func_get_args();
         $addon = '';
         if (count($args) == 2 && $args[1] == true) {
             $addon = '-small';
         } else {
             if (count($args) > 1) {
                 return;
             }
         }
         if (empty($args[0])) {
             $url = Routes::getControllerRelativeUrl('image#noavatar');
         } else {
             $url = Routes::getControllerRelativeUrl('image#viewthumb', array($args[0]));
         }
         echo '<div class="avatar-wrapper"><div class="avatar' . $addon . '" style="background-image: url(\'' . $url . '\');"></div></div>';
     });
     $twig->addFunction($avatarFunction);
     // Used to make images square with no distortion
     $friendlyUrlFunction = new Twig_SimpleFunction("seo_friendly", function () {
         $args = func_get_args();
         if (count($args) != 1) {
             return;
         }
         return Utils::makeSeoFriendly($args[0]);
     });
     $twig->addFunction($friendlyUrlFunction);
     // The public function allows the interface to get public resources
     $publicResourceFunction = new Twig_SimpleFunction("public_path", function ($path) {
         echo APP_RELATIVE_URL . '/public/' . Routes::fixPath($path);
     });
     $twig->addFunction($publicResourceFunction);
     // Set the reference
     self::$twig = $twig;
     self::$initialized = true;
 }