@param int $idSite
@param string $period
@param Date $date
@param bool $segment
@param bool $expanded
@param bool $idSubtable

@return DataTable|DataTable\Map
432493
public function getPageTitlesFollowingSiteSearch($idSite, $period, $date, $segment = false, $expanded = false, $idSubtable = false)
    {
        Piwik::checkUserHasViewAccess($idSite);

        $dataTable = $this->getPageTitles($idSite, $period, $date, $segment, $expanded, $idSubtable);
        $this->keepPagesFollowingSearch($dataTable);
        return $dataTable;
    }
1222801
public function getGoals($idSite)
    {
        $cacheId = self::getCacheId($idSite);
        $cache = $this->getGoalsInfoStaticCache();
        if (!$cache->contains($cacheId)) {
            // note: the reason this is secure is because the above cache is a static cache and cleared after each request
            // if we were to use a different cache that persists the result, this would not be secure because when a
            // result is in the cache, it would just return the result
            $idSite = Site::getIdSitesFromIdSitesString($idSite);

            if (empty($idSite)) {
                return array();
            }

            Piwik::checkUserHasViewAccess($idSite);

            $goals = $this->getModel()->getActiveGoals($idSite);

            $cleanedGoals = array();
            foreach ($goals as &$goal) {
                $cleanedGoals[$goal['idgoal']] = $this->formatGoal($goal);
            }

            $cache->save($cacheId, $cleanedGoals);
        }

        return $cache->fetch($cacheId);
    }
1195900
public function getFollowingPages($url, $idSite, $period, $date, $segment = false)
    {
        $url = PageUrl::excludeQueryParametersFromUrl($url, $idSite);
        // we don't unsanitize $url here. it will be done in the Transitions plugin.

        $resultDataTable = new DataTable;

        try {
            $limitBeforeGrouping = Config::getInstance()->General['overlay_following_pages_limit'];
            $transitionsReport = APITransitions::getInstance()->getTransitionsForAction(
                $url, $type = 'url', $idSite, $period, $date, $segment, $limitBeforeGrouping,
                $part = 'followingActions');
        } catch (Exception $e) {
            return $resultDataTable;
        }

        $reports = array('followingPages', 'outlinks', 'downloads');
        foreach ($reports as $reportName) {
            if (!isset($transitionsReport[$reportName])) {
                continue;
            }
            foreach ($transitionsReport[$reportName]->getRows() as $row) {
                // don't touch the row at all for performance reasons
                $resultDataTable->addRow($row);
            }
        }

        return $resultDataTable;
    }
