Plugin Directory

Changeset 178651


Ignore:
Timestamp:
12/02/2009 04:03:19 AM (16 years ago)
Author:
karunanidhi
Message:
  • Added settings page options that will allow users to apply custom CSS classes to the image container, images, and control thumbnail width
  • Updated default regular expressions
  • Added "Maintenance" functions to clean-up thumbnails and force renaming of all images for search engine optimization
  • Removed all inline style code for the admin screen and moved it into an admin-page only css file
Location:
auto-post-images-api/trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • auto-post-images-api/trunk/auto-post-images.php

    r155924 r178651  
    33Plugin Name: Auto Post Images (API)
    44Plugin URI: http://www.karthikeyankarunanidhi.com
    5 Version: 2.2
     5Version: 2.3
    66Author: <a href="http://www.karthikeyankarunanidhi.com">Karthikeyan Karunanidhi</a>
    77Description: Automatically adds images to posts without having to edit the post.
     
    8787
    8888            /**
     89            * Width of the thumbnails
     90            */
     91            var $iThumbnailWidth = 100;
     92
     93            /**
     94            * Style class to apply to images
     95            */
     96            var $sImageClass = '';
     97
     98            /**
     99            * Style class to apply the the image container
     100            */
     101            var $sContainerClass = '';
     102
     103            /**
    89104            * Plugin settings
    90105            */
     
    97112                                            "sImageThumbnailDirUrl" => '',
    98113                                            "sImageCacheDir" => '',
    99                                             "sRegEx" => "^Image___POSTID__[^0-9]*\.[a-zA-Z]+$",
    100                                             "bOptmizeImagesForSearch" => 'NO'
     114                                            "sRegEx" => "^api__POSTID__[^\.]*\.[a-zA-Z]+$",
     115                                            "bOptmizeImagesForSearch" => 'NO',
     116                                            "sImageClass" => '',
     117                                            "sContainerClass" => '',
     118                                            "iThumbnailWidth" => 100
    101119                                        );
    102120            /**
     
    105123            *  the postid before searching for images
    106124            */
    107             var $sRegEx = "^Image___POSTID__[^0-9]*\.[a-zA-Z]+$";
     125            var $sRegEx = "^api__POSTID__[^\.]*\.[a-zA-Z]+$";
    108126
    109127            /**
    110128            * Default regular expression to use when searching for images associated with a post.
    111129            */
    112             var $sDefaultRegEx = "^Image___POSTID__[^0-9]*\.[a-zA-Z]+$";
     130            var $sDefaultRegEx = "^api__POSTID__[^\.]*\.[a-zA-Z]+$";
    113131
    114132            /**
    115133            * Default regular expression to use when renaming images for SEO
    116134            */
    117             var $sImageSEOPrefix = "api";
     135            var $sImageSEOPrefix = "sapi";
    118136            var $sImageSEOPattern = '';
     137            var $sImageSEOPatternMatched = '';
    119138
    120139            /**
     
    123142            function KKAutoPostImages () {
    124143
    125                 $this->sImageSEOPattern = '^' . $this->sImageSEOPrefix . '[0-9]+_';
     144                $this->sImageSEOPattern = '^' . $this->sImageSEOPrefix . '[0-9]+';
     145                $this->sImageSEOPatternMatched = '^' . $this->sImageSEOPrefix . '([0-9]+)';
    126146
    127147                $this->init();
     
    144164                $this->sDefaultImageUrl = $this->sImageDirUrl . $this->sDefaultImageName;
    145165
     166                $this->sImageClass = $this->aAdminOptions['sImageClass'];
     167                $this->sContainerClass = $this->aAdminOptions['sContainerClass'];
     168
     169                $this->iThumbnailWidth = ( empty($this->aAdminOptions['iThumbnailWidth']) || !is_numeric($this->aAdminOptions['iThumbnailWidth']) ) ? 100 : $this->aAdminOptions['iThumbnailWidth'];
     170
    146171                if ($this->aAdminOptions['bOptmizeImagesForSearch'] == 'YES') {
    147172
    148                     $this->sRegEx = '^' . $this->sImageSEOPrefix . '__POSTID___'; //[^\n]*\.[^\n]+$';
     173                    $this->sRegEx = '^' . $this->sImageSEOPrefix . '__POSTID__'; //[^\n]*\.[^\n]+$';
    149174
    150175                } else {
     
    261286                }
    262287
    263                 $sHtml .= '<div class="kkautopostimage">';
     288                $sHtml .= '<div class="kkautopostimage '.$this->sContainerClass.'">';
    264289
    265290                foreach($aImageUrls as $sImageName => $sImageUrl) {
     
    287312                                $oThumbs = new ThumbCreator();
    288313
    289                                 $bStatus = $oThumbs->createThumbnail($this->sImageDirPath, $sImageFilePath, $sThumbnailPath);
     314                                $bStatus = $oThumbs->createThumbnail($this->sImageDirPath, $sImageFilePath, $sThumbnailPath, $this->iThumbnailWidth);
    290315
    291316                                if( $bStatus === FALSE ) {
     
    300325                    $sThumbSearchTags = str_replace('-', ' ', $sThumbSearchName);
    301326
    302                     $sHtml .= "<a href=\"{$sImageUrl}\"  rel=\"ibox\" title=\"&nbsp;\"><img src=\"{$sThumbnailUrl}\" alt=\"{$sThumbSearchTags}\" title=\"Click to enlarge\" /></a><br />";
     327                    //echo '<pre>', print_r($post, TRUE), '</pre>';
     328
     329                    $sHtml .= "<a href=\"{$sImageUrl}\"  rel=\"ibox\" title=\"&nbsp;\"><img src=\"{$sThumbnailUrl}\" class=\"{$this->sImageClass}\" alt=\"{$sThumbSearchTags}\" title=\"".ucwords($post->post_title)."\" /></a><br />";
    303330                }
    304331
     
    314341
    315342                echo '<link type="text/css" rel="stylesheet" href="' . get_bloginfo('wpurl') . '/wp-content/plugins/auto-post-images-api/css/kkimageinpost.css" />' . "\n";
     343            }
     344
     345            /**
     346            * Hooked into 'admin_head' and inserts the css <link> tag into the pages <head>
     347            */
     348            function includeAdminCSS() {
     349                echo '<link type="text/css" rel="stylesheet" href="' . get_bloginfo('wpurl') . '/wp-content/plugins/auto-post-images-api/css/kkapiadmin.css" />' . "\n";
    316350            }
    317351
     
    366400                $aAdminOptions['sImageThumbnailDirUrl'] = $this->sImageThumbnailDirUrl;
    367401                $aAdminOptions['sImageCacheDir'] = $this->sImageCacheDir;
     402                $aAdminOptions['sImageClass'] = $this->sImageClass;
     403                $aAdminOptions['sContainerClass'] = $this->sContainerClass;
     404
     405                $aAdminOptions['iThumbnailWidth'] = $this->iThumbnailWidth;
    368406
    369407                if (isset($_POST['updateAutoPostImagesSettings'])) {
     
    421459                    }
    422460
     461                    if (isset($_POST['AutoPostImagesImageClass'])) {
     462
     463                        $aAdminOptions['sImageClass'] = $_POST['AutoPostImagesImageClass'];
     464                    }
     465
     466                    if (isset($_POST['AutoPostImagesContainerClass'])) {
     467
     468                        $aAdminOptions['sContainerClass'] = $_POST['AutoPostImagesContainerClass'];
     469                    }
     470
     471                    if (isset($_POST['AutoPostImagesThumbnailWidth'])) {
     472
     473                        $aAdminOptions['iThumbnailWidth'] = ( !empty($_POST['AutoPostImagesThumbnailWidth']) ) ? $_POST['AutoPostImagesThumbnailWidth'] : $aAdminOptions['iThumbnailWidth'];
     474                    }
     475
    423476                    if ( !ereg("/$", $aAdminOptions['sImageDirPath']) ) {
    424477
    425                         $aAdminOptions['sImageDirPath'] = $aAdminOptions['sImageDirPath'] . '/';
     478                        $aAdminOptions['sImageDirPath'] = $aAdminOptions['sImageDirPath'] . '\\';
    426479                    }
    427480
    428481                    if ( !ereg("/$", $aAdminOptions['sImageThumbnailDirPath']) ) {
    429482
    430                         $aAdminOptions['sImageThumbnailDirPath'] = $aAdminOptions['sImageThumbnailDirPath'] . '/';
     483                        $aAdminOptions['sImageThumbnailDirPath'] = $aAdminOptions['sImageThumbnailDirPath'] . '\\';
    431484                    }
    432485
     
    443496                    if ( !ereg("/$", $aAdminOptions['sImageCacheDir']) ) {
    444497
    445                         $aAdminOptions['sImageCacheDir'] = $aAdminOptions['sImageCacheDir'] . '/';
    446                     }
     498                        $aAdminOptions['sImageCacheDir'] = $aAdminOptions['sImageCacheDir'] . '\\';
     499                    }
     500
     501                    $aAdminOptions = array_map('stripslashes_deep', $aAdminOptions);
     502
     503                    //echo '<pre>', print_r($aAdminOptions, TRUE), '</pre>';
    447504
    448505                    update_option($this->sAdminOptionsName, $aAdminOptions);
     506
     507                    if (isset($_POST['AutoPostImagesRerun']) && $_POST['AutoPostImagesRerun'] == 'rerun') {
     508
     509                        //echo '<pre>', print_r($_POST, TRUE), '</pre>';
     510
     511                        $sRerunStatus = $this->rerunImagesProcesses();
     512
     513                        if($bRerunStatus !== FALSE) {
     514
     515                            echo $sRerunStatus;
     516                        }
     517                    }
    449518
    450519                    echo '<div class="updated"><p><strong>' . __("Settings Updated.", "KKAutoPostImages") . '</strong></p></div>';
     
    507576
    508577                echo "
    509                         <div class=\"wrap\">
     578                        <div class=\"kkwrap\">
    510579
    511580                            <form method=\"post\" action=\"{$sRequestUri}\">
     
    513582                                <h2>Auto Post Images (API) Settings</h2>
    514583
    515                                 <h3>Display default image if not image is found?</h3>
    516 
    517                                 <p>
    518                                     <input type=\"radio\" id=\"AutoPostImagesDisplayDefaultImages_yes\" name=\"AutoPostImagesDisplayDefaultImages\" value=\"YES\" {$sDisplayDefaultImageYesRadio} /> <label for=\"AutoPostImagesDisplayDefaultImages_yes\">Yes</label>
    519                                     <input type=\"radio\" id=\"AutoPostImagesDisplayDefaultImages_no\" name=\"AutoPostImagesDisplayDefaultImages\" value=\"NO\" {$sDisplayDefaultImageNoRadio} /> <label for=\"AutoPostImagesDisplayDefaultImages_no\">No</label>
    520                                 </p>
    521 
    522                                 <p>Selecting &quot;No&quot; will hide the default &quot;Image coming soon&quot; image if no images are found for the post.</p>
    523 
    524                                 <h3>Use thumbnails to link to full size images?</h3>
    525 
    526                                 <p>
    527                                     <input type=\"radio\" id=\"AutoPostImagesUseThumbnails_yes\" name=\"AutoPostImagesUseThumbnails\" value=\"YES\" {$sUseThumbnailsYesRadio} /> <label for=\"AutoPostImagesUseThumbnails_yes\">Yes</label>
    528                                     <input type=\"radio\" id=\"AutoPostImagesUseThumbnails_no\" name=\"AutoPostImagesUseThumbnails\" value=\"NO\" {$sUseThumbnailsNoRadio} /> <label for=\"AutoPostImagesUseThumbnails_no\">No</label>
    529                                 </p>
    530 
    531                                 <p>Selecting &quot;Yes&quot; will use thumbnail images in the post to link to full size images.</p>
    532 
    533                                 <h3>Image search Regular Expression?</h3>
    534 
    535                                 <p>
    536                                     <input type=\"text\" size=\"75\" id=\"AutoPostImagesRegEx\" name=\"AutoPostImagesRegEx\" value=\"$aAdminOptions[sRegEx]\" />
    537                                 </p>
    538 
    539                                 <p>
    540                                     Regular expression to use when searching for images associated with a post. Must have __POSTID__ somewhere in the expression which will be replaced with the actual post id before searching.
    541                                 </p>
    542 
    543                                 <p>
    544                                     <strong>Note: </strong>If <em>Rename images for SEO</em> (below) is enabled then images uploaded must still be named according to the regular expression specified here. The plugin will automatically rename images for SEO.
    545                                 </p>
    546 
    547                                 <h3>Rename images for SEO?</h3>
    548 
    549                                 <p>
    550                                     <input type=\"radio\" id=\"AutoPostImagesOptmizeImagesForSearch_yes\" name=\"AutoPostImagesOptmizeImagesForSearch\" value=\"YES\" {$sOptmizeImagesForSearchYesRadio} onClick=\"javascript:alert('Ensure that images uploaded are named according to the regular expression specified in Image search Regular Expression (above). The plugin will automatically rename images for SEO.')\" /> <label for=\"AutoPostImagesOptmizeImagesForSearch_yes\">Yes</label>
    551                                     <input type=\"radio\" id=\"AutoPostImagesOptmizeImagesForSearch_no\" name=\"AutoPostImagesOptmizeImagesForSearch\" value=\"NO\" {$sOptmizeImagesForSearchNoRadio} /> <label for=\"AutoPostImagesOptmizeImagesForSearch_no\">No</label>
    552                                 </p>
    553 
    554                                 <p>Selecting &quot;Yes&quot; will use rename the images using the POST title so that the images names are optimized for search.</p>
    555 
    556                                 <p>
    557                                     <strong>Note: </strong>Ensure that images uploaded are named according to the regular expression specified in <em>Image search Regular Expression</em> (above). The plugin will automatically rename images for SEO.
    558                                 </p>
    559 
    560                                 <h3>Image directory?</h3>
    561 
    562                                 <p>
    563                                     <input type=\"text\" size=\"75\" id=\"AutoPostImagesImgDir\" name=\"AutoPostImagesImgDir\" value=\"$aAdminOptions[sImageDirPath]\" />
    564                                 </p>
    565 
    566                                 <h3>Thumbnail directory?</h3>
    567 
    568                                 <p>
    569                                     <input type=\"text\" size=\"75\" id=\"AutoPostImagesThumbDir\" name=\"AutoPostImagesThumbDir\" value=\"$aAdminOptions[sImageThumbnailDirPath]\" />
    570                                 </p>
    571 
    572                                 <h3>Image directory URL?</h3>
    573 
    574                                 <p>
    575                                     <input type=\"text\" size=\"75\" id=\"AutoPostImagesImgUrl\" name=\"AutoPostImagesImgUrl\" value=\"$aAdminOptions[sImageDirUrl]\" />
    576                                 </p>
    577 
    578                                 <h3>Thumbnail directory URL?</h3>
    579 
    580                                 <p>
    581                                     <input type=\"text\" size=\"75\" id=\"AutoPostImagesThumbUrl\" name=\"AutoPostImagesThumbUrl\" value=\"$aAdminOptions[sImageThumbnailDirUrl]\" />
    582                                 </p>
    583 
    584                                 <h3>Cache directory? (Used by the thumbnail creator)</h3>
    585 
    586                                 <p>
    587                                     <input type=\"text\" size=\"75\" id=\"AutoPostImagesCacheDir\" name=\"AutoPostImagesCacheDir\" value=\"$aAdminOptions[sImageCacheDir]\" />
    588                                 </p>
     584                                <fieldset class=\"kkfieldset\">
     585                                    <legend>General Settings</legend>
     586
     587                                    <h3>Display default image if not image is found?</h3>
     588
     589                                    <p>
     590                                        <input type=\"radio\" id=\"AutoPostImagesDisplayDefaultImages_yes\" name=\"AutoPostImagesDisplayDefaultImages\" value=\"YES\" {$sDisplayDefaultImageYesRadio} /> <label for=\"AutoPostImagesDisplayDefaultImages_yes\">Yes</label>
     591                                        <input type=\"radio\" id=\"AutoPostImagesDisplayDefaultImages_no\" name=\"AutoPostImagesDisplayDefaultImages\" value=\"NO\" {$sDisplayDefaultImageNoRadio} /> <label for=\"AutoPostImagesDisplayDefaultImages_no\">No</label>
     592                                    </p>
     593
     594                                    <p>Selecting &quot;No&quot; will hide the default &quot;Image coming soon&quot; image if no images are found for the post.</p>
     595
     596                                    <h3>Use thumbnails to link to full size images?</h3>
     597
     598                                    <p>
     599                                        <input type=\"radio\" id=\"AutoPostImagesUseThumbnails_yes\" name=\"AutoPostImagesUseThumbnails\" value=\"YES\" {$sUseThumbnailsYesRadio} /> <label for=\"AutoPostImagesUseThumbnails_yes\">Yes</label>
     600                                        <input type=\"radio\" id=\"AutoPostImagesUseThumbnails_no\" name=\"AutoPostImagesUseThumbnails\" value=\"NO\" {$sUseThumbnailsNoRadio} /> <label for=\"AutoPostImagesUseThumbnails_no\">No</label>
     601                                    </p>
     602
     603                                    <p>Selecting &quot;Yes&quot; will use thumbnail images in the post to link to full size images.</p>
     604
     605                                    <h3>Customize appearance</h3>
     606
     607                                    <p>
     608                                        <label class=\"kklabel\">Container style class: </label><input type=\"text\" class=\"kkwidth20\" id=\"AutoPostImagesContainerClass\" name=\"AutoPostImagesContainerClass\" value=\"$aAdminOptions[sContainerClass]\" /> (Class names specified here is applied to the <em>div</em> that contains the images.)
     609                                    </p>
     610
     611                                    <p>
     612                                        <label class=\"kklabel\">Image style class: </label><input type=\"text\" class=\"kkwidth20\" id=\"AutoPostImagesImageClass\" name=\"AutoPostImagesImageClass\" value=\"$aAdminOptions[sImageClass]\" /> (Class names specified here is applied to the images.)
     613                                    </p>
     614
     615                                    <p>
     616                                        <label class=\"kklabel\">Thumbnail width (px): </label><input type=\"text\" class=\"kkwidth20\" id=\"AutoPostImagesThumbnailWidth\" name=\"AutoPostImagesThumbnailWidth\" value=\"$aAdminOptions[iThumbnailWidth]\" /> (Width of the thumbnails generated. The height is automatically calculated to maintain the aspect ratio. Changes are applied to any new thumbnails generated. If you wish to apply the new width to existing thumbnails then enable Maintenance functions at the end of this page.)
     617                                    </p>
     618
     619                                    <h3>Image search Regular Expression?</h3>
     620
     621                                    <p>
     622                                        <input type=\"text\" size=\"75\" id=\"AutoPostImagesRegEx\" name=\"AutoPostImagesRegEx\" value=\"$aAdminOptions[sRegEx]\" /> (Regular expression to use when searching for images associated with a post. Must have __POSTID__ somewhere in the expression which will be replaced with the actual post id before searching.)
     623                                    </p>
     624
     625                                    <p>
     626                                        <strong>Note: </strong>If <em>Rename images for SEO</em> (below) is enabled then images uploaded must still be named according to the regular expression specified here. The plugin will automatically rename images for SEO.
     627                                    </p>
     628
     629                                    <h3>Rename images for SEO?</h3>
     630
     631                                    <p>
     632                                        <input type=\"radio\" id=\"AutoPostImagesOptmizeImagesForSearch_yes\" name=\"AutoPostImagesOptmizeImagesForSearch\" value=\"YES\" {$sOptmizeImagesForSearchYesRadio} onClick=\"javascript:alert('Ensure that images uploaded are named according to the regular expression specified in Image search Regular Expression (above). The plugin will automatically rename images for SEO.')\" /> <label for=\"AutoPostImagesOptmizeImagesForSearch_yes\">Yes</label>
     633                                        <input type=\"radio\" id=\"AutoPostImagesOptmizeImagesForSearch_no\" name=\"AutoPostImagesOptmizeImagesForSearch\" value=\"NO\" {$sOptmizeImagesForSearchNoRadio} /> <label for=\"AutoPostImagesOptmizeImagesForSearch_no\">No</label>
     634                                    </p>
     635
     636                                    <p>Selecting &quot;Yes&quot; will rename the images using the POST title so that the images names are optimized for indexing by search engines.</p>
     637
     638                                    <p>
     639                                        <strong>Note: </strong>Ensure that images uploaded are named according to the regular expression specified in <em>Image search Regular Expression</em> (above). The plugin will automatically rename images for SEO. For example: If <em>Image search Regular Expression</em> is set to \"^api__POSTID__[^.]*.[a-zA-Z]+$\" then you will upload images for POST #3 as <em>api3.jpg</em> and the SEO process will rename it as <em>sapi3_the-title-of-the-post_0.jpg</em> and the thumbnail will be named <em>thumb_sapi3_the-title-of-the-post_0.jpg</em>
     640                                    </p>
     641
     642                                    <h3>Image directory?</h3>
     643
     644                                    <p>This is the location where you will be putting all the images. You should change this from the default to a folder outside the plugin directory.</p>
     645
     646                                    <p>
     647                                        <input type=\"text\" class=\"kkwidth90\" id=\"AutoPostImagesImgDir\" name=\"AutoPostImagesImgDir\" value=\"$aAdminOptions[sImageDirPath]\" />
     648                                    </p>
     649
     650                                    <h3>Thumbnail directory?</h3>
     651
     652                                    <p>This is where the thumbnails generated by the plugin are stored. You should change this from the default to a folder outside the plugin directory.</p>
     653
     654                                    <p>
     655                                        <input type=\"text\" class=\"kkwidth90\" id=\"AutoPostImagesThumbDir\" name=\"AutoPostImagesThumbDir\" value=\"$aAdminOptions[sImageThumbnailDirPath]\" />
     656                                    </p>
     657
     658                                    <h3>Cache directory? (Used by the thumbnail creator)</h3>
     659
     660                                    <p>This is the directory used by the plugin as cache location when generating thumbnails. Ensure that the plugin has write permissions for this folder.</p>
     661
     662                                    <p>
     663                                        <input type=\"text\" class=\"kkwidth90\" id=\"AutoPostImagesCacheDir\" name=\"AutoPostImagesCacheDir\" value=\"$aAdminOptions[sImageCacheDir]\" />
     664                                    </p>
     665
     666                                    <h3>Image directory URL?</h3>
     667
     668                                    <p>This the url to the directory where the images are stored.</p>
     669
     670                                    <p>
     671                                        <input type=\"text\" class=\"kkwidth90\" id=\"AutoPostImagesImgUrl\" name=\"AutoPostImagesImgUrl\" value=\"$aAdminOptions[sImageDirUrl]\" />
     672                                    </p>
     673
     674                                    <h3>Thumbnail directory URL?</h3>
     675
     676                                    <p>This is the url to the directory where the thumbnails are stored.</p>
     677
     678                                    <p>
     679                                        <input type=\"text\" class=\"kkwidth90\" id=\"AutoPostImagesThumbUrl\" name=\"AutoPostImagesThumbUrl\" value=\"$aAdminOptions[sImageThumbnailDirUrl]\" />
     680                                    </p>
     681
     682                                </fieldset>
     683
     684                                <hr style=\"border:1px dashed #888;margin:20px 0;\" />
     685
     686                                <fieldset class=\"kkfieldset\">
     687                                    <legend>Maintenance</legend>
     688
     689                                    <h3>Rerun image maintenence functions?</h3>
     690
     691                                    <p>
     692                                        <input type=\"checkbox\" id=\"AutoPostImagesRerun\" value=\"rerun\" name=\"AutoPostImagesRerun\" value=\"$aAdminOptions[bRerun]\" /> Yes! Re-generate thumbnails &amp; SEO renaming (if enabled).
     693                                    </p>
     694
     695                                    <p>
     696                                        <strong>Note:</strong> If checked the plugin will delete &amp; re-generate all thumbnails folder, rename all images for SEO (if enabled). Use this to clean-up the thumbnails and ensure that all the images are named appropriately.
     697                                    </p>
     698                                </fieldset>
    589699
    590700                                <div class=\"submit\">
     
    596706            }
    597707
    598             function renameImagesForSEO() {
    599 
    600                 global $post;
    601 
    602                 $sThumbSearchName = $post->post_name;
     708            function renameImagesForSEO($iPostId = FALSE, $sPostName = '') {
     709
     710                if($iPostId === FALSE || is_numeric($iPostId) === FALSE) {
     711
     712                    global $post;
     713
     714                    $iPostId = $this->iPostId;
     715                    $sPostName = $post->post_name;
     716                }
     717
     718                $sThumbSearchName = $sPostName;
    603719                $sThumbSearchTags = str_replace('-', ' ', $sThumbSearchName);
    604720                $iImageSeoCount = 0;
     
    608724                //
    609725
    610                 $aImageFiles = $this->getImagesForThisPost($this->iPostId, $this->aAdminOptions['sRegEx']);
     726                $aImageFiles = $this->getImagesForThisPost($iPostId, $this->aAdminOptions['sRegEx']);
    611727
    612728                foreach($aImageFiles as $sKey => $sImageName) {
     
    625741                            do {
    626742
    627                                 $sNewSeoImageName = $this->sImageSEOPrefix . $this->iPostId . '_' . $sThumbSearchName . '_' . $iImageSeoCount++  . '.' . $sExtn;
     743                                $sNewSeoImageName = $this->sImageSEOPrefix . $iPostId . '_' . $sThumbSearchName . '_' . $iImageSeoCount++  . '.' . $sExtn;
    628744                                $sNewSeoThumbImageName = 'thumb_' . $sNewSeoImageName;
    629745
     
    631747                                $sNewThumbImageFilePath = $this->sImageThumbnailDirPath . $sNewSeoThumbImageName;
    632748
    633                             } while (is_file($sNewSeoImageName) === TRUE);
     749                            } while (is_file($sNewImageFilePath) === TRUE);
    634750
    635751                            //echo "<p>rename {$sImageName} to {$sNewImageFilePath}</p>";
     
    649765                                rename($sThumbImageFilePath, $sNewThumbImageFilePath);
    650766                            }
     767
     768                        } else {
     769
     770                            //
     771                            //echo "<p>{$sImageName} does not need SEO renaming</p>";
    651772                        }
    652773                    }
    653774                }
     775            }
     776
     777            function rerunImagesProcesses() {
     778
     779                $aImageTypes = array();
     780
     781                $oFileSys = new Filesystem();
     782                $sStatus = '<div class="updated"><p><strong>' . __("Running maintenance methods on images.", "KKAutoPostImages") . '</strong></p>';
     783
     784                //
     785                // Delete all the thumbnails
     786                //
     787                $aThumbnails = $oFileSys->readDir($this->sImageThumbnailDirPath);
     788
     789                //echo '<pre>', print_r($aThumbnails, TRUE), '</pre>';
     790
     791                foreach($aThumbnails as $sThumbnailPath) {
     792
     793                    //echo "<p>{$this->sImageThumbnailDirPath} {$sThumbnailPath}</p>";
     794
     795                    unlink($this->sImageThumbnailDirPath.$sThumbnailPath);
     796                }
     797
     798                $sStatus .= '<p>- ' . __("Deleted all thumbnails.", "KKAutoPostImages") . '</p>';
     799
     800                $aPostIds = array();
     801
     802                //
     803                // Run SEO on image names
     804                //
     805                if ($this->aAdminOptions['bOptmizeImagesForSearch'] == 'YES') {
     806
     807                    $aPostsList = get_posts('');
     808
     809                    foreach($aPostsList as $post) {
     810
     811                        //echo $post->ID;
     812                        //echo '<pre>', print_r($post, TRUE), '</pre>';
     813
     814                        $aPostIds[$post->ID] = $post->ID;
     815                        $this->renameImagesForSEO($post->ID, $post->post_name);
     816                    }
     817                }
     818
     819                $sStatus .= '<p> - ' . __("Optimied all image names for search engine optimization.", "KKAutoPostImages") . '</p>';
     820
     821                //
     822                // Locate images that are not associated with any POSTs & images that are not named correctly
     823                //
     824                $aImages = $oFileSys->readDir($this->sImageDirPath);
     825
     826                $aImagePostIds = array();
     827
     828                $sRegExMatched = $this->aAdminOptions['sRegEx'];
     829
     830                foreach($aImages as $sImagePath) {
     831
     832                    //echo "<p>{$this->sImageDirPath} {$sImagePath}</p>";
     833
     834                    if( eregi($this->sImageSEOPatternMatched, $sImagePath) ) {
     835
     836                        //$aImageTypes['seo'][] = $sImagePath;
     837
     838                    } else if(eregi($sRegExMatched, $sImagePath)) {
     839
     840                        $aImageTypes['Non SEO Images'][] = $sImagePath;
     841
     842                    } else {
     843
     844                        $aImageTypes['Unknown Images'][] = $sImagePath;
     845                    }
     846                }
     847
     848                $sImageProperties = '<strong>Report:</strong><ul class="kkreportui">';
     849                foreach($aImageTypes as $sImageType => $aImageList) {
     850
     851                    $sImageProperties .= "<li><strong>{$sImageType}</strong><ul class=\"kkreportui2\">";
     852
     853                    foreach($aImageList as $sImage) {
     854
     855                        $sImageProperties .= "<li>{$sImage}</li>";
     856                    }
     857
     858                    $sImageProperties .= "</ul></li>";
     859                }
     860                $sImageProperties .= "</ul>";
     861
     862                $sStatus .= '<p> - ' . __("Examining all images.", "KKAutoPostImages") . '</p>' . "<p>{$sImageProperties}</p>";
     863
     864                //echo '<pre>', print_r($aImageTypes, TRUE), '</pre>';
     865
     866                $sStatus .= '<p /><p><strong>' . __("Maintenance complete.", "KKAutoPostImages") . '</strong></p>';
     867
     868                $sStatus .= '</div>';
     869
     870                return $sStatus;
    654871            }
    655872
     
    675892            if ( function_exists('add_options_page') ) {
    676893
    677                 add_options_page('Auto Post Images (API) Settings', 'Auto Post Images (API) Settings', 9, basename(__FILE__), array(&$oKKAutoPostImages, 'printAdminPage'));
     894                $mypage = add_options_page('Auto Post Images (API) Settings', 'Auto Post Images (API) Settings', 9, basename(__FILE__), array(&$oKKAutoPostImages, 'printAdminPage'));
     895
     896                add_action( "admin_print_scripts-$mypage", array(&$oKKAutoPostImages, 'includeAdminCSS'), 1);
    678897            }
    679898        }
  • auto-post-images-api/trunk/php/Filesystem.class.php

    r72153 r178651  
    6363                        } else {
    6464
    65                             if($sFileRegEx !== FALSE && !ereg($sFileRegEx, $file)) {
     65                            if($sFileRegEx !== FALSE && !eregi($sFileRegEx, $file)) {
    6666
    6767                                continue;
  • auto-post-images-api/trunk/php/ThumbCreator.class.php

    r90273 r178651  
    1616        }
    1717
    18         function createThumbnail ($sImageDir, $sImageFilePath, $sThumbnailFilePath) {
     18        function createThumbnail ($sImageDir, $sImageFilePath, $sThumbnailFilePath, $iThumbnailWidth = 100) {
    1919
    2020            // create phpThumb object
     
    2222            $oThumb = new phpThumb();
    2323
    24             // thumbnail width
    25             //
    26             $iThumbnailWidth = 100;
    2724            $sCache = dirname(__FILE__) . '/phpThumb/cache/';
    2825
  • auto-post-images-api/trunk/readme.txt

    r155929 r178651  
    44Tags: auto,automatic,image,images,post,recipe,recipes,cook,cooking,chef,kitchen,photo,blog,photos
    55Requires at least: 2.6.2
    6 Tested on: 2.6.2, 2.7, 2.7.1, 2.8.4
    7 Tested up to: 2.8.4
    8 Stable tag: 2.2
     6Tested on: 2.6.2, 2.7, 2.7.1, 2.8.4,2.8.6
     7Tested up to: 2.8.6
     8Stable tag: 2.3
    99
    1010Automatically adds images to posts without having to edit the post.
     
    2424Images tagged with the POSTID are displayed on that post. If the thumbnail option is enabled the plugin will use thumbnails in the post to link to the full size images. The plugin will automatically create thumbnails when needed.
    2525
    26 Usage: Upload images by naming them as `'Image_POSTID'` where 'POSTID' is ID of post where the image should be displayed. If you wish to use a different filename format then you can edit the regular expression pattern in the settings page.
     26Usage: Upload images by naming them as `'apiPOSTID'` where 'POSTID' is ID of post where the image should be displayed. If you wish to use a different filename format then you can edit the regular expression pattern in the settings page.
    2727
    2828Multiple images can be attached to a post simply by ensuring that all of them have the same prefix. For posts that do not have images a default "Image coming soon" image is displayed; this can be disabled from the settings screen.
    2929
    30 Example Image Name: `'Image_66.jpg', 'Image_66_a.jpeg', 'Image_66_two.gif', 'Image_66something'`, etc. Note: When posting multiple images to the same post by naming them with the same 'Image_NNN' prefix the image name after the prefix cannot have numbers. For example: `'Image_66abc2xyx.gif'` is not allowed because the filename after the prefix has a number, in this case the number "2". Again, if you wish to use a different filename format then you can edit the regular expression pattern in the settings page.
     30Example Image Name: `'api66.jpg', 'api66a.jpeg', 'api66_two.gif', 'api66something'`, etc. Note: When posting multiple images to the same post by naming them with the same 'apiNNN' prefix. Avoid numbers immediately after the POSTID. For example: `'api662.gif'` will not work if the ID of the POST is 66; instead name it something like `'api66image2.gif'`. Again, if you wish to use a different filename format then you can edit the regular expression pattern in the settings page.
    3131
    3232Demo: [Dash of Salt & A Pinch of Love](http://sethulakshmi.karunanidhi.com/)
     
    83831. Click Auto Post Images (API) Settings
    8484
    85 = I want to name the images something other than Image_POSTID ? =
     85= I want to name the images something other than apiPOSTID ? =
    8686
    8787Sure. All you have to do is change the regular expression "**Image search Regular Expression?**". Just make sure it has __POSTID__ somewhere in the expression so that the plugin knows which images are attached to which post.
     
    113113== Changelog ==
    114114
     115= 2.3 =
     116* On Tuesday, December 1, 2009
     117* Added settings page options that will allow users to apply custom CSS classes to the image container, images, and control thumbnail width
     118* Updated default regular expressions
     119* Added "Maintenance" functions to clean-up thumbnails and force renaming of all images for search engine optimization
     120* Removed all inline style code for the admin screen and moved it into an admin-page only css file
     121
    115122= 2.2 =
    116 * On
     123* On 12:46:43 AM, Friday, September 18, 2009
    117124* Added SEO support for images. When enabled the images will renamed using the post title
    118125
Note: See TracChangeset for help on using the changeset viewer.