public function after_create()
 {
     UserMailer::deliver_new_user($this->email, $this);
     $path = FileUtils::join(NIMBLE_ROOT, 'get', $this->username);
     FileUtils::mkdir_p($path);
     chmod($path, 0755);
 }
Example #2
0
 public function setUp()
 {
     $dir = dirname(__FILE__);
     $this->nimble = Nimble::getINstance();
     Nimble::set_config('stylesheet_folder', FileUtils::join($dir, 'assets', 'stylesheets'));
     Nimble::set_config('stylesheet_folder_url', '/stylesheet');
     Nimble::set_config('javascript_folder', FileUtils::join($dir, 'assets', 'javascript'));
     Nimble::set_config('javascript_folder_url', '/javascript');
 }
 public function about()
 {
     $this->set_default_side_bar();
     require_once FileUtils::join(NIMBLE_ROOT, 'lib', 'markdown.php');
     $template = FileUtils::join(NIMBLE_ROOT, 'app', 'view', 'help', 'about.markdown');
     $this->about = file_get_contents($template);
     $this->title = 'About Pearfarm';
     Nimble::set_title($this->title);
 }
 public static function create_package()
 {
     $user = User::find_by_username('bob');
     $file = FileUtils::join(NIMBLE_ROOT, 'test', 'data', 'bobs_other_package-0.0.1.tgz');
     $package = Package::from_upload(array('file' => $file, 'user' => $user));
     foreach (User::_find('all') as $user) {
         $raiting = '0.' . $user->id;
         PackageRating::_create(array('user_id' => $user->id, 'package_id' => $package->id, 'rating' => (double) $raiting));
     }
 }
 public function testUploadHtmlFailsnoFile()
 {
     $localfile = FileUtils::join(NIMBLE_ROOT, 'test', 'data', 'bobs_other_package-1.0.4.tgz');
     $_FILES = array();
     $_FILES['file'] = array();
     $_FILES['file']['tmp_name'] = '';
     $key = md5(time());
     $this->post('upload', array(), array('upload_key' => $key), array('upload_key' => md5(md5(time())), 'user' => User::find_by_username('bob')->id), 'html');
     $this->assertEquals($_SESSION['flashes']['notice'], 'Package channel  does not match bob.localhost.com');
     $this->assertRedirect(url_for('LandingController', 'user_index', User::find_by_username('bob')->username));
 }
 public function testUploadFailbadSig()
 {
     $localfile = FileUtils::join(NIMBLE_ROOT, 'test', 'data', 'joes_other_package-1.0.4.tgz');
     $sig = PackageVerifyTest::calculatePackageSignature($localfile);
     $user = User::find_by_username('joe');
     try {
         $p = Package::from_upload(array('file' => $localfile, 'sig' => $sig, 'user' => $user), true);
     } catch (NimbleException $e) {
         $this->assertEquals("Invalid package signature", $e->getMessage());
     }
 }
Example #7
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;
 }
 public function file_path($version)
 {
     return FileUtils::join(NIMBLE_ROOT, 'get', $this->user->username, "{$this->name}-{$version}.tgz");
 }
Example #9
0
 public function testFileJoinReturnsString()
 {
     $string = 'test' . DIRECTORY_SEPARATOR . 'myfolder';
     $this->assertEquals($string, FileUtils::join('test', 'myfolder'));
 }
Example #10
0
 public static function load_interfaces($dir = '')
 {
     $dirs = array(__DIR__ . '/interfaces');
     if (!empty($dir)) {
         $dirs[] = $dir;
     }
     foreach ($dirs as $dir) {
         if ($dh = opendir($dir)) {
             while (($file = readdir($dh)) !== false) {
                 if (strpos($file, '.php') !== false) {
                     require_once FileUtils::join($dir, $file);
                     $class = Inflector::classify(substr(basename($file), 0, -4));
                     $methods = call_user_func(array($class, 'methods'));
                     $out = array();
                     foreach ($methods as $method) {
                         $out[$method] = $class;
                     }
                     static::$interface_map = array_merge(static::$interface_map, $out);
                 }
             }
             closedir($dh);
         }
     }
 }
Example #11
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));
 }
Example #12
0
function nimble_load_helper($name)
{
    require_once FileUtils::join(dirname(__FILE__), $name . '.php');
}
Example #13
0
<?php

/**
 * @package NimbleSupport
 * Loads in all support classes
 */
$dir = __DIR__;
require_once $dir . '/file_utils.php';
foreach (array('tag_helper', 'mime', 'string_cacher', 'asset_tag', 'cycler', 'form_helper') as $file) {
    require_once FileUtils::join($dir, $file . '.php');
}
Example #14
0
 private static function mailer_template($class, $method)
 {
     FileUtils::mkdir_p(FileUtils::join(NIMBLE_ROOT, 'app', 'view', strtolower(Inflector::underscore($class))));
     touch(FileUtils::join(NIMBLE_ROOT, 'app', 'view', strtolower(Inflector::underscore($class)), strtolower($method) . '.php'));
     touch(FileUtils::join(NIMBLE_ROOT, 'app', 'view', strtolower(Inflector::underscore($class)), strtolower($method) . '.txt'));
 }
