isPluginEnabled( $module ))
{
throw new Exception_PluginDeactivated($module);
}
$controllerClassName = "Piwik_".$module."_Controller";
if(!class_exists($controllerClassName))
{
$moduleController = "plugins/" . $module . "/Controller.php";
if( !Zend_Loader::isReadable($moduleController))
{
throw new Exception("Module controller $moduleController not found!");
}
require_once $moduleController;
}
$controller = new $controllerClassName;
if($action === false)
{
$action = $controller->getDefaultAction();
}
if( !is_callable(array($controller, $action)))
{
throw new Exception("Action $action not found in the controller $controllerClassName.");
}
try {
return call_user_func_array( array($controller, $action ), $parameters);
} catch(Piwik_Access_NoAccessException $e) {
Piwik_PostEvent('FrontController.NoAccessException', $e);
}
}
/**
* Often plugins controller display stuff using echo/print.
* Using this function instead of dispath() returns the output form the actions calls.
*
* @param string $controllerName
* @param string $actionName
* @param array $parameters
* @return string
*/
function fetchDispatch( $controllerName = null, $actionName = null, $parameters = null)
{
ob_start();
$output = $this->dispatch( $controllerName, $actionName, $parameters);
// if nothing returned we try to load something that was printed on the screen
if(empty($output))
{
$output = ob_get_contents();
}
ob_end_clean();
return $output;
}
/**
* Called at the end of the page generation
*
*/
function __destruct()
{
try {
Piwik::printSqlProfilingReportZend();
Piwik::printQueryCount();
} catch(Exception $e) {}
// Piwik::printMemoryUsage();
// Piwik::printTimer();
// Piwik::uninstall();
}
/**
* Checks that the directories Piwik needs write access are actually writable
* Displays a nice error page if permissions are missing on some directories
*
* @return void
*/
protected function checkDirectoriesWritableOrDie()
{
$resultCheck = Piwik::checkDirectoriesWritable( );
if( array_search(false, $resultCheck) !== false )
{
$directoryList = '';
foreach($resultCheck as $dir => $bool)
{
$dir = realpath($dir);
if(!empty($dir) && $bool === false)
{
$directoryList .= "chmod 777 $dir
";
}
}
$directoryList .= '';
$directoryMessage = "
Piwik couldn't write to some directories.
Try to Execute the following commands on your Linux server:
"; $directoryMessage .= $directoryList; $directoryMessage .= "If this doesn't work, you can try to create the directories with your FTP software, and set the CHMOD to 777 (with your FTP software, right click on the directories, permissions)."; $directoryMessage .= "
After applying the modifications, you can refresh the page."; $directoryMessage .= "
If you need more help, try Piwik.org."; $html = '
'.$directoryMessage.'
'; print($html); exit; } } /** * Must be called before dispatch() * - checks that directories are writable, * - loads the configuration file, * - loads the plugin, * - inits the DB connection, * - etc. * * @return void */ function init() { Zend_Registry::set('timer', new Piwik_Timer); $this->checkDirectoriesWritableOrDie(); $this->assignCliParametersToRequest(); $exceptionToThrow = false; //move into a init() method try { Piwik::createConfigObject(); } catch(Exception $e) { Piwik_PostEvent('FrontController.NoConfigurationFile', $e); $exceptionToThrow = $e; } Piwik::loadPlugins(); if($exceptionToThrow) { throw $exceptionToThrow; } // database object Piwik::createDatabaseObject(); // Create the log objects Piwik::createLogObject(); Piwik::terminateLoadPlugins(); Piwik::install(); // Piwik::printMemoryUsage('Start program'); // can be used for debug purpose $doNotDrop = array( Piwik::prefixTable('access'), Piwik::prefixTable('user'), Piwik::prefixTable('site'), Piwik::prefixTable('archive'), Piwik::prefixTable('logger_api_call'), Piwik::prefixTable('logger_error'), Piwik::prefixTable('logger_exception'), Piwik::prefixTable('logger_message'), Piwik::prefixTable('log_visit'), Piwik::prefixTable('log_link_visit_action'), Piwik::prefixTable('log_action'), Piwik::prefixTable('log_profiling'), ); // Setup the auth object Piwik_PostEvent('FrontController.authSetCredentials'); try { $authAdapter = Zend_Registry::get('auth'); } catch(Exception $e){ throw new Exception("Object 'auth' cannot be found in the Registry. Maybe the Login plugin is not enabled?Plugins[] = Login
[Plugins]
section in your config/config.inc.php");
}
// Perform the authentication query, saving the result
$access = new Piwik_Access($authAdapter);
Zend_Registry::set('access', $access);
Zend_Registry::get('access')->loadAccess();
}
/**
* Assign CLI parameters as if they were REQUEST or GET parameters.
* You can trigger Piwik from the command line by
* # /usr/bin/php5 /path/to/piwik/index.php -- "module=API&method=Actions.getActions&idSite=1&period=day&date=previous8&format=php"
*
* @return void
*/
protected function assignCliParametersToRequest()
{
if(isset($_SERVER['argc'])
&& $_SERVER['argc'] > 0)
{
for ($i=1; $i < $_SERVER['argc']; $i++)
{
parse_str($_SERVER['argv'][$i],$tmp);
$_REQUEST = array_merge($_REQUEST, $tmp);
$_GET = array_merge($_GET, $tmp);
}
}
}
}
/**
* Exception thrown when the requested plugin is not activated in the config file
*
* @package Piwik
*/
// TODO organize exceptions
class Exception_PluginDeactivated extends Exception
{
function __construct($module)
{
parent::__construct("The plugin '$module' is not enabled. You can activate the plugin on the Plugins admin page.");
}
}