Skip to content
Extraits de code Groupes Projets
Valider ab3f264f rédigé par sgiehl's avatar sgiehl
Parcourir les fichiers

code cleanup; moved require of Socials.php to seperate method

parent 0c40ae91
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -749,6 +749,21 @@ class Common
return $searchEngines;
}
/**
* Returns list of social networks by URL
*
* @see core/DataFiles/Socials.php
*
* @return array Array of ( URL => Social Network Name )
*/
public static function getSocialUrls()
{
require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/Socials.php';
$searchEngines = $GLOBALS['Piwik_socialUrl'];
return $searchEngines;
}
/**
* Returns list of provider names
*
......
......@@ -316,8 +316,6 @@ class API extends \Piwik\Plugin\API
*/
public function getSocials($idSite, $period, $date, $segment = false, $expanded = false)
{
require PIWIK_INCLUDE_PATH . '/core/DataFiles/Socials.php';
$dataTable = $this->getDataTable(Archiver::WEBSITES_RECORD_NAME, $idSite, $period, $date, $segment, $expanded);
$dataTable->filter('ColumnCallbackDeleteRow', array('label', function ($url) { return !isSocialUrl($url); }));
......@@ -349,21 +347,21 @@ class API extends \Piwik\Plugin\API
*/
public function getUrlsForSocial($idSite, $period, $date, $segment = false, $idSubtable = false)
{
require PIWIK_INCLUDE_PATH . '/core/DataFiles/Socials.php';
$dataTable = $this->getDataTable(Archiver::WEBSITES_RECORD_NAME, $idSite, $period, $date, $segment, $expanded = true);
// get the social network domain referred to by $idSubtable
$socialNetworks = Common::getSocialUrls();
$social = false;
if ($idSubtable !== false) {
--$idSubtable;
reset($GLOBALS['Piwik_socialUrl']);
reset($socialNetworks);
for ($i = 0; $i != (int)$idSubtable; ++$i) {
next($GLOBALS['Piwik_socialUrl']);
next($socialNetworks);
}
$social = current($GLOBALS['Piwik_socialUrl']);
$social = current($socialNetworks);
}
// filter out everything but social network indicated by $idSubtable
......@@ -457,7 +455,7 @@ class API extends \Piwik\Plugin\API
$socialName = $row->getColumn('label');
$i = 1; // start at one because idSubtable=0 is equivalent to idSubtable=false
foreach ($GLOBALS['Piwik_socialUrl'] as $domain => $name) {
foreach (Common::getSocialUrls() as $domain => $name) {
if ($name == $socialName) {
$row->c[Row::DATATABLE_ASSOCIATED] = $i;
break;
......
......@@ -37,7 +37,7 @@ function getPathFromUrl($url)
*/
function getSocialNetworkFromDomain($url)
{
foreach ($GLOBALS['Piwik_socialUrl'] AS $domain => $name) {
foreach (Common::getSocialUrls() AS $domain => $name) {
if(preg_match('/(^|[\.\/])'.$domain.'([\.\/]|$)/', $url)) {
......@@ -58,7 +58,7 @@ function getSocialNetworkFromDomain($url)
*/
function isSocialUrl($url, $socialName = false)
{
foreach ($GLOBALS['Piwik_socialUrl'] AS $domain => $name) {
foreach (Common::getSocialUrls() AS $domain => $name) {
if (preg_match('/(^|[\.\/])'.$domain.'([\.\/]|$)/', $url) && ($socialName === false || $name == $socialName)) {
......@@ -79,11 +79,12 @@ function isSocialUrl($url, $socialName = false)
function getSocialsLogoFromUrl($domain)
{
$social = getSocialNetworkFromDomain($domain);
$socialNetworks = Common::getSocialUrls();
$filePattern = 'plugins/Referrers/images/socials/%s.png';
foreach ($GLOBALS['Piwik_socialUrl'] as $domainKey => $name) {
if ($social == $GLOBALS['Piwik_socialUrl'][$domainKey] && file_exists(PIWIK_DOCUMENT_ROOT . '/' . sprintf($filePattern, $domainKey))) {
foreach ($socialNetworks as $domainKey => $name) {
if ($social == $socialNetworks[$domainKey] && file_exists(PIWIK_DOCUMENT_ROOT . '/' . sprintf($filePattern, $domainKey))) {
return sprintf($filePattern, $domainKey);
}
}
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter