Beispiel #1
0
function u($short_url)
{
    $args = func_get_args();
    $route_info = Nimble::getInstance()->get_route_info_by_short_name($short_url);
    $args = array_merge(array($route_info->controller, $route_info->method), array_slice($args, 1));
    return call_user_func_array('UrlBuilder::url_for', $args);
}
Beispiel #2
0
 /**
  * Get the global Nimble object instance.
  * @return Nimble The global Nimble reference.
  */
 public static function getInstance()
 {
     if (self::$instance == NULL) {
         self::$instance = new Nimble();
     }
     return self::$instance;
 }
 /**
  * This handles uploads to a persions channel
  * Need file posted as 'file' and the has poster as 'hash'
  */
 public function upload()
 {
     switch ($this->format) {
         case 'xml':
             try {
                 $package = Package::from_upload(array('file' => $_FILES['file']['tmp_name'], 'sig' => $_POST['signatureBase64'], 'user' => $this->user), true);
                 if ($package->saved) {
                     echo 'Package uploaded succesfuly!';
                 }
             } catch (Exception $e) {
                 $this->header("HTTP/1.0 500 Internal Server Error", 500);
                 echo $e->getMessage();
             }
             $this->has_rendered = true;
             break;
         default:
             if ($_SESSION['upload_key'] !== $_POST['upload_key']) {
                 Nimble::flash('notice', 'Invalid Upload Key');
                 $this->redirect_to(url_for('LandingController', 'user_index', $this->user->username));
             }
             unset($_SESSION['upload_key']);
             try {
                 $package = Package::from_upload(array('file' => $_FILES['file']['tmp_name'], 'user' => $this->user));
                 if ($package->saved) {
                     $this->redirect_to(url_for('LandingController', 'user_index', $this->user->username));
                 }
             } catch (Exception $e) {
                 Nimble::flash('notice', $e->getMessage());
                 $this->redirect_to(url_for('ChannelController', 'upload'));
             }
             break;
     }
 }
 public function show_flash()
 {
     if (isset($_SESSION['flashes']['notice']) && !empty($_SESSION['flashes']['notice'])) {
         $notice = Nimble::display_flash('notice');
         echo "<div id='flash' class='notice'>{$notice}</div>";
     }
 }
Beispiel #5
0
 public function testPageTitleCarrierWithCustomSeperator()
 {
     Nimble::set_config('site_title', 'Mysite');
     Nimble::set_config('title_seperator', '->');
     Nimble::set_title('My Page');
     $this->assertEquals('Mysite->My Page', Nimble::get_title());
 }
Beispiel #6
0
 public static function build($rootNode, $vals = null)
 {
     $xsz = new XML_Serializer(array('rootName' => $rootNode, 'mode' => 'simplexml'));
     $xsz->serialize($vals);
     $xml = $xsz->getSerializedData();
     Nimble::log($xml, PEAR_LOG_DEBUG);
     return $xml;
 }
Beispiel #7
0
function Run($test_mode = false)
{
    if (defined('NIMBLE_IS_TESTING')) {
        $test_mode = NIMBLE_IS_TESTING;
    }
    Nimble::getInstance()->dispatch($test_mode);
    // exceptions handled by my_exception_handler.
}
Beispiel #8
0
 /**
  * @expectedException NimbleException
  */
 public function testUrlForFailsWrongParams()
 {
     $this->Nimble->routes = array();
     $this->Nimble->uri = '';
     Nimble::set_config('url', '/class/1');
     $this->Nimble->add_url('/class/:method', "Class", "Method");
     $this->assertEquals('/class/1', url_for('Class', 'Method', 1, 2));
 }
