Your IP : 216.73.216.219


Current Path : /home/pteabiscqq/www/plugins/system/lab5_cookie_commander/_installer/
Upload File :
Current File : /home/pteabiscqq/www/plugins/system/lab5_cookie_commander/_installer/lab5_installer.php

<?php
/** 
* Cookie Commander
* 
* @author : Lab5 - Dennis Riegelsberger
* @authorUrl : https://lab5.ch
* @copyright : Copyright (C) 2018+  Lab5 - Dennis Riegelsberger. All rights reserved.
* @license : GNU/GPL General Public License version 2 or later
* @project : https://lab5.ch/cookie-commander
* @on JED : https://extensions.joomla.org/extensions/extension/site-management/cookie-control/lab5-cookie-commander/
* 
* Built with <3 
* Lab5
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 
/**
 * @CHANGELOG 
 *  * 2019-12-14 : FIRST VERSION
 *  * 2020-01-02 : OUTPUTS CHANGELOG + SPLITTING & RENAMING FUNCTIONS
 *  * 2020-04-01 : WIPE OLD FILES - FUNCTION
 *  * 2020-04-05 : NO LONGER ALLWAYS WIPE OLD FILES ( HAVE TO BE CALLED EXPLICITLY BY INSTALLER NOW )
 *  * 2020-08-10 : RENAMED THE INSTALLER
 */
defined('_JEXEC') or die;
////////////////////////////////////////////////////////////////////////////////////////
// if(!class_exists('lab5_installer')):
jimport('joomla.filesystem.folder');
jimport('joomla.filesystem.file');
////////////////////////////////////////////////////////////////////////////////////////
class lab5_installer_cookie_commander extends  JInstallerScript {
////////////////////////////////////////////////////////////////////////////////////////
				
				/* * * *
				INFO :
				https://api.joomla.org/cms-3/classes/Joomla.CMS.Installer.InstallerScript.html
				* * * */
				
				var $installed_version = null ; // version BEFORE install
				var $search = '';
				var $extension = '';
				var $type = ''; // plugin / module
				
