Skip to content
GitLab
Explorer
Connexion
S'inscrire
Navigation principale
Rechercher ou aller à…
Projet
S
stats-facil
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Extraits de code
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de paquets
Registre de conteneurs
Registre de modèles
Opération
Environnements
Modules Terraform
Surveillance
Incidents
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
facil
stats-facil
Validations
4c212e16
Valider
4c212e16
rédigé
11 years ago
par
diosmosis
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Refs #4200 documented core/View.php and core/WidgetsList.php
parent
d25f87b1
Branches
Branches contenant la validation
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
2
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
2 fichiers modifiés
core/View.php
+95
-16
95 ajouts, 16 suppressions
core/View.php
core/WidgetsList.php
+41
-17
41 ajouts, 17 suppressions
core/WidgetsList.php
avec
136 ajouts
et
33 suppressions
core/View.php
+
95
−
16
Voir le fichier @
4c212e16
...
@@ -24,8 +24,72 @@ if (!defined('PIWIK_USER_PATH')) {
...
@@ -24,8 +24,72 @@ if (!defined('PIWIK_USER_PATH')) {
}
}
/**
/**
*
View class to render the user interface
*
Encapsulates and manages a [Twig](http://twig.sensiolabs.org/) template.
*
*
* View lets you set properties that will be passed on to a Twig template.
* View will also set several properties that will be available in all Twig
* templates, including:
*
* - **currentModule**: The value of the 'module' query parameter.
* - **currentAction**: The value of the 'action' query parameter.
* - **userLogin**: The current user login name.
* - **sites**: List of site data for every site the current user has at least
* view access for.
* - **url**: The current URL (sanitized).
* - **token_auth**: The current user's token auth.
* - **userHasSomeAdminAccess**: True if the user has admin access to at least
* one site, false if otherwise.
* - **userIsSuperUser**: True if the user is the superuser, false if otherwise.
* - **latest_version_available**: The latest version of Piwik available.
* - **isWidget**: The value of the 'widget' query parameter.
* - **show_autocompleter**: Whether the site selector should be shown or not.
* - **loginModule**: The name of the currently used authentication module.
* - **userAlias**: The alias of the current user.
*
* ### Twig
*
* Twig templates must exist in the **templates** folder in a plugin's root
* folder.
*
* The following filters are available to twig templates:
*
* - **translate**: Outputs internationalized text using a translation token, eg,
* `{{ 'General_Date'|translate }}`. sprintf parameters can be passed
* to the filter.
* - **urlRewriteWithParameters**: Modifies the current query string with the given
* set of parameters, eg,
* ```
* {{ {'module':'MyPlugin', 'action':'index'} | urlRewriteWithParameters }}
* ```
* - **sumTime**: Pretty formats an number of seconds.
* - **money**: Formats a numerical value as a monetary value using the currency
* of the supplied site (second arg is site ID).
* eg, `{{ 23|money(site.idsite)|raw }}
* - **truncate**: Truncates the text to certain length (determined by first arg.)
* eg, `{{ myReallyLongText|truncate(80) }}`
* - **implode**: Calls `implode`.
* - **ucwords**: Calls `ucwords`.
*
* The following functions are available to twig templates:
*
* - **linkTo**: Modifies the current query string with the given set of parameters,
* eg `{{ linkTo({'module':'MyPlugin', 'action':'index'}) }}`.
* - **sparkline**: Outputs a sparkline image HTML element using the sparkline image
* src link. eg, `{{ sparkline(sparklineUrl) }}`.
* - **postEvent**: Posts an event that allows event observers to add text to a string
* which is outputted in the template, eg, `{{ postEvent('MyPlugin.event') }}`
* - **isPluginLoaded**: Returns true if the supplied plugin is loaded, false if otherwise.
* `{% if isPluginLoaded('Goals') %}...{% endif %}`
*
* ### Examples
*
* **Basic usage**
*
* $view = new View("@MyPlugin/myView");
* $view->property1 = "a view property";
* $view->property2 = "another view property";
* echo $view->render();
*
* @package Piwik
* @package Piwik
*
*
* @api
* @api
...
@@ -43,6 +107,13 @@ class View implements ViewInterface
...
@@ -43,6 +107,13 @@ class View implements ViewInterface
private
$contentType
=
'text/html; charset=utf-8'
;
private
$contentType
=
'text/html; charset=utf-8'
;
private
$xFrameOptions
=
null
;
private
$xFrameOptions
=
null
;
/**
* Constructor.
*
* @param string $templateFile The template file to load. Must be in the following format:
* `"@MyPlugin/templateFileName"`. Note the absence of .twig
* from the end of the name.
*/
public
function
__construct
(
$templateFile
)
public
function
__construct
(
$templateFile
)
{
{
$templateExt
=
'.twig'
;
$templateExt
=
'.twig'
;
...
@@ -79,7 +150,7 @@ class View implements ViewInterface
...
@@ -79,7 +150,7 @@ class View implements ViewInterface
/**
/**
* Directly assigns a variable to the view script.
* Directly assigns a variable to the view script.
* V
AR
names may not be prefixed with '_'.
* V
ariable
names may not be prefixed with '_'.
*
*
* @param string $key The variable name.
* @param string $key The variable name.
* @param mixed $val The variable value.
* @param mixed $val The variable value.
...
@@ -91,7 +162,7 @@ class View implements ViewInterface
...
@@ -91,7 +162,7 @@ class View implements ViewInterface
/**
/**
* Retrieves an assigned variable.
* Retrieves an assigned variable.
* V
AR
names may not be prefixed with '_'.
* V
ariable
names may not be prefixed with '_'.
*
*
* @param string $key The variable name.
* @param string $key The variable name.
* @return mixed The variable value.
* @return mixed The variable value.
...
@@ -101,16 +172,17 @@ class View implements ViewInterface
...
@@ -101,16 +172,17 @@ class View implements ViewInterface
return
$this
->
templateVars
[
$key
];
return
$this
->
templateVars
[
$key
];
}
}
p
ublic
function
initializeTwig
()
p
rivate
function
initializeTwig
()
{
{
$piwikTwig
=
new
Twig
();
$piwikTwig
=
new
Twig
();
$this
->
twig
=
$piwikTwig
->
getTwigEnvironment
();
$this
->
twig
=
$piwikTwig
->
getTwigEnvironment
();
}
}
/**
/**
* Renders the current view.
* Renders the current view. Also sends the stored 'Content-Type' HTML header.
* See [setContentType](#setContentType).
*
*
* @return string Generated template
* @return string Generated template
.
*/
*/
public
function
render
()
public
function
render
()
{
{
...
@@ -195,9 +267,9 @@ class View implements ViewInterface
...
@@ -195,9 +267,9 @@ class View implements ViewInterface
}
}
/**
/**
* Set
Content-Type field in HTTP response.
* Set
stored value used in the Content-Type HTTP header field. The header is
*
Since PHP 5.1.2, header() protects against hea
der
in
jection attacks
.
*
set just before ren
derin
g
.
*
*
* @param string $contentType
* @param string $contentType
*/
*/
public
function
setContentType
(
$contentType
)
public
function
setContentType
(
$contentType
)
...
@@ -206,7 +278,11 @@ class View implements ViewInterface
...
@@ -206,7 +278,11 @@ class View implements ViewInterface
}
}
/**
/**
* Set X-Frame-Options field in the HTTP response.
* Set X-Frame-Options field in the HTTP response. The header is set just
* before rendering.
*
* Note: setting this allows you to make sure the View **cannot** be
* embedded in iframes. Learn more [here](https://developer.mozilla.org/en-US/docs/HTTP/X-Frame-Options).
*
*
* @param string $option ('deny' or 'sameorigin')
* @param string $option ('deny' or 'sameorigin')
*/
*/
...
@@ -224,6 +300,7 @@ class View implements ViewInterface
...
@@ -224,6 +300,7 @@ class View implements ViewInterface
* Add form to view
* Add form to view
*
*
* @param QuickForm2 $form
* @param QuickForm2 $form
* @ignore
*/
*/
public
function
addForm
(
QuickForm2
$form
)
public
function
addForm
(
QuickForm2
$form
)
{
{
...
@@ -238,6 +315,7 @@ class View implements ViewInterface
...
@@ -238,6 +315,7 @@ class View implements ViewInterface
* ToDo: This is ugly.
* ToDo: This is ugly.
* @param string|array $var
* @param string|array $var
* @param mixed $value
* @param mixed $value
* @ignore
*/
*/
public
function
assign
(
$var
,
$value
=
null
)
public
function
assign
(
$var
,
$value
=
null
)
{
{
...
@@ -252,6 +330,7 @@ class View implements ViewInterface
...
@@ -252,6 +330,7 @@ class View implements ViewInterface
/**
/**
* Clear compiled Smarty templates
* Clear compiled Smarty templates
* @ignore
*/
*/
static
public
function
clearCompiledTemplates
()
static
public
function
clearCompiledTemplates
()
{
{
...
@@ -260,12 +339,12 @@ class View implements ViewInterface
...
@@ -260,12 +339,12 @@ class View implements ViewInterface
}
}
/**
/**
*
R
ender the single report template
*
Creates a View for and then r
ender
s
the single report template
.
*
*
* @param string $title
R
eport title
* @param string $title
The r
eport title
.
* @param string $reportHtml
R
eport body
* @param string $reportHtml
The r
eport body
HTML.
* @param bool $fetch If true, return report contents as a string;
el
se echo to screen
* @param bool $fetch If true, return report contents as a string;
otherwi
se echo to screen
.
* @return string
R
eport contents if $fetch
==
true
* @return string
|void The r
eport contents if
`
$fetch
` is
true
.
*/
*/
static
public
function
singleReport
(
$title
,
$reportHtml
,
$fetch
=
false
)
static
public
function
singleReport
(
$title
,
$reportHtml
,
$fetch
=
false
)
{
{
...
@@ -278,4 +357,4 @@ class View implements ViewInterface
...
@@ -278,4 +357,4 @@ class View implements ViewInterface
}
}
echo
$view
->
render
();
echo
$view
->
render
();
}
}
}
}
\ No newline at end of file
Ce diff est replié.
Cliquez pour l'agrandir.
core/WidgetsList.php
+
41
−
17
Voir le fichier @
4c212e16
...
@@ -11,7 +11,13 @@
...
@@ -11,7 +11,13 @@
namespace
Piwik
;
namespace
Piwik
;
/**
/**
* Manages the global list of reports that can be displayed as dashboard widgets.
*
* Reports are added as dashboard widgets through the [WidgetsList.addWidgets](#)
* event. Plugins should call [add](#add) in event observers for this event.
*
* @package PluginsFunctions
* @package PluginsFunctions
* @api
*/
*/
class
WidgetsList
class
WidgetsList
{
{
...
@@ -30,10 +36,21 @@ class WidgetsList
...
@@ -30,10 +36,21 @@ class WidgetsList
static
protected
$hookCalled
=
false
;
static
protected
$hookCalled
=
false
;
/**
/**
* Returns all available widgets
* Returns all available widgets.
* The event WidgetsList.addWidgets is used to create the list
*
*
* @return array
* @return array Maps widget categories with an array of widget information, eg,
* ```
* array(
* 'Visitors' => array(
* array(...),
* array(...)
* ),
* 'Visits' => array(
* array(...),
* array(...)
* ),
* )
* ```
*/
*/
static
public
function
get
()
static
public
function
get
()
{
{
...
@@ -108,13 +125,14 @@ class WidgetsList
...
@@ -108,13 +125,14 @@ class WidgetsList
}
}
/**
/**
* Adds a
n widge
t to the list
* Adds a
repor
t to the list
of dashboard widgets.
*
*
* @param string $widgetCategory
* @param string $widgetCategory The widget category. This can be a translation token.
* @param string $widgetName
* @param string $widgetName The name of the widget. This can be a translation token.
* @param string $controllerName
* @param string $controllerName The report's controller name (same as the plugin name).
* @param string $controllerAction
* @param string $controllerAction The report's controller action method name.
* @param array $customParameters
* @param array $customParameters Extra query parameters that should be sent while getting
* this report.
*/
*/
static
public
function
add
(
$widgetCategory
,
$widgetName
,
$controllerName
,
$controllerAction
,
$customParameters
=
array
())
static
public
function
add
(
$widgetCategory
,
$widgetName
,
$controllerName
,
$controllerAction
,
$customParameters
=
array
())
{
{
...
@@ -137,7 +155,14 @@ class WidgetsList
...
@@ -137,7 +155,14 @@ class WidgetsList
);
);
}
}
/**
* Removes one more widgets from the widget list.
*
* @param string $widgetCategory The widget category. Can be a translation token.
* @param string|false $widgetName The name of the widget to remove. Cannot be a
* translation token. If not supplied, entire category
* will be removed.
*/
static
public
function
remove
(
$widgetCategory
,
$widgetName
=
false
)
static
public
function
remove
(
$widgetCategory
,
$widgetName
=
false
)
{
{
if
(
empty
(
$widgetName
))
{
if
(
empty
(
$widgetName
))
{
...
@@ -153,10 +178,11 @@ class WidgetsList
...
@@ -153,10 +178,11 @@ class WidgetsList
}
}
/**
/**
* Checks if the widget with the given parameters exists in der widget list
* Returns true if the widget with the given parameters exists in the widget list,
* false if otherwise.
*
*
* @param string $controllerName
* @param string $controllerName
The controller name of the widget's report.
* @param string $controllerAction
* @param string $controllerAction
The controller action of the widget's report.
* @return bool
* @return bool
*/
*/
static
public
function
isDefined
(
$controllerName
,
$controllerAction
)
static
public
function
isDefined
(
$controllerName
,
$controllerAction
)
...
@@ -177,13 +203,11 @@ class WidgetsList
...
@@ -177,13 +203,11 @@ class WidgetsList
/**
/**
* Method to reset the widget list
* Method to reset the widget list
* For testing only
* For testing only
* @ignore
*/
*/
public
static
function
_reset
()
public
static
function
_reset
()
{
{
self
::
$widgets
=
null
;
self
::
$widgets
=
null
;
self
::
$hookCalled
=
false
;
self
::
$hookCalled
=
false
;
}
}
}
}
\ No newline at end of file
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter