monthlyarchive.script.php 6.75 KB
<?php
/* ======================================================
# Monthly Archive - Joomla! Component v4.3.3 (PRO version)
# -------------------------------------------------------
# For Joomla! 3.x
# Author: Yiannis Christodoulou (yiannis@web357.eu)
# Copyright (©) 2009-2018 Web357. All rights reserved.
# License: GNU/GPLv3, http://www.gnu.org/licenses/gpl-3.0.html
# Website: https://www.web357.eu/
# Demo: http://demo.web357.eu/?item=monthlyarchive
# Support: support@web357.eu
# Last modified: 09 Feb 2018, 13:55:18
========================================================= */

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

class com_monthlyarchiveInstallerScript
{

	/**
	 * method to install the component
	 *
	 * @return void
	 */
	function install($parent) 
	{
		// $parent is the class calling this method
	}
 
	/**
	 * method to uninstall the component
	 *
	 * @return void
	 */
	function uninstall($parent) 
	{
		// $parent is the class calling this method
	}
 
	/**
	 * method to update the component
	 *
	 * @return void
	 */
	function update($parent) 
	{
		// $parent is the class calling this method
	}

	/**
	 * method to run before an install/update/uninstall method
	 *
	 * @return void
	 */
	function preflight($type, $parent) 
	{
		// $parent is the class calling this method
	}

	/**
	 * method to run after an install/update/uninstall method
	 *
	 * @return void
	 */
	function postflight($type, $parent) 
	{
		if (!in_array($type, array('install', 'update')))
		{
			return;
		}

		jimport('joomla.filesystem.folder');
		jimport('joomla.filesystem.file');

		// Connect to DB
		$db = JFactory::getDbo();
		
		// Delete the old name of Extension
		$query = "DELETE FROM #__extensions WHERE element='com_web357monthlyarchive'"; $db->setQuery($query); $db->query();
		
		// Delete Old package
		$query = "DELETE FROM #__extensions WHERE element='pkg_monthlyarchive'"; $db->setQuery($query); $db->query();
		
		// Update and Set the correct names for extensions.

		// component
		$query = "UPDATE #__extensions SET name='COM_MONTHLYARCHIVE' WHERE element='com_monthlyarchive'"; $db->setQuery($query); $db->query();
		
		// module
		$query = "UPDATE #__extensions SET name='MOD_MONTHLYARCHIVE' WHERE element='mod_monthlyarchive'"; $db->setQuery($query); $db->query();

		// Update Menu
		$query = "UPDATE #__menu SET title='COM_MONTHLYARCHIVE', alias='com-monthlyarchive', path='com-monthlyarchive' WHERE link='index.php?option=com_monthlyarchive'"; $db->setQuery($query); $db->query();

		// Update Menu (after upgrade monthlyarchive to v4.0.0)
		$query = "UPDATE #__menu SET link='index.php?option=com_monthlyarchive&view=archive' WHERE link='index.php?option=com_monthlyarchive&view=all' OR link='index.php?option=com_monthlyarchive&view=monthlyarchive'"; $db->setQuery($query); $db->query();

		// Define DS
		if (!defined("DS")):
			define("DS", DIRECTORY_SEPARATOR);
		endif;

		// BEGIN: Rename the old Monthly Archive language files from /language/ and /administrator/language/, because the new files have been moved to each extension directory.
		$lang_admin_arr = $this->getFilesFromEntireDirectory(JPATH_ADMINISTRATOR.'/language/','ini','monthlyarchive');
		$lang_site_arr = $this->getFilesFromEntireDirectory(JPATH_SITE.'/language/','ini','monthlyarchive');
		$lang_arr = array_merge($lang_admin_arr, $lang_site_arr);
		
		// Rename action
		foreach ($lang_arr as $lang_file):
			if (JFile::exists($lang_file)):
				rename ($lang_file, $lang_file.'-BKP');
			endif;
		endforeach;
		// END: Rename the old Monthly Archive language files
		
    // Remove files from older versions
		$remove_files_arr = array(
		
			// monthlyarchive component (after v4.0.0)
			JPATH_ROOT.DS.'components'.DS.'com_monthlyarchive'.DS.'controllers'.DS.'all.php',
			JPATH_ROOT.DS.'components'.DS.'com_monthlyarchive'.DS.'controllers'.DS.'monthlyarchive.php',
			JPATH_ROOT.DS.'components'.DS.'com_monthlyarchive'.DS.'models'.DS.'all.php',
			JPATH_ROOT.DS.'components'.DS.'com_monthlyarchive'.DS.'models'.DS.'monthlyarchive.php',

			// monthlyarchive module
			JPATH_ROOT.DS.'components'.DS.'mod_monthlyarchive'.DS.'elements'.DS.'info.php', 
			JPATH_ROOT.DS.'modules'.DS.'mod_monthlyarchive'.DS.'tmpl'.DS.'accordion.php', 
			JPATH_ROOT.DS.'modules'.DS.'mod_monthlyarchive'.DS.'assets'.DS.'ma_output.php',
			JPATH_ROOT.DS.'modules'.DS.'mod_monthlyarchive'.DS.'assets'.DS.'style.css',

			// supporthours
			JPATH_ROOT.DS.'modules'.DS.'mod_supporthours'.DS.'timezone.php', 
			
			// failedloginattempts
			JPATH_ROOT.DS.'plugins'.DS.'authentication'.DS.'failedloginattempts'.DS.'elements'.DS.'info.php',

			// cookiespolicynotificationbar
			JPATH_ROOT.DS.'plugins'.DS.'system'.DS.'cookiespolicynotificationbar'.DS.'elements'.DS.'info.php',
		);
			
    // Remove action
		foreach ($remove_files_arr as $remove_file):
			if (JFile::exists($remove_file)):
				JFile::delete($remove_file);
			endif;
		endforeach;

		// Remove folders from older versions
		$remove_folders_arr = array(
		
			// monthlyarchive component (after v4.0.0)
			JPATH_ROOT.DS.'components'.DS.'com_monthlyarchive'.DS.'assets'.DS.'icons',
			JPATH_ROOT.DS.'components'.DS.'com_monthlyarchive'.DS.'classes',
			JPATH_ROOT.DS.'components'.DS.'com_monthlyarchive'.DS.'views'.DS.'all',
			JPATH_ROOT.DS.'components'.DS.'com_monthlyarchive'.DS.'views'.DS.'monthlyarchive',

			// monthlyarchive module (after v4.0.0)
			JPATH_ROOT.DS.'modules'.DS.'mod_monthlyarchive'.DS.'assets'.DS.'js'

		);
        
 		// Remove action
		foreach ($remove_folders_arr as $remove_folder):
			if (JFolder::exists($remove_folder)):
				JFolder::delete($remove_folder);
			endif;
		endforeach;

	}

	// get files from entire directory (and sub directories)
	function getFilesFromEntireDirectory($root = '.', $file_type = '', $file_name_like = ''){ // $file_type = ini or php or html 
	  $files  = array(); 
	  $directories  = array(); 
	  $last_letter  = $root[strlen($root)-1]; 
	  $root  = ($last_letter == '\\' || $last_letter == '/') ? $root : $root.DIRECTORY_SEPARATOR; 
	
	  $directories[]  = $root; 
	
	  while (sizeof($directories)) { 
		$dir  = array_pop($directories); 
		if ($handle = opendir($dir)) { 
		  while (false !== ($file = readdir($handle))) { 
			if ($file == '.' || $file == '..') { 
			  continue; 
			} 
			$file  = $dir.$file; 
			if (is_dir($file)) { 
			  $directory_path = $file.DIRECTORY_SEPARATOR; 
			  array_push($directories, $directory_path); 
			} elseif (is_file($file)) { 
			  $ext = pathinfo($file, PATHINFO_EXTENSION);
			  if ($file_type == $ext && (strpos($file, $file_name_like) !== false) && substr( $file, -strlen( ".".$file_type ) ) == ".".$file_type) { 
				  $files[]  = $file; 
			  }elseif (empty($file_type) && empty($file_name_like)){
				//display all
				$files[] = $file;
			  }
			} 
		  } 
		  closedir($handle); 
		} 
	  } 
	
	  return $files; 
	}
	
}