Advertisement
Guest User

collapse-o-matic.php

a guest
Oct 31st, 2012
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.40 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: jQuery Collapse-O-Matic
  4. Plugin URI: http://plugins.twinpictures.de/plugins/collapse-o-matic/ Description: Collapse-O-Matic adds an [expand] shortcode that wraps content into a lovely, jQuery collapsible div.  Version: 1.4.9 Author: twinpictures, baden03 Author URI: http://twinpictures.de/
  5. License: GPL2
  6.  
  7. */
  8.  
  9. /*  Copyright 2012 Twinpictures (www.twinpictures.de)
  10.  
  11.     This program is free software; you can redistribute it and/or modify
  12.     it under the terms of the GNU General Public License, version 2, as
  13.     published by the Free Software Foundation.
  14.  
  15.     This program is distributed in the hope that it will be useful,
  16.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.     GNU General Public License for more details.
  19.  
  20.     You should have received a copy of the GNU General Public License
  21.     along with this program; if not, write to the Free Software
  22.     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  23. */
  24.  
  25.  
  26.  
  27. /* AA 20121031 Stolen from j-shortcodes.
  28.     Allows nesting of the expand shortcodes by adding "=" to the front of the nested ones.
  29.     ie.
  30.     [expand ...]
  31.         [=expand ...]
  32.             [==expand ...]
  33.             [==/expand]
  34.         [=/expand]
  35.     [/expand]
  36.  */
  37. function recursive__do_shortcode ($content)
  38. {
  39.   // Quick test for presence of possibly nested shortcodes
  40.     if (strpos ($content, '[=') !== FALSE)
  41.   {
  42.         // remove one '=' --> un-nest one level
  43.     $content = preg_replace ('@(\[=*)=(e|/)@', "$1$2", $content);
  44.   }
  45.   return do_shortcode ($content);
  46. }
  47.  
  48.  
  49. function collapsTronicInit() {
  50.     wp_enqueue_script('jquery');
  51.     if (!is_admin()){
  52.         //collapse script
  53.         wp_register_script('collapseomatic-js', plugins_url('/collapse.min.js', __FILE__), array('jquery'), '1.4.9');
  54.         //wp_register_script('collapseomatic-js', plugins_url('/collapse.js', __FILE__), array('jquery'), '1.4.9');
  55.         wp_enqueue_script('collapseomatic-js');
  56.  
  57.             //css
  58.         wp_register_style( 'collapseomatic-css', plugins_url('/style.css', __FILE__) , array (), '1.5.2' );
  59.         wp_enqueue_style( 'collapseomatic-css' );
  60.     }
  61.    
  62.     add_shortcode('expand', 'collapsTronic');
  63.    
  64.     for ($i=1; $i<30; $i++) {
  65.         add_shortcode('expandsub'.$i, 'collapsTronic');
  66.     }
  67.    
  68.     //add the filter to the sidebar widgets
  69.     add_filter('widget_text', 'do_shortcode');
  70. }
  71. add_action('init', 'collapsTronicInit');
  72.        
  73.  
  74. function collapsTronic($atts, $content = null){
  75.     //find a random number, incase there is no id assigned
  76.     $ran = rand(1, 10000);
  77.     extract(shortcode_atts(array(
  78.         'title' => '',
  79.         'swaptitle' => '',
  80.         'alt' => '',
  81.         'notitle' => '',
  82.         'id' => 'id'.$ran,
  83.         'tag' => 'span',
  84.         'trigclass' => '',
  85.         'targclass' => '',
  86.         'trigpos' => 'above',
  87.         'rel' => '',
  88.         'expanded' => '',
  89.         'excerpt' => '',
  90.         'excerptpos' => 'below-trigger',
  91.         'excerpttag' => 'div',
  92.         'excerptclass' => '',
  93.         'findme' => '',
  94.         'scrollonclose' => '',
  95.         'startwrap' => '',
  96.         'endwrap' => '',
  97.         'wraptag' => ''             //AA 20121031 eg. 'h2' will wrap the title in <h2> $title </h2>
  98.     ), $atts));
  99.     if($excerpt){
  100.         if($excerptpos == 'above-trigger'){
  101.             $nibble = '<'.$excerpttag.' class="'.$excerptclass.'">'.$excerpt.'</'.$excerpttag.'>';
  102.         }
  103.         else{
  104.             $nibble = '<'.$excerpttag.' class="collapseomatic_excerpt '.$excerptclass.'">'.$excerpt.'</'.$excerpttag.'>';
  105.         }
  106.        
  107.     }
  108.     $altatt = '';
  109.     if($alt){
  110.         $altatt = 'alt="'.$alt.'" title="'.$alt.'"';
  111.     }
  112.     else if( !$notitle ){
  113.         $altatt = 'title="'.$title.'"';
  114.     }
  115.     $relatt = '';
  116.     if($rel){
  117.         $relatt = 'rel="'.$rel.'"';
  118.     }
  119.     if($expanded){
  120.         $trigclass .= ' colomat-close';
  121.     }
  122.     $anchor = '';
  123.     if($findme){
  124.         $trigclass .= ' find-me';
  125.         $offset = '';
  126.         if($findme != 'true' && $findme != 'auto'){
  127.             $offset = $findme;
  128.         }
  129.         $anchor = '<a id="find-'.$id.'" name="'.$offset.'"> </a>';
  130.     }
  131.     $closeanchor = '';
  132.     if($scrollonclose && (is_numeric($scrollonclose) || $scrollonclose == 0)){
  133.         $trigclass .= ' scroll-to-trigger';
  134.         $closeanchor = '<a id="scrollonclose-'.$id.'" name="'.$scrollonclose.'"> </a>';
  135.     }
  136.     //AA 20121031 wrap startwrap and endwrap with wraptag if it was passed through
  137.     if($wraptag != ''){
  138.         $startwrap = "<" . $wraptag . ">" . $startwrap;
  139.         $endwrap = "</" . $wraptag . ">" . $endwrap;
  140.     }
  141.     $link = $closeanchor.$anchor.'<'.$tag.' class="collapseomatic '.$trigclass.'" id="'.$id.'" '.$relatt.' '.$altatt.'>'.$startwrap.$title.$endwrap.'</'.$tag.'>';
  142.     if($swaptitle){
  143.         $link .= "<".$tag." id='swap-".$id."' style='display:none;'>".$startwrap.$swaptitle.$endwrap."</".$tag.">";
  144.     }
  145.  
  146.     $eDiv = '';
  147.     if($content){
  148.         //AA 20121031 Use recursive__do_shortcode() instead
  149.         $eDiv = '<div id="target-'.$id.'" class="collapseomatic_content '.$targclass.'">'.recursive__do_shortcode($content).'</div>';
  150.     }
  151.    
  152.     if($excerpt){
  153.         if($excerptpos == 'above-trigger'){
  154.             if($trigpos == 'below'){
  155.                 $retStr = $eDiv.$nibble.$link;
  156.             }
  157.             else{
  158.                 $retStr = $nibble.$link.$eDiv;
  159.             }
  160.         }
  161.         else if($excerptpos == 'below-trigger'){
  162.             if($trigpos == 'below'){
  163.                 $retStr =  $eDiv.$link.$nibble;
  164.             }
  165.             else{
  166.                 $retStr = $link.$nibble.$eDiv;
  167.             }
  168.         }
  169.         else{
  170.             if($trigpos == 'below'){
  171.                 $retStr = $eDiv.$link.$nibble;
  172.             }
  173.             else{
  174.                 $retStr = $link.$eDiv.$nibble;
  175.             }
  176.         }
  177.     }
  178.     else{
  179.         if($trigpos == 'below'){
  180.             $retStr = $eDiv.$link;
  181.         }
  182.         else{
  183.             $retStr = $link.$eDiv;
  184.         }
  185.     }
  186.     //return '<span class="removeomatic">'.$retStr.'</span>';
  187.     return $retStr;
  188. }
  189. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement