PageRenderTime 24ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/wp-content/themes/vtte-base/functions.php

https://gitlab.com/VTTE/sitios-vtte
PHP | 415 lines | 310 code | 29 blank | 76 comment | 27 complexity | 11d4c082b0bce9af02afa24cd1ca0a71 MD5 | raw file
  1. <?php
  2. /**
  3. * Functions: lista de funciones del theme vtte-editorial
  4. * Funciones nuevas para el sitio
  5. * Editorial UTEM
  6. * @version 2.0
  7. * @package vtte
  8. */
  9. use GutenPress\Forms;
  10. use GutenPress\Forms\Element;
  11. use GutenPress\Validate;
  12. use GutenPress\Validate\Validations;
  13. use GutenPress\Model;
  14. /* Theme Constants (to speed up some common things) ------*/
  15. define('HOME_URI', get_bloginfo( 'url' ));
  16. define('PRE_HOME_URI',get_bloginfo('url').'/wp-content/themes');
  17. define('SITE_NAME', get_bloginfo( 'name' ));
  18. define('THEME_URI', get_template_directory_uri());
  19. define('THEME_IMG', THEME_URI . '/img');
  20. define('THEME_CSS', THEME_URI . '/css');
  21. define('THEME_FONTS', THEME_URI . '/fonts');
  22. define('PRE_THEME_JS', PRE_HOME_URI . '/js');
  23. define('PRE_THEME_CSS', PRE_HOME_URI . '/vtte-base/css');
  24. define('THEME_JS', THEME_URI. '/js');
  25. define('MULTILINGUAL', function_exists( 'qtrans_use' ));
  26. /*
  27. calling related files
  28. */
  29. include TEMPLATEPATH . '/inc/widgets.php';
  30. include TEMPLATEPATH . '/inc/settings.php';
  31. include TEMPLATEPATH . '/inc/site.php';
  32. include TEMPLATEPATH . '/inc/search_filter.php';
  33. include TEMPLATEPATH . '/inc/helpers.php';
  34. /**
  35. * Images
  36. * ------
  37. * */
  38. // Add theme suppor for post thumbnails
  39. add_theme_support( 'post-thumbnails' );
  40. // Define the default post thumbnail size
  41. // set_post_thumbnail_size( 200, 130, true );
  42. // Define custom thumbnail sizes
  43. // add_image_size( $name, $width, $height, $crop );
  44. add_image_size('squared', 300, 300, true);
  45. add_image_size('featured-page', 570, 385, true);
  46. add_image_size('letter', 315, 390, true);
  47. add_image_size('side-img', 150, 9999, false);
  48. add_image_size('page-featured', 1170, 383, true);
  49. add_image_size('landscape-small', 215, 100, true);
  50. // add_image_size('thumbnail-home', 290, 180, true);
  51. // add_image_size('post-image', 640, 300, true);
  52. // add_image_size('main-feature', 727, 317, true);
  53. /*
  54. REGISTER SIDEBARS
  55. */
  56. /*
  57. Theme sidebars
  58. */
  59. $mandatory_sidebars = array(
  60. 'Página' => array(
  61. 'name' => 'page',
  62. 'size' => 4
  63. ),
  64. 'Página contenido' => array(
  65. 'name' => 'page_contenido',
  66. 'size' => 4
  67. ),
  68. 'Página footer 1' => array(
  69. 'name' => 'page_footer_1',
  70. 'size' => 6
  71. ),
  72. 'Página footer 2' => array(
  73. 'name' => 'page_footer_2',
  74. 'size' => 3
  75. ),
  76. 'Página footer 3' => array(
  77. 'name' => 'page_footer_3',
  78. 'size' => 3
  79. ),
  80. 'Entrada' => array(
  81. 'name' => 'single',
  82. 'size' => 4
  83. ),
  84. 'Entrada footer 1' => array(
  85. 'name' => 'single_footer_1',
  86. 'size' => 6
  87. ),
  88. 'Entrada footer 2' => array(
  89. 'name' => 'single_footer_2',
  90. 'size' => 3
  91. ),
  92. 'Entrada footer 3' => array(
  93. 'name' => 'single_footer_3',
  94. 'size' => 3
  95. ),
  96. );
  97. $mandatory_sidebars = apply_filters('vtte_base_mandatory_sidebars',$mandatory_sidebars);
  98. foreach ( $mandatory_sidebars as $sidebar => $id_sidebar ) {
  99. register_sidebar( array(
  100. 'name' => $sidebar,
  101. 'id' => $id_sidebar['name'],
  102. 'before_widget' => '<section id="%1$s" class="widget %2$s">'."\n",
  103. 'after_widget' => '</section>',
  104. 'before_title' => '<header class="widget-header"><h3 class="widget-title">',
  105. 'after_title' => '</h3></header>',
  106. 'size' => $id_sidebar['size']
  107. ) );
  108. }
  109. /**
  110. * Theme specific stuff
  111. * --------------------
  112. * */
  113. /**
  114. * Theme singleton class
  115. * ---------------------
  116. * Stores various theme and site specific info and groups custom methods
  117. **/
  118. class site {
  119. private static $instance;
  120. protected $settings;
  121. const id = __CLASS__;
  122. const theme_ver = '20140624';
  123. const theme_settings_permissions = 'edit_theme_options';
  124. private function __construct(){
  125. /**
  126. * Get our custom theme options so we can easily access them
  127. * on templates or other admin pages
  128. * */
  129. // $this->settings = get_option( __CLASS__ .'_theme_settings' );
  130. $this->actions_manager();
  131. }
  132. public function __get($key){
  133. return isset($this->$key) ? $this->$key : null;
  134. }
  135. public function __isset($key){
  136. return isset($this->$key);
  137. }
  138. public static function get_instance(){
  139. if ( !isset(self::$instance) ){
  140. $c = __CLASS__;
  141. self::$instance = new $c;
  142. }
  143. return self::$instance;
  144. }
  145. public function __clone(){
  146. trigger_error( 'Clone is not allowed.', E_USER_ERROR );
  147. }
  148. /**
  149. * Setup theme actions, both in the front and back end
  150. * */
  151. public function actions_manager(){
  152. if ( is_admin() ) {
  153. //
  154. } else {
  155. //add_filter('wp_title', array($this, 'original_title'), 1, 1);
  156. //add_filter('wp_title', array($this, 'wp_title'), 99, 3);
  157. //add_filter('wpseo_canonical', array($this, 'canonical'), 99, 1);
  158. //add_filter('request', array($this, 'filter_request'));
  159. }
  160. add_action( 'after_setup_theme', array($this, 'setup_theme') );
  161. add_action( 'wp_enqueue_scripts', array($this, 'enqueue_styles') );
  162. add_action( 'wp_enqueue_scripts', array($this, 'enqueue_scripts') );
  163. add_action( 'enqueue_scripts', array($this, 'enqueue_scripts') );
  164. add_action( 'admin_enqueue_scripts', array($this, 'admin_enqueue_scripts') );
  165. add_action('init', array($this, 'init_functions') );
  166. add_action('init', array($this,'register_menus_locations') );
  167. }
  168. public function init_functions() {
  169. add_post_type_support( 'page', 'excerpt' );
  170. register_post_status( 'suspended', array(
  171. 'label' => 'Suspendida',
  172. 'public' => true,
  173. 'show_in_admin_all_list' => true,
  174. 'show_in_admin_status_list' => true,
  175. 'exclude_from_search' => false
  176. ) );
  177. add_action('do_faviconico', array($this,'set_default_favicon'), 10);
  178. }
  179. public function set_default_favicon() {
  180. wp_redirect(PRE_HOME_URI.'/img/favicon-utem-vcm.png');
  181. exit;
  182. }
  183. /**
  184. * habilitar funcionalidades del tema
  185. * @return void
  186. */
  187. public function setup_theme(){
  188. // habilitar post formats
  189. add_theme_support('post-formats', array('gallery', 'image', 'video', 'audio'));
  190. add_theme_support('post-thumbnails');
  191. add_theme_support('automatic_feed_links');
  192. add_theme_support('menus');
  193. }
  194. public function register_menus_locations(){
  195. register_nav_menus(array(
  196. 'principal' => 'Menú Principal',
  197. 'header_aux' => 'Auxiliar',
  198. 'footer_1' => 'Footer Col 1',
  199. 'footer_2' => 'Footer Col 2',
  200. 'footer_3' => 'Footer Col 3'
  201. ));
  202. }
  203. public function get_post_thumbnail_url( $postid = null, $size = 'landscape-medium' ){
  204. if ( is_null($postid) ){
  205. global $post;
  206. $postid = $post->ID;
  207. }
  208. $thumb_id = get_post_thumbnail_id( $postid );
  209. $img_src = wp_get_attachment_image_src( $thumb_id, $size );
  210. return $img_src ? current( $img_src ) : '';
  211. }
  212. public function enqueue_styles(){
  213. // Front-end styles
  214. //wp_enqueue_style( 'vtte_font', THEME_URI.'/font/stylesheet.css' );
  215. wp_enqueue_style( 'vtte_style_base', PRE_HOME_URI.'/vtte-base/style.css' );
  216. wp_enqueue_style( 'vtte_style', get_stylesheet_uri() );
  217. wp_enqueue_style( 'slick', THEME_JS .'/slick/slick.css');
  218. // wp_enqueue_style( 'slick', THEME_JS .'/slick/slick.css');
  219. wp_enqueue_style( 'slick-theme', THEME_JS .'/slick/slick-theme.css');
  220. wp_enqueue_style( 'swipebox', PRE_THEME_CSS .'/swipebox.min.css');
  221. wp_enqueue_style( 'ionicons', 'https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css' );
  222. wp_enqueue_style( 'dashicons' );
  223. }
  224. function admin_enqueue_scripts(){
  225. // admin scripts
  226. global $pagenow;
  227. // wp_enqueue_script( 'theme_admin_scripts', THEME_JS .'/admin_scripts.js', array('jquery'), true );
  228. if ( is_admin() && (($pagenow == 'index.php' ) || ($pagenow == 'admin.php')) ) {
  229. if ($_GET['page'] == 'vtte-site-settings')
  230. wp_enqueue_media();
  231. //wp_enqueue_script( 'script-admin', THEME_JS . '/admin_scripts.js', array('jquery'), THEME_VERSION );
  232. }
  233. if (is_admin() && ( ($pagenow == 'link-add.php') || ( $pagenow == 'link.php' ) ) ) {
  234. wp_enqueue_media();
  235. }
  236. if ( is_admin() && ($pagenow == 'widgets.php' ) ) {
  237. wp_enqueue_media();
  238. wp_enqueue_script( 'script-admin', THEME_JS . '/admin_scripts.js', array('jquery'), THEME_VERSION );
  239. }
  240. // if ($pagenow == 'nav-menus.php' || $pagenow == 'edit-tags.php') {
  241. // wp_enqueue_media();
  242. // }
  243. }
  244. function enqueue_scripts(){
  245. // front-end scripts
  246. wp_enqueue_script( 'jquery' );
  247. wp_enqueue_script( 'modernizr', PRE_THEME_JS .'/modernizr.js', array('jquery'), self::theme_ver, '' );
  248. /*foundation JS*/
  249. wp_enqueue_script( 'Foundation', THEME_JS .'/foundation.core.js', array('jquery'), self::theme_ver, '' );
  250. wp_enqueue_script( 'foundation-timer-image', THEME_JS.'/foundation.util.timerAndImageLoader.js',
  251. array('jquery'), self::theme_ver, '' );
  252. wp_enqueue_script( 'Foundation-mediaquery', THEME_JS .'/foundation.util.mediaQuery.js', array('Foundation'), self::theme_ver, '' );
  253. wp_enqueue_script( 'Foundation-util-box', THEME_JS .'/foundation.util.box.js', array('Foundation'), self::theme_ver, '' );
  254. wp_enqueue_script( 'Foundation-util-keyboard', THEME_JS .'/foundation.util.keyboard.js', array('Foundation'), self::theme_ver, '' );
  255. wp_enqueue_script( 'Foundation-util-nest', THEME_JS .'/foundation.util.nest.js', array('Foundation'), self::theme_ver, '' );
  256. wp_enqueue_script( 'Foundation-equalizer', THEME_JS .'/foundation.equalizer.js', array('Foundation'), self::theme_ver, '' );
  257. wp_enqueue_script( 'Foundation-dropdown-menu', THEME_JS .'/foundation.dropdownMenu.js', array('Foundation'), self::theme_ver, '' );
  258. wp_enqueue_script( 'Foundation-accordion', THEME_JS . '/foundation.accordion.js', array('Foundation'), self::theme_ver, '');
  259. wp_enqueue_script( 'Foundation-accordion-menu', THEME_JS .'/foundation.accordionMenu.js', array('Foundation'), self::theme_ver, '' );
  260. wp_enqueue_script( 'Foundation-drilldown', THEME_JS .'/foundation.drilldown.js', array('Foundation'), self::theme_ver, '' );
  261. wp_enqueue_script( 'Foundation-dropdown', THEME_JS .'/foundation.dropdown.js', array('Foundation'), self::theme_ver, '' );
  262. wp_enqueue_script( 'Foundation-responsiveMenu', THEME_JS .'/foundation.responsiveMenu.js', array('Foundation'), self::theme_ver, '' );
  263. wp_enqueue_script( 'Foundation-responsiveToggle', THEME_JS .'/foundation.responsiveToggle.js', array('Foundation'), self::theme_ver, '' );
  264. wp_enqueue_script( 'Foundation-triggers', THEME_JS .'/foundation.util.triggers.js', array('Foundation'), self::theme_ver, '' );
  265. wp_enqueue_script( 'Foundation-sticky', THEME_JS .'/foundation.sticky.js', array('Foundation'), self::theme_ver, '' );
  266. wp_enqueue_script( 'Foundation-abide', THEME_JS .'/foundation.abide.js', array('Foundation'), self::theme_ver, '' );
  267. wp_enqueue_script('Foundation-tabs', THEME_JS . '/foundation.tabs.js', array('Foundation'), self::theme_ver, '');
  268. wp_enqueue_script( 'Slick', PRE_THEME_JS .'/slick.min.js', array('jquery'), self::theme_ver, '' );
  269. wp_enqueue_script( 'Swipebox', PRE_THEME_JS .'/swipebox.min.js', array('jquery'), self::theme_ver, '' );
  270. //wp_enqueue_script( 'isotope', PRE_THEME_JS .'/masonry.js', array('jquery'), self::theme_ver, '' );
  271. wp_enqueue_script( 'vtte_script', PRE_THEME_JS .'/script.js', array('jquery'), self::theme_ver, '' );
  272. //attach data to script.js
  273. $ajax_data = array(
  274. 'url' => admin_url( 'admin-ajax.php' )
  275. );
  276. wp_localize_script( 'vtte_script', 'Ajax', $ajax_data );
  277. }
  278. }
  279. /**
  280. * Instantiate the class object
  281. * You can access its methods or variables by globalizing $wpbp or
  282. * using the get_instance() method (it's a singleton class, so it won't
  283. * create a new instance)
  284. * */
  285. $_s = site::get_instance();
  286. class base {
  287. static function sidebar_page($post) {
  288. $sidebar_content = '';
  289. $sidebar = apply_filters('vtte_page_sidebar', $sidebar_content, $post);
  290. echo $sidebar;
  291. }
  292. static function get_meta_page($post) {
  293. $sidebar_content = '';
  294. $sidebar = apply_filters('vtte_page_content_sidebar', $sidebar_content, $post);
  295. echo $sidebar;
  296. }
  297. static function translate_google_widget($mode='text') {
  298. global $_set;
  299. $settings = $_set->settings;
  300. if (isset($settings['translator_active'])) {
  301. $selected_mode = ($mode != 'text') ? ', layout: google.translate.TranslateElement.InlineLayout.SIMPLE' : '';
  302. echo '<div id="google_translate_element"></div>';
  303. echo '<script type="text/javascript">';
  304. echo 'function googleTranslateElementInit() {';
  305. echo 'new google.translate.TranslateElement({pageLanguage: \'es\''.$selected_mode.'}, \'google_translate_element\');';
  306. echo '}';
  307. echo '</script>';
  308. echo '<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>';
  309. }
  310. }
  311. static function news_share($post) {
  312. $has_thumb = ( !has_post_thumbnail( $post->ID ) ) ? ' no-thumb' : '';
  313. $out = '<div class="column">';
  314. $out .= '<article class="hentry entry-article'.$has_thumb.'">';
  315. $out .= '<div class="entry-content">';
  316. if (has_post_thumbnail( $post->ID )) {
  317. $out .= '<div class="entry-image">';
  318. $out .= '<a href="'.get_permalink($post->ID).'">';
  319. $out .= get_the_post_thumbnail( $book->ID, 'squared' );
  320. $out .= '<span class="wrap">';
  321. $out .= '</span>';
  322. $out .= '</a>';
  323. $out .= '<div class="social">';
  324. $out .= sitio::get_facebook_link($post);
  325. $out .= sitio::get_tweet_link($post);
  326. $out .= '</div>';
  327. $out .= '</div>';
  328. } else {
  329. $out .= '<div class="wrap">';
  330. $out .= '<div class="social">';
  331. $out .= sitio::get_facebook_link($post);
  332. $out .= sitio::get_tweet_link($post);
  333. $out .= '</div>';
  334. $out .= '</div>';
  335. }
  336. $out .= '</div>';
  337. $out .= '<h4 class="entry-title"><a href="'.get_permalink($post->ID).'">'.get_the_title($post->ID).'</a></h4>';
  338. $out .= '</article>';
  339. $out .= '</div>';
  340. return $out;
  341. }
  342. }
  343. add_filter( 'wpseo_opengraph_url', 'my_opengraph_url' );
  344. function my_opengraph_url( $url ) {
  345. return str_replace( 'https://', 'http://', $url );
  346. }
  347. add_filter( 'wpseo_canonical', 'yoast_remove_canonical_search' );
  348. function yoast_remove_canonical_search( $canonical ) {;
  349. return str_replace( 'https://', 'http://', $canonical );
  350. }
  351. class render {
  352. static function feature($item, $thumb='featured-page') {
  353. $out = '<div class="hentry entry-feature">';
  354. $out .= get_the_post_thumbnail($item->ID, $thumb);
  355. $out .= '<div class="wrap">';
  356. $out .= '<div class="wrap-content">';
  357. if (!empty($item->feature_subtitle)) {
  358. $out .= '<h4 class="subtitle">' . esc_attr($item->feature_subtitle) . '</h4>';
  359. }
  360. $out .= '<h3 class="entry-title">' . get_the_title($item->ID) . '</h3>';
  361. if (!empty($item->post_excerpt)) {
  362. $out .= '<div class="entry-summary">' . apply_filters('the_content', $item->post_excerpt) . '</div>';
  363. }
  364. if (!empty($item->feature_button_url)) {
  365. $out .= '<a href="' . esc_attr($item->feature_button_url) . '" class="button primary">' . esc_attr($item->feature_button_text) . '</a>';
  366. }
  367. $out .= '</div>';
  368. $out .= '</div>';
  369. $out .= '</div>';
  370. return $out;
  371. }
  372. }
  373. // Disable dashboard updates
  374. add_action('after_setup_theme', 'remove_core_updates');
  375. function remove_core_updates()
  376. {
  377. if (!current_user_can('update_core')) {
  378. return;
  379. }
  380. add_action('init', create_function('$a', "remove_action( 'init', 'wp_version_check' );"), 2);
  381. add_filter('pre_option_update_core', '__return_null');
  382. add_filter('pre_site_transient_update_core', '__return_null');
  383. add_filter('auto_update_theme', '__return_false');
  384. add_filter('auto_update_plugin', '__return_false');
  385. remove_action('load-update-core.php', 'wp_update_plugins');
  386. }