285502
public function getUrlImageFromAdresse($idAdresse = 0, $format = 'mini', $params = array())
    {
        $url="";
        $dateUpload = "";
        $idHistoriqueImage = "";
        $string = new stringObject();


        switch ($format) {
            case 'mini':
                $chemin = $this->getUrlImage("mini");
                break;
            case 'moyen':
                $chemin = $this->getUrlImage("moyen");
                break;
            case 'grand':
                $chemin = $this->getUrlImage("grand");
                break;
        }

        // requete desactivée (limit 0) : on n'affiche pas les images reliee a l'adresse par la table _adresseimage
        $queryAdresse = "
				SELECT hi.idHistoriqueImage as idHistoriqueImage , hi.idImage as idImage, hi.nom as nom , hi.dateUpload as dateUpload , hi.dateCliche as dateCliche
				FROM historiqueImage hi2, historiqueImage hi
				RIGHT JOIN _adresseImage ai ON ai.idImage = hi.idImage
				WHERE ai.idAdresse = '".$idAdresse."'
						AND hi2.idImage = hi.idImage
						GROUP BY hi.idImage, hi.idHistoriqueImage
						HAVING hi.idHistoriqueImage = max(hi2.idHistoriqueImage)
						LIMIT 0
						";
        $resAdresse = $this->connexionBdd->requete($queryAdresse);

        if (mysql_num_rows($resAdresse)==1) { // toujours 0
            $fetchAdresse = mysql_fetch_assoc($resAdresse);
            $url = $chemin.$fetchAdresse['dateUpload'].'/'.$fetchAdresse['idHistoriqueImage'].".jpg";
            $dateUpload = $fetchAdresse['dateUpload'];
            $idHistoriqueImage = $fetchAdresse['idHistoriqueImage'];
        } else {
            // on recherche une image appartenant a un evenement de l'adresse

            // recherche des evenements de l'adresse:
            $arrayListeEvenementsGroupeAdresse=array();
            $arrayImagePrincipale = array();

            $affichageListeAdresseFromSourceTrouvee = false;
            // l'affichage contextuel sur l'ecran des sources est desactive...
            /*if(isset($this->variablesGet['archiAffichage']) && $this->variablesGet['archiAffichage']=='listeAdressesFromSource' && isset($this->variablesGet['source']) && $this->variablesGet['source']!='')
			 {
			$reqImagesSource = "
			SELECT hi1.idHistoriqueImage as idHistoriqueImage, hi1.idImage as idImage, hi1.dateUpload as dateUpload
			FROM historiqueImage hi2, historiqueImage hi1
			LEFT JOIN _evenementImage ei ON ei.idImage = hi1.idImage
			LEFT JOIN _evenementEvenement ee ON ee.idEvenementAssocie = ei.idEvenement
			WHERE hi2.idImage = hi1.idImage
			AND hi1.idSource='".$this->variablesGet['source']."'
			AND ee.idEvenement='".$params['idEvenementGroupeAdresse']."'
			GROUP BY hi1.idImage , hi1.idHistoriqueImage
			HAVING hi1.idHistoriqueImage = max(hi2.idHistoriqueImage)
			LIMIT 1
			";

			$resImagesSource = $this->connexionBdd->requete($reqImagesSource);

			if(mysql_num_rows($resImagesSource)==1)
			{
			$fetchImagesSource = mysql_fetch_assoc($resImagesSource);
			$dateUpload = $fetchImagesSource['dateUpload'];
			$idHistoriqueImage = $fetchImagesSource['idHistoriqueImage'];
			$url = $chemin.$dateUpload."/".$idHistoriqueImage.".jpg";
			$affichageListeAdresseFromSourceTrouvee = true;
			}

			}
			*/

            $affichageListeAdressesPersonneImageTrouvee = false;
            if (isset($this->variablesGet['archiAffichage']) && $this->variablesGet['archiAffichage']=='evenementListe' && isset($this->variablesGet['selection']) && $this->variablesGet['selection']=='personne' && isset($this->variablesGet['id']) && $this->variablesGet['id']!='' && isset($params['idEvenementGroupeAdresse']) && $params['idEvenementGroupeAdresse']!='' && !$affichageListeAdresseFromSourceTrouvee) {
            // si on est sur l'affichage de la liste des adresses d'un architecte par exemple , on va chercher les photos sur les evenements concernant l'architecte
                // verifions s'il y a au moins une photo sur l'evenement concerné

                // ajout 29/07/2010
                // si l'image principale se situe sur l'evenement concerné , on affiche l'image principale , sinon une image de l'evenement
                $image = new archiImage();
                $arrayImagePrincipale = $image->getArrayInfosImagePrincipaleFromIdGroupeAdresse(array('idEvenementGroupeAdresse'=>$params['idEvenementGroupeAdresse'],'format'=>$format));
                if ($arrayImagePrincipale['trouve']) {
                    $affichageListeAdressesPersonneImageTrouvee=true;
                    $dateUpload = $arrayImagePrincipale['dateUpload'];
                    $idHistoriqueImage = $arrayImagePrincipale['idHistoriqueImage'];
                    $url = $chemin.$dateUpload."/".$idHistoriqueImage.".jpg";
                } else {
                    $reqPersonneEvenement = "
							SELECT hi1.idHistoriqueImage as idHistoriqueImage, hi1.idImage as idImage, hi1.dateUpload as dateUpload
							FROM historiqueImage hi2,historiqueImage hi1
							LEFT JOIN _evenementPersonne ep ON ep.idPersonne = ".mysql_real_escape_string($this->variablesGet['id'])."
									LEFT JOIN _evenementEvenement ee ON ee.idEvenementAssocie=ep.idEvenement
									LEFT JOIN _evenementImage ei ON ei.idEvenement = ee.idEvenementAssocie
									WHERE ee.idEvenement=".mysql_real_escape_string($params['idEvenementGroupeAdresse'])."
											AND hi1.idImage = ei.idImage
											AND hi2.idImage = hi1.idImage
											GROUP BY hi1.idImage, hi1.idHistoriqueImage
											HAVING hi1.idHistoriqueImage = max(hi2.idHistoriqueImage)
											ORDER BY ei.position DESC,hi1.idHistoriqueImage ASC
											LIMIT 1
											";
                    $resPersonneEvenement = $this->connexionBdd->requete($reqPersonneEvenement);
                    if (mysql_num_rows($resPersonneEvenement)==1) {
                        $fetchPersonneEvenement = mysql_fetch_assoc($resPersonneEvenement);
                        $affichageListeAdressesPersonneImageTrouvee=true;

                        $dateUpload = $fetchPersonneEvenement['dateUpload'];
                        $idHistoriqueImage = $fetchPersonneEvenement['idHistoriqueImage'];
                        $url = $chemin.$dateUpload."/".$idHistoriqueImage.".jpg";
                    }
                }
            }

            if (isset($params['idEvenementGroupeAdresse']) && $params['idEvenementGroupeAdresse']!='' && $params['idEvenementGroupeAdresse']!='0' && !$affichageListeAdressesPersonneImageTrouvee && !$affichageListeAdresseFromSourceTrouvee) {
                $image = new archiImage();

                $arrayListeEvenementsGroupeAdresse[] =$params['idEvenementGroupeAdresse'];

                // si un groupe d'adresse est precisé on va d'abord regarder s'il une image principale est selectionnee
                $arrayImagePrincipale = $image->getArrayInfosImagePrincipaleFromIdGroupeAdresse(array('idEvenementGroupeAdresse'=>$params['idEvenementGroupeAdresse'],'format'=>$format));
            } elseif (!$affichageListeAdressesPersonneImageTrouvee && !$affichageListeAdresseFromSourceTrouvee) {
                $queryEvenements ="SELECT idEvenement FROM _adresseEvenement WHERE idAdresse = '".$idAdresse."'";

                $resEvenements = $this->connexionBdd->requete($queryEvenements);

                while ($fetchEvenement = mysql_fetch_assoc($resEvenements)) {
                    $arrayListeEvenementsGroupeAdresse[] = $fetchEvenement['idEvenement'];
                }
            }


            if (isset($arrayImagePrincipale['trouve']) && $arrayImagePrincipale['trouve']==true && !$affichageListeAdressesPersonneImageTrouvee && !$affichageListeAdresseFromSourceTrouvee) {
            // on a trouve une photo principale sur l'evenement groupe adresse
                $url = $arrayImagePrincipale['url'];
                $dateUpload = $arrayImagePrincipale['dateUpload'];
                $idHistoriqueImage = $arrayImagePrincipale['idHistoriqueImage'];
            } elseif (count($arrayListeEvenementsGroupeAdresse)>0 && !$affichageListeAdressesPersonneImageTrouvee && !$affichageListeAdresseFromSourceTrouvee) {
            // si on est sur l'affichage des adresses concernant une personne (architecte etc ...)
                // on affiche une photo de l'evenement concerné par cette personne si il y a des photos , sinon on ne met pas ce critere dans la requete de recherche de photo
                $arrayCritereListeIdEvenementPersonne=array();
                if (isset($this->variablesGet['selection']) && $this->variablesGet['selection']=='personne') {
                // voyons d'abord s'il y a des photos sur l'evenement concerné par l'architect , sinon ce n'est pas la peine d'ajouter ce critere a la recherche de la photo
                    $reqIsPhotoSurEvenement = "
							SELECT idEvenementAssocie as idEvenementPhotoPersonne
							FROM _evenementEvenement ee
							LEFT JOIN _evenementImage ei ON ei.idEvenement = ee.idEvenementAssocie
							LEFT JOIN _evenementPersonne ep ON ep.idEvenement = ee.idEvenementAssocie
							WHERE ee.idEvenement IN (".implode(",", $arrayListeEvenementsGroupeAdresse).")
									AND ep.idPersonne = '".$this->variablesGet['id']."'
											GROUP BY ei.idEvenement
											HAVING count(ei.idImage)>0
											";
                    $resIsPhotoSurEvenement = $this->connexionBdd->requete($reqIsPhotoSurEvenement);

                    if (mysql_num_rows($resIsPhotoSurEvenement)>0) {
                        while ($fetchIsPhotoSurEvenement = mysql_fetch_assoc($resIsPhotoSurEvenement)) {
                            $arrayCritereListeIdEvenementPersonne[] = $fetchIsPhotoSurEvenement['idEvenementPhotoPersonne'];
                        }

                        $listeEvenementsAssocies = implode("','", $arrayCritereListeIdEvenementPersonne);
                    }
                }

                // si la recherche ne concerne pas un personne on fait une recherche plus generale
                if (count($arrayCritereListeIdEvenementPersonne)==0) {
                // on recherche les evenements du groupe d'adresses
                    $listeEvenementsGroupeAdresse = implode("','", $arrayListeEvenementsGroupeAdresse);
                    $queryEvenementAssocies = "
							SELECT idEvenementAssocie FROM _evenementEvenement WHERE idEvenement in ('".$listeEvenementsGroupeAdresse."')
									";

                    $resEvenementsAssocies = $this->connexionBdd->requete($queryEvenementAssocies);

                    $arrayListeEvenementsAssocies=array();
                    while ($fetchEvenementsAssocies = mysql_fetch_assoc($resEvenementsAssocies)) {
                        $arrayListeEvenementsAssocies[] = $fetchEvenementsAssocies['idEvenementAssocie'];
                    }

                    $listeEvenementsAssocies = implode("','", $arrayListeEvenementsAssocies);
                }

                $queryImage = " SELECT hi.idImage as idImage , hi.idHistoriqueImage as idHistoriqueImage, hi.dateUpload as dateUpload,ha1.numero as numero,

						r.nom as nomRue,
						sq.nom as nomSousQuartier,
						q.nom as nomQuartier,
						v.nom as nomVille,
						p.nom as nomPays,
						ha1.numero as numeroAdresse,
						ha1.idRue,
						r.prefixe as prefixeRue,
						IF (ha1.idSousQuartier != 0, ha1.idSousQuartier, r.idSousQuartier) AS idSousQuartier,
						IF (ha1.idQuartier != 0, ha1.idQuartier, sq.idQuartier) AS idQuartier,
						IF (ha1.idVille != 0, ha1.idVille, q.idVille) AS idVille,
						IF (ha1.idPays != 0, ha1.idPays, v.idPays) AS idPays

						FROM historiqueImage hi2, historiqueImage hi

						RIGHT JOIN _evenementImage ei ON ei.idImage = hi.idImage
						RIGHT JOIN _evenementEvenement ee ON ee.idEvenementAssocie = ei.idEvenement
						RIGHT JOIN _adresseEvenement ae ON ae.idEvenement = ee.idEvenement
						RIGHT JOIN historiqueAdresse ha1 ON ha1.idAdresse = ae.idAdresse
						RIGHT JOIN historiqueAdresse ha2 ON ha2.idAdresse = ha1.idAdresse

						LEFT JOIN rue r         ON r.idRue = ha1.idRue
						LEFT JOIN sousQuartier sq   ON sq.idSousQuartier = IF(ha1.idRue='0' and ha1.idSousQuartier!='0' ,ha1.idSousQuartier ,r.idSousQuartier )
						LEFT JOIN quartier q        ON q.idQuartier = IF(ha1.idRue='0' and ha1.idSousQuartier='0' and ha1.idQuartier!='0' ,ha1.idQuartier ,sq.idQuartier )
						LEFT JOIN ville v       ON v.idVille = IF(ha1.idRue='0' and ha1.idSousQuartier='0' and ha1.idQuartier='0' and ha1.idVille!='0' ,ha1.idVille ,q.idVille )
						LEFT JOIN pays p        ON p.idPays = IF(ha1.idRue='0' and ha1.idSousQuartier='0' and ha1.idQuartier='0' and ha1.idVille='0' and ha1.idPays!='0' ,ha1.idPays ,v.idPays )

						LEFT JOIN _adresseImage ai ON hi.idImage = ai.idImage

						WHERE ei.idEvenement in ('".$listeEvenementsAssocies."')
								AND hi2.idImage = hi.idImage
								AND ai.idImage IS NULL
								GROUP BY hi.idImage , hi.idHistoriqueImage,ha1.idAdresse,ha1.idHistoriqueAdresse
								HAVING hi.idHistoriqueImage = max(hi2.idHistoriqueImage) AND ha1.idHistoriqueAdresse = max(ha2.idHistoriqueAdresse)
								ORDER BY ei.position ASC,hi.idHistoriqueImage
								LIMIT 1
								"; // on limit a 1 sinon cela peut prendre du temps

                $resImage = $this->connexionBdd->requete($queryImage);
                if (mysql_num_rows($resImage)>0) {
                    $fetchImage = mysql_fetch_assoc($resImage);
                    //$url = $chemin.$fetchImage['dateUpload'].'/'.$fetchImage['idHistoriqueImage'].".jpg";
                    $url = 'photos-'.$string->convertStringToUrlRewrite($this->getIntituleAdresse($fetchImage)).'-'.$fetchImage['dateUpload'].'-'.$fetchImage['idHistoriqueImage'].'-'.$format.'.jpg';
                    $dateUpload = $fetchImage['dateUpload'];
                    $idHistoriqueImage = $fetchImage['idHistoriqueImage'];
                }
            }
        }

        // pas d'url trouvé , on va chercher dans les images vues sur l'adresse courante
        if (!$affichageListeAdressesPersonneImageTrouvee && !$affichageListeAdresseFromSourceTrouvee && $url=='' && isset($params['idEvenementGroupeAdresse']) && $params['idEvenementGroupeAdresse']!='') {
            $reqVueSur = "
					SELECT hi1.idImage as idImage , hi1.idHistoriqueImage as idHistoriqueImage, hi1.dateUpload as dateUpload,ha1.numero as numero,

					r.nom as nomRue,
					sq.nom as nomSousQuartier,
					q.nom as nomQuartier,
					v.nom as nomVille,
					p.nom as nomPays,
					ha1.numero as numeroAdresse,
					ha1.idRue,
					r.prefixe as prefixeRue,
					IF (ha1.idSousQuartier != 0, ha1.idSousQuartier, r.idSousQuartier) AS idSousQuartier,
					IF (ha1.idQuartier != 0, ha1.idQuartier, sq.idQuartier) AS idQuartier,
					IF (ha1.idVille != 0, ha1.idVille, q.idVille) AS idVille,
					IF (ha1.idPays != 0, ha1.idPays, v.idPays) AS idPays

					FROM _adresseImage ai
					LEFT JOIN historiqueImage hi1 ON hi1.idImage = ai.idImage
					LEFT JOIN historiqueImage hi2 ON hi2.idImage = hi1.idImage
					LEFT JOIN historiqueAdresse ha1 ON ha1.idAdresse = ai.idAdresse
					LEFT JOIN historiqueAdresse ha2 ON ha2.idAdresse = ha1.idAdresse

					LEFT JOIN rue r         ON r.idRue = ha1.idRue
					LEFT JOIN sousQuartier sq   ON sq.idSousQuartier = IF(ha1.idRue='0' and ha1.idSousQuartier!='0' ,ha1.idSousQuartier ,r.idSousQuartier )
					LEFT JOIN quartier q        ON q.idQuartier = IF(ha1.idRue='0' and ha1.idSousQuartier='0' and ha1.idQuartier!='0' ,ha1.idQuartier ,sq.idQuartier )
					LEFT JOIN ville v       ON v.idVille = IF(ha1.idRue='0' and ha1.idSousQuartier='0' and ha1.idQuartier='0' and ha1.idVille!='0' ,ha1.idVille ,q.idVille )
					LEFT JOIN pays p        ON p.idPays = IF(ha1.idRue='0' and ha1.idSousQuartier='0' and ha1.idQuartier='0' and ha1.idVille='0' and ha1.idPays!='0' ,ha1.idPays ,v.idPays )

					WHERE ai.idEvenementGroupeAdresse='".$params['idEvenementGroupeAdresse']."'
					AND ai.vueSur='1'
					AND ai.idAdresse<>'' AND ai.idAdresse<>'0'

					GROUP BY hi1.idImage , hi1.idHistoriqueImage,ha1.idAdresse,ha1.idHistoriqueAdresse


							";
            $resVueSur = $this->connexionBdd->requete($reqVueSur);
            if (mysql_num_rows($resVueSur)>0) {
                $fetchVueSur = mysql_fetch_assoc($resVueSur);
                $url = 'photos-'.$string->convertStringToUrlRewrite($this->getIntituleAdresse($fetchVueSur)).'-'.$fetchVueSur['dateUpload'].'-'.$fetchVueSur['idHistoriqueImage'].'-'.$format.'.jpg';
                $dateUpload = $fetchVueSur['dateUpload'];
                $idHistoriqueImage = $fetchVueSur['idHistoriqueImage'];
            }
        }

        $trouveImage = true;
        if ($url=='') {
            if (isset($params['placeholder']) && $params['placeholder']!="") {
                $url=$params['placeholder'];
                $trouveImage=false;
            } else {
                $url = $this->getUrlImage().'transparent.gif';
                $trouveImage = false;
            }
        }

        return array('url'=>$url,'dateUpload'=>$dateUpload,'idHistoriqueImage'=>$idHistoriqueImage,'trouve'=>$trouveImage);
    }
