Example #1
0
 public function page()
 {
     self::$bundles = e::configure('manage')->bundle;
     $out = '<div style="padding: 30px;">';
     foreach (self::$bundles as $namespace => $link) {
         try {
             if (strlen($namespace) < 3) {
                 throw new Exception("Invalid namespace `{$namespace}` for manage page `{$link}`");
             }
             $class = "{$namespace}\\Manage";
             $manage = new $class();
             $tile = $manage->tile();
             if (is_null($tile)) {
                 continue;
             }
             if (!$tile instanceof Tile) {
                 throw new Exception("Bundle manager `{$class}` tile is not a valid Tile class");
             }
             $tiles[$manage->title] = $tile->output($manage->title);
         } catch (Exception $e) {
             e\trace_exception($e);
             $tile = $this->tile($e->getMessage());
             $tiles[$link] = $tile->output($link);
         }
     }
     ksort($tiles);
     foreach ($tiles as $tile) {
         $out .= $tile;
     }
     $out .= '</div>';
     return $out;
 }
Example #2
0
 public function _on_framework_security()
 {
     // Add manager
     e::configure('manage')->activeAddKey('bundle', __NAMESPACE__, 'security');
     $developer = false;
     // Check cookie login
     if (isset($_COOKIE['e-developer'])) {
         // Check cookie data
         $cookie = explode('_', $_COOKIE['e-developer'], 2);
         $name = $cookie[0];
         // Use key to encrypt cookie
         $keys = e::configure('developers');
         if (!isset($keys->{$name})) {
             throw new Exception("Invalid developer access username in cookie");
         }
         $key = $keys->{$name};
         $check = $this->genCookieSegment($name, $key);
         if ($check === $cookie[1]) {
             $developer = true;
         }
     }
     // Check file based access
     $file = realpath(e\root . "/../.e-developer");
     if ($file) {
         $cookie = explode('_', file_get_contents($file), 2);
         $name = $cookie[0];
         // Use key to encrypt cookie
         $keys = e::configure('developers');
         if (!isset($keys->{$name})) {
             throw new Exception("Invalid developer access username in file");
         }
         $key = $keys->{$name};
         $check = $this->genCookieSegment($name, $key);
         if ($check === $cookie[1]) {
             $developer = true;
         }
     }
     // Check credentials if not logged in
     if (!$developer) {
         $key = $this->getPOSTKey();
         if (!is_null($key)) {
             // Get the account name
             $name = $key[0];
             // Load the encoded version of the key
             $key = $this->validateCredentials($key);
             // Compare it to existing keys
             $keys = e::configure('developers');
             if ($keys->{$name} === $key) {
                 // Set the cookie
                 setcookie('e-developer', $name . '_' . $this->genCookieSegment($name, $key));
                 // Redirect to prevent pages that use postdata from accessing the credentials
                 e\Redirect($_SERVER['REQUEST_URI']);
             } else {
                 $this->page('access', 'You entered incorrect credentials');
             }
         }
     }
     $this->developer = $developer;
 }
Example #3
0
 /**
  * Require dev mode before page load
  */
 public function _on_framework_loaded()
 {
     /**
      * Add to manager
      */
     e::configure('manage')->activeAddKey('bundle', __NAMESPACE__, 'environment');
     /**
      * Check dev mode to avoid issues later
      */
     e::$environment->requireVar('Development.Master', 'yes | no');
     e::$environment->requireVar('Development.Trace', 'yes | no');
 }
Example #4
0
 public function __initBundle()
 {
     /**
      * Set $_GET and $_POST to hooks
      */
     e::configure('lhtml')->activeAddKey('hook', ':get', array('--reference' => &$_GET));
     e::configure('lhtml')->activeAddKey('hook', ':post', array('--reference' => &$_POST));
     $url = $_SERVER['REDIRECT_URL'];
     /**
      * Router bundle access
      */
     if (substr($url, 0, 2) == '/@') {
         $this->__routeBundle($url);
     }
 }
Example #5
0
 public function __routeBundle($path)
 {
     /**
      * Security access for development
      */
     e::$security->developerAccess("EvolutionSDK Management Center");
     // Get name
     $name = array_shift($path);
     // Site sandbox TODO MOVE THIS SOMEWHERE ELSE?
     if ($name == 'sandbox') {
         $path = implode('/', $path);
         if ($path === '') {
             $path = 'index';
         }
         $file = e\site . '/sandbox/' . $path . '.php';
         $dir = dirname($file);
         if (!is_dir($dir)) {
             throw new Exception("Sandbox directory `{$dir}` does not exist");
         }
         chdir($dir);
         echo '<style>body {margin: 0; padding: 0; font-family: Tahoma, Lucida Grande, Sans, sans-serif;}</style>';
         echo '<div style="padding: 1em; background: black; box-shadow: 0 0 4px #000; color: #fff;"><b>Sandbox File </b>';
         echo '<pre style="display: inline">' . $file . '</pre></div>';
         require_once $file;
         e\complete();
     }
     if ($name === 'manage') {
         e\redirect('/@manage');
     }
     if ($name === '' || is_null($name)) {
         $name = 'manage';
     }
     $bundles = e::configure('manage')->bundle;
     $ns = array_search($name, $bundles);
     if ($ns === false) {
         throw new Exception("No manage panel for `{$name}`");
     }
     $class = $ns . '\\Manage';
     $panel = new $class();
     $title = "EvolutionSDK&trade; &rarr; " . $panel->title;
     $css = file_get_contents(__DIR__ . '/../debug/theme.css') . self::style();
     $header = '<span>EvolutionSDK</span> &rarr; <a href="/@manage">Manage System</a>' . ($name !== 'manage' ? " &rarr; <span>" . $panel->title . "</span>" : '');
     echo "<!doctype html><html><head><title>{$title}</title><style>{$css}</style></head><body class='_e_dump'><h1>{$header}</h1><div class='manage-page'>";
     echo $panel->page($path);
     echo "</div></body></html>";
     e\complete();
 }