Beispiel #9
0
 /**
  * Bind the Route object to Nimble's router.
  * @throws NimbleException if the requested HTTP method is invalid.
  */
 function bind()
 {
     if (in_array($this->http_method, self::$allowed_methods)) {
         $router = Nimble::getInstance()->add_url($this->pattern, $this->controller, $this->action, $this->http_method);
     } else {
         throw new NimbleException('Invalid Request');
     }
 }
 public function testLoadBothCustomAndNimble()
 {
     Nimble::plugins('test_plugin');
     $this->Nimble->__construct();
     $this->Nimble->dispatch(true);
     $test_class = new TestPlugin();
     $this->assertEquals($test_class->foo(), 'foo');
     $this->assertEquals(1, 1);
 }
Beispiel #11
0
 function __construct()
 {
     $this->nimble = Nimble::getInstance();
     $this->view_path = $this->nimble->config['view_path'];
     if (defined('NIMBLE_IS_TESTING') && NIMBLE_IS_TESTING && defined('FAKEMAIL_PORT')) {
         $this->mailmethod = 'smtp';
         $this->mailparams['port'] = FAKEMAIL_PORT;
     }
 }
Beispiel #12
0
 public function testGETisSetFromUrlArgs()
 {
     global $_GET;
     Nimble::set_config('url', '/class/1');
     $this->Nimble->add_url('/class/:method', "MyTestClass", "method");
     $this->Nimble->dispatch(true);
     $this->assertTrue(isset($_GET['method']));
     $this->assertEquals($_GET['method'], '1');
 }
Beispiel #13
0
 /**
  * This class has 3 required variables that need to be set
  * $from (string), $subject (string), $recipient | $recipients (string || array)
  * Options Variables
  * $time (time), $headers (string)
  */
 public function __construct()
 {
     $this->nimble = Nimble::getInstance();
     $this->view_path = $this->nimble->config['view_path'];
     $this->class = get_called_class();
     $this->time = time();
     $this->_divider = '------=_' . rand(10000000, 99999999999) * 2;
     $this->_content = array();
 }
 public function index()
 {
     $this->title = 'Making it trivially easy to create PEAR packages.';
     Nimble::set_title($this->title);
     $this->set_default_side_bar();
     if ($this->is_logged_in()) {
         $this->login_user();
     }
 }
 public function setUp()
 {
     $_SESSION = array();
     $_POST['_method'] = 'GET';
     $_SERVER['REQUEST_METHOD'] = '';
     $_SESSION['flashes'] = array();
     $this->Nimble = Nimble::getInstance();
     $this->Nimble->routes = array();
     $this->Nimble->url = '';
 }
Beispiel #16
0
 public function setUp()
 {
     $_SESSION = array();
     $_SESSION['flashes'] = array();
     $_SERVER['REQUEST_METHOD'] = 'GET';
     $this->Nimble = Nimble::getInstance();
     $this->Nimble->routes = array();
     $this->url = '';
     $this->Nimble->test_mode = true;
     Nimble::set_config('plugins_path', join(DIRECTORY_SEPARATOR, array(dirname(__FILE__), 'test_plugins')));
     Nimble::set_config('view_path', join(DIRECTORY_SEPARATOR, array(dirname(__FILE__), 'views')));
 }
 public function delete()
 {
     $this->login_user();
     try {
         $package = Package::find('first', array('conditions' => array('id' => $_GET['id'], 'user_id' => $this->user->id)));
         $package->clear_all_version();
         Nimble::flash('notice', $package->name . " was deleted");
         $package->destroy();
         $this->redirect_to('/');
     } catch (NimbleRecordNotFound $e) {
         Nimble::flash('notice', "Package does not exist or does not belong to you");
         $this->redirect_to('/');
     }
 }
