55 private static $scanLog =
"";
63 if (!ComponentManager::$scanLog)
65 ComponentManager::$scanLog =
$config[
'uploadbase'].DIRECTORY_SEPARATOR.
"component_scan_".date(
"Ymd-His").
".log";
68 error_log(
$message.
"\n", 3, ComponentManager::$scanLog);
94 $path =
$root . DIRECTORY_SEPARATOR . str_replace(
"/", DIRECTORY_SEPARATOR, $subdir);
100 $handle = opendir(
$path);
101 while(
false !== (
$file = readdir($handle)))
104 $m =
$f . DIRECTORY_SEPARATOR .
"manifest.inc";
105 $d =
$f . DIRECTORY_SEPARATOR .
"DEPRECATED";
113 Cache::invalidate(
"fakoli_includes_$file");
117 if ($this->found[
$file])
138 $component = $manifest->getComponentDefinition();
154 Cache::invalidate(
"fakoli_includes_$file");
170 $admin =
$component->component_path . DIRECTORY_SEPARATOR .
"admin";
172 if (!is_dir($admin))
return;
176 $handle = opendir($admin);
178 while(
false !== (
$file = readdir($handle)))
180 if (endsWith(
$file,
".inc"))
183 $page->identifier = preg_replace(
"/\\.inc$/",
"",
$file);
184 $page->server_path = $admin . DIRECTORY_SEPARATOR .
$file;
186 $page->joinTransaction($this->tx);
188 Cache::invalidate(
"fakoli_admin_pages_{$page->identifier}");
202 if (!is_dir(
$pages))
return;
205 $handle = opendir(
$pages);
207 while(
false !== (
$file = readdir($handle)))
209 if (endsWith(
$file,
".inc"))
219 $page->scanned =
true;
221 $page->filter =
new InclusionFilter(
"component_page_id",
"server_path",
"scanned");
224 catch(DataNotFoundException $e)
232 $page->enabled =
true;
233 $page->scanned =
true;
253 $this->tx =
new DataTransaction();
259 $c->joinTransaction($this->tx);
264 $p->joinTransaction($this->tx);
268 $cp->joinTransaction($this->tx);
269 $cp->updateExplicit(
"SET scanned=0");
271 $path .=
$config[
'homedir'] . PATH_SEPARATOR . ini_get(
"include_path");
275 $roots = explode(PATH_SEPARATOR,
$path);
277 foreach($roots as
$root)
279 if (
$root ==
".")
continue;
286 Cache::invalidate(
"fakoli_components");
287 Cache::invalidate(
"fakoli_admin_menu");
288 Cache::invalidate(
"fakoli_admin_icons");
289 Cache::invalidate(
"fakoli_scripts");
290 Cache::invalidate(
"fakoli_styles");
291 Cache::invalidate(
"fakoli_event_map");
293 $cp->delete(
"WHERE scanned=0");
312 $this->tx->rollback();
319 echo $e->__toString();
337 $path .=
$config[
'homedir'] . PATH_SEPARATOR . ini_get(
"include_path");
341 $roots = explode(PATH_SEPARATOR,
$path);
343 foreach($roots as
$root)
345 if (
$root ==
".")
continue;
347 $path =
$root . DIRECTORY_SEPARATOR .
"cms" . DIRECTORY_SEPARATOR .
"components" . DIRECTORY_SEPARATOR .
$name;
349 if (file_exists(
$path))
351 if (!file_exists(
$path.DIRECTORY_SEPARATOR.
"DEPRECATED"))
return $path;
354 $path =
$root . DIRECTORY_SEPARATOR .
"components" . DIRECTORY_SEPARATOR .
$name;
356 if (file_exists(
$path))
358 if (!file_exists(
$path.DIRECTORY_SEPARATOR.
"DEPRECATED"))
return $path;
376 throw new FakoliException(
"Unrecognized or disabled component '$component'");
388 $eventMap = Cache::get(
"fakoli_event_map");
400 if (!$manifest || !method_exists($manifest, subscribeToEvents))
continue;
420 Cache::put(
"fakoli_event_map",
$eventMap);
432 return $item1[
"priority"] - $item2[
"priority"];
444 trace(
"** Firing event '$event'", 4);
450 trace(
"No handlers subscribed to '$event'", 4);
460 if (is_array($subscription[
"handler"]))
462 trace(
"Handling $event with {$subscription["handler
"][0]}::{$subscription["handler
"][1]}", 4);
466 trace(
"Handling $event with {$subscription["handler
"]}", 4);
469 if (!is_callable($subscription[
"handler"]))
471 if (is_array($subscription[
"handler"]))
473 trace(
"Subscription handler {$subscription["handler
"][0]}::{$subscription["handler
"][1]} for $event is invalid", 2);
477 trace(
"Subscription handler $event with {$subscription["handler
"]} for $event is invalid", 2);
480 trace(printIncludes(
false,
true), 3);
484 $parameter = call_user_func_array($subscription[
"handler"], array($parameter, &$continue));
486 if (!$continue)
break;
489 if ($mustBeConsumed && $continue)
506 trace(
"** Firing event '$event' to $component", 4);
512 trace(
"No handlers subscribed to '$event'", 4);
523 if (is_array($subscription[
"handler"]))
525 trace(
"Handling $event with {$subscription["handler
"][0]}::{$subscription["handler
"][1]}", 4);
529 trace(
"Handling $event with {$subscription["handler
"]}", 4);
532 $parameter = call_user_func_array($subscription[
"handler"], array($parameter, &$continue));
554 if (!preg_match(
"/^[\\w\\d_\\.]+$/",
$action))
563 $this->dispatchActionInternal(
$process);
565 $out = ob_get_contents();
576 private function dispatchActionInternal(
$process =
null)
585 trace(
"ComponentManager::dispatchAction action: $action", 3);
589 if (!preg_match(
"/^[\\w\\d_\\.]+$/",
$action))
596 if (!isset(
$user) && !
$process && (!$manifest->allow_sessionless_handlers ||
597 (is_array($manifest->allow_sessionless_handlers) && array_search(
$action, $manifest->allow_sessionless_handlers) === FALSE)))
603 trace(
"ComponentManager::dispatchAction handler: $handler", 3);
618 echo $exit->getMessage();
633 trace(
"URI: $uri, Query String: $queryString", 3);
637 trace(
"Prefix: $prefix, Component: $component, Action: $action", 3);
639 if ($prefix !=
"action")
646 "_REQUEST" => $_REQUEST,
647 "_SERVER" => $_SERVER,
651 parse_str($queryString, $_GET);
655 $_SERVER[
"REQUEST_URI"] =
$uri;
667 $this->dispatchActionInternal(
$process);
671 trace($e->getMessage(), 3);
672 echo $e->getMessage();
680 foreach($context as
$name => $value)
699 $page_template = (preg_match(
"/tpl$/",
$page->template)) ?
$page->template :
"{$page->template}.tpl";
704 if (!checkRole(
$page->role))
710 echo $pageView->drawView();
714 catch(DataNotFoundException $e)
744 ->bind(
":component_name", $component_name)
756 if($latest_version && $latest_version !=
$component->version)
759 $component->filter =
new InclusionFilter(
"version");
768 $mgr->upgrade($version);
774 $tabs = array(
"Components" =>
"/admin/components",
775 "Component Pages" =>
"/admin/component_pages"
778 $bar =
new TabBar(
"tabs",
$tabs,
"");
779 $bar->useQueryString =
false;
786 $tabs = array(
"Definition" =>
"/admin/component_page_form",
787 "Modules" =>
"/admin/component_page_modules");
789 $qs = ($key) ?
"component_page_id=$key" :
"";
790 $bar =
new TabBar(
"tabs",
$tabs,
$qs);
797 $tabs = array(
"Definition" =>
"/admin/component_form",
798 "Component Pages" =>
"/admin/component_pages",
799 "Version History" =>
"/admin/component_versions"
802 $qs = ($key) ?
"component_id=$key" :
"";
803 $bar =
new TabBar(
"tabs",
$tabs,
$qs);
810 trace(
"ComponentManager::setDefaults", 3);
813 $defaultPath =
$config[
'uploadbase'] . DIRECTORY_SEPARATOR .
"upgrade_output_path";
814 if (!file_exists($defaultPath)) mkdir($defaultPath);
817 Settings::setDefaultValue(
"settings",
"enable_inline_editing",
false,
"Boolean",
"Turns on or off inline editing capabilities (for those components that support this option)",
"General");
ComponentManager provides the core functionality for building the component map describing the applic...
static displayPage($identifier, &$continue)
scan($verbosity=0)
Scans the application home directory and PHP include path and builds the component and administration...
static componentPageTabs($key)
static $verbosityLevel
Verbosity level for component scan (same as trace level)
static deleteRole($del_role)
dispatchAction($process=null)
Dispatch an incoming user action to the appropriate component handler script.
static fireEvent($event, $parameter=null, $mustBeConsumed=false)
Fire an event to all subscribers as detailed in their manifests.
static getEventHandlers()
Retrieve the event handler map.
static upgradeComponent($version)
scanAdminPages($component)
Builds the administration page map for the specified component.
dispatchLocalAction($action, $process=null)
static getComponentSignature()
Retrieves a unique signature for the application's enabled components, based on their installed versi...
static compareByPriority($item1, $item2)
Priority comparison callback - not for external use.
static componentFormTabs($key)
static scanTrace($message, $level)
getComponent($component)
Retrieve the component definition record for the specified component.
static setComponentVersion($component_name)
static findComponentPath($name)
Locate the component path for the named component using the standard precedence rules.
static enumerateComponentPages($items)
ComponentManager()
Creates a new ComponentManager object.
static $plainOutput
Set to true for plain text output during component scan.
scanComponents($root, $subdir)
Scan the specified root and sub-directory for components.
scanComponentPages($component)
Scan and build the compoment page map for the specified component.
static componentListTabs()
static fireEventTo($event, $component, $parameter=null)
Fire an event to the specificed component.
static findByIdentifier($identifier, $constraint="")
ComponentPageView generates the page content for a component page, substituting page fields,...
static getLatestVersion($component)
FakoliEarlyExit is an internal exception class used to provide for controlled early exits during page...
FakoliEventNotConsumed is thrown when no subscriber has handled an event that was fired with $mustBeC...
FakoliException is the base exception class for all Fakoli errors.
static coreTraceLevel()
Change to the configured trace level for Fakoli core code.
static getComponents()
Retrieve an array of all the currently enabled components, indexed by component name.
static applicationTraceLevel()
Change to the configured trace level for application code.
static using()
Import the datamodels, views and manifest for the specified component(s).
static getComponentClassRoot($name)
Retrieves the capitalized camlCase name for the specified component.
static $scanning
Semaphore indicating that a component scan is in progress.
static storeRedirectPage()
Store the page from which a user has been redirected when prompted to login or create an account.
static deleteRoleFromString(&$items, $del_role, $field="")
static setDefaultValue($component, $name, $value, $field_type="String", $annotation="", $category="", $options="", $weight=0)
Sets the default value of the given component setting.
static setDefaultPermission($component, $name, $annotation, $value, $weight=0)
Set a default Permission value indicating which SiteRoles have the given permission.
if(!checkRole("admin") && $_SERVER["REMOTE_ADDR"] !=$_SERVER["SERVER_ADDR"] && $_SERVER["REMOTE_ADDR"] !=gethostbyname($config['http_host']) && $_SERVER["REMOTE_ADDR"] !="127.0.0.1") if($_SERVER["REMOTE_ADDR"]=="127.0.0.1" &&array_key_exists("clear", $_GET)) $verbosity
$method
Pull out a simple reference to the request method.
if($config["default_content_type"]) $isAction
if(!checkRole("admin")) $c
if(!checkRole($library->allow_access) &&! $library->allowAccess()) if(!checkRole($document->allow_access)) $d