Plugin Directory

Changeset 517648


Ignore:
Timestamp:
03/11/2012 09:11:47 PM (14 years ago)
Author:
smartredfox
Message:
  • Fixed initial style not set (BUG)
  • Added editor button to insert shortcode (FEATURE)
  • Added shortcode wizard to insert shortcode (FEATURE)
  • Now reads custom css files from a folder in your theme directory (stops files getting wiped after upgrade).
Location:
pretty-file-lister/trunk
Files:
5 added
3 edited

Legend:

Unmodified
Added
Removed
  • pretty-file-lister/trunk/PrettyFileList.php

    r514601 r517648  
    44   Plugin URI: http://www.smartredfox.com/prettylist
    55   Description: A plugin that lists files attached to the current post/page.
    6    Version: 0.1
     6   Version: 0.2
    77   Author: James Botham
    88   Author URI: http://www.smartredfox.com
     
    2121        if(!is_admin())
    2222        {
    23             add_shortcode('prettyfilelist', array($this, 'prettyfilelist_shortcode'));         
     23            add_shortcode('prettyfilelist', array($this, 'prettyfilelist_shortcode'));
    2424        }
    2525    }
     
    5151            //Attach save event for Settings page
    5252            add_filter( 'attachment_fields_to_save', array($this,'srf_attachment_field_prettylist_save'), 10, 2 );             
     53            //Add shortcode button
     54            add_action('init', array($this,'add_button'));
    5355        }
    5456    } 
     
    8890        return $html;
    8991    }
    90  
     92
    9193    //Add Stylesheet
    9294    public function prettyfilelist_stylesheets()
     
    9496        //Get user selected stylesheet if any
    9597        $options['stylesheet_to_use'] = get_option('stylesheet_to_use');
    96 
    97         $stylesheet_url = PRETTY_FILE_LIST_URL . '/styles/prettylist.css';
    98 
     98        $option = $options['stylesheet_to_use'];
     99        $stylesheet_url = PRETTY_FILE_LIST_URL . 'styles/prettylinks.css';
     100
     101        //Add our prettylist stylesheet
    99102        if($options['stylesheet_to_use'] != ""){
    100             //Add our prettylist stylesheet
    101             $stylesheet_url = PRETTY_FILE_LIST_URL . '/styles/' . $options['stylesheet_to_use'];   
    102         }
     103            //See if the selected style has a hash in it (this means it's an alt style)
     104            if(strpos($options['stylesheet_to_use'],'#') > 0){
     105                //See if the file exists in the template directory first
     106                //if(!file_exists($stylesheet_url)){
     107                $cleanOption = str_replace("#", "", $option);
     108                $stylesheet_url = (get_bloginfo('template_url') . '/prettystyles/' . $cleanOption);
     109                //}
     110            }
     111            else{
     112                //If not, fallback to plugin version
     113                $stylesheet_url = (PRETTY_FILE_LIST_URL . 'styles/' . $options['stylesheet_to_use']);
     114            }
     115        }
     116       
     117        //echo $stylesheet_url;
    103118       
    104119        wp_register_style('srfprettylistStyleSheets', $stylesheet_url);
    105         wp_enqueue_style( 'srfprettylistStyleSheets'); 
     120        wp_enqueue_style( 'srfprettylistStyleSheets');
    106121    } 
    107122   
     
    216231    function srf_prettylist_admin_scripts()
    217232    {
    218       $params = array('pluginUrl' => PRETTY_FILE_LIST_URL); 
     233      $params = array('pluginUrl' => PRETTY_FILE_LIST_URL,'altPluginUrl' => get_bloginfo('template_directory') . '/prettystyles/');
    219234      wp_register_script('prettylistpreviewer', PRETTY_FILE_LIST_URL . '/js/style_previewer.js');
    220235      wp_localize_script('prettylistpreviewer', 'prettylistScriptParams', $params );
     
    245260      }
    246261
    247       //path to directory to scan
     262      //Path to directories to scan
    248263      $directory = PRETTY_FILE_LIST_PATH . '/styles/';
     264      $altDirectory = get_template_directory() . '/prettystyles/';
    249265     
    250266      //get all css files with a .css extension.
    251267      $styles = glob($directory . "*.css");
     268      $altStyles = glob($altDirectory . "*.css"); 
    252269     
    253270      //Get our options
    254271      $options['stylesheet_to_use'] = get_option('stylesheet_to_use');
    255272
    256       //Display options form
    257       echo '<div style="background-color:#eee;border:solid 1px #ccc;border-radius:3px;float:right;margin:20px;padding:10px;width:300px;">
     273    //Display options form
     274    echo '<div style="background-color:#eee;border:solid 1px #ccc;border-radius:3px;float:right;margin:20px;padding:10px;width:300px;">
    258275            <div style="background-color:#fff;border:solid 1px #ccc;float:right;">
    259276                <img src="http://www.smartredfox.com/wp-content/uploads/2012/02/All_styles-150x150.png" style="margin:5px;" />
     
    265282            <div class="wrap">'.$message.
    266283        '<div id="icon-options-general" class="icon32"><br /></div> 
    267         <h2>prettylist Settings</h2> 
     284        <h2>Pretty file list Settings</h2> 
    268285     
    269286        <form method="post" action=""> 
     
    278295      {
    279296        echo '<option value="' . basename($style) .'"' . (basename($style) == $options['stylesheet_to_use'] ? 'selected="selected"' : '')  . '>' . basename($style) . '</option>';
     297      }
     298      foreach($altStyles as $style)
     299      {
     300        echo '<option value="' . basename($style) .'#"' . (basename($style) == $options['stylesheet_to_use'] ? 'selected="selected"' : '')  . '>' . basename($style) . ' (Custom)</option>';
    280301      }
    281302     
     
    301322      return $post;
    302323    }
     324   
     325    /*********************
     326    ADD SHORTCODE BUTTON
     327    **********************/
     328   
     329    function add_button() { 
     330       if ( current_user_can('edit_posts') &&  current_user_can('edit_pages') ) 
     331       { 
     332         add_filter('mce_external_plugins', array($this,'add_plugin'));
     333         add_filter('mce_buttons', array($this,'register_button'));
     334       } 
     335    } 
     336   
     337    function register_button($buttons) { 
     338       array_push($buttons, "prettylist"); 
     339       return $buttons; 
     340    } 
     341   
     342    function add_plugin($plugin_array) { 
     343       $plugin_array['prettylist'] = PRETTY_FILE_LIST_URL.'js/prettygen.js'; 
     344       return $plugin_array; 
     345    }
     346   
     347    /*************************
     348    UPGRADE FUNCTIONALITY TO SAVE STYLE PACK
     349    **************************/
     350    function hpt_copyr($source, $dest)
     351    {
     352        // Check for symlinks
     353        if (is_link($source)) {
     354            return symlink(readlink($source), $dest);
     355        }
     356 
     357        // Simple copy for a file
     358        if (is_file($source)) {
     359            return copy($source, $dest);
     360        }
     361
     362        // Make destination directory
     363        if (!is_dir($dest)) {
     364            mkdir($dest);   
     365        }
     366 
     367        // Loop through the folder
     368        $dir = dir($source);
     369        while (false !== $entry = $dir->read()) {
     370            // Skip pointers
     371            if ($entry == '.' || $entry == '..') {
     372                continue;
     373            }
     374
     375            // Deep copy directories
     376            $this->hpt_copyr("$source/$entry", "$dest/$entry");
     377        }
     378
     379        // Clean up
     380        $dir->close();
     381        return true;
     382    }
     383   
     384    function hpt_backup()
     385    {
     386            $from = PRETTY_FILE_LIST_PATH."styles/";
     387            $to = WP_CONTENT_DIR."/uploads/prettystyles/";
     388            $this->hpt_copyr($from, $to);
     389    }
     390    function hpt_recover()
     391    {       
     392            $from = WP_CONTENT_DIR."/uploads/prettystyles/";
     393            $to = PRETTY_FILE_LIST_PATH."styles/";         
     394            $this->hpt_copyr($from, $to);
     395            if (is_dir($from)) {
     396                rmdir($from);
     397            }
     398    }   
    303399
    304400 
  • pretty-file-lister/trunk/js/style_previewer.js

    r514601 r517648  
    44    {   
    55        jQuery.get(prettylistScriptParams.pluginUrl + '/styles/prettylist.css', updateImageUrls);
    6        
    76    }
    87    else
    98    {
    10         jQuery.get(prettylistScriptParams.pluginUrl + '/styles/' + jQuery('#show_pages').attr('value'), updateImageUrls);
     9        //If it contains a hash it's an alt style
     10        if((jQuery('#show_pages').attr('value')).indexOf('#') > 0){
     11            jQuery.get(prettylistScriptParams.altPluginUrl + jQuery('#show_pages').attr('value'), updateImageUrls);
     12        }
     13        else{
     14            jQuery.get(prettylistScriptParams.pluginUrl + '/styles/' + jQuery('#show_pages').attr('value'), updateImageUrls);
     15        }
    1116    }
    1217   
    13     /*After selecting a stylesheet*/   
     18    /*After selecting a stylesheet*/
    1419    jQuery('#show_pages').change(function(){
     20            //If it contains a hash it's an alt style
     21        if((jQuery('#show_pages').attr('value')).indexOf('#') > 0){
     22            jQuery.get(prettylistScriptParams.altPluginUrl + jQuery('#show_pages').attr('value'), updateImageUrls);
     23        }
     24        else{
     25            jQuery.get(prettylistScriptParams.pluginUrl + '/styles/' + jQuery('#show_pages').attr('value'), updateImageUrls);
     26        }
     27   
    1528        //Load styles
    16         jQuery.get(prettylistScriptParams.pluginUrl + '/styles/' + jQuery(this).attr('value'), updateImageUrls);
     29        //jQuery.get(prettylistScriptParams.pluginUrl + '/styles/' + jQuery(this).attr('value'), updateImageUrls);
    1730    });
    1831   
    19     function updateImageUrls(data) {
    20         //Make image paths work with a greedy regex
    21         newData = data.replace( new RegExp( "../images/", "g" ), prettylistScriptParams.pluginUrl + '/images/' );
     32    //Make image paths work in the previewer
     33    function updateImageUrls(data) {       
     34        //If it contains a hash it's an alt style
     35        if((jQuery('#show_pages').attr('value')).indexOf('#') > 0){
     36            //Make image paths work with a greedy regex
     37            //Uses "../i because we can't be sure if it will be images or img.
     38            //Also uses ../../../ to fix style pack icons
     39            //Also looks for a bracket or quote to stop ../../ etc from matching
     40            //This will not always work.
     41            newData = data.replace( new RegExp( '"../i', 'g' ), '"' + prettylistScriptParams.altPluginUrl + 'i' );     
     42            newData = data.replace( new RegExp( '\\(../i', 'g' ),'(' +  prettylistScriptParams.altPluginUrl + 'i' );       
     43            newData = data.replace( new RegExp( '.../../../plugins/pretty-file-lister/', 'g' ),'(' +  prettylistScriptParams.pluginUrl + '' ); 
     44        }
     45        else{
     46            //Make image paths work with a greedy regex
     47            newData = data.replace( new RegExp( '../images/', 'g' ), prettylistScriptParams.pluginUrl + 'images/' );
     48        }
     49       
    2250        //Empty and refill styles section
    2351        jQuery('#Previewer').empty().append(newData);
  • pretty-file-lister/trunk/readme.txt

    r515211 r517648  
    44Requires at least: 3.0.0
    55Tested up to: 3.3.1
    6 Stable tag: 0.1
     6Stable tag: 0.2
    77
    88The Pretty file list plugin lists files attached to a post, displays them, and pages them in an attractive format without you having to do any work. It’s designed to be very easy to use, and even comes with built in styles for different set ups.
     
    26263. An example of the split Pretty File List style.
    2727
    28 
    2928== Changelog ==
    3029
    3130= 0.1 =
    3231* Initial release
     32
     33= 0.2 =
     34* Fixed initial style not set (BUG)
     35* Added editor button to insert shortcode (FEATURE)
     36* Added shortcode wizard to insert shortcode (FEATURE)
     37* Now reads custom css files from a folder in your theme directory (stops files getting wiped after upgrade).
     38
     39== Upgrade Notice ==
     40
     41= 0.2 =
     42If you are using the Style Pack you will need to [redownload it (Style Pack v0.3)](http://www.smartredfox.com/style-pack-download/) and install it into your theme directory.
Note: See TracChangeset for help on using the changeset viewer.