Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 31.69 KB | None | 0 0
  1. <?php
  2. /**
  3. * Define a largura das páginas de conteúdo
  4. */
  5. if ( ! isset( $content_width ) )$content_width = 552;
  6. #Define uma constante com a URL principal do site
  7. define('ABSURL', get_bloginfo('template_url'));
  8. #Define uma constante com a URL das imagens
  9. define('IMGURL', ABSURL.'/images');
  10.  
  11. #Define uma constante com a URL principal do site
  12. define('TEMPLATEURL', get_bloginfo('template_url'));
  13. require( TEMPLATEPATH . '/packsystem/ps_functions.php' );
  14.  
  15. if(!is_admin()){
  16. session_start();
  17. $force_mobile = is_null( $_GET['forcemobile'] ) ? 0 : 1;
  18. $no_mobile = is_null( $_GET['nomobile'] ) ? 0 : 1;
  19.  
  20. #Salva em sessão as variaveis de mobile,
  21. if( $force_mobile ){ #força a visualização em mobile
  22. $_SESSION['forcemobile'] = 1;
  23. $_SESSION['nomobile'] = 0;
  24. $no_mobile = null;
  25. }
  26.  
  27. if( $no_mobile ){ #força a visualização padrão
  28. $_SESSION['nomobile'] = 1;
  29. $_SESSION['forcemobile'] = 0;
  30. $force_mobile = null;
  31. }
  32.  
  33. define('MOBILE', $force_mobile || ( is_mobile() && !is_tablet() && !$no_mobile ) );
  34. } else {
  35. define( 'MOBILE', false );
  36. }
  37.  
  38. /**
  39. * Inicia as configurações do Tema
  40. *
  41. */
  42. add_action( 'after_setup_theme', 'ps_setup' );
  43. if ( ! function_exists( 'ps_setup' ) ):
  44. function ps_setup() {
  45. // Adiciona o CSS para aplciar dentro do editor de textos
  46. add_editor_style('editor-style.css');
  47. // Add default posts and comments RSS feed links to <head>.
  48. add_theme_support( 'automatic-feed-links' );
  49. // Adiciona suporte a Menu
  50. register_nav_menus( array(
  51. 'primary' => 'Menu Principal',
  52. 'left_menu' => 'Menu de Técnicas',
  53. 'left_menu2' => 'Menu de Técnicas 2',
  54. 'left_menu3' => 'Menu de Técnicas 3',
  55. 'right_menu' => 'Menu Extra',
  56. 'm-primary' => 'Mobile Principal',
  57. 'm-tecnicas' => 'Mobile Técnicas'
  58. ) );
  59.  
  60. // Adiciona suporte a imagens destagadas em posts e páginas
  61. add_theme_support( 'post-thumbnails' );
  62. add_image_size( 'blog-image', 620, 225);
  63. add_image_size( 'related-thumb', 287, 105);
  64. add_action( 'pre_get_posts', 'set_blog_posts_per_page' );
  65. }
  66. endif;
  67.  
  68. /**
  69. * Adiciona classes para controle no body
  70. *
  71. * @param array $classes
  72. * @return array
  73. */
  74. add_filter( 'body_class', 'ps_body_class' );
  75. function ps_body_class( $classes ) {
  76. $classes[] = get_platform('ps');
  77. if(ps_is_blog()){
  78. $classes[] = 'cat-blog';
  79. }
  80.  
  81. if(MOBILE) $classes[] = 'is-mobile';
  82. return $classes;
  83. }
  84. /**
  85. * Filtra os temas, para adicionar o mobile e o blog
  86. *
  87. * @param string $template
  88. * @return string
  89. */
  90. add_filter( 'template_include', 'ps_template_include', 99 );
  91. function ps_template_include( $template ) {
  92. $name = basename($template, '.php');
  93. if(MOBILE){
  94. $new_template = locate_template( array( 'mobile-'.$name.'.php' ) );
  95. if(ps_is_blog()){
  96. $new_template = locate_template( array( 'mobile-category-blog.php' ) );
  97. }
  98. if ( '' != $new_template ) {
  99. $template = $new_template ;
  100. }
  101. }elseif(ps_is_blog()){
  102. $new_template = locate_template( array( 'category-blog.php' ) );
  103. if ( '' != $new_template ) {
  104. $template = $new_template ;
  105. }
  106. }
  107. return $template;
  108. }
  109.  
  110. /**
  111. * Verifica se a página a ser carregada é do blog
  112. *
  113. * @return boolean
  114. */
  115. function ps_is_blog(){
  116. if(is_home() || is_front_page()) return false;
  117.  
  118. $cat_blog = false;
  119. if(is_category()){
  120. $categ = get_category(get_query_var('cat'));
  121. $cat_blog = (is_category(8) || $categ->category_parent == 8);
  122. }else
  123. if(is_single() && in_category(8)){
  124. $cat_blog = true;
  125. }
  126. return ($cat_blog || is_tag());
  127. }
  128.  
  129. /**
  130. * Pega o nome das categorias do post
  131. *
  132. * @param string $catExclude Código das categorias que não deseja exibir
  133. * @return array Retorna um array com os links para cada categoria
  134. */
  135. function ps_get_cat_names($catExclude = NULL){
  136. if(!$catExclude) $catExclude = array();
  137. $nameCats = array();
  138. foreach((get_the_category()) as $cat){
  139. if(!in_array($cat->cat_ID, $catExclude)) $nameCats[] = '<a href="'.get_category_link( $cat->term_id ).'">'.$cat->cat_name.'</a>';
  140. }
  141. return $nameCats;
  142. }
  143.  
  144. /**
  145. * Imprime o nome das categorias do post
  146. *
  147. * @param string $catExclude Código das categorias que não deseja exibir
  148. * @param string $sep Separador dos links
  149. * @return string Retorna uma string com o resultado da função ps_get_cat_names separados pelo conteúdo da variável $sep;
  150. */
  151. function ps_the_cat_names($catExclude = NULL, $sep = ', '){
  152. $cats = ps_get_cat_names($catExclude);
  153. echo implode($sep, $cats);
  154. }
  155.  
  156. /**
  157. * Adiciona os scripts necessários para o site
  158. *
  159. */
  160. add_action('wp_enqueue_scripts', 'ps_enqueue_scripts', 999);
  161. function ps_enqueue_scripts(){
  162. if (!is_admin()) {
  163. #wp_register_script( 'packsystem', ABSURL.'/js/js.php', array('jquery'), '1.0', true);
  164. #wp_enqueue_script( 'packsystem' );
  165.  
  166. wp_register_script( 'packsystem1', ABSURL.'/js/gsap/TweenLite.min.js', null, filemtime( get_template_directory().'/js/gsap/TweenLite.min.js' ), true);
  167. wp_enqueue_script( 'packsystem1' );
  168.  
  169. wp_register_script( 'packsystem11', ABSURL.'/js/gsap/CSSPlugin.min.js', null, filemtime( get_template_directory().'/js/gsap/CSSPlugin.min.js' ), true);
  170. wp_enqueue_script( 'packsystem11' );
  171.  
  172. wp_register_script( 'packsystem2', ABSURL.'/js/min.js', array('jquery'), filemtime( get_template_directory().'/js/min.js' ), true);
  173. wp_enqueue_script( 'packsystem2' );
  174. }
  175. }
  176.  
  177. /**
  178. * Função para comprimir os scripts em GZIP
  179. *
  180.  
  181. add_action('wp_enqueue_scripts', 'ps_force_compress');
  182. function ps_force_compress(){
  183. global $compress_scripts, $concatenate_scripts;
  184. $compress_scripts = 1;
  185. $concatenate_scripts = 1;
  186. define('ENFORCE_GZIP', true);
  187. }
  188. */
  189.  
  190. /**
  191. * Função para registrar as áreas de widget do site
  192. *
  193. */
  194. add_action( 'widgets_init', 'ps_widgets_init' );
  195. function ps_widgets_init() {
  196. register_sidebar( array(
  197. 'name' => 'Lateral Blog',
  198. 'id' => 'w-sidebar',
  199. 'before_widget' => '<div id="%1$s" class="widget w-sidebar %2$s">',
  200. 'after_widget' => "</div></div>",
  201. 'before_title' => '<h3 class="widget-title">',
  202. 'after_title' => '</h3><div class="widget-content">',
  203. ) );
  204.  
  205. register_sidebar( array(
  206. 'name' => 'Rodapé',
  207. 'id' => 'w-footer',
  208. 'before_widget' => '<div id="%1$s" class="w-footer %2$s">',
  209. 'after_widget' => "</div>",
  210. 'before_title' => '<h3 class="widget-title">',
  211. 'after_title' => '</h3>',
  212. ) );
  213.  
  214. register_sidebar( array(
  215. 'name' => 'SubMenu',
  216. 'id' => 'w-submenu',
  217. 'before_widget' => '<div id="%1$s" class="w-submenu %2$s">',
  218. 'after_widget' => "</div>",
  219. 'before_title' => '<h3 class="widget-title">',
  220. 'after_title' => '</h3>',
  221. ) );
  222.  
  223.  
  224. }
  225.  
  226. /**
  227. * Função para pegar a músca que está cadastrada no ADM.
  228. *
  229. * @url http://paulapires.com.br/wp-admin/options-general.php?page=ps-custom
  230. *
  231. * @return string
  232. */
  233. function ps_get_sound(){
  234. $options = get_option( 'ps_custom_option' );
  235. $sound = $options['ps_sounds'];
  236. if(!$sound) $sound = '/wp-content/uploads/2014/10/Trilha-final-do-site.mp3';
  237.  
  238. return $sound;
  239. }
  240.  
  241. /**
  242. * Imprime a função ps_get_sound
  243. *
  244. */
  245. function ps_the_sound(){ echo ps_get_sound();}
  246.  
  247.  
  248.  
  249. /**
  250. * Função para pegar uma imagem de fundo das que estão cadastradas no ADM.
  251. * São cadastradas em: http://paulapires.com.br/wp-admin/options-general.php?page=ps-custom
  252. *
  253. * @param string $type Tipo para buscar web ou mobile
  254. * @return string
  255. */
  256. function ps_get_bg($type = 'web'){
  257. $bg = '';
  258.  
  259. $options = get_option( 'ps_custom_option' );
  260.  
  261. $opt_bgs = trim($type == 'web' ? $options['ps_backgrounds'] : $options['ps_backgrounds_m']);
  262.  
  263. if(!$opt_bgs)
  264. return '/wp-content/uploads/2015/03/fundo1.jpg';
  265.  
  266. $bgs = explode("\n", $opt_bgs);
  267.  
  268. while(!$bg)
  269. $bg = $bgs[array_rand($bgs)];
  270.  
  271. return trim($bg);
  272. }
  273.  
  274. /**
  275. * Imprime a função ps_get_bg
  276. *
  277. * @param string $type Tipo para buscar web ou mobile
  278. */
  279. function ps_the_bg($type = 'web'){echo ps_get_bg($type);}
  280.  
  281. /**
  282. * Função para imprimir as opções de compartilhamento
  283. *
  284. * @param string
  285. */
  286. function ps_share()
  287. {
  288. $whatsapp_api = get_option('pp_api_settings');
  289. $whatsapp_number = preg_replace( '/[^0-9]/', '', $whatsapp_api['pp_whats_settings_number'] );
  290. $whatsapp_text = $whatsapp_api['pp_whats_settings_text'];
  291. $link = 'https://wa.me/55' . $whatsapp_number;
  292.  
  293. if ( ! empty( $whatsapp_number ) && ! empty( $whatsapp_text ) ) {
  294. $link = 'https://wa.me/55' . $whatsapp_number . '?text=' . $whatsapp_text;
  295. }
  296.  
  297. global $post;
  298. ps_facebook();
  299. ps_twitter();
  300. ps_googleplus();
  301. ?>
  302. <ul class="entry-share">
  303. <?php if ( $whatsapp_number ) : ?>
  304. <li class="wapp" style="text-align:left;"><a href="<?php echo $link ?>" target="_blank">
  305. <img src="<?php the_img('whatsapp-logo.png')?>" alt="">
  306. <span>Via WhatsApp</span>
  307. </a>
  308. </li>
  309. <?php endif; ?>
  310. <li class="tube"><div class="g-ytsubscribe" data-channel="safhica" data-layout="default" data-count="default"></div></li>
  311. <li class="face"><div class="fb-share-button" data-href="<?php echo get_permalink(); ?>" data-layout="button_count"></div></li>
  312. <li class="insta"><a href="https://www.instagram.com/paulapiresastro/" rel="noopener noreferrer nofollow" target="_blank"></a></li>
  313. <?php echo comments_number( '', '<li class="comments">1 coment&aacute;rio</li>', '<li class="comments">% coment&aacuterios</li>' );?>
  314. </ul>
  315. <?php
  316. }
  317.  
  318.  
  319. /**
  320. * Exibe a paginação
  321. *
  322. * @param string $nav_id Define o atributo id da tag nav que será impressa
  323. */
  324. function ps_content_nav( $nav_id ) {
  325. global $wp_query;
  326.  
  327. #pre($wp_query);
  328. if ( $wp_query->max_num_pages > 1 ) : ?>
  329. <p class="tc"><a id="more-pageOnDemand" class="ps-btn-elipse dn" href="#">Carregar mais Artigos</a></p>
  330. <div id="pageOnDemand" class="tc dn"><img src="<?php the_img('loader3.gif')?>" alt="Carregando" title="Carregando"></div>
  331. <nav id="<?php echo $nav_id; ?>" class="navigation">
  332. <?php
  333. $big = 999999999; // need an unlikely integer
  334.  
  335. echo paginate_links( array(
  336. 'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
  337. 'format' => '?paged=%#%',
  338. 'current' => max( 1, get_query_var('paged') ),
  339. 'total' => $wp_query->max_num_pages,
  340. 'prev_text' => '&laquo;',
  341. 'next_text' => '&raquo;'
  342. ) );
  343.  
  344. ?>
  345. </nav><!-- #nav-above -->
  346. <?php endif;
  347. }
  348.  
  349. /**
  350. * Limpa o conteúdo para exibição do texto sem imagens
  351. *
  352. * @param string $content
  353. * @return string
  354. */
  355. function ps_get_the_content($content){
  356. $content = apply_filters('the_content', $content);
  357. $content = str_replace(']]>', ']]&gt;', $content);
  358. return $content;
  359. }
  360.  
  361. /**
  362. * Conta o número de visitas de cada post
  363. *
  364. */
  365. if(!function_exists('ps_countviews')):
  366. add_action('wp_footer', 'ps_countviews');
  367.  
  368. function ps_countviews() {
  369. if(!is_single()) return false;
  370. global $post;
  371.  
  372. if(is_int($post)) $post = get_post($post);
  373. if(wp_is_post_revision($post)) return false;
  374.  
  375. $visitas = intval(get_post_meta($post->ID, '_ps_postviews', true));
  376. if(!update_post_meta($post->ID, '_ps_postviews', ($visitas+1))) {
  377. add_post_meta($post->ID, '_ps_postviews', 1, true);
  378. }
  379. }
  380. endif;
  381.  
  382. /**
  383. * Exibe o posts mais visualizados em um widget lateral através do shortcode [ps_show_most_views]
  384. *
  385. * @param string $content
  386. * @return $content
  387. */
  388. add_filter('widget_text', 'ps_show_most_views');
  389. function ps_show_most_views($content){
  390. if(strpos($content, '[ps_show_most_views]') === false) return $content;
  391. $html = '';
  392. $query = new WP_Query('posts_per_page=4&orderby=meta_value_num&order=DESC&meta_key=_ps_postviews&cat=8');
  393. global $post;
  394. if($query->have_posts()){
  395. $html.= '<ul class="top-posts">';
  396. while($query->have_posts()){
  397. $query->the_post();
  398. $html.= '<li class="post post-views-'.get_post_meta($post->ID, '_ps_postviews', true).'"><a href="'.get_the_permalink().'" title="'.get_the_title().'" rel="bookmark">'.get_the_title().'</a></li>';
  399. }
  400. $html.= '</ul>';
  401. }
  402. wp_reset_query();
  403.  
  404. $content = str_replace('[ps_show_most_views]', $html, $content);
  405. return $content;
  406. }
  407.  
  408. /**
  409. * Exibe o posts em destaque através do shortcode [ps_artigos_destaque]
  410. *
  411. * @param string $content
  412. * @return $content
  413. */
  414. add_filter('widget_text', 'ps_show_destaques');
  415. function ps_show_destaques($content){
  416. $shotcode = '[ps_artigos_destaque]';
  417. if(strpos($content, $shotcode) === false) return $content;
  418. $html = '';
  419. $query = new WP_Query('posts_per_page=4&meta_key=_ps_isDestaque&meta_value=1&cat=8');
  420. global $post;
  421. if($query->have_posts()){
  422. $html.= '<ul class="top-posts">';
  423. while($query->have_posts()){
  424. $query->the_post();
  425. $html.= '<li class="post post-destaque-'.$post->ID.'"><a href="'.get_the_permalink().'" title="'.get_the_title().'" rel="bookmark">'.get_the_title().'</a></li>';
  426. }
  427. $html.= '</ul>';
  428. }
  429. wp_reset_query();
  430.  
  431. $content = str_replace($shotcode, $html, $content);
  432. return $content;
  433. }
  434.  
  435. /**
  436. * Customiza o tamanho das tags
  437. *
  438. * @param array $args
  439. * @return array
  440. */
  441. add_filter( 'widget_tag_cloud_args', 'ps_tag_cloud_args' );
  442. function ps_tag_cloud_args($args) {
  443. $args['largest'] = 16; //largest tag
  444. $args['smallest'] = 8; //smallest tag
  445. return $args;
  446. }
  447.  
  448. /**
  449. * Permite fazer arquivos separados para cada post de acordo com a categoria
  450. *
  451. * @param string $single_template
  452. * @return $path
  453. */
  454. add_filter( 'single_template', 'ps_single_template' );
  455. function ps_single_template($single_template) {
  456. global $wp_query, $post;
  457.  
  458. foreach((array)get_the_category() as $cat){
  459. $path = TEMPLATEPATH.'/single-cat-'.$cat->term_id.'.php';
  460. if(file_exists($path)) return $path;
  461.  
  462. $path = TEMPLATEPATH.'/single-cat-'.$cat->slug.'.php';
  463. if(file_exists($path)) return $path;
  464. }
  465.  
  466. return $single_template;
  467. }
  468.  
  469.  
  470. /**
  471. * Adiciona caixa de estilos no editor do WP
  472. *
  473. * @param array $buttons
  474. * @return array
  475. */
  476. add_filter('mce_buttons_2', 'ps_mce_buttons_2');
  477. function ps_mce_buttons_2($buttons) {
  478. array_unshift($buttons, 'styleselect');
  479. return $buttons;
  480. }
  481.  
  482. /**
  483. * Adiciona os itens na caixa de estilos
  484. *
  485. * @param string $init_array
  486. * @return $init_array
  487. */
  488. add_filter( 'tiny_mce_before_init', 'ps_insert_formats' );
  489. function ps_insert_formats( $init_array ) {
  490. $style_formats = array('{"title":"Botão Elipse", "classes":"ps-btn-elipse", "selector":"a", "wrapper":false}'
  491. ,'{"title":"Botão de Imprimir", "classes":"ps-btn-print", "selector":"a", "wrapper":false}'
  492. ,'{"title":"Lista de Links", "classes":"link-list", "selector":"ul", "wrapper":false}'
  493. ,'{"title":"Link", "classes":"link", "selector":"a", "wrapper":false}'
  494. );
  495.  
  496. $init_array['style_formats'] = '['.implode(',', $style_formats).']';
  497.  
  498. return $init_array;
  499.  
  500. }
  501.  
  502. /**
  503. * Adiciona os audio e vídeo de acordo com o shortcode
  504. *
  505. * @param string $atts Array com os parametros necessários
  506. * @param string id caso sejam adicionados mais de um vídeo no msmo post, isso garante que não haverá elementos com id duplicado
  507. * @param string type audio/video
  508. * @param string url Caminho para o vídeo flv
  509. * @param string src Caminho para o vídeo m4v
  510. * @param string altura Altura em pixels do vídeo
  511. * @param string largura Largura em pixels do vídeo
  512. * @param boolean autoplay Caso esteja definido, será dado play quando a página terminar de carregar
  513. * @return string
  514. * @ Ex: http://www.paulapires.com.br/wp-admin/post.php?post=3237&action=edit
  515. */
  516. add_shortcode('ps_media', 'ps_media_add');
  517. function ps_media_add( $atts ) {
  518. if(!$atts['url']) return '';
  519. if(!$atts['id']) $atts['id'] = 1;
  520. if(!$atts['type']) $atts['type'] = 'audio';
  521. $atts['autoplay'] = $atts['autoplay'] ? 'autoplay' : '';
  522. extract($atts);
  523. $id = $type.'_'.get_the_ID().'-'.$id;
  524. $w = $largura ? $largura : 'null';
  525. $h = !$altura && $type == 'audio' ? '55' : ($altura ? $altura : 'null');
  526.  
  527. $html = '<div class="media '.$type.' '.$id.'">';
  528. if(is_mobile()){
  529. if($autoplay == 'sim') $autoplay = 'autoplay="play"';
  530. if($type == 'audio'){
  531. $iPod = stripos($_SERVER['HTTP_USER_AGENT'],"iPod");
  532. $iPhone = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone");
  533. $iPad = stripos($_SERVER['HTTP_USER_AGENT'],"iPad");
  534.  
  535. //do something with this information
  536. if( $iPod || $iPhone || $iPad){
  537. #$html.= '<p>&nbsp;<br><br><audio controls autoplay="false"><source src="'.$url.'" type="audio/mp3"><p>Seu navegador exige que você <a href="'.$url.'">clique aqui</a> novamente para ouvir o áudio.<p></audio></p>';
  538. $html.= '<p>&nbsp;<br><br>Seu navegador exige que você <a href="'.$url.'">clique aqui</a> novamente para ouvir o áudio.</p>';
  539. }else{
  540. $html.= '<p>&nbsp;<br><br><audio controls autoplay="false"><source src="'.$url.'" type="audio/mp3"></audio></p>';
  541. }
  542.  
  543.  
  544.  
  545. }else{
  546. $html.= '<p><video src="'.$src.'" controls style="width:554px;" '.$autoplay.'></video></p>';
  547. }
  548. }else{
  549. $html = '<div class="'.$type.' '.$id.'">';
  550. $html.= '<div id="'.$id.'"></div>';
  551. $html.= '<script >jQuery(document).ready(function(e) {Site.addMedia("'.$id.'", "'.$url.'", '.$h.', '.$w.', "'.$autoplay.'");});</script>';
  552. }
  553. $html.= '</div>';
  554. return $html;
  555. }
  556.  
  557. /**
  558. * Substitui a tag hr para fazer o hr padrão do site
  559. *
  560. * @param string $content
  561. * @return $content
  562. */
  563. function ps_replace_hr($content){
  564. $content = str_replace('<hr>', '<div class="hr"></div>', $content);
  565. $content = str_replace('<hr/>', '<div class="hr"></div>', $content);
  566. $content = str_replace('<hr />', '<div class="hr"></div>', $content);
  567.  
  568. return $content;
  569. }
  570. add_filter('the_content', 'ps_replace_hr');
  571.  
  572. /**
  573. * Formulário de newsletter
  574. *
  575. * @param string $content
  576. * @param string $id Altera o atributo id da tag <form>
  577. * @return $content
  578. */
  579. add_filter('widget_text', 'ps_form_newsletter');
  580. add_filter('the_content', 'ps_form_newsletter');
  581.  
  582. function ps_form_newsletter($content, $id='') {
  583. if ( strpos( $content, '[ps_form_newsletter]' ) === false ) {
  584. return $content;
  585. }
  586.  
  587. $form = '
  588. <form method="post" action="#" id="frmNewsletter'.$id.'" class="frmNewsletter">
  589. <input type="text" name="mc4wp-TXTNAME" id="nl_nome'.$id.'" placeholder="nome" class="obrig" title="nome" required="required" />
  590. <input type="email" name="EMAIL" id="nl_email'.$id.'" placeholder="e-mail" class="obrig email" title="E-MAIL" required="required" />
  591. <input type="submit" id="sbt_frmNewsletter'.$id.'" name="sbt_frmNewsletter" class="submit sbt_frmNewsletter" value="Enviar">
  592. <span class="loader-submit dn loader_frmNewsletter"><img src="'.ABSURL.'/images/loader3.gif" height="30" alt="Aguarde" class="va"> Enviando</span>
  593. <input type="hidden" value="1" name="mc4wp-subscribe">
  594. </form>';
  595.  
  596. $content = str_replace( '[ps_form_newsletter]', $form, $content );
  597.  
  598. if ( $_SERVER['REQUEST_METHOD'] !== 'POST' ) {
  599. return $content;
  600. }
  601.  
  602. $msg_form = false;
  603. $txt_name = isset( $_POST['mc4wp-TXTNAME'] ) ? esc_html( $_POST['mc4wp-TXTNAME'] ) : false;
  604. $email = isset( $_POST['EMAIL'] ) ? sanitize_email( $_POST['EMAIL'] ) : false;
  605.  
  606. if ( ! $txt_name || ! $email ) {
  607. $msg_form = 'Os campos Nome e E-mail devem ser preenchidos!';
  608. }
  609.  
  610. if ( $txt_name && $email ) {
  611. $site_url = esc_url( home_url( '/' ) );
  612. $blog_name = esc_html( get_bloginfo( 'name', 'display' ) );
  613. $msg = "******************************************************************
  614. Formulário de Newsletter
  615. ******************************************************************\n
  616. Nome: {$txt_name}
  617. E-mail: {$email}
  618.  
  619. Esse e-mail foi enviado através do site {$blog_name}\n{$site_url}
  620. ";
  621. //ps_save_form('Newsletter', $nl_nome, $nl_email, $nl_origem);
  622. ps_send_email( utf8_decode( $msg ), 'Newslleter' );
  623.  
  624. $msg_form = 'Obrigado! Seu e-mail foi cadastrado com sucesso!';
  625. }
  626.  
  627. if ( $msg_form ) {
  628. $content .= '<script>jQuery( document ).ready( function() { alert( "' . $msg_form . '" ) } );</script>';
  629. }
  630.  
  631. return $content;
  632. }
  633.  
  634. /**
  635. * Envia os e-mails
  636. *
  637. * @param string $content Corpo do e-mail
  638. * @param string $subject Assunto do E-mail
  639. * @param string $reply E-mail para o qual deve encaminhar quando o usuário responder
  640. */
  641. function ps_send_email($content, $subject, $reply = ''){
  642. $admin_email = 'renata7protegida@gmail.com';
  643. $subject = get_bloginfo( 'name', 'display' ).' - '.$subject;
  644. $from = 'naoresponda@paulapires.com.br';
  645.  
  646. $headers = 'MIME-Version: 1.0'."\n";
  647. $headers .= 'Content-type: text/plain; charset=iso-8859-1'."\n";
  648. #$headers .= 'To: '.$admin_email."\n";
  649. #$headers .= 'Cc: richard.venancio@gmail.com'."\n";
  650. #$headers .= 'Bcc: richard.venancio@gmail.com'."\n";
  651. $headers .= 'From: SITE - Paula Pires <'.$from.'>'."\n";
  652. if($reply) $headers .= "Reply-to: $reply"."\n";
  653.  
  654. #echo '<pre class="dn">'."$admin_email, $subject, $content, $headers, $from".'</pre>';
  655.  
  656. $resp = @mail($admin_email, $subject, $content, $headers, "-r".$from);
  657. }
  658.  
  659. /**
  660. * Customiza a quantidade de caracter aceita no resumo do post
  661. *
  662. * @param string $length
  663. * @return 300
  664. */
  665. add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
  666. function custom_excerpt_length( $length ) {
  667. return 300;
  668. }
  669.  
  670.  
  671. /**
  672. * Imprime os links para aumentar e diminuir as fontes
  673. *
  674. */
  675. function font_size(){?>
  676. <span class="font-size">
  677. <a href="#" class="less" data-min="14" title="Diminuir Fonte">-A</a>
  678. <a href="#" class="more" data-max="22" title="Aumentar Fonte">+A</a>
  679. </span>
  680. <?php
  681. }
  682.  
  683. /**
  684. * Delimita o tamanho do resumo para exibição garantindo que nenhuma palavra seja cortada ao meio.
  685. *
  686. * @param string $n define a quantidade máxima de caracters a ser exibida
  687. * @return $excerpt
  688. */
  689. function ps_get_excerpt($n = 190){
  690. $excerpt = get_the_excerpt();
  691. $pos = @strpos($excerpt, ' ', $n);
  692. if(strlen($excerpt) < $n || $pos === false) return $excerpt;
  693. return substr($excerpt, 0, $pos);
  694. }
  695.  
  696. /**
  697. * Customiza o formulário de comentários
  698. *
  699. * @param string $nameTextarea Define o label do campo textarea
  700. */
  701. function ps_comment_form($nameTextarea = 'Deixe seu coment&aacute;rio'){
  702. $commenter = wp_get_current_commenter();
  703. $req = get_option( 'require_name_email' );
  704. $aria_req = ( $req ? " aria-required='true'" : '' );
  705.  
  706. $fields = array(
  707. 'author' => '<p><label for="author">Nome<br><input id="author" name="author" type="text" class="campo" title="Preencha seu nome" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' required /></label></p>',
  708. 'email' => '<p><label for="email">E-mail<br><input id="email" name="email" type="text" class="campo" title="Preencha seu e-mail" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' required /></label></p>',
  709. 'url' => '',
  710. );
  711.  
  712. $comments_args = array(
  713. 'title_reply'=>'',
  714. 'comment_notes_after' => '',
  715. 'comment_notes_before' => '',
  716. 'cancel_reply_link' => 'Cancelar',
  717. 'comment_field' => '<label for="comment">'.$nameTextarea.'<br><textarea id="comment" name="comment" title="'.$nameTextarea.'" aria-required="true" required class="campo"></textarea></label>',
  718. 'label_submit' => 'Enviar >',
  719. 'title_reply_to' => '',
  720. 'id_submit' => 'sbt_frmComment',
  721. 'fields' => $fields
  722. );
  723. comment_form($comments_args);
  724. }
  725.  
  726. /**
  727. * Customiza a lista de comentários
  728. *
  729. * @param string $comment
  730. * @param string $args
  731. * @param string $depth
  732. */
  733. function ps_comment( $comment, $args, $depth ) {
  734. $GLOBALS['comment'] = $comment;
  735. switch ( $comment->comment_type ) :
  736. case 'pingback' :
  737. case 'trackback' : ?>
  738. <div <?php comment_class('p-comment h-cite'); ?> id="comment-<?php comment_ID(); ?>">
  739. <p><?php _e( 'Pingback:', 'ps' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( 'Edit', 'ps' ), '<span class="edit-link">', '</span>' ); ?></p>
  740. <?php break;
  741. default : ?>
  742. <div <?php comment_class('p-comment h-cite'); ?> id="comment-<?php comment_ID(); ?>">
  743. <div class="comment-header">
  744. <?php if ( $comment->comment_approved == '0' ) : ?>
  745. <em class="comment-awaiting-moderation flr">Seu coment&aacute;rio est&aacute; aguardando aprova&ccedil;&atilde;o!</em>
  746. <?php endif; ?>
  747. <h4 class="fn p-author"><?php comment_author() ?></h4>
  748. <span class="data"><?php comment_time('d M, Y')?></span>
  749. </div>
  750. <div class="comment-content p-content">
  751. <?php comment_text(); ?>
  752. </div>
  753. <div class="reply">
  754. <?php comment_reply_link( array_merge( $args, array( 'reply_text' => 'Responder', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
  755. </div><!-- .reply -->
  756. <?php break;
  757. endswitch;
  758. }
  759.  
  760. /**
  761. * Adiciona um parametro para que seja possível identificar quando um comentário foi salvo
  762. *
  763. * @param string $location
  764. * @param string $comment
  765. * @return string
  766. */
  767. add_action('comment_post_redirect', 'ps_comment_post_redirect');
  768. function ps_comment_post_redirect($location, $comment = NULL){
  769. $location = substr($location, 0, strpos($location, '#'));
  770. return $location.'?msg=sucesso#sbt_frmComment';
  771. }
  772.  
  773. /**
  774. * Adiciona o e-mail paulapires7@paulapires.com.br para receber todos os e-mails de comentários
  775. *
  776. * @param string $emails
  777. * @return $emails
  778. */
  779. #add_filter('comment_notification_recipients' , 'ps_add_comment_notify');
  780. function ps_add_comment_notify($emails){
  781. $emails[] = 'paulapires7@paulapires.com.br';
  782. $emails[] = 'paulapires@paulapires.com.br';
  783. return $emails;
  784. }
  785.  
  786. /**
  787. * Código do Google Analytics
  788. */
  789. function ps_ga(){ ?>
  790. <script >
  791. (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  792. (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  793. m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  794. })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  795.  
  796. ga('create', 'UA-46955706-1', 'auto');
  797. ga('require', 'displayfeatures');
  798. ga('send', 'pageview');
  799. </script>
  800. <?php
  801. }
  802.  
  803. function ps_facebook()
  804. {
  805. ?>
  806. <script >
  807. (function(d, s, id) {
  808. var js, fjs = d.getElementsByTagName(s)[0];
  809. if (d.getElementById(id)) return;
  810. js = d.createElement(s); js.id = id;
  811. js.src = "//connect.facebook.net/pt_BR/sdk.js#xfbml=1&version=v2.0";
  812. fjs.parentNode.insertBefore(js, fjs);
  813. }(document, 'script', 'facebook-jssdk'));
  814. </script>
  815. <?php
  816. }
  817.  
  818. function ps_twitter()
  819. {
  820. ?>
  821. <script >
  822. !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
  823. </script>
  824. <?php
  825. }
  826.  
  827. function ps_googleplus()
  828. {
  829. ?>
  830. <script >
  831. window.___gcfg = {lang: 'pt-BR'};
  832. (function() {
  833. var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
  834. po.src = 'https://apis.google.com/js/plusone.js';
  835. var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  836. })();
  837. </script>
  838. <?php
  839. }
  840.  
  841. function set_blog_posts_per_page( $query )
  842. {
  843. if ( is_category() and $query->is_category( 8 ) ){ // Blogs
  844. $query->set( 'posts_per_page', 6 );
  845. }
  846.  
  847. }
  848.  
  849. if(MOBILE){
  850. add_filter('autoptimize_filter_css_replacetag','my_ao_override_css_replacetag',10,1);
  851. function my_ao_override_css_replacetag($replacetag) {
  852. return array("</body>","before");
  853. }
  854. }
  855.  
  856. function disable_wp_emojicons() {
  857.  
  858. // all actions related to emojis
  859. remove_action( 'admin_print_styles', 'print_emoji_styles' );
  860. remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
  861. remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
  862. remove_action( 'wp_print_styles', 'print_emoji_styles' );
  863. remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
  864. remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
  865. remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
  866.  
  867. // filter to remove TinyMCE emojis
  868. add_filter( 'tiny_mce_plugins', 'disable_emojicons_tinymce' );
  869. }
  870. add_action( 'init', 'disable_wp_emojicons' );
  871.  
  872. function disable_emojicons_tinymce( $plugins ) {
  873. if ( is_array( $plugins ) ) {
  874. return array_diff( $plugins, array( 'wpemoji' ) );
  875. } else {
  876. return array();
  877. }
  878. }
  879.  
  880. function _pp_cf7_current_form_title( $out, $pairs, $atts, $shortcode ) {
  881. global $pp_cf7_current_form_title;
  882.  
  883. $pp_cf7_current_form_title = isset( $out['title'] ) ? esc_html( $out['title'] ) : '';
  884.  
  885. return $out;
  886. }
  887. add_filter( 'shortcode_atts_wpcf7', '_pp_cf7_current_form_title', 99, 4 );
  888.  
  889. function _pp_cf7_add_field_hidden_title( $fields ) {
  890. global $pp_cf7_current_form_title;
  891.  
  892. if ( ! function_exists( 'wpcf7_get_current_contact_form' ) ) {
  893. return $fields;
  894. }
  895.  
  896. $form_title = $pp_cf7_current_form_title;
  897. $query_title = isset( $_GET['form-title'] ) ? esc_html( $_GET['form-title'] ) : false;
  898.  
  899. if ( ! empty( $query_title ) ) {
  900. $form_title = $query_title;
  901.  
  902. } elseif ( empty( $form_title ) ) {
  903. $current_form = wpcf7_get_current_contact_form();
  904. $form_title = $current_form->title();
  905. }
  906.  
  907. $fields['_title'] = esc_html( $form_title );
  908.  
  909. return $fields;
  910. }
  911. add_filter( 'wpcf7_form_hidden_fields', '_pp_cf7_add_field_hidden_title' );
  912.  
  913. add_action( 'init', '_pp_check_clear_psft_results' );
  914.  
  915. function _pp_check_clear_psft_results() {
  916.  
  917. if ( ! wp_next_scheduled ( 'pp_clear_psft_results' ) ) {
  918. wp_schedule_event( time(), 'daily', 'pp_clear_psft_results' );
  919. }
  920. }
  921.  
  922. add_action( 'pp_clear_psft_results', '_pp_clear_psft_results' );
  923.  
  924. function _pp_clear_psft_results() {
  925.  
  926. global $wpdb;
  927.  
  928. $wpdb->query( 'DELETE FROM dnvu4lf_psft_results WHERE date < NOW() - INTERVAL 15 DAY' );
  929. }
  930.  
  931. require( TEMPLATEPATH . '/packsystem/ps_admin/ps_admin_custom.php' );
  932. require( TEMPLATEPATH . '/packsystem/ps_forms_testes/ps_forms_testes.php' );
  933. require( TEMPLATEPATH . '/packsystem/ps_gallery_post/ps_gallery_post.php' );
  934. require( TEMPLATEPATH . '/packsystem/ps_banners/ps_banners.php' );
  935. require( TEMPLATEPATH . '/packsystem/ps_Walker_Nav_Menu/ps_Walker_Nav_Menu.php' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement