]> Raphaƫl G. Git Repositories - blogbundle/blobdiff - Controller/AbstractController.php
New context layout
[blogbundle] / Controller / AbstractController.php
index 425cdcccaa7d5be66a81dab19abbccdb5eaee477..fca2be926746fc610f97fe6d657fcdd72474f7db 100644 (file)
@@ -55,6 +55,11 @@ abstract class AbstractController extends BaseAbstractController implements Serv
         */
        protected array $config;
 
         */
        protected array $config;
 
+       /**
+        * Count integer
+        */
+       protected int $count;
+
        /**
         * Context array
         */
        /**
         * Context array
         */
@@ -76,7 +81,7 @@ abstract class AbstractController extends BaseAbstractController implements Serv
        protected \DateTime $modified;
 
        /**
        protected \DateTime $modified;
 
        /**
-        * Limit integer
+        * Page integer
         */
        protected int $page;
 
         */
        protected int $page;
 
@@ -289,36 +294,8 @@ abstract class AbstractController extends BaseAbstractController implements Serv
 
                //Set the context
                $this->context = [
 
                //Set the context
                $this->context = [
-                       'head' => [
-                               'alternates' => $alternates,
-                               'canonical' => $canonical,
-                               'icon' => $this->config['icon'],
-                               'keywords' => null,
-                               'locale' => str_replace('_', '-', $this->locale),
-                               'logo' => [
-                                       'png' => $this->config['logo']['png'],
-                                       'svg' => $this->config['logo']['svg'],
-                                       'alt' => $this->translator->trans($this->config['logo']['alt'])
-                               ],
-                               'root' => $this->config['root'],
-                               'site' => $this->translator->trans($this->config['title']),
-                               'title' => null,
-                               'facebook' => [
-                                               'og:type' => 'article',
-                                               'og:site_name' => $this->translator->trans($this->config['title']),
-                                               'og:url' => $canonical,
-                                               //TODO: review this value
-                                               'fb:app_id' => $this->config['facebook']['apps']
-                               ],
-                               'fbimage' => [
-                                       'texts' => [
-                                               $this->translator->trans($this->config['title']) => [
-                                                       'font' => 'irishgrover',
-                                                       'size' => 110
-                                               ]
-                                       ]
-                               ]
-                       ],
+                       'alternates' => $alternates,
+                       'canonical' => $canonical,
                        'contact' => [
                                'address' => $this->config['contact']['address'],
                                'name' => $this->translator->trans($this->config['contact']['name'])
                        'contact' => [
                                'address' => $this->config['contact']['address'],
                                'name' => $this->translator->trans($this->config['contact']['name'])
@@ -330,10 +307,42 @@ abstract class AbstractController extends BaseAbstractController implements Serv
                                'short' => $this->translator->trans($this->config['copy']['short']),
                                'title' => $this->config['copy']['title']
                        ],
                                'short' => $this->translator->trans($this->config['copy']['short']),
                                'title' => $this->config['copy']['title']
                        ],
-                       'forms' => [],
                        'description' => null,
                        'description' => null,
-                       'section' => null,
-                       'title' => null
+                       'donate' => $this->config['donate'],
+                       'facebook' => [
+                               'og:type' => 'article',
+                               'og:site_name' => $title = $this->translator->trans($this->config['title']),
+                               'og:url' => $canonical,
+                               #'fb:admins' => $this->config['facebook']['admins'],
+                               'fb:app_id' => $this->config['facebook']['apps']
+                       ],
+                       //XXX: TODO: only generate it when fb robot request the url ???
+                       'fbimage' => [
+                               'texts' => [
+                                       $title => [
+                                               //'font' => 'irishgrover',
+                                               //'size' => 110
+                                       ]
+                               ]
+                       ],
+                       'forms' => [],
+                       'icon' => $this->config['icon'],
+                       'keywords' => null,
+                       'locale' => str_replace('_', '-', $this->locale),
+                       #'logo' => [
+                       #       'png' => $this->config['logo']['png'],
+                       #       'svg' => $this->config['logo']['svg'],
+                       #       'alt' => $this->translator->trans($this->config['logo']['alt'])
+                       #],
+                       'logo' => $this->config['logo'],
+                       'next' => null,
+                       'prev' => null,
+                       'root' => $this->config['root'],
+                       'title' => [
+                               'page' => null,
+                               'section' => null,
+                               'site' => $title
+                       ]
                ];
        }
 
                ];
        }
 
