Changeset 14854
- Timestamp:
- May 8, 2012, 4:18:51 PM (12 years ago)
- Location:
- extensions/Prune_History
- Files:
-
- 1 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/Prune_History/admin/PH_admin.php
r14838 r14854 18 18 $page['global'] = array(); 19 19 $range = array(); 20 $dump_download = ''; 20 21 21 // +-----------------------------------------------------------------------+ 22 // | Getting plugin version | 23 // +-----------------------------------------------------------------------+ 22 23 // +-------------------------------------------------------------------+ 24 // | Get plugin version and name | 25 // +-------------------------------------------------------------------+ 24 26 $plugin = PHInfos(PH_PATH); 25 27 $version = $plugin['version']; … … 45 47 } 46 48 49 50 // +--------------------------------------------------------------------+ 51 // | Saving history tables | 52 // +--------------------------------------------------------------------+ 53 if (isset($_POST['save'])) 54 { 55 $dump_download = (isset($_POST['dump_download'])) ? 'true' : 'false'; 56 57 if(PH_dump($dump_download) and $dump_download == 'false') 58 { 59 array_push($page['infos'], l10n('PH_Dump_OK')); 60 } 61 else 62 { 63 array_push($page['errors'], l10n('PH_Dump_NOK')); 64 } 65 } 66 67 68 // +--------------------------------------------------------------------+ 69 // | Restoring backed up history tables | 70 // +--------------------------------------------------------------------+ 71 if (isset($_POST['restore'])) 72 { 73 $Backup_File = PH_PATH.'/include/backup/PH_Historybackup.sql'; 74 75 if (file_exists($Backup_File) and $file = file($Backup_File, FILE_IGNORE_NEW_LINES) and !empty($file)) 76 { 77 // Check backup file version 78 // ------------------------- 79 if ($file[0] == "-- ".$version." --") 80 { 81 $restore = PH_Restore_backup_file(); 82 if(empty($restore)) 83 { 84 array_push($page['infos'], l10n('PH_Restoration_OK')); 85 } 86 else 87 { 88 array_push($page['errors'], l10n('PH_Restoration_NOK')); 89 } 90 } 91 else array_push($page['errors'], l10n('PH_Bad_version_backup')); 92 } 93 else 94 { 95 array_push($page['errors'], l10n('PH_No_Backup_File')); 96 } 97 } 98 99 100 // +--------------------------------------------------------------------+ 101 // | Manual prune settings | 102 // +--------------------------------------------------------------------+ 47 103 $conf_PH = unserialize($conf['PruneHistory']); 48 104 … … 87 143 } 88 144 145 89 146 // +-----------------------------------------------------------------------+ 90 147 // | templates init | … … 104 161 'PH_NAME' => $name, 105 162 'PH_VERSION' => $version, 163 'PH_DUMP_DOWNLOAD' => $dump_download, 106 164 'PH_AUTOPRUNE_TRUE' => $conf_PH[1]=='true' ? 'checked="checked"' : '' , 107 165 'PH_AUTOPRUNE_FALSE' => $conf_PH[1]=='false' ? 'checked="checked"' : '' , … … 119 177 ); 120 178 179 121 180 // +-----------------------------------------------------------------------+ 122 181 // | templates display | -
extensions/Prune_History/admin/template/PH_admin.tpl
r14838 r14854 26 26 </div> 27 27 28 <fieldset >28 <fieldset class="save"> 29 29 <ul> 30 30 <li> … … 32 32 {'PH_ManualPrune_title'|@translate} 33 33 </label> 34 35 <fieldset class="save"> 36 <div style="text-align: center; text-transform: uppercase;"> 37 <label class="cluetip" title="{'PH_Save_Title'|translate}|{'PH_Save_Title_d'|translate}"> 38 {'PH_Save_Title'|@translate} 39 </label> 40 </div> 41 <form method="post" action="" class="general"> 42 <p> 43 {'PH_Dump_Download'|@translate} 44 <input type="checkbox" name="dump_download" value="true" {$PH_DUMP_DOWNLOAD}><br><br> 45 <input class="submit" type="submit" value="{'PH_Save'|@translate}" name="save" {$TAG_INPUT_ENABLED}> 46 </p> 47 </form> 48 <br> 49 <form method="post" action="" class="general"> 50 <p> 51 {'PH_Restore'|@translate}<br><br> 52 <input class="submit" type="submit" value="{'PH_Restore_File'|@translate}" name="restore" {$TAG_INPUT_ENABLED}> 53 </p> 54 </form> 55 </fieldset> 56 34 57 <br><br> 35 58 <form method="post" name="prune" action="" class="general"> … … 77 100 </li> 78 101 </ul> 102 79 103 <p> 80 104 <input class="submit" type="submit" value="{'PH_Prune'|@translate}" name="prune" {$TAG_INPUT_ENABLED}> … … 132 156 jQuery('#theAdminPage #the_page').addClass('{$themeconf.name}'); 133 157 jQuery(".infos").fadeOut(800).fadeIn(1200).fadeOut(400).fadeIn(800).fadeOut(400); 134 jQuery(".errors").fadeOut( 200).fadeIn(200).fadeOut(300).fadeIn(300).fadeOut(400).fadeIn(400);158 jQuery(".errors").fadeOut(400).fadeIn(400).fadeOut(400).fadeIn(400).fadeOut(400).fadeIn(400); 135 159 }); 136 160 </script> -
extensions/Prune_History/admin/template/ph.css
r14838 r14854 15 15 margin-bottom: 0.5em; 16 16 } 17 18 .save P, .save FIELDSET { 19 display: block; 20 float: right; 21 margin-left: 1em; 22 padding-bottom: 0; 23 padding-left: 0; 24 padding-right: 0; 25 padding-top: 0; 26 } -
extensions/Prune_History/include/functions.inc.php
r14838 r14854 1 1 <?php 2 /* Function called from main.inc.php to get the plugin version and name */ 2 /** 3 * Plugin administration menu 4 */ 5 function PH_admin_menu($menu) 6 { 7 // Retreive plugin name 8 $plugin = PHInfos(PH_PATH); 9 $name = $plugin['name']; 10 11 array_push($menu, 12 array( 13 'NAME' => $name, 14 'URL' => get_root_url().'admin.php?page=plugin-'.basename(PH_PATH) 15 ) 16 ); 17 18 return $menu; 19 } 20 21 22 /** 23 * Function to retreive some plugin information like version and name 24 * stored in main.inc.php file 25 * 26 * @param : Path to plugin 27 * 28 * @return : Array of retreived information 29 */ 3 30 function PHInfos($dir) 4 31 { … … 46 73 47 74 48 /* *************************************** */49 /* Update plugin version in conf table */ 50 /* Used everytime a new version is updated */ 51 /* even if no database upgrade is needed */ 52 /* ****************************************/75 /** 76 * Function to update plugin version number in config table 77 * Used everytime a new version is updated even if no database 78 * upgrade is needed 79 */ 53 80 function PH_version_update() 54 81 { … … 190 217 191 218 /** 192 * Automatic prune function 193 * 194 * @param : Start and stop range to prune 195 * 196 * @return : boolean 219 * Automatic prune function called from 'login_success' trigger 220 * in main.inc.php file 221 * 197 222 */ 198 223 function history_autoprune() … … 236 261 } 237 262 263 264 /** 265 * PH specific database dump 266 * Creates an SQL dump of history table for safety before manual prune 267 * 268 * @returns : Boolean to manage appropriate message display 269 * 270 */ 271 function PH_dump($download) 272 { 273 global $conf; 274 275 $plugin = PluginInfos(PH_PATH); 276 $version = $plugin['version']; 277 278 // Initial backup folder creation and file initialisation 279 // ------------------------------------------------------ 280 if (!is_dir(PH_PATH.'/include/backup')) 281 mkdir(PH_PATH.'/include/backup'); 282 283 $Backup_File = PH_PATH.'/include/backup/PH_Historybackup.sql'; 284 285 $fp = fopen($Backup_File, 'w'); 286 287 // Writing plugin version 288 $insertions = "-- ".$version." --\n\n"; 289 fwrite($fp, $insertions); 290 291 // Saving History table 292 // -------------------- 293 $ListTables = array(HISTORY_TABLE); 294 $j=0; 295 296 while($j < count($ListTables)) 297 { 298 $sql = 'SHOW CREATE TABLE '.$ListTables[$j]; 299 $res = pwg_query($sql); 300 301 if ($res) 302 { 303 $insertions = "-- -------------------------------------------------------\n"; 304 $insertions .= "-- Create ".$ListTables[$j]." table\n"; 305 $insertions .= "-- ------------------------------------------------------\n\n"; 306 307 $insertions .= "DROP TABLE IF EXISTS ".$ListTables[$j].";\n\n"; 308 309 $array = mysql_fetch_array($res); 310 $array[1] .= ";\n\n"; 311 $insertions .= $array[1]; 312 313 $req_table = pwg_query('SELECT * FROM '.$ListTables[$j]) or die(mysql_error()); 314 $nb_fields = mysql_num_fields($req_table); 315 while ($line = mysql_fetch_array($req_table)) 316 { 317 $insertions .= 'INSERT INTO '.$ListTables[$j].' VALUES ('; 318 for ($i=0; $i<$nb_fields; $i++) 319 { 320 $insertions .= '\'' . pwg_db_real_escape_string($line[$i]) . '\', '; 321 } 322 $insertions = substr($insertions, 0, -2); 323 $insertions .= ");\n"; 324 } 325 $insertions .= "\n\n"; 326 } 327 328 fwrite($fp, $insertions); 329 $j++; 330 } 331 332 fclose($fp); 333 334 // Download generated dump file 335 // ---------------------------- 336 if ($download == 'true') 337 { 338 if (@filesize($Backup_File)) 339 { 340 $http_headers = array( 341 'Content-Length: '.@filesize($Backup_File), 342 'Content-Type: text/x-sql', 343 'Content-Disposition: attachment; filename="PH_Historybackup.sql";', 344 'Content-Transfer-Encoding: binary', 345 ); 346 347 foreach ($http_headers as $header) 348 { 349 header($header); 350 } 351 352 @readfile($Backup_File); 353 exit(); 354 } 355 } 356 357 return true; 358 } 359 360 361 /** 362 * PH_Restore_backup_file 363 * Restore backup history table 364 * 365 * @returns : Boolean 366 */ 367 function PH_Restore_backup_file() 368 { 369 global $prefixeTable, $dblayer, $conf; 370 371 define('DEFAULT_PREFIX_TABLE', 'piwigo_'); 372 373 $Backup_File = PH_PATH.'/include/backup/PH_Historybackup.sql'; 374 375 // Restore sql backup file - DROP TABLE queries are executed 376 // --------------------------------------------------------- 377 UAM_execute_sqlfile( 378 $Backup_File, 379 DEFAULT_PREFIX_TABLE, 380 $prefixeTable, 381 $dblayer 382 ); 383 } 384 385 386 /** 387 * loads an sql file and executes all queries / Based on Piwigo's original install file 388 * 389 * Before executing a query, $replaced is... replaced by $replacing. This is 390 * useful when the SQL file contains generic words. 391 * 392 * @param string filepath 393 * @param string replaced 394 * @param string replacing 395 * @return void 396 */ 397 function PH_execute_sqlfile($filepath, $replaced, $replacing, $dblayer) 398 { 399 $sql_lines = file($filepath); 400 $query = ''; 401 foreach ($sql_lines as $sql_line) 402 { 403 $sql_line = trim($sql_line); 404 if (preg_match('/(^--|^$)/', $sql_line)) 405 { 406 continue; 407 } 408 409 $query.= ' '.$sql_line; 410 411 // if we reached the end of query, we execute it and reinitialize the 412 // variable "query" 413 if (preg_match('/;$/', $sql_line)) 414 { 415 $query = trim($query); 416 $query = str_replace($replaced, $replacing, $query); 417 if ('mysql' == $dblayer) 418 { 419 if (preg_match('/^(CREATE TABLE .*)[\s]*;[\s]*/im', $query, $matches)) 420 { 421 $query = $matches[1].' DEFAULT CHARACTER SET utf8'.';'; 422 } 423 } 424 pwg_query($query); 425 $query = ''; 426 } 427 } 428 } 238 429 239 430 -
extensions/Prune_History/language/en_UK/description.txt
r14838 r14854 1 Manual prune and background process which cleans your history table on regular basis.1 Manual and automatic pruning of the history table. -
extensions/Prune_History/language/fr_FR/description.txt
r14838 r14854 1 Elaguage manuel et tâche de fond pour nettoyerla table historique.1 Elaguage manuel et automatique de la table historique. -
extensions/Prune_History/language/fr_FR/plugin.lang.php
r14838 r14854 1 1 <?php 2 2 $lang['PH_ManualPrune_title'] = 'Elagage manuel'; 3 $lang['PH_ManualPrune_title_d'] = 'Cette fonction permet de supprimer des entrées dans l\'historique en fonction d\'une plage de dates. Choisissez une date de début et une date de fin de traitement et exécutez.<br><br> 4 <b style="color: red;">Attention : Les données de l\'historique seront alors irrémédiablement supprimées !</b> Vous pouvez sauvegarder préalablement et restaurer la table d\'historique en utilisant les fonctions dans le cadre de droite.<br><br> 5 Note : Le récapiltulatif de l\'historique n\'est pas affecté par l\'élagage.'; 6 7 $lang['PH_Save_Title'] = 'Sauvegarde de sécurité'; 8 $lang['PH_Save_Title_d'] = 'L\'élagage étant définitif et irréversible, il est vivement conseillé de sauvegarder votre table d\'historique avant de lancer un élagage. Par défaut, la table est sauvegardée dans un fichier sur le serveur et peut être restaurée depuis cet emplacement.<br><br> 9 Mais il est aussi possible de télécharger le fichier de sauvegarde pour le conserver en dehors de votre galerie. Dans ce cas, la restauration devra se faire via votre outil de gestion de base de données (généralement PhpMyAdmin).'; 10 11 $lang['PH_Dump_Download'] = 'Pour télécharger le fichier de sauvegarde, cochez cette case:'; 12 $lang['PH_Restore'] = 'Pour restaurer une sauvegarde de votre table d\'historique.<br>Seul le fichier sauvegardé sur le serveur est pris en compte.'; 13 $lang['PH_Save'] = 'Sauvegarder l\'historique'; 14 $lang['PH_Restore_File'] = 'Restaurer l\'historique'; 15 $lang['PH_Dump_OK'] = 'La sauvegarde a réussi !'; 16 $lang['PH_Dump_NOK'] = 'La sauvegarde a échoué !'; 17 $lang['PH_Restoration_OK'] = 'Restauration réussie !'; 18 $lang['PH_Restoration_NOK'] = 'Restauration échouée !'; 19 $lang['PH_Bad_version_backup'] = 'Mauvaise version du plugin ! La sauvegarde que vous tentez de restaurer est obsolète ou a été créée avec une ancienne version du plugin.'; 20 $lang['PH_No_Backup_File'] = 'Aucun fichier de sauvegarde trouvé pour la restauration !'; 21 3 22 $lang['PH_AutoPrune_title'] = 'Elagage automatique'; 4 $lang['PH_AutoPrune_false'] = 'Désactiver'; 23 $lang['PH_AutoPrune_title_d'] = 'Si vous activez l\'élagage automatique, celui-ci se déclenchera automatiquement en fonction du critère de conservation à chaque connexion d\'un utilisateur sur la galerie (y compris un administrateur ou le webmaster).<br><br> 24 <b style="color: red;">A utiliser avec précaution ! Les données élaguées ne seront pas récupérables en cas d\'erreur !</b>'; 25 26 $lang['PH_AutoPrune_false'] = 'Désactiver (par défaut)'; 5 27 $lang['PH_AutoPrune_true'] = 'Activer'; 6 28 $lang['Start_Date'] = 'Date de début'; 29 7 30 $lang['PH_AutoRange_title'] = 'Ne conserver un historique que sur :'; 31 $lang['PH_AutoRange_title_d'] = 'Configurez ici votre critère <b>de conservation</b> de l\'historique pour l\'élagage automatique. Plusieurs choix sont possibles :<br><br> 32 - Conserver x jours<br> 33 - Conserver x mois<br> 34 - Conserver x années<br><br> 35 Par exemple : Si vous ne souhaitez conserver qu\'une profondeur d\'historique de 3 mois, vous pouvez paramétrer 3 mois ou 91 jours.<br><br> 36 Note : Le récapiltulatif de l\'historique n\'est pas affecté par l\'élagage automatique.'; 37 8 38 $lang['PH_save_config'] = 'Configuration enregistrée !'; 9 39 $lang['PH_Prune'] = 'Exécuter l\'élagage manuel'; … … 16 46 $lang['range'][2] = 'Mois'; 17 47 $lang['range'][3] = 'Année(s)'; 48 49 $lang['PH_Support'] = 'Le support officiel sur ce plugin se fait exclusivement sur ce fil du forum FR de Piwigo:<br> 50 <a href="http://fr.piwigo.org/forum/viewtopic.php?id=" onclick="window.open(this.href);return false;">Forum français - http://fr.piwigo.org/forum/viewtopic.php?id=</a>'; 18 51 ?> -
extensions/Prune_History/main.inc.php
r14838 r14854 2 2 /* 3 3 Plugin Name: Prune History 4 Version: 1.0.0 -beta14 Version: 1.0.0 5 5 Description: Based on original History_cleanup plugin from VDigital, this plugin allows to manually or automatically prune history table according to configurable criteria 6 6 Plugin URI: http://piwigo.org/ext/extension_view.php?eid= … … 8 8 Author URI: http://www.infernoweb.net 9 9 */ 10 11 /* See release history and changes in changelog.txt file */ 10 12 11 13 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); … … 23 25 $conf_PH = unserialize($conf['PruneHistory']); 24 26 25 /* Plugin admin */ 27 28 /* Plugin administration */ 26 29 add_event_handler('get_admin_plugin_menu_links', 'PH_admin_menu'); 27 30 28 function PH_admin_menu($menu)29 {30 // +-----------------------------------------------------------------------+31 // | Getting plugin name |32 // +-----------------------------------------------------------------------+33 $plugin = PHInfos(PH_PATH);34 $name = $plugin['name'];35 36 array_push($menu,37 array(38 'NAME' => $name,39 'URL' => get_root_url().'admin.php?page=plugin-'.basename(PH_PATH)40 )41 );42 31 43 return $menu; 44 } 45 46 // Prune automation on user login 32 /* Prune automation on user login */ 47 33 if (isset($conf_PH[1]) and $conf_PH[1] == 'true') 48 34 { -
extensions/Prune_History/maintain.inc.php
r14838 r14854 26 26 $defaultPH[0] = $version; // Prune History version 27 27 $defaultPH[1] = 'false'; // Enable automated prune 28 $defaultPH[2] = '0'; // Range 29 $defaultPH[3] = '0'; // Value (Year, month, day) 28 30 29 31 // Create Prune History conf if not already exists
Note: See TracChangeset
for help on using the changeset viewer.