Plugin Directory

Changeset 779794


Ignore:
Timestamp:
09/29/2013 08:54:40 AM (13 years ago)
Author:
amtyera
Message:

Problem of recaching on every plugin update is resolved by creating outside folder.
Manual cache.

Location:
amtythumb
Files:
11 added
6 edited

Legend:

Unmodified
Added
Removed
  • amtythumb/trunk/amtyThumb.php

    r777391 r779794  
    66
    77Author: Amit Gupta
    8 Version: 3.2.0
     8Version: 4.0.0
    99Author URI: http://article-stack.com/
    1010*/
  • amtythumb/trunk/amtyThumbAdminFunction.php

    r776329 r779794  
    99    echo '</div>';
    1010    echo '<div style="float:left;width:50%;">';
    11     $dir = WP_PLUGIN_DIR . "/amtythumb/cache";
    12     $url =  WP_PLUGIN_URL . "/amtythumb/cache";
     11    $dir = getAmtyThumbCachePath();
     12    $url =  getAmtyThumbCacheURL();
    1313    echo "<br />Image path on server : " . $dir;
    1414    echo "<br />Image url : " . $url;
     
    3636    }
    3737    //echo $img;
    38     $img_uri = WP_PLUGIN_DIR . "/amtythumb/testimage.jpg";
    39     $img_url = WP_PLUGIN_URL . "/amtythumb/testimage.jpg";
     38    $img_uri = getAmtyThumbPluginPath() . "testimage.jpg";
     39    $img_url = getAmtyThumbPluginURL() . "testimage.jpg";
    4040    //echo $img_uri;
    4141    $starttime = time();
  • amtythumb/trunk/amtyThumbAdminPg.php

    r776474 r779794  
    5454    <br />
    5555    <br />
    56     Total images cached : <?php echo amty_getImageCacheCount(); ?>
     56    Total images cached : <?php echo amty_getImageCacheCount(); ?> <br/>
     57    Total thumbnails in cache : <?php echo amty_getFilesInCacheFolder(); ?>
    5758    <p class="submit">
    5859    <input type="submit" name="Submit" value="submit" />
     
    6162</div>
    6263<hr />
     64
    6365<div>
    64 <strong>Test Image cache</strong>
     66<h1> Manual Caching </h1>
     67<form name="amtyThumb_form" method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>">
     68    <input type="hidden" name="manualcache" value="Y" />
     69    <p>
     70    Cache For :
     71    <select name="action">
     72        <option value="0">Single Post</option>
     73        <option value="1">All posts</option>       
     74    </select>
     75    Post ID (optional) :  <input type="text" name="post_id" />
     76    Width : <input type="text" name="width" />
     77    , height : <input type="text" name="height" />
     78    , Constrain :   <select name="constrain">
     79        <option value="0">0</option>
     80        <option value="1">1</option>       
     81    </select>
     82    , Zoom/Crop :   <select name="zc">
     83        <option value="0">Zoom</option>
     84        <option value="1">Crop</option>     
     85    </select>
     86    <input type="submit" name="Submit" value="submit" />
     87    </p>
     88    <?php
     89        if(isset($_POST['manualcache']) && $_POST['manualcache'] == 'Y') {
     90            if(isset($_POST['width']) && isset($_POST['height']) && isset($_POST['constrain']) && isset($_POST['zc'])) {
     91                if($_POST['action'] == '0') {
     92                    if(isset($_POST['post_id'])) {
     93                        amty_populateCacheManual($_POST['width'],$_POST['height'],$_POST['constrain'],$_POST['zc'],$_POST['post_id']);
     94                    }else{
     95                        echo "Please provide Post ID.";
     96                    }
     97                }else{
     98                    amty_populateCacheAllManual($_POST['width'],$_POST['height'],$_POST['constrain'],$_POST['zc']);
     99                }
     100            }else{
     101                echo "Please provide all required parameters.";
     102            }
     103        }
     104    ?>
     105</form>
     106</div>
     107<hr />
     108<div>
     109<h1>Test Image cache</h1>
    65110<form name="amtyThumbShow_form" method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>">
    66111    <input type="hidden" name="showthumb" value="Y" />
     
    77122<hr />
    78123<div>
    79 <strong>Test Plugin </strong>
    80 <br />
    81 <div style="float:left">
    82 <form name="amtyThumbTest_form" method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>">
    83     <input type="hidden" name="testplugin" value="Y" />
    84     Mode : <select name="mode"><option value="0">Image URL </option><option value="1">Post Id </option></select>
    85     Image URL/Post ID : <input type="text" name="post_id" value="<?php echo $_POST['post_id'];?>" style="width:250px"/>
    86     <br />
    87     If you don't specify percent then specify width and height both.
    88     <br />
    89     Percent (only numeric) : <input type="text" name="percent" value="<?php echo $_POST['percent'];?>" style="width:50px"/> |
    90     Width : <input type="text" name="width" value="<?php echo $_POST['width'];?>" style="width:50px"/>
    91     Height : <input type="text" name="height" value="<?php echo $_POST['height'];?>" style="width:50px"/>
    92     <br />
    93     if you specify Constrain as 0, resized image will be stretched. To maintain the ratio keep it 1.
    94     <br />
    95     Zoom/Crop :  <select name="zc"><option value="0">0</option><option value="1">1</option></select>
    96     Constrain : <select name="cons"><option value="0">0</option><option value="1">1</option></select>
    97     <center><p><input type="submit" name="Submit" value="submit" /></p></center>
    98 </form>
     124<h1>Test Plugin </h1>
     125
     126    <form name="amtyThumbTest_form" method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>">
     127        <input type="hidden" name="testplugin" value="Y" />
     128        Mode : <select name="mode"><option value="0">Image URL </option><option value="1">Post Id </option></select>
     129        Image URL/Post ID : <input type="text" name="post_id" value="<?php echo $_POST['post_id'];?>" style="width:250px"/>
     130        <br />
     131        If you don't specify percent then specify width and height both.
     132        <br />
     133        Percent (only numeric) : <input type="text" name="percent" value="<?php echo $_POST['percent'];?>" style="width:50px"/> |
     134        Width : <input type="text" name="width" value="<?php echo $_POST['width'];?>" style="width:50px"/>
     135        Height : <input type="text" name="height" value="<?php echo $_POST['height'];?>" style="width:50px"/>
     136        <br />
     137        if you specify Constrain as 0, resized image will be stretched. To maintain the ratio keep it 1.
     138        <br />
     139        Zoom/Crop :  <select name="zc"><option value="0">0</option><option value="1">1</option></select>
     140        Constrain : <select name="cons"><option value="0">0</option><option value="1">1</option></select>
     141        <center><p><input type="submit" name="Submit" value="submit" /></p></center>
     142       
     143        <?php
     144            if($_POST['testplugin'] == 'Y') {
     145                if($_POST['mode'] == 0){
     146                    amty_testPlugin($_POST['post_id'],'',$_POST['width'],$_POST['height'],$_POST['percent'],$_POST['cons'],$_POST['zc']);
     147                }
     148                else{
     149                    amty_testPlugin('',$_POST['post_id'],$_POST['width'],$_POST['height'],$_POST['percent'],$_POST['cons'],$_POST['zc']);
     150                }
     151            }
     152        ?>
     153    </form>
    99154</div>
     155<hr />
    100156<div>
    101     <?php
    102         if($_POST['testplugin'] == 'Y') {
    103             if($_POST['mode'] == 0){
    104                 amty_testPlugin($_POST['post_id'],'',$_POST['width'],$_POST['height'],$_POST['percent'],$_POST['cons'],$_POST['zc']);
    105             }
    106             else{
    107                 amty_testPlugin('',$_POST['post_id'],$_POST['width'],$_POST['height'],$_POST['percent'],$_POST['cons'],$_POST['zc']);
    108             }
    109         }
    110     ?>
    111 </div>
    112 </div>
    113 <div style="clear:both;"></div>
    114 <hr />
    115 <br />
     157<h1>Report Broken but cached Links</h1>
    116158<form name="amtyThumbReport_form" method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>">
    117159    <input type="hidden" name="reportBroken" value="Y" />
    118160    <center><p><input type="submit" name="reportBrokenSubmit" value="Report Broken Cached Images" /></p></center>
    119 </form>
    120 </div>
    121 <div>
    122161    <?php
    123162        if($_POST['reportBroken'] == 'Y') {
     
    125164        }
    126165    ?>
     166</form>
    127167</div>
    128168
    129 <div style="clear:both;"></div>
    130169<hr />
    131 </div>
  • amtythumb/trunk/cacheFunction.php

    r776588 r779794  
    11<?php
     2
     3function getAmtyThumbCachePath(){
     4    $dir = WP_CONTENT_DIR . "/amtythumbcache/";
     5    if (!file_exists($dir)) {
     6        mkdir($dir, 0755, true);
     7    }
     8    return $dir;
     9}
     10
     11function getAmtyThumbPluginURL(){
     12    return WP_PLUGIN_URL . "/amtythumb/";
     13}
     14
     15function getAmtyThumbPluginPath(){
     16    return WP_PLUGIN_DIR . "/amtythumb/";
     17}
     18
     19function getAmtyThumbCacheURL(){
     20    $dir = WP_CONTENT_URL . "/amtythumbcache/";
     21}
    222
    323//empty image cache and all thumbnails from file system
     
    1131
    1232function amty_clearImageCacheHard(){
    13     $dir = WP_PLUGIN_DIR . "/amtythumb/cache";
    14     if($handle=opendir($dir)){
     33    if($handle=opendir(getAmtyThumbCachePath())){
    1534        while ( ($file = readdir($handle)) !==false) {
    16             @unlink($dir.'/'.$file);
     35            @unlink(getAmtyThumbCachePath().$file);
    1736        }
    1837        closedir($handle);
     
    2948function amty_deletePostFromCache($postId){
    3049    if(get_post_meta($postId,'amtyThumb',true) != '' ){
    31         $dir = WP_PLUGIN_DIR . "/amtythumb/cache";
    32         if($handle=opendir($dir)){
     50        if($handle=opendir(getAmtyThumbCachePath())){
    3351            while ( ($file = readdir($handle)) !==false) {
    3452                if(preg_match('/^'. $postId .'_.*\.jpg/', $file)){
    35                     @unlink($dir.'/'.$file);
     53                    @unlink(getAmtyThumbCachePath().$file);
    3654                }
    3755            }
     
    5472            }
    5573            else{
    56                 $img = WP_PLUGIN_URL . "/amtythumb/amtytextthumb.gif";
     74                $img = getAmtyThumbPluginURL(). "amtytextthumb.gif";
    5775            }
    5876        }elseif(!isImage($img)){//image is not valid
    59             $img = WP_PLUGIN_URL . "/amtythumb/invalid.gif";
     77            $img = getAmtyThumbPluginURL(). "invalid.gif";
    6078        }
    6179        update_post_meta($postId,'amtyThumb',$img);
     
    7088    endwhile;
    7189    wp_reset_postdata();
     90}
     91
     92function amty_populateCacheAllManual($w,$h,$c,$zc){
     93    $query = new WP_Query( 'posts_per_page=-1' );
     94    print "caching for : ";
     95    while ( $query->have_posts() ) : $query->the_post();
     96        print $pid .",";
     97        $pid = get_the_ID();
     98        amty_lead_img($w,$h,$c,'','',$zc,$pid,'','');
     99    endwhile;
     100    wp_reset_postdata();
     101}
     102
     103function amty_populateCacheManual($w,$h,$c,$zc,$pid){
     104    amty_lead_img($w,$h,$c,'','',$zc,$pid,'','');
    72105}
    73106
     
    90123}
    91124
     125function amty_getFilesInCacheFolder(){
     126    $count = 0;
     127    $dir = getAmtyThumbCachePath();
     128    if ($handle = opendir($dir)) {
     129        while (($file = readdir($handle)) !== false){
     130            if (!in_array($file, array('.', '..')) && !is_dir($dir.$file))
     131                $count++;
     132        }
     133    }
     134    return $count;
     135}
     136
    92137function reportBrokenImage(){
    93138    $query = new WP_Query( 'posts_per_page=-1' );
  • amtythumb/trunk/lead-img.php

    r777391 r779794  
    2727    }else{
    2828        if(isImage($img)){//to avoid invalid path or 404 errors
    29             $img = WP_PLUGIN_URL . "/amtythumb/invalid.gif";
     29            $img = getAmtyThumbPluginURL() . "invalid.gif";
    3030        }
    3131    }
    3232   
    3333    //To save image on disk
    34     $img_uri = WP_PLUGIN_DIR . "/amtythumb/cache/". $pid . "_" . $w . "_" . $h . ".jpg";
     34    $img_uri = getAmtyThumbCachePath() . $pid . "_" . $w . "_" . $h . ".jpg";
    3535   
    3636    if($pid == -1 || !file_exists($img_uri)) { //for specific image resizging, caching is not required. it'll be saved with -1 pid
     
    4040   
    4141    //Actual image url
    42     $resized_img = WP_PLUGIN_URL . "/amtythumb/cache/". $pid . "_" . $w . "_" . $h . ".jpg";
     42    $resized_img = getAmtyThumbCacheURL() . $pid . "_" . $w . "_" . $h . ".jpg";
    4343   
    4444    if($img_url_only == "y"){
  • amtythumb/trunk/readme.txt

    r777391 r779794  
    55Requires at least: 2.5
    66Tested up to: 3.5
    7 Stable tag: 3.2.0
     7Stable tag: 4.0.0
    88
    99Fetch first image of a post and Resize it. Otherwise resize an image.
     
    9494== Changelog ==
    9595
     96= 4.0.0 =
     97* cache outside plugin folder. So your cache doesnt get empty on plugin update
     98* offline cache - You can rebuild cache for all or particular posts directly through option page. It saves client response time for posts which are not cached yet.
     99* HTML design fix amty thumb option page.
     100
    96101= 3.2.0 =
    97102* improved quality of PNG and GIF files resizing
     
    137142== Upgrade Notice ==
    138143
     144= 4.0.0 =
     145* cache outside plugin folder. So your cache doesnt get empty on plugin update
     146* offline cache - You can rebuild cache for all or particular posts directly through option page. It saves client response time for posts which are not cached yet.
     147* HTML design fix amty thumb option page.
     148
    139149= 3.2.0 =
    140150* improved quality of PNG and GIF files resizing
    141 
    142 = 3.1.1 =
    143 * direct recache link.
    144151
    145152= 3.0.1 =
Note: See TracChangeset for help on using the changeset viewer.