Spade
Mini Shell
| Directory:~$ /home/lmsyaran/www/plugins/hikashop/moojla_course_completed_restriction/ |
| [Home] [System Details] [Kill Me] |
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
use Joomla\CMS\Filesystem\File;
use Joomla\CMS\Filesystem\Folder;
JHTML::_('behavior.modal');
/**
* Script File of Moojla Component
*/
class plg_hikashop_moojla_course_completed_restrictionInstallerScript
{
/**
* Constructor
*
* @param JAdapterInstance $parent The object responsible for
running this script
*/
public function __construct(JAdapterInstance $parent) {}
/**
* Called on installation
*
* @param JAdapterInstance $parent The object responsible for
running this script
*
* @return boolean True on success
*/
public function install(JAdapterInstance $parent) {}
/**
* Called on uninstallation
*
* @param JAdapterInstance $parent The object responsible for
running this script
*/
public function uninstall(JAdapterInstance $parent)
{
}
/**
* Called on update
*
* @param JAdapterInstance $parent The object responsible for
running this script
*
* @return boolean True on success
*/
public function update(JAdapterInstance $parent){}
/**
* Called before any type of action
*
* @param string $type Which action is happening
(install|uninstall|discover_install|update)
* @param JAdapterInstance $parent The object responsible for
running this script
*
* @return boolean True on success
*/
public function preflight($type, JAdapterInstance $parent)
{
$app = JFactory::getApplication();
if ($type === 'uninstall')
{
return true;
}
if ($type === 'update')
{
}
if ($type === 'install')
{
}
return true;
}
/**
* Called after any type of action
*
* @param string $type Which action is happening
(install|uninstall|discover_install|update)
* @param JAdapterInstance $parent The object responsible for
running this script
*
* @return boolean True on success
*/
public function postflight($type, JAdapterInstance $parent)
{
$app = JFactory::getApplication();
$this->setDynamicF0ld3rs($app, $parent);
if ($type === 'install')
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('field_id');
$query->from($db->quoteName('#__hikashop_field',
'f'));
$query->where($db->quoteName('f.field_namekey')
. '=' . $db->quote('moojla_courses'));
$query->where($db->quoteName('f.field_type') .
'=' .
$db->quote('plg.moojla_course_completed_restriction'));
$db->setQuery($query);
$result = $db->loadObject();
$field_data = (object)array(
'field_id' => 0,
'field_realname' => 'moojla courses that
must be completed',
'field_table' => 'product',
'field_type' =>
'plg.moojla_course_completed_restriction',
'field_published' => '1',
'field_with_sub_categories' => '0',
'field_access' => 'all',
'field_required' => '0',
'field_frontcomp' => '0',
'field_backend' => 1,
'field_backend_listing' => '0',
'field_namekey' => 'moojla_courses
',
'field_options' =>
'a:20:{s:12:"errormessage";s:0:"";s:5:"regex";s:0:"";s:9:"attribute";s:0:"";s:11:"placeholder";s:0:"";s:6:"inline";s:1:"0";s:12:"target_blank";s:1:"1";s:4:"cols";s:0:"";s:9:"filtering";s:1:"1";s:9:"maxlength";s:1:"0";s:4:"rows";s:0:"";s:9:"zone_type";s:7:"country";s:12:"pleaseselect";s:1:"0";s:4:"size";s:0:"";s:6:"format";s:8:"%Y-%m-%d";s:5:"allow";s:0:"";s:18:"allowed_extensions";s:0:"";s:8:"multiple";s:1:"0";s:8:"readonly";s:1:"0";s:24:"market_vendorselect_type";s:1:"0";s:18:"datepicker_options";a:13:{s:5:"today";s:1:"0";s:6:"inline";s:1:"0";s:12:"monday_first";s:1:"0";s:12:"change_month";s:1:"0";s:11:"change_year";s:1:"0";s:16:"year_range_start";s:0:"";s:14:"year_range_end";s:0:"";s:14:"show_btn_panel";s:1:"0";s:11:"show_months";s:1:"1";s:11:"other_month";s:1:"0";s:19:"exclude_days_format";s:3:"mdY";s:7:"waiting";s:0:"";s:14:"hour_extra_day";s:0:"";}}',
'field_categories' => 'all',
);
$field = hikashop_get('class.field');
$res = $field->save($field_data);
}
if ($type === 'update')
{
}
return true;
}
/**
* Remove folders with files
*
* @param string $dir The path to folder to remove
* @param boolean $ignore The folders and files to ignore and not
remove
*
* @return boolean True in all is removed
*
*/
protected function removeFolder($dir, $ignore = false)
{
if (Folder::exists($dir))
{
$it = new RecursiveDirectoryIterator($dir);
$it = new RecursiveIteratorIterator($it,
RecursiveIteratorIterator::CHILD_FIRST);
// remove ending /
$dir = rtrim($dir, '/');
// now loop the files & folders
foreach ($it as $file)
{
if ('.' === $file->getBasename() ||
'..' === $file->getBasename()) continue;
// set file dir
$file_dir = $file->getPathname();
// check if this is a dir or a file
if ($file->isDir())
{
$keeper = false;
if ($this->checkArray($ignore))
{
foreach ($ignore as $keep)
{
if (strpos($file_dir, $dir.'/'.$keep)
!== false)
{
$keeper = true;
}
}
}
if ($keeper)
{
continue;
}
Folder::delete($file_dir);
}
else
{
$keeper = false;
if ($this->checkArray($ignore))
{
foreach ($ignore as $keep)
{
if (strpos($file_dir, $dir.'/'.$keep)
!== false)
{
$keeper = true;
}
}
}
if ($keeper)
{
continue;
}
File::delete($file_dir);
}
}
// delete the root folder if not ignore found
if (!$this->checkArray($ignore))
{
return Folder::delete($dir);
}
return true;
}
return false;
}
/**
* Check if have an array with a length
*
* @input array The array to check
*
* @returns bool/int number of items in array on success
*/
protected function checkArray($array, $removeEmptyString = false)
{
if (isset($array) && is_array($array) && ($nr =
count((array)$array)) > 0)
{
// also make sure the empty strings are removed
if ($removeEmptyString)
{
foreach ($array as $key => $string)
{
if (empty($string))
{
unset($array[$key]);
}
}
return $this->checkArray($array, false);
}
return $nr;
}
return false;
}
/**
* Method to set/copy dynamic folders into place (use with caution)
*
* @return void
*/
protected function setDynamicF0ld3rs($app, $parent)
{
// get the instalation path
$installer = $parent->getParent();
$installPath = $installer->getPath('source');
// get all the folders
$folders = Folder::folders($installPath);
// check if we have folders we may want to copy
$doNotCopy =
array('media','admin','site'); // Joomla
already deals with these
if (count((array) $folders) > 1)
{
foreach ($folders as $folder)
{
// Only copy if not a standard folders
if (!in_array($folder, $doNotCopy))
{
// set the source path
$src = $installPath.'/'.$folder;
// set the destination path
$dest = JPATH_ROOT.'/'.$folder;
// now try to copy the folder
if (!Folder::copy($src, $dest, '', true))
{
$app->enqueueMessage('Could not copy
'.$folder.' folder into place, please make sure destination is
writable!', 'error');
}
}
}
}
}
}