コード例 #1
0
ファイル: post.php プロジェクト: EGreg/PHP-On-Pie
function users_register_post_download($url, $folder, $size = 80)
{
    $url_parts = parse_url($url);
    if (substr($url_parts['host'], -12) != 'gravatar.com') {
        return false;
    }
    $dir = Pie_Config::get('users', 'paths', 'icons', 'files/users/icons');
    $ch = curl_init(Pie_Uri::url($_REQUEST['icon'] . '?s=' . $size));
    $dir2 = Pie::realPath($dir) . DS . $folder;
    if (!file_exists($dir2)) {
        mkdir($dir2, 0777);
        chmod($dir2, 0777);
    }
    $fp = fopen($dir2 . DS . "{$size}.png", 'wb');
    curl_setopt($ch, CURLOPT_FILE, $fp);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_exec($ch);
    curl_close($ch);
    fclose($fp);
    return true;
}
コード例 #2
0
ファイル: Parameters.php プロジェクト: EGreg/PHP-On-Pie
 /**
  * Loads all the configuration files matching $pattern
  * @param string $filename
  *  The filename of the file to load.
  * @return boolean
  *  Returns true if saved, otherwise false.
  */
 function load($filename)
 {
     $filename2 = Pie::realPath($filename);
     if (!$filename2) {
         return false;
     }
     $contents = file_get_contents($filename2);
     $arr = json_decode($contents, true);
     if (!isset($arr)) {
         throw new Pie_Exception_InvalidInput(array('source' => $filename));
     }
     if (is_array($arr)) {
         $this->merge($arr);
     }
     return true;
 }
コード例 #3
0
ファイル: Bootstrap.php プロジェクト: EGreg/PHP-On-Pie
 /**
  * Loads the configuration and plugins in the right order
  */
 static function configure()
 {
     Pie_Config::load('config/pie.json');
     // Get the app config, but don't load it yet
     $app_p = new Pie_Parameters();
     $app_p->load('config/app.json');
     $app_p->load('local/app.json');
     // Load all the plugin config files first
     $paths = explode(PS, get_include_path());
     $plugins = $app_p->get('pie', 'plugins', array());
     foreach ($plugins as $plugin) {
         $plugin_path = Pie::realPath('plugins' . DS . $plugin);
         if (!$plugin_path) {
             throw new Pie_Exception_MissingPlugin(compact('plugin'));
         }
         Pie_Config::load($plugin_path . DS . 'config' . DS . 'plugin.json');
         array_splice($paths, 1, 0, array($plugin_path));
         $PLUGIN = strtoupper($plugin);
         if (!defined($PLUGIN . '_PLUGIN_DIR')) {
             define($PLUGIN . '_PLUGIN_DIR', $plugin_path);
         }
         if (!defined($PLUGIN . '_PLUGIN_CONFIG_DIR')) {
             define($PLUGIN . '_PLUGIN_CONFIG_DIR', $plugin_path . DS . 'config');
         }
         if (!defined($PLUGIN . '_PLUGIN_CLASSES_DIR')) {
             define($PLUGIN . '_PLUGIN_CLASSES_DIR', $plugin_path . DS . 'classes');
         }
         if (!defined($PLUGIN . '_PLUGIN_FILES_DIR')) {
             define($PLUGIN . '_PLUGIN_FILES_DIR', $plugin_path . DS . 'files');
         }
         if (!defined($PLUGIN . '_PLUGIN_HANDLERS_DIR')) {
             define($PLUGIN . '_PLUGIN_HANDLERS_DIR', $plugin_path . DS . 'handlers');
         }
         if (!defined($PLUGIN . '_PLUGIN_PLUGINS_DIR')) {
             define($PLUGIN . '_PLUGIN_PLUGINS_DIR', $plugin_path . DS . 'plugins');
         }
         if (!defined($PLUGIN . '_PLUGIN_SCRIPTS_DIR')) {
             define($PLUGIN . '_PLUGIN_SCRIPTS_DIR', $plugin_path . DS . 'scripts');
         }
         if (!defined($PLUGIN . '_PLUGIN_TESTS_DIR')) {
             define($PLUGIN . '_PLUGIN_TESTS_DIR', $plugin_path . DS . 'tests');
         }
         if (!defined($PLUGIN . '_PLUGIN_WEB_DIR')) {
             define($PLUGIN . '_PLUGIN_WEB_DIR', $plugin_path . DS . 'web');
         }
     }
     set_include_path(implode(PS, $paths));
     // Now, we can merge in our app's config
     Pie_Config::merge($app_p);
     // Now, load any other files we were supposed to load
     $config_files = Pie_Config::get('pie', 'configFiles', array());
     foreach ($config_files as $cf) {
         Pie_Config::load($cf);
     }
     $script_files = Pie_Config::get('pie', 'scriptFiles', array());
     foreach ($script_files as $cf) {
         Pie::includeFile($cf);
     }
 }
