/**
  * The default process
  *
  * @since ADD MVC 0.0
  */
 public function process_mode_default()
 {
     $this->view()->assign('current_controller', add::current_controller_class());
     $this->view()->assign('current_view', $this->view_filepath());
     $this->view()->assign('utc_timestamp', time());
     $this->view()->assign('member', member::current_logged_in());
 }
 /**
  * Require existence of a directory
  *
  * @since ADD MVC 0.5
  */
 public static function require_dir_exists($dir, $writable = null)
 {
     if (!file_exists($dir)) {
         throw new e_system("Directory {$dir} is not existing", add::config());
     }
     if (!is_writable($dir)) {
         throw new e_system("Directory {$dir} is not writable", add::config());
     }
 }
 public static function current_user_allowed()
 {
     add::load_functions('network');
     if (current_ip_in_network()) {
         return true;
     } else {
         return false;
     }
 }
 /**
  * The pre-view process
  *
  * @since ADD MVC 0.0
  */
 public function process()
 {
     # Required Directories
     self::require_dir_exists(add::config()->incs_dir);
     self::require_dir_exists(add::config()->caches_dir, true);
     $this->require_dir($this->view()->compile_dir, true);
     $this->require_dir($this->view()->cache_dir, true);
     # Other essential directories
     $this->check_dir_exists(add::config()->classes_dir);
     $this->check_dir_exists(add::config()->assets_dir);
     $this->check_dir_exists(add::config()->css_dir);
     $this->check_dir_exists(add::config()->js_dir);
 }
 /**
  * Smarty construct
  *
  * @since ADD MVC 0.0
  */
 public function __construct()
 {
     $C = add::config();
     parent::__construct();
     if (is_array($C->views_dir)) {
         $this->setTemplateDir(array_merge($C->views_dir, array($C->add_dir . '/views/')));
     } else {
         $this->setTemplateDir(array($C->views_dir, $C->add_dir . '/views/'));
     }
     $this->compile_dir = $C->caches_dir . '/smarty_compile/';
     $this->config_dir = $C->configs_dir . '/smarty/';
     $this->cache_dir = $C->caches_dir . '/smarty_cache/';
 }
 /**
  * Must echo the page response
  *
  * @since ADD MVC 0.6
  */
 public function execute()
 {
     # ADD MVC 0.5 backward support
     if (method_exists($this, 'page')) {
         return $this->page();
     }
     # Set Content Type
     $this->content_type($this->content_type);
     $this->mode = isset($_REQUEST['mode']) ? "{$_REQUEST['mode']}" : '';
     add::$handle_shutdown = false;
     $this->process_data(isset($this->common_gpc) ? ctrl_tpl_page::recursive_compact($this->common_gpc) : array());
     $this->print_response($this->data);
 }
 /**
  * run the page
  *
  * @since ADD MVC 0.4
  */
 public function page()
 {
     header("Content-type: text/plain");
     e_hack::assert($this->can_run(), "Invalid aux script authentication key");
     ob_start();
     try {
         $this->process();
     } catch (Exception $e) {
         add::handle_exception($e);
     }
     $this->response = ob_get_clean();
     $this->handle_response();
 }
 /**
  * run the page
  *
  * @since ADD MVC 0.6.2
  */
 public function execute()
 {
     e_hack::assert($this->can_run(), "Invalid aux script authentication key");
     # Set Content Type
     $this->content_type($this->content_type);
     ob_start();
     try {
         $this->process_data();
     } catch (Exception $e) {
         add::handle_exception($e);
     }
     $this->response = ob_get_clean();
     $this->handle_response();
 }
 /**
  * Login
  *
  * @param array $gpc - contains $gpc['username'] and $gpc['password']
  *
  */
 public function process_mode_login($gpc)
 {
     # validation on controller
     if (empty($gpc['username'])) {
         throw new e_user_input("Blank username");
     }
     if (empty($gpc['password'])) {
         throw new e_user_input("Blank password");
     }
     # login the session user class
     if (member::login($gpc['username'], $gpc['password']) instanceof member) {
         add::redirect(add::config()->path);
     }
 }
 public static function load_dir_classes($dir)
 {
     $class_files = new DirectoryIterator($dir);
     foreach ($class_files as $class_file) {
         if ($class_file->isDot()) {
             continue;
         }
         if ($class_file->isDir()) {
             static::load_dir_classes($class_file->getPathName());
             continue;
         }
         if (preg_match('/(\\.class)?\\.php$/', $class_file->getFileName())) {
             $class_name = $class_file->getBaseName('.class.php');
             if (!$class_name) {
                 var_dump($class_file->getPathName());
                 die;
             }
             if (add::load_class($class_name)) {
                 static::println("{$class_name} successfully loaded");
             }
         }
     }
 }
 /**
  * Smarty construct
  *
  * @since ADD MVC 0.0
  */
 public function __construct()
 {
     $C = add::config();
     parent::__construct();
     if (is_array($C->views_dir)) {
         $this->setTemplateDir(array_merge($C->views_dir, array($C->add_dir . '/views/')));
     } else {
         $this->setTemplateDir(array($C->views_dir, $C->add_dir . '/views/'));
     }
     $this->compile_dir = $C->caches_dir . '/smarty_compile/';
     $this->config_dir = $C->configs_dir . '/smarty/';
     $this->cache_dir = $C->caches_dir . '/smarty_cache/';
     if (add::is_development()) {
         foreach (array($this->compile_dir, $this->cache_dir) as $dir) {
             if (!is_dir($dir)) {
                 $this->_dir_perms = 0777;
             } else {
                 if (!is_writable($dir)) {
                     # Do something
                 }
             }
         }
     }
 }
 /**
  * is_developer()
  *
  * Checks if the user is developer according to his/her IP
  *
  * @since ADD MVC 0.7.2
  */
 public static function is_developer()
 {
     /**
      * @see http://code.google.com/p/add-mvc-framework/issues/detail?id=39
      */
     if (php_sapi_name() == "cli") {
         return true;
     }
     # Fix for issue #6
     if (current_ip_in_network()) {
         return true;
     }
     if (isset(add::config()->developer_ips)) {
         return in_array(current_user_ip(), (array) add::config()->developer_ips);
     } else {
         return false;
     }
 }
