add piwik installation

This commit is contained in:
coderkun 2014-04-25 03:56:02 +02:00
commit 8c5d4f0c31
3197 changed files with 563902 additions and 0 deletions

View file

@ -0,0 +1,87 @@
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\View;
/**
* Post-update view
*
* During a Piwik software update, there will be instances of old classes
* loaded in memory. This is problematic as we will start to instantiate
* new classes which may not be backward compatible. This class provides
* a clean bridge/transition by forcing a new request.
*
* This class needs to be self-contained, with no external dependencies.
*
*/
class OneClickDone
{
/**
* @var string
*/
private $tokenAuth;
/**
* @var string
*/
public $coreError;
/**
* @var array
*/
public $feedbackMessages;
public function __construct($tokenAuth)
{
$this->tokenAuth = $tokenAuth;
}
/**
* Outputs the data.
*
* @return string html
*/
public function render()
{
// set response headers
@header('Content-Type: text/html; charset=UTF-8');
@header('Pragma: ');
@header('Expires: ');
@header('Cache-Control: must-revalidate');
@header('X-Frame-Options: deny');
$error = htmlspecialchars($this->coreError, ENT_QUOTES, 'UTF-8');
$messages = htmlspecialchars(serialize($this->feedbackMessages), ENT_QUOTES, 'UTF-8');
$tokenAuth = $this->tokenAuth;
// use a heredoc instead of an external file
echo <<<END_OF_TEMPLATE
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<form name="myform" method="post" action="?module=CoreUpdater&amp;action=oneClickResults">
<input type="hidden" name="token_auth" value="$tokenAuth" />
<input type="hidden" name="error" value="$error" />
<input type="hidden" name="messages" value="$messages" />
<noscript>
<button type="submit">Continue</button>
</noscript>
</form>
<script type="text/javascript">
document.myform.submit();
</script>
</body>
</html>
END_OF_TEMPLATE;
}
}

View file

@ -0,0 +1,83 @@
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\View;
use Twig_Token;
use Twig_TokenParser;
use Twig_Node_Expression_MethodCall;
use Twig_Node_Expression_Array;
use Twig_Node_Include;
use Exception;
/**
* Defines a new Twig tag that will render a Piwik View.
*
* Use the tag like this:
*
* {% render theView %}
*
* where `theView` is a variable referencing a View instance.
*/
class RenderTokenParser extends Twig_TokenParser
{
/**
* Parses the Twig stream and creates a Twig_Node_Include instance that includes
* the View's template.
*
* @return Twig_Node_Include
*/
public function parse(Twig_Token $token)
{
$parser = $this->parser;
$stream = $parser->getStream();
$view = $parser->getExpressionParser()->parseExpression();
$variablesOverride = new Twig_Node_Expression_Array(array(), $token->getLine());
if ($stream->test(Twig_Token::NAME_TYPE, 'with')) {
$stream->next();
$variablesOverride->addElement($this->parser->getExpressionParser()->parseExpression());
}
$stream->expect(Twig_Token::BLOCK_END_TYPE);
$viewTemplateExpr = new Twig_Node_Expression_MethodCall(
$view,
'getTemplateFile',
new Twig_Node_Expression_Array(array(), $token->getLine()),
$token->getLine()
);
$variablesExpr = new Twig_Node_Expression_MethodCall(
$view,
'getTemplateVars',
$variablesOverride,
$token->getLine()
);
return new Twig_Node_Include(
$viewTemplateExpr,
$variablesExpr,
$only = false,
$ignoreMissing = false,
$token->getLine()
);
}
/**
* Returns the tag identifier.
*
* @return string
*/
public function getTag()
{
return 'render';
}
}

View file

@ -0,0 +1,129 @@
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\View;
use Piwik\FrontController;
use Piwik\Piwik;
use Piwik\Url;
use Piwik\View;
/**
* A facade that makes it easier to use the '_reportsByDimension.twig' template.
*
* This view will output HTML that displays a list of report names by category and
* loads them by AJAX when clicked. The loaded report is displayed to the right
* of the report listing.
*/
class ReportsByDimension extends View
{
/**
* Constructor.
*
* @param string $id
*/
public function __construct($id)
{
parent::__construct('@CoreHome/ReportsByDimension/_reportsByDimension');
$this->dimensionCategories = array();
$this->id = $id;
}
/**
* Adds a report to the list of reports to display.
*
* @param string $category The report's category. Can be a i18n token.
* @param string $title The report's title. Can be a i18n token.
* @param string $action The controller action used to load the report, ie, Referrers.getAll
* @param array $params The list of query parameters to use when loading the report.
* This list overrides query parameters currently in use. For example,
* array('idSite' => 2, 'viewDataTable' => 'goalsTable')
* would mean the goals report for site w/ ID=2 will always be loaded.
*/
public function addReport($category, $title, $action, $params = array())
{
list($module, $action) = explode('.', $action);
$params = array('module' => $module, 'action' => $action) + $params;
$categories = $this->dimensionCategories;
$categories[$category][] = array(
'title' => $title,
'params' => $params,
'url' => Url::getCurrentQueryStringWithParametersModified($params)
);
$this->dimensionCategories = $categories;
}
/**
* Adds a set of reports to the list of reports to display.
*
* @param array $reports An array containing report information. The array requires
* the 'category', 'title', 'action' and 'params' elements.
* For information on what they should contain, @see addReport.
*/
public function addReports($reports)
{
foreach ($reports as $report) {
$this->addReport($report['category'], $report['title'], $report['action'], $report['params']);
}
}
/**
* @return string The ID specified in the constructor, usually the plugin name
*/
public function getId()
{
return $this->id;
}
/**
* Renders this view.
*
* @return string The rendered view.
*/
public function render()
{
/**
* Triggered before rendering {@link ReportsByDimension} views.
*
* Plugins can use this event to configure {@link ReportsByDimension} instances by
* adding or removing reports to display.
*
* @param ReportsByDimension $this The view instance.
*/
Piwik::postEvent('View.ReportsByDimension.render', array($this));
$this->firstReport = "";
// if there are reports & report categories added, render the first one so we can
// display it initially
$categories = $this->dimensionCategories;
if (!empty($categories)) {
$firstCategory = reset($categories);
$firstReportInfo = reset($firstCategory);
$oldGet = $_GET;
$oldPost = $_POST;
foreach ($firstReportInfo['params'] as $key => $value) {
$_GET[$key] = $value;
}
$_POST = array();
$module = $firstReportInfo['params']['module'];
$action = $firstReportInfo['params']['action'];
$this->firstReport = FrontController::getInstance()->fetchDispatch($module, $action);
$_GET = $oldGet;
$_POST = $oldPost;
}
return parent::render();
}
}