1024052
public static function displayEvenementsLies($idPerson, $dateDebut, $date2)
    {
        global $config;
        $linkedEvents=archiPersonne::getEvenementsLies($idPerson, $dateDebut, $date2);
        if (count($linkedEvents)) {
            $linkedEventsHTML="<h4>"._("Adresses liées :")."</h4><ul>";
            foreach ($linkedEvents as $linkedEvent) {
                $req = "
                    SELECT titre, dateDebut, idTypeEvenement
                    FROM historiqueEvenement
                    WHERE idEvenement = '".$linkedEvent."'
                    ORDER BY idHistoriqueEvenement DESC
                ";

                $res = $config->connexionBdd->requete($req);
                $event=mysql_fetch_object($res);

                $a=new archiAdresse();
                $linkedEventAddress=$a->getIntituleAdresseFrom($linkedEvent, "idEvenement");
                $e = new archiEvenement();
                if (!empty($linkedEventAddress)) {
                    $req = "
                            SELECT  idAdresse
                            FROM _adresseEvenement
                            WHERE idEvenement = ".
                            $e->getIdEvenementGroupeAdresseFromIdEvenement($linkedEvent);
                    $res = $config->connexionBdd->requete($req);
                    $fetch = mysql_fetch_object($res);
                    if (isset($fetch->idAdresse)) {
                        $linkedEventIdAddress=$fetch->idAdresse;
                    }
                }

                $idEvenementGroupeAdresse = $a->getIdEvenementGroupeAdresseFromIdAdresse($linkedEventIdAddress);

                $reqAdresseDuGroupeAdresse = "
                    SELECT ha1.idAdresse as idAdresse,ha1.numero as numero,
                    ha1.idRue as idRue, IF(ha1.idIndicatif='0','',i.nom)
                    as nomIndicatif, ha1.idQuartier as idQuartier, ha1.idSousQuartier as idSousQuartier
                    FROM historiqueAdresse ha2, historiqueAdresse ha1
                    LEFT JOIN _adresseEvenement ae ON ae.idAdresse = ha1.idAdresse
                    LEFT JOIN indicatif i ON i.idIndicatif = ha1.idIndicatif
                    WHERE ha2.idAdresse = ha1.idAdresse
                    AND ae.idEvenement ='".mysql_real_escape_string($idEvenementGroupeAdresse)."'

                    GROUP BY ha1.idAdresse, ha1.idHistoriqueAdresse
                    HAVING ha1.idHistoriqueAdresse = max(ha2.idHistoriqueAdresse)
                    ORDER BY ha1.numero,ha1.idRue
                ";

                $resAdresseDuGroupeAdresse = $a->connexionBdd->requete($reqAdresseDuGroupeAdresse);

                if (mysql_num_rows($resAdresseDuGroupeAdresse) > 1) {
                    $txtAdresses = '';
                    $arrayNumero = [];
                    while ($fetchAdressesGroupeAdresse = mysql_fetch_assoc($resAdresseDuGroupeAdresse)) {
                        $isAdresseCourante = false;
                        if ($address['idAdresse'] == $fetchAdressesGroupeAdresse['idAdresse']) {
                            $isAdresseCourante = true;
                        }

                        if ($fetchAdressesGroupeAdresse['idRue'] == '0' || $fetchAdressesGroupeAdresse['idRue'] == '') {
                            if ($fetchAdressesGroupeAdresse['idQuartier'] != ''
                                && $fetchAdressesGroupeAdresse['idQuartier'] != '0'
                            ) {
                                $arrayNumero[$this->a->getIntituleAdresseFrom(
                                    $fetchAdressesGroupeAdresse['idAdresse'],
                                    'idAdresse',
                                    ['noSousQuartier' => true, 'noQuartier' => false, 'noVille' => true]
                                )][] =
                                    [
                                        'indicatif'         => $fetchAdressesGroupeAdresse['nomIndicatif'],
                                        'numero'            => $fetchAdressesGroupeAdresse['numero'],
                                        'isAdresseCourante' => $isAdresseCourante,
                                    ];
                            }

                            if ($fetchAdressesGroupeAdresse['idSousQuartier'] != ''
                                && $fetchAdressesGroupeAdresse['idSousQuartier'] != '0'
                            ) {
                                $arrayNumero[$this->a->getIntituleAdresseFrom(
                                    $fetchAdressesGroupeAdresse['idAdresse'],
                                    'idAdresse',
                                    ['noSousQuartier' => false, 'noQuartier' => true, 'noVille' => true]
                                )][] =
                                    [
                                        'indicatif'         => $fetchAdressesGroupeAdresse['nomIndicatif'],
                                        'numero'            => $fetchAdressesGroupeAdresse['numero'],
                                        'isAdresseCourante' => $isAdresseCourante,
                                    ];
                            }
                        } else {
                            $arrayNumero[$a->getIntituleAdresseFrom(
                                $fetchAdressesGroupeAdresse['idRue'],
                                'idRueWithNoNumeroAuthorized',
                                ['noSousQuartier' => true, 'noQuartier' => true, 'noVille' => true]
                            )][] =
                                [
                                    'indicatif'         => $fetchAdressesGroupeAdresse['nomIndicatif'],
                                    'numero'            => $fetchAdressesGroupeAdresse['numero'],
                                    'isAdresseCourante' => $isAdresseCourante,
                                ];
                        }
                    }

                    // affichage adresses regroupees
                    foreach ($arrayNumero as $intituleRue => $arrayInfosNumero) {
                        foreach ($arrayInfosNumero as $indice => $infosNumero) {
                            if ($infosNumero['numero'] == '' || $infosNumero['numero'] == '0') {
                                //rien
                            } else {
                                $txtAdresses .= $infosNumero['numero'].$infosNumero['indicatif'].'-';
                            }
                        }

                        $txtAdresses = trim($txtAdresses, '-');

                        $txtAdresses .= $intituleRue.', ';
                    }
                    $txtAdresses = trim($txtAdresses, ', ').
                        str_replace(
                            $a->getIntituleAdresseFrom($linkedEvent, "idEvenement", ['noQuartier'=>true, 'noSousQuartier'=>true, 'noVille'=>true]),
                            '',
                            $linkedEventAddress
                        );
                } else {
                    $txtAdresses = $linkedEventAddress;
                }

                //WIP sélection de l'image des personnes
                /*$req = "
                        SELECT  nom
                        FROM typeEvenement
                        WHERE idTypeEvenement = ".
                        mysql_real_escape_string($event->idTypeEvenement);
                $res = $config->connexionBdd->requete($req);
                $linkedEventType=mysql_fetch_object($res)->nom;

                 $req = "
                        SELECT idImage
                        FROM _personneAdresse
                        WHERE idPersonne = ".mysql_real_escape_string($idPerson)."
                        AND idAdresse = ".mysql_real_escape_string($linkedEventIdAddress)."
                        LIMIT 1";
                $res = $config->connexionBdd->requete($req);*/
                if ($idImage = mysql_fetch_object($res)->idImage) {
                    $img=new ArchiImage();
                    $img=($img->getInfosCompletesFromIdImage($idImage));
                    $linkedEventImg['url'] = $a->getUrlImage("mini").$img['dateUpload'].'/'.$idImage.'.jpg';
                } else {
                    $linkedEventImg=$a->getUrlImageFromEvenement($linkedEvent, "mini");
                    if ($linkedEventImg["url"]==$config->getUrlImage("", "transparent.gif")) {
                        $linkedEventImg=$a->getUrlImageFromAdresse($linkedEventIdAddress, "mini");
                    }
                }
                $linkedEventUrl=$config->creerUrl("", "adresseDetail", array("archiIdAdresse"=>$linkedEventIdAddress, "archiIdEvenementGroupeAdresse"=>$linkedEvent));
                $linkedEventsHTML.="<li class='linkedEvents'><img src='".
                $linkedEventImg["url"]."' alt='' /> <div><a href='$linkedEventUrl'>".$txtAdresses;
                $res=$e->getInfosEvenementsLiesForAncres($e->getIdEvenementGroupeAdresseFromIdEvenement($linkedEvent));
                $i=0;
                while ($rep=mysql_fetch_object($res)) {
                    if ($rep->idEvenement == $linkedEvent) {
                        $linkedEventPos=$i;
                    }
                    $i++;
                }
                $linkedEventsHTML.="</a>";
                $linkedEventsHTML.="<br/><small><a href='".$linkedEventUrl."#".$linkedEventPos."'>";
                if ($event->dateDebut != "0000-00-00") {
                    $linkedEventsHTML.=$config->date->toFrench($event->dateDebut);
                    if (!empty($event->titre)) {
                        $linkedEventsHTML.=", ";
                    }
                }
                if (!empty($event->titre)) {
                    $linkedEventsHTML.=stripslashes($event->titre);
                }
                if (!empty($linkedEventType)) {
                    $linkedEventsHTML.=", ";
                }
                $linkedEventsHTML.=$linkedEventType;
                $linkedEventsHTML.="</a></small>";
                $linkedEventsHTML.="</div></li>";
            }
            $linkedEventsHTML.="</ul>";
            return $linkedEventsHTML;
        }
    }