Example #13
0
<?php

/**
 * Created by PhpStorm.
 * @author albert
 * Date: 1/18/16
 * Time: 3:41 AM
 */
require 'add_configure.php';
$current_controller = add::current_controller();
$current_controller->execute();
<?php

if (!class_exists('phpmailer')) {
    add::load_lib('phpmailer');
}
/**
 * Mailer Abstract
 *
 */
abstract class ctrl_mailer_abstract extends phpmailer
{
    /**
     * Default Wordwrap 70 characters
     *
     * @var int
     *
     */
    public $WordWrap = 70;
    /**
     * View variable cache
     *
     */
    protected static $views;
    /**
     * assign()ed data
     *
     */
    protected $data = array();
    /**
     * controller variable cache
     *
<?php

require '../config.php';
require $C->add_dir . '/init.php';
date_default_timezone_set('UTC');
$G_errors = array();
session_start();
session_set_cookie_params(3600, $C->path, $C->domain, true);
#add::canonicalize_path();
add::current_controller()->page();
    trigger_error("Cache directory is not writeable", E_USER_WARNING);
    unset($cache_file, $cache_files);
}
if (!isset($C->assets_dir)) {
    $C->assets_dir = $C->root_dir . '/assets';
}
if (!isset($C->images_dir)) {
    $C->images_dir = $C->assets_dir . '/images';
}
if (!isset($C->css_dir)) {
    $C->css_dir = $C->assets_dir . '/css';
}
$C->js_dir = $C->assets_dir . '/js';
$C->domain = ($C->sub_domain ? "{$C->sub_domain}." : "") . $C->super_domain;
$C->base_url = "http://{$C->domain}{$C->path}";
set_include_path($C->incs_dir);
/**
 * assets
 * @author albertdiones@gmail.com
 */
$C->assets_path = $C->path . 'assets/';
$C->css_path = $C->assets_path . 'css/';
$C->js_path = $C->assets_path . 'js/';
$C->images_path = $C->assets_path . 'images/';
$C->assets_libs_path = $C->assets_path . 'libs/';
/**
 * Libraries
 */
add::load_lib('adodb');
add::load_lib('smarty');
 /**
  * environment check: is_development()
  *
  * @since ADD MVC 0.7
  */
 public static function is_development()
 {
     return add::config()->environment_status === 'development';
 }
 public function fetch_view()
 {
     $this->view()->assign('C', add::config());
     return $this->view()->fetch(static::view_filepath());
 }
 /**
  * sets the content_type or get the current one
  *
  * @param string $new_content_type
  *
  * @deprecated see add::content_type();
  *
  * @since ADD MVC 0.8
  */
 public function content_type($new_content_type = null)
 {
     return add::content_type($new_content_type);
 }
/**
 * handle_error()
 * callback function for handling trigger_error() errors
 *
 * @param int  $errno contains the level of the error raised, as an integer.
 * @param string $errstr contains the error message, as a string.
 * @param string $errfile contains the filename that the error was raised in, as a string.
 * @param int $errline contains the line number the error was raised at, as an integer.
 * @param array $errcontext an array that points to the active symbol table at the point the error occurred. In other words, errcontext will contain an array of every variable that existed in the scope the error was triggered in. User error handler must not modify error context.
 *
 * @see http://www.php.net/manual/en/function.set-error-handler.php
 * @version 1.0
 */
function handle_error($errno, $errstr, $errfile = NULL, $errline = NULL, $errcontext = NULL)
{
    return add::handle_error($errno, $errstr, $errfile, $errline, $errcontext);
}
 /**
  * login_redirect()
  * extend to change
  * @since ADD MVC 0.0
  */
 static function login_redirect()
 {
     add::redirect(add::config()->path . static::LOGIN_PAGE . "?redirect=" . urlencode($_SERVER['REQUEST_URI']));
 }
 public static function current_user_allowed()
 {
     return !add::is_live();
 }
 /**
  * The pre-view process
  *
  * @param array $common_gpc
  *
  * @since ADD MVC 0.0
  */
 public function process_data($common_gpc = array())
 {
     header("HTTP/1.0 404 Not Found");
     $this->assign('is_development', add::is_development());
 }
 /**
  * Do nothing, the reason we hate spam is because it bothers us, so we will ignore this error
  *
  */
 public function handle_exception()
 {
     return add::shutdown(false);
 }
<?php

require '../config.php';
require_once "{$C->add_dir}/init.php";
$exceptions = array('e_developer', 'e_syntax', 'e_hack', 'e_spam', 'e_system');
$exception = (string) $_GET['exception'];
$email = (string) $_GET['email'];
if ($exception) {
    if ($_REQUEST['is_live']) {
        add::environment_status('live');
    }
    add::content_type($_REQUEST['content_type']);
    e_add::$email_addresses = $email;
    $e = new $exception("Test Error Message");
    #debug::var_dump($e->mail_body());
    throw $e;
}
?>
<form method="GET">
   <select name="exception">
      <option><?php 
echo implode("</option><option>", $exceptions);
?>
</option>
   </select>
   <label>Email<input type="text" name="email" /></label>
   <label><input name="is_live" type="checkbox" />Live</label>
   <label>
      Content Type<select name="content_type">
         <option>text/html</option>
         <option>text/plain</option>
 /**
  * Settings and stuffs
  *
  * @since ADD MVC 0.8-data_mining
  */
 public function __construct()
 {
     if (!isset($this->cookie_dir)) {
         $this->cookie_dir = add::config()->caches_dir . '/' . preg_replace('/\\W+/', '_', get_called_class()) . '.class.cookies';
     }
     if ($this->enable_cache) {
         $this->cache_dir = add::config()->caches_dir . '/' . preg_replace('/\\W+/', '_', get_called_class()) . '.class.cache';
         if (!file_exists($this->cache_dir)) {
             mkdir($this->cache_dir, 0777);
         }
     }
     $this->set_curl_options();
     if ($this->curl_options[CURLOPT_HTTPPROXYTUNNEL] && empty($this->curl_options[CURLOPT_PROXY]) && !empty($this->proxies) && is_array($this->proxies)) {
         $this->curl_options[CURLOPT_PROXY] = $this->proxies[array_rand($this->proxies)];
         $this->cookie_dir = add::config()->caches_dir . '/cookies_' . preg_replace('/\\W+/', '_', __FILE__) . "_" . preg_replace("/\\W+/", "_", $this->curl_options[CURLOPT_PROXY]);
     }
 }
 /**
  * content_type()
  *
  * @since ADD MVC 0.8
  */
 public static function content_type($new_content_type = null)
 {
     if ($new_content_type == 'text/plain') {
         ini_set('html_errors', 0);
     }
     return add::current_controller()->content_type($new_content_type);
 }
 /**
  * Returns the file and line number of the caller of the function
  * @since ADD MVC 0.0
  */
 static function caller_file_line()
 {
     $backtraces = debug_backtrace();
     foreach ($backtraces as $backtrace) {
         $is_trace_class_debug = $backtrace['class'] == __CLASS__ || is_subclass_of($backtrace['class'], __CLASS__);
         if (empty($backtrace['class']) || !$is_trace_class_debug) {
             break;
         }
         $file_line = $backtrace['file'] . ':' . $backtrace['line'];
     }
     if (!$file_line) {
         return "Unknown Location";
     }
     $file_line = preg_replace('/^' . preg_quote(add::config()->root_dir, '/') . '\\//', '', $file_line);
     return $file_line;
 }
 /**
  * Prints the config value
  *
  * @since ADD MVC 0.7.4
  */
 public static function print_config($field, $boolean = false)
 {
     $value = isset(add::config()->{$field}) ? add::config()->{$field} : null;
     $label = "config - {$field}";
     if ($boolean) {
         $value = (bool) $value;
         $label .= " declared";
     }
     static::print_data($label, $value);
 }
 /**
  * meta keywords
  *
  * @since ADD MVC 0.1, ctrl_tpl_page 0.1
  * @deprecated use the view instead
  */
 public function meta_keywords()
 {
     return isset(add::config()->default_meta_keywords) ? add::config()->default_meta_keywords : null;
 }