View file

@ -0,0 +1,172 @@
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\View;
use Piwik\View;
use Exception;
/**
* Base type of UI controls.
*
* The JavaScript companion class can be found in plugins/CoreHome/javascripts/uiControl.js.
*
* @api
*/
class UIControl extends \Piwik\View
{
/**
* The Twig template file that generates the control's HTML.
*
* Derived classes must set this constant.
*/
const TEMPLATE = '';
/**
* The CSS class that is used to map the root element of this control with the JavaScript class.
*
* This field must be set prior to rendering.
*
* @var string
*/
public $cssIdentifier = null;
/**
* The name of the JavaScript class that handles the behavior of this control.
*
* This field must be set prior to rendering.
*
* @var string
*/
public $jsClass = null;
/**
* The JavaScript module that contains the JavaScript class.
*
* @var string
*/
public $jsNamespace = 'piwik/UI';
/**
* Extra CSS class(es) for the root element.
*
* @var string
*/
public $cssClass = "";
/**
* The inner view that renders the actual control content.
*
* @var View
*/
private $innerView = null;
/**
* Constructor.
*/
public function __construct()
{
$this->innerView = new View(static::TEMPLATE);
parent::__construct("@CoreHome\_uiControl");
}
/**
* Sets a variable. See {@link View::__set()}.
*/
public function __set($key, $val)
{
$this->innerView->__set($key, $val);
}
/**
* Gets a view variable. See {@link View::__get()}.
*/
public function &__get($key)
{
return $this->innerView->__get($key);
}
public function __isset($key)
{
return isset($this->innerView->templateVars[$key]);
}
/**
* Renders the control view within a containing <div> that is used by the UIControl JavaScript
* class.
*
* @return string
*/
public function render()
{
if ($this->cssIdentifier === null) {
throw new Exception("All UIControls must set a cssIdentifier property");
}
if ($this->jsClass === null) {
throw new Exception("All UIControls must set a jsClass property");
}
return parent::render();
}
/**
* See {@link View::getTemplateVars()}.
*/
public function getTemplateVars($override = array())
{
$this->templateVars['implView'] = $this->innerView;
$this->templateVars['cssIdentifier'] = $this->cssIdentifier;
$this->templateVars['cssClass'] = $this->cssClass;
$this->templateVars['jsClass'] = $this->jsClass;
$this->templateVars['jsNamespace'] = $this->jsNamespace;
$this->templateVars['implOverride'] = $override;
$innerTemplateVars = $this->innerView->getTemplateVars($override);
$this->templateVars['clientSideProperties'] = array();
foreach ($this->getClientSideProperties() as $name) {
$this->templateVars['clientSideProperties'][$name] = $innerTemplateVars[$name];
}
$this->templateVars['clientSideParameters'] = array();
$clientSideParameters = $this->getClientSideParameters();
foreach ($this->getClientSideParameters() as $name) {
$this->templateVars['clientSideParameters'][$name] = $innerTemplateVars[$name];
}
return parent::getTemplateVars($override);
}
/**
* Returns the array of property names whose values are passed to the UIControl JavaScript class.
*
* Should be overriden by descendants.
*
* @return array
*/
public function getClientSideProperties()
{
return array();
}
/**
* Returns an array of property names whose values are passed to the UIControl JavaScript class.
* These values differ from those in {@link $clientSideProperties} in that they are meant to passed as
* request parameters when the JavaScript code makes an AJAX request.
*
* Should be overriden by descendants.
*
* @return array
*/
public function getClientSideParameters()
{
return array();
}
}

View file

@ -0,0 +1,25 @@
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\View;
/**
* Rendering interface for all "view" types.
*
* @api
*/
interface ViewInterface
{
/**
* Returns data.
*
* @return string Serialized data, eg, (image, array, html...).
*/
function render();
}