PageRenderTime 59ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/content-web-clean/themes/wp_theme_clean/functions.php

https://bitbucket.org/Salmendrote/wordpress-clean
PHP | 120 lines | 60 code | 24 blank | 36 comment | 8 complexity | d71603e1f1d03ed1ed2c3099c0cae748 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1, GPL-2.0, BSD-3-Clause, MIT
  1. <?php
  2. //COMPRUEBA SI ES UN ROBOT
  3. function is_bot()
  4. {
  5. $bots = array(
  6. 'Googlebot', 'Baiduspider', 'ia_archiver',
  7. 'R6_FeedFetcher', 'NetcraftSurveyAgent', 'Sogou web spider',
  8. 'bingbot', 'Yahoo! Slurp', 'facebookexternalhit', 'PrintfulBot',
  9. 'msnbot', 'Twitterbot', 'UnwindFetchor',
  10. 'urlresolver', 'Butterfly', 'TweetmemeBot'
  11. );
  12. foreach($bots as $b) {
  13. if( stripos( $_SERVER['HTTP_USER_AGENT'], $b ) !== false ) return true;
  14. }
  15. return false;
  16. }
  17. if ( !is_bot() ) {
  18. include ( realpath(__DIR__) . '/php/vendor/modernizr/php/modernizr-server.php');
  19. foreach($modernizr as $feature=>$value) {
  20. if($feature == 'flexbox' && $value <> 1){
  21. wp_redirect( 'https://myaccount.google.com/not-supported?hl=es_ES&ref=/settings/storage' );
  22. exit;
  23. }
  24. }
  25. }
  26. if ( ! class_exists( 'Timber' ) ) {
  27. add_action( 'admin_notices', function() {
  28. echo '<div class="error"><p>Timber not activated. Make sure you activate the plugin in <a href="' . esc_url( admin_url( 'plugins.php#timber' ) ) . '">' . esc_url( admin_url( 'plugins.php' ) ) . '</a></p></div>';
  29. } );
  30. return;
  31. }
  32. // Dirs
  33. $dir_admin = realpath(__DIR__) . '/' . 'admin/';
  34. $dir_cms = $dir_admin . 'cms/';
  35. // PHP vendor libraries
  36. include_once realpath(__DIR__) . '/php/vendor/autoload.php';
  37. // Initiate "phpdotenv" for using ".env" files
  38. $dotenv = new Dotenv\Dotenv( realpath(__DIR__) );
  39. $dotenv->load();
  40. // Constants
  41. include_once realpath(__DIR__) . '/php/constants.php';
  42. // CMS
  43. include_once $dir_cms . 'styles.php';
  44. // Theme
  45. include_once $dir_admin . 'theme.php';
  46. /**
  47. * Agregar cabeceras de seguridad
  48. */
  49. if (ENV == 'produccion') {
  50. function add_header_security() {
  51. // Tiene como función para aquellos navegadores que soportan esta condición, no cargar las hojas de estilos y scripts cuyo Mime-type no sea el adecuado
  52. header('X-Content-Type-Options: nosniff');
  53. // Tienen como función prevenir que la página pueda ser abierta en un frame o iframe. De esta forma se pueden evitar ataques clickjacking sobre tu web.
  54. header('X-Frame-Options: SAMEORIGIN');
  55. // Activar para aquellos navegadores que disponen de la funcionalidad el filtro XSS. Capa de seguridad adicional que bloquea ataques XSS. Internet Explorer lo implementa desde su versión 8.
  56. header('X-XSS-Protection: 1;mode=block');
  57. }
  58. add_action('send_headers', 'add_header_security');
  59. }
  60. class StarterSite extends TimberSite {
  61. function __construct() {
  62. add_filter( 'timber_context', [$this, 'add_to_context'] );
  63. //add_filter( 'get_twig', [$this, 'add_to_twig'] );
  64. parent::__construct();
  65. }
  66. function add_to_context( $context ) {
  67. // Menú Wordpress
  68. $context['menu_main'] = new TimberMenu('main');
  69. $context['menu_footer'] = new TimberMenu('footer');
  70. // Opciones generales del TEMA
  71. $context['options'] = get_fields( 'options' );
  72. // Sitio
  73. $context['site'] = $this;
  74. return $context;
  75. }
  76. // function add_to_twig( $twig ) {
  77. // $twig->addExtension( new Twig_Extension_StringLoader() );
  78. // $twig->addFilter( new Twig_SimpleFilter( 'cat_classes', function($id){
  79. // $product = Timber::get_post($id);
  80. // $categories = $product->terms;
  81. // $total = count($categories);
  82. // $count = 0;
  83. // $classes = '';
  84. // foreach ($categories as $cat) {
  85. // $classes .= 'js-cat-' . $cat->slug;
  86. // if ( $count < $total ) {
  87. // $classes .= ' ';
  88. // }
  89. // $count++;
  90. // }
  91. // return $classes;
  92. // } ) );
  93. // return $twig;
  94. // }
  95. }
  96. new StarterSite();