Propagandist
This script in PHP 5 allows you to copy an ID tag from an HTML page to all other HTML pages in the same directory and its subdirectories.
It can be used, in particular, to insert Analytics code into all pages of a site built from local files.
If the site is managed by CMS, then this script is useless if code is placed in the template for distribution, for example, in a footer or sidebar. If you want to put it in the body of articles, then SQL queries should be used to distribute it, depending on the tables specific to CMS, this is beyond its scope.
Restriction
Due to an error in PHP 5.2.8, copying is disabled on pages containing PHP code.
When a PHP script is contained on a web page, and this script contains a comparison with the code ">" (more), the loadHTMLile function (used by Propagator) replaces the final script code "?>" with the string "? & gt;."
Obviously, this is a bug in PHP and you will have to wait for a later version to fix it.
At this time, you can use the -p option to support files containing PHP code.
To test the function, you can use the php-test.php script in the archive.
Use of script
Works on the command line, on Windows, Linux and other systems that support PHP. PHP 5 must be installed.
- You must have a local copy of the site. The script does not work remotely.
- Back up this copy.
- Insert code for distribution into the source file, usually index.html.
- Give the tag containing this code an ID.
- Select a location to copy code to pages (see below).
- Run Script.
- Checking for modified files on sample pages.
- If the page code is generated incorrectly, the PHP DOM functions will not work, the code will have to be copied manually.
The script can be used infinitely many times on the same site. Code is added to pages for the first time, and then updated the next time the source page changes.
You can also erase inserted codes with the appropriate command.
Orders
The general syntax of the command is as follows.
php propag.php [option] ID fichiersource
ID - the name of the tag ID containing the code to copy.
Example:
<div id="demo"> <script .... </script> </div>
php propag.php demo fichiersource
The source file is the path and name of the file that contains the code to copy. Usually index.html .
You can simply type php propag.php to show the version and parameters.
Options
You can combine variants after the sign - for example: -hbi
-h copy code to <head> part of pages. By default, it is copied to <body>, at the end.
-b copy the code to the beginning of the content of the head or body tag. By default, it is appended to the end.
-i limited to directory only, do not change anything in subdirectories.
-d clear code on all pages where it was inserted.
-v displays details of operations.
-q show nothing (except error messages).
-0.. 9 specifies the minimum file size to consider. The digit is multiplied by 1024. The default is 1, so files smaller than 1024 bytes are ignored.
-test only to see what happens is used in conjunction with -v in the form of -tv. The files will not be modified.
The -p option should not be used with PHP 5.2.8 and all versions that have the loadHTMLile method error described above.
Loading
The script is uploaded to the archive in ZIP format .
PHP 5 required.
GPL 3.0 licensing.
Versions
- 1.0 - January 22, 2009 - First version