Advertisement
_Sascha_

tooltips.php - quickfix

Apr 20th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 16.19 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Tooltips
  4. Plugin URI:  http://tomas.zhu.bz/wordpress-plugin-tooltips.html
  5. Description: Wordpress Tooltips,You can add text,image,link,video,radio in tooltips, add tooltips in gallery. More amazing features? Do you want to customize a beautiful style for your tooltips? Get <a href='http://tooltips.org' target='blank'>Wordpress Tooltips Pro</a> now.
  6. Version: 3.5.9
  7. Author: Tomas Zhu: <a href='http://tooltips.org' target='_blank'>Tooltips Pro</a>
  8. Author URI: http://tomas.zhu.bz
  9. Text Domain: wordpress-tooltips
  10. License: GPL2
  11. */
  12. /*  Copyright 2011 Tomas.Zhu (email : expert2wordpress@gmail.com)
  13.  
  14.     This program is free software; you can redistribute it and/or modify
  15.     it under the terms of the GNU General Public License, version 2, as
  16.     published by the Free Software Foundation.
  17.  
  18.     This program is distributed in the hope that it will be useful,
  19.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.     GNU General Public License for more details.
  22.  
  23.     You should have received a copy of the GNU General Public License
  24.     along with this program; if not, write to the Free Software
  25.     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  26. */
  27. error_reporting(0);
  28. require_once("tooltipsfunctions.php");
  29. function tooltipsHead()
  30. {
  31.     $m_pluginURL = get_option('siteurl').'/wp-content/plugins';
  32.  
  33. ?>
  34. <link rel="stylesheet" type="text/css" media="all" href="<?php echo $m_pluginURL; ?>/<?php echo  "/wordpress-tooltips" ?>/js/jdirectory/directory.css" title="green" />
  35.  
  36.  
  37.     <script type="text/javascript">
  38.     if(typeof jQuery=='undefined')
  39.     {
  40.         document.write('<'+'script src="<?php echo $m_pluginURL; ?>/<?php echo  '/wordpress-tooltips'; ?>/js/qtip/jquery.js" type="text/javascript"></'+'script>');
  41.     }
  42.     </script>
  43.    
  44.     <script type="text/javascript" src="<?php echo $m_pluginURL; ?>/<?php echo  "/wordpress-tooltips" ?>/js/qtip/jquery.qtip-1.0.0-rc3.min.js"></script>
  45.     <script type="text/javascript" src="<?php echo $m_pluginURL; ?>/<?php echo  "/wordpress-tooltips" ?>/js/jdirectory/jquery.directory.js"></script>
  46.     <script type="text/javascript">
  47.  
  48.     function toolTips(whichID,theTipContent)
  49.     {
  50.             jQuery(whichID).qtip
  51.             (
  52.                 {
  53.                     content:theTipContent,
  54.                     style:
  55.                     {
  56.                         width: 400,
  57.                         padding: 5,
  58.                         background: '#fcfcec',
  59.                         color: 'black',
  60.                         textAlign: 'left',
  61.                         border:
  62.                         {
  63.                             width: 1,
  64.                             radius: 8,
  65.                             color: '#eee'
  66.                         }
  67.                     },
  68.                     position:
  69.                     {
  70.                         corner:
  71.                         {
  72.                             target: 'rightMiddle',
  73.                             tooltip: 'leftBottom'
  74.                         }
  75.                     },
  76.                     show:'mouseover',
  77.                     hide: { fixed: true, delay: 200 }
  78.                 }
  79.             )
  80.     }
  81. </script>
  82.    
  83. <?php
  84. }
  85.  
  86. function tooltipsMenu()
  87. {
  88.  
  89.     add_menu_page(__('Tooltips','Tooltips'), __('Tooltips','Tooltips'), 'edit_posts', 'tooltipsfunctions.php','editTooltips');
  90.     add_submenu_page('tooltipsfunctions.php',__('Edit Tooltips','Tooltips'), __('Edit Tooltips','Tooltips'),'edit_posts', 'tooltipsfunctions.php','editTooltips');
  91. }
  92.  
  93. add_action('admin_menu', 'tooltips_menu');
  94.  
  95. function tooltips_menu() {
  96.     add_submenu_page('edit.php?post_type=tooltips',__('Global Settings','Tooltips'), __('Global Settings','Tooltips'),'edit_posts', 'tooltipglobalsettings','tooltipGlobalSettings');
  97. }
  98.  
  99. function showTooltips($content)
  100. {
  101.     global $table_prefix,$wpdb,$post;
  102.  
  103.     do_action('action_before_showtooltips', $content);
  104.     remove_filter('the_title', 'wptexturize');    // version 3.5.1
  105.     $content = apply_filters( 'filter_before_showtooltips',  $content);
  106.    
  107.     //!!! $m_result = get_option('tooltipsarray');
  108.     $curent_post = get_post($post);
  109.    
  110.     $curent_content = $curent_post->post_content;
  111.  
  112.    
  113.     $m_result = tooltips_get_option('tooltipsarray');
  114.     $m_keyword_result = '';
  115.     if (!(empty($m_result)))
  116.     {
  117.         $m_keyword_id = 0;
  118.         foreach ($m_result as $m_single)
  119.         {
  120.            
  121.                     if (stripos($curent_content,$m_single['keyword']) === false)
  122.                     {
  123.                        
  124.                     }
  125.                     else
  126.                     {          
  127.             $m_keyword_result .= '<script type="text/javascript">';
  128.             $m_content = $m_single['content'];
  129.             $m_content = str_ireplace('\\','',$m_content);
  130.             $m_content = str_ireplace("'","\'",$m_content);
  131.             $m_content = preg_replace('|\r\n|', '<br/>', $m_content);
  132.             if (!(empty($m_content)))
  133.             {
  134.                 $m_keyword_result .= " toolTips('.classtoolTips$m_keyword_id','$m_content'); ";
  135.             }
  136.             $m_keyword_result .= '</script>';
  137.                     }
  138.                     $m_keyword_id++;
  139.         }
  140.  
  141.  
  142.     }
  143.     $content = $content.$m_keyword_result;
  144.     do_action('action_after_showtooltips', $content);
  145.     $content = apply_filters( 'filter_after_showtooltips',  $content);
  146.     add_filter('the_title', 'wptexturize'); // version 3.5.1
  147.     return $content;
  148. }
  149.  
  150. function showTooltipsInTag($content)
  151. {
  152.     global $table_prefix,$wpdb,$post;
  153.  
  154.     do_action('action_before_showtooltipsintag', $content);
  155.     $content = apply_filters( 'filter_before_showtooltipsintag',  $content);
  156.     //!!! $m_result = get_option('tooltipsarray');
  157.    
  158.     $curent_content = $content;
  159.  
  160.    
  161.     $m_result = tooltips_get_option('tooltipsarray');
  162.     $m_keyword_result = '';
  163.     if (!(empty($m_result)))
  164.     {
  165.         $m_keyword_id = 0;
  166.         foreach ($m_result as $m_single)
  167.         {
  168.            
  169.                     if (stripos($curent_content,$m_single['keyword']) === false)
  170.                     {
  171.                        
  172.                     }
  173.                     else
  174.                     {          
  175.             $m_keyword_result .= '<script type="text/javascript">';
  176.             $m_content = $m_single['content'];
  177.             $m_content = str_ireplace('\\','',$m_content);
  178.             $m_content = str_ireplace("'","\'",$m_content);
  179.             $m_content = preg_replace('|\r\n|', '<br/>', $m_content);
  180.             if (!(empty($m_content)))
  181.             {
  182.                 $m_keyword_result .= " toolTips('.classtoolTips$m_keyword_id','$m_content'); ";
  183.             }
  184.             $m_keyword_result .= '</script>';
  185.                     }
  186.                     $m_keyword_id++;
  187.         }
  188.  
  189.  
  190.     }
  191.     $content = $content.$m_keyword_result;
  192.  
  193.     do_action('action_after_showtooltipsintag', $content);
  194.     $content = apply_filters( 'filter_after_showtooltipsintag',  $content);
  195.  
  196.     return $content;
  197. }
  198.  
  199.  
  200. function tooltipsInContent($content)
  201. {
  202.     do_action('action_before_tooltipsincontent', $content);
  203.     $content = apply_filters( 'filter_before_tooltipsincontent',  $content);
  204.        
  205.     $onlyFirstKeyword = get_option("onlyFirstKeyword");
  206.     if  ($onlyFirstKeyword == false)
  207.     {
  208.         $onlyFirstKeyword = 'all';
  209.     }
  210.  
  211.     $m_result = tooltips_get_option('tooltipsarray');
  212.     if (!(empty($m_result)))
  213.     {
  214.         $m_keyword_id = 0;
  215.         foreach ($m_result as $m_single)
  216.         {
  217.        
  218.             $m_keyword = $m_single['keyword'];
  219.             $m_content = $m_single['content'];
  220.             $m_replace = "<span class='classtoolTips$m_keyword_id' style='border-bottom:2px dotted #888;'>$m_keyword</span>";
  221.    
  222.             if (stripos($content,$m_keyword) === false)
  223.             {
  224.                
  225.             }
  226.             else
  227.             {
  228.                 //!!! 3.0.1 $content = preg_replace("/(\W)(".$m_keyword.")(?![^<|^\[]*[>|\]])(\W)/is","\\1"."<span class='classtoolTips$m_keyword_id' style='border-bottom:2px dotted #888;'>"."\\2"."</span>"."\\3",$content);
  229.                 if ($onlyFirstKeyword == 'all')
  230.                 {
  231.                     $content = preg_replace("/(\W)(".$m_keyword.")(?![^<|^\[]*[>|\]])(\W)/is","\\1"."<span class='classtoolTips$m_keyword_id' style='border-bottom:2px dotted #888;'>"."\\2"."</span>"."\\3",$content);
  232.                 }
  233.            
  234.                 if ($onlyFirstKeyword == 'first')
  235.                 {
  236.                     $content = preg_replace("/(\W)(".$m_keyword.")(?![^<|^\[]*[>|\]])(\W)/is","\\1"."<span class='classtoolTips$m_keyword_id' style='border-bottom:2px dotted #888;'>"."\\2"."</span>"."\\3",$content,1);
  237.                 }
  238.             }
  239.             $m_keyword_id++;
  240.         }
  241.     }
  242.    
  243.     do_action('action_after_tooltipsincontent', $content);
  244.     $content = apply_filters( 'filter_after_tooltipsincontent',  $content);
  245.        
  246.     return $content;
  247. }
  248.  
  249. function nextgenTooltips()
  250. {
  251. ?>
  252. <script type="text/javascript">
  253.     jQuery("img").load(function()
  254.     {
  255.         if ((jQuery(this).parent("a").attr('title') != '' )  && (jQuery(this).parent("a").attr('title') != undefined ))
  256.         {
  257.             toolTips(jQuery(this).parent("a"),jQuery(this).parent("a").attr('title'));
  258.         }
  259.         else
  260.         {
  261.             var tempAlt = jQuery(this).attr('alt');
  262.             tempAlt = tempAlt.replace(' ', '');
  263.             if (tempAlt == '')
  264.             {
  265.                
  266.             }
  267.             else
  268.             {
  269.                 toolTips(jQuery(this),jQuery(this).attr('alt'));
  270.             }
  271.         }
  272.     }
  273.  
  274.     );
  275. </script>
  276. <?php
  277. }
  278.  
  279. function tooltipsAdminHead()
  280. {
  281. ?> 
  282. <style type="text/css">
  283. span.question, span.questionimage, span.questionexcerpt, span.questiontags {
  284.   cursor: pointer;
  285.   display: inline-block;
  286.   line-height: 14px;
  287.   width: 14px;
  288.   height: 14px;
  289.   border-radius: 7px;
  290.   -webkit-border-radius:7px;
  291.   -moz-border-radius:7px;
  292.   background: #5893ae;
  293.   color: #fff;
  294.   text-align: center;
  295.   position: relative;
  296.   font-size: 10px;
  297.   font-weight: bold;
  298. }
  299. span.question:hover { background-color: #21759b; }
  300. span.questionimage:hover { background-color: #21759b; }
  301. span.questiontags:hover { background-color: #21759b; }
  302.  
  303. div.tooltip {
  304.   text-align: left;
  305.   left: 25px;
  306.   background: #21759b;
  307.   color: #fff;
  308.   position: absolute;
  309.   z-index: 1000000;
  310.   width: 400px;
  311.   border-radius: 5px;
  312.   -webkit-border-radius:5px;
  313.   -moz-border-radius:5px;
  314. top: -80px;
  315. }
  316.  
  317. div.tooltip1 {
  318.   text-align: left;
  319.   left: 25px;
  320.   background: #21759b;
  321.   color: #fff;
  322.   position: absolute;
  323.   z-index: 1000000;
  324.   width: 400px;
  325.   border-radius: 5px;
  326.   -webkit-border-radius:5px;
  327.   -moz-border-radius:5px;
  328. top: -50px;
  329. }
  330. div.tooltip3 {
  331.   text-align: left;
  332.   left: 25px;
  333.   background: #21759b;
  334.   color: #fff;
  335.   position: absolute;
  336.   z-index: 1000000;
  337.   width: 400px;
  338.   border-radius: 5px;
  339.   -webkit-border-radius:5px;
  340.   -moz-border-radius:5px;
  341. top: -60px;
  342. }
  343. div.tooltip:before, .tooltip1:before, .tooltip3:before {
  344.   border-color: transparent #21759b transparent transparent;
  345.   border-right: 6px solid #21759b;
  346.   border-style: solid;
  347.   border-width: 6px 6px 6px 0px;
  348.   content: "";
  349.   display: block;
  350.   height: 0;
  351.   width: 0;
  352.   line-height: 0;
  353.   position: absolute;
  354.   top: 40%;
  355.   left: -6px;
  356. }
  357. div.tooltip p, .tooltip1 p, .tooltip3 p {
  358.   margin: 10px;
  359.  line-height:13px;
  360.  font-size:11px;
  361.  color:#eee;
  362. }
  363. </style>                                       
  364. <?php
  365. }                                      
  366. add_action('the_content','tooltipsInContent');
  367. //add_action('the_excerpt','tooltipsInContent');
  368. //add_action('the_tags','tooltipsInContent');
  369. add_action('wp_head', 'tooltipsHead');
  370. add_action('the_content','showTooltips');
  371. //add_action('the_excerpt','showTooltips');
  372. //add_action('the_tags','showTooltipsInTag');
  373. add_action('admin_head', 'tooltipsAdminHead');
  374.  
  375. $enableTooltipsForExcerpt = get_option("enableTooltipsForExcerpt");
  376. if ($enableTooltipsForExcerpt =='YES')
  377. {
  378.     add_action('the_excerpt','tooltipsInContent');
  379.     add_action('the_excerpt','showTooltips');  
  380. }
  381.  
  382. $enableTooltipsForTags = get_option("enableTooltipsForTags");
  383. if ($enableTooltipsForTags =='YES')
  384. {
  385.     add_action('the_tags','tooltipsInContent');
  386.     add_action('the_tags','showTooltipsInTag');
  387. }
  388.  
  389. $enableTooltipsForImageCheck = get_option("enableTooltipsForImage");
  390. if ($enableTooltipsForImageCheck == false)
  391. {
  392.     update_option("enableTooltipsForImage", "YES");
  393. }
  394. if ($enableTooltipsForImageCheck == 'YES')
  395. {
  396.     add_action('wp_footer','nextgenTooltips');
  397. }
  398.  
  399.  
  400. function add_tooltips_post_type() {
  401.   $labels = array(
  402.     'name' => __('Tooltips', 'tooltips'),
  403.     'singular_name' => __('Tooltip', 'tooltips'),
  404.     'add_new' => __('Add New', 'tooltips'),
  405.     'add_new_item' => __('Add New Tooltip', 'tooltips'),
  406.     'edit_item' => __('Edit Tooltip', 'tooltips'),
  407.     'new_item' => __('New Tooltip', 'tooltips'),
  408.     'all_items' => __('All Tooltips', 'tooltips'),
  409.     'view_item' => __('View Tooltip', 'tooltips'),
  410.     'search_items' => __('Search Tooltip', 'tooltips'),
  411.     'not_found' =>  __('No Tooltip found', 'tooltips'),
  412.     'not_found_in_trash' => __('No Tooltip found in Trash', 'tooltips'),
  413.     'menu_name' => __('Tooltips', 'tooltips')
  414.   );
  415.  
  416.   $args = array(
  417.     'labels' => $labels,
  418.     'public' => false,
  419.     'show_ui' => true,
  420.     'show_in_menu' => true,
  421.     '_builtin' =>  false,
  422.     'query_var' => "tooltips",
  423.     'rewrite' => false,
  424.     'capability_type' => 'post',
  425.     'has_archive' => false,
  426.     'hierarchical' => false,
  427.     'menu_position' => null,
  428.     'supports' => array( 'title', 'editor','author','custom-fields','thumbnail' )
  429.   );
  430.   register_post_type('tooltips', $args);
  431. }
  432. add_action( 'init', 'add_tooltips_post_type' );
  433.  
  434. function upgrade_check()
  435. {
  436.     $currentVersion = get_option('ztooltipversion');
  437.  
  438.     if (empty($currentVersion))
  439.     {
  440.         $m_result = get_option('tooltipsarray');
  441.         if (!(empty($m_result)))
  442.         {
  443.             $m_keyword_id = 0;
  444.             foreach ($m_result as $m_single)
  445.             {
  446.                 $m_keyword = $m_single['keyword'];
  447.                 $m_content = $m_single['content'];             
  448.                 $my_post = array(
  449.                 //'post_title'    => wp_strip_all_tags( $_POST['post_title'] ),
  450.                 'post_title'    => $m_keyword,
  451.                 'post_content'  => $m_content,
  452.                 'post_status'   => 'publish',
  453.                 'post_type'   => 'tooltips',
  454.                 'post_author'   => 1,
  455.                 );
  456.                 wp_insert_post( $my_post );
  457.             }
  458.         }
  459.    
  460.     }
  461.     update_option('ztooltipversion','3.0.0');
  462. }
  463. add_action( 'init', 'upgrade_check');
  464.  
  465. function tooltips_get_option($type)
  466. {
  467.     $tooltipsarray = array();
  468.     $m_single = array();
  469.     if ($type == 'tooltipsarray')
  470.     {
  471.         $type = 'tooltips';
  472.         $args=array(
  473.         'post_type' => $type,
  474.         'post_status' => 'publish',
  475.         'posts_per_page' => -1,
  476.         'ignore_sticky_posts'=> 1
  477.         );
  478.         $my_query = null;
  479.         $my_query = new WP_Query($args);
  480.         if( $my_query->have_posts() )
  481.         {
  482.             while ($my_query->have_posts()) : $my_query->the_post();
  483.             $m_single = array();
  484.             $m_single['keyword'] = get_the_title();
  485.             $m_single['content'] = get_the_content();
  486.             $tooltipsarray[] = $m_single;
  487.             endwhile;
  488.         }
  489.         wp_reset_query();
  490.     }
  491.     return $tooltipsarray;
  492. }
  493.  
  494. $enableTooltipsForImageCheck = get_option("enableTooltipsForImage");
  495. if ($enableTooltipsForImageCheck == false)
  496. {
  497.     update_option("enableTooltipsForImage", "YES");
  498. }
  499.  
  500. // version 3.4.3
  501. function showTooltipsInShorcode($content)
  502. {
  503.     global $table_prefix,$wpdb,$post;
  504.  
  505.     do_action('action_before_showtooltips', $content);
  506.     $content = apply_filters( 'filter_before_showtooltips',  $content);
  507.    
  508.  
  509.     $curent_content = $content;
  510.  
  511.    
  512.     $m_result = tooltips_get_option('tooltipsarray');
  513.     $m_keyword_result = '';
  514.     if (!(empty($m_result)))
  515.     {
  516.         $m_keyword_id = 0;
  517.         foreach ($m_result as $m_single)
  518.         {
  519.            
  520.                     if (stripos($curent_content,$m_single['keyword']) === false)
  521.                     {
  522.                        
  523.                     }
  524.                     else
  525.                     {          
  526.             $m_keyword_result .= '<script type="text/javascript">';
  527.             $m_content = $m_single['content'];
  528.             $m_content = str_ireplace('\\','',$m_content);
  529.             $m_content = str_ireplace("'","\'",$m_content);
  530.             $m_content = preg_replace('|\r\n|', '<br/>', $m_content);
  531.             if (!(empty($m_content)))
  532.             {
  533.                 $m_keyword_result .= " toolTips('.classtoolTips$m_keyword_id','$m_content'); ";
  534.             }
  535.             $m_keyword_result .= '</script>';
  536.                     }
  537.                     $m_keyword_id++;
  538.         }
  539.  
  540.  
  541.     }
  542.     $content = $content.$m_keyword_result;
  543.     do_action('action_after_showtooltips', $content);
  544.     $content = apply_filters( 'filter_after_showtooltips',  $content);
  545.     return $content;
  546. }
  547. // version 3.4.3
  548. function tooltips_list_shortcode($atts)
  549. {
  550.     global $table_prefix,$wpdb,$post;
  551.  
  552.     $args = array( 'post_type' => 'tooltips', 'post_status' => 'public' );
  553.     $loop = new WP_Query( $args );
  554.     $return_content = '';
  555.     $return_content .= '<div class="tooltips_directory">';
  556.     while ( $loop->have_posts() ) : $loop->the_post();
  557.         $return_content .= '<div class="tooltips_list">'.get_the_title().'</div>';
  558.     endwhile;
  559.     $return_content = tooltipsInContent($return_content);
  560.     $return_content = showTooltipsInShorcode($return_content);
  561.  
  562.     $return_content .= '</div>';
  563.    
  564.     return $return_content;
  565. }
  566. // version 3.4.3
  567. add_shortcode( 'tooltipslist', 'tooltips_list_shortcode' );
  568.  
  569. //version 3.4.7
  570. add_action('widgets_init', 'TooltipsWidgetInit');
  571.  
  572. // version 3.4.9
  573. /**** localization ****/
  574. add_action('plugins_loaded','tooltips_load_textdomain');
  575.  
  576. function tooltips_load_textdomain()
  577. {
  578.     load_plugin_textdomain('wordpress-tooltips', false, dirname( plugin_basename( __FILE__ ) ).'/languages/');
  579. }
  580.  
  581.  
  582. function footernav()
  583. {
  584.     //version 3.4.5
  585. ?>
  586. <script type="text/javascript">
  587. jQuery('.tooltips_directory').directory();
  588. </script>
  589. <?php
  590. }
  591. add_action('wp_footer','footernav');
  592. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement