Example #1
0
 public static function getInstance()
 {
     if (!self::$instance instanceof Config) {
         self::$instance = new Config();
     }
     return self::$instance;
 }
Example #2
0
 public function __construct()
 {
     $config = Config::instance();
     // Check if logging is enabled. Default: enabled
     $this->_enabled = $config->item('log', 'enabled') !== null ? (bool) $config->item('log', 'enabled') : true;
     if ($this->_enabled) {
         // Assign a default log path if not specified in config
         $this->_log_path = $config->item('log', 'path') !== '' ? $config->item('log', 'path') : APPPATH . 'logs/';
         // Assign a default log extension if not specified in config
         $this->_file_ext = $config->item('log', 'file_extension') && $config->item('log', 'file_extension') !== '' ? ltrim($config->item('log', 'file_extension'), '.') : 'php';
         // Create the log directory if it doesn't exist
         file_exists($this->_log_path) or mkdir($this->_log_path, DIR_WRITE_MODE, true);
         // Wait what? We failed to create the directory. Abort!
         if (!is_dir($this->_log_path)) {
             Exception::trace('Could not create the logging directory');
         }
         if (is_numeric($config->item('log', 'threshold'))) {
             $this->_threshold = (int) $config->item('log', 'threshold');
         } elseif (is_array($config->item('log', 'threshold'))) {
             $this->_threshold = $this->_threshold_max;
             $this->_threshold_array = array_flip($config->item('log', 'threshold'));
         }
         if ($config->item('log', 'date_format') !== '') {
             $this->_date_fmt = $config->item('log', 'date_format');
         }
     }
 }
Example #3
0
 public static function getInstance()
 {
     if (is_null(self::$instance)) {
         self::$instance = new Config($_SESSION['user_id']);
     }
     return self::$instance;
 }
Example #4
0
function logException(Exception $e, $mail = true)
{
    Logger::messages()->exception($e);
    if (Config::instance()->production) {
        if (Phalcon\DI::getDefault()->has('request')) {
            /** @var \Phalcon\Http\Request $request */
            $request = Phalcon\DI::getDefault()->getShared('request');
            $message = sprintf("%s %s: %s\n" . "UserAgent: %s\n" . "HTTP Referer: %s\n" . "%s URL: %s://%s\n" . "LoggedUser: %s\n" . "%s", date('Y-m-d H:i:s'), get_class($e), $e->getMessage(), $request->getUserAgent(), urldecode($request->getHTTPReferer()), $request->getClientAddress(), $request->getScheme(), $request->getHttpHost() . urldecode(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '<!undefined>'), $e->getTraceAsString());
        } else {
            $message = date('Y-m-d H:i:s') . ' ' . $e->getMessage() . "\n" . "There is no request object\n" . $e->getTraceAsString();
        }
        switch (true) {
            //			case $e instanceof PageNotFound:
            //			case $e instanceof Phalcon\Mvc\Dispatcher\Exception:
            //				break;
            default:
                if (Config::instance()->mail_exceptions && $mail) {
                    MailQueue::push2admin('Exception', $message);
                }
                break;
        }
    } else {
        throw $e;
    }
}
Example #5
0
 public static function openDefaultConnection()
 {
     if (!self::$initialized) {
         self::__init();
     }
     return self::$instance->dataAccessFactory->openConnection(Config::instance()->DB_NAME, Config::instance()->DB_HOSTNAME, Config::instance()->DB_USERNAME, Config::instance()->DB_PASSWORD, Config::instance()->DB_PERSISTENT_CONNECTION);
 }
Example #6
0
 public static function getConfig($configPath = null)
 {
     if (!self::$instance) {
         self::$instance = new Config($configPath);
     }
     return self::$instance;
 }
 function setUp()
 {
     DB::openConnection(Config::instance()->TEST_DB_NAME, "localhost", Config::instance()->TEST_DB_USERNAME, Config::instance()->TEST_DB_PASSWORD, false);
     $sql = DB::newDirectSql("CREATE TABLE simple3_table(\n          id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id),\n          nome VARCHAR(255),\n          livello INT,\n          properties TEXT);");
     $sql->exec();
     ActiveRecord::init("Simple3");
 }
