Plugin Directory

Changeset 2440250


Ignore:
Timestamp:
12/16/2020 12:21:27 AM (5 years ago)
Author:
3UU
Message:

if WP is installed within a subdir now add subdir in the hints

Location:
flexistatic
Files:
4 edited
1 copied

Legend:

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

    r1842014 r2440250  
    55 * Description:  Make real static posts flexible.
    66 * Author: 3UU
    7  * Version: 2.0.1
     7 * Version: 2.1.1
    88 * Author URI: http://datenverwurstungszentrale.com
    99 * License: MIT
     
    1616- log all static so that they can get unlink also if structure of permalinks changes
    1717- speichern an anderem Ort / auf anderem Server (trigger publish)
    18 - make all / remove all
    1918*/
    2019
     
    2726  // sanitoeter
    2827  $static3uu_search     = isset($_REQUEST['static3uu_search'])                                                    ? sanitize_text_field($_REQUEST['static3uu_search']) : ''; 
    29   $static3uu_post_ID    = isset($_REQUEST['static3uu_post_ID']) && intval($_REQUEST['static3uu_post_ID']) >= '0'  ? intval($_REQUEST['static3uu_post_ID']) : '';
    30   $static3uu_startID    = isset($_REQUEST['static3uu_startID']) && intval($_REQUEST['static3uu_startID']) >= '0'  ? intval($_REQUEST['static3uu_startID']) :  '';
     28  $static3uu_post_ID    = isset($_REQUEST['static3uu_post_ID']) && intval($_REQUEST['static3uu_post_ID']) >= '0'  ? intval($_REQUEST['static3uu_post_ID']) : '0';
     29  $static3uu_startID    = isset($_REQUEST['static3uu_startID']) && intval($_REQUEST['static3uu_startID']) >= '0'  ? intval($_REQUEST['static3uu_startID']) :  '0';
    3130
    3231  // create/remove static content
    3332  $static3uu_act        = isset($_REQUEST['static3uu_act'])                                                       ? sanitize_text_field($_REQUEST['static3uu_act'])    : '';
    34   if($static3uu_act=='static3UU_proc_make_static')   static3UU_proc_make_static($static3uu_post_ID);
    35   if($static3uu_act=='static3UU_proc_remove_static') static3UU_proc_remove_static($static3uu_post_ID);
     33  if($static3uu_act=='static3UU_proc_make_static')      static3UU_proc_make_static($static3uu_post_ID);
     34  if($static3uu_act=='static3UU_proc_remove_static')    static3UU_proc_remove_static($static3uu_post_ID);
     35  if($static3uu_act=='static3UU_proc_make_all_static')  static3UU_proc_make_all_static();
     36  if($static3uu_act=='static3UU_proc_remove_all_static')static3UU_proc_remove_all_static();
    3637}
    3738add_action( 'admin_init', 'static3UU_init' );
     
    5758         <hr>
    5859<?
    59 #    global $wp_rewrite;
    60 #    $rtz=$wp_rewrite->mod_rewrite_rules();
    61 #    echo "<pre>";
    62 #    var_dump($rtz);
    63 #    echo "</pre>";
    64 #    #$wp_rewrite->flush_rules();               
    65 
    6660        // search a post
    6761        global $static3uu_search;
     
    9892
    9993  global $static3uu_startID;
    100  
     94  if(empty($static3uu_startID))$static3uu_startID='0';
     95   
    10196  // start page static
    10297  echo "<h2>".__('Make the start page static.','flexistatic')."</h2>";
     
    122117      // if index.html get preference. E.g. the very usefull "Simple Custom CSS".
    123118      echo "<p>".__('Attention: Some more ore less usefull plugins do need direct requests to the <code>index.php</code> in the blog root folder. Therefor you should add','flexistatic')," ";
    124 $SUBDIR="FR/"; // rtzrtz: must end with an "/"
    125       echo "<pre>            # FlexiStatic
    126             # first make shure that we do not match
    127             # requests with dynamic parameters. Also
    128             # make sure that the webserver prefers
    129             # 'index.html' over directory listing
    130             RewriteEngine On
    131 
    132             RewriteBase /".$SUBDIR."
    133             RewriteCond %{REQUEST_URI} (index|%{HTTP_HOST})\.html$
    134             RewriteCond %{QUERY_STRING} !^$
    135             RewriteRule . /index.php [L]</pre>";
    136       echo "<pre>            ### only needed for WPMU ###
    137             RewriteCond %{REQUEST_URI} ^/".$SUBDIR."$
    138             RewriteCond %{QUERY_STRING} ^$
    139             RewriteCond %{DOCUMENT_ROOT}/".$SUBDIR."%{HTTP_HOST}.html -f
    140             RewriteRule .* %{HTTP_HOST}.html [L]
    141             # END FlexiStatic
    142       </pre>";
     119
     120#    global $wp_rewrite;
     121#    $rtz=$wp_rewrite->mod_rewrite_rules();
     122#    echo "<pre>";
     123#    var_dump($rtz);
     124#    echo "</pre>";
     125#    #$wp_rewrite->flush_rules();
     126
     127$SUBDIR=wp_make_link_relative(get_site_url())."/"; # / and only 1 is needed
     128
     129      echo "<pre>      # FlexiStatic
     130           # make sure that the webserver prefers
     131           # index.html over directory listing
     132
     133           # with dynamic content
     134           RewriteEngine On
     135           RewriteBase ".$SUBDIR."
     136           RewriteRule index\.html$ - [L]
     137           RewriteCond %{REQUEST_URI} (index|%{HTTP_HOST})\.html$
     138           RewriteCond %{QUERY_STRING} !^$
     139           RewriteRule . /index.php? [L]</pre>";
     140      echo "<pre>           ### use HTTP_HOST to enable WPMU ###
     141           # only needed for the blog page that is
     142           # not index.hml like used in subdirs
     143           RewriteBase ".$SUBDIR."
     144           RewriteRule index\.html$ - [L]
     145           RewriteRule %{HTTP_HOST}\.html - [L]
     146           RewriteCond %{REQUEST_FILENAME} /$
     147           RewriteCond %{REQUEST_FILENAME} !.*wp-admin.*$
     148           RewriteCond %{QUERY_STRING} !^$
     149           RewriteCond %{DOCUMENT_ROOT}/%{HTTP_HOST}.html -f
     150           RewriteRule .* %{HTTP_HOST}.html [L]
     151           # END FlexiStatic</pre>";
    143152     
    144153      printf ( __("to your <code>%s/.htaccess</code> file.",'flexistatic'), $_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_site_url()) );
     
    148157  // all list posts/pages
    149158  echo "<h2>".__('Make single posts static.','flexistatic')."</h2>";
    150   // alle Seiten-Urls holen
     159  // get all posts/pages
    151160  $posts = new WP_Query('post_type=any&posts_per_page=-1');
    152161  $posts = $posts->posts;
     
    204213 
    205214  echo "<hr> $nav <hr>";
    206 }
    207 
     215 
     216  echo "ALL => ";
     217  echo " posts/pages/cats <form style='display:inline!important;' action='".$_SERVER['PHP_SELF']."?page=flexistatic/flexistatic.php' method='POST'>";
     218  echo "<input type='hidden' name='static3uu_startID' value='$static3uu_startID'>
     219        <input type='hidden' name='static3uu_act' value='static3UU_proc_remove_all_static'><input type='submit' style='background-color: #ff0000;' value='".__('remove static','flexistatic')."'></form> ";
     220  echo "<form style='display:inline!important;' action='".$_SERVER['PHP_SELF']."?page=flexistatic/flexistatic.php' method='POST'>";
     221  echo "<input type='hidden' name='static3uu_startID' value='$static3uu_startID'>
     222        <input type='hidden' name='static3uu_act' value='static3UU_proc_make_all_static'><input type='submit' value='".__('make static','flexistatic')."'></form> Content";
     223                   
     224}
    208225
    209226function static3UU_proc_make_static($static3uu_post_ID){
     
    291308    elseif(get_post_type($static3uu_post_ID)=='post')    $fsfile=$_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_permalink($static3uu_post_ID));
    292309
    293     // check that the static file exists. Than read it...
    294     if(is_file($fsfile)) $content=file_get_contents($fsfile);
    295     // ...to make sure that we only delete files that this plugin has written!
    296     if( strstr($content,"static3UU|$static3uu_post_ID") || strstr($content,"static3UU|autocreate") ) unlink($fsfile);
    297     // clean up empty subdirs
    298     // rtzTodo: Think about that sombody could have the stupid idea to set permalinks to the temp-dir
    299     // auf this vhost. That could become an empty dir! But how to avoid this problem without leaving
    300     // perhaps tousends of emty dirs?
    301     // However we should at least check that the dir is empty!
    302     if(count(scandir(dirname($fsfile)))=='2') rmdir(dirname($fsfile));
     310    // check that the static file exists.
     311    if(is_file($fsfile)){
     312      // Than read it...
     313      $content=file_get_contents($fsfile);
     314      // ...and  make sure that we only delete files that this plugin has written!
     315      if( strstr($content,"static3UU|$static3uu_post_ID") || strstr($content,"static3UU|autocreate") ) unlink($fsfile);
     316      // clean up empty subdirs
     317      // rtzTodo: Think about that sombody could have the stupid idea to set permalinks to the temp-dir
     318      // auf this vhost. That could become an empty dir! But how to avoid this problem without leaving
     319      // perhaps tousends of empty dirs?
     320      // However we should at least check that the dir is empty!
     321      if(count(scandir(dirname($fsfile)))=='2') rmdir(dirname($fsfile));
     322    }
    303323    // if we have updated a post/page perhaps we must update the blog startpage too
    304324    // rtzTodo: this is workarround until we do a implementition at the editor pages and make a hook on save action
     
    307327
    308328function static3UU_proc_update_static($static3uu_post_ID){
    309    static3UU_proc_remove_static($static3uu_post_ID);
    310    static3UU_proc_make_static($static3uu_post_ID);
     329  static3UU_proc_remove_static($static3uu_post_ID);
     330  static3UU_proc_make_static($static3uu_post_ID);
    311331}
    312332
     
    316336  if( file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_permalink($static3uu_post_ID) ) ) ){
    317337    echo "<h2>WARNING: A static version of this post exists. Please remove it first!!! You must create the static site (and perhaps a static blog start page) again after editing!</h2>";
     338  }
     339}
     340
     341function static3UU_proc_make_all_static(){
     342  // get all posts/pages
     343  $posts = new WP_Query('post_type=any&posts_per_page=-1');
     344  $posts = $posts->posts;
     345
     346  foreach($posts as $post) {
     347#    echo "working on ID ".$post->ID." | ".$post->post_name."<br>";
     348#    flush();
     349#    ob_flush();
     350    // only on posts/pages
     351    if( ($post->post_type!='post') && ($post->post_type!='page') )continue;
     352    static3UU_proc_update_static(intval($post->ID));
     353  }
     354}
     355
     356function static3UU_proc_remove_all_static(){
     357  // get all posts/pages
     358  $posts = new WP_Query('post_type=any&posts_per_page=-1');
     359  $posts = $posts->posts;
     360       
     361  foreach($posts as $post) {
     362#    echo "working on ID ".$post->ID." | ".$post->post_name."<br>";
     363#    flush();
     364#    ob_flush();
     365    // only on posts/pages
     366    if( ($post->post_type!='post') && ($post->post_type!='page') )continue;
     367    static3UU_proc_remove_static(intval($post->ID));
    318368  }
    319369}
     
    337387}
    338388add_action( 'add_meta_boxes_post', 'add_static3uu_meta_boxes' );
     389
     390
    339391
    340392#function static3UUadmin_sub_page(){
  • flexistatic/tags/2.1.0/readme.txt

    r1842020 r2440250  
    33Tags: static page, performance
    44Requires at least: 4.4
    5 Tested up to: 4.9.4
    6 Stable tag: 2.0.2
     5Tested up to: 5.6
     6Stable tag: 2.1.0
    77License: MIT
    88License URI: http://opensource.org/licenses/mit
     
    9595== Changelog ==
    9696
     97= 2.1.0 =
     98- works also with parameters (like needed for client side JS) now
     99- if WP is installed within a subdir now add subdir in the hints
     100
    97101= 2.0.2 =
    98102- optimize RewriteRules to work with installations in subdirs
  • flexistatic/trunk/flexistatic.php

    r1842014 r2440250  
    55 * Description:  Make real static posts flexible.
    66 * Author: 3UU
    7  * Version: 2.0.1
     7 * Version: 2.1.1
    88 * Author URI: http://datenverwurstungszentrale.com
    99 * License: MIT
     
    1616- log all static so that they can get unlink also if structure of permalinks changes
    1717- speichern an anderem Ort / auf anderem Server (trigger publish)
    18 - make all / remove all
    1918*/
    2019
     
    2726  // sanitoeter
    2827  $static3uu_search     = isset($_REQUEST['static3uu_search'])                                                    ? sanitize_text_field($_REQUEST['static3uu_search']) : ''; 
    29   $static3uu_post_ID    = isset($_REQUEST['static3uu_post_ID']) && intval($_REQUEST['static3uu_post_ID']) >= '0'  ? intval($_REQUEST['static3uu_post_ID']) : '';
    30   $static3uu_startID    = isset($_REQUEST['static3uu_startID']) && intval($_REQUEST['static3uu_startID']) >= '0'  ? intval($_REQUEST['static3uu_startID']) :  '';
     28  $static3uu_post_ID    = isset($_REQUEST['static3uu_post_ID']) && intval($_REQUEST['static3uu_post_ID']) >= '0'  ? intval($_REQUEST['static3uu_post_ID']) : '0';
     29  $static3uu_startID    = isset($_REQUEST['static3uu_startID']) && intval($_REQUEST['static3uu_startID']) >= '0'  ? intval($_REQUEST['static3uu_startID']) :  '0';
    3130
    3231  // create/remove static content
    3332  $static3uu_act        = isset($_REQUEST['static3uu_act'])                                                       ? sanitize_text_field($_REQUEST['static3uu_act'])    : '';
    34   if($static3uu_act=='static3UU_proc_make_static')   static3UU_proc_make_static($static3uu_post_ID);
    35   if($static3uu_act=='static3UU_proc_remove_static') static3UU_proc_remove_static($static3uu_post_ID);
     33  if($static3uu_act=='static3UU_proc_make_static')      static3UU_proc_make_static($static3uu_post_ID);
     34  if($static3uu_act=='static3UU_proc_remove_static')    static3UU_proc_remove_static($static3uu_post_ID);
     35  if($static3uu_act=='static3UU_proc_make_all_static')  static3UU_proc_make_all_static();
     36  if($static3uu_act=='static3UU_proc_remove_all_static')static3UU_proc_remove_all_static();
    3637}
    3738add_action( 'admin_init', 'static3UU_init' );
     
    5758         <hr>
    5859<?
    59 #    global $wp_rewrite;
    60 #    $rtz=$wp_rewrite->mod_rewrite_rules();
    61 #    echo "<pre>";
    62 #    var_dump($rtz);
    63 #    echo "</pre>";
    64 #    #$wp_rewrite->flush_rules();               
    65 
    6660        // search a post
    6761        global $static3uu_search;
     
    9892
    9993  global $static3uu_startID;
    100  
     94  if(empty($static3uu_startID))$static3uu_startID='0';
     95   
    10196  // start page static
    10297  echo "<h2>".__('Make the start page static.','flexistatic')."</h2>";
     
    122117      // if index.html get preference. E.g. the very usefull "Simple Custom CSS".
    123118      echo "<p>".__('Attention: Some more ore less usefull plugins do need direct requests to the <code>index.php</code> in the blog root folder. Therefor you should add','flexistatic')," ";
    124 $SUBDIR="FR/"; // rtzrtz: must end with an "/"
    125       echo "<pre>            # FlexiStatic
    126             # first make shure that we do not match
    127             # requests with dynamic parameters. Also
    128             # make sure that the webserver prefers
    129             # 'index.html' over directory listing
    130             RewriteEngine On
    131 
    132             RewriteBase /".$SUBDIR."
    133             RewriteCond %{REQUEST_URI} (index|%{HTTP_HOST})\.html$
    134             RewriteCond %{QUERY_STRING} !^$
    135             RewriteRule . /index.php [L]</pre>";
    136       echo "<pre>            ### only needed for WPMU ###
    137             RewriteCond %{REQUEST_URI} ^/".$SUBDIR."$
    138             RewriteCond %{QUERY_STRING} ^$
    139             RewriteCond %{DOCUMENT_ROOT}/".$SUBDIR."%{HTTP_HOST}.html -f
    140             RewriteRule .* %{HTTP_HOST}.html [L]
    141             # END FlexiStatic
    142       </pre>";
     119
     120#    global $wp_rewrite;
     121#    $rtz=$wp_rewrite->mod_rewrite_rules();
     122#    echo "<pre>";
     123#    var_dump($rtz);
     124#    echo "</pre>";
     125#    #$wp_rewrite->flush_rules();
     126
     127$SUBDIR=wp_make_link_relative(get_site_url())."/"; # / and only 1 is needed
     128
     129      echo "<pre>      # FlexiStatic
     130           # make sure that the webserver prefers
     131           # index.html over directory listing
     132
     133           # with dynamic content
     134           RewriteEngine On
     135           RewriteBase ".$SUBDIR."
     136           RewriteRule index\.html$ - [L]
     137           RewriteCond %{REQUEST_URI} (index|%{HTTP_HOST})\.html$
     138           RewriteCond %{QUERY_STRING} !^$
     139           RewriteRule . /index.php? [L]</pre>";
     140      echo "<pre>           ### use HTTP_HOST to enable WPMU ###
     141           # only needed for the blog page that is
     142           # not index.hml like used in subdirs
     143           RewriteBase ".$SUBDIR."
     144           RewriteRule index\.html$ - [L]
     145           RewriteRule %{HTTP_HOST}\.html - [L]
     146           RewriteCond %{REQUEST_FILENAME} /$
     147           RewriteCond %{REQUEST_FILENAME} !.*wp-admin.*$
     148           RewriteCond %{QUERY_STRING} !^$
     149           RewriteCond %{DOCUMENT_ROOT}/%{HTTP_HOST}.html -f
     150           RewriteRule .* %{HTTP_HOST}.html [L]
     151           # END FlexiStatic</pre>";
    143152     
    144153      printf ( __("to your <code>%s/.htaccess</code> file.",'flexistatic'), $_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_site_url()) );
     
    148157  // all list posts/pages
    149158  echo "<h2>".__('Make single posts static.','flexistatic')."</h2>";
    150   // alle Seiten-Urls holen
     159  // get all posts/pages
    151160  $posts = new WP_Query('post_type=any&posts_per_page=-1');
    152161  $posts = $posts->posts;
     
    204213 
    205214  echo "<hr> $nav <hr>";
    206 }
    207 
     215 
     216  echo "ALL => ";
     217  echo " posts/pages/cats <form style='display:inline!important;' action='".$_SERVER['PHP_SELF']."?page=flexistatic/flexistatic.php' method='POST'>";
     218  echo "<input type='hidden' name='static3uu_startID' value='$static3uu_startID'>
     219        <input type='hidden' name='static3uu_act' value='static3UU_proc_remove_all_static'><input type='submit' style='background-color: #ff0000;' value='".__('remove static','flexistatic')."'></form> ";
     220  echo "<form style='display:inline!important;' action='".$_SERVER['PHP_SELF']."?page=flexistatic/flexistatic.php' method='POST'>";
     221  echo "<input type='hidden' name='static3uu_startID' value='$static3uu_startID'>
     222        <input type='hidden' name='static3uu_act' value='static3UU_proc_make_all_static'><input type='submit' value='".__('make static','flexistatic')."'></form> Content";
     223                   
     224}
    208225
    209226function static3UU_proc_make_static($static3uu_post_ID){
     
    291308    elseif(get_post_type($static3uu_post_ID)=='post')    $fsfile=$_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_permalink($static3uu_post_ID));
    292309
    293     // check that the static file exists. Than read it...
    294     if(is_file($fsfile)) $content=file_get_contents($fsfile);
    295     // ...to make sure that we only delete files that this plugin has written!
    296     if( strstr($content,"static3UU|$static3uu_post_ID") || strstr($content,"static3UU|autocreate") ) unlink($fsfile);
    297     // clean up empty subdirs
    298     // rtzTodo: Think about that sombody could have the stupid idea to set permalinks to the temp-dir
    299     // auf this vhost. That could become an empty dir! But how to avoid this problem without leaving
    300     // perhaps tousends of emty dirs?
    301     // However we should at least check that the dir is empty!
    302     if(count(scandir(dirname($fsfile)))=='2') rmdir(dirname($fsfile));
     310    // check that the static file exists.
     311    if(is_file($fsfile)){
     312      // Than read it...
     313      $content=file_get_contents($fsfile);
     314      // ...and  make sure that we only delete files that this plugin has written!
     315      if( strstr($content,"static3UU|$static3uu_post_ID") || strstr($content,"static3UU|autocreate") ) unlink($fsfile);
     316      // clean up empty subdirs
     317      // rtzTodo: Think about that sombody could have the stupid idea to set permalinks to the temp-dir
     318      // auf this vhost. That could become an empty dir! But how to avoid this problem without leaving
     319      // perhaps tousends of empty dirs?
     320      // However we should at least check that the dir is empty!
     321      if(count(scandir(dirname($fsfile)))=='2') rmdir(dirname($fsfile));
     322    }
    303323    // if we have updated a post/page perhaps we must update the blog startpage too
    304324    // rtzTodo: this is workarround until we do a implementition at the editor pages and make a hook on save action
     
    307327
    308328function static3UU_proc_update_static($static3uu_post_ID){
    309    static3UU_proc_remove_static($static3uu_post_ID);
    310    static3UU_proc_make_static($static3uu_post_ID);
     329  static3UU_proc_remove_static($static3uu_post_ID);
     330  static3UU_proc_make_static($static3uu_post_ID);
    311331}
    312332
     
    316336  if( file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative(get_permalink($static3uu_post_ID) ) ) ){
    317337    echo "<h2>WARNING: A static version of this post exists. Please remove it first!!! You must create the static site (and perhaps a static blog start page) again after editing!</h2>";
     338  }
     339}
     340
     341function static3UU_proc_make_all_static(){
     342  // get all posts/pages
     343  $posts = new WP_Query('post_type=any&posts_per_page=-1');
     344  $posts = $posts->posts;
     345
     346  foreach($posts as $post) {
     347#    echo "working on ID ".$post->ID." | ".$post->post_name."<br>";
     348#    flush();
     349#    ob_flush();
     350    // only on posts/pages
     351    if( ($post->post_type!='post') && ($post->post_type!='page') )continue;
     352    static3UU_proc_update_static(intval($post->ID));
     353  }
     354}
     355
     356function static3UU_proc_remove_all_static(){
     357  // get all posts/pages
     358  $posts = new WP_Query('post_type=any&posts_per_page=-1');
     359  $posts = $posts->posts;
     360       
     361  foreach($posts as $post) {
     362#    echo "working on ID ".$post->ID." | ".$post->post_name."<br>";
     363#    flush();
     364#    ob_flush();
     365    // only on posts/pages
     366    if( ($post->post_type!='post') && ($post->post_type!='page') )continue;
     367    static3UU_proc_remove_static(intval($post->ID));
    318368  }
    319369}
     
    337387}
    338388add_action( 'add_meta_boxes_post', 'add_static3uu_meta_boxes' );
     389
     390
    339391
    340392#function static3UUadmin_sub_page(){
  • flexistatic/trunk/readme.txt

    r1842020 r2440250  
    33Tags: static page, performance
    44Requires at least: 4.4
    5 Tested up to: 4.9.4
    6 Stable tag: 2.0.2
     5Tested up to: 5.6
     6Stable tag: 2.1.0
    77License: MIT
    88License URI: http://opensource.org/licenses/mit
     
    9595== Changelog ==
    9696
     97= 2.1.0 =
     98- works also with parameters (like needed for client side JS) now
     99- if WP is installed within a subdir now add subdir in the hints
     100
    97101= 2.0.2 =
    98102- optimize RewriteRules to work with installations in subdirs
Note: See TracChangeset for help on using the changeset viewer.