Plugin Directory

Changeset 1546144


Ignore:
Timestamp:
12/05/2016 10:56:15 PM (9 years ago)
Author:
3UU
Message:

add date of static files; add autoupdate of startpage; fix subdir

Location:
flexistatic
Files:
2 edited
6 copied

Legend:

Unmodified
Added
Removed
  • flexistatic/tags/1.0.4/flexistatic.php

    r1545276 r1546144  
    55 * Description:  Make real static posts flexible.
    66 * Author: 3UU
    7  * Version: 1.0.3
     7 * Version: 1.0.4
    88 * Author URI: http://datenverwurstungszentrale.com
    99 * License: MIT
     
    107107      echo "<p><form style='display:inline!important;' action='".$_SERVER['PHP_SELF']."?page=flexistatic/flexistatic.php' method='POST'>";
    108108      echo "<input type='hidden' name='static3uu_post_ID' value='0'><input type='hidden' name='static3uu_startID' value='$static3uu_startID'>
    109       <input type='hidden' name='static3uu_act' value='static3UU_proc_remove_static'><input type='submit' style='background-color: #ff0000;' value='".__('remove static','flexistatic')."'></form>";
     109      <input type='hidden' name='static3uu_act' value='static3UU_proc_remove_static'><input type='submit' style='background-color: #ff0000;' value='".__('remove static','flexistatic')."'></form> ";
     110      echo date("Y-m-d H:i:s", filemtime($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_site_url()).'/index.html'));
    110111      echo " ". __('Homepage (this will remove the file','flexistatic'). "<code><a target='_blank' href='".get_site_url()."'>".get_site_url()."</a>/<b>index.html</b></code> )</p>";
    111112      // some plugins with dirty hooks to the /index.php of WP instead of the plugin files will not work
     
    122123  // all list posts/pages
    123124  echo "<h2>".__('Make single posts static.','flexistatic')."</h2>";
    124   // retrieve all URLs
     125  // alle Seiten-Urls holen
    125126  $posts = new WP_Query('post_type=any&posts_per_page=-1');
    126127  $posts = $posts->posts;
     
    160161
    161162    // draw the buttons
    162     $status = is_file($_SERVER['DOCUMENT_ROOT'].$permalink) ? 'static' : 'dynamic';
     163    if($post->post_type =='post') $fsfile = $_SERVER['DOCUMENT_ROOT'].$permalink;
     164    if($post->post_type =='page') $fsfile = $_SERVER['DOCUMENT_ROOT'].$permalink.'/index.html';
     165    $status = is_file($fsfile) ? 'static' : 'dynamic';
     166   
    163167    if($status=='dynamic'){
    164168      echo "<form style='display:inline!important;' action='".$_SERVER['PHP_SELF']."?page=flexistatic/flexistatic.php' method='POST'>";
     
    168172      echo "<form style='display:inline!important;' action='".$_SERVER['PHP_SELF']."?page=flexistatic/flexistatic.php' method='POST'>";
    169173      echo "$i<input type='hidden' name='static3uu_post_ID' value='". sanitize_html_class($post->ID) ."'><input type='hidden' name='static3uu_startID' value='$static3uu_startID'>
    170             <input type='hidden' name='static3uu_act' value='static3UU_proc_remove_static'><input type='submit' style='background-color: #ff0000;' value='".__('remove static','flexistatic')."'></form>";
     174            <input type='hidden' name='static3uu_act' value='static3UU_proc_remove_static'><input type='submit' style='background-color: #ff0000;' value='".__('remove static','flexistatic')."'></form> ";
     175      echo date("Y-m-d H:i:s", filemtime($fsfile));
    171176    }
    172     echo "$post->post_type <a target='_blank' href='$permalink'>". esc_html( $post->post_title) ."</a> $permalink <br>";
     177    echo " $post->post_type <a target='_blank' href='$permalink'>". esc_html( $post->post_title) ."</a> $permalink <br>";
    173178  }
    174179 
     
    178183
    179184function static3UU_proc_make_static($static3uu_post_ID){
    180 
    181185    // make sure we deal with an int
    182186    if( !(intval($static3uu_post_ID) >= '0') ) die('something is really wrong');
     
    184188    $webfile=($static3uu_post_ID == '0') ? get_site_url() : get_permalink($static3uu_post_ID);
    185189    $content=file_get_contents($webfile.'?ModPagespeed=off');
     190
     191    // the blog startpage   
     192    if($static3uu_post_ID == '0')             $fsfile = $_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_site_url()).'/index.html';
     193    // pages
     194    elseif(get_post_type($static3uu_post_ID)=='page') $fsfile=$_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_permalink($static3uu_post_ID).'/index.html');
     195    // posts
     196    elseif(get_post_type($static3uu_post_ID)=='post') $fsfile = $_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_permalink($static3uu_post_ID));
     197    // anything else is not supported
     198    else return 'something goes wrong: unknown content type';
    186199   
    187     $fsfile =($static3uu_post_ID == '0') ? $_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_site_url()).'/index.html' : $_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_permalink($static3uu_post_ID));
    188 
    189200    // Falls das Unterverzeichnis noch nicht existiert, legen wir es an
    190201    if( !is_dir( dirname($fsfile) ) ) mkdir(dirname($fsfile), 0755, true);
     
    233244        }
    234245    }
     246    // if we have updated a post/page perhaps we must update the blog startpage too
     247    // rtzTodo: this is workarround until we do a implementition at the editor pages and make a hook on save action
     248    if(($static3uu_post_ID != '0') && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_site_url()).'/index.html')) static3UU_proc_update_static('0');
    235249}
    236250
    237251function static3UU_proc_remove_static($static3uu_post_ID){
    238  
    239252  // make sure we deal with an int
    240253  // 0 is internal used as sign for the blog start page because posts will start at 1
     
    244257  if(wp_is_post_revision($static3uu_post_ID)) { global $post; $static3uu_post_ID=$post->ID; }
    245258
    246     $fsfile=$_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_permalink($static3uu_post_ID));
    247     // the blog page has no permalink format. So we use index.html and hope that it has hiegher priority than index.php
     259    // the blog page has no permalink format. So we use index.html and hope that it has higher priority than index.php
    248260    // rtzTodo: make an admin option to define the name of the index.html
    249     if($static3uu_post_ID == '0') $fsfile=$_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_site_url()).'/index.html';
    250     // look up the URI
    251     else $fsfile=$_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_permalink($static3uu_post_ID));
     261    // blog page
     262    if($static3uu_post_ID == '0')           $fsfile=$_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_site_url()).'/index.html';
     263    // page
     264    elseif(get_post_type($static3uu_post_ID)=='page')   $fsfile=$_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_permalink($static3uu_post_ID).'/index.html');
     265    // post
     266    elseif(get_post_type($static3uu_post_ID)=='post')    $fsfile=$_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_permalink($static3uu_post_ID));
    252267
    253268    // check that the static file exists. Than read it...
     
    261276    // However we should at least check that the dir is empty!
    262277    if(count(scandir(dirname($fsfile)))=='2') rmdir(dirname($fsfile));
    263 }
    264 
    265 #function static3UU_proc_update_static($static3uu_post_ID){
    266 #  // update only needed, if static content exists
    267 #  if(file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_permalink($static3uu_post_ID)))){
    268 #    static3UU_proc_remove_static($static3uu_post_ID);
    269 #    // perhaps we have a (now outdated) static start page too
    270 #    if( file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_site_url()).'/index.html') ){
    271 #      static3UU_proc_remove_static('0');
    272 #    } static3UU_proc_make_static('0');
    273 #  } static3UU_proc_make_static($static3uu_post_ID);
    274 #}
     278    // if we have updated a post/page perhaps we must update the blog startpage too
     279    // rtzTodo: this is workarround until we do a implementition at the editor pages and make a hook on save action
     280    if(($static3uu_post_ID != '0') && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_site_url()).'/index.html')) static3UU_proc_update_static('0');
     281}
     282
     283function static3UU_proc_update_static($static3uu_post_ID){
     284   static3UU_proc_remove_static($static3uu_post_ID);
     285   static3UU_proc_make_static($static3uu_post_ID);
     286}
    275287
    276288# only a warning on edit. prehaps later on auto delete/create
  • flexistatic/tags/1.0.4/readme.txt

    r1545276 r1546144  
    44Requires at least: 4.4
    55Tested up to: 4.6.1
    6 Stable tag: 1.0.3
     6Stable tag: 1.0.4
    77License: MIT
    88License URI: http://opensource.org/licenses/mit
     
    100100== Changelog ==
    101101
     102= 1.0.4 =
     103- show creation date of the static content
     104- added autoupdate of a static startpage on any make/remove of static
     105  content. This is a workarround for people how forget to recreate the
     106  static blogpage on new/updated posts/pages.
     107- bugfix: correct find real localtion of virtual subdirs
     108
    102109= 1.0.3 =
    103110- Bugfix: DOCUMENT_ROOT != blog_root; dont use get_home_path() because of
  • flexistatic/trunk/flexistatic.php

    r1545276 r1546144  
    55 * Description:  Make real static posts flexible.
    66 * Author: 3UU
    7  * Version: 1.0.3
     7 * Version: 1.0.4
    88 * Author URI: http://datenverwurstungszentrale.com
    99 * License: MIT
     
    107107      echo "<p><form style='display:inline!important;' action='".$_SERVER['PHP_SELF']."?page=flexistatic/flexistatic.php' method='POST'>";
    108108      echo "<input type='hidden' name='static3uu_post_ID' value='0'><input type='hidden' name='static3uu_startID' value='$static3uu_startID'>
    109       <input type='hidden' name='static3uu_act' value='static3UU_proc_remove_static'><input type='submit' style='background-color: #ff0000;' value='".__('remove static','flexistatic')."'></form>";
     109      <input type='hidden' name='static3uu_act' value='static3UU_proc_remove_static'><input type='submit' style='background-color: #ff0000;' value='".__('remove static','flexistatic')."'></form> ";
     110      echo date("Y-m-d H:i:s", filemtime($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_site_url()).'/index.html'));
    110111      echo " ". __('Homepage (this will remove the file','flexistatic'). "<code><a target='_blank' href='".get_site_url()."'>".get_site_url()."</a>/<b>index.html</b></code> )</p>";
    111112      // some plugins with dirty hooks to the /index.php of WP instead of the plugin files will not work
     
    122123  // all list posts/pages
    123124  echo "<h2>".__('Make single posts static.','flexistatic')."</h2>";
    124   // retrieve all URLs
     125  // alle Seiten-Urls holen
    125126  $posts = new WP_Query('post_type=any&posts_per_page=-1');
    126127  $posts = $posts->posts;
     
    160161
    161162    // draw the buttons
    162     $status = is_file($_SERVER['DOCUMENT_ROOT'].$permalink) ? 'static' : 'dynamic';
     163    if($post->post_type =='post') $fsfile = $_SERVER['DOCUMENT_ROOT'].$permalink;
     164    if($post->post_type =='page') $fsfile = $_SERVER['DOCUMENT_ROOT'].$permalink.'/index.html';
     165    $status = is_file($fsfile) ? 'static' : 'dynamic';
     166   
    163167    if($status=='dynamic'){
    164168      echo "<form style='display:inline!important;' action='".$_SERVER['PHP_SELF']."?page=flexistatic/flexistatic.php' method='POST'>";
     
    168172      echo "<form style='display:inline!important;' action='".$_SERVER['PHP_SELF']."?page=flexistatic/flexistatic.php' method='POST'>";
    169173      echo "$i<input type='hidden' name='static3uu_post_ID' value='". sanitize_html_class($post->ID) ."'><input type='hidden' name='static3uu_startID' value='$static3uu_startID'>
    170             <input type='hidden' name='static3uu_act' value='static3UU_proc_remove_static'><input type='submit' style='background-color: #ff0000;' value='".__('remove static','flexistatic')."'></form>";
     174            <input type='hidden' name='static3uu_act' value='static3UU_proc_remove_static'><input type='submit' style='background-color: #ff0000;' value='".__('remove static','flexistatic')."'></form> ";
     175      echo date("Y-m-d H:i:s", filemtime($fsfile));
    171176    }
    172     echo "$post->post_type <a target='_blank' href='$permalink'>". esc_html( $post->post_title) ."</a> $permalink <br>";
     177    echo " $post->post_type <a target='_blank' href='$permalink'>". esc_html( $post->post_title) ."</a> $permalink <br>";
    173178  }
    174179 
     
    178183
    179184function static3UU_proc_make_static($static3uu_post_ID){
    180 
    181185    // make sure we deal with an int
    182186    if( !(intval($static3uu_post_ID) >= '0') ) die('something is really wrong');
     
    184188    $webfile=($static3uu_post_ID == '0') ? get_site_url() : get_permalink($static3uu_post_ID);
    185189    $content=file_get_contents($webfile.'?ModPagespeed=off');
     190
     191    // the blog startpage   
     192    if($static3uu_post_ID == '0')             $fsfile = $_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_site_url()).'/index.html';
     193    // pages
     194    elseif(get_post_type($static3uu_post_ID)=='page') $fsfile=$_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_permalink($static3uu_post_ID).'/index.html');
     195    // posts
     196    elseif(get_post_type($static3uu_post_ID)=='post') $fsfile = $_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_permalink($static3uu_post_ID));
     197    // anything else is not supported
     198    else return 'something goes wrong: unknown content type';
    186199   
    187     $fsfile =($static3uu_post_ID == '0') ? $_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_site_url()).'/index.html' : $_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_permalink($static3uu_post_ID));
    188 
    189200    // Falls das Unterverzeichnis noch nicht existiert, legen wir es an
    190201    if( !is_dir( dirname($fsfile) ) ) mkdir(dirname($fsfile), 0755, true);
     
    233244        }
    234245    }
     246    // if we have updated a post/page perhaps we must update the blog startpage too
     247    // rtzTodo: this is workarround until we do a implementition at the editor pages and make a hook on save action
     248    if(($static3uu_post_ID != '0') && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_site_url()).'/index.html')) static3UU_proc_update_static('0');
    235249}
    236250
    237251function static3UU_proc_remove_static($static3uu_post_ID){
    238  
    239252  // make sure we deal with an int
    240253  // 0 is internal used as sign for the blog start page because posts will start at 1
     
    244257  if(wp_is_post_revision($static3uu_post_ID)) { global $post; $static3uu_post_ID=$post->ID; }
    245258
    246     $fsfile=$_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_permalink($static3uu_post_ID));
    247     // the blog page has no permalink format. So we use index.html and hope that it has hiegher priority than index.php
     259    // the blog page has no permalink format. So we use index.html and hope that it has higher priority than index.php
    248260    // rtzTodo: make an admin option to define the name of the index.html
    249     if($static3uu_post_ID == '0') $fsfile=$_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_site_url()).'/index.html';
    250     // look up the URI
    251     else $fsfile=$_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_permalink($static3uu_post_ID));
     261    // blog page
     262    if($static3uu_post_ID == '0')           $fsfile=$_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_site_url()).'/index.html';
     263    // page
     264    elseif(get_post_type($static3uu_post_ID)=='page')   $fsfile=$_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_permalink($static3uu_post_ID).'/index.html');
     265    // post
     266    elseif(get_post_type($static3uu_post_ID)=='post')    $fsfile=$_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_permalink($static3uu_post_ID));
    252267
    253268    // check that the static file exists. Than read it...
     
    261276    // However we should at least check that the dir is empty!
    262277    if(count(scandir(dirname($fsfile)))=='2') rmdir(dirname($fsfile));
    263 }
    264 
    265 #function static3UU_proc_update_static($static3uu_post_ID){
    266 #  // update only needed, if static content exists
    267 #  if(file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_permalink($static3uu_post_ID)))){
    268 #    static3UU_proc_remove_static($static3uu_post_ID);
    269 #    // perhaps we have a (now outdated) static start page too
    270 #    if( file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_site_url()).'/index.html') ){
    271 #      static3UU_proc_remove_static('0');
    272 #    } static3UU_proc_make_static('0');
    273 #  } static3UU_proc_make_static($static3uu_post_ID);
    274 #}
     278    // if we have updated a post/page perhaps we must update the blog startpage too
     279    // rtzTodo: this is workarround until we do a implementition at the editor pages and make a hook on save action
     280    if(($static3uu_post_ID != '0') && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_site_url()).'/index.html')) static3UU_proc_update_static('0');
     281}
     282
     283function static3UU_proc_update_static($static3uu_post_ID){
     284   static3UU_proc_remove_static($static3uu_post_ID);
     285   static3UU_proc_make_static($static3uu_post_ID);
     286}
    275287
    276288# only a warning on edit. prehaps later on auto delete/create
  • flexistatic/trunk/readme.txt

    r1545276 r1546144  
    44Requires at least: 4.4
    55Tested up to: 4.6.1
    6 Stable tag: 1.0.3
     6Stable tag: 1.0.4
    77License: MIT
    88License URI: http://opensource.org/licenses/mit
     
    100100== Changelog ==
    101101
     102= 1.0.4 =
     103- show creation date of the static content
     104- added autoupdate of a static startpage on any make/remove of static
     105  content. This is a workarround for people how forget to recreate the
     106  static blogpage on new/updated posts/pages.
     107- bugfix: correct find real localtion of virtual subdirs
     108
    102109= 1.0.3 =
    103110- Bugfix: DOCUMENT_ROOT != blog_root; dont use get_home_path() because of
Note: See TracChangeset for help on using the changeset viewer.