src/ClassTheatre/TheatreController.php line 520

Open in your IDE?
  1. <?php
  2. namespace App\ClassTheatre;
  3. use App\Controller\ArticlesController;
  4. use App\Service\Date_time;
  5. use App\Service\Functions;
  6. use App\Service\Text\Keywords;
  7. use App\Service\WebServices\StatusCodes;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  10. use Symfony\Component\Form\Extension\Core\Type\FormType;
  11. use Symfony\Component\Form\Extension\Core\Type\TextType;
  12. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  13. use Symfony\Contracts\Translation\TranslatorInterface;
  14. use TheatreCore\Entity\Bannieres;
  15. use TheatreCore\Entity\Contents;
  16. use TheatreCore\Entity\Exports;
  17. use TheatreCore\Entity\Extranetusers;
  18. use TheatreCore\Entity\Multimedias;
  19. use TheatreCore\Entity\Playlists;
  20. use TheatreCore\Entity\Spectacles;
  21. use TheatreCore\Entity\Templates;
  22. class TheatreController extends AbstractController
  23. {
  24.     public $em null;
  25.     public $parameterBag null;
  26.     // context[view]
  27.     public $context null;
  28.     public $view null;
  29.     // menu courant
  30.     protected $current = array();
  31.     // identifiant de l'objet
  32.     protected $idobject null;
  33.     // type d'object (persons, spectacles...)
  34.     protected $object null;
  35.     // faut-il ne pas enregistrer les stats de cette page
  36.     protected $no_stats null;
  37.     // grouper les contenus associés par classification
  38.     public $group_by_classification false;
  39.     // url de la racine du dossier
  40.     public $url_folder null;
  41.     // taille image dans le contenu
  42.     public $other_img_size null;
  43.     // contenu publie ou pas
  44.     protected $publish_status 1;
  45.     // période de recherche
  46.     protected $search_period = array();
  47.     // zone de recherche
  48.     protected $search_area null;
  49.     // saison de recherche
  50.     protected $search_season null;
  51.     // direction de recherche
  52.     protected $order 'DESC';
  53.     // limite de recherche
  54.     protected $limit = array(
  55.         'start' => 0,
  56.         'end' => 400,
  57.     );
  58.     // nombre de résultat par page
  59.     protected $perPage 400;
  60.     // format de vignette
  61.     protected $format_vignette = array();
  62.     // version de la carte des régions
  63.     protected $carte_version 'flash';
  64.     protected $lng 'fr';
  65.     protected $js_more;
  66.     protected $rub_courante;
  67.     public function __construct(TranslatorInterface $trTokenStorageInterface $tokenStorage)
  68.     {
  69.         $token $tokenStorage->getToken();
  70.         $GLOBALS['session'] = $token $token->getUser() : null;
  71.         $GLOBALS['url_module'] = $_ENV['URL_THNET'];
  72.         $this->context['url_module'] = $GLOBALS['url_module'];
  73.         $this->context['params'] = array();
  74.         $this->context['session'] = $token $token->getUser() : null;
  75.         $this->context['tokenStorage'] = $tokenStorage;
  76. //        if($GLOBALS['session'] == 'anon.'){
  77. //            $GLOBALS['session'] = new Extranetusers();
  78. //        }
  79.         $GLOBALS['lng'] = 'fr';
  80.         $GLOBALS['module'] = $GLOBALS['context']['module'] = 'thnet';
  81.         $this->context['module'] = $GLOBALS['context']['module'];
  82.         $GLOBALS['format_ymd'] = array(
  83.             'en' => array('YMD' => '%d %B %Y''YM' => '%B %Y''Y' => '%Y'),
  84.             'fr' => array('YMD' => '%d %B %Y''YM' => '%B %Y''Y' => '%Y'),
  85.             'pt' => array('YMD' => '%d %B %Y''YM' => '%B %Y''Y' => '%Y'),
  86.             'de' => array('YMD' => '%d %B %Y''YM' => '%B %Y''Y' => '%Y'),
  87.             'ru' => array('YMD' => '%d %B %Y''YM' => '%B %Y''Y' => '%Y'),
  88.             'es' => array('YMD' => '%d %B %Y''YM' => '%B %Y''Y' => '%Y'),
  89.         );
  90.         if(!isset($GLOBALS['tr'])){
  91.             $GLOBALS['tr'] = $tr;
  92.         }
  93.         $GLOBALS['format_date']['fr'] = 'd/m/Y';
  94.         $GLOBALS['format_date_heure'][$GLOBALS['lng']] = 'h:i';
  95.         $this->context['lng'] = $GLOBALS['lng'];
  96.         $this->context['tr'] = $tr;
  97.         $this->context['view'] = new \Stdclass();
  98.         $this->view = &$this->context['view'];
  99.         // Utile pour les asides uniquement... (ça reprends l'ancien format de la première version du site, il faudra à changer ça à l'avenir
  100.         $this->context['view']->context['params'] = &$this->context['params'];
  101.         if(isset($GLOBALS['rub_courante'])){
  102.             $this->context['view']->controller $GLOBALS['rub_courante'];
  103.         }
  104.         // barre addthis
  105.         $this->view->use_addthis true;
  106.         $this->view->title_page '';
  107.         $this->view->errtrace['request_uri'] = $_SERVER['REQUEST_URI'];
  108.     }
  109.     public function view($template$view = [])
  110.     {
  111.         if(method_exists($this'finalizeAction')){
  112.             $this->finalizeAction();
  113.         }
  114.         if(!empty($this->form_r) || !empty($this->reponse) || !empty($this->error) || !empty($this->view->form_r) || !empty($this->view->reponse) || !empty($this->view->error)) {
  115.             $this->view->vmesg 1;
  116.         }
  117.         $this->view->racine_site $_ENV['URL_THNET'];
  118.         $this->view->css_refresh '202311161600'//pour forcer la mise-à-jour du css YYYY-MM-DD-V
  119.         $this->view->url_module $this->context['url_module'];
  120.         $this->common();
  121.         $view array_merge($view, (array)$this->view);
  122.         // renvoyer au format json
  123.         if (!empty($this->context['json_response']) && $this->context['json_response']) {
  124.             $displayWidget '';
  125.             if(isset($_GET['displayWidget'])){
  126.                 $displayWidget = (int)$_GET['displayWidget'];
  127.             }
  128.             $view['minHeader'] = true;
  129.             $html $this->renderview($template,
  130.                 $view
  131.             );
  132.             $htmlPage 'setWidgetThnet('.json_encode($html).', '.$displayWidget.')';
  133.             echo $htmlPage;
  134.             exit;
  135. //            return $this->render($html);
  136.         } else if(!empty($this->context['pdf']) && $this->context['pdf']){
  137.             $template 'pdfs/'.$template;
  138.             $mpdf = new \Mpdf\Mpdf(['marginTop' => 300'tempDir' => getenv('PATH_TEMPORAIRE').'mpdf/']);
  139.             $url2 "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  140.             $url preg_replace('/pdf\/1/'''$url2);
  141.             $mpdf->SetHTMLFooter('
  142.                 <table width="100%">
  143.                     <tr>
  144.                         <td width="10%" style="font-size: 0.7rem">{DATE j-m-Y}</td>
  145.                         <td width="75%" style="text-align: center;">{PAGENO}/{nbpg}</td>
  146.                         <td width="15%" align="center"></td>
  147.                     </tr>
  148.                     <tr>
  149.                         <td colspan="3" style="font-size: 0.7rem">'.$url.'</td>
  150.                     </tr>
  151.                 </table>');
  152.             $htmlPage $this->renderView($template,
  153.                 $view
  154.             );
  155.             $mpdf->WriteHTML($htmlPage);
  156.             $name_file '';
  157.             if(!empty($this->context['params']['name_file'])){
  158.                 $name_file $this->context['params']['name_file'];
  159.             }
  160.             if(!empty($this->context['params']['download'])){
  161.                 $mpdf->Output($this->context['action'].$name_file.'-'.md5(uniqid()).'.pdf''D');
  162.             }
  163.             else {
  164.                 $mpdf->Output($this->context['action'] . $name_file '-' md5(uniqid()) . '.pdf''I');
  165.             }
  166.             return true;
  167.         }
  168.         return $this->render($template,
  169.             $view
  170.         );
  171.     }
  172.     private function common()
  173.     {
  174.         if(!isset($this->func)){
  175.             $this->func = new Functions();
  176.         }
  177.         $conges_start '2018-07-27';
  178.         $conges_end '2018-08-20';
  179.         if (date('Y-m-d') > $conges_start && date('Y-m-d') < $conges_end) {
  180.             $this->view->conges_services = array(
  181.                 'ajoutspectacle' => array(
  182.                     'message' => true,
  183.                     'close' => false,
  184.                 ),
  185.                 'ajoutvideo' => array(
  186.                     'message' => true,
  187.                     'close' => false,
  188.                 ),
  189.                 'annonces' => array(
  190.                     'message' => true,
  191.                     'close' => false,
  192.                 ),
  193.                 'evenements' => array(
  194.                     'message' => true,
  195.                     'close' => false,
  196.                 ),
  197.                 'contacts' => array(
  198.                     'message' => true,
  199.                     'close' => false,
  200.                 ),
  201.                 'critiques' => array(
  202.                     'message' => true,
  203.                     'close' => false,
  204.                 ),
  205.                 'ajoutdate' => array(
  206.                     'message' => true,
  207.                     'close' => false,
  208.                 ),
  209.             );
  210.             $this->view->conges 'Vous pouvez continuez à enregistrer vos spectacles pendant la période estivale, leur validation et mise en ligne reprendra à partir du 20 août.';
  211.         }
  212.         // header et footer
  213.         if (!isset($this->view->ajax)) {
  214.             $this->view->pages_infos = array(
  215.                 'page_evenements' => '/evenements/',
  216.                 'page_auteurs' => '/auteurs/biographies',
  217.                 'page_acteurs' => '/acteurs/biographies',
  218.                 'page_biographies' => '/biographies/',
  219.                 'page_metteurs' => '/metteurs-en-scene/biographies',
  220.                 'page_traducteurs' => '/traducteurs/biographies',
  221.                 'page_spectacles' => '/spectacles/',
  222.                 'page_educ' => '/educ/spectacles/type/prochains/area/',
  223.                 'page_calendrier' => '/calendrier/affiche',
  224.                 'page_critiques' => '/critiques/spectacles',
  225.                 'page_montheatre' => '/montheatre/',
  226.                 'page_accueil' => '/',
  227.                 'page_liens' => '/liens/annuaire',
  228.                 'page_contacts' => '/site/contacts',
  229.                 'page_structures' => '/contacts/',
  230.                 'page_annonces' => '/annonces/',
  231.                 // 'page_editions' => '/editions/editeurs',
  232.                 'page_editions' => '/textes/contemporain/affiche',
  233.                 'page_actu' => '/actualites/theatre',
  234.                 'page_blogs' => '/blogs/',
  235.                 'page_mozilla' => '/site/mozilla',
  236.                 'page_statistiques' => '/site/statistiques',
  237.                 'page_cris' => '/site/association-cris',
  238.                 'page_forum' => '/forum/',
  239.                 'page_inscri_nl' => '/lettre/inscription',
  240.                 'page_aide_rss' => '/site/aide-rss',
  241.                 'page_rss_news' => '/actualites/nouvelles',
  242.                 'page_rss_forum' => '/forum/rss.php',
  243.                 'page_rss_annonces' => '/annonces/suivre/rss',
  244.                 'page_publicite' => '/site/publicite',
  245.                 'page_telechargements' => '/documents/',
  246.                 'page_videos' => '/videos/actualites/',
  247.                 'page_audios' => '/audios/'
  248.             );
  249.             $this->view->racine_site $_ENV['URL_THNET'];
  250.             $this->view->page_encodage 'UTF-8';
  251.             $this->view->annee date('Y');
  252.             $this->view->lng 'fr';
  253.             // preciser l'encodage
  254.             if (empty($this->view->page_encodage)) {
  255.                 $this->view->page_encodage 'iso-8859-1';
  256.             }
  257.             // titre du site par defaut
  258.             if (empty($titresite)) {
  259.                 $titresite 'theatre-contemporain.net';
  260.             }
  261.             if (empty($this->view->titre_de_la_page)) {
  262.                 if (!empty($this->view->title_page)) {
  263.                     $this->view->titre_de_la_page $this->view->title_page ' - ' $titresite;
  264.                     $this->view->titre_de_la_page_short $this->view->title_page;
  265.                 } elseif (!empty($this->title_page)) {
  266.                     $this->view->titre_de_la_page $this->title_page ' - ' $titresite;
  267.                     $this->view->titre_de_la_page_short $this->title_page;
  268.                 } else {
  269.                     $this->view->titre_de_la_page $titresite;
  270.                     $this->view->titre_de_la_page_short $titresite;
  271.                 }
  272.             }
  273.             // header
  274.             $extra_keywords ' culture théâtre spectacle planches scène art dramatique comédie tragédie vaudeville lieu cadre arène boulevard compagnie contemporain auteur éditeur édition actualité date représentation pièce oeuvre';
  275.             /* Meta Keywords */
  276.             if (empty($meta_keywords)) {
  277.                 $meta_keywords '';
  278.             }
  279.             $meta_keywords .= ' ' $this->view->titre_de_la_page $extra_keywords;
  280.             if (!empty($meta_keywords)) {
  281.                 $__kw = new Keywords();
  282.                 $__kw->cache_enabled false;
  283.                 $__kw->parseCached($meta_keywords$GLOBALS['module']);
  284.                 if (!empty($__kw->keywords)) {
  285.                     $meta_keywords $__kw->toString(', ');
  286.                     $meta_dc_keywords $__kw->toString('; ');
  287.                 } else {
  288.                     unset($meta_keywords);
  289.                     unset($meta_dc_keywords);
  290.                 }
  291.                 unset($__kw);
  292.             } else {
  293.                 unset($meta_keywords);
  294.                 unset($meta_dc_keywords);
  295.             }
  296.              // pour la vue (inutile depuis 10 ans... mais je l'utilise encore pour l'Opengraph Twitter ?)
  297.             if(!empty($this->func)){
  298.                 if (!empty($meta_keywords)) {
  299.                     $this->view->meta_keywords $this->func->convEncoding($meta_keywords$this->view->page_encodage);
  300.                 }
  301.                 if (!empty($meta_dc_keywords)) {
  302.                     $this->view->meta_dc_keywords $this->func->convEncoding($meta_keywords$this->view->page_encodage);
  303.                 }
  304.                 if (!empty($this->view->meta_description)) {
  305.                     $this->view->meta_description $this->func->convEncoding($this->view->meta_description$this->view->page_encodage);
  306.                 }
  307.             }
  308.             // rub_courante inexistant
  309.             if (!isset($this->rub_courante)) {
  310.                 $this->rub_courante null;
  311.                 if(!empty($GLOBALS['rub_courante'])){
  312.                     $this->rub_courante $GLOBALS['rub_courante'];
  313.                 }
  314.             }
  315.             // menu principal
  316.             $menu_principal = array(
  317.                 'actualites' => array(
  318.                     'disable_mega_menu' => true,
  319.                     'href' => $this->view->racine_site,
  320.                     'title' => 'Page d\'accueil et d\'actualités sur le théâtre',
  321.                     'label' => 'actu',
  322.                     'class' => 'none',
  323.                 ),
  324.                 'biographies' => array(
  325.                     'href' => $this->view->racine_site $this->view->pages_infos['page_biographies'],
  326.                     'title' => 'Les auteurs de théâtre contemporain',
  327.                     'label' => 'biographies',
  328.                     'class' => 'lien',
  329.                 ),
  330.                 'editions' => array(
  331.                     'href' => $this->view->racine_site $this->view->pages_infos['page_editions'],
  332.                     'title' => 'Les maisons d\'édition de théâtre, les revues et les anthologies',
  333.                     'label' => 'textes',
  334.                     'class' => 'lien',
  335.                     'activates_options_more' => [
  336.                         'textes'
  337.                     ]
  338.                 ),
  339.                 'spectacles' => array(
  340.                     'href' => $this->view->racine_site $this->view->pages_infos['page_spectacles'],
  341.                     'title' => 'Les dossiers complets des spectacles à l\'affiche et les archives',
  342.                     'label' => 'spectacles',
  343.                     'class' => 'lien',
  344.                 ),
  345.                 'videos' => array(
  346.                     'href' => $this->view->racine_site $this->view->pages_infos['page_videos'],
  347.                     'title' => 'Les vidéos référencées sur théatre-contemporain ',
  348.                     'label' => 'Vidéos',
  349.                     'class' => 'lien',
  350.                 ),
  351.                 'audios' => array(
  352.                     'href' => $this->view->racine_site $this->view->pages_infos['page_audios'],
  353.                     'title' => 'Les podcasts référencées sur théatre-contemporain ',
  354.                     'label' => 'Audio',
  355.                     'class' => 'lien',
  356.                 ),
  357.                 'educ' => array(
  358.                     'href' => $this->view->racine_site $this->view->pages_infos['page_educ'],
  359.                     'title' => 'Les contenus pédagogiques liés aux spectacles – pièces démontées',
  360.                     'label' => 'éduc',
  361.                     'class' => 'lien',
  362.                 ),
  363.                 'critiques' => array(
  364.                     'href' => $this->view->racine_site $this->view->pages_infos['page_critiques'],
  365.                     'title' => 'Critiques de spectacles',
  366.                     'label' => 'critiques',
  367.                     'class' => 'none',
  368.                 ),
  369.                 'contacts' => array(
  370.                     'href' => $this->view->racine_site $this->view->pages_infos['page_structures'],
  371.                     'title' => 'Les théâtres, les lieux et les compagnies',
  372.                     'label' => 'théâtres & cie.',
  373.                     'class' => 'lien',
  374.                 ),
  375.                 'evenements' => array(
  376.                     'href' => $this->view->racine_site $this->view->pages_infos['page_evenements'],
  377.                     'title' => 'Proposer votre évènement de theatre',
  378.                     'label' => 'évènements',
  379.                     'class' => 'none',
  380.                 ),
  381.                 'annonces' => array(
  382.                     'href' => $this->view->racine_site $this->view->pages_infos['page_annonces'],
  383.                     'title' => 'Les incontournables petites annonces consacrées au monde du spectacle',
  384.                     'label' => 'annonces',
  385.                     'class' => 'lien',
  386.                 ),
  387.                 //    'telechargements' => array(
  388.                 //         'href' => $this->view->racine_site.$this->view->pages_infos['page_telechargements'],
  389.                 //         'title' => 'Documents numérisés à télécharger',
  390.                 //         'label' => 'doc. numérisés',
  391.                 //         'class' => 'none',
  392.                 //     ),
  393.             );
  394.             foreach ($menu_principal as $k => $v) {
  395.                 $menu_principal[$k]['label'] = $this->func->convEncoding($v['label'], $this->view->page_encodage);
  396.                 $menu_principal[$k]['title'] = $this->func->convEncoding($v['title'], $this->view->page_encodage);
  397.                 if ($k == $this->rub_courante || (!empty($menu_principal[$k]['activates_options_more']) && in_array($this->rub_courante$menu_principal[$k]['activates_options_more']))) {
  398.                     $menu_principal[$k]['active'] = 'on';
  399.                 } else {
  400.                     $menu_principal[$k]['active'] = 'off';
  401.                 }
  402.             }
  403.             $this->view->menu_principal $menu_principal;
  404.             if (!empty($this->view->flux_rss)) {
  405.                 foreach ($this->view->flux_rss as $k => $v) {
  406.                     $this->view->flux_rss[$k]['name'] = $this->func->convEncoding($v['name'], $this->view->page_encodage);
  407.                 }
  408.             }
  409.             // js en plus
  410.             if (!empty($this->view->js_more) || !empty($this->view->js_more)) {
  411.                 if (!empty($this->view->js_more)) {
  412.                     $js_more $this->view->js_more;
  413.                 }
  414.                 if (!empty($this->view->js_more)) {
  415.                     $js_more $this->view->js_more;
  416.                 }
  417.                 if (is_array($js_more)) {
  418.                     foreach ($js_more as $js) {
  419.                         if (is_array($js)) {
  420.                             foreach ($js as $ojs) {
  421.                                 $this->view->js_more_final[] = $ojs;
  422.                             }
  423.                         } else {
  424.                             $this->view->js_more_final[] = $this->view->racine_site '/navigation/js/' $js;
  425.                         }
  426.                     }
  427.                 } else {
  428.                     $this->view->js_more_final[] = $this->view->racine_site '/navigation/js/' $js_more;
  429.                 }
  430.             }
  431.         }
  432.         //// la bannière du bas seulement une fois
  433.         if (count(
  434.             ($banniere $this->em->getRepository(Bannieres::class)->getBottomBanniere())
  435.             ) > 0
  436.         ) {
  437.             if (
  438.                 ! empty($banniere)
  439.                 && file_exists($_ENV['PATH_IMG'] . 'bannieres/' $banniere['imgfile'])
  440.             ) {
  441.                 $banniere['img'] = $_ENV['URL_IMG'] . 'bannieres/' $banniere['imgfile'];
  442.                 $this->view->banniere $banniere;
  443.                 if (!isset($_SESSION['hide_bottom_banner'])) {
  444.                     $this->view->show_bottom_banner true;
  445.                 } else {
  446.                     // si la différence entre la date actuelle et la date du cookie est supérieure à 2heures, supprimer la session
  447.                     $date_hide_bottom_banner = new \Datetime($_SESSION['hide_bottom_banner']);
  448.                     $date_courante = new \Datetime(date('Y-m-d H:i:s'));
  449.                     $interval $date_hide_bottom_banner->diff($date_courante);
  450.                     if ($interval->60) {
  451.                         unset($_SESSION['hide_bottom_banner']);
  452.                         unset($this->view->show_bottom_banner);
  453.                     }
  454.                 }
  455.             }
  456.         }
  457.     }
  458.     // {{{ _doAction()
  459.     /** Appelle la méthode qui correspond à l'action passée
  460.      *
  461.      *
  462.      * @param  string $action le nom de l'action
  463.      * @access protected
  464.      * @return boolean  false si pas de méthode trouvée, true sinon
  465.      */
  466.     protected function _doAction($action)
  467.     {
  468.         if (!is_string($action) || $action=='') return false;
  469.         $methode_folder 'action_'.str_replace('-','_',$action);
  470.         if(method_exists($this$methode_folder)) {
  471.             $this->$methode_folder();
  472.             if(method_exists($this'finalizeAction')) {
  473.                 $this->finalizeAction();
  474.             }
  475.             return true;
  476.         }
  477.         return false;
  478.     }
  479.     // }}}
  480.     // {{{ doAction()
  481.     /** Appelle la méthode correspondante à l'action en cours
  482.      *
  483.      *
  484.      * @param  mixed $action si spécifiée, utilise la chaine passée comme action
  485.      * @access public
  486.      * @return boolean  true si ok, false si méthode non trouvée
  487.      */
  488.     public function doAction($action=null)
  489.     {
  490.         if (is_null($action)) {
  491.             $action $this->context['action'];
  492.         }
  493.         return $this->_doAction($action);
  494.     }
  495.     // }}}
  496.     // {{{ tokenCsrf()
  497.     /**
  498.      * Générer un token pour l'anti csrf en GET
  499.      *
  500.      * @return string le token
  501.      */
  502.     function tokenCsrf($page_name,&$context) {
  503.         // il y a eu un pb avec csrf
  504.         if(!empty($_GET['tc']) && $_GET['tc']=='err') {
  505.             $context['error'][] = 'Il y a eu un problème pendant le processus';
  506.         }
  507.         // page du token
  508.         $page_name md5($page_name);
  509.         // dans la session et le context->view
  510.         $_SESSION[$page_name] = md5(uniqid(rand(), true).session_id());
  511.         $context['view']->t_csrf $_SESSION[$page_name];
  512.         return $_SESSION[$page_name];
  513.     }
  514.     // {{{ checkCsrfToken()
  515.     /**
  516.      * vérifier le token csrf pour les paramètres get
  517.      *
  518.      * @return string le token
  519.      */
  520.     function checkCsrfToken($page_name) {
  521.         // on vérifie que le token présent dans la session est le mm que celui passé en GET
  522.         if(!empty($_SESSION[md5($page_name)]) && !empty($_GET['tc'])
  523.             && $_SESSION[md5($page_name)] == $_GET['tc']) {
  524.             return true;
  525.         } else {
  526.             return false;
  527.         }
  528.     }
  529.     // }}}
  530.     // {{{ action_enimages()
  531.     /** Les diaporamas
  532.      *
  533.      */
  534.     public function action_enimages($idobject,$object)
  535.     {
  536.         // requete SQL pour les diaporamas
  537.         $sql 'SELECT * FROM object_content oc, contents c, content_classification cc, classifications cl
  538.                 WHERE oc.idcontent=c.idcontent
  539.                 AND cc.idcontent=c.idcontent
  540.                 AND cc.idclassification=cl.idclassification
  541.                 AND cl.classification=\'class_diaporama\'
  542.                 AND oc.idobject=\''.$idobject.'\'
  543.                 AND oc.object=\''.$object.'\' ';
  544.         // contenus diaporamas publies ou pas
  545.         if($this->publish_status<2) {
  546.             $sql .= ' AND c.publish='.(int)$this->publish_status;
  547.         }
  548.         // classement par range et/ou date d'insertion
  549.         $sql .= ' ORDER BY c.`range`,c.dateinsert ASC';
  550.         // chemin vers l'album/diaporama flash
  551.         $this->view->url_param $_ENV['URL_THNET'].'/site/diaporama-param/object/'.$object.'/idobject/'.$idobject;
  552.         // selection des contents avec la classification "ex : class_diaporama"
  553.         $contents $this->em->getRepository(Contents::class);
  554.         // contenus diaporamas publies ou pas
  555.         if($this->publish_status<2) {
  556.             $contents->setPublishStatus($this->publish_status);
  557.         }
  558.         $diaporamas $this->contents->queryAll($sql);
  559.         if (!empty($diaporamas)) {
  560.             if (!empty($this->context['params']['idcontent'])) {
  561.                 $idcontent $this->context['params']['idcontent'];
  562.             } else {
  563.                 // si premier affichage prendre le premier article de la liste
  564.                 $idcontent $diaporamas[0]['idcontent'];
  565.             }
  566.             // nombre de diaporamas
  567.             if(count($diaporamas)>1) {
  568.                 $this->view->autrediapo true;
  569.             }
  570.             foreach($diaporamas as $key=>$value) {
  571.                 // recuperer les photos associees a ce contenu
  572.                 $datafile $this->contents->getAssociateFileContent($value['idcontent'],'contents','class_photo_content');
  573.                 // recuperer chaque fichier associe a chaque diaporama
  574.                 if(!empty($datafile)) {
  575.                     foreach($datafile as $fk => $fv) {
  576.                         $label '';
  577.                         if (trim($fv['description']) != '') {
  578.                             if ($label$label .= ' - ';
  579.                             $label .= $fv['description'];
  580.                         }
  581.                         if (trim($fv['title']) != '') {
  582.                             if ($label$label .= ' - ';
  583.                             $label .= $fv['title'];
  584.                         }
  585.                         if (trim($fv['copyright']) != '') {
  586.                             if ($label$label .= ' - ';
  587.                             $label .= $fv['copyright'];
  588.                         }
  589.                         // label
  590.                         $datafile[$fk]['label'] = $label;
  591.                         // vignette
  592.                         $datafile[$fk]['vignette'] = $this->contents->getThumbnail($datafile[$fk]['file'],100,'thumb');
  593.                     }
  594.                     // vignette de l'album avec le premier fichier
  595.                     $datafile[0]['vignette_entete'] = $this->contents->getThumbnail($datafile[0]['file'],130,'thumb');
  596.                     $diaporamas[$key]['vignette_entete'] = $datafile[0]['vignette_entete'];
  597.                     // tous les fichiers du diaporama
  598.                     $diaporamas[$key]['files'] = $datafile;
  599.                 }
  600.                 // exclure le diaporama en cours
  601.                 if($diaporamas[$key]['idcontent']==$idcontent) {
  602.                     $diaporamas[$key]['exclure'] = true;
  603.                 }
  604.             }
  605.             // liste des diaporamas pour le template
  606.             $this->view->diaporamas $diaporamas;
  607.             //=====> on veut le detail d'un diaporama
  608.             // selection des contents avec la classification "class_diaporama"
  609.             $detaildiaporama $this->contents->get($idcontent);
  610.             // recuperer les photos associees a ce contenu
  611.             $datafile $this->contents->getAssociateFileContent($detaildiaporama['idcontent'],'contents','class_photo_content');
  612.             // parcourir le tableau des photos et creer des vignettes
  613.             if(!empty($datafile)) {
  614.                 foreach($datafile as $k=>$v) {
  615.                     // copyright ?
  616.                     /*if($v['watermark']==1) {
  617.                         $watermark = $v['copyright'];
  618.                     } else {
  619.                         $watermark = null;
  620.                     }*/
  621.                     $watermark null// désactivé
  622.                     $params_img = array('watermark' => $watermark);
  623.                     // 3 tailles => 100 / 400 / 680
  624.                     $datafile[$k]['vignette'] = $this->contents->getThumbnail($datafile[$k]['file'],500,'thumb');
  625.                     $datafile[$k]['format_375'] = $this->contents->getThumbnail($datafile[$k]['file'],375,'thumb');
  626.                     $datafile[$k]['format_480'] = $this->contents->getThumbnail($datafile[$k]['file'],480,'thumb');
  627.                     $datafile[$k]['format_1600'] = $this->contents->getThumbnail($datafile[$k]['file'],1600,'thumb');
  628.                     $datafile[$k]['image'] = $this->contents->getThumbnail($datafile[$k]['file'],400,'L',$params_img);
  629.                     $datafile[$k]['image_grd'] = $this->contents->getThumbnail($datafile[$k]['file'],680,'L',$params_img);
  630.                     if(!empty($v['copyright']) && !empty($v['description'])) {
  631.                         $datafile[$k]['copyright_view'] = '<br /><i>'.$v['copyright'].'</i>';
  632.                     } else {
  633.                         $datafile[$k]['copyright_view'] = '<i>'.$v['copyright'].'</i>';
  634.                     }
  635.                     // prendre la premiere image ou celle passée en param comme img de tete
  636.                     if(!empty($_GET['idfile']) && (int)$_GET['idfile']==$datafile[$k]['idfile']) {
  637.                         $detaildiaporama['image_tete'] = $datafile[$k];
  638.                         //$datafile[$k]['active']['image_tete'] = $datafile[$k];
  639.                         unset($datafile[$k]);
  640.                     } elseif(empty($detaildiaporama['image_tete'])) {
  641.                         $detaildiaporama['image_tete'] = $datafile[$k];
  642.                         $detaildiaporama['vignette_entete'] = $datafile[$k]['vignette'];
  643.                     }
  644.                 }
  645.                 $detaildiaporama['files'] = $datafile;
  646.             }
  647.             // convertir les champs wiki si nécessaire
  648.             foreach (array('deck','text') as $v) {
  649.                 if (empty($detaildiaporama[$v])) continue;
  650.                 $detaildiaporama[$v] = $this->contents->wikiTransform($detaildiaporama[$v]);
  651.             }
  652.             if(!empty($detaildiaporama['idcontent'])) {
  653.                 $this->current['idcontent'] = $detaildiaporama['idcontent'];
  654.             }
  655.             // pour le template
  656.             $this->view->detaildiaporama $detaildiaporama;
  657.         }
  658.         // voir si choix de template pour contents via le backoffice
  659.         $templates $this->em->getRepository(Templates::class);
  660.         $others_templates $templates->getAssociateTemplates('contents',$idcontent);
  661.         if(!empty($others_templates)) { // TODO : voir l'utilite du tableau
  662.             if($object=='persons') {
  663.                 $object 'biographies';
  664.             }
  665.             $this->view->stdpage $object.'/'.$others_templates[0]['fichier'].'.std.html';
  666.             $this->context['def_tpl'] = $others_templates[0]['fichier'];
  667.         }
  668.         $this->view->gallery_css true;
  669.         $this->js_more[] = 'lightgallery/lightgallery.min.js';
  670.         // titre de la page et fil d'arianne
  671.         $this->view->extra_locate $this->extra_title 'En images';
  672.     }
  673.     // }}}
  674.     // {{{ action_gadget()
  675.     /** Gadget
  676.      *
  677.      *
  678.      * @access public
  679.      * @return void
  680.      */
  681.     public function action_gadget()
  682.     {
  683.         $this->context['formFactory'] = $this->get('form.factory')->createBuilder(FormType::class, null, [
  684.             'attr' => [
  685.                 'id' => 'masterform'
  686.             ]
  687.         ]);
  688.         $params = array();
  689.         // taille de l'image ?
  690.         $preview_sizes = array(
  691.             'none' => 65,
  692.             'small' => 65,
  693.             'bigsmall' => 90,
  694.             'large' => 100,
  695.         );
  696.         $post = [];
  697.         if(!empty($_POST) && !empty($_POST['form'])){
  698.             $post $_POST['form'];
  699.         }
  700.         if(!empty($post['preview']) && array_key_exists($post['preview'], $preview_sizes)) {
  701.             $vignette_size $preview_sizes[$post['preview']];
  702.             $params[] = 'preview='.$post['preview'];
  703.         } else {
  704.             $vignette_size $preview_sizes['small'];
  705.         }
  706.         if(!empty($post['multiple_element'])) {
  707.             $params[] = 'multiple_element='.$post['multiple_element'];
  708.         }
  709.         // taille de la colonne
  710.         if(!empty($post['colsize'])) {
  711.             $params[] = 'colsize='.$post['colsize'];
  712.             $colsize $post['colsize'];
  713.         } else {
  714.             $colsize 344;
  715.         }
  716.         // hauteur de la colonne
  717.         if(!empty($post['heightcol'])) {
  718.             $params[] = 'heightcol='.$post['heightcol'];
  719.             $heightcol $post['heightcol'];
  720.         } else {
  721.             $heightcol null;
  722.         }
  723.         // nombre d'items maxi
  724.         $max_nbitems 50;
  725.         if(!empty($post['nbitems']) && is_numeric($post['nbitems']) && $post['nbitems']<=$max_nbitems) {
  726.             $params[] = 'nbitems='.$post['nbitems'];
  727.             $nbitems $post['nbitems'];
  728.             if($nbitems>5) { $nbitems 5; }
  729.         } else {
  730.             $nbitems 1;
  731.         }
  732.         // taille de la colonne = taille de la vignette x par nbitems + haut et bas
  733.         if(empty($heightcol)) {
  734.             $hauteur_widget = ($nbitems*$vignette_size)+110;
  735.         } else {
  736.             $hauteur_widget $heightcol;
  737.         }
  738.         $this->view->widget_width $colsize+80;
  739.         if(!empty($params) || !empty($preview)) {
  740.             $params_string join('&',$params);
  741.         } else {
  742.             $params_string null;
  743.         }
  744.         // formulaire
  745.         for($i=1;$i<50;$i++) {
  746.             $val[$i] = $i;
  747.         }
  748.         $this->context['formFactory']->add('nbitems'ChoiceType::class, [
  749.             'label' => 'Nombre à afficher',
  750.             'choices' => $val
  751.         ]);
  752.         $preview_sizes_name = array(
  753.             'large' => 'Vignette (100x100 pixels)',
  754.             'bigsmall' => 'Vignette (80x80 pixels)',
  755.             'small' => 'Petite vignette (55x55 pixels)',
  756.             'none' => 'Pas de vignette',
  757.         );
  758.         $this->context['formFactory']->add('preview'ChoiceType::class, [
  759.             'label' => 'Taille de l\'image',
  760.             'choices' => array_flip($preview_sizes_name)
  761.         ]);
  762.         $nombre_colonnes = array(
  763.             => 'Non',
  764.             => 'Oui',
  765.         );
  766.         $this->context['formFactory']->add('multiple_element'ChoiceType::class, [
  767.             'label' => 'Plusieurs colonnes ?',
  768.             'choices' => $nombre_colonnes
  769.         ]);
  770.         $this->context['formFactory']->add('colsize'TextType::class, [
  771.             'label' => 'Largeur de la colonne (en pixels)',
  772.             'attr' => array('size' => 3)
  773.         ]);
  774.         $this->context['formFactory']->add('heightcol'TextType::class, [
  775.             'label' => 'Hauteur de la colonne (en pixels)',
  776.             'attr' => array('size' => 3)
  777.         ]);
  778.         //règles
  779. //        $this->context['form']->addRule('colsize','La largeur doit-être un nombre','numeric');
  780. //        $this->context['form']->addRule('heightcol','La hauteur doit-être un nombre','numeric');
  781.         $this->context['form'] = $this->context['formFactory']->getForm();
  782.         // largeur, nbitems et hauteur par défaut
  783.         if(!empty($vignette_size)) {
  784.             $this->context['form']->setData(array('preview' => $vignette_size));
  785.         }
  786.         if(empty($post['colsize'])) {
  787.             $this->context['form']->setData(array('colsize' => $colsize+10));
  788.         }
  789.         if(empty($post['heightcol'])) {
  790.             $this->context['form']->setData(array('heightcol' => $hauteur_widget));
  791.         }
  792.         if(empty($post['nbitems'])) {
  793.             $this->context['form']->setData(array('nbitems' => $nbitems));
  794.         }
  795.         if(isset($post['multiple_element'])){
  796.             $this->context['form']->setData(array('multiple_element' => 1));
  797.         }
  798.         $url_widget $_ENV['URL_THNET'].$this->url_folder.'/widget/';
  799.         $url_widget_iframe $url_widget.'?'.$params_string;
  800.         $iframe_code '<iframe src="'.$url_widget_iframe.'" style="width:'.($colsize+40).'px; height:'.$hauteur_widget.'px;border:none;"></iframe>';
  801.         $this->view->iframe_code_html $iframe_code;
  802.         $this->view->iframe_code htmlentities($iframe_code);
  803.         //Non responsive
  804.         $url_widget_ajax $url_widget.'?v=ajax&'.$params_string;
  805.         $rtl "\n";
  806.         $ajax_code  '<script type="text/javascript" src="'.$_ENV['URL_THNET'].'/navigation/js/widget_thnet.js"></script>'.$rtl;
  807.         $ajax_code .= '<div class="widget_thnet_content" data-content="'.$url_widget_ajax.'"></div>';
  808.         $this->view->ajax_code_html trim($ajax_code);
  809.         $this->view->ajax_code htmlentities(trim($ajax_code));
  810.         //Responsive
  811.         $url_widget_ajax $url_widget.'?v=ajax&responsive=1&'.$params_string;
  812.         $ajax_code  '<script type="text/javascript" src="'.$_ENV['URL_THNET'].'/navigation/js/widget_thnet.js"></script>'.$rtl;
  813.         $ajax_code .= '<div class="widget_thnet_content" data-content="'.$url_widget_ajax.'"></div>';
  814.         $this->view->ajax_code_responsive trim($ajax_code);
  815.         $this->extra_title 'Widget';
  816.         $this->extra_locate 'Widget';
  817.     }
  818.     // }}}
  819.     // {{{ action_playlist()
  820.     /** liste de lecture
  821.      *
  822.      *
  823.      * @access public
  824.      * @return void
  825.      */
  826.     public function action_playlist($params_display = array())
  827.     {
  828.         // objet
  829.         $playlists $this->em->getRepository(Playlists::class);
  830.         // trouver la playlist
  831.         if(!empty($this->context['params']['id'])) {
  832.             $url_clean_playlist filter_var($this->context['params']['id'], FILTER_SANITIZE_STRING);
  833.             $idplaylist $playlists->getIdByUrl($url_clean_playlist);
  834.         } else {
  835.             return $this->redirect($this->view->url_folder);
  836.         }
  837.         // playlist
  838.         $playlist $playlists->getInfosPlaylist(
  839.             $idplaylist,
  840.             array(
  841.                 'all' => true,
  842.                 'multimedias' => true
  843.             ),
  844.             $params_display
  845.         );
  846.         // pour les textes, la playlist doitêtre associée au texte
  847.         if($this->context['controller']=='textes' && isset($this->idtext)) {
  848.             foreach($playlist['idtext'] as $k=>$v) {
  849.                 if($v['idtext']==$this->idtext) {
  850.                     $is_text true;
  851.                     break;
  852.                 }
  853.             }
  854.             if(empty($is_text)) {
  855.                 return $this->redirectToRoute('erreur');
  856.             }
  857.         }
  858.         if(empty($playlist)) {
  859.             return $this->redirect($this->url_folder);
  860.         }
  861.         if(empty($playlist['multimedias'])) {
  862.             return $this->redirectToRoute('erreur');
  863.         }
  864.         if(!empty($this->infosperson) && $this->infosperson['sexe']==2) {
  865.             foreach($playlist['classifications'] as $k=>$v) {
  866.                 if($v['classification']=='class_auteur_meme') {
  867.                     $playlist['classifications'][$k]['view_name'] = 'L\'auteure par elle-même';
  868.                 }
  869.             }
  870.         }
  871.         $this->context['view']->playlist $playlist;
  872.         // on a une video en paramètre
  873.         if(!empty($this->context['params']['video'])) {
  874.             $url_clean filter_var($this->context['params']['video'], FILTER_SANITIZE_STRING);
  875.             // la première au chargement
  876.             foreach($playlist['multimedias'] as $k=>$v) {
  877.                 if($v['url_clean']==$url_clean) {
  878.                     $idmultimedia $v['idmultimedia'];
  879.                     break;
  880.                 }
  881.             }
  882.         }
  883.         // si rien, prendre la première vidéo de la playlist
  884.         if(empty($idmultimedia)) {
  885.             foreach($playlist['multimedias'] as $k=>$v) {
  886.                 $idmultimedia $v['idmultimedia'];
  887.                 break;
  888.             }
  889.         }
  890.         // les autres
  891.         if(!empty($playlist['multimedias'])) {
  892.             foreach($playlist['multimedias'] as $k=>$v) {
  893.                 $playlist['multimedias'][$k]['description_courte'] = $playlists->cutSentence($v['description'],100);
  894.                 $playlist['multimedias'][$k]['description'] = html_entity_decode($playlist['multimedias'][$k]['description']);
  895.                 // video en cours
  896.                 if($v['idmultimedia']==$idmultimedia) {
  897.                     $playlist['multimedias'][$k]['current'] = true;
  898.                     $this->context['view']->playlist['title'] = $playlist['multimedias'][$k]['sujet_titre'];
  899.                     $multimedias $this->em->getRepository(Multimedias::class);
  900.                     $video $multimedias->getInfosMultimedia($idmultimedia,false,false,array('tableau' => true));
  901.                     $video['player'] = $multimedias->getPlayer($video);
  902.                     $video['typemultimedia'] = $multimedias->getTypeMultimediaLabel($video['mediatype']);
  903.                     $video['langue'] = $multimedias->getNameLanguage($video['language']);
  904.                     $video['share'] = true;
  905.                     $this->context['view']->video $video;
  906.                 }
  907.             }
  908.             $this->context['view']->videos_playlist $playlist['multimedias'];
  909.         }
  910.         // titre de la page
  911.         $this->extra_locate $this->extra_title $playlist['title'];
  912.     }
  913.     // }}}
  914.     // {{{ getDoAction()
  915.     /** Récupérer l'action possible
  916.      *
  917.      */
  918.     public function getDoAction($possible_do = array('edit','delete','publish'))
  919.     {
  920.         // action ?
  921.         if(!empty($_REQUEST['do']) && in_array($_REQUEST['do'],$possible_do)) {
  922.             $do $_REQUEST['do'];
  923.         } else {
  924.             $do null;
  925.         }
  926.         return $do;
  927.     }
  928.     // }}}
  929.     // {{{ __getView()
  930.     /** Getter View
  931.      *
  932.      * @param  string $attr Attribut
  933.      * @access public
  934.      * @return void
  935.      */
  936.     public function __getView($attr)
  937.     {
  938.         if(!empty($this->context['view']->$attr)) {
  939.             return $this->context['view']->$attr;
  940.         }
  941.         return '';
  942.     }
  943.     // }}}
  944.     // {{{ contenus()
  945.     /** Les articles associés aux dossiers
  946.      *
  947.      */
  948.     public function contenus($object$idobject$type_class null$type_class_view null$other_dimensions=array('width'=>500'grow'=>false), $params=array())
  949.     {
  950.         // si on a plusieurs classifications = sous-sous-sous-sous-menu
  951.         if(is_array($type_class)) {
  952.             $multiple true;
  953.             foreach($type_class as $c) {
  954.                 $type_class_tab[] = '\''.$c.'\'';
  955.             }
  956.         }
  957.         // pour le template = ce qui est ajouté au lien
  958.         $this->view->type_class $type_class_view;
  959.         if(!empty($params['count_only'])){
  960.             $sql 'SELECT COUNT(DISTINCT(c.idcontent)) ';
  961.         }
  962.         else{
  963.             // requete SQL pour la liste des contenus associe a la classification
  964.             $sql 'SELECT c.title,c.idcontent,c.link,c.writer_group,c.writer,c.date_article,c.writer_group_url,c.dateinsert,
  965.             oc.idclassification as group_idclassification, cloc.classification as group_classification,
  966.             c.is_link,c.deck,c.idextranetuser,c.display_media,c.language,cl.classification,cl.idclassification,e.login';
  967.         }
  968.         // select en plus
  969.         if(!empty($params['select'])) {
  970.             $sql .= ','.$params['select'];
  971.         }
  972.         $sql .= ' FROM contents c
  973.                     LEFT JOIN extranetusers e ON c.idextranetuser=e.idextranetuser
  974.                     , content_classification cc, classifications cl, object_content oc
  975.                     LEFT JOIN classifications cloc ON oc.idclassification=cloc.idclassification ';
  976.         // from en plus
  977.         if(!empty($params['from'])) {
  978.             $sql .= ','.$params['from'];
  979.         }
  980.         // join en plus
  981.         if(!empty($params['join'])) {
  982.             $sql .= $params['join'];
  983.         }
  984.         $sql .= ' WHERE oc.idcontent=c.idcontent
  985.                    AND cc.idcontent=c.idcontent
  986.                    AND cc.idclassification=cl.idclassification
  987.                    AND oc.object=\''.$object.'\' ';
  988.         // contenu publié ou pas ?
  989.         if($this->publish_status<2) {
  990.             $sql .= ' AND c.publish='.(int)$this->publish_status;
  991.         }
  992.         if(!empty($params['where'])) {
  993.             $sql .= ' AND '.$params['where'];
  994.         } else {
  995.             $sql .= ' AND oc.idobject='.(int)$idobject;
  996.         }
  997.         if(!empty($params['specif_sql'])) {
  998.             $sql .= $params['specif_sql'];
  999.         }
  1000.         if(!empty($multiple) && !empty($type_class_tab)) {
  1001.             $sql .= ' AND cl.classification IN ('.join(','$type_class_tab).') ';
  1002.         } else if(!empty($type_class)) {
  1003.             $sql .= ' AND cl.classification=\''.$type_class.'\' ';
  1004.         }
  1005.         // classement précisé sinon par date
  1006.         if($type_class=='class_critique') {
  1007.             $sql .= ' ORDER BY c.`date_article` DESC';
  1008.         } else {
  1009.             $sql .= ' ORDER BY c.`range`,c.dateinsert ASC';
  1010.         }
  1011.         if(!array_key_exists('limit'$params)) {
  1012.             $sql .= ' LIMIT 0,10 ';
  1013.         } else {
  1014.             if($params['limit']!='all') {
  1015.                 if(is_array($params['limit'])) {
  1016.                     $sql .= ' LIMIT '.$params['limit'][0].','.$params['limit'][1];
  1017.                 } else {
  1018.                     $sql .= ' LIMIT '.$params['limit'];
  1019.                 }
  1020.             } else {
  1021.                 $sql .= ' ';
  1022.             }
  1023.         }
  1024.         // classe de gestion des articles
  1025.         $articles_folder = new ArticlesController($this->em$this->context['tokenStorage'], $this->context);
  1026.         if(!empty($params['setGroupByClassification'])){
  1027.             $articles_folder->setGroupByClassification($params['setGroupByClassification']);
  1028.         }
  1029.         // grouper par classifications
  1030.         if($this->group_by_classification===true) {
  1031.             $articles_folder->group_by_classification true;
  1032.         }
  1033.         // taille maxi des vidéos
  1034.         if(!empty($other_dimensions)) {
  1035.             $articles_folder->setOtherDimensions($other_dimensions);
  1036.         }
  1037.         if(!empty($this->other_dimensions)) {
  1038.             $articles_folder->setOtherDimensions($this->other_dimensions);
  1039.         }
  1040.         // taille des images
  1041.         if(!empty($this->other_img_size)) {
  1042.             $articles_folder->setImageSize($this->other_img_size);
  1043.         }
  1044.         if(!empty($params['count_only'])){
  1045.             return $articles_folder->contents->queryOne($sql);
  1046.         }
  1047.         else{
  1048.             // execute la requete
  1049.             $articles_folder->execQuery($sql);
  1050.             // liste des articles
  1051.             $articles $articles_folder->getArticles();
  1052.             // article sur lequel on se trouve
  1053.             $detailarticle $articles_folder->getDetailArticle();
  1054.             // marquer le contenu associé courant
  1055.             if(!empty($detailarticle['idcontent'])) {
  1056.                 $this->current['idcontent'] = $detailarticle['idcontent'];
  1057.             }
  1058.             //Index des noms de catégorie pour les articles
  1059.             $voir_langues = array(
  1060.                 'français' => 'Voir aussi',
  1061.                 'anglais' => 'See',
  1062.                 'portugais' => 'Assistir',
  1063.                 'allemand' => 'Siehe auch',
  1064.                 'espagnol' => 'Ver',
  1065.             );
  1066.             // génération des mots-clés pour les méta
  1067.             if(isset($this->meta_keywords)) {
  1068.                 if (!empty($articles)) {
  1069.                     foreach($articles as $k_content => $a_content) {
  1070.                         if(!empty($a_content['articles_by_lng'])) {
  1071.                             foreach ($a_content['articles_by_lng'] as $k => $v) {
  1072.                                 if (!empty($v['content'])) {
  1073.                                     foreach ($v['content'] as $vv) {
  1074.                                         if (!empty($vv['title'])) {
  1075.                                             $this->meta_keywords .= ' ' $vv['title'];
  1076.                                         }
  1077.                                     }
  1078.                                 }
  1079.                                 $articles[$k_content]['articles_by_lng'][$k]['menu_title'] = (isset($voir_langues[$v['term']])) ? $voir_langues[$v['term']] : null;
  1080.                             }
  1081.                         }
  1082.                         else{
  1083.                             if (!empty($a_content['content'])) {
  1084.                                 foreach($a_content['content'] as $vv) {
  1085.                                     if (!empty($vv['title'])) {
  1086.                                         $this->meta_keywords .= ' '.$vv['title'];
  1087.                                     }
  1088.                                 }
  1089.                             }
  1090.                             $articles[$k_content]['menu_title'] = (isset($voir_langues[$a_content['term']])) ? $voir_langues[$a_content['term']] : null;
  1091.                         }
  1092.                     }
  1093.                 }
  1094.             }
  1095.             // pour le template
  1096.             if(!empty($params['return_content'])) {
  1097.                 return $articles;
  1098.             }
  1099.             $this->view->articles $articles;
  1100.             // pour le template
  1101.             $this->view->detailarticle $detailarticle;
  1102.             // titre de la page
  1103.             if (empty($detailarticle['title']) || trim($detailarticle['title']) == '') {
  1104.                 if (!empty($this->current['menu_name'])) {
  1105.                     $this->extra_locate $this->extra_title $this->current['menu_name'];
  1106.                 } else {
  1107.                     $this->extra_locate $this->extra_title 'En savoir plus';
  1108.                 }
  1109.             } else {
  1110.                 $this->extra_title $detailarticle['title'];
  1111.                 $this->extra_locate $this->contents->cutSentence($detailarticle['title'],40);
  1112.             }
  1113.             // voir si choix de template pour contents via le backoffice
  1114.             if (!empty($detailarticle['idcontent'])) {
  1115.                 $templates $this->em->getRepository(Templates::class);
  1116.                 $others_templates $templates->getAssociateTemplates('contents',$detailarticle['idcontent']);
  1117.             }
  1118.             if(!empty($others_templates)) { // TODO : voir l'utilite du tableau
  1119.                 if($object=='persons') {
  1120.                     $object 'biographies';
  1121.                 }
  1122.                 if($object=='texts') {
  1123.                     $object 'textes';
  1124.                 }
  1125.                 $this->view->stdpage $object.'/'.$others_templates[0]['fichier'].'.std.html';
  1126.                 $this->context['def_tpl'] = $others_templates[0]['fichier'];
  1127.             }
  1128.         }
  1129.     }
  1130.     // }}}
  1131.     // {{{ exports()
  1132.     /** Exports des différents documents auprès des sites externes
  1133.      *
  1134.      */
  1135.     public function exports(&$template null)
  1136.     {
  1137.         //Si nous réclamons le mode "ajax"
  1138.         if(!empty($_GET['v']) && $_GET['v']=='ajax') {
  1139.             $uri_export false;
  1140.             if(!empty($_GET['uri'])){
  1141.                 $uri_exports explode('/',$_GET['uri']);
  1142.                 $uri_exports explode('.'$uri_exports[2]);
  1143.                 if(!empty($uri_exports[1])){
  1144.                     $uri_export $uri_exports[1];
  1145.                 }
  1146.                 if(!empty($uri_exports[0]) && $uri_exports[0] != 'www'){
  1147.                     $uri_export $uri_exports[0];
  1148.                 }
  1149.             }
  1150.             else if(!empty($_GET['partenaire'])){
  1151.                 $uri_export $_GET['partenaire'];
  1152.             }
  1153.             if(empty($this->context['params']['cat'])){
  1154.                 unset($this->context['params']['cat']);
  1155.             }
  1156.             else {
  1157.                 $cat_params implode('_'$this->context['params']['cat']);
  1158.             }
  1159.             $params_api_action implode('_'$this->context['params']);
  1160.             if(isset($cat_params)){
  1161.                 $params_api_action array_merge($params_api_action$cat_params);
  1162.             }
  1163.             $params_api = [
  1164.                 'controller' => $this->context['controller'],
  1165.                 'action' => $this->context['action'],
  1166.                 'params' => $params_api_action,
  1167.                 'uri' => $uri_export
  1168.             ];
  1169.             $exports $this->em->getRepository(Exports::class);
  1170.             //Nous vérifions que ça existe bien
  1171.             $extranetusers $this->em->getRepository(Extranetusers::class);
  1172.             if(!empty($_GET['key_public']) && $extranetusers->checkAPIKey($_GET['key_public'])) {
  1173.                 $template_ajax $exports->getExportByPublicKey(
  1174.                     $_GET['key_public'],
  1175.                     $params_api
  1176.                 );
  1177.             }
  1178.             else {
  1179.                 $template_ajax $exports->getExportBy(
  1180.                     $params_api
  1181.                 );
  1182.             }
  1183.             if($template_ajax){
  1184.                 $html $template_ajax['template'].$template_ajax['footer'];
  1185.                 if(!empty($template_ajax['css'])) {
  1186.                     $html .= '<style>'.$template_ajax['css'].'</style>';
  1187.                 }
  1188.                 $filetest getenv('PATH_ROOT').'templates/includes/template_ajax.inc.html.twig';
  1189.                 file_put_contents($filetest,$html);
  1190.                 $this->context['json_response'] = true;
  1191.                 $this->view->iframe_page true;
  1192.                 $this->view->template_ajax $template_ajax;
  1193.             }
  1194.         }
  1195.     }
  1196.     // }}}
  1197.     // {{{ setOtherImgSize()
  1198.     /** Définir la taille de l'image dans le contenu
  1199.      *
  1200.      *
  1201.      * @param  array $other_img_size Définition de l'image
  1202.      * @access public
  1203.      */
  1204.     public function setOtherImgSize($other_img_size) { $this->other_img_size $other_img_size; }
  1205.     // }}}
  1206.     // {{{ setNoStats()
  1207.     /** pas de stats
  1208.      *
  1209.      *
  1210.      * @param  bool $value Actif/non actif
  1211.      * @access public
  1212.      */
  1213.     public function setNoStats($value=true) { $this->no_stats $value; }
  1214.     // }}}
  1215.     // {{{ isNoStats()
  1216.     /** pas de stats ?
  1217.      *
  1218.      *
  1219.      * @return bool
  1220.      * @access public
  1221.      */
  1222.     public function isNoStats() { return $this->no_stats; }
  1223.     // }}}
  1224.     // {{{ setPublishStatus()
  1225.     /** Précise si on veux les articles publiés, pas publiés ou tous
  1226.      *
  1227.      * Par défaut : uniquement les publiés
  1228.      *
  1229.      */
  1230.     public function setPublishStatus($publish_status=1) { $this->publish_status $publish_status; }
  1231.     // }}}
  1232.     // {{{ getJsMore()
  1233.     /** Js en plus (getter)
  1234.      *
  1235.      */
  1236.     public function getJsMore() { return $this->js_more; }
  1237.     // }}}
  1238.     // {{{ getApiData()
  1239.     /** retourner les données dans un formatage convenant à l'API => soit JSON, soit XML
  1240.      *
  1241.      * @param arrau $datas les données
  1242.      * @param string $type le type à utiliser (json ou xml)
  1243.      * @return array
  1244.      */
  1245.     public function getApiData($datas,$type='json',$only_value=true,$json_pretty_print=false)
  1246.     {
  1247.         // convertir les types
  1248.         if($type=='xml') {
  1249.             // traite le XML
  1250.             require_once PATH_LIBS.'XML/Xml.php';
  1251.             return array2xml($datas);
  1252.         } else {
  1253.             // jsonp ou json
  1254.             if(!empty($_GET['callback'])) {
  1255.                 return filter_var($_GET['callback'], FILTER_SANITIZE_STRING).'('.json_encode($datas).')';
  1256.             } else {
  1257.                 if($only_value) {
  1258.                     $datas array_values($datas);
  1259.                 } else {
  1260.                     $datas json_encode($datas);
  1261.                 }
  1262.                 if($json_pretty_print || isset($_REQUEST['json_pretty_print'])) {
  1263.                     if($json_pretty_print=='JSON_UNESCAPED_SLASHES'
  1264.                         || (isset($_REQUEST['json_pretty_print']) && $_REQUEST['json_pretty_print']=='JSON_UNESCAPED_SLASHES')) {
  1265.                         return json_encode($datas,JSON_PRETTY_PRINT JSON_UNESCAPED_SLASHES);
  1266.                     } else {
  1267.                         return json_encode($datas,JSON_PRETTY_PRINT);
  1268.                     }
  1269.                 } else {
  1270.                     return json_encode($datas);
  1271.                 }
  1272.             }
  1273.         }
  1274.     }
  1275.     // }}}
  1276.     // {{{ getApiType()
  1277.     /** retourner le type demandé : XML ou JSON. Défaut : json
  1278.      *
  1279.      * @return string
  1280.      */
  1281.     public function getApiType()
  1282.     {
  1283.         if(!empty($this->context['params']['f'])) {
  1284.             if($this->context['params']['f']=='xml') {
  1285.                 return 'xml';
  1286.             } else {
  1287.                 return 'json';
  1288.             }
  1289.         } elseif(!empty($_REQUEST['f'])) {
  1290.             if($_REQUEST['f']=='xml') {
  1291.                 return 'xml';
  1292.             } else {
  1293.                 return 'json';
  1294.             }
  1295.         } else {
  1296.             return 'json';
  1297.         }
  1298.     }
  1299.     // }}}
  1300.     // {{{ apiHeaderType()
  1301.     /** retourner le header suivant le type de l'api
  1302.      *
  1303.      * @return void
  1304.      */
  1305.     public function apiHeaderType($api_type,$statut=200)
  1306.     {
  1307.         if($api_type=='xml') {
  1308.             header("Content-type: text/xml");
  1309.         } else {
  1310.             header('Content-type: application/json');
  1311.         }
  1312.         header(StatusCodes::httpHeaderFor($statut));
  1313.     }
  1314.     // }}}
  1315.     // {{{ getSaisonsNav()
  1316.     /**  Navigation dans les saisons
  1317.      *
  1318.      * @return array
  1319.      */
  1320.     public function getSaisonsNav($saisons,$current_saison) {
  1321.         $saisons_nav = array();
  1322.         if(!empty($saisons)) {
  1323.             foreach($saisons as $s) {
  1324.                 if(isset($prev)) {
  1325.                     $saisons_nav['next'] = $s;
  1326.                     break;
  1327.                 }
  1328.                 if($s==$current_saison && !isset($saisons_nav['prev'])) {
  1329.                     if(isset($current_s)) {
  1330.                         $saisons_nav['prev'] = $current_s;
  1331.                     }
  1332.                     $prev true;
  1333.                 }
  1334.                 $current_s $s;
  1335.             }
  1336.         }
  1337.         return $saisons_nav;
  1338.     }
  1339.     // }}}
  1340.     // {{{ getSaison()
  1341.     /** Récupérer le paramètre des saisons
  1342.      *
  1343.      * @return string
  1344.      */
  1345.     public function getSaison()
  1346.     {
  1347.         if(!empty($_REQUEST['s'])) {
  1348.             $saison filter_var($_REQUEST['s'], FILTER_SANITIZE_URL);
  1349.         } else {
  1350.             $saison null;
  1351.         }
  1352.         return $saison;
  1353.     }
  1354.     // }}}
  1355.     // {{{ getYear()
  1356.     /** Récupérer le paramètre des années
  1357.      *
  1358.      * @return int
  1359.      */
  1360.     public function getYear()
  1361.     {
  1362.         if(!empty($_REQUEST['y']) && is_numeric($_REQUEST['y'])) {
  1363.             return filter_var($_REQUEST['y'], FILTER_SANITIZE_NUMBER_INT);
  1364.         } else {
  1365.             return null;
  1366.         }
  1367.     }
  1368.     // }}}
  1369.     // {{{ getFrom()
  1370.     /** Récupérer le paramètre de début de période
  1371.      *
  1372.      * @return int
  1373.      */
  1374.     public function getFrom()
  1375.     {
  1376.         return Date_time::getDateParam('from');
  1377.     }
  1378.     // }}}
  1379.     // {{{ getTo()
  1380.     /** Récupérer le paramètre de fin de période
  1381.      *
  1382.      * @return int
  1383.      */
  1384.     public function getTo()
  1385.     {
  1386.         return Date_time::getDateParam('to');
  1387.     }
  1388.     // }}}
  1389.     // {{{ getFromPeriod()
  1390.     /** Récupérer le début de recherche
  1391.      *
  1392.      * @return string
  1393.      */
  1394.     public function getFromPeriod() { return $this->search_period['from']; }
  1395.     // }}}
  1396.     // {{{ getToPeriod()
  1397.     /** Récupérer la fin de recherche
  1398.      *
  1399.      * @return string
  1400.      */
  1401.     public function getToPeriod() { return $this->search_period['to']; }
  1402.     // }}}
  1403.     // {{{ getArea()
  1404.     /** Récupérer la zone de recherche
  1405.      *
  1406.      * @return string
  1407.      */
  1408.     public function getArea() { return $this->search_area; }
  1409.     // }}}
  1410.     // {{{ getSeason()
  1411.     /** Récupérer la saison de recherche
  1412.      *
  1413.      * @return string
  1414.      */
  1415.     public function getSeason() { return $this->search_season; }
  1416.     // }}}
  1417.     // {{{ getListSeasonsYears()
  1418.     /** générer la liste des saisons et des années à partir de la liste des dates
  1419.      *
  1420.      * @param array $listdates Liste des dates
  1421.      * @param string $only retourner uniquelent e tableau des saisons ou le tableau des années
  1422.      * @return array
  1423.      */
  1424.     public function getListSeasonsYears($listdates,$only=null,$change_order=false)
  1425.     {
  1426.         foreach($listdates as $a) {
  1427.             if($a['date']>date('Y-m-d'mktime(0,0,0,8,31,$a['annee'])) ) {
  1428.                 $s $a['annee'].'-'.($a['annee']+1);
  1429.             } else {
  1430.                 $s = ($a['annee']-1).'-'.$a['annee'];
  1431.             }
  1432.             $annees_saisons['saisons'][$s] = $s;
  1433.             //$annees_saisons['saisons_key'][] = $s;
  1434.             $annees_saisons['annees'][$a['annee']] = $a['annee'];
  1435.         }
  1436.         if($only) {
  1437.             return $annees_saisons[$only];
  1438.         }
  1439.         if(isset($annees_saisons)){
  1440.             if($change_order) {
  1441.                 krsort($annees_saisons['annees']);
  1442.                 krsort($annees_saisons['saisons']);
  1443.             }
  1444.             return $annees_saisons;
  1445.         }
  1446.         else{
  1447.             return array();
  1448.         }
  1449.     }
  1450.     // }}}
  1451.     // {{{ getIdpersonType()
  1452.     /** Récupérer le paramètre  de l'auteur
  1453.      *
  1454.      * @return int
  1455.      */
  1456.     public function getIdpersonType($type='idauthor',$tabs=array())
  1457.     {
  1458.         if(!empty($tabs)) {
  1459.             if(!empty($_REQUEST['idperson_'.$type]) && is_numeric($_REQUEST['idperson_'.$type])
  1460.                 && !empty($tabs[$_REQUEST['idperson_'.$type]])) {
  1461.                 return (int)$_REQUEST['idperson_'.$type];
  1462.             }
  1463.         } else {
  1464.             if(!empty($_REQUEST['idperson_'.$type]) && is_numeric($_REQUEST['idperson_'.$type])) {
  1465.                 return (int)$_REQUEST['idperson_'.$type];
  1466.             }
  1467.         }
  1468.         return null;
  1469.     }
  1470.     // }}}
  1471.     // {{{ getIdpersonDirector()
  1472.     /** Récupérer le paramètre  du metteur en scène
  1473.      *
  1474.      * @return int
  1475.      */
  1476.     public function getIdpersonDirector($tabs=array()) { return $this->getIdpersonType('director',$tabs); }
  1477.     // }}}
  1478.     // {{{ getIdpersonAuthor()
  1479.     /** Récupérer le paramètre  de l'auteur
  1480.      *
  1481.      * @return int
  1482.      */
  1483.     public function getIdpersonAuthor($tabs=array()) { return $this->getIdpersonType('author',$tabs); }
  1484.     // }}}
  1485.     // {{{ setSearchPeriod()
  1486.     /** Préciser la période de recherche
  1487.      *
  1488.      * @return int
  1489.      */
  1490.     public function setSearchPeriod($from,$to)
  1491.     {
  1492.         $this->search_period = array(
  1493.             'from' => $from,
  1494.             'to' => $to,
  1495.         );
  1496.     }
  1497.     // }}}
  1498.     // {{{ isSearchPeriod()
  1499.     /** Y a t-il une période de recherche ?
  1500.      *
  1501.      * @return bool
  1502.      */
  1503.     public function isSearchPeriod()
  1504.     {
  1505.         if(!empty($this->search_period)) {
  1506.             return true;
  1507.         } else {
  1508.             return false;
  1509.         }
  1510.     }
  1511.     // }}}
  1512.     // {{{ isSearchArea()
  1513.     /** Y a t-il une zone de recherche ?
  1514.      *
  1515.      * @return bool
  1516.      */
  1517.     public function isSearchArea()
  1518.     {
  1519.         if(!empty($this->search_area)) {
  1520.             return true;
  1521.         } else {
  1522.             return false;
  1523.         }
  1524.     }
  1525.     // }}}
  1526.     // {{{ setSearchArea()
  1527.     /** Préciser la zone de recherche
  1528.      *
  1529.      * @return int
  1530.      */
  1531.     public function setSearchArea($area)
  1532.     {
  1533.         $this->search_area $area;
  1534.     }
  1535.     // }}}
  1536.     // {{{ isSearchSeason()
  1537.     /** Y a t-il une saison de recherche ?
  1538.      *
  1539.      * @return bool
  1540.      */
  1541.     public function isSearchSeason()
  1542.     {
  1543.         if(!empty($this->search_season)) {
  1544.             return true;
  1545.         } else {
  1546.             return false;
  1547.         }
  1548.     }
  1549.     // }}}
  1550.     // {{{ setSearchSeason()
  1551.     /** Préciser la zone de recherche
  1552.      *
  1553.      * @return int
  1554.      */
  1555.     public function setSearchSeason($season)
  1556.     {
  1557.         $this->search_season $season;
  1558.     }
  1559.     // }}}
  1560.     // {{{ setOrder()
  1561.     /** Préciser la direction de recherche
  1562.      *
  1563.      * @return void
  1564.      */
  1565.     public function setOrder($order)
  1566.     {
  1567.         if(strtoupper($order)=='DESC' || strtoupper($order)=='ASC') {
  1568.             $this->order strtoupper($order);
  1569.         }
  1570.     }
  1571.     // }}}
  1572.     // {{{ getOrder()
  1573.     /** Récupère la direction de recherche
  1574.      *
  1575.      * @return string
  1576.      */
  1577.     public function getOrder() { return $this->order; }
  1578.     // }}}
  1579.     // {{{ isOrder()
  1580.     /** Y a t-il une direction de recherche ?
  1581.      *
  1582.      * @return bool
  1583.      */
  1584.     public function isOrder()
  1585.     {
  1586.         if(!empty($this->order)) {
  1587.             return true;
  1588.         } else {
  1589.             return false;
  1590.         }
  1591.     }
  1592.     // }}}
  1593.     // {{{ getLimit()
  1594.     /**
  1595.      * Limite départ et fin
  1596.      */
  1597.     public function getLimit($limit=null,$return_array=false)
  1598.     {
  1599.         if(empty($limit)) {
  1600.             foreach(array('start','end') as $limit) {
  1601.                 if(!empty($_REQUEST[$limit]) && is_numeric($_REQUEST[$limit]) && ($limit=='start' || $limit=='end')) {
  1602.                     $this->limit[$limit] = $_REQUEST[$limit];
  1603.                 }
  1604.                 // si end-start > à perPage, alors ajouter perPage à start
  1605.                 if(($this->limit['end']-$this->limit['start'])>$this->perPage) {
  1606.                     $this->limit['end'] = $this->limit['start']+$this->perPage;
  1607.                 }
  1608.             }
  1609.             if($return_array) {
  1610.                 return array($this->limit['start'],$this->limit['end']);
  1611.             } else {
  1612.                 return $this->limit;
  1613.             }
  1614.         } else {
  1615.             if(!empty($_REQUEST[$limit]) && is_numeric($_REQUEST[$limit]) && ($limit=='start' || $limit=='end')) {
  1616.                 $this->limit[$limit] = $_REQUEST[$limit];
  1617.             }
  1618.             // si end-start > à perPage, alors ajouter perPage à start
  1619.             if(($this->limit['end']-$this->limit['start'])>$this->perPage) {
  1620.                 $this->limit['end'] = $this->limit['start']+$this->perPage;
  1621.             }
  1622.             return $this->limit[$limit];
  1623.         }
  1624.     }
  1625.     // }}}
  1626.     // {{{ getLimitStart()
  1627.     /**
  1628.      * Récupèrer les limites de recherche
  1629.      */
  1630.     public function getLimitStart() { return $this->getLimit('start'); }
  1631.     // }}}
  1632.     // {{{ getLimitEnd()
  1633.     /**
  1634.      * Récupèrer les limites de recherche
  1635.      */
  1636.     public function getLimitEnd() { return $this->getLimit('end'); }
  1637.     // }}}
  1638.     // {{{ setLimit()
  1639.     /** Préciser la limite de recherche
  1640.      *
  1641.      * @return int
  1642.      */
  1643.     public function setLimit($start,$end)
  1644.     {
  1645.         $this->limit = array(
  1646.             'start' => $start,
  1647.             'end' => $end,
  1648.         );
  1649.     }
  1650.     // }}}
  1651.     // {{{ getPagination()
  1652.     /**
  1653.      * Pour la vue => infos de pagination
  1654.      */
  1655.     public function getPagination($total,$limitPage=10,$params=array())
  1656.     {
  1657.         $pagination['total'] = $total;
  1658.         if($total<$this->perPage) {
  1659.             $pagination['perPage'] = $total;
  1660.         } else {
  1661.             $pagination['perPage'] = $this->perPage;
  1662.         }
  1663.         $request_uri str_replace('datestart''DATEBEGIN'$_SERVER['REQUEST_URI']);
  1664.         if(isset($params['url_custom'])){
  1665.             $request_uri str_replace('datestart''DATEBEGIN'$params['url_custom']);
  1666.         }
  1667.         if($this->getLimitStart()<$total) {
  1668.             if($this->getLimitStart()>0) {
  1669.                 $pagination['previous'] = preg_replace('#start=([0-9]+)#''start='.($this->getLimitStart()-$this->perPage), $request_uri);
  1670.             }
  1671.             if(!empty($request_uri) && strpos($request_uri'start=')!==false) {
  1672.                 $pagination['next'] = preg_replace('#start=([0-9]+)#''start='.($this->getLimitStart()+$this->perPage), $request_uri);
  1673.             } else {
  1674.                 if(!empty($request_uri) && strpos($request_uri'?')!==false) {
  1675.                     $pagination['next'] = $request_uri.'&start='.$this->perPage;
  1676.                 } else {
  1677.                     $pagination['next'] = $request_uri.'?start='.$this->perPage;
  1678.                 }
  1679.             }
  1680.         }
  1681.         if(!empty($limitPage)) {
  1682.             $nb_pages ceil($total/$this->perPage);
  1683.             $position $p 0;
  1684.             for($i=1$i<=$nb_pages$i++) {
  1685.                 $pages[$i] = array(
  1686.                     'num' => $i,
  1687.                     'start' => $p,
  1688.                 );
  1689.                 if($p==$this->getLimitStart()) {
  1690.                     $pages[$i]['current'] = true;
  1691.                     $position $i;
  1692.                 }
  1693.                 if(strpos($request_uri'start=')!==false) {
  1694.                     $pages[$i]['url'] = preg_replace('#start=([0-9]+)#''start='.$p$request_uri);
  1695.                 } else {
  1696.                     if(strpos($request_uri'?')!==false) {
  1697.                         $pages[$i]['url'] = $request_uri.'&start='.$p;
  1698.                     } else {
  1699.                         $pages[$i]['url'] = $request_uri.'?start='.$p;
  1700.                     }
  1701.                 }
  1702.                 $p $p+$this->perPage;
  1703.             }
  1704.             $limitPage round($limitPage/2);
  1705.             if($nb_pages>$limitPage) {
  1706.                 $reducePages = array();
  1707.                 if($position==1) { // position début
  1708.                     foreach($pages as $k=>$v) {
  1709.                         if($k==($limitPage)) {
  1710.                             $reducePages[$k] = array(
  1711.                                 'num' => '...',
  1712.                                 'current' => true,
  1713.                                 'point' => true,
  1714.                             );
  1715.                         } elseif($k>($limitPage-1) && $k<$nb_pages) {
  1716.                         } else {
  1717.                             $reducePages[$k] = $v;
  1718.                         }
  1719.                     }
  1720.                 } elseif($position==$nb_pages) { // position fin
  1721.                     foreach($pages as $k=>$v) {
  1722.                         if($k==|| $k>($nb_pages-($limitPage-1))) {
  1723.                             $reducePages[$k] = $v;
  1724.                         }  elseif($k==2) {
  1725.                             $reducePages[2] = array(
  1726.                                 'num' => '...',
  1727.                                 'current' => true,
  1728.                                 'point' => true,
  1729.                             );
  1730.                         }
  1731.                     }
  1732.                 } else {
  1733.                     // compter le nb avant et après la position
  1734.                     $nb_before 0;
  1735.                     $nb_after 0;
  1736.                     foreach($pages as $k=>$v) {
  1737.                         if($k<$position) {
  1738.                             $nb_before++;
  1739.                         } elseif($k>$position) {
  1740.                             $nb_after++;
  1741.                         }
  1742.                         $reducePages[$k] = $v;
  1743.                     }
  1744.                     $reducePagesOk = array();
  1745.                     foreach($reducePages as $k=>$v) {
  1746.                         if($k!=&& $k!=$nb_pages && $k!=$position) {
  1747.                             if($k==($position-2)) {
  1748.                                 $reducePages[$k] = array(
  1749.                                     'num' => '...',
  1750.                                     'current' => true,
  1751.                                     'point' => true,
  1752.                                 );
  1753.                             } elseif(count($reducePages)>$limitPage && $k!=($position-1) && $k!=($position+1)) {
  1754.                                 unset($reducePages[$k]);
  1755.                             }
  1756.                         } else {
  1757.                         }
  1758.                     }
  1759.                 }
  1760.                 /*
  1761.                 if($position>1) {
  1762.                     $reducePages[] = $pages[1];
  1763.                     $reducePages[] = array(
  1764.                         'num' => '...',
  1765.                         'current' => true,
  1766.                         'point' => true,
  1767.                     );
  1768.                 }
  1769.                 if($position>$limitPage) {
  1770.                     $reducePages += array_slice($pages, $position-$limitPage-2, $limitPage);
  1771.                 } else {
  1772.                     $reducePages += array_slice($pages, 0, $position-1);
  1773.                 }
  1774.                 $reducePages[] = $pages[$position];
  1775.                 $reducePages = array_merge($reducePages, array_slice($pages, $position, $limitPage));
  1776.                 if($position==1) {
  1777.                     if($position<count($pages)) {
  1778.                         $reducePages[] = array(
  1779.                             'num' => '...',
  1780.                             'current' => true,
  1781.                             'point' => true,
  1782.                         );
  1783.                         $reducePages[] = $pages[count($pages)];
  1784.                     }
  1785.                 }
  1786.                 */
  1787.                 $pagination['pages'] = $reducePages;
  1788.             } else {
  1789.                 if(!empty($pages)) {
  1790.                     $pagination['pages'] = $pages;
  1791.                 }
  1792.             }
  1793.         }
  1794.         foreach(array('next','previous') as $f) {
  1795.             if(!empty($pagination[$f])) {
  1796.                 $pagination[$f] = str_replace('DATEBEGIN''datestart'$pagination[$f]);
  1797.             }
  1798.         }
  1799.         if(!empty($pagination['pages'])) {
  1800.             foreach($pagination['pages'] as $k=>$v) {
  1801.                 if(!empty($pagination['pages'][$k]['url'])) {
  1802.                     $pagination['pages'][$k]['url'] = str_replace('DATEBEGIN''datestart'$pagination['pages'][$k]['url']);
  1803.                 }
  1804.             }
  1805.         }
  1806.         if($total<=$this->perPage || $position==$nb_pages) {
  1807.             unset($pagination['next']);
  1808.         }
  1809.         if(!empty($pagination['previous']) && $position==1) {
  1810.             unset($pagination['previous']);
  1811.         }
  1812.         if(!empty($params['total_dates'])) {
  1813.             $pagination['total_dates'] = $params['total_dates'];
  1814.         }
  1815.         return $pagination;
  1816.     }
  1817.     // }}}
  1818.     // {{{ isFormatVignette()
  1819.     /** Y a t-il un format de vignette
  1820.      *
  1821.      * @return bool
  1822.      */
  1823.     public function isFormatVignette()
  1824.     {
  1825.         if(!empty($this->format_vignette)) {
  1826.             return true;
  1827.         } else {
  1828.             return false;
  1829.         }
  1830.     }
  1831.     // }}}
  1832.     // {{{ setFormatVignette()
  1833.     /** Définir le format des vignettes
  1834.      *
  1835.      * @return bool
  1836.      */
  1837.     public function setFormatVignette($format_vignette) {
  1838.         if(!empty($format_vignette['vignette'])) {
  1839.             $this->format_vignette['vignette'] = $format_vignette['vignette'];
  1840.         }
  1841.         if(!empty($format_vignette['stylemore'])) {
  1842.             $this->format_vignette['stylemore'] = $format_vignette['stylemore'];
  1843.         }
  1844.     }
  1845.     // }}}
  1846.     // {{{ getCommonSearch()
  1847.     public function getInitSearch()
  1848.     {
  1849.     }
  1850.     // }}}
  1851.     // {{{ getCommonSearch()
  1852.     /** recherche par saison, période, date_start, date_end
  1853.      *
  1854.      * @return void
  1855.      */
  1856.     public function getCommonSearch($params_search=array())
  1857.     {
  1858.         $this->context['formAsideSearch'] = $this->get('form.factory')->createNamedBuilder(''FormType::class);
  1859.         if(empty($params_search['nb_days'])) {
  1860.             $params_search['nb_days'] = 3;
  1861.         }
  1862.         // saison courante
  1863.         $this->context['view']->current_saison Date_time::getLastSaison();
  1864.         // une saison ?
  1865.         $this->context['view']->saison Date_time::getSaisonParam();
  1866.         if($this->context['view']->saison==$this->context['view']->current_saison) {
  1867.             $this->context['view']->is_current_saison true;
  1868.         }
  1869.         // une période ?
  1870.         $this->context['view']->datestart Date_time::getDateParam('datestart');
  1871.         $this->context['view']->dateend Date_time::getDateParam('dateend');
  1872.         if(!Date_time::checkDateFormat($this->context['view']->datestart)) {
  1873.             $this->context['view']->datestart null;
  1874.         } else {
  1875.             $this->context['view']->datestart_string $this->em->getRepository(Spectacles::class)->getFormeDate($this->context['view']->datestart,'d/m/y');
  1876.         }
  1877.         if(!Date_time::checkDateFormat($this->context['view']->dateend)) {
  1878.             $this->context['view']->dateend null;
  1879.         } else {
  1880.             $this->context['view']->dateend_string $this->em->getRepository(Spectacles::class)->getFormeDate($this->context['view']->dateend,'d/m/y');
  1881.         }
  1882.         // un nombre de jours ?
  1883.         if(empty($this->context['view']->days)){
  1884.             $this->context['view']->days Date_time::getDaysParam();
  1885.         }
  1886.         // une année ?
  1887.         $this->context['view']->year Date_time::getYearParam();
  1888.         if(!$this->context['view']->saison && !$this->context['view']->year && !$this->context['view']->days && !$this->context['view']->datestart && !$this->context['view']->dateend) {
  1889.             if(!empty($params_search['default_saison'])) {
  1890.                 $this->context['view']->saison $params_search['default_saison'];
  1891.             } else {
  1892.                 $this->context['view']->days $params_search['nb_days'];
  1893.             }
  1894.         }
  1895.         if(!empty($this->context['view']->days) && isset($this->context['view']->menu_jours)) {
  1896.             foreach($this->context['view']->menu_jours as $k=>$v) {
  1897.                 if($k==$this->context['view']->days) {
  1898.                     $this->context['view']->menu_jours[$k]['active'] = 'on';
  1899.                     $this->context['view']->days_name $v['name'];
  1900.                 }
  1901.             }
  1902.         }
  1903.         // liste des saisons des spectacles
  1904.         if(!empty($params_search['saisons_annees']['saisons'])) {
  1905.             $this->context['view']->saisons $params_search['saisons_annees']['saisons'];
  1906.             if(!empty($params_search['inverse_periode']) || !empty($params_search['inverse_saisons'])) {
  1907.                 krsort($params_search['saisons_annees']['saisons']);
  1908.             }
  1909.             $this->context['formAsideSearch']->add('s'ChoiceType::class, [
  1910.                 'label' => 'Saisons',
  1911.                 'placeholder' => 'Choisissez une saison...',
  1912.                 'choices' => $params_search['saisons_annees']['saisons'],
  1913.                 'attr' => [
  1914.                     'id' => 'saisons'
  1915.                 ]
  1916.             ]);
  1917.         }
  1918.         // liste des annees des spectacles
  1919.         if(!empty($params_search['saisons_annees']['annees'])) {
  1920.             // max et min anneée pour le datepicker
  1921.             $i 0;
  1922.             foreach($params_search['saisons_annees']['annees'] as $k=>$v) {
  1923.                 if($i==0) {
  1924.                     $start_year $v;
  1925.                     if(!empty($v['annee'])) {
  1926.                         $start_year $v['annee'];
  1927.                     }
  1928.                 } else {
  1929.                     $end_year $v;
  1930.                 }
  1931.                 $i++;
  1932.             }
  1933.             $this->context['view']->year_range = ($start_year-date('Y')).':+5';
  1934.             $this->context['view']->annees $params_search['saisons_annees']['annees'];
  1935.             if(!empty($params_search['inverse_periode']) || !empty($params_search['inverse_annees'])) {
  1936.                 ksort($params_search['saisons_annees']['annees']);
  1937.             }
  1938.             $this->context['formAsideSearch']->add('y'ChoiceType::class, [
  1939.                 'label' => 'Années',
  1940.                 'placeholder' => 'Choisissez une année...',
  1941.                 'choices' => $params_search['saisons_annees']['annees'],
  1942.                 'attr' => [
  1943.                     'id' => 'annees'
  1944.                 ]
  1945.             ]);
  1946.         }
  1947.         $this->context['formAsideSearch']->add('datestart'TextType::class, [
  1948.             'label' => 'Entre',
  1949.             'attr' => [
  1950.                 'size'=>'7',
  1951.                 'id'=>'datestart',
  1952.                 'class' => 'input-group-field'
  1953.             ]
  1954.         ]);
  1955.         $this->context['formAsideSearch']->add('dateend'TextType::class, [
  1956.             'label' => 'et',
  1957.             'attr' => [
  1958.                 'size'=>'7',
  1959.                 'id'=>'dateend',
  1960.                 'class' => 'input-group-field'
  1961.             ]
  1962.         ]);
  1963.     }
  1964.     // }}}
  1965.     public function getCommonSearchView($request null)
  1966.     {
  1967.         $this->context['formAsideSearch'] = $this->context['formAsideSearch']->getForm();
  1968.         if(!empty($request)){
  1969.             $this->context['formAsideSearch']->handleRequest($request);
  1970.         }
  1971.         $this->view->formAsideSearch $this->context['formAsideSearch']->createView();
  1972.     }
  1973.     // {{{ setCommonSearchSpectacles()
  1974.     /** appliquer les élèments de recherche
  1975.      *
  1976.      * @return array
  1977.      */
  1978.     public function setCommonSearchSpectacles($params_sql$disable false)
  1979.     {
  1980.         // recherche par saison
  1981.         if(!empty($this->context['view']->saison)) {
  1982.             $params_sql['special']['saison'] = $this->context['view']->saison;
  1983.         } elseif(!empty($this->context['view']->year)) { // recherche par année
  1984.             $params_sql['special']['year'] = $this->context['view']->year;
  1985.         } elseif(!empty($this->context['view']->datestart) && !empty($this->context['view']->dateend)) { // par période
  1986.             $params_sql['special']['period'] = array(
  1987.                 'start' => $this->context['view']->datestart,
  1988.                 'end' => $this->context['view']->dateend,
  1989.             );
  1990.         } else if(empty($params_sql['special']['anciens_stricts']) && !$disable) { // prochains jours
  1991.             $params_sql['special']['prochains'] = $this->context['view']->days;
  1992.         }
  1993.         // une région en particulier ?
  1994.         if(!empty($this->context['params']['area']) &&
  1995.             (is_numeric($this->context['params']['area']) || strlen($this->context['params']['area'])==2)) {
  1996.             $params_sql['special']['area'] =  $this->context['params']['area']; // recherche dans la région
  1997.             $params_sql['special']['carte_version'] =  $this->getCarteVersion(); // recherche dans la région
  1998.             if(is_numeric($params_sql['special']['area'])) {
  1999.                 $this->context['view']->region_name $this->em->getRepository('TheatreCore\Entity\\'.$this->getCarteVersion())->getRegionName($params_sql['special']['area']); // nom de la région
  2000.             } else {
  2001.                 $this->context['view']->country_name $this->em->getRepository('TheatreCore\Entity\\'.$this->getCarteVersion())->getNameCountry($params_sql['special']['area']); // nom de la région
  2002.             }
  2003.             $this->context['view']->area $this->context['params']['area'];
  2004.         }
  2005.         return $params_sql;
  2006.     }
  2007.     // }}}
  2008.     // {{{ getCommonXmlCarte()
  2009.     /** Fichier XML standard de la cartes de France
  2010.      *
  2011.      */
  2012.     public function getCommonXmlCarte($page=null)
  2013.     {
  2014.         // regions
  2015.         $regions $this->em->getRepository('TheatreCore\Entity\\'.$this->getCarteVersion());
  2016.         $regions_list = ($regions->getArea(false,false,false));
  2017.         // affiche la région en surbrillance
  2018.         if(!empty($this->context['params']['area']) &&
  2019.             (is_numeric($this->context['params']['area']) || strlen($this->context['params']['area'])==2)) {
  2020.             $this->context['view']->area_view 'area/'.$this->context['params']['area'].'/';
  2021.             $this->context['view']->area $this->context['params']['area'];
  2022.         } else {
  2023.             $this->context['view']->area_view '';
  2024.             $this->context['view']->area null;
  2025.         }
  2026.         if(!empty($_GET['page'])) {
  2027.             $this->context['view']->page filter_var($_GET['page'], FILTER_SANITIZE_STRING);
  2028.         } elseif(!empty($this->context['params']['page'])) {
  2029.             $this->context['view']->page $this->context['params']['page'];
  2030.         } else {
  2031.             $this->context['view']->page $page;
  2032.         }
  2033.         foreach(array('s','y','datestart','dateend','d','type','idtypestructure') as $f) {
  2034.             if(!empty($_GET[$f])) {
  2035.                 $this->context['view']->$f filter_var($_GET[$f], FILTER_SANITIZE_STRING);
  2036.             }
  2037.         }
  2038.         foreach(array('dom','tom','be','ch','lu') as $f) {
  2039.             if(isset($_GET[$f])) {
  2040.                 $this->context['view']->$f filter_var($_GET[$f], FILTER_SANITIZE_STRING);
  2041.             } else {
  2042.                 $this->context['view']->$f 1;
  2043.             }
  2044.         }
  2045.         // classement en fonction du xml
  2046.         foreach($regions->getXmlClassement() as $k=>$v) {
  2047.             $regions_final[$k] = array(
  2048.                 'id' => $v,
  2049.                 'name' => $regions_list[$v],
  2050.             );
  2051.             if(!empty($this->context['view']->area) && $v==$this->context['view']->area) {
  2052.                 $regions_final[$k]['selected'] = 1;
  2053.             } else {
  2054.                 $regions_final[$k]['selected'] = 0;
  2055.             }
  2056.         }
  2057.         foreach(array('BE','CH','LU') as $k=>$v) {
  2058.             if(!empty($this->context['view']->area) && $v==$this->context['view']->area) {
  2059.                 $this->context['view']->{'selected_'.$v} = 1;
  2060.             } else {
  2061.                 $this->context['view']->{'selected_'.$v} = 0;
  2062.             }
  2063.         }
  2064.         $this->context['view']->regions $regions_final;
  2065.     }
  2066.     // }}}
  2067.     // {{{ getCarteVersion()
  2068.     /** Version SVG bigregion ou Flash
  2069.      *
  2070.      */
  2071.     public function getCarteVersion()
  2072.     {
  2073.         if(isset($_REQUEST['carte_version'])) {
  2074.             $this->carte_version filter_var($_REQUEST['carte_version'], FILTER_SANITIZE_STRING);
  2075.         }
  2076. //        if($this->carte_version=='svg') {
  2077.             $object 'Bigregions';
  2078.             $this->context['view']->carte_version 'svg';
  2079.             $this->context['view']->is_carte_svg true;
  2080. //        } else {
  2081. //            $object = 'Regions';
  2082. //            $this->context['view']->carte_version = 'flash';
  2083. //            $this->context['view']->is_carte_flash = true;
  2084. //            $this->context['view']->jquery_flash = true;
  2085. //
  2086. //        }
  2087.         return $object;
  2088.     }
  2089.     // }}}
  2090.     // {{{ getZoneRecherche()
  2091.     /** Version SVG bigregion ou Flash
  2092.      *
  2093.      */
  2094.     public function getZoneRecherche($area) { return $this->em->getRepository('TheatreCore\Entity\\'.$this->getCarteVersion())->getZipCode($area); }
  2095.     // }}}
  2096.     // {{{ setAreaRecherche()
  2097.     /** Recherche avec region/pays
  2098.      *
  2099.      */
  2100.     public function setAreaRecherche($params_sql) {
  2101.         // une région en particulier ?
  2102.         if(!empty($this->context['params']['area']) && (is_numeric($this->context['params']['area']) || strlen($this->context['params']['area'])==2)) {
  2103.             $this->context['view']->area $this->context['params']['area'];
  2104.             $params_sql['special']['area'] = $this->context['view']->area// recherche dans la région
  2105.             $params_sql['special']['carte_version'] = $this->getCarteVersion(); // recherche dans la région
  2106.             if(is_numeric($this->context['view']->area)) {
  2107.                 $this->context['view']->region_name $this->em->getRepository('TheatreCore\Entity\\'.$this->getCarteVersion())->getRegionName($this->context['view']->area); // nom de la région
  2108.             } else {
  2109.                 $this->context['view']->country_name $this->em->getRepository('TheatreCore\Entity\\'.$this->getCarteVersion())->getNameCountry($this->context['view']->area); // nom de la région
  2110.             }
  2111.             // définir la zone de recherche
  2112.             $this->spectacles->setZoneRecherche($this->em->getRepository('TheatreCore\Entity\\'.$this->getCarteVersion())->getZipCode($this->context['view']->area)); // définir la zone de recherche
  2113.         } else {
  2114.             $this->context['view']->area null;
  2115.         }
  2116.         return $params_sql;
  2117.     }
  2118.     // {{{ setSocialCustomContent()
  2119.     /** Initie des contenus customisés pour les réseaux sociaux
  2120.      *
  2121.      * @return void
  2122.      */
  2123.     public function setSocialCustomContent($contents$reseau_specifique null)
  2124.     {
  2125.         //Si le contenu est un tableau et contient plusieurs valeurs
  2126.         if(is_array($contents)){
  2127.             //Nous faisons une boucle de chaune de ces valeurs
  2128.             foreach($contents AS $key_contents => $value_content){
  2129.                 //Si la valeur contient un nouveau tableau c'est que la clé est le prefix d'un réseau social (fb, tw, ggle etc.)
  2130.                 if(is_array($value_content)){
  2131.                     //Nous assignons à la vue la clé du réseau social et la valeur devat être contenu
  2132.                     foreach($value_content AS $key_contents_2 => $value_content_2){
  2133.                         $this->view->reseaux[$key_contents][$key_contents_2] = $value_content_2;
  2134.                     }
  2135.                 }
  2136.                 //Sinon c'est que les valeurs sont pour un réseau social spécifique
  2137.                 else{
  2138.                     //Si le réseau social spécifique est sélectionné
  2139.                     if(!is_null($reseau_specifique)){
  2140.                         $this->view->reseaux[$reseau_specifique][$key_contents] = $value_content;
  2141.                     }
  2142.                     else{
  2143.                         //A faire
  2144.                         //Boucler les reseaux sociaux déjà disponibles un à un et y assigner les nouvelles valeurs.
  2145.                     }
  2146.                 }
  2147.             }
  2148.         }
  2149.     }
  2150.     public function RouterOptions($slug null$action null$controller null){
  2151.         // debut du tableau params (exclu l'url_clean)
  2152.         $first_param 3;
  2153.         $defaut_value = array(
  2154.             'biographies' => array(
  2155.                 'action' => 'biographie',
  2156.                 'val_id' => 'idperson',
  2157.                 'object' => 'persons',
  2158.             ),
  2159.             'spectacles' => array(
  2160.                 'action' => 'detail-spectacle',
  2161.                 'val_id' => 'idspectacle',
  2162.                 'object' => 'spectacles',
  2163.                 'groups' => array('detail-spectacle' => array(
  2164.                     'ensavoirplus','enimages','entretiens','extraits','commentaires','contenuprofessionnel'
  2165.                 )),
  2166.             ),
  2167.             'textes' => array(
  2168.                 'action' => 'detail-texte',
  2169.                 'val_id' => 'idtext',
  2170.                 'object' => 'texts',
  2171.             ),
  2172.             'liens' => array(
  2173.                 'action' => 'categories',
  2174.                 'default_action' => 'view',
  2175.                 'val_id' => 'idcategorie',
  2176.                 'object' => 'liens_categories',
  2177.             ),
  2178.             'annonces' => array(
  2179.                 'action' => 'categorie',
  2180.                 'val_id' => 'idcategorie',
  2181.                 'object' => 'ann_categories',
  2182.             ),
  2183.             'editions' => array(
  2184.                 'action' => 'details',
  2185.                 'val_id' => 'idcontact',
  2186.                 'object' => 'contacts',
  2187.             ),
  2188.             'contacts' => array(
  2189.                 'action' => 'detail-contact',
  2190.                 'val_id' => 'idcontact',
  2191.                 'object' => 'contacts',
  2192.             ),
  2193.             'video' => array(
  2194.                 'action' => 'view',
  2195.                 'val_id' => 'idmultimedia',
  2196.                 'object' => 'multimedias',
  2197.             ),
  2198.             'dvd' => array(
  2199.                 'action' => 'view',
  2200.                 'val_id' => 'iddvd',
  2201.                 'object' => 'dvds',
  2202.             ),
  2203.             // 'videos' => array(
  2204.             //     'action' => 'view',
  2205.             //     'val_id' => 'idmultimedia',
  2206.             //     'object' => 'multimedias',
  2207.             // ),
  2208.             'embed' => array(
  2209.                 'action' => 'view',
  2210.             )
  2211.         );
  2212.         if(!empty($defaut_value[$controller])) {
  2213.             $object $defaut_value[$controller]['object'];
  2214.         } elseif($controller=='api' || $controller=='widgets') { // API ou widgets
  2215.             // l'action unique
  2216.             $action 'view';
  2217.             // => /api/persons/Olivier-Py
  2218.             // => /controller/view/object/persons/url_clean/Olivier-Py/
  2219.             $path $_SERVER['REQUEST_URI'];
  2220.             $path preg_replace('#\?.*$#','',$path);
  2221.             $path explode('/'trim($path'/'));
  2222.             if(count($path)>=2) {
  2223.                 // redéfinir le path
  2224.                 $new_path = array(
  2225.                     $path[0], // controller
  2226.                     'view'// action (redéfini à la place de l'objet)
  2227.                     'url_clean'// url de l'objet
  2228.                     $path[2], // valeur de l'url (eg: JTN)
  2229.                     'object'// type d'objet
  2230.                     $path[1], // valeur du type d'objet (eg; contacts)
  2231.                 );
  2232.                 // on ajoute ce qu'il y a après 3 => les params
  2233.                 for ($i 3$i<count($path); $i++) {
  2234.                     $new_path[] = $path[$i];
  2235.                 }
  2236.                 $path $new_path;
  2237.                 // params commence à l'index 2 de path
  2238.                 $first_param 2;
  2239.             }
  2240.         } else {
  2241.             $object $controller;
  2242.         }
  2243.         //spécifique à l'embed
  2244.         if($controller=='embed') {
  2245.             $action 'view';
  2246.             // devient [code] => 'le code';
  2247.             $path[2] = $path[1];
  2248.             $path[1] = 'code';
  2249.             $first_param 1;
  2250.         }
  2251.         // rechercher l'url_clean dans la BDD
  2252.         else if(!is_null($slug) && !empty($object)) {
  2253.             // objet
  2254.             $objs $this->em->getRepository('TheatreCore\Entity\\'.implode(''array_map(function($m) { return ucfirst($m); }, explode('_'$object))));
  2255.             // si c'est un spectacle, on va vérifier qu'il n'y a pas un url_redirect
  2256.             if($object=='spectacles') {
  2257.                 // si l'url contient du htm, on matche sur url_redirect
  2258.                 $pos strripos($_SERVER['REQUEST_URI'], '.htm');
  2259.                 // on cherche url_clean
  2260.                 if($pos === false) {
  2261.                     $this->id $objs->queryOne('SELECT '.$objs->__idtable.' FROM '.$object.' WHERE url_clean=\''.$objs->escape($slug).'\' ');
  2262.                 }
  2263.                 // ou url_redirect
  2264.                 if(empty($this->id)) {
  2265.                     preg_match('/spectacles\/([a-z,A-Z,\-,\_,0-9]+)\//',$_SERVER['REQUEST_URI'],$match);
  2266.                     if(!empty($match)) {
  2267.                         $path_url $match[1];
  2268.                         if(!empty($path_url)) {
  2269.                             $url_clean $objs->queryOne('SELECT url_clean FROM '.$object.' WHERE url_redirect=\''.$objs->escape($path_url).'\' ');
  2270.                             if(!empty($url_clean)) {
  2271.                                 // TODO utiliser un $this->redirect (!! on a un replace false, donc on veut conserver les param de la requête)
  2272.                                 header('HTTP/1.1 301 Moved Permanently'false301);
  2273.                                 header('Location: /spectacles/'.$url_clean.'/');
  2274.                                 exit();
  2275.                             }
  2276.                         }
  2277.                     }
  2278.                 }
  2279.             }
  2280.             else {
  2281.                 $this->id $objs->queryOne('SELECT '.$objs->__idtable.' FROM '.$object.' WHERE url_clean=\''.$objs->escape($slug).'\' ');
  2282.                 // si object contact mais id vide
  2283.                 if(empty($this->id) && $object=='contacts') {
  2284.                     $url_clean $objs->queryOne('SELECT url_clean FROM '.$object.' WHERE url_redirect=\''.$objs->escape($slug).'\' ');
  2285.                     if(!empty($url_clean)) {
  2286. //                        header('HTTP/1.1 301 Moved Permanently', false, 301);
  2287. //                        var_dump($path);
  2288. //                        exit;
  2289.                         return $this->redirectToRoute('contact_view', ['slug' => $url_clean]);
  2290.                     }
  2291.                 }
  2292.             }
  2293.             // on a une url_clean
  2294.             if(!empty($this->id)) {
  2295.                 $this->view->url_clean $slug;
  2296.                 // si il y un id mais que $action est vide, prendre l'action par defaut
  2297.                 if(empty($action)) {
  2298.                     $this->action $defaut_value[$controller]['action'];
  2299.                 }
  2300.                 // definir la valeur de l'id
  2301.                 $defaut_value[$controller]['val_id'] = $this->id;
  2302.             } else { // on n'a pas l'id mais on avait le path[1]
  2303.                 // erreur spécifique pour les widgets
  2304.                 if($action=='widget') {
  2305.                     $this->func->sendHeader(404,true); // header et exit
  2306.                 }
  2307.             }
  2308.             // debug
  2309.             // $controller.' '.$action;
  2310.         }
  2311.     }
  2312.     public function now() {
  2313.         return date('Y-m-d H:i:s');
  2314.     }
  2315.     public function escape($str) {
  2316.         return addslashes($str);
  2317.     }
  2318.     public function db_escape_string($str) {
  2319.         return $this->escape($str);
  2320.     }
  2321.     public function setParamsPDF($p_pdf null$p_download null) {
  2322.         if(!is_null($p_pdf)){
  2323.             $this->context['params']['pdf'] = $p_pdf;
  2324.         }
  2325.         if(!is_null($p_download)){
  2326.             $this->context['params']['download'] = $p_download;
  2327.         }
  2328.     }
  2329.     public function checkConditionsPDF($abonnements true) {
  2330.         $active true;
  2331.         //Si nous voulons que l'utilisateur soit abonné et qu'il ne l'es pas.
  2332.         if($abonnements && !$this->abonnementIsActive()){
  2333.             $active false;
  2334.         }
  2335.         if($active && !empty($this->context['params']['pdf']) && $this->context['params']['pdf']){
  2336.             $this->context['pdf'] = true;
  2337.         }
  2338.     }
  2339.     public function addPubliciteGoogle()
  2340.     {
  2341.         $asides_publicite = new asides();
  2342.         asides::setEntityManager($this->em);
  2343.         asides::loadaside('Publicite')->addGoogle($asides_publicite$this->serviceAbonnements);
  2344.         $this->context['view']->asides_publicite $asides_publicite->view($this->context['view']);
  2345.     }
  2346.     public function abonnementIsActive(){
  2347.         return (isset($this->serviceAbonnements) && $this->serviceAbonnements->isActive());
  2348.     }
  2349.     public function video_populaire($globalstats null)
  2350.     {
  2351.         if(is_null($globalstats)){
  2352.             return [];
  2353.         }
  2354.         //Les fichiers multimedias que l'on ne souhaite pas voir afficher en page d'accueil
  2355.         $multimedia_exclude = array(5126,6056,11808,11863,11868,11899,11895,11897,11901,2024);
  2356.         $plusvues $globalstats->getMostViewed(1,4,$multimedia_exclude);
  2357.         $multimedias $this->em->getRepository(Multimedias::class);
  2358.         $plusvues_videos = [];
  2359.         if(!empty($plusvues)) {
  2360.             foreach($plusvues as $k=>$v) {
  2361.                 $idmultimedia_plusvues[] = $v["idmultimedia"];
  2362.             }
  2363.             if(!empty($idmultimedia_plusvues)) {
  2364.                 $params_query_plusvues = array(
  2365.                     'limit' => array(0,4),
  2366.                     'where' => array(array('multimedias''idmultimedia'$idmultimedia_plusvues)),
  2367.                     'order' => array(array('multimedias','idmultimedia',$idmultimedia_plusvues)), // classement FIELD()
  2368.                     'direction' => 'no',
  2369.                     'dbg' => array('plusvues','Vidéos les plus vues'),
  2370.                 );
  2371.                 $plusvues_videos $multimedias->getListMultimedias($params_query_plusvues,
  2372.                     array('width' => getenv('VIGN_VIDEO_WIDTH'),'height' => getenv('VIGN_VIDEO_HEIGHT'),'fleche'=>'none','ratio' => '169'),
  2373.                     array('display' => array('no_footer' => true))
  2374.                 );
  2375.             }
  2376.         }
  2377.         return $plusvues_videos;
  2378.     }
  2379. }