Beispiel #18
0
function Run($test_mode = false)
{
    try {
        Nimble::getInstance()->dispatch($test_mode);
    } catch (Exception $e) {
        if (NIMBLE_ENV == 'development' && !$test_mode) {
            ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title>Error!</title>
    </head>
    <body>
        <h1>Caught exception: <?php 
            echo $e->getMessage();
            ?>
</h1>
        <h2>File: <?php 
            echo $e->getFile();
            ?>
</h2>
        <h2>Line: <?php 
            echo $e->getLine();
            ?>
</h2>
        <h3>Trace</h3>
        <pre>
        <?php 
            echo $e->getTraceAsString();
            ?>
        </pre>
        <h3>Exception Object</h3>
        <pre>
        <?php 
            var_dump($e);
            ?>
        </pre>
        <h3>Var Dump</h3>
        <pre>
        <?php 
            debug_print_backtrace();
            ?>
        </pre>
    </body>
</html>        
        <?php 
        }
    }
}
 public function delete()
 {
     $this->login_user();
     try {
         $package = Package::find($_GET['id']);
         $version = Version::find($_GET['version']);
     } catch (NimbleRecordNotFound $e) {
         $this->redirect_to('/');
     }
     if ($version->package_id == $package->id && $package->user_id == $this->user->id) {
         $file = $package->file_path($version->version);
         @unlink($file);
         Nimble::flash('notice', "Version: {$version->version} was deleted");
         $version->delete();
         $this->redirect_to(url_for('PackageController', 'show', $package->user->username, $package->name));
     } else {
         $this->redirect_to('/');
     }
 }
