Blame view

administrator/components/com_monthlyarchive/monthlyarchive.script.php 6.75 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
<?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; 
	}
	
}