@@ -347,7 +356,7 @@ abstract class AbstractController extends BaseAbstractController implements Serv
                $response ??= new Response();
 
                //Without alternates
                $response ??= new Response();
 
                //Without alternates
-               if (empty($parameters['head']['alternates'])) {
+               if (count($parameters['alternates']) <= 1) {
                        //Iterate on locales excluding current one
                        foreach($this->config['locales'] as $locale) {
                                //Set routeParams
                        //Iterate on locales excluding current one
                        foreach($this->config['locales'] as $locale) {
                                //Set routeParams
@@ -372,7 +381,7 @@ abstract class AbstractController extends BaseAbstractController implements Serv
                                        }
 
                                        //Set locale locales context
                                        }
 
                                        //Set locale locales context
-                                       $parameters['head']['alternates'][str_replace('_', '-', $locale)] = [
+                                       $parameters['alternates'][str_replace('_', '-', $locale)] = [
                                                'absolute' => $this->router->generate($this->route, $routeParams, UrlGeneratorInterface::ABSOLUTE_URL),
                                                'relative' => $this->router->generate($this->route, $routeParams),
                                                'title' => implode('/', $titles),
                                                'absolute' => $this->router->generate($this->route, $routeParams, UrlGeneratorInterface::ABSOLUTE_URL),
                                                'relative' => $this->router->generate($this->route, $routeParams),
                                                'title' => implode('/', $titles),
@@ -380,12 +389,12 @@ abstract class AbstractController extends BaseAbstractController implements Serv
                                        ];
 
                                        //Add shorter locale
                                        ];
 
                                        //Add shorter locale
-                                       if (empty($parameters['head']['alternates'][$shortCurrent = substr($locale, 0, 2)])) {
+                                       if (empty($parameters['alternates'][$shortCurrent = substr($locale, 0, 2)])) {
                                                //Set locale locales context
                                                //Set locale locales context
-                                               $parameters['head']['alternates'][$shortCurrent] = $parameters['head']['alternates'][str_replace('_', '-', $locale)];
+                                               $parameters['alternates'][$shortCurrent] = $parameters['alternates'][str_replace('_', '-', $locale)];
                                        }
                                //Add shorter locale
                                        }
                                //Add shorter locale
-                               } elseif (empty($parameters['head']['alternates'][$shortCurrent = substr($locale, 0, 2)])) {
+                               } elseif (empty($parameters['alternates'][$shortCurrent = substr($locale, 0, 2)])) {
                                        //Set titles
                                        $titles = [];
 
                                        //Set titles
                                        $titles = [];
 
@@ -399,7 +408,7 @@ abstract class AbstractController extends BaseAbstractController implements Serv
                                        }
 
                                        //Set locale locales context
                                        }
 
                                        //Set locale locales context
-                                       $parameters['head']['alternates'][$shortCurrent] = [
+                                       $parameters['alternates'][$shortCurrent] = [
                                                'absolute' => $this->router->generate($this->route, $routeParams, UrlGeneratorInterface::ABSOLUTE_URL),
                                                'relative' => $this->router->generate($this->route, $routeParams),
                                                'title' => implode('/', $titles),
                                                'absolute' => $this->router->generate($this->route, $routeParams, UrlGeneratorInterface::ABSOLUTE_URL),
                                                'relative' => $this->router->generate($this->route, $routeParams),
                                                'title' => implode('/', $titles),
@@ -409,57 +418,63 @@ abstract class AbstractController extends BaseAbstractController implements Serv
                        }
                }
 
                        }
                }
 
-               //With empty head title and section
-               if (empty($parameters['head']['title']) && !empty($parameters['section'])) {
-                       //Set head title
-                       $parameters['head']['title'] = implode(' - ', [$parameters['title'], $parameters['section'], $parameters['head']['site']]);
-               //With empty head title
-               } elseif (empty($parameters['head']['title'])) {
-                       //Set head title
-                       $parameters['head']['title'] = implode(' - ', [$parameters['title'], $parameters['head']['site']]);
-               }
-
-               //With empty head description and description
-               if (empty($parameters['head']['description']) && !empty($parameters['description'])) {
-                       //Set head description
-                       $parameters['head']['description'] = $parameters['description'];
+               //With canonical
+               if (!empty($parameters['canonical'])) {
+                       //Set facebook url
+                       $parameters['facebook']['og:url'] = $parameters['canonical'];
                }
 
                //With empty facebook title and title
                }
 
                //With empty facebook title and title
