Пример #1
0
    /**
     * Quick and nice way to output a mixed variable to the browser
     *
     * @static
     * @access	public
     * @return	string
     */
    public static function inspect()
    {
        $backtrace = debug_backtrace();
        // If being called from within, show the file above in the backtrack
        if (strpos($backtrace[0]['file'], 'core/classes/debug.php') !== FALSE) {
            $callee = $backtrace[1];
            $label = \Inflector::humanize($backtrace[1]['function']);
        } else {
            $callee = $backtrace[0];
            $label = 'Debug';
        }
        $arguments = func_get_args();
        $total_arguments = count($arguments);
        $callee['file'] = \Fuel::clean_path($callee['file']);
        if (!static::$js_displayed) {
            echo <<<JS
<script type="text/javascript">function fuel_debug_toggle(a){if(document.getElementById){if(document.getElementById(a).style.display=="none"){document.getElementById(a).style.display="block"}else{document.getElementById(a).style.display="none"}}else{if(document.layers){if(document.id.display=="none"){document.id.display="block"}else{document.id.display="none"}}else{if(document.all.id.style.display=="none"){document.all.id.style.display="block"}else{document.all.id.style.display="none"}}}};</script>
JS;
            static::$js_displayed = true;
        }
        echo '<div style="font-size: 13px;background: #EEE !important; border:1px solid #666; color: #000 !important; padding:10px;">';
        echo '<h1 style="border-bottom: 1px solid #CCC; padding: 0 0 5px 0; margin: 0 0 5px 0; font: bold 120% sans-serif;">' . $callee['file'] . ' @ line: ' . $callee['line'] . '</h1>';
        echo '<pre style="overflow:auto;font-size:100%;">';
        $i = 0;
        foreach ($arguments as $argument) {
            echo '<strong>' . $label . ' #' . ++$i . ' of ' . $total_arguments . '</strong>:<br />';
            echo static::format('...', $argument);
            echo '<br />';
        }
        echo "</pre>";
        echo "</div>";
    }
Пример #2
0
 /**
  * Loads the given package.  If a path is not given, then PKGPATH is used.
  * It also accepts an array of packages as the first parameter.
  *
  * @param   string|array  $package  The package name or array of packages.
  * @param   string|null   $path     The path to the package
  * @return  bool  True on success
  * @throws  PackageNotFoundException
  */
 public static function load($package, $path = null)
 {
     if (is_array($package)) {
         foreach ($package as $pkg) {
             $path = null;
             if (is_array($pkg)) {
                 list($pkg, $path) = $pkg;
             }
             static::load($pkg, $path);
         }
         return false;
     }
     if (static::loaded($package)) {
         return;
     }
     // Load it from PKGPATH if no path was given.
     if ($path === null) {
         $path = PKGPATH . $package . DS;
     }
     if (!is_dir($path)) {
         throw new \PackageNotFoundException("Package '{$package}' could not be found at '" . \Fuel::clean_path($path) . "'");
     }
     \Finder::instance()->add_path($path, 1);
     \Fuel::load($path . 'bootstrap.php');
     static::$packages[$package] = $path;
     return true;
 }
Пример #3
0
 /**
  * Loads the given package.
  * If a path is not given, if will search through
  * the defined package_paths. If not defined, then PKGPATH is used.
  * It also accepts an array of packages as the first parameter.
  *
  * @param string|array $package
  *        	The package name or array of packages.
  * @param string|null $path
  *        	The path to the package
  * @return bool True on success
  * @throws PackageNotFoundException
  */
 public static function load($package, $path = null)
 {
     if (is_array($package)) {
         foreach ($package as $pkg => $path) {
             if (is_numeric($pkg)) {
                 $pkg = $path;
                 $path = null;
             }
             static::load($pkg, $path);
         }
         return false;
     }
     if (static::loaded($package)) {
         return;
     }
     // if no path is given, try to locate the package
     if ($path === null) {
         $paths = \Config::get('package_paths', array());
         empty($paths) and $paths = array(PKGPATH);
         if (!empty($paths)) {
             foreach ($paths as $modpath) {
                 if (is_dir($path = $modpath . strtolower($package) . DS)) {
                     break;
                 }
             }
         }
     }
     if (!is_dir($path)) {
         throw new \PackageNotFoundException("Package '{$package}' could not be found at '" . \Fuel::clean_path($path) . "'");
     }
     \Finder::instance()->add_path($path, 1);
     \Fuel::load($path . 'bootstrap.php');
     static::$packages[$package] = $path;
     return true;
 }