コード例 #4
0
ファイル: Dispatcher.php プロジェクト: EGreg/PHP-On-Pie
 /**
  * Dispatches a URI for internal processing.
  * Usually called by a front controller.
  * @param mixed $uri
  *  Optional. You can pass a custom URI to dispatch. Otherwise, PIE will attempt
  *  to route the requested URL, if any.
  * @param array $check
  *  Optional. Pass array() to skip checking whether the URI can be obtained
  *  as a result of routing some URL.
  * @return boolean
  */
 static function dispatch($uri = null, $check = array('accessible'))
 {
     if (!is_array($check)) {
         $check = array('accessible');
     }
     if (isset($uri)) {
         if (in_array('accessible', $check)) {
             if (!Pie_Uri::url($uri)) {
                 // We shouldn't dispatch to this URI
                 $uri = Pie_Uri::from(array());
             }
         }
         self::$uri = Pie_Uri::from($uri);
     } else {
         self::$uri = Pie_Request::uri();
     }
     // if file or dir is requested, try to serve it
     $served = false;
     $skip = Pie_Config::get('pie', 'dispatcherSkipFilename', false);
     $filename = $skip ? false : Pie_Request::filename();
     if ($filename) {
         if (is_dir($filename)) {
             $served = Pie::event("pie/dir", compact('filename', 'routed_uri'));
             $dir_was_served = true;
         } else {
             $served = Pie::event("pie/file", compact('filename', 'routed_uri'));
             $dir_was_served = false;
         }
     }
     // if response was served, then return
     if ($served) {
         self::result($dir_was_served ? "Dir served" : "File served");
         return true;
     }
     // This loop is for forwarding
     $max_forwards = Pie_Config::get('pie', 'maxForwards', 10);
     for ($try = 0; $try < $max_forwards; ++$try) {
         // Make an array from the routed URI
         $routed_uri_array = array();
         if (self::$uri instanceof Pie_Uri) {
             $routed_uri_array = self::$uri->toArray();
         }
         // If no module was found, then respond with noModule and return
         if (!isset(self::$uri->module)) {
             Pie::event("pie/noModule", $routed_uri_array);
             // should echo things
             self::result("No module");
             return false;
         }
         $module = self::$uri->module;
         // Implement restricting of modules we are allowed to access
         $routed_modules = Pie_Config::get('pie', 'routedModules', null);
         if (isset($routed_modules)) {
             if (!in_array($module, $routed_modules)) {
                 Pie::event('pie/notFound', $routed_uri_array);
                 // should echo things
                 self::result("Unknown module");
                 return false;
             }
         } else {
             if (!Pie::realPath("handlers/{$module}")) {
                 Pie::event('pie/notFound', $routed_uri_array);
                 // should echo things
                 self::result("Unknown module");
                 return false;
             }
         }
         try {
             // Fire a pure event, for aggregation etc
             if (!in_array('pie/prepare', self::$skip)) {
                 Pie::event('pie/prepare', $routed_uri_array, true);
             }
             // Perform validation
             if (!in_array('pie/validate', self::$skip)) {
                 Pie::event('pie/validate', $routed_uri_array);
                 // Check if any errors accumulated
                 if (Pie_Response::getErrors()) {
                     // There were validation errors -- render a response
                     self::errors(null, $module, null);
                     self::result('Validation errors');
                     return false;
                 }
             }
             // Time to instantiate some app objects from the request
             if (!in_array('pie/objects', self::$skip)) {
                 Pie::event('pie/objects', $routed_uri_array, true);
             }
             // We might want to reroute the request
             if (!in_array('pie/reroute', self::$skip)) {
                 $stop_dispatch = Pie::event('pie/reroute', $routed_uri_array, true);
                 if ($stop_dispatch) {
                     self::result("Stopped dispatch");
                     return false;
                 }
             }
             if (Pie_Request::isPost()) {
                 if (!in_array('pie/post', self::$skip)) {
                     // Make some changes to server state, possibly
                     Pie::event('pie/post', $routed_uri_array);
                 }
             }
             // Time to instantiate some app objects from the request
             if (!in_array('pie/analytics', self::$skip)) {
                 Pie::event('pie/analytics', $routed_uri_array, true);
             }
             // Start buffering the response, unless otherwise requested
             if ($handler = Pie_Response::isBuffered()) {
                 $ob = new Pie_OutputBuffer($handler);
             }
             // Generate and render a response
             Pie::event("pie/response", $routed_uri_array);
             if (!empty($ob)) {
                 $ob->endFlush();
             }
             self::result("Served response");
             return true;
         } catch (Pie_Exception_DispatcherForward $e) {
             // Go again, this time with a different URI.
             self::$uri = Pie_Uri::from($e->uri);
             if (is_array($e->skip)) {
                 self::$skip = $e->skip;
             } else {
                 // Don't process the POST fields this time around
                 self::$skip = array('pie/post');
             }
             // We'll be handling errors anew
             self::$handling_errors = false;
         } catch (Pie_Exception_DispatcherErrors $e) {
             if (!empty($ob)) {
                 $partial_response = $ob->getClean();
             } else {
                 $partial_response = null;
             }
             self::errors(null, $module, $partial_response);
             self::result("Rendered errors");
             return true;
         } catch (Exception $exception) {
             if (!empty($ob)) {
                 $partial_response = $ob->getClean();
             } else {
                 $partial_response = null;
             }
             self::errors($exception, $module, $partial_response);
             self::result("Exception occurred");
             return false;
         }
     }
     // If we are here, we have done forwarding too much
     throw new Pie_Exception_Recursion(array('function_name' => 'Dispatcher::forward()'));
 }