Example #6
0
 public function _on_framework_loaded()
 {
     // Add manager
     e::configure('manage')->activeAddKey('bundle', __NAMESPACE__, 'unit');
 }
Example #7
0
/**
 * This is the main autoloader
 * @author Nate Ferrero
 */
function load($class)
{
    /* DEBUG * /
    	echo "<p>Autoload $class</p>";
    	/* END DEBUG */
    /**
     * Special autoload overrides
     * @author Nate Ferrero
     */
    if (stack::$loaded) {
        $raw = e::configure('autoload', false)->activeGet('special');
        if (!is_null($raw)) {
            $special = array();
            foreach ($raw as $key => $value) {
                $special[strtolower($key)] = $value;
            }
            $class = strtolower($class);
            if (isset($special[$class])) {
                require_once $special[$class];
                return true;
            }
        }
    }
    $path = explode('\\', strtolower($class));
    if ($path[0] == '') {
        array_shift($path);
    }
    $ns = $path;
    array_pop($ns);
    $ns = implode('/', $ns);
    $a = array_shift($path);
    $b = array_shift($path);
    if (count($path)) {
        $base = $path[count($path) - 1];
    } else {
        $base = '';
    }
    $c = implode('/', $path);
    if (empty($c)) {
        return false;
        /**
         * Cant't do this for compatibility with 3rd party code (maybe can check for invalid class bundles\\something)
         * throw new Exception("The class `$class` does not follow the expected autoload format `bundles\\<i>bundle-name</i>\\<i>some-class</i>`");
         */
    }
    if ($base === 'e') {
        throw new Exception("You need to put `use e;` at the top of your PHP file with namespace `{$ns}`.");
    }
    if (strtolower($base) === 'exception') {
        throw new AutoLoadException("You need to put `use Exception;` at the top of your PHP file with namespace `{$ns}`.");
    }
    /**
     * Handle reserved names in classes by allowing _className
     * @author Nate Ferrero
     * @author Kelly Becker
     */
    if ($base[0] === '_') {
        $base = substr($base, 1);
        array_pop($path);
        array_push($path, $base);
        $c = implode('/', $path);
    }
    /**
     * Added Phar Format
     * @author Kelly Becker
     */
    $files = array("{$a}/{$b}/{$c}.php", "{$a}/{$b}/library/{$c}.php", "{$a}/{$b}.phar/{$c}.php", "{$a}/{$b}.phar/library/{$c}.php");
    $bfiles = array("{$b}/{$c}.php", "{$b}/library/{$c}.php", "{$b}.phar/{$c}.php", "{$b}.phar/library/{$c}.php");
    $site = e\site;
    $dirs = array(root, $site);
    /**
     * Allow the addition of more dirs to scan inside
     * (Useful for portals within bundles ETC...)
     * @author Kelly Becker
     */
    if (stack::$loaded) {
        $dirs = array_merge($dirs, (array) e::configure('autoload')->dirs);
    }
    /**
     * Special handling for bundle files
     * @author Nate Ferrero
     */
    if (strtolower($a) === 'bundles') {
        /**
         * Get bundle libraries
         * ====================
         *    04 - 06 - 2012
         * ====================
         * @author Kelly Becker
         */
        $constants = get_defined_constants(true);
        $EBL = array_filter(array_flip($constants['user']), function ($key) {
            if (strpos($key, 'EvolutionBundleLibrary') === false) {
                return false;
            } else {
                return true;
            }
        });
        foreach (array_flip($EBL) as $EBLD) {
            $dirs[] = '@' . $EBLD;
        }
        if (isset(stack::$bundlePreferences[$b])) {
            if (stack::$bundlePreferences[$b] == 'off') {
                throw new Exception("Trying to rely on a bundle that has been turned off in `{$site}/configure/bundles.txt`");
            } else {
                if (stack::$bundlePreferences[$b] == 'core') {
                    $dirs = array(root);
                } else {
                    if (stack::$bundlePreferences[$b] == 'site') {
                        $dirs = array($site);
                    }
                }
            }
        }
        /**
         * Check for bundle extension folders
         * @author Nate Ferrero
         */
        $extensions = extend($b);
        if (is_array($extensions)) {
            foreach ($extensions as $extension) {
                array_unshift($dirs, '@' . $extension);
            }
        }
    }
    foreach ($dirs as $dir) {
        /**
         * "@/some/directory" means that the bundles folder is that directory, rather than looking for a 
         * /bundles directory within that directory
         * @author Nate Ferrero
         */
        if ($dir[0] === '@') {
            $xfiles = $bfiles;
            $dir = substr($dir, 1);
        } else {
            $xfiles = $files;
        }
        /**
         * Search for specified files
         */
        foreach ($xfiles as $pattern) {
            $pattern = "{$dir}/" . strtolower($pattern);
            /* DEBUG * /
            			echo "<p>Class <code>$class</code> could be in <code>$pattern</code></p>";
            			/* END */
            if (file_exists($pattern)) {
                require_once $pattern;
                /* DEBUG * /
                			echo "<p>It was!</p>";
                			/* END */
                return;
            } else {
                if (file_exists($pattern = 'phar://' . $pattern)) {
                    require_once $pattern;
                    /* DEBUG * /
                    			echo "<p>It was!</p>";
                    			/* END */
                    return;
                }
            }
        }
    }
    if (!class_exists($class, false)) {
        throw new AutoLoadException("Class `{$class}` not found" . (isset($file) ? " in file `{$file}`" : ''));
    }
}