Example #15
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));
 }
Example #16
0
 /**
  * Retrieve the help documentation.
  */
 public static function help()
 {
     return file_get_contents(FileUtils::join(static::$template_path, 'help.tmpl'));
 }
Example #17
0
 /**
  * Renders a partial template
  * @param string $name name of partial to load and render
  */
 public function render_partial($name)
 {
     $vars = get_object_vars($this);
     $partial = FileUtils::join($this->view_path, strtolower($this->class), $name);
     if (!file_exists($partial)) {
         $partial = $name;
     }
     ob_start();
     if (count($vars) > 0) {
         foreach ($vars as $key => $value) {
             if ($key == 'nimble') {
                 continue;
             }
             ${$key} = $value;
         }
     }
     require $partial;
     return ob_get_clean();
 }
Example #18
0
 /**
  * Require the requested plugins' init.php files into the program.
  * @param string $array The list of plugin directories.
  */
 public static function require_plugins($array)
 {
     $klass = self::getInstance();
     foreach ($array as $plugin) {
         if (array_key_exists('plugins_path', $klass->config)) {
             $file = FileUtils::join($klass->config['plugins_path'], $plugin, 'init.php');
             if (file_exists($file)) {
                 require_once $file;
                 continue;
             }
         }
         $file = FileUtils::join(dirname(__FILE__), '..', 'plugins', $plugin, 'init.php');
         require_once $file;
     }
 }
Example #19
0
 /**
  * Renders the email templates and stores the data in the $this->_content class variable
  *
  * @param string $name         name of function we are in, ie the template type
  */
 private function load_templates($name)
 {
     $class = get_class($this);
     $view_class_folder = strtolower(Inflector::underscore($class));
     $file_root = FileUtils::join($this->view_path, $view_class_folder, $name);
     $tp_html = $file_root . '.php';
     if (file_exists($tp_html)) {
         $this->prep_template($tp_html, 'html');
     }
     $tp_txt = $file_root . '.txt';
     if (file_exists($tp_txt)) {
         $this->prep_template($tp_txt, 'txt');
     }
     if (empty($this->_content)) {
         throw new NimbleException("No valid templates found at {$file_root}");
     }
 }
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);
session_start();
//load database connection
$database_info = json_decode(file_get_contents(FileUtils::join(NIMBLE_ROOT, 'config', NIMBLE_ENV, 'database.json')), true);
$database_info = $database_info[NIMBLE_ENV];
NimbleRecord::establish_connection($database_info);
/** boot the framework */
if (!defined('CLI_RUNNER')) {
    Run();
}
<?php

define("CLI_RUNNER", true);
require_once 'nimblize/nimble_support/lib/command_line_colors.php';
require_once 'nimblize/nimble_record/migrations/lib/migration_runner.php';
require_once 'nimblize/nimble_record/migrations/migration.php';
$nimble_root = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..';
require_once join(DIRECTORY_SEPARATOR, array($nimble_root, 'config', 'boot.php'));
MigrationRunner::$dir = FileUtils::join(NIMBLE_ROOT, 'db', 'migrations');
$storyhelper_path = FileUtils::join(NIMBLE_ROOT, 'lib', 'story_helper.php');
if (file_exists($storyhelper_path)) {
    require_once $storyhelper_path;
}
Example #22
-3
 public function __construct()
 {
     if (static::$enabled) {
         FileUtils::mkdir_p(FileUtils::join(FileUtils::join(NIMBLE_ROOT, 'log')));
         $this->log_file = FileUtils::join(NIMBLE_ROOT, 'log', NIMBLE_ENV . '.log');
     }
 }
 public static function create_package()
 {
     $user = User::find_by_username('bob');
     $file = FileUtils::join(NIMBLE_ROOT, 'test', 'data', 'bobs_other_package-0.0.1.tgz');
     $pp = Package::from_upload(array('file' => $file, 'user' => $user));
     $p = Package::update($pp->id, array('url' => 'http://jetviper21.com'));
 }
 public function testGetHelp()
 {
     $_SERVER['SERVER_NAME'] = 'bob.localhost.com';
     $dir = FileUtils::join(NIMBLE_ROOT, 'app', 'view', 'help', 'markdown');
     foreach (HelpController::get_markdown_files($dir) as $help) {
         $name = substr(basename($help), 0, -9);
         $this->get('show', array(), array('name' => $name));
         $this->responseIncludes(ucwords(Inflector::humanize($name)));
         $this->controller = new HelpController();
     }
 }