				////////////////////////////////////////////////////////////////////////////////////////    
				function _swipe_oldfiles( $parent ) {
				////////////////////////////////////////////////////////////////////////////////////////    
									
									/* * * * * * * *
									This Funktion deletes files and folders that are no longer in the current version of the extension,
									by simply deleting everything, before rewriting all files anew.
									* * * * * * * * */
									// echo "<code>";
												
												$paths = $parent->get('parent')->get('paths') ;
												$extension_root = $paths['extension_root'];
												if( empty($extension_root) && $extension_root != JPATH_ROOT) return; // just to make sure / be paranoid.
												$exclusions = array(basename($paths['manifest'])); // to exclude this from deletion
												
												
												if( JFolder::exists($extension_root) ):
												
																$old_files = JFolder::files($extension_root, '.', false, true, $exclusions);
																$old_folders = JFolder::folders($extension_root, '.', false, true);
																
																// Because File paths MUST be relative to root :
																if( $old_files ){
																		foreach( $old_files as $file ){
																			
																					$this->deleteFiles[] = str_replace( JPATH_ROOT, '', $file );
																		}
																}
																if( $old_folders ){
																		foreach( $old_folders as $folder ){
																			
																					$this->deleteFolders[] = str_replace( JPATH_ROOT, '', $folder );
																		}
																}
																
																$this->removeFiles();
												
												endif;
												
									// echo "</code>";
									 
				} //////////////////////////////////////////////////////////////////////////////////////
				function preflight( $type, $parent ) {
				////////////////////////////////////////////////////////////////////////////////////////    
				
												$this->_load_current_versions_info( $this->type, $parent );
												// $this->_swipe_oldfiles( $parent );
												
				} //////////////////////////////////////////////////////////////////////////////////////
				/* * * * * * * * * * * * * * * * * * * * * * * *
				* $parent is the class calling this method.  */
				function update( $parent ) {
				////////////////////////////////////////////////////////////////////////////////////////    
									 
											$this->_show_changelog( $parent ); 
											$this->_post_update_message_new_features( $parent ); 
			 
				} //////////////////////////////////////////////////////////////////////////////////////
				  /*
				  * $parent is the class calling this method.
				  * install runs after the database scripts are executed.
				  * If the extension is new, the install method is run.
				  * If install returns false, Joomla will abort the install and undo everything already done.
				  */
				////////////////////////////////////////////////////////////////////////////////////////    
				function install( $parent ) {
				////////////////////////////////////////////////////////////////////////////////////////    
					
											$this->_post_install_message( $parent );
							
				} //////////////////////////////////////////////////////////////////////////////////////  
				/* * * * * * * * * * * * * * * * * * * * * * * *
				* After everything else ( after install / uninstall / update )  */
				////////////////////////////////////////////////////////////////////////////////////////    
				function postflight($type, $parent) {
				////////////////////////////////////////////////////////////////////////////////////////    
								
				} //////////////////////////////////////////////////////////////////////////////////////////////// 
				 /*
				  * $parent is the class calling this method
				  * uninstall runs before any other action is taken (file removal or database processing).
				  */
				////////////////////////////////////////////////////////////////////////////////////////      
				function uninstall( $parent ) {         
				} //////////////////////////////////////////////////////////////////////////////////////  
				
				
				
				
				////////////////////////////////////////////////////////////////////////////////////////    
				function _show_changelog( $parent ) {
				////////////////////////////////////////////////////////////////////////////////////////    
										
													// $element = $parent->get('element');
													$manifest = $parent->get('manifest');
													$element = $manifest->name; // 
													
													/////////////////////////
													// LIST NEW FEATURES :
													/////////////////////////
													$msg = '';
													foreach( $manifest->changeLog->changeDate as $changeDate  ){
																$date = $changeDate->attributes()->date;
																if( trim($date) == trim($manifest->updateDate) ){
																		$msg .=  '<dl class="">';
																		$msg .= '<dt class="">CHANGES ( '.$date.' ):</dt>';	
																		foreach( $changeDate->change as $change  ){
																				$msg .=  '<dd class="muted">'.$change.'</dd>';
																		}
																		$msg .=  '</dl>';
																}
													}
													$app = JFactory::getApplication();
													$element = JText::_($element);  
													$app->enqueueMessage($msg, $element); 

				} //////////////////////////////////////////////////////////////////////////////////////
				function _post_update_new_features_message( $parent, $messagetype = NULL ) {
				////////////////////////////////////////////////////////////////////////////////////////    
				
													/////////////////////////
													// NEW FEATURES - MESSAGE :
													/////////////////////////
													
													if( !$messagetype ){
														$messagetype = $parent->get('element');
														// $messagetype = JText::_(strtoupper($messagetype)); 
													}
													
													$LNG_STRNG = 'LAB5_EXTENSION_MSG_UPDATED';
													$exttype = $parent->get('manifest')->attributes()->type;
												
													$app = JFactory::getApplication();
													$msg = sprintf( JText::_($LNG_STRNG), 
													JUri::base( false ).'index.php?option=com_'.$exttype.'s&view='.$exttype.'s&filter[search]='.$this->search, 
													JText::_($this->extension) );
													$app->enqueueMessage($msg, $messagetype); 
									 
				} //////////////////////////////////////////////////////////////////////////////////////
				function _post_install_message( $parent, $messagetype = 'notice' ) {
				////////////////////////////////////////////////////////////////////////////////////////    
												
													$LNG_STRNG = 'LAB5_EXTENSION_MSG_INSTALLED';
													$exttype = $parent->get('manifest')->attributes()->type;
												
													$app = JFactory::getApplication();
													$msg = sprintf( JText::_($LNG_STRNG), 
													JUri::base( false ).'index.php?option=com_'.$exttype.'s&view='.$exttype.'s&filter[search]='.$this->search, 
													JText::_($this->extension) );
													$app->enqueueMessage($msg, $messagetype); 
								 
				} //////////////////////////////////////////////////////////////////////////////////////
				function _load_current_versions_info( $exttype, $parent ) {
				////////////////////////////////////////////////////////////////////////////////////////    
										
										/////////////////////////////////
										// GET INSTALLED / OLD VERSION NUMBER
										/////////////////////////////////
												
												// HAS to be from DB ( not from Manifest ), because only DB holds CURRENT number.
												
												// Get extension table class
												$extensionTable = JTable::getInstance('extension');
												// Find extension id
												$extensionId = $extensionTable->find( array('element' => $parent->get('element'), 'type' => $exttype) );
												// $extensionId = $parent->get('currentExtensionId');
												$currentextension = $extensionTable->load($extensionId);
												// load Field
												$manifest_cache = $extensionTable->get('manifest_cache');
												$manifest_cache = new JRegistry;
												$manifest_cache->loadString( $extensionTable->get('manifest_cache'), 'JSON'); // Load  params.  
												
												$this->installed_version = $manifest_cache->get('version') ;
												return $this->installed_version ;
												// $parent->get('element');  
								 
				} //////////////////////////////////////////////////////////////////////////////////////
		 
} //////////////////////////////////////////////////////////////////////////////////////
// endif;
////////////////////////////////////////////////////////////////////////////////////////