1096578
public function getAllSegmentsForSite($idSite, $userLogin)
    {
        $bind = array($idSite, $userLogin);
        $sql  = $this->buildQuerySortedByName('(enable_only_idsite = ? OR enable_only_idsite = 0)
                                               AND deleted = 0
                                               AND (enable_all_users = 1 OR login = ?)');
        $segments = $this->getDb()->fetchAll($sql, $bind);

        return $segments;
    }
398207
protected function enrichItemsTableWithViewMetrics($dataTable, $recordName, $idSite, $period, $date, $segment)
    {
        // Enrich the datatable with Product/Categories views, and conversion rates
        $customVariables = \Piwik\Plugins\CustomVariables\API::getInstance()->getCustomVariables($idSite, $period, $date, $segment, $expanded = false,
            $_leavePiwikCoreVariables = true);
        $mapping = array(
            'Goals_ItemsSku'      => '_pks',
            'Goals_ItemsName'     => '_pkn',
            'Goals_ItemsCategory' => '_pkc',
        );
        $reportToNotDefinedString = array(
            'Goals_ItemsSku'      => Piwik::translate('General_NotDefined', Piwik::translate('Goals_ProductSKU')), // Note: this should never happen
            'Goals_ItemsName'     => Piwik::translate('General_NotDefined', Piwik::translate('Goals_ProductName')),
            'Goals_ItemsCategory' => Piwik::translate('General_NotDefined', Piwik::translate('Goals_ProductCategory'))
        );
        $notDefinedStringPretty = $reportToNotDefinedString[$recordName];
        $customVarNameToLookFor = $mapping[$recordName];

        // Handle case where date=last30&period=day
        if ($customVariables instanceof DataTable\Map) {
            $customVariableDatatables = $customVariables->getDataTables();
            $dataTables = $dataTable->getDataTables();
            foreach ($customVariableDatatables as $key => $customVariableTableForDate) {
                $dataTableForDate = isset($dataTables[$key]) ? $dataTables[$key] : new DataTable();

                // we do not enter the IF
                // if case idSite=1,3 AND period=day&date=datefrom,dateto,
                if ($customVariableTableForDate instanceof DataTable
                    && $customVariableTableForDate->getMetadata(Archive\DataTableFactory::TABLE_METADATA_PERIOD_INDEX)
                ) {
                    $dateRewrite = $customVariableTableForDate->getMetadata(Archive\DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getDateStart()->toString();
                    $row = $customVariableTableForDate->getRowFromLabel($customVarNameToLookFor);
                    if ($row) {
                        $idSubtable = $row->getIdSubDataTable();
                        $this->enrichItemsDataTableWithItemsViewMetrics($dataTableForDate, $idSite, $period, $dateRewrite, $segment, $idSubtable);
                    }
                    $dataTable->addTable($dataTableForDate, $key);
                }
                $this->renameNotDefinedRow($dataTableForDate, $notDefinedStringPretty);
            }
        } elseif ($customVariables instanceof DataTable) {
            $row = $customVariables->getRowFromLabel($customVarNameToLookFor);
            if ($row) {
                $idSubtable = $row->getIdSubDataTable();
                $this->enrichItemsDataTableWithItemsViewMetrics($dataTable, $idSite, $period, $date, $segment, $idSubtable);
            }
            $this->renameNotDefinedRow($dataTable, $notDefinedStringPretty);
        }
    }
962466
public function getExitPageTitles($idSite, $period, $date, $segment = false, $expanded = false,
                                      $idSubtable = false, $flat = false)
    {
        Piwik::checkUserHasViewAccess($idSite);

        $dataTable = $this->getPageTitles($idSite, $period, $date, $segment, $expanded, $idSubtable, $flat);
        $this->filterNonExitActions($dataTable);
        return $dataTable;
    }
1074132
public function getCity($idSite, $period, $date, $segment = false)
    {
        $dataTable = $this->getDataTable(Archiver::CITY_RECORD_NAME, $idSite, $period, $date, $segment);

        $separator = Archiver::LOCATION_SEPARATOR;
        $unk = Visit::UNKNOWN_CODE;

        $dataTables = [$dataTable];

        if ($dataTable instanceof DataTable\Map) {
            $dataTables = $dataTable->getDataTables();
        }

        foreach ($dataTables as $dt) {
            $archiveDate = $dt->getMetadata(DataTable::ARCHIVED_DATE_METADATA_NAME);

            // convert fips region codes to iso if required
            if ($this->shouldRegionCodesBeConvertedToIso($archiveDate, $date, $period)) {
                $dt->filter('GroupBy', array(
                    'label',
                    function ($label) use ($separator, $unk) {
                        $regionCode = getElementFromStringArray($label, $separator, 1, '');
                        $countryCode = getElementFromStringArray($label, $separator, 2, '');

                        list($countryCode, $regionCode) = GeoIp2::convertRegionCodeToIso($countryCode,
                            $regionCode, true);

                        $splitLabel = explode($separator, $label);

                        if (isset($splitLabel[1])) {
                            $splitLabel[1] = $regionCode;
                        }

                        if (isset($splitLabel[2])) {
                            $splitLabel[2] = strtolower($countryCode);
                        }

                        return implode($separator, $splitLabel);
                    }
                ));
            } else {
                $dt->filter('GroupBy', array(
                    'label',
                    function ($label) {
                        if (substr($label, -5) == '|1|ti') {
                            return substr($label, 0, -5) . '|14|cn';
                        }
                        return $label;
                    }
                ));
            }
        }

        $segments = array('city', 'regionCode', 'countryCode');
        $dataTable->filter('AddSegmentByLabel', array($segments, Archiver::LOCATION_SEPARATOR));

        // split the label and put the elements into the 'city_name', 'region', 'country',
        // 'lat' & 'long' metadata fields
        $strUnknown = Piwik::translate('General_Unknown');
        $dataTable->filter('ColumnCallbackAddMetadata',
            array('label', 'city_name', __NAMESPACE__ . '\getElementFromStringArray',
                  array($separator, 0, $strUnknown)));
        $dataTable->filter('MetadataCallbackAddMetadata',
            array('city_name', 'city', function ($city) use ($strUnknown) {
                if ($city == $strUnknown) {
                    return "xx";
                } else {
                    return false;
                }
            }));
        $dataTable->filter('ColumnCallbackAddMetadata',
            array('label', 'region', __NAMESPACE__ . '\getElementFromStringArray', array($separator, 1, $unk)));
        $dataTable->filter('ColumnCallbackAddMetadata',
            array('label', 'country', __NAMESPACE__ . '\getElementFromStringArray', array($separator, 2, $unk)));

        // backwards compatibility: for reports that have lat|long in label
        $dataTable->filter('ColumnCallbackAddMetadata',
            array('label', 'lat', __NAMESPACE__ . '\getElementFromStringArray', array($separator, 3, false)));
        $dataTable->filter('ColumnCallbackAddMetadata',
            array('label', 'long', __NAMESPACE__ . '\getElementFromStringArray', array($separator, 4, false)));

        // add country name & region name metadata
        $dataTable->filter('MetadataCallbackAddMetadata',
            array('country', 'country_name', __NAMESPACE__ . '\countryTranslate', $applyToSummaryRow = false));

        $getRegionName = '\\Piwik\\Plugins\\UserCountry\\getRegionNameFromCodes';
        $dataTable->filter('MetadataCallbackAddMetadata', array(
                                                               array('country', 'region'), 'region_name', $getRegionName, $applyToSummaryRow = false));

        // add the country flag as a url to the 'logo' metadata field
        $dataTable->filter('MetadataCallbackAddMetadata', array('country', 'logo', __NAMESPACE__ . '\getFlagFromCode'));

        // prettify the label
        $dataTable->filter('ColumnCallbackReplace', array('label', __NAMESPACE__ . '\getPrettyCityName'));

        $dataTable->queueFilter('ReplaceSummaryRowLabel');

        return $dataTable;
    }
905678
public function indexOf(Period $interval)
    {
        foreach ($this->intervals as $offset => $period) {
            if ($period->equals($interval)) {
                return $offset;
            }
        }

        return false;
    }
768062
public function getAll($idSite = false)
    {
        if (!empty($idSite)) {
            Piwik::checkUserHasViewAccess($idSite);
        } else {
            Piwik::checkUserHasSomeViewAccess();
        }

        $userLogin = Piwik::getCurrentUserLogin();

        $model = $this->getModel();
        if(Piwik::hasUserSuperUserAccess()) {
            $segments = $model->getAllSegmentsForAllUsers($idSite);
        } else {
            if (empty($idSite)) {
                $segments = $model->getAllSegments($userLogin);
            } else {
                $segments = $model->getAllSegmentsForSite($idSite, $userLogin);
            }
        }

        $segments = $this->sortSegmentsCreatedByUserFirst($segments);

        return $segments;
    }
127141
public function set($idSite, $period, $name, $value)
    {
        $row = & $this->get($idSite, $period);
        $row[$name] = $value;
    }
378627
public static function getKnownSegmentsToArchiveForSite($idSite)
    {
        $cacheId = 'KnownSegmentsToArchiveForSite' . $idSite;
        $cache   = PiwikCache::getTransientCache();
        if ($cache->contains($cacheId)) {
            return $cache->fetch($cacheId);
        }

        $segments = array();
        /**
         * Triggered during the cron archiving process to collect segments that
         * should be pre-processed for one specific site. The archiving process will be launched
         * for each of these segments when archiving data for that one site.
         *
         * This event can be used to add segments to be pre-processed for one site.
         *
         * _Note: If you just want to add a segment that is managed by the user, you should use the
         * SegmentEditor API._
         *
         * **Example**
         *
         *     Piwik::addAction('Segments.getKnownSegmentsToArchiveForSite', function (&$segments, $idSite) {
         *         $segments[] = 'country=jp;city=Tokyo';
         *     });
         *
         * @param array &$segmentsToProcess List of segment definitions, eg,
         *
         *                                      array(
         *                                          'browserCode=ff;resolution=800x600',
         *                                          'country=JP;city=Tokyo'
         *                                      )
         *
         *                                  Add segments to this array in your event handler.
         * @param int $idSite The ID of the site to get segments for.
         */
        Piwik::postEvent('Segments.getKnownSegmentsToArchiveForSite', array(&$segments, $idSite));

        $segments = array_unique($segments);

        $cache->save($cacheId, $segments);

        return $segments;
    }
869906
public function getRowFromIdSubDataTable($idSubTable)
    {
        $idSubTable = (int)$idSubTable;
        foreach ($this->rows as $row) {
            if ($row->getIdSubDataTable() === $idSubTable) {
                return $row;
            }
        }
        return false;
    }
1213802
private function putRowInIndex(&$index, $metadataNamesToIndexBy, $row, $idSite, $period)
    {
        $currentLevel = & $index;

        foreach ($metadataNamesToIndexBy as $metadataName) {
            if ($metadataName == DataTableFactory::TABLE_METADATA_SITE_INDEX) {
                $key = $idSite;
            } elseif ($metadataName == DataTableFactory::TABLE_METADATA_PERIOD_INDEX) {
                $key = $period;
            } else {
                $key = $row[self::METADATA_CONTAINER_ROW_KEY][$metadataName];
            }

            if (!isset($currentLevel[$key])) {
                $currentLevel[$key] = array();
            }

            $currentLevel = & $currentLevel[$key];
        }

        $currentLevel = $row;
    }
1043303
public function getRegion($idSite, $period, $date, $segment = false)
    {
        $dataTable = $this->getDataTable(Archiver::REGION_RECORD_NAME, $idSite, $period, $date, $segment);

        $separator = Archiver::LOCATION_SEPARATOR;
        $unk = Visit::UNKNOWN_CODE;

        $dataTables = [$dataTable];

        if ($dataTable instanceof DataTable\Map) {
            $dataTables = $dataTable->getDataTables();
        }

        foreach ($dataTables as $dt) {
            $archiveDate = $dt->getMetadata(DataTable::ARCHIVED_DATE_METADATA_NAME);

            // convert fips region codes to iso if required
            if ($this->shouldRegionCodesBeConvertedToIso($archiveDate, $date, $period)) {
                $dt->filter('GroupBy', array(
                    'label',
                    function ($label) use ($separator, $unk) {
                        $regionCode = getElementFromStringArray($label, $separator, 0, '');
                        $countryCode = getElementFromStringArray($label, $separator, 1, '');

                        list($countryCode, $regionCode) = GeoIp2::convertRegionCodeToIso($countryCode,
                            $regionCode, true);

                        $splitLabel = explode($separator, $label);

                        if (isset($splitLabel[0])) {
                            $splitLabel[0] = $regionCode;
                        }

                        if (isset($splitLabel[1])) {
                            $splitLabel[1] = strtolower($countryCode);
                        }

                        return implode($separator, $splitLabel);
                    }
                ));
            } else if ($dt->getRowFromLabel('1|ti')) {
                $dt->filter('GroupBy', array(
                    'label',
                    function ($label) {
                        if ($label == '1|ti') {
                            return '14|cn';
                        }
                        return $label;
                    }
                ));
            }
        }

        $segments = array('regionCode', 'countryCode');
        $dataTable->filter('AddSegmentByLabel', array($segments, Archiver::LOCATION_SEPARATOR));

        // split the label and put the elements into the 'region' and 'country' metadata fields
        $dataTable->filter('ColumnCallbackAddMetadata',
            array('label', 'region', __NAMESPACE__ . '\getElementFromStringArray', array($separator, 0, $unk)));
        $dataTable->filter('ColumnCallbackAddMetadata',
            array('label', 'country', __NAMESPACE__ . '\getElementFromStringArray', array($separator, 1, $unk)));

        // add country name metadata
        $dataTable->filter('MetadataCallbackAddMetadata',
            array('country', 'country_name', __NAMESPACE__ . '\CountryTranslate', $applyToSummaryRow = false));

        // get the region name of each row and put it into the 'region_name' metadata
        $dataTable->filter('ColumnCallbackAddMetadata',
            array('label', 'region_name', __NAMESPACE__ . '\getRegionName', $params = null,
                  $applyToSummaryRow = false));

        // add the country flag as a url to the 'logo' metadata field
        $dataTable->filter('MetadataCallbackAddMetadata', array('country', 'logo', __NAMESPACE__ . '\getFlagFromCode'));

        // prettify the region label
        $dataTable->filter('ColumnCallbackReplace', array('label', __NAMESPACE__ . '\getPrettyRegionName'));

        $dataTable->queueFilter('ReplaceSummaryRowLabel');

        return $dataTable;
    }
133434
public function getModel($idSite, $period, $date, $segment = false)
    {
        $dataTable = $this->getDataTable('DevicesDetection_models', $idSite, $period, $date, $segment);

        $dataTable->filter(function (DataTable $table) {
            foreach ($table->getRowsWithoutSummaryRow() as $row) {

                $label = $row->getColumn('label');

                if (strpos($label, ';') !== false) {
                    list($brand, $model) = explode(';', $label, 2);
                    $brand = getDeviceBrandLabel($brand);
                } else {
                    $brand = null;
                    $model = $label;
                }

                $segment = sprintf('deviceBrand==%s;deviceModel==%s', urlencode($brand), urlencode($model));

                $row->setMetadata('segment', $segment);
            }
        });

        $dataTable->filter('GroupBy', array('label', __NAMESPACE__ . '\getModelName'));
        return $dataTable;
    }