Beispiel #20
0
 /**
  * @param string $action action you wish to call
  * @param array $action_params array of arguments to pass to the action method
  */
 private function load_action($action, $action_params)
 {
     global $_SESSION, $_POST, $_GET;
     $nimble = Nimble::getInstance();
     ob_start();
     $controller = new $this->controller_name();
     $controller->format = !empty($action_params['format']) ? $action_params['format'] : $controller->default_format;
     call_user_func(array($controller, "run_before_filters"), $action);
     call_user_func_array(array($controller, $action), array($action_params));
     $path = strtolower(Inflector::underscore(str_replace('Controller', '', $this->controller_name)));
     $template = FileUtils::join($path, $action);
     if ($controller->has_rendered === false) {
         if (empty($controller->layout_template) && $controller->layout) {
             $controller->set_layout_template();
         }
         $controller->render($template);
     }
     call_user_func(array($controller, "run_after_filters"), $action);
     $this->response = ob_get_clean();
     $this->controller = $controller;
 }
}
/** load nimble */
require_once 'nimblize/nimblize.php';
/** Set the path to the view templates */
Nimble::set_config('view_path', FileUtils::join(dirname(__FILE__), '..', 'app', 'view'));
/** set the default plugin path */
Nimble::set_config('plugins_path', FileUtils::join(dirname(__FILE__), '..', 'plugin'));
Nimble::set_config('default_layout', FileUtils::join(Nimble::getInstance()->config['view_path'], 'layout', 'application.php'));
/** set asset path change this in your config.php to override */
Nimble::set_config('stylesheet_folder', FileUtils::join(dirname(__FILE__), '..', 'public', 'style'));
Nimble::set_config('stylesheet_folder_url', '/public/style');
Nimble::set_config('javascript_folder', FileUtils::join(dirname(__FILE__), '..', 'public', 'javascript'));
Nimble::set_config('javascript_folder_url', '/public/javascript');
Nimble::set_config('image_url', 'public/image');
Nimble::set_config('image_path', FileUtils::join(dirname(__FILE__), '..', 'public', 'image'));
Nimble::set_config('uri', '/');
//define the root
define('NIMBLE_ROOT', FileUtils::join(dirname(__FILE__), '..'));
// load any custom global config options
require_once FileUtils::join(dirname(__FILE__), 'config.php');
require_once FileUtils::join(dirname(__FILE__), 'routes.php');
require_once FileUtils::join(dirname(__FILE__), 'r404.php');
// load any custom enviroment config options
// Nimble::Log('loading ' . NIMBLE_ENV . ' enviroment');
require_once FileUtils::join(dirname(__FILE__), NIMBLE_ENV, 'config.php');
require_once FileUtils::join(NIMBLE_ROOT, 'app', 'controller', 'application_controller.php');
/** load controlers and models */
foreach (array('model', 'controller') as $dir) {
    __load_files(FileUtils::join(dirname(__FILE__), '..', 'app', $dir));
}
session_set_cookie_params(time() + 1000, '/', '.' . DOMAIN);
Beispiel #22
0
 /**
  * Match the HTTP request's URL and HTTP method against the stored routes and, if a match is found, call the appropriate controller's method.
  * If the client you're using doesn't support sending HTTP requests with methods
  * other than GET or POST, set $_POST['_method'] to the actual HTTP method you wish to use.
  */
 public function dispatch($test = false)
 {
     $this->load_plugins();
     foreach ($this->routes as $rule => $conf) {
         // if a vaild _method is passed in a post set it to the REQUEST_METHOD so that we can route for DELETE and PUT methods
         if (isset($_POST['_method']) && !empty($_POST['_method']) && in_array(strtoupper($_POST['_method']), Route::$allowed_methods)) {
             $_SERVER['REQUEST_METHOD'] = strtoupper($_POST['_method']);
         }
         if (empty($_SERVER['REQUEST_METHOD'])) {
             if (!$test) {
                 throw new NimbleException('No valid Request Method given.');
             } else {
                 return false;
             }
         }
         /** test to see if its a valid route */
         if (preg_match($conf[0], $this->url, $matches) && (empty($conf[3]) || $_SERVER['REQUEST_METHOD'] == $conf[3])) {
             /** Only declared variables in URL regex */
             $matches = $this->parse_urls_args($matches);
             $this->klass = new $conf[1]();
             /** set the layout tempalte to the default */
             $this->klass->set_layout_template();
             $this->klass->format = $conf[4] ? array_pop($matches) : $this->klass->default_format;
             Nimble::log("dispatching '/{$this->url}' as {$conf[1]}::{$conf[2]} {$conf[3]} {$this->klass->format}", NIMBLE_LOG_INFO);
             ob_start();
             // call before filters
             call_user_func(array($this->klass, "run_before_filters"), $conf[2]);
             // call methods on controller class
             call_user_func_array(array($this->klass, $conf[2]), array($matches));
             if (!$this->klass->has_rendered && isset($this->config['view_path'])) {
                 $dir = str_replace('Controller', '', $conf[1]);
                 $dir = strtolower(Inflector::underscore($dir));
                 $tpl = empty($this->klass->template) ? $conf[2] : $this->klass->template;
                 $view = FileUtils::join($dir, $tpl);
                 $this->klass->render($view);
             }
             // call after filters
             call_user_func(array($this->klass, "run_after_filters"), $conf[2]);
             $out = ob_get_clean();
             if (count($this->klass->headers) > 0) {
                 foreach (array_values($this->klass->headers) as $header) {
                     if (!$this->test_mode) {
                         header($header[0], true, empty($header[1]) ? null : $header[1]);
                     }
                 }
             }
             print $out;
             if (!$test) {
                 exit;
             }
         }
     }
     if (!$test) {
         if (class_exists('r404')) {
             if (method_exists('r404', $_SERVER['REQUEST_METHOD'])) {
                 call_user_func(array('r404', $_SERVER['REQUEST_METHOD']));
             } else {
                 call_user_func(array('r404', 'renderError'));
             }
         } else {
             throw new NimbleException("Routing Error. No suitable routes found and no 404 handler exists.");
         }
     }
 }
Beispiel #23
0
 function rebind()
 {
     if (isset($this->bind_id)) {
         Nimble::getInstance()->remove_url_by_id($this->bind_id);
         $this->bind();
     }
 }
Beispiel #24
0
 /**
  * respond to a given request format directly, using a specific function/method 
  * - instead of the default Controller->render() action which loads a view.
  *
  * Would be nice to use a lambda function with a closure here, so we could pass the controller
  * itself to the function at runtime. But for php<5.3 have to settle for this.
  *
  * example call, in a controller action:
  *      $this->respond_to('xml', array('XMLview', 'build'), array('loginResult', $this->result));
  *      # pre-supposes that xml_view plugin is loaded via Nimble::plugins('xml_view')
  *
  * @param $format string        format we are expecting to respond to (xml, json, etc)
  * @param $func mixed           function name, reference or array suitable for call_user_func_array()
  * @param $args array opt       arguments to be passed to the function
  * @throws NimbleException       
  */
 public function respond_to($format, $func = null, $args = array())
 {
     if ($this->format() == $format) {
         if (is_callable($func)) {
             $funcname = is_array($func) ? $func[0] . '::' . $func[1] : (string) $funcname;
             Nimble::log("responding to {$format} with {$funcname}", NIMBLE_LOG_DEBUG);
             echo call_user_func_array($func, $args);
             $this->has_rendered = true;
             if (isset($this->headers_by_format[$format])) {
                 $this->headers[] = $this->headers_by_format[$format];
             }
         } else {
             throw new NimbleException('Uncallable function given to respond_to()');
         }
     }
 }
Beispiel #25
0
 public function setUp()
 {
     $this->nimble = Nimble::getInstance();
     $this->nimble->config['view_path'] = join(DIRECTORY_SEPARATOR, array(dirname(__FILE__), 'views'));
 }
Beispiel #26
0
 /**
  * Include a PHP file, inject the controller's properties into that file, and return the output.
  * @param string $file The view file to render, relative to the base of the application.
  * @return string The rendered view file.
  */
 public function render_partial($file)
 {
     NimbleLogger::log("RENDERING PARTIAL: {$file}");
     $this->rendered_partials[] = $file;
     return $this->open_template(FileUtils::join(Nimble::getInstance()->config['view_path'], $file));
 }
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
	<link rel="Shortcut Icon" href="/public/image/favico.ico" />
	<link rel="icon" href="/public/image/favico.ico" type="image/x-icon" />
	<link rel="search" type="application/opensearchdescription+xml" href="http://<?php 
echo DOMAIN;
?>
/opensearch.xml" title="Pearfarm" /> 
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta name="google-site-verification" content="griVQ0kTz8ri_7TzrEN8bOALKwWT8g2fgbow_3GsDQM" />
	<meta name="description" content="Pearfarm is the Php community's pear hosting service. Instantly publish your pear packages and install them. Become a contributor and enhance the site with your own changes." /> 
	<meta name="keywords" content="php pear packages community code repository opensource" />
	<title><?php 
echo h(Nimble::get_title());
?>
</title>
	<?php 
echo stylesheet_link_tag('stylesheet.css', 'facebox.css');
?>
	<!--[if lt IE 7]>
	  <?php 
echo javascript_include_tag('pngfix.js');
?>
  <![endif]-->
	<?php 
echo javascript_include_tag('prototype.js', 'scriptaculous.js', 'facebox.js');
?>
	<script type='text/javascript'>
		Event.observe(window, 'load', function(){
Beispiel #28
0
 /**
  * Dump out application routes to a human readable format.
  * @param boolean $cli True if being called from the command line.
  * @return string The application's routes in a human readable format.
  */
 public static function dumpRoutes($cli = false)
 {
     $klass = Nimble::getInstance();
     $out = array();
     foreach ($klass->routes as $route) {
         $pattern = self::clean_route($route[0]);
         $pattern = empty($pattern) ? 'root path' : $pattern;
         array_push($out, "Controller: {$route[1]} Action: {$route[2]} Method: {$route[3]} Pattern: " . $pattern);
     }
     $return = "\n";
     $return .= join("\n", $out);
     $return .= "\n";
     return $cli ? $return : htmlspecialchars($return);
 }
 public function stats()
 {
     $this->title = 'Pearfarm Stats';
     Nimble::set_title($this->title);
 }
Beispiel #30
0
 /**
  * Include a PHP file, inject the controller's properties into that file, and return the output.
  * @param string $file The view file to render, relative to the base of the application.
  * @return string The rendered view file.
  */
 public function render_partial($file)
 {
     $this->rendered_partials[] = $file;
     return $this->open_template(FileUtils::join(Nimble::getInstance()->config['view_path'], $file));
 }