Plugin Directory

Changeset 1242285


Ignore:
Timestamp:
09/10/2015 10:03:42 AM (11 years ago)
Author:
ckanitz
Message:

Changelog

=======

0.6.0

Added a live-search.
Added lazy load depending on the viewport.
Added a preview button within the sidebar.
Implemented client-caching to prevent long loads and/or timeouts.
Rewrote part of the JS-Core for a better workflow.
Changed template behaviour.
Fixed a bug where our upload-spinner appeared in new opened media-frames sometimes.

Location:
free-imagescc-importer/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • free-imagescc-importer/trunk/css/admin.css

    r1229112 r1242285  
    1 .progress-container{position:absolute;width:100%;height:100%;background:rgba(255,255,255,0.8);top:0;left:0;z-index:90000000000}@-webkit-keyframes load{0%{stroke-dashoffset:0}50%{stroke-dashoffset:630}100%{stroke-dashoffset:0}}@keyframes load{0%{stroke-dashoffset:0}50%{stroke-dashoffset:630}100%{stroke-dashoffset:0}}.progress-container .progress{position:relative;display:inline-block;padding:0;text-align:center;display:block;margin-top:15%}.progress-container .progress .dashicons.dashicons-yes{font-size:170px;position:relative;right:174px;font-weight:200;visibility:hidden}.progress-container .progress>li{display:inline-block;position:relative;text-align:center;color:#93A2AC;font-family:Lato;font-weight:100;margin:2rem}.progress-container .progress svg{width:10rem;height:10rem}.progress-container .progress svg:nth-child(2){position:absolute;left:0;top:0;transform:rotate(-90deg);-webkit-transform:rotate(-90deg);-moz-transform:rotate(-90deg);-ms-transform:rotate(-90deg)}.progress-container .progress svg:nth-child(2) path{fill:none;stroke-width:7;stroke-dasharray:629;stroke:rgba(255,255,255,0.9);-webkit-animation:load 5s;animation:load 5s;-webkit-animation-iteration-count:infinite;animation-iteration-count:infinite}.progress-container.success .progress .dashicons.dashicons-yes{visibility:visible}.progress-container.success .progress svg:nth-child(2) path{stroke:rgba(255,255,255,0)}.attachment-browser.fap-media ul{padding:8px;display:block;position:absolute;top:0px;left:0;right:300px;bottom:0;overflow:auto;outline:0}.attachment-browser.fap-media ul li .attachment-preview{box-shadow:inset 0 0 15px rgba(0,0,0,0.1),inset 0 0 0 1px rgba(0,0,0,0.05)}.attachment-browser.fap-media ul li .attachment-preview .check{display:none;background-color:#1e8cbe;top:-8px;right:-8px;box-shadow:0 0 0 1px #fff,0 0 0 2px #1e8cbe}.attachment-browser.fap-media ul li .attachment-preview .check .media-modal-icon{background-position:-21px 0}.attachment-browser.fap-media ul li .attachment-preview .check .media-modal-icon:hover{background-position:-63px 0}.attachment-browser.fap-media ul li .attachment-preview.selected{box-shadow:0 0 0 1px #fff, 0 0 0 5px #1e8cbe}.attachment-browser.fap-media ul li .attachment-preview.selected .check{display:block}.attachment-browser.fap-media .media-sidebar *{visibility:hidden}.attachment-browser.fap-media .media-sidebar.visible *{visibility:visible}
     1.progress-container{position:absolute;width:100%;height:100%;background:rgba(255,255,255,0.8);top:0;left:0;z-index:90000000000}@-webkit-keyframes load{0%{stroke-dashoffset:0}50%{stroke-dashoffset:630}100%{stroke-dashoffset:0}}@keyframes load{0%{stroke-dashoffset:0}50%{stroke-dashoffset:630}100%{stroke-dashoffset:0}}.progress-container .progress{position:relative;display:inline-block;padding:0;text-align:center;display:block;margin-top:15%}.progress-container .progress .dashicons.dashicons-yes{font-size:170px;position:relative;right:174px;font-weight:200;visibility:hidden}.progress-container .progress>li{display:inline-block;position:relative;text-align:center;color:#93A2AC;font-family:Lato;font-weight:100;margin:2rem}.progress-container .progress svg{width:10rem;height:10rem}.progress-container .progress svg:nth-child(2){position:absolute;left:0;top:0;transform:rotate(-90deg);-webkit-transform:rotate(-90deg);-moz-transform:rotate(-90deg);-ms-transform:rotate(-90deg)}.progress-container .progress svg:nth-child(2) path{fill:none;stroke-width:7;stroke-dasharray:629;stroke:rgba(255,255,255,0.9);-webkit-animation:load 5s;animation:load 5s;-webkit-animation-iteration-count:infinite;animation-iteration-count:infinite}.progress-container.success .progress .dashicons.dashicons-yes{visibility:visible}.progress-container.success .progress svg:nth-child(2) path{stroke:rgba(255,255,255,0)}.attachments-browser.fap-media .media-sidebar .lh-logo{visibility:visible !important;position:absolute;width:267px;bottom:25px}.attachments-browser.fap-media .media-sidebar .lh-logo img{max-width:215px;display:block;margin:auto}.attachments-browser.fap-media .media-sidebar .lh-logo:before{content:"powered by";display:block;text-align:center;font-size:10px}
  • free-imagescc-importer/trunk/fap_client.php

    r1229175 r1242285  
    99Author: Luehrsen // Heinrich
    1010Author URI: http://www.luehrsen-heinrich.de
    11 Version: 0.5.1
     11Version: 0.6.0
    1212License: GNU General Public License v2 or later
    1313License URI: http://www.gnu.org/licenses/gpl-2.0.html
  • free-imagescc-importer/trunk/inc/lhfap.admin.php

    r1229112 r1242285  
    5151        $strings['menuTitle'] = __('Free Images', 'fap');
    5252        $strings['addToLibrary'] = __('Insert into Library', 'fap');
    53         //$strings['addToPost'] = __('Insert into Post', 'fap');
     53        $strings['pluginUrl'] = LHFAP__PLUGIN_URL;
    5454        return $strings;
    55     }
    56 
    57     public function custom_media_tab($tabs) {
    58         $newtab = array( 'tab_slug' => 'FAP Media' );
    59         return array_merge( $tabs, $newtab );
    60     }
    61 
    62     public function custom_media_tab_content() {
    63         echo media_upload_header();
    64         var_dump(media_upload_header());
    65 
    66         $url = "https://unsplash.com/rss";
    67         $rss = fetch_feed( $url );
    68 
    69         $maxitems = 0;
    70 
    71         if ( ! is_wp_error( $rss ) ) : // Checks that the object is created correctly
    72 
    73             // Figure out how many total items there are, but limit it to 5.
    74             $maxitems = $rss->get_item_quantity( 10 );
    75 
    76             // Build an array of all the items, starting with element 0 (first element).
    77             $rss_items = $rss->get_items( 0, $maxitems );
    78 
    79         endif;
    80 
    81         foreach($rss_items as $item) {
    82             $doc = new DOMDocument();
    83             $doc->loadHTML($item->get_content());
    84             $images = $doc->getElementsByTagName('img');
    85 
    86             foreach($images as $img) {
    87                 echo $img->getAttribute("src") . "<br>";
    88             }
    89         }
    9055    }
    9156
  • free-imagescc-importer/trunk/inc/lhfap.import.php

    r1229112 r1242285  
    33 * @package lh_fap
    44 */
    5 
    6 
    75/**
    86 * The importer class that handles the sideloading of the images from the api endpoint.
    97 */
    108class LH_Fap_Import {
    11 
    129    private $_apiUrl = "http://www.free-images.cc/wp-json";
    13 
    1410    /**
    1511     * The constructor of this class.
     
    2218        $this->filter_dispatcher();
    2319    }
    24 
    2520    /**
    2621     * The function that dispatches all used actions by this class.
     
    3126    private function action_dispatcher(){
    3227        add_action('wp_ajax_import_image',      array( $this, 'import_image' ) );
    33 
    34     }
    35 
     28        add_action('wp_ajax_list_images',       array( $this, 'list_images' ) );
     29    }
    3630    /**
    3731     * The function that dispatches all used filters by this class.
     
    4135     */
    4236    private function filter_dispatcher(){
    43 
    44     }
    45 
     37    }
    4638    /**
    4739     * The ajax call, that actually imports the image.
     
    5143     */
    5244    public function import_image(){
    53         $image_id = intval($_GET['image_id']);
     45        $image_id = isset($_GET['image_id']) ? intval($_REQUEST['image_id']) : null;
    5446        $post_id = isset($_GET['post_id']) ? intval($_REQUEST['post_id']) : null;
    55 
    5647        $response = array(
    5748            "error" => true,
    5849            "msg"   => __("An unknown error occured!", "lhf"),
    5950        );
    60 
    6151        // If the current user cannot upload files, die with an error message
    6252        if(!current_user_can("upload_files")){
     
    6656            die();
    6757        }
    68 
     58        if(!$image_id){
     59            http_response_code(401);
     60            $this->json_response($response);
     61            die();
     62        }
    6963        if($image_id){
    7064            // Check if we already have an image with that FAP ID in the database
     
    7973                ),
    8074            ));
    81 
    8275            // If that query returns any results, die with the error message, including
    8376            if($qry->have_posts()){
     
    8881                die();
    8982            }
    90 
    91 
    9283            // Download the data from the api
    9384            $json_data = $this->curl_download($this->_apiUrl . "/image/" . $image_id . "/");
    94 
    9585            if($json_data['header']['http_code'] !== 200){
    9686                http_response_code($json_data['header']['http_code']);
     
    9989                die();
    10090            }
    101 
    10291            // At this point we should have working data from our API
    10392            $body = json_decode($json_data['body']);
    10493            $id = $this->add_to_library($body->data[0], $post_id);
    105 
    10694            if($id){
    10795                $response = array(
     
    112100            }
    113101        }
    114 
    115102        $this->json_response($response);
    116103        die();
    117104    }
    118 
     105    public function list_images(){
     106        $response = array(
     107            "success"   => false,
     108        );
     109        $search_term = isset($_GET['s']) ? ($_REQUEST['s']) : null;
     110        $paged = isset($_GET['paged']) ? intval($_REQUEST['paged']) : null;
     111        $api_url = $this->_apiUrl . "/image/";
     112        $api_url = add_query_arg(array(
     113            "paged"     => $paged,
     114            "s"         => $search_term,
     115        ), $api_url);
     116        $json_data = $this->curl_download($api_url);
     117        if($json_data){
     118            $response = json_decode($json_data['body']);
     119        }
     120        $this->json_response($response);
     121        die();
     122    }
    119123    /**
    120124     * add_to_library function.
     
    125129     */
    126130    private function add_to_library($data, $post_id){
    127 
    128131        if(isset($data->url) && !filter_var($data->url, FILTER_VALIDATE_URL) === false){
    129132            // The download URL is legal
     
    132135                // download failed, handle error
    133136            }
    134 
    135137            $desc = $data->title;
    136138            $file_array = array();
    137 
    138139            // Set variables for storage
    139140            // fix file filename for query strings
     
    141142            $file_array['name'] = basename($matches[0]);
    142143            $file_array['tmp_name'] = $tmp;
    143 
    144144            // If error storing temporarily, unlink
    145145            if ( is_wp_error( $tmp ) ) {
     
    147147                $file_array['tmp_name'] = '';
    148148            }
    149 
    150149            $post_data = array(
    151150                'post_content'  => sprintf(__("by %s via free-images.cc", "lhf"), $data->author),
    152151            );
    153 
    154152            // do the validation and storage stuff
    155153            $id = media_handle_sideload( $file_array, $post_id, $desc, $post_data );
    156 
    157154            // If error storing permanently, unlink
    158155            if ( is_wp_error($id) ) {
     
    162159                $res = update_post_meta($id, '_fap_id', $data->id);
    163160            }
    164 
    165161            return $id;
    166162        }
    167 
    168163        return false;
    169164    }
    170 
    171165    /**
    172166     * Make sure we have a legal json response.
     
    180174        echo json_encode($response);
    181175    }
    182 
    183176    /**
    184177     * Handle the downloading of the url.
     
    189182     */
    190183    private function curl_download($url){
    191 
    192184        // is cURL installed yet?
    193185        if (!function_exists('curl_init')){
    194186            die('Sorry cURL is not installed!');
    195187        }
    196 
    197188        // OK cool - then let's create a new cURL resource handle
    198189        $ch = curl_init();
    199 
    200190        // Now set some options (most are optional)
    201 
    202191        // Set URL to download
    203192        curl_setopt($ch, CURLOPT_URL, $url);
    204 
    205193        // Set a referer
    206194        curl_setopt($ch, CURLOPT_REFERER, get_bloginfo("url"));
    207 
    208195        // User agent
    209196        curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
    210 
    211197        // Include header in result? (0 = yes, 1 = no)
    212198        curl_setopt($ch, CURLOPT_HEADER, 0);
    213 
    214199        // Should cURL return or print out the data? (true = return, false = print)
    215200        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    216 
    217201        // Timeout in seconds
    218202        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    219 
    220 
    221203        // Download the given URL, and return output
    222204        $output = curl_exec($ch);
    223205        // Get the connection info
    224206        $info = curl_getinfo($ch);
    225 
    226207        // Close the cURL resource, and free system resources
    227208        curl_close($ch);
    228 
    229209        return array(
    230210            "body"      => $output,
  • free-imagescc-importer/trunk/inc/lhfap.templates.php

    r1229175 r1242285  
    22    function fap_mediaview_templates() {
    33        ?>
    4 
    5         <script type="text/html" id="tmpl-fap-image">
    6             <div class="media-sidebar"></div>
    7 
    8             <ul class="attachments ui-sortable ui-sortable-disabled">
    9             <# _.each(images[0].data, function(fap, i){ #>
    10                 <li tabindex="0" role="checkbox" aria-label="{{ fap.title }}" aria-checked="false" data-id="{{ fap.id  }}" class="attachment save-ready">
    11                     <div class="attachment-preview js--select-attachment type-image subtype-jpeg landscape" fap-id="{{ fap.id }}" index="{{ i }}">
    12                         <div class="thumbnail">
    13                             <div class="centered">
    14                                 <img src="{{ fap.sizes.medium.url }}" draggable="false" alt="">
    15                             </div>
    16                         </div>
    17                         <a class="check" href="#" title="<?php esc_attr_e('Remove'); ?>">
    18                             <div class="media-modal-icon"></div>
    19                         </a>
    20                     </div>
    21                 </li>
    22             <# }); #>
    23             </ul>
    24         </script>
    254
    265        <script type="text/html" id="tmpl-fap-image-upload">
     
    7857
    7958        <script type="text/html" id="tmpl-fap-image-details">
    80             <# var index = jQuery('.selected').attr('index'); #>
    81             <# var image = images[0].data[index]; #>
    8259            <h3>
    8360                <?php _e('Attachment Details'); ?>
    8461            </h3>
    85                
     62
    8663            <div class="attachment-info">
    87                 <div class="thumbnail thumbnail-image">
    88                     <img src="{{ image.sizes.medium.url  }}" draggable="false">
     64                <div class="thumbnail thumbnail-{{ data.type }}">
     65                    <# if ( 'image' === data.type && data.sizes ) { #>
     66                        <img src="{{ data.size.url }}" draggable="false" />
     67                    <# } else { #>
     68                        <img src="{{ data.icon }}" class="icon" draggable="false" />
     69                    <# } #>
    8970                </div>
    9071                <div class="details">
    91                     <div class="filename">{{ image.title }}</div>
    92                     <div class="uploaded">{{ image.dateFormatted }}</div>
    93                     <div class="file-size">{{ image.filesizeHumanReadable }}</div>
    94                     <div class="dimensions">{{ image.width }} &times; {{ image.height }}</div>
    95                        
    96                     <a class="edit-attachment" href="" target="_blank"></a>
    97                     <a class="refresh-attachment" href="#"></a>
    98                        
    99                     <a class="delete-attachment" href="#"></a>
    100                                        
     72                    <div class="filename">{{ data.filename }}</div>
     73                    <div class="uploaded">{{ data.dateFormatted }}</div>
    10174
    102                     <div class="compat-meta"></div>
     75                    <div class="file-size">{{ data.filesizeHumanReadable }}</div>
     76                    <# if ( 'image' === data.type && ! data.uploading ) { #>
     77                        <# if ( data.width && data.height ) { #>
     78                            <div class="dimensions">{{ data.width }} &times; {{ data.height }}</div>
     79                            <a href="{{ data.link }}?utm_source=fap-plugin&utm_medium=preview&utm_campaign=media-preview&utm_term=preview" target="_blank">Preview</a>
     80                        <# } #>
     81                    <# } #>
     82
     83                    <# if ( data.fileLength ) { #>
     84                        <div class="file-length"><?php _e( 'Length:' ); ?> {{ data.fileLength }}</div>
     85                    <# } #>
     86
     87                    <div class="compat-meta">
     88                        <# if ( data.compat && data.compat.meta ) { #>
     89                            {{{ data.compat.meta }}}
     90                        <# } #>
     91                    </div>
    10392                </div>
    10493            </div>
     
    10695            <label class="setting" data-setting="url">
    10796                <span class="name"><?php _e('URL'); ?></span>
    108                 <input type="text" value="{{ image.link }}" readonly />
     97                <input type="text" value="{{ data.size.url }}" readonly />
    10998            </label>
     99            <# var maybeReadOnly = data.can.save || data.allowLocalEdits ? '' : 'readonly'; #>
    110100
    111101            <label class="setting" data-setting="title">
    112102                <span class="name"><?php _e('Title'); ?></span>
    113                 <input type="text" value="{{ image.title  }}" readonly />
     103
     104                <input type="text" value="{{ data.title }}" {{ maybeReadOnly }} />
     105
    114106            </label>
     107        </script>
     108
     109        <script type="text/html" id="tmpl-lh-logo">
     110            <div class="lh-logo">
     111                <a href="http://www.luehrsen-heinrich.de/?utm_source=fap-plugin&utm_medium=banner&utm_campaign=media-banner&utm_term=banner" target="_blank">
     112                    <img src="<?=LHFAP__PLUGIN_URL?>img/lh_logo_head.svg" alt="Luehrsen // Heinrich GmbH" title="Luehrsen // Heinrich GmbH">
     113                </a>
     114            </div>
    115115        </script>
    116116        <?php
  • free-imagescc-importer/trunk/js/fap.min.js

    r1229175 r1242285  
    1 var Images=Backbone.Collection.extend({url:"http://www.free-images.cc/wp-json/image"}),imagedata=null,oldMediaFrame=wp.media.view.MediaFrame.Post,l10n=wp.media.view.l10n;wp.media.view.MediaFrame.Post=oldMediaFrame.extend({initialize:function(){oldMediaFrame.prototype.initialize.apply(this,arguments),this.states.add([new wp.media.controller.FAPController({id:"fap-action",menu:"default",content:"custom",title:wp.media.view.l10n.menuTitle,priority:60,toolbar:"fap-media-frame-toolbar",type:"link"})]),this.on("toolbar:create:fap-media-frame-toolbar",this.createCustomFrameToolbar,this),this.on("content:render:custom",this.FAPContent,this)},createCustomFrameToolbar:function(a){a.view=new wp.media.view.Toolbar.FAPToolbar({controller:this})},FAPContent:function(){this.$el.addClass("hide-router");var a=new wp.media.view.FAPCustomView({controller:this,model:this.state().props});this.content.set(a)}});var custom_data=!1;wp.media.view.Toolbar.FAPToolbar=wp.media.view.Toolbar.extend({initialize:function(){_.defaults(this.options,{event:"custom_event",close:!1,items:{custom_event:{text:wp.media.view.l10n.addToLibrary,style:"primary",priority:80,requires:!1,click:this.customAction}}}),wp.media.view.Toolbar.prototype.initialize.apply(this,arguments)},refresh:function(){this.get("custom_event").model.set("disabled",!custom_data),wp.media.view.Toolbar.prototype.refresh.apply(this,arguments)},customAction:function(){custom_data=!1,this.controller.toolbar.get().refresh();var a=document.getElementsByClassName("js--select-attachment selected")[0].getAttribute("fap-id"),b=ajaxurl+"?action=import_image&image_id="+a+"&post_id=0",c=this;_.templateSettings={evaluate:/<#([\s\S]+?)#>/g,interpolate:/\{\{\{([\s\S]+?)\}\}\}/g,escape:/\{\{([^\}]+?)\}\}(?!\})/g};var d=_.template(jQuery("#tmpl-fap-image-upload").html());jQuery(".media-frame-content").append(d),jQuery.get(b,function(a){jQuery(".progress-container").addClass("success"),setTimeout(function(){c.controller.states.get("insert").get("library").props.trigger("change",!0),c.controller.setState("insert")},1e3)}).fail(function(a,b,c){jQuery(".js--select-attachment").each(function(a){jQuery(this).hasClass("selected")&&jQuery(this).removeClass("selected")}),jQuery(".progress-container").remove(),alert(jQuery.parseJSON(a.responseText).msg)})},deactivateButton:function(){}}),wp.media.controller.FAPController=wp.media.controller.State.extend({initialize:function(){this.props=new Backbone.Model({custom_data:""}),this.props.on("change:custom_data",this.refresh,this)},refresh:function(){this.frame.toolbar.get().refresh()},customAction:function(){this.frame.content.mode("browse")}}),wp.media.view.FAPCustomView=wp.media.View.extend({tagName:"div",className:"attachment-browser fap-media",events:{"click .js--select-attachment":"toggleSelectionHandler"},initialize:function(){this.model.on("change:custom_data",this.render,this)},render:function(){var a=this,b=new Images;b.fetch({error:function(b,c,d){alert(jQuery.parseJSON(c.responseText)[0].message),a.controller.states.get("insert").get("library").props.trigger("change",!0),a.controller.setState("insert")},success:function(b){var c=b.toJSON();_.templateSettings={evaluate:/<#([\s\S]+?)#>/g,interpolate:/\{\{\{([\s\S]+?)\}\}\}/g,escape:/\{\{([^\}]+?)\}\}(?!\})/g};var d=_.template(jQuery("#tmpl-fap-image").html(),{images:c});a.$el.append(d),imagedata={images:c}}})},custom_update:function(a){this.model.set("custom_data",a.target.value)},toggleSelectionHandler:function(a){var b=jQuery,c=b(a.currentTarget),d=b(".media-sidebar");return d.html(""),b(c).hasClass("selected")?(b(c).removeClass("selected"),custom_data=!1,void this.controller.toolbar.get().refresh()):(b(".js--select-attachment").each(function(a){b(this).hasClass("selected")&&b(this).removeClass("selected")}),d.addClass("visible"),b(a.currentTarget).addClass("selected").attr("aria-checked",!0),custom_data=!0,this.controller.toolbar.get().refresh(),void this.createSidebarInfo(c))},createSidebarInfo:function(a){_.templateSettings={evaluate:/<#([\s\S]+?)#>/g,interpolate:/\{\{\{([\s\S]+?)\}\}\}/g,escape:/\{\{([^\}]+?)\}\}(?!\})/g};var b=_.template(jQuery("#tmpl-fap-image-details").html(),imagedata);jQuery(".media-sidebar").append(b)}});
     1var FAPImage=Backbone.Model.extend({defaults:{buttons:{check:!0},can:{save:!1,remove:!1},id:null,title:"",link:"http://www.free-images.cc",date:null,modified:null,mime:"image/jpeg",dateFormatted:null,height:null,width:null,orientation:null,filesizeInBytes:null,filesizeHumanReadable:null,size:{url:null},type:"image",icon:null,sizes:{thumbnail:{height:null,width:null,url:"http://www.free-images.cc",orientation:null},medium:{height:null,width:null,url:"http://www.free-images.cc",orientation:null},large:{height:null,width:null,url:"http://www.free-images.cc",orientation:null}}}}),FAPPage=1,subState,searchTerm,FAPSearchInterval,View=wp.media.View,mediaTrash=wp.media.view.settings.mediaTrash,l10n=wp.media.view.l10n,$=jQuery,FAPBrowser;FAPBrowser=View.extend({tagName:"div",className:"attachments-browser fap-media",initialize:function(){var a,b=this;_.defaults(this.options,{filters:!1,search:!1,date:!1,display:!1,sidebar:!0,toolbar:!0,AttachmentView:wp.media.view.Attachment.Library}),this.options.toolbar&&this.createToolbar(),this.toolbar.get("spinner").show(),this.options.sidebar&&(this.createSidebar(),this.createSidebarLogo()),this.options.sidebar&&"errors"!==this.options.sidebar||(this.$el.addClass("hide-sidebar"),"errors"===this.options.sidebar&&this.$el.addClass("sidebar-for-errors")),a=new FapCollection({page:FAPPage}),a.fetch({success:function(a){subState="fap";var c=new ImagesView({controller:b.controller,collection:a});b.views.add(c),b.toolbar.get("spinner").hide()}})},createSidebar:function(){var a=(this.options,this.sidebar=new wp.media.view.Sidebar({controller:this.controller}));this.views.add(a)},createSidebarLogo:function(){var a=new LHLogo;a.createLogo(),this.sidebar.views.add(a)},createToolbar:function(){var a;a={controller:this.controller},this.toolbar=new wp.media.view.Toolbar(a),this.views.add(this.toolbar),this.toolbar.set("spinner",new wp.media.view.Spinner({priority:-60})),this.toolbar.set("search",new FAPSearch({controller:this.controller,fapView:this.views}))},createUpload:function(){var a;a=new FAPUpload({controller:this.controller}),this.views.add(a)}});var View=wp.media.View,$=jQuery,ImagesView;ImagesView=View.extend({tagName:"ul",className:"attachments fap-images",attributes:{tabIndex:0},initialize:function(){this.el.id=_.uniqueId("__attachments-view-");var a=this;_.defaults(this.options,{refreshSensitivity:wp.media.isTouchDevice?300:200,refreshThreshold:3,AttachmentView:wp.media.view.Attachment,sortable:!1,resize:!0,idealColumnWidth:$(window).width()<640?135:150}),this._viewsByCid={},this.$window=$(window),this.scroll=_.chain(this.scroll).bind(this).throttle(this.options.refreshSensitivity).value(),this.options.scrollElement=this.options.scrollElement||this.el,$(this.options.scrollElement).on("scroll",this.scroll),this.collection.each(function(b){var c=new ImageView({controller:a.controller,model:b});a.views.add(c)})},ready:function(){this.scroll()},scroll:function(){var a,b=this.options.scrollElement,c=b.scrollTop;b===document&&(b=document.body,c=$(document).scrollTop()),a=this.views.parent.toolbar,b.scrollHeight-(c+b.clientHeight)<b.clientHeight/3&&(FAPPage+=1,this.loadMorePictures(FAPPage))},loadMorePictures:function(a){var b,c=this;"fap"==subState?b=new FapCollection({page:a}):"search"==subState&&(b=new FapSearchCollection({searchTerm:searchTerm,page:a})),b.fetch({success:function(a){a.length<=0||a.each(function(a){var b=new ImageView({controller:c.controller,model:a});c.views.add(b)})}})}});var View=wp.media.View,$=jQuery,ImagesView;ImageView=View.extend({tagName:"li",className:"attachment fap-image",template:wp.template("attachment"),controller:this.controller,events:{"click .js--select-attachment":"toggleSelectionHandler","click .check":"toggleSelectionHandler",keydown:"toggleSelectionHandler"},attributes:function(){return{tabIndex:0,role:"checkbox","aria-label":this.model.get("title"),"aria-checked":!1,"data-id":this.model.get("id")}},buttons:{},initialize:function(){this.render()},render:function(){var a,b=this.model.get("size");b.url=this.model.get("sizes").thumbnail.url,this.model.set("size",b),this.model.set({icon:this.model.get("sizes").thumbnail.url}),a=_.defaults(this.model.toJSON(),{orientation:"landscape",uploading:!1,type:"",subtype:"",icon:"",filename:"",caption:"",title:"",dateFormatted:"",width:"",height:"",compat:!1,alt:"",description:""},this.options),this.$el.html(this.template(a))},toggleSelectionHandler:function(a){var b,c,d;return b=this.views.parent.views.parent.sidebar,c=this.$el,custom_data=!0,this.controller.toolbar.get().refresh(),jQuery(".attachment-details").remove(),c.hasClass("selected")?(c.removeClass("selected").removeClass("details"),custom_data=!1,void this.controller.toolbar.get().refresh()):(jQuery(".fap-image").each(function(a){jQuery(this).hasClass("selected")&&jQuery(this).removeClass("selected").removeClass("details")}),c.addClass("selected").addClass("details"),custom_data=!0,this.controller.toolbar.get().refresh(),d=new FAPDetails({controller:this.controller,model:this.model}),void b.views.add(d))}});var l10n=wp.media.view.l10n,FAPSearch;toolbar,FAPSearch=wp.media.View.extend({tagName:"input",className:"search",id:"media-search-input fap-search",attributes:{type:"search",placeholder:l10n.search},events:{input:"search",keyup:"search",change:"search",search:"search"},render:function(){return this},search:function(a){var b,c=this;b=c.views.parent.views.parent.get("spinner"),clearTimeout(FAPSearchInterval),FAPSearchInterval=setTimeout(function(){var d,e;if(FAPPage=1,searchTerm=a.target.value,d=c.options.fapView,b.show(),searchTerm)e=new FapSearchCollection({searchTerm:searchTerm,page:FAPPage}),e.fetch({success:function(a){if(jQuery(".attachments.fap-images").remove(),subState="search",a.length>0){jQuery(".no-fap").remove();var e=new ImagesView({controller:c.controller,collection:a});d.add(e)}else jQuery(".no-fap").remove(),jQuery(".attachments-browser").append('<div class="no-fap"><h2>Sorry, we couldn\'t find any images with the keyword "'+searchTerm+'"</h2></div>');b.hide()}});else{jQuery(".no-fap").remove();var f=new FapCollection({page:FAPPage});f.fetch({success:function(a){jQuery(".attachments.fap-images").remove(),subState="fap";var e=new ImagesView({controller:c.controller,collection:a});d.add(e),b.hide()}})}},500)}});var FAPDetails=ImageView.extend({tagName:"div",className:"attachment-details",template:wp.template("fap-image-details"),attributes:function(){return{tabIndex:0,"data-id":this.model.get("id")}},initialize:function(){var a;a=_.defaults(this.model.toJSON(),{orientation:"landscape",uploading:!1,type:"",subtype:"",icon:"",filename:"",caption:"",title:"",dateFormatted:"",width:"",height:"",compat:!1,alt:"",description:""},this.options),jQuery(".attachment-details").remove(),this.$el.html(this.template(a))}}),LHLogo=Backbone.View.extend({logoTemplate:wp.template("lh-logo"),createLogo:function(){this.$el.html(this.logoTemplate())}}),FAPUpload=wp.media.View.extend({template:wp.template("fap-image-upload"),initialize:function(){this.$el.html(this.template(""))}}),FapCollection=Backbone.Collection.extend({model:FAPImage,initialize:function(a){this.url=ajaxurl+"?action=list_images&paged="+a.page},parse:function(a){return a.data}}),FapSearchCollection=Backbone.Collection.extend({model:FAPImage,initialize:function(a){this.url=ajaxurl+"?action=list_images&s="+a.searchTerm+"&paged="+a.page},parse:function(a){return a.data}}),oldMediaFrame=wp.media.view.MediaFrame.Post,l10n=wp.media.view.l10n;wp.media.view.MediaFrame.Post=oldMediaFrame.extend({initialize:function(){oldMediaFrame.prototype.initialize.apply(this,arguments),this.states.add([new wp.media.controller.FAPController({id:"fap-action",menu:"default",content:"custom",title:wp.media.view.l10n.menuTitle,priority:60,toolbar:"fap-media-frame-toolbar",type:"link"})]),this.on("toolbar:create:fap-media-frame-toolbar",this.createCustomFrameToolbar,this),this.on("content:render:custom",this.FAPContent,this)},createCustomFrameToolbar:function(a){a.view=new wp.media.view.Toolbar.FAPToolbar({controller:this})},FAPContent:function(){this.$el.addClass("hide-router");var a=new FAPBrowser({controller:this});this.content.set(a)}});var custom_data=!1;wp.media.view.Toolbar.FAPToolbar=wp.media.view.Toolbar.extend({initialize:function(){_.defaults(this.options,{event:"custom_event",close:!1,items:{custom_event:{text:wp.media.view.l10n.addToLibrary,style:"primary",priority:80,requires:!1,click:this.customAction}}}),wp.media.view.Toolbar.prototype.initialize.apply(this,arguments)},refresh:function(){this.get("custom_event").model.set("disabled",!custom_data),wp.media.view.Toolbar.prototype.refresh.apply(this,arguments)},customAction:function(){custom_data=!1,this.controller.toolbar.get().refresh();var a=document.getElementsByClassName("attachment-details")[0].getAttribute("data-id"),b=ajaxurl+"?action=import_image&image_id="+a+"&post_id=0",c=this,d=new FAPUpload({controller:this.controller});this.controller.content.get("view").views.add(d),jQuery.get(b,function(a){jQuery(".progress-container").addClass("success"),setTimeout(function(){oldMediaFrame.prototype.open(),c.controller.states.get("insert").get("library").props.trigger("change",!0),c.controller.setState("insert")},1e3)}).fail(function(a,b,c){jQuery(".js--select-attachment").each(function(a){jQuery(this).hasClass("selected")&&jQuery(this).removeClass("selected")}),jQuery(".progress-container").remove(),alert(jQuery.parseJSON(a.responseText).msg)})},deactivateButton:function(){}}),wp.media.controller.FAPController=wp.media.controller.State.extend({initialize:function(){this.props=new Backbone.Model({custom_data:""}),this.props.on("change:custom_data",this.refresh,this)},refresh:function(){this.frame.toolbar.get().refresh()},customAction:function(){this.frame.content.mode("browse")}});
  • free-imagescc-importer/trunk/readme.txt

    r1229175 r1242285  
    55Requires at least: 4.0
    66Tested up to: 4.3
    7 Stable tag: 0.5.1
     7Stable tag: 0.6.0
    88License: GNU General Public License v2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3939Because they are released under the [CC0 Public Domain license](https://creativecommons.org/publicdomain/zero/1.0/). The photographer made them free to use for everyone around the world.
    4040
     41=======
     42
    4143= Are there any restrictions on the usage? =
    4244
     
    4547We just kindly ask you not to use these images for pornographic, criminal, defamatory or degrading purposes.
    4648
     49
    4750== Screenshots ==
    4851
     
    5053
    5154== Changelog ==
     55=======
     56= 0.6.0 =
     57Added a live-search.
     58Added lazy load depending on the viewport.
     59Added a preview button within the sidebar.
     60Implemented client-caching to prevent long loads and/or timeouts.
     61Rewrote part of the JS-Core for a better workflow.
     62Changed template behaviour.
     63Fixed a bug where our upload-spinner appeared in new opened media-frames sometimes.
     64
     65= 0.5.2 =
     66Frame reload fix to ensure a reload of the local media collection.
     67Small template changes.
    5268
    5369= 0.5.1 =
Note: See TracChangeset for help on using the changeset viewer.