Plugin Directory

Changeset 732164


Ignore:
Timestamp:
06/26/2013 02:03:03 PM (13 years ago)
Author:
smartredfox
Message:

0.8

  • Added file size to listed items - with option to turn off in settings.
  • Changed to single text box for new media uploader.
  • Added xslx, pptx, doc, and rar support.
Location:
pretty-file-links/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pretty-file-links/trunk/PrettyFileLinks.php

    r548694 r732164  
    44   Plugin URI: http://www.smartredfox.com/prettylinks
    55   Description: A plugin that makes file links in pages much prettier.
    6    Version: 0.7
     6   Version: 0.8
    77   Author: James Botham
    88   Author URI: http://www.smartredfox.com
     
    1919        $this->setup_actions();         
    2020       
    21         if(!is_admin())
    22         {
    23                     add_shortcode('prettyfilelink', array($this, 'prettyfilelinks_shortcode'));
    24         }
     21       
     22        //Add shortcode
     23        add_shortcode('prettyfilelink', array($this, 'prettyfilelinks_shortcode'));
    2524    } 
    2625
     
    3837     */ 
    3938    function setup_actions(){
    40             if(!is_admin())
    41             {
    42                 //Add stylesheets
    43                 add_action('init', array($this,'prettyfilelinks_stylesheets'));
    44             }
    45             else
    46             {           
    47                 //Add option to media upload page in admin
    48                 add_filter( 'attachment_fields_to_edit', array($this,'srf_attachment_field_prettylinks'), 10, 2 );
    49                 //Filter to add shortcode into content from admin
    50                 add_filter('media_send_to_editor', array($this,'srf_add_prettylinks_shortcode_to_editor'), 20, 3);
    51                 //Attach the settings menu
    52                 add_action('admin_menu', array($this,'srf_prettylinks_admin_menu'));
    53                 //Attach save event for Settings page
    54                 add_filter( 'attachment_fields_to_save', array($this,'srf_attachment_field_prettylinks_save'), 10, 2 );             
    55             }
    56 
     39        if(!is_admin())
     40        {
     41            //Add stylesheets
     42            add_action('init', array($this,'prettyfilelinks_stylesheets'));
     43        }
     44        else
     45        {           
     46            //Add option to media upload page in admin
     47            add_filter( 'attachment_fields_to_edit', array($this,'srf_attachment_field_prettylinks'), 10, 2 );
     48            //Filter to add shortcode into content from admin
     49            add_filter('media_send_to_editor', array($this,'srf_add_prettylinks_shortcode_to_editor'), 20, 3);
     50            //Attach the settings menu
     51            add_action('admin_menu', array($this,'srf_prettylinks_admin_menu'));
     52            //Attach save event for Settings page
     53            add_filter( 'attachment_fields_to_save', array($this,'srf_attachment_field_prettylinks_save'), 10, 2 );             
     54            //Set domain for translations
     55            load_plugin_textdomain( 'prettyfilelist', false, dirname(plugin_basename( __FILE__ )));
     56        }
     57    }
    5758     
    5859    //Output shortcode
     
    6263            "type" => "note",
    6364            "src" => "#",
    64                         "newwindow" => false
     65            "newwindow" => false,
     66            "size" => ''
    6567        ), $atts));
    66        
    67         $returnString = '<a class="prettylink ' . $type . '" ' . ($newwindow ? 'target="_blank"' : '') . ' href="' . $src .'">' . $content .'</a>';
     68               
     69        $returnString = '<a class="prettylink ' . $type . '" ' . ($newwindow ? 'target="_blank"' : '') . ' href="' . $src .'"><span style="float:right">' . $size . '</span>' . $content .'</a>';
    6870
    6971        return $returnString;
     
    103105    //Add out pretty file links option to the upload media page
    104106    //todo:check file uploaded and only show if matched
    105     function srf_attachment_field_prettylinks( $form_fields, $post ){
    106 
    107       // Set up options
    108       $options = array( '1' => 'Yes', '0' => 'No' );
    109      
    110       // Get currently selected value
    111       $selected = get_post_meta( $post->ID, 'srf_prettylinks-include', true );
    112      
    113       // If no selected value, default to 'Yes'
    114       if( !isset( $selected ) )
    115         $selected = '1';
    116      
    117       // Display each option 
    118       foreach ( $options as $value => $label ) {
    119         $checked = '';
    120         $css_id = 'srf_prettylinks-include-option-' . $value;
    121 
    122         if ( $selected == $value ) {
    123           $checked = " checked='checked'";
    124         }
    125 
    126         $html = "<div class='srf_prettylinks-include-option'><input type='radio' name='attachments[$post->ID][srf_prettylinks-include]' id='{$css_id}' value='{$value}'$checked />";
    127         $html .= "<label for='{$css_id}'>$label</label>";
     107    function srf_attachment_field_prettylinks( $form_fields, $post ){       
     108
     109        $html = "<div class='srf_prettylinks-include-option'>";
     110            $html .= "<label class='setting' for='srf_prettylinks-include-option-checked'><span>" . __( 'Make pretty link', 'prettyfilelink' ) . "</span></label>";
     111            $html = "<input type='checkbox' name='attachments[$post->ID][srf_prettylinks-include]' id='srf_prettylinks-include-option-checked' value='true' />";   
    128112        $html .= '</div>';
    129113
    130         $out[] = $html;
    131       }
    132114
    133115      // Construct the form field
    134116      $form_fields['srf-include-srf_prettylinks'] = array(
    135         'label' => 'Make pretty link',
     117        'label' => __( 'Make pretty link', 'prettyfilelink' ),
    136118        'input' => 'html',
    137         'html'  => join("\n", $out),
    138       );
    139      
     119        'html' => $html
     120      );     
     121     
    140122      // Return all form fields
    141123      return $form_fields;
     
    149131      $use_pretty = get_post_meta($id, "srf_prettylinks-include", true); 
    150132
    151       if($use_pretty == 1){   
     133      if($use_pretty == "true"){   
    152134        //If we do, create our pretty shortcode 
    153135        $attachment = get_post($id); //fetch attachment by $id passed through 
     
    155137        $title_temp = $attachment->post_title; //Get the title
    156138           
    157         //check mime-type against our list of types we style links for
    158         $type="";   
    159         switch ($mime_type) {
    160           case "application/pdf":
    161           case "application/x-pdf":
    162           case "application/acrobat":
    163           case "applications/vnd.pdf":
    164           case "text/pdf":
    165           case "text/x-pdf":
    166             $type = "pdf";
     139        //check mime-type against the list of types that links can be styled for
     140        $type="";   
     141        switch ($mime_type) {
     142            case "image/gif":
     143            case "image/png":
     144            case "image/jpeg":
     145                $type = "img";
     146            break;
     147                     
     148            case "application/pdf":
     149            case "application/x-pdf":
     150            case "application/acrobat":
     151            case "applications/vnd.pdf":
     152            case "text/pdf":
     153            case "text/x-pdf":
     154                $type = "pdf";
     155            break;
     156           
     157            case "application/vnd.ms-excel":
     158            case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":
     159            case "text/csv":
     160                $type = "xls"; 
     161            break;
     162           
     163            case "video/quicktime":
     164            case "video/mp4v-es":
     165            case "audio/mp4":
     166                $type = "video";
     167            break;
     168           
     169            case "audio/mpeg3":
     170            case    "audio/x-mpeg-3":
     171                $type = "mp3";
     172            break;
     173           
     174            case "application/doc":
     175            case "'application/vnd.msword":
     176            case "application/vnd.ms-word":
     177            case "application/winword":
     178            case "application/word":
     179            case "application/x-msw6":
     180            case "application/x-msword":
     181            case "application/msword":
     182            case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
     183                $type = "doc";
    167184            break;
    168           case "application/vnd.ms-excel":
    169           case "text/csv":
    170             $type = "xls"; 
    171             break;
    172           case "video/quicktime":
    173             $type = "video";
    174             break;
    175                   case "audio/mpeg3":
    176                   case  "audio/x-mpeg-3":
    177                         $type = "mp3";
    178                         break;
    179           case "application/doc":
    180           case "'application/vnd.msword":
    181           case "application/vnd.ms-word":
    182           case "application/winword":
    183           case "application/word":
    184           case "application/x-msw6":
    185           case "application/x-msword":
    186           case "application/msword":
    187             $type = "doc";
    188             break;
    189           case "application/mspowerpnt":
    190           case "application/vnd-mspowerpoint":
    191           case "application/powerpoint":
    192           case "application/x-powerpoint":
    193           case "application/vnd.ms-powerpoint":
    194           case "application/mspowerpoint":
    195           case "application/ms-powerpoint":
    196             $type = "ppt";
     185           
     186            case "application/mspowerpnt":
     187            case "application/vnd-mspowerpoint":
     188            case "application/powerpoint":
     189            case "application/x-powerpoint":
     190            case "application/vnd.ms-powerpoint":
     191            case "application/mspowerpoint":
     192            case "application/ms-powerpoint":
     193            case "application/vnd.openxmlformats-officedocument.presentationml.presentation":
     194                $type = "ppt";
    197195            break;     
    198           case "application/zip":
    199           case "application/x-zip":
    200           case "application/x-zip-compressed":
    201           case "application/x-compress":
    202           case "application/x-compressed":
    203           case "multipart/x-zip":
    204             $type = "zip";
    205             break;       
     196           
     197            case "application/zip":
     198            case "application/x-zip":
     199            case "application/x-zip-compressed":
     200            case "application/x-compress":
     201            case "application/x-compressed":
     202            case "multipart/x-zip":
     203            case "application/x-rar-compressed":
     204                $type = "zip";
     205            break; 
    206206        }
    207        
     207                   
     208       
    208209        //If we matched a type create our shortcode
    209210        if($type != "")
    210211        {
    211           $src = wp_get_attachment_url( $id );   
    212           $html = '[prettyfilelink src="'.$src.'" type="' . $type .'"]'. $title_temp . '[/prettyfilelink]';
     212            $sizeText = '';
     213            $getfilesize = get_option('pfl_showfilesize');
     214           
     215            //TODO:Get this from settings and then switch to ==
     216            if($getfilesize == "true"){
     217                $filesize = filesize(get_attached_file($attachment->ID));
     218                $sizeText = size_format($filesize);
     219            }
     220           
     221            $src = wp_get_attachment_url( $id );
     222            return '[prettyfilelink size="' . $sizeText . '" src="' . $src . '" type="' . $type . '"]' . $title_temp . '[/prettyfilelink]';
    213223        }   
    214       } 
    215         return $html; // return new $html
     224      }
     225     
     226      return $html; // return new $html
    216227    }
    217228   
     
    220231    public function srf_prettylinks_admin_menu()
    221232    { 
    222       //This is where we add our plugin to the admin menu 
    223       $page = add_options_page('Prettylinks', 'Pretty file links', 'manage_options', dirname(__FILE__), array($this,'srf_prettylinks_settings')); 
    224       //Add admin preview script only to our pages
    225       add_action( 'admin_print_styles-' . $page, array($this,'srf_prettylinks_admin_scripts'));
     233        //This is where we add our plugin to the admin menu 
     234        $page = add_options_page('Prettylinks', 'Pretty file links', 'manage_options', dirname(__FILE__), array($this,'srf_prettylinks_settings')); 
     235        //Add admin preview script only to our pages
     236        add_action( 'admin_print_styles-' . $page, array($this,'srf_prettylinks_admin_scripts'));       
    226237    }
    227238
     
    246257      $message = "";
    247258       
    248       //The @ suppresses an error if post[action] is not set
    249       if (@$_POST['action'] == 'update') 
    250       { 
    251         //Set the option to the form variable
    252         update_option('stylesheet_to_use', $_POST['stylesheet_name']); 
    253         //Send a message to the user to let them know it was updated
    254         $message = '<div id="message" class="updated fade"><p><strong>Options Saved</strong></p></div>'; 
     259        //The @ suppresses an error if post[action] is not set
     260        if (@$_POST['action'] == 'update') 
     261        { 
     262            if(@$_POST['stylesheet_name']){
     263                //Set the option to the form variable
     264                update_option('stylesheet_to_use', $_POST['stylesheet_name']);
     265            }
     266
     267            if(@$_POST['showfilesize']){
     268                //Set the option to the form variable
     269                update_option('pfl_showfilesize', $_POST['showfilesize']);
     270            }                       
     271           
     272            //Send a message to the user to let them know it was updated
     273            $message = '<div id="message" class="updated fade"><p><strong>' . __( 'Options Saved', 'prettyfilelink' ) . '</strong></p></div>'; 
    255274      }
    256275
     
    265284      //Get our options
    266285      $options['stylesheet_to_use'] = get_option('stylesheet_to_use');
    267 
    268       //Display options form
    269       echo '<div style="background-color:#eee;border:solid 1px #ccc;border-radius:3px;float:right;margin:20px;padding:10px;width:300px;">
    270             <div style="background-color:#fff;border:solid 1px #ccc;float:right;">
    271                 <img src="http://www.smartredfox.com/wp-content/uploads/2012/02/All_styles-150x150.png" style="margin:5px;" />
    272             </div>
    273             <h2>Want more styles?</h2>
    274             <p>Buy the Styles Pack (15 extra styles) for just $3.</p>
    275             <p><a class="button-secondary" href="http://www.smartredfox.com/pretty-file-links-wordpress-plugin/style-pack-for-pretty-file-links/">Buy the pack now</a></p>
    276             </div>
    277             <div class="wrap">'.$message.
    278         '<div id="icon-options-general" class="icon32"><br /></div> 
    279         <h2>Prettylinks Settings</h2> 
    280      
    281         <form method="post" action=""> 
    282         <input type="hidden" name="action" value="update" /> 
    283      
    284         <h3>Which stylesheet would you like to use</h3>     
    285         <style id="Previewer"></style>
    286         <p><select name="stylesheet_name" id="show_pages">';
    287        
    288       //print each available css file
    289       foreach($styles as $style)
    290       {
    291         echo '<option value="' . basename($style) .'"' . (basename($style) == $options['stylesheet_to_use'] ? 'selected="selected"' : '')  . '>' . basename($style) . '</option>';
    292       }
    293       foreach($altStyles as $style)
    294       {
    295         echo '<option value="' . basename($style) .'#"' . (basename($style) == $options['stylesheet_to_use'] ? 'selected="selected"' : '')  . '>' . basename($style) . ' (Custom)</option>';
    296       }
    297      
    298       echo '</select></p><p><input type="submit" class="button-primary" value="Save Changes" /></p>
    299         <h3 style="clear:both;width:100%;">Current style example:</h3>
    300         <a href="#" class="prettylink doc">A Word document example pretty file link</a>
    301         <a href="#" class="prettylink xls">An Excel spreadsheet example pretty file link</a>
    302                 <a href="#" class="prettylink mp3">An mp3 file example pretty file link</a>     
    303                 <a href="#" class="prettylink pdf">A pdf example pretty file link</a>
    304                 <a href="#" class="prettylink ppt">A PowerPoint example pretty file link</a>
    305         <a href="#" class="prettylink video">A video file example pretty file link</a>
    306         <a href="#" class="prettylink zip">A Zip file example pretty file link</a>
    307         </form>   
    308       </div>';
     286      $options['showfilesize'] = get_option('pfl_showfilesize');
     287
     288        //Display options form
     289        echo '<div style="background-color:#eee;border:solid 1px #ccc;border-radius:3px;float:right;margin:20px;padding:10px;width:300px;">';
     290            echo '<div style="background-color:#fff;border:solid 1px #ccc;float:right;">';
     291                echo '<img src="http://www.smartredfox.com/wp-content/uploads/2012/02/All_styles-150x150.png" style="margin:5px;" />';
     292            echo '</div>';
     293            echo '<h2>' . __('Want more styles?','prettyfilelink')  . '</h2>';
     294            //TODO:Add check here for style pack already installed
     295            echo '<p>' . __('Buy the Styles Pack (15 extra styles) for just $3.','prettyfilelink')  . '</p>';
     296            echo '<p>';
     297            echo '<a class="button-secondary" href="http://www.smartredfox.com/pretty-file-links-wordpress-plugin/style-pack-for-pretty-file-links/">' .  __('Buy the pack now','prettyfilelink') .'</a></p>';
     298        echo '</div>';
     299       
     300        echo '<div class="wrap">' . $message;
     301            echo '<div id="icon-options-general" class="icon32"><br /></div>';
     302            echo '<h2>' . __( 'Prettylinks Settings', 'prettyfilelink' ) . '</h2>';
     303            echo '<form method="post" action="">';
     304                echo '<input type="hidden" name="action" value="update" />';   
     305                echo '<h3>' . __( 'Which stylesheet would you like to use', 'prettyfilelink' ) . '</h3>';
     306                echo '<style id="Previewer"></style>';
     307                echo '<p>';
     308                    echo '<select name="stylesheet_name" id="show_pages">';               
     309                      //print each available css file
     310                      foreach($styles as $style)
     311                      {
     312                        echo '<option value="' . basename($style) .'"' . (basename($style) == $options['stylesheet_to_use'] ? 'selected="selected"' : '')  . '>' . basename($style) . '</option>';
     313                      }
     314                      foreach($altStyles as $style)
     315                      {
     316                        echo '<option value="' . basename($style) .'#"' . (basename($style) == $options['stylesheet_to_use'] ? 'selected="selected"' : '')  . '>' . basename($style) . ' (Custom)</option>';
     317                      }   
     318                    echo '</select>';
     319                echo'</p>';
     320               
     321                echo '<h3>' . __( 'Other options', 'prettyfilelink' ) . '</h3>';     
     322                echo '<p><label><input type="checkbox" ' . ($options['showfilesize'] == "true" ? 'checked="checked"' : '') . ' name="showfilesize" value="true" id="showfilesize"> Open links in a new window</label></p>';
     323               
     324                echo '<p><input type="submit" class="button-primary" value="Save Changes" /></p>';
     325                echo '<h3 style="clear:both;width:100%;">' . __( 'Current style example', 'prettyfilelink' ) . '</h3>';
     326                echo '<a href="#" class="prettylink doc">' . __( 'A Word document example pretty file link', 'prettyfilelink' ) . '</a>';
     327                echo '<a href="#" class="prettylink xls">' . __( 'An Excel spreadsheet example pretty file link', 'prettyfilelink' ) . '</a>';
     328                echo '<a href="#" class="prettylink mp3">' . __( 'An mp3 file example pretty file link', 'prettyfilelink' ) . '</a>';
     329                echo '<a href="#" class="prettylink pdf">' . __( 'A pdf example pretty file link', 'prettyfilelink' ) . '</a>';
     330                echo '<a href="#" class="prettylink ppt">' . __( 'A PowerPoint example pretty file link', 'prettyfilelink' ) . '</a>';
     331                echo '<a href="#" class="prettylink video">' . __( 'A video file example pretty file link', 'prettyfilelink' ) . '</a>';
     332                echo '<a href="#" class="prettylink zip">' . __( 'A Zip file example pretty file link', 'prettyfilelink' ) . '</a>';
     333            echo '</form>';
     334        echo '</div>';
    309335    }
    310336     
  • pretty-file-links/trunk/readme.txt

    r548697 r732164  
    5757* Added option to make links open in new window.
    5858* Added two new file types - mp3 and video.
     59= 0.8 =
     60* Added file size to listed items - with option to turn off in settings.
     61* Changed to single text box for new media uploader.
     62* Added xslx, pptx, doc, and rar support.
    5963
    6064== Upgrade Notice ==
Note: See TracChangeset for help on using the changeset viewer.