Пример #4
0
 /**
  * passes the data to the template and returns the result
  *
  * @param 	string 	$template_file	the template file used to structure the data
  * @return 	array	the restructured data
  */
 public function to($template)
 {
     $template_folder = \Config::get('structure.templates_folder');
     $template_path = \Fuel::find_file($template_folder, $template);
     if (!$template_path) {
         throw new \Fuel_Exception('The requested template could not be found: ' . \Fuel::clean_path($file));
     }
     $data = static::capture($template_path, $this->_data);
     return static::capture($template_path, $this->_data);
 }
Пример #5
0
 public function action_index($page = 'petro')
 {
     $dir = APPPATH . 'views';
     $file = '/dashboard/' . $page . '.md';
     $path = \Fuel::clean_path($dir . $file);
     // var_dump($dir, $file, $path);
     // var_dump(\Finder::instance()->locate($dir, 'dashboard/index'));  die;
     $data['text'] = \View::forge('dashboard/' . $page . '.md');
     $this->template->content = \View::forge('dashboard/index', $data);
 }
Пример #6
0
 private function write($filepath, $data)
 {
     if (!($handle = fopen($filepath, 'w+'))) {
         throw new Exception('Cannot open file: ' . \Fuel::clean_path($filepath));
     }
     $result = @fwrite($handle, $data);
     // Write $somecontent to our opened file.
     if ($result === FALSE) {
         throw new Exception('Cannot write to file: ' . \Fuel::clean_path($filepath));
     }
     @fclose($handle);
     chmod($filepath, 0666);
     return $result;
 }
Пример #7
0
 /**
  * Loads the given module.  If a path is not given, then 'module_paths' is used.
  * It also accepts an array of modules as the first parameter.
  *
  * @param   string|array  $package  The module name or array of modules.
  * @param   string|null   $path     The path to the module
  * @return  bool  True on success
  * @throws  ModuleNotFoundException
  */
 public static function load($module, $path = null)
 {
     if (is_array($module)) {
         $result = true;
         foreach ($module as $mod => $path) {
             if (is_numeric($mod)) {
                 $mod = $path;
                 $path = null;
             }
             $result = $result and static::load($mod, $path);
         }
         return $result;
     }
     if (static::loaded($module)) {
         return;
     }
     // if no path is given, try to locate the module
     if ($path === null) {
         $paths = \Config::get('module_paths', array());
         if (!empty($paths)) {
             foreach ($paths as $modpath) {
                 if (is_dir($path = $modpath . strtolower($module) . DS)) {
                     break;
                 }
             }
         }
     } else {
         // make sure it's terminated properly
         $path = rtrim($path, DS) . DS;
     }
     // make sure the path exists
     if (!is_dir($path)) {
         throw new \ModuleNotFoundException("Module '{$module}' could not be found at '" . \Fuel::clean_path($path) . "'");
     }
     // determine the module namespace
     $ns = '\\' . ucfirst($module);
     // add the namespace to the autoloader
     \Autoloader::add_namespaces(array($ns => $path . 'classes' . DS), true);
     static::$modules[$module] = $path;
     return true;
 }
Пример #8
0
	public static function run()
	{
		$writable_paths = array(
			APPPATH . 'cache',
			APPPATH . 'logs',
			APPPATH . 'tmp'
		);

		foreach ($writable_paths as $path)
		{
			if (@chmod($path, 0777))
			{
				\Cli::write("\t" . \Cli::color('Made writable: ' . \Fuel::clean_path($path), 'green'));
			}

			else
			{
				\Cli::write("\t" . \Cli::color('Failed to make writable: ' . \Fuel::clean_path($path), 'red'));
			}
		}
	}
Пример #9
0
 public static function migration($args)
 {
     // Get the migration name
     $migration_name = strtolower(array_shift($args));
     // See if the action exists
     $methods = get_class_methods(__NAMESPACE__ . '\\Generate_Migration_Actions');
     // For empty migrations that dont have actions
     $migration = array('', '');
     // Loop through the actions and act on a matching action appropriately
     foreach ($methods as $method_name) {
         // If the miration name starts with the name of the action method
         if (substr($migration_name, 0, strlen($method_name)) === $method_name) {
             /**
              *	Create an array of the subject the migration is about
              *
              *	- In a migration named 'create_users' the subject is 'users' since thats what we want to create
              *		So it would be the second object in the array
              *			array(false, 'users')
              *
              *	- In a migration named 'add_name_to_users' the object is 'name' and the subject is 'users'.
              *		So again 'users' would be the second object, but 'name' would be the first
              *			array('name', 'users')
              *
              */
             $subjects = array(false, false);
             $matches = explode('_', str_replace($method_name . '_', '', $migration_name));
             if (count($matches) == 1) {
                 $subjects = array(false, $matches[0]);
             } elseif (count($matches) == 3 and $matches[1] == 'to') {
                 $subjects = array($matches[0], $matches[2]);
             } elseif (count($matches) !== 0) {
                 $subjects = array(false, implode('_', $matches));
             } else {
                 break;
             }
             // We always pass in fields to a migration, so lets sort them out here.
             $fields = array();
             foreach ($args as $field) {
                 $field_array = array();
                 // Each paramater for a field is seperated by the : character
                 $parts = explode(":", $field);
                 // We must have the 'name:type' if nothing else!
                 if (count($parts) >= 2) {
                     $field_array['name'] = array_shift($parts);
                     foreach ($parts as $part_i => $part) {
                         preg_match('/([a-z0-9_-]+)(?:\\[([a-z0-9]+)\\])?/i', $part, $part_matches);
                         array_shift($part_matches);
                         if (count($part_matches) < 1) {
                             // Move onto the next part, something is wrong here...
                             continue;
                         }
                         $option_name = '';
                         // This is the name of the option to be passed to the action in a field
                         $option = $part_matches;
                         // The first option always has to be the field type
                         if ($part_i == 0) {
                             $option_name = 'type';
                             $type = $option[0];
                             if ($type === 'string') {
                                 $type = 'varchar';
                             } else {
                                 if ($type === 'integer') {
                                     $type = 'int';
                                 }
                             }
                             if (!in_array($type, array('text', 'blob', 'datetime', 'date', 'timestamp', 'time'))) {
                                 if (!isset($option[1]) || $option[1] == NULL) {
                                     if (isset(self::$_default_constraints[$type])) {
                                         $field_array['constraint'] = self::$_default_constraints[$type];
                                     }
                                 } else {
                                     $field_array['constraint'] = (int) $option[1];
                                 }
                             }
                             $option = $type;
                         } else {
                             // This allows you to put any number of :option or :option[val] into your field and these will...
                             // ... always be passed through to the action making it really easy to add extra options for a field
                             $option_name = array_shift($option);
                             if (count($option) > 0) {
                                 $option = $option[0];
                             } else {
                                 $option = true;
                             }
                         }
                         $field_array[$option_name] = $option;
                     }
                     $fields[] = $field_array;
                 } else {
                     // Invalid field passed in
                     continue;
                 }
             }
             // Call the magic action which returns an array($up, $down) for the migration
             \Cli::write("\tBuilding magic migration:" . $method_name);
             $migration = call_user_func(__NAMESPACE__ . "\\Generate_Migration_Actions::{$method_name}", $subjects, $fields);
         } else {
             // No magic action for this migration...
         }
     }
     // Build the migration
     if ($filepath = static::_build_migration($migration_name, $migration[0], $migration[1])) {
         \Cli::write("\tCreated migration: " . \Fuel::clean_path($filepath), 'green');
     }
 }
Пример #10
0
 public function query($type, $sql, $as_object)
 {
     // Make sure the database is connected
     if ($this->_connection) {
         // Make sure the connection is still alive
         if (!$this->_connection->ping()) {
             throw new \Database_Exception($this->_connection->error . ' [ ' . $sql . ' ]', $this->_connection->errno);
         }
     } else {
         $this->connect();
     }
     if (!empty($this->_config['profiling'])) {
         // Get the paths defined in config
         $paths = \Config::get('profiling_paths');
         // Storage for the trace information
         $stacktrace = array();
         // Get the execution trace of this query
         $include = false;
         foreach (debug_backtrace() as $index => $page) {
             // Skip first entry and entries without a filename
             if ($index > 0 and empty($page['file']) === false) {
                 // Checks to see what paths you want backtrace
                 foreach ($paths as $index => $path) {
                     if (strpos($page['file'], $path) !== false) {
                         $include = true;
                         break;
                     }
                 }
                 // Only log if no paths we defined, or we have a path match
                 if ($include or empty($paths)) {
                     $stacktrace[] = array('file' => Fuel::clean_path($page['file']), 'line' => $page['line']);
                 }
             }
         }
         $benchmark = \Profiler::start("Database ({$this->_instance})", $sql, $stacktrace);
     }
     if (!empty($this->_config['connection']['persistent']) and $this->_config['connection']['database'] !== static::$_current_databases[$this->_connection_id]) {
         // Select database on persistent connections
         $this->_select_db($this->_config['connection']['database']);
     }
     // Execute the query
     if (($result = $this->_connection->query($sql)) === false) {
         if (isset($benchmark)) {
             // This benchmark is worthless
             \Profiler::delete($benchmark);
         }
         throw new \Database_Exception($this->_connection->error . ' [ ' . $sql . ' ]', $this->_connection->errno);
     }
     // check for multiresults, we don't support those at the moment
     while ($this->_connection->more_results() and $this->_connection->next_result()) {
         if ($more_result = $this->_connection->use_result()) {
             throw new \Database_Exception('The MySQLi driver does not support multiple resultsets', 0);
         }
     }
     if (isset($benchmark)) {
         \Profiler::stop($benchmark);
     }
     // Set the last query
     $this->last_query = $sql;
     if ($type === \DB::SELECT) {
         // Return an iterator of results
         return new \Database_MySQLi_Result($result, $sql, $as_object);
     } elseif ($type === \DB::INSERT) {
         // Return a list of insert id and rows created
         return array($this->_connection->insert_id, $this->_connection->affected_rows);
     } else {
         // Return the number of rows affected
         return $this->_connection->affected_rows;
     }
 }
Пример #11
0
 protected static function prepare_exception(\Exception $e, $fatal = true)
 {
     $data = array();
     $data['type'] = get_class($e);
     $data['severity'] = $e->getCode();
     $data['message'] = $e->getMessage();
     $data['filepath'] = $e->getFile();
     $data['error_line'] = $e->getLine();
     $data['backtrace'] = $e->getTrace();
     $data['severity'] = !isset(static::$levels[$data['severity']]) ? $data['severity'] : static::$levels[$data['severity']];
     foreach ($data['backtrace'] as $key => $trace) {
         if (!isset($trace['file'])) {
             unset($data['backtrace'][$key]);
         } elseif ($trace['file'] == COREPATH . 'classes/error.php') {
             unset($data['backtrace'][$key]);
         }
     }
     $data['debug_lines'] = \Debug::file_lines($data['filepath'], $data['error_line'], $fatal);
     $data['orig_filepath'] = $data['filepath'];
     $data['filepath'] = \Fuel::clean_path($data['filepath']);
     $data['filepath'] = str_replace("\\", "/", $data['filepath']);
     return $data;
 }
Пример #12
0
 /**
  * Run the environment validation
  */
 protected static function run_validation()
 {
     // storage for collected errors
     $errors = array();
     // validate the auth configuration file
     if (!is_file($file = APPPATH . 'config' . DS . 'auth.php')) {
         $errors[] = \Fuel::clean_path($file) . ' does not exist.';
     } else {
         \Config::load('auth', true);
         if (!($driver = \Config::get('auth.driver', false))) {
             $errors[] = \Fuel::clean_path($file) . ' does not define an auth driver.';
         } elseif ($driver != 'Ormauth') {
             $errors[] = \Fuel::clean_path($file) . ' is not configured to use the Ormauth driver.';
         }
     }
     // validate the simpleauth configuration file
     if (!is_file($file = APPPATH . 'config' . DS . 'simpleauth.php')) {
         $errors[] = \Fuel::clean_path($file) . ' does not exist.';
     } else {
         \Config::load('simpleauth', true);
         if (!($table = \Config::get('simpleauth.table_name', false))) {
             $errors[] = \Fuel::clean_path($file) . ' does not define a user table.';
         } elseif (!\DBUtil::table_exists($table)) {
             $errors[] = \Fuel::clean_path($file) . ' defines a table that does not exist.';
         } else {
             // store the table name for future use
             static::$data['simpleauth_table'] = $table;
         }
     }
     // validate the ormauth configuration file
     if (!is_file($file = APPPATH . 'config' . DS . 'ormauth.php')) {
         $errors[] = \Fuel::clean_path($file) . ' does not exist.';
     } else {
         $config = \Config::load('ormauth', true);
         if (!($table = \Config::get('ormauth.table_name', false))) {
             $errors[] = \Fuel::clean_path($file) . ' does not define a user table.';
         } elseif (!\DBUtil::table_exists($table)) {
             $errors[] = \Fuel::clean_path($file) . ' defines a table that does not exist.';
         } else {
             // store the table name for future use
             static::$data['ormauth_table'] = $table;
         }
         if (!($cache_prefix = \Config::get('ormauth.cache_prefix', false)) or empty($cache_prefix)) {
             $errors[] = \Fuel::clean_path($file) . ' does not define a cache_prefix.';
         } else {
             // store the cache prefix for future use
             static::$data['cache_prefix'] = $cache_prefix;
         }
     }
     // check if all migrations have run, and the migration system is consistent
     $migrations = \Config::load('migrations', true);
     if (!isset($migrations['version']['package']['auth'][6])) {
         $errors[] = 'Auth database migrations haven\'t run (succesfully).';
     } else {
         $result = \DB::select('*')->from($migrations['table'])->where('type', '=', 'package')->where('name', '=', 'auth')->execute();
         if (count($result) < 7) {
             $errors[] = 'Auth database migrations haven\'t run (succesfully).';
             $errors[] = 'There is a discrepancy between your migration configuration file and the migration table.';
         }
     }
     // check the fields of the users table
     $usertable = array('id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true), 'username' => array('type' => 'varchar', 'constraint' => 50, 'after' => 'id'), 'password' => array('type' => 'varchar', 'constraint' => 255, 'after' => 'username'), 'group_id' => array('type' => 'int', 'constraint' => 11, 'default' => 1, 'after' => 'password'), 'email' => array('type' => 'varchar', 'constraint' => 255, 'after' => 'group_id'), 'last_login' => array('type' => 'varchar', 'constraint' => 25, 'after' => 'email'), 'previous_login' => array('type' => 'varchar', 'constraint' => 25, 'default' => 0, 'after' => 'last_login'), 'login_hash' => array('type' => 'varchar', 'constraint' => 255, 'after' => 'previous_login'), 'user_id' => array('type' => 'int', 'constraint' => 11, 'default' => 0, 'after' => 'login_hash'), 'created_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0, 'after' => 'user_id'), 'updated_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0, 'after' => 'created_at'));
     foreach ($usertable as $field => $value) {
         if (\DBUtil::field_exists(static::$data['ormauth_table'], $field)) {
             unset($usertable[$field]);
         }
     }
     if (!empty($usertable)) {
         $errors[] = 'User table "' . static::$data['ormauth_table'] . '" is missing the field(s): ' . implode(', ', array_keys($usertable));
     }
     // process the results of the validation
     if ($errors) {
         // display all errors
         \Cli::write('You environment did not validate:', 'light_red');
         foreach ($errors as $error) {
             \Cli::write('* ' . $error);
         }
         return false;
     }
     // inform the user we're good to go
     \Cli::write('Environment validated', 'light_green');
     return true;
 }
Пример #13
0
 public function migration($args)
 {
     $migration_name = strtolower(array_shift($args));
     // Starts with create, so lets create a table
     if (strpos($migration_name, 'create_') === 0) {
         $mode = 'create_table';
         $table = str_replace('create_', '', $migration_name);
     } else {
         if (strpos($migration_name, 'add_') === 0) {
             $mode = 'add_fields';
             preg_match('/add_[a-z0-9_]+_to_([a-z0-9_]+)/i', $migration_name, $matches);
             $table = $matches[1];
         } else {
             if (strpos($migration_name, 'remove_') === 0) {
                 $mode = 'remove_field';
                 preg_match('/remove_([a-z0-9_])+_from_([a-z0-9_]+)/i', $migration_name, $matches);
                 $remove_field = $matches[1];
                 $table = $matches[2];
             } else {
                 if (strpos($migration_name, 'drop_') === 0) {
                     $mode = 'drop_table';
                     $table = str_replace('drop_', '', $migration_name);
                 }
             }
         }
     }
     unset($matches);
     // Now that we know that, lets build the migration
     if ($filepath = static::_build_migration($migration_name, $mode, $table, $args)) {
         \Cli::write('Created migration: ' . \Fuel::clean_path($filepath));
     }
 }
Пример #14
0
 /**
  * Query the database
  *
  * @param integer $type
  * @param string  $sql
  * @param mixed   $as_object
  *
  * @return mixed
  *
  * @throws \Database_Exception
  */
 public function query($type, $sql, $as_object)
 {
     // Make sure the database is connected
     $this->_connection or $this->connect();
     if (!empty($this->_config['profiling'])) {
         // Get the paths defined in config
         $paths = \Config::get('profiling_paths');
         // Storage for the trace information
         $stacktrace = array();
         // Get the execution trace of this query
         $include = false;
         foreach (debug_backtrace() as $index => $page) {
             // Skip first entry and entries without a filename
             if ($index > 0 and empty($page['file']) === false) {
                 // Checks to see what paths you want backtrace
                 foreach ($paths as $index => $path) {
                     if (strpos($page['file'], $path) !== false) {
                         $include = true;
                         break;
                     }
                 }
                 // Only log if no paths we defined, or we have a path match
                 if ($include or empty($paths)) {
                     $stacktrace[] = array('file' => \Fuel::clean_path($page['file']), 'line' => $page['line']);
                 }
             }
         }
         $benchmark = \Profiler::start($this->_instance, $sql, $stacktrace);
     }
     // run the query. if the connection is lost, try 3 times to reconnect
     $attempts = 3;
     do {
         try {
             // try to run the query
             $result = $this->_connection->query($sql);
             break;
         } catch (\Exception $e) {
             // if failed and we have attempts left
             if ($attempts > 0) {
                 // try reconnecting if it was a MySQL disconnected error
                 if (strpos($e->getMessage(), '2006 MySQL') !== false) {
                     $this->disconnect();
                     $this->connect();
                 } else {
                     // other database error, cleanup the profiler
                     isset($benchmark) and \Profiler::delete($benchmark);
                     // and convert the exception in a database exception
                     if (!is_numeric($error_code = $e->getCode())) {
                         if ($this->_connection) {
                             $error_code = $this->_connection->errorinfo();
                             $error_code = $error_code[1];
                         } else {
                             $error_code = 0;
                         }
                     }
                     throw new \Database_Exception($e->getMessage() . ' with query: "' . $sql . '"', $error_code, $e);
                 }
             } else {
                 // and convert the exception in a database exception
                 if (!is_numeric($error_code = $e->getCode())) {
                     if ($this->_connection) {
                         $error_code = $this->_connection->errorinfo();
                         $error_code = $error_code[1];
                     } else {
                         $error_code = 0;
                     }
                 }
                 throw new \Database_Exception($e->getMessage() . ' with query: "' . $sql . '"', $error_code, $e);
             }
         }
     } while ($attempts-- > 0);
     if (isset($benchmark)) {
         \Profiler::stop($benchmark);
     }
     // Set the last query
     $this->last_query = $sql;
     if ($type === \DB::SELECT) {
         // Convert the result into an array, as PDOStatement::rowCount is not reliable
         if ($as_object === false) {
             $result = $result->fetchAll(\PDO::FETCH_ASSOC);
         } elseif (is_string($as_object)) {
             $result = $result->fetchAll(\PDO::FETCH_CLASS, $as_object);
         } else {
             $result = $result->fetchAll(\PDO::FETCH_CLASS, 'stdClass');
         }
         // Return an iterator of results
         return new \Database_Result_Cached($result, $sql, $as_object);
     } elseif ($type === \DB::INSERT) {
         // Return a list of insert id and rows created
         return array($this->_connection->lastInsertId(), $result->rowCount());
     } elseif ($type === \DB::UPDATE or $type === \DB::DELETE) {
         // Return the number of rows affected
         return $result->errorCode() === '00000' ? $result->rowCount() : -1;
     }
     return $result->errorCode() === '00000' ? true : false;
 }
Пример #15
0
 /**
  * Sets the view filename.
  *
  *     $view->set_filename($file);
  *
  * @param   string  view filename
  * @return  View
  * @throws  FuelException
  */
 public function set_filename($file)
 {
     // strip the extension from it
     $pathinfo = pathinfo($file);
     if (!empty($pathinfo['extension'])) {
         $this->extension = $pathinfo['extension'];
         $file = substr($file, 0, strlen($this->extension) * -1 - 1);
     }
     // set find_file's one-time-only search paths
     \Finder::instance()->flash($this->request_paths);
     // locate the view file
     if (($path = \Finder::search('views', $file, '.' . $this->extension, false, false)) === false) {
         throw new \FuelException('The requested view could not be found: ' . \Fuel::clean_path($file) . '.' . $this->extension);
     }
     // Store the file path locally
     $this->file_name = $path;
     return $this;
 }
Пример #16
0
 public function query($type, $sql, $as_object)
 {
     // Make sure the database is connected
     if ($this->_connection) {
         if (!mysql_ping($this->_connection)) {
             throw new \Database_Exception(mysql_error($this->_connection) . ' [ ' . $sql . ' ]', mysql_errno($this->_connection));
         }
     } else {
         $this->connect();
     }
     if (!empty($this->_config['profiling'])) {
         // Get the paths defined in config
         $paths = \Config::get('profiling_paths');
         // Storage for the trace information
         $stacktrace = array();
         // Get the execution trace of this query
         $include = false;
         foreach (debug_backtrace() as $index => $page) {
             // Skip first entry and entries without a filename
             if ($index > 0 and empty($page['file']) === false) {
                 // Checks to see what paths you want backtrace
                 foreach ($paths as $index => $path) {
                     if (strpos($page['file'], $path) !== false) {
                         $include = true;
                         break;
                     }
                 }
                 // Only log if no paths we defined, or we have a path match
                 if ($include or empty($paths)) {
                     $stacktrace[] = array('file' => \Fuel::clean_path($page['file']), 'line' => $page['line']);
                 }
             }
         }
         $benchmark = \Profiler::start($this->_instance, $sql, $stacktrace);
     }
     if (!empty($this->_config['connection']['persistent']) and $this->_config['connection']['database'] !== static::$_current_databases[$this->_connection_id]) {
         // Select database on persistent connections
         $this->_select_db($this->_config['connection']['database']);
     }
     // Execute the query
     if (($result = mysql_query($sql, $this->_connection)) === false) {
         if (isset($benchmark)) {
             // This benchmark is worthless
             \Profiler::delete($benchmark);
         }
         throw new \Database_Exception(mysql_error($this->_connection) . ' [ ' . $sql . ' ]', mysql_errno($this->_connection));
     }
     if (isset($benchmark)) {
         \Profiler::stop($benchmark);
     }
     // Set the last query
     $this->last_query = $sql;
     if ($type === \DB::SELECT) {
         // Return an iterator of results
         return new \Database_MySQL_Result($result, $sql, $as_object);
     } elseif ($type === \DB::INSERT) {
         // Return a list of insert id and rows created
         return array(mysql_insert_id($this->_connection), mysql_affected_rows($this->_connection));
     } elseif ($type === \DB::UPDATE or $type === \DB::DELETE) {
         // Return the number of rows affected
         return mysql_affected_rows($this->_connection);
     }
     return $result;
 }
Пример #17
0
 /**
  * Checks to see if the given class has a static _init() method.  If so then
  * it calls it.
  *
  * @param	string	the class name
  * @param	string	the file containing the class to include
  */
 protected static function init_class($class, $file = null)
 {
     // include the file if needed
     if ($file) {
         include $file;
     }
     // if the loaded file contains a class...
     if (class_exists($class, false)) {
         // call the classes static init if needed
         if (static::$auto_initialize === $class) {
             static::$auto_initialize = null;
             if (method_exists($class, '_init') and is_callable($class . '::_init')) {
                 call_user_func($class . '::_init');
             }
         }
     } elseif (interface_exists($class, false)) {
         // nothing to do here
     } elseif (function_exists('trait_exists') and trait_exists($class, false)) {
         // nothing to do here
     } elseif ($file) {
         throw new \Exception('File "' . \Fuel::clean_path($file) . '" does not contain class "' . $class . '"');
     } else {
         throw new \FuelException('Class "' . $class . '" is not defined');
     }
 }
Пример #18
0
 public function set_filename($file)
 {
     // set find_file's one-time-only search paths
     \Finder::instance()->flash($this->request_paths);
     $is_pjax = Input::server('HTTP_X_PJAX') or Input::get('_pjax');
     // Check if this request is being made by PJAX
     if ($is_pjax) {
         $pjax_file = explode('.', $file);
         $pjax_file = $pjax_file[0] . Config::get('pjax.file', '-pjax');
         // locate the pjax view file
         if (($path = \Finder::search('views', $pjax_file, '.' . $this->extension, false, false)) !== false) {
             $this->pjax_file_loaded = true;
         } else {
             // PJAX file not found, carry on looking for normal view file
             if (($path = \Finder::search('views', $file, '.' . $this->extension, false, false)) === false) {
                 throw new \FuelException('The requested view could not be found: ' . \Fuel::clean_path($file));
             }
         }
         Log::info('Pjax\\View::forge - loaded WITH PJAX: ' . $path);
     } else {
         // locate the view file
         if (($path = \Finder::search('views', $file, '.' . $this->extension, false, false)) === false) {
             throw new \FuelException('The requested view could not be found: ' . \Fuel::clean_path($file));
         }
         Log::info('Pjax\\View::forge - loaded WITHOUT PJAX: ' . $path);
     }
     // Store the file path locally
     $this->file_name = $path;
     return $this;
 }
Пример #19
0
}
?>
		<h2>Backtrace</h2>
		<ol>
		<?php 
$id = 0;
foreach ($backtrace as $trace) {
    $id++;
    $debug_lines = \Debug::file_lines($trace['file'], $trace['line']);
    ?>
			<li><a href="#"
				onclick="javascript:fuel_toggle('backtrace_<?php 
    echo $id;
    ?>
');return false;"><?php 
    echo \Fuel::clean_path($trace['file']) . ' @ line ' . $trace['line'];
    ?>
</a>
				<div id="backtrace_<?php 
    echo $id;
    ?>
" class="backtrace_block">
					<pre class="fuel_debug_source"><?php 
    foreach ((array) $debug_lines as $line_num => $line_content) {
        ?>
<span
							<?php 
        echo $line_num == $trace['line'] ? ' class="fuel_line fuel_current_line"' : ' class="fuel_line"';
        ?>
><span
							class="fuel_line_number"><?php 
Пример #20
0
 /**
  * Sets the view filename.
  *
  *     $view->set_filename($file);
  *
  * @param   string  view filename
  * @return  View
  * @throws  Fuel_Exception
  */
 public function set_filename($file)
 {
     // set find_file's one-time-only search paths
     \Fuel::$volatile_paths = $this->request_paths;
     // locate the view file
     if (($path = \Fuel::find_file('views', $file, '.' . $this->extension, false, false)) === false) {
         throw new \Fuel_Exception('The requested view could not be found: ' . \Fuel::clean_path($file));
     }
     // Store the file path locally
     $this->_file = $path;
     return $this;
 }
Пример #21
0
	/**
	 * Sets the view filename.
	 *
	 *     $view->set_filename($file);
	 *
	 * @param   string  view filename
	 * @return  View
	 * @throws  Fuel_Exception
	 */
	public function set_filename($file)
	{
		if (($path = \Fuel::find_file('views', $file, '.'.$this->extension, false, false)) === false)
		{
			throw new \Fuel_Exception('The requested view could not be found: '.\Fuel::clean_path($file));
		}

		// Store the file path locally
		$this->_file = $path;

		return $this;
	}
Пример #22
0
 private static function _download_package_zip($zip_url, $package, $version)
 {
     \Cli::write('Downloading package: ' . $zip_url);
     // Make the folder so we can extract the ZIP to it
     mkdir($tmp_folder = APPPATH . 'tmp/' . $package . '-' . time());
     $zip_file = $tmp_folder . '.zip';
     @copy($zip_url, $zip_file);
     $unzip = new \Unzip();
     $files = $unzip->extract($zip_file, $tmp_folder);
     // Grab the first folder out of it (we dont know what it's called)
     list($tmp_package_folder) = glob($tmp_folder . '/*', GLOB_ONLYDIR);
     $package_folder = PKGPATH . $package;
     // Move that folder into the packages folder
     rename($tmp_package_folder, $package_folder);
     unlink($zip_file);
     rmdir($tmp_folder);
     foreach ($files as $file) {
         $path = str_replace($tmp_package_folder, $package_folder, $file);
         chmod($path, octdec(755));
         \Cli::write("\t" . \Fuel::clean_path($path));
     }
 }
Пример #23
0
 /**
  * Sets the view filename.
  *
  *     $view->set_filename($file);
  *
  * @param   string  view filename
  * @return  View
  * @throws  FuelException
  */
 public function set_filename($file)
 {
     // set find_file's one-time-only search paths
     \Finder::instance()->flash($this->request_paths);
     // locate the view file
     if (($path = \Finder::search('views', $file, '.' . $this->extension, false, false)) === false) {
         throw new \FuelException('The requested view could not be found: ' . \Fuel::clean_path($file));
     }
     // Store the file path locally
     $this->file_name = $path;
     return $this;
 }
Пример #24
0
	public static function notice($msg, $always_show = false)
	{
		if ( ! $always_show && (\Fuel::$env == \Fuel::PRODUCTION || \Config::get('show_notices', true) === false))
		{
			return;
		}

		$trace = array_merge(array('file' => '(unknown)', 'line' => '(unknown)'), \Arr::element(debug_backtrace(), 1));

		logger(Fuel::L_DEBUG, 'Notice - '.$msg.' in '.$trace['file'].' on line '.$trace['line']);

		$data['message']	= $msg;
		$data['type']		= 'Notice';
		$data['filepath']	= \Fuel::clean_path($trace['file']);
		$data['line']		= $trace['line'];
		$data['function']	= $trace['function'];

		echo \View::factory('errors'.DS.'php_short', $data);
	}