/** * Parse a string * @author Kelly Becker */ public function string($string) { /** * Include the slightly modified markdown class */ require_once __DIR__ . '/markdown.php'; // Trace it e\trace_enter("Parse Markdown String", htmlentities(substr($string, 0, 250) . "...")); /** * Transform the text */ $return = Markdown($string); // Trace it e\trace("Markdown Parsed", htmlentities($return)); // Step down a trace e\trace_exit(); return $return; }
public function __call($event, $args) { $method = '_on_' . $event; $objects = stack::methodObjects($method); /** * Allow configurable event handling */ $last = count($args) - 1; if (isset($args[$last]) && is_string($args[$last]) && substr($args[$last], 0, 6) === 'allow:') { $master = false; $file = substr($args[$last], 6); array_pop($args); } else { $master = true; $file = e\site . "/configure/master-events.yaml"; } if (empty($file)) { throw new Exception('Invalid or no file to control event handling'); } $ext = explode('.', $file); $ext = end($ext); $filename = basename($file); $conf = array(); if (is_file($file)) { switch ($ext) { case 'json': $current = e\decode_file($file); break; case 'yaml': if ($master) { if (self::$masterEvents === null) { self::$masterEvents = e::$yaml->load($file, true); } $current = self::$masterEvents; } else { $current = e::$yaml->load($file, true); } break; default: throw new Exception("Error with file `{$filename}` the extension `{$ext}` is not supported."); break; } if (!is_array($current)) { $current = array(); } if (isset($current[$event]) && is_array($current[$event])) { $conf = $current[$event]; } if (is_array($conf) && !empty($conf)) { /** * Sort into order specified in Yaml */ usort($objects, function ($class_a, $class_b) use($conf) { $conf = array_keys(array_reverse($conf)); $a = array_search(get_class($class_a), $conf); $b = array_search(get_class($class_b), $conf); return $a < $b ? 1 : -1; }); } } /** * Check if we need to add entries to the file */ $save = false; if ($master) { /** * Use master syntax structure */ if (!isset($current['events'])) { $current['events'] = array(); } if (!isset($current['events'][$event])) { $current['events'][$event] = 'enabled'; $save = true; } foreach ($objects as $obj) { $class = get_class($obj); if (!isset($current['handlers'][$class])) { $current['handlers'][$class] = 'enabled'; $save = true; } } if ($save = true) { self::$masterEvents = $current; } } else { /** * Use individual syntax */ foreach ($objects as $obj) { $class = get_class($obj); if (!isset($current[$event][$class])) { $current[$event][$class] = "enabled"; $save = true; } } } // Disable master save if ($master) { $save = false; } if ($save && isset($_GET['--debug'])) { switch ($ext) { case 'json': e\encode_file($file, $current); break; case 'yaml': e::$yaml->save($file, $current); break; default: throw new Exception("Error with file `{$filename}` the extension `{$ext}` is not supported."); break; } } e\trace_enter("Running Event <code class='alt'>{$event}</code>", '', $args, 9); $results = array(); if ($master) { /** * Check if the current event is regulated in master-events */ if ($current['events'][$event] !== 'enabled') { e\trace('Event <code class="alt2">' . $event . '</code> is disabled', "In file <code>{$file}</code>", null, 9); continue; } } /** * Sort by priority * @todo Cache most event functionality * @author Nate Ferrero */ $sortCategories = array('first' => array(), 'unsorted' => array(), 'last' => array()); $sortedObjects = array(); $sort = $method . '_order'; foreach ($objects as $obj) { if (property_exists($obj, $sort)) { $s = $obj->{$sort}; if (!isset($sortCategories[$s])) { throw new Exception("Invalid event sort order `{$s}`"); } $sortCategories[$s][] = $obj; } else { $sortCategories['unsorted'][] = $obj; } } /** * Debug */ if (isset($_GET['--events-event']) && $_GET['--events-event'] == $event) { dump($sortCategories); } /** * Run all events * @author Nate Ferrero */ foreach ($sortCategories as $category => $objs) { foreach ($objs as $obj) { $class = get_class($obj); if ($master) { /** * Check if the current handler is enabled in master-events */ if ($current['handlers'][$class] !== 'enabled') { e\trace('Event handler <code class="alt2">' . $class . '</code> is disabled', "In file <code>{$file}</code>", null, 9); continue; } } /** * Check if the current event is regulated */ if (isset($current) && isset($current[$event])) { if (!isset($current[$event][$class]) || $current[$event][$class] !== "enabled") { e\trace('Event handler <code class="alt2">' . $class . '</code> is disabled', "In file <code>{$file}</code>", null, 9); continue; } } e\trace_enter('Object <code class="alt2">' . $class . '</code> handling event', '', null, 9); try { $results[$class] = call_user_func_array(array($obj, $method), $args); e\trace_exit(); } catch (Exception $e) { if ($e->getCode() != 401) { e\trace_exception($e); /** * Trace_exit needs to be here twice, not a typo */ e\trace_exit(); e\trace_exit(); throw $e; } else { e\trace('Skipped event.', null, 9); e\trace_exit(); } } } } e\trace_exit(); return $results; }
public function route_bundle_api($bundle, $path) { $version = array_shift($path); $type = array_shift($path); if ($type !== 'json') { throw new Exception("API format `{$type}` is not a valid type"); } else { if (!isset($_GET['--debug'])) { header("Content-type: application/json"); } } e\trace(__CLASS__, "API `{$type}` access for bundle `{$bundle}`"); /** * Wrap any exceptions */ try { if (strlen($bundle) === 0) { throw new Exception("No bundle specified for routing after API access `@`"); } $class = "Bundles\\{$bundle}\\api\\{$version}"; $result = new $class($path); e\trace(__CLASS__, "Processing API access with `" . get_class($result) . "`"); foreach ($path as $segment) { /** * Null */ if (is_null($result)) { break; } /** * Handle String access */ if (is_string($result)) { $subs = explode(',', $segment); $temp = ''; foreach ($subs as $sub) { $sub = explode('-', $sub); if (count($sub) == 1) { $sub[] = $sub[0]; } $temp .= substr($result, $sub[0], $sub[1] - $sub[0] + 1); } $result = $temp; } else { if (is_array($result)) { if (isset($result[$result])) { $result = $result[$result]; } else { $result = null; } } else { if (is_object($result)) { if (isset($result->{$segment})) { $result = $result->{$segment}; } else { if (method_exists($result, $segment)) { $result = $result->{$segment}(); } else { $result = null; } } } } } } /** * API output */ switch ($type) { case 'plain': echo $result; break; case 'json': if (method_exists($result, '__toAPI')) { $result = $result->__toAPI(); } echo json_encode($result); break; } } catch (Exception $exception) { e::$events->exception($exception); if (isset($_GET['--debug'])) { throw $exception; } /** * Format exception for API */ switch ($type) { case 'plain': throw $exception; case 'json': echo json_encode(array('exception' => $exception->getMessage())); break; default: throw $exception; } } if (!isset($_GET['--debug'])) { e\disable_trace(); } e\complete(); }
public static function load() { // Check for file if (!is_file(self::$file) && !e::$yaml->save(self::$file, array())) { throw new Exception("No environment file at `" . self::$file . "`"); } // Trace environment load e\trace("Loading environment config."); // Load environment file $tmp = e::$yaml->file(self::$file); foreach ($tmp as $key => $value) { self::$environment[strtolower($key)] = $value; } // Load Environment Custom $results = e::$events->environmentLoad(self::$environment); foreach ($results as $result) { foreach ($result as $key => $value) { self::$environment[strtolower($key)] = $value; } } }
$stack = debug_backtrace(); echo "Stack:\n\n"; array_shift($stack); if (defined('DUMP_SINGLE_VAR')) { array_shift($stack); } echo dumpVarText(null, $stack); e\disable_trace(); e\complete(); } /** * Ensure proper content type * @author Kelly Becker */ header("Content-Type: text/html"); e\trace('Debug Dump'); /** * Helper functions */ function dumpVars(&$out) { list($void, $file, $line) = $out; if (defined('DUMP_SINGLE_VAR')) { $backtrace = debug_backtrace(); $backtrace = $backtrace[3]; extract($backtrace); } $code = file($file); $start = max(1, $line - 4); $vrx = '/(\\$)([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)/'; $out = '<div class="section"><p><span class="line">Lines ' . $start . ' – ' . $line . '</span>
/** * Save a value to memory and the cache file. * * @param string $library * @param string $key * @param string $value * @return boolean * @author David D. Boskovic */ public function store($library, $key, $value, $encrypt = false) { e\trace('Cache', "Storing `{$key}` in `{$library}`"); # make sure the current library values are loaded $this->check($library, $key); $value = serialize($value); switch ($encrypt) { default: # get base64string $save_value = wordwrap(base64_encode($value), 120, "\n", true); break; } $this->cache[$library][$key] = $value; return $this->write($library, $key, $save_value); }