Example #8
0
 /**
  * Override the before method
  * check if ajax and select correct template
  */
 public function before()
 {
     $this->auth_filter();
     if (Auth::instance()->logged_in()) {
         $this->acl_filter();
     }
     // create a new Config reader and attach to the Config instance
     $config = Config::instance();
     $config->attach(new Config_Database());
     $this->breadcrumbs();
     //check if controller is of innerpage of course and courseid is there in session
     // TODO - fix for modular extensibility
     if ($this->request->is_initial()) {
         // check if this is initial request
         $course_pages = array('document', 'flashcard', 'link', 'video', 'lesson', 'quiz', 'assignment', 'question', 'quiz', 'exercise');
         $controller = $this->request->controller();
         $course_id = Session::instance()->get('course_id');
         if (in_array($controller, $course_pages) && !$course_id) {
             $this->request->redirect('course');
         } elseif (!in_array($controller, $course_pages)) {
             Session::instance()->delete('course_id');
         }
     }
     return parent::before();
 }
Example #9
0
    protected function __construct()
    {
        $config = Config::instance();
        $this->dbh = new \PDO('mysql:host=' . $config->data['db']['host'] . ';

            dbname=' . $config->data['db']['dbname'], $config->data['db']['user'], $config->data['db']['password']);
    }
Example #10
0
 /**
  * Running triggers for some actions
  *
  * @param string	$trigger	For example <i>admin/System/components/plugins/disable</i>
  * @param mixed		$data		For example ['name'	=> <i>plugin_name</i>]
  *
  * @return bool
  */
 function run($trigger, $data = null)
 {
     if (!is_string($trigger)) {
         return true;
     }
     if (!$this->initialized) {
         $modules = array_keys(Config::instance()->components['modules']);
         foreach ($modules as $module) {
             _include_once(MODULES . '/' . $module . '/trigger.php', false);
         }
         unset($modules, $module);
         $plugins = get_files_list(PLUGINS, false, 'd');
         if (!empty($plugins)) {
             foreach ($plugins as $plugin) {
                 _include_once(PLUGINS . '/' . $plugin . '/trigger.php', false);
             }
         }
         unset($plugins, $plugin);
         $this->initialized = true;
     }
     if (!isset($this->triggers[$trigger]) || empty($this->triggers[$trigger])) {
         return true;
     }
     $return = true;
     foreach ($this->triggers[$trigger] as $closure) {
         if ($data === null) {
             $return = $return && ($closure() === false ? false : true);
         } else {
             $return = $return && ($closure($data) === false ? false : true);
         }
     }
     return $return;
 }
Example #11
0
 public static function &instance()
 {
     if (empty(Config::$instance)) {
         Config::$instance = new Config();
     }
     return Config::$instance;
 }
Example #12
0
 private static function getInstance()
 {
     if (!is_object(self::$instance)) {
         self::$instance = new Config();
     }
     return self::$instance;
 }
Example #13
0
 /**
  * Fetch instance of this class
  */
 public static function getInstance()
 {
     if (!isset(self::$instance)) {
         self::$instance = new Config();
     }
     return self::$instance;
 }
 function add_to_gallery()
 {
     $gallery_peer = new GalleryPeer();
     $gallery = $gallery_peer->find_by_id(Params::get("id_gallery"));
     $collection_peer = new GalleryCollectionPeer();
     $gallery_collection = $collection_peer->find_by_id($gallery->id_gallery_collection);
     $full_folder_path = GalleryCollectionController::GALLERY_COLLECTION_ROOT_DIR . $gallery_collection->folder . "/" . $gallery->folder;
     if (Upload::isUploadSuccessful("file")) {
         $filename = Random::newHexString() . "_" . Upload::getRealFilename("file");
         $gallery_dir = new Dir($full_folder_path);
         $uploaded_img = Upload::saveTo("file", $gallery_dir, $filename);
         if (isset(Config::instance()->GALLERY_RESIZE_BY_WIDTH)) {
             image_w($uploaded_img->getPath(), Config::instance()->GALLERY_RESIZE_BY_WIDTH);
         } else {
             if (isset(Config::instance()->GALLERY_RESIZE_BY_HEIGHT)) {
                 image_h($uploaded_img->getPath(), Config::instance()->GALLERY_RESIZE_BY_HEIGHT);
             }
         }
         $peer = new GalleryImagePeer();
         $do = $peer->new_do();
         $peer->setupByParams($do);
         $do->image_name = $filename;
         $peer->save($do);
         return Redirect::success();
     } else {
         Flash::error(Upload::getUploadError("file"));
         return Redirect::failure();
     }
 }
Example #15
0
 /**
  *
  * Return Config instance or create intitial instance
  *
  * @access public
  *
  * @return object
  *
  */
 public static function getInstance()
 {
     if (is_null(self::$instance)) {
         self::$instance = new config();
     }
     return self::$instance;
 }
Example #16
0
 /**
  * @return Toggle
  */
 public static function instance()
 {
     if (!isset(self::$instance)) {
         self::$instance = new Toggle(Config::instance());
     }
     return self::$instance;
 }
Example #17
0
 public static function get_instance()
 {
     if (empty(self::$instance)) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Example #18
0
 public static function get($k)
 {
     if (self::$instance == null) {
         self::$instance = new Config();
     }
     return self::$instance->{$k};
 }
Example #19
0
 public static function getInstance()
 {
     if (self::$instance == false) {
         self::$instance = new Config();
     }
     return self::$instance;
 }
Example #20
0
 public static function &getInstance()
 {
     if (self::$instance === false) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Example #21
0
 public static function getInstance()
 {
     if (self::$instance === null) {
         self::$instance = new self();
     }
     return self::$instance;
 }
 function invia_commento()
 {
     try {
         $nome = Params::get("nome");
         $subject = Params::get("subject");
         $email = Params::get("email");
         $testo = Params::get("testo");
         //$codice_hidden = Params::get("codice_hidden");
         //$codice = Params::get("codice");
         //if ($codice_hidden!=$codice)
         //    throw new InvalidParameterException("Il codice non e' impostato correttamente!!");
         if ($nome != null && $subject != null && $email != null && $testo != null && isset(Config::instance()->EMAIL_COMMENT_RECEIVED)) {
             $e = new EMail("no_reply@" . Host::current_no_www(), Config::instance()->EMAIL_COMMENT_RECEIVED, "[Nuova commento da : " . $nome . "] - " . Host::current(), EMail::HTML_FORMAT);
             $e->render_and_send("include/messages/mail/alert/" . Lang::current() . "/nuovo_commento.php.inc", array("nome" => $nome, "email" => $email, "subject" => $subject, "testo" => $testo));
             return Redirect::success();
         } else {
             if (!isset(Config::instance()->EMAIL_COMMENT_RECEIVED)) {
                 throw new InvalidDataException("Il parametri di configurazione EMAIL_COMMENT_RECEIVED non e' impostato correttamente!!");
             } else {
                 throw new InvalidDataException("I dati immessi nella form non sono validi!!");
             }
         }
     } catch (Exception $ex) {
         Flash::error($ex->getMessage());
         return Redirect::failure();
     }
 }
Example #23
0
 public function __construct()
 {
     $this->input = new Input();
     $this->config = Config::instance();
     $this->log = Log::instance();
     $this->log->write('debug', 'Library Class Initialized');
 }
Example #24
0
 /**
  * Singleton
  *
  * @static
  * @access public
  * @return Config static instance of the Config object
  */
 public static function &getInstance()
 {
     if (empty(self::$instance)) {
         self::$instance = new Config();
     }
     return self::$instance;
 }
Example #25
0
 public static function getInstance($sConfig = null)
 {
     if (self::$instance == null) {
         self::$instance = new self($sConfig);
     }
     return self::$instance;
 }
Example #26
0
 public static function initialize($path)
 {
     Config::setPath($path . 'config/');
     self::$request = Request::instance();
     self::$config = Config::instance();
     self::$store = Store::instance();
 }
Example #27
0
 /**
  * singelton constructor
  */
 public static function create_instance()
 {
     if (self::$instance === NULL) {
         self::$instance = new Config();
     }
     return self::$instance;
 }
Example #28
0
 /**
  * Adding key into specified database
  *
  * @param int|object	$database	Keys database
  * @param bool|string	$key		If <b>false</b> - key will be generated automatically, otherwise must contain 56 character [0-9a-z] key
  * @param null|mixed	$data		Data to be stored with key
  * @param int			$expire		Timestamp of key expiration, if not specified - default system value will be used
  *
  * @return bool|string
  */
 function add($database, $key, $data = null, $expire = 0)
 {
     if (!is_object($database)) {
         $database = DB::instance()->{$database}();
     }
     if (!preg_match('/^[a-z0-9]{56}$/', $key)) {
         if ($key === false) {
             $key = $this->generate($database);
         } else {
             return false;
         }
     }
     $expire = (int) $expire;
     $Config = Config::instance();
     if ($expire == 0 || $expire < TIME) {
         $expire = TIME + $Config->core['key_expire'];
     }
     $this->del($database, $key);
     $database->q("INSERT INTO `[prefix]keys`\n\t\t\t\t(\n\t\t\t\t\t`key`,\n\t\t\t\t\t`expire`,\n\t\t\t\t\t`data`\n\t\t\t\t) VALUES (\n\t\t\t\t\t'%s',\n\t\t\t\t\t'%s',\n\t\t\t\t\t'%s'\n\t\t\t\t)", $key, $expire, _json_encode($data));
     $id = $database->id();
     /**
      * Cleaning old keys
      */
     if ($id && $id % $Config->core['inserts_limit'] == 0) {
         $time = TIME;
         $database->aq("DELETE FROM `[prefix]keys`\n\t\t\t\tWHERE `expire` < {$time}");
     }
     return $key;
 }
Example #29
0
 /**
  * Gets the value of a configuration.
  *
  * @param $configName string Name of the configuration property
  * @param $defaultValue string Default value of the configuration in case it hasn't been set
  * @return string
  */
 public static function get($configName, $defaultValue = null)
 {
     if (null === Config::$instance) {
         Config::$instance = new Config();
     }
     return isset(Config::$instance->settings[$configName]) ? Config::$instance->settings[$configName] : $defaultValue;
 }
Example #30
-1
 public function run_db_utility()
 {
     require_once __DIR__ . "/../halfmoon.php";
     $db_config = Utils::A(Config::instance()->db_config, HALFMOON_ENV);
     switch ($db_config["adapter"]) {
         case "mysql":
             if ($db_config["socket"]) {
                 $bin_args = array("-S", $db_config["socket"]);
             } else {
                 $bin_args = array("-h", $db_config["hostname"], "-P", $db_config["port"]);
             }
             array_push($bin_args, "-D");
             array_push($bin_args, $db_config["database"]);
             array_push($bin_args, "-u");
             array_push($bin_args, $db_config["username"]);
             if ($this->include_password) {
                 array_push($bin_args, "--password="******"password"]);
             }
             $bin_path = null;
             foreach (explode(":", getenv("PATH")) as $dir) {
                 if (file_exists($dir . "/mysql")) {
                     $bin_path = $dir . "/mysql";
                     break;
                 }
             }
             if (!$bin_path) {
                 die("cannot find mysql in \$PATH\n");
             }
             pcntl_exec($bin_path, $bin_args);
             break;
         default:
             die($db_config["adapter"] . " not yet supported\n");
     }
 }