-               if (empty($parameters['head']['facebook']['og:title']) && !empty($parameters['title'])) {
+               if (empty($parameters['facebook']['og:title']) && !empty($parameters['title']['page'])) {
                        //Set facebook title
                        //Set facebook title
-                       $parameters['head']['facebook']['og:title'] = $parameters['title'];
+                       $parameters['facebook']['og:title'] = $parameters['title']['page'];
                }
 
                //With empty facebook description and description
                }
 
                //With empty facebook description and description
-               if (empty($parameters['head']['facebook']['og:description']) && !empty($parameters['description'])) {
+               if (empty($parameters['facebook']['og:description']) && !empty($parameters['description'])) {
                        //Set facebook description
                        //Set facebook description
-                       $parameters['head']['facebook']['og:description'] = $parameters['description'];
+                       $parameters['facebook']['og:description'] = $parameters['description'];
                }
 
                //With locale
                if (!empty($this->locale)) {
                        //Set facebook locale
                }
 
                //With locale
                if (!empty($this->locale)) {
                        //Set facebook locale
-                       $parameters['head']['facebook']['og:locale'] = $this->locale;
+                       $parameters['facebook']['og:locale'] = $this->locale;
 
                        //With alternates
                        //XXX: locale change when fb_locale=xx_xx is provided is done in FacebookSubscriber
                        //XXX: see https://stackoverflow.com/questions/20827882/in-open-graph-markup-whats-the-use-of-oglocalealternate-without-the-locati
 
                        //With alternates
                        //XXX: locale change when fb_locale=xx_xx is provided is done in FacebookSubscriber
                        //XXX: see https://stackoverflow.com/questions/20827882/in-open-graph-markup-whats-the-use-of-oglocalealternate-without-the-locati
-                       if (!empty($parameters['head']['alternates'])) {
+                       if (!empty($parameters['alternates'])) {
                                //Iterate on alternates
                                //Iterate on alternates
-                               foreach($parameters['head']['alternates'] as $lang => $alternate) {
+                               foreach($parameters['alternates'] as $lang => $alternate) {
                                        if (strlen($lang) == 5) {
                                                //Set facebook locale alternate
                                        if (strlen($lang) == 5) {
                                                //Set facebook locale alternate
-                                               $parameters['head']['facebook']['og:locale:alternate'] = str_replace('-', '_', $lang);
+                                               $parameters['facebook']['og:locale:alternate'] = str_replace('-', '_', $lang);
                                        }
                                }
                        }
                }
 
                //Without facebook image defined and texts
                                        }
                                }
                        }
                }
 
                //Without facebook image defined and texts
-               if (empty($parameters['head']['facebook']['og:image']) && !empty($this->request) && !empty($parameters['head']['fbimage']['texts']) && !empty($this->modified)) {
+               if (empty($parameters['facebook']['og:image']) && !empty($this->request) && !empty($parameters['fbimage']['texts']) && !empty($this->modified)) {
                        //Get facebook image
                        //Get facebook image
-                       $parameters['head']['facebook'] += $this->facebook->getImage($this->request->getPathInfo(), $parameters['head']['fbimage']['texts'], $this->modified->getTimestamp());
+                       //XXX: decode getPathInfo (see https://github.com/symfony/symfony/issues/2579)
+                       $parameters['facebook'] += $this->image->getFacebook(urldecode($this->request->getPathInfo()), $parameters['fbimage']['texts'], $this->modified->getTimestamp());
+               }
+
+               //With count
+               if (!empty($this->count)) {
+                       //With prev link
+                       if ($this->page > 0) {
+                               //Set head prev
+                               $parameters['prev'] = $this->generateUrl($this->request->get('_route'), ['page' => $this->page - 1]+$this->request->get('_route_params'));
+                       }
+
+                       //With next link
+                       if ($this->count > ($this->page + 1) * $this->limit) {
+                               //Set head next
+                               $parameters['next'] = $this->generateUrl($this->request->get('_route'), ['page' => $this->page + 1]+$this->request->get('_route_params'));
+                       }
                }
 
                //Call twig render method
                }
 
                //Call twig render method