Spade
Mini Shell
PK`;�[q�Z��AbstractApplication.phpnu�[���<?php
/**
* Part of the Joomla Framework Application Package
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All
rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\Application;
use Joomla\Input\Input;
use Joomla\Registry\Registry;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
/**
* Joomla Framework Base Application Class
*
* @since 1.0
*/
abstract class AbstractApplication implements LoggerAwareInterface
{
/**
* The application configuration object.
*
* @var Registry
* @since 1.0
*/
protected $config;
/**
* The application input object.
*
* @var Input
* @since 1.0
*/
public $input;
/**
* A logger.
*
* @var LoggerInterface
* @since 1.0
*/
private $logger;
/**
* Class constructor.
*
* @param Input $input An optional argument to provide dependency
injection for the application's input object. If the argument is an
* Input object that object will become the
application's input object, otherwise a default input object is
created.
* @param Registry $config An optional argument to provide dependency
injection for the application's config object. If the argument
* is a Registry object that object will
become the application's config object, otherwise a default config
* object is created.
*
* @since 1.0
*/
public function __construct(Input $input = null, Registry $config = null)
{
$this->input = $input instanceof Input ? $input : new Input;
$this->config = $config instanceof Registry ? $config : new Registry;
// Set the execution datetime and timestamp;
$this->set('execution.datetime', gmdate('Y-m-d
H:i:s'));
$this->set('execution.timestamp', time());
$this->set('execution.microtimestamp', microtime(true));
$this->initialise();
}
/**
* Method to close the application.
*
* @param integer $code The exit code (optional; default is 0).
*
* @return void
*
* @codeCoverageIgnore
* @since 1.0
*/
public function close($code = 0)
{
exit($code);
}
/**
* Method to run the application routines. Most likely you will want to
instantiate a controller
* and execute it, or perform some sort of task directly.
*
* @return mixed
*
* @since 1.0
*/
abstract protected function doExecute();
/**
* Execute the application.
*
* @return void
*
* @since 1.0
*/
public function execute()
{
// @event onBeforeExecute
// Perform application routines.
$this->doExecute();
// @event onAfterExecute
}
/**
* Returns a property of the object or the default value if the property
is not set.
*
* @param string $key The name of the property.
* @param mixed $default The default value (optional) if none is set.
*
* @return mixed The value of the configuration.
*
* @since 1.0
*/
public function get($key, $default = null)
{
return $this->config->get($key, $default);
}
/**
* Get the logger.
*
* @return LoggerInterface
*
* @since 1.0
*/
public function getLogger()
{
// If a logger hasn't been set, use NullLogger
if (! ($this->logger instanceof LoggerInterface))
{
$this->logger = new NullLogger;
}
return $this->logger;
}
/**
* Custom initialisation method.
*
* Called at the end of the AbstractApplication::__construct method.
* This is for developers to inject initialisation code for their
application classes.
*
* @return void
*
* @codeCoverageIgnore
* @since 1.0
*/
protected function initialise()
{
}
/**
* Modifies a property of the object, creating it if it does not already
exist.
*
* @param string $key The name of the property.
* @param mixed $value The value of the property to set (optional).
*
* @return mixed Previous value of the property
*
* @since 1.0
*/
public function set($key, $value = null)
{
$previous = $this->config->get($key);
$this->config->set($key, $value);
return $previous;
}
/**
* Sets the configuration for the application.
*
* @param Registry $config A registry object holding the
configuration.
*
* @return AbstractApplication Returns itself to support chaining.
*
* @since 1.0
*/
public function setConfiguration(Registry $config)
{
$this->config = $config;
return $this;
}
/**
* Set the logger.
*
* @param LoggerInterface $logger The logger.
*
* @return AbstractApplication Returns itself to support chaining.
*
* @since 1.0
*/
public function setLogger(LoggerInterface $logger)
{
$this->logger = $logger;
return $this;
}
}
PK`;�[N�K�YYAbstractCliApplication.phpnu�[���<?php
/**
* Part of the Joomla Framework Application Package
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All
rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\Application;
use Joomla\Input;
use Joomla\Registry\Registry;
/**
* Base class for a Joomla! command line application.
*
* @since 1.0
* @deprecated 2.0 Use the `joomla/console` package instead
*/
abstract class AbstractCliApplication extends AbstractApplication
{
/**
* Output object
*
* @var Cli\CliOutput
* @since 1.0
*/
protected $output;
/**
* CLI Input object
*
* @var Cli\CliInput
* @since 1.6.0
*/
protected $cliInput;
/**
* Class constructor.
*
* @param Input\Cli $input An optional argument to provide
dependency injection for the application's input object. If the
* argument is an Input\Cli object that
object will become the application's input object, otherwise
* a default input object is created.
* @param Registry $config An optional argument to provide
dependency injection for the application's config object. If the
* argument is a Registry object that
object will become the application's config object, otherwise
* a default config object is created.
* @param Cli\CliOutput $output An optional argument to provide
dependency injection for the application's output object. If the
* argument is a Cli\CliOutput object
that object will become the application's input object, otherwise
* a default output object is created.
* @param Cli\CliInput $cliInput An optional argument to provide
dependency injection for the application's CLI input object. If the
* argument is a Cli\CliInput object
that object will become the application's input object, otherwise
* a default input object is created.
*
* @since 1.0
*/
public function __construct(Input\Cli $input = null, Registry $config =
null, Cli\CliOutput $output = null, Cli\CliInput $cliInput = null)
{
// Close the application if we are not executed from the command line.
// @codeCoverageIgnoreStart
if (!\defined('STDOUT') || !\defined('STDIN') ||
!isset($_SERVER['argv']))
{
$this->close();
}
// @codeCoverageIgnoreEnd
$this->output = ($output instanceof Cli\CliOutput) ? $output : new
Cli\Output\Stdout;
// Set the CLI input object.
$this->cliInput = ($cliInput instanceof Cli\CliInput) ? $cliInput :
new Cli\CliInput;
// Call the constructor as late as possible (it runs `initialise`).
parent::__construct($input instanceof Input\Input ? $input : new
Input\Cli, $config);
// Set the current directory.
$this->set('cwd', getcwd());
}
/**
* Get an output object.
*
* @return Cli\CliOutput
*
* @since 1.0
*/
public function getOutput()
{
return $this->output;
}
/**
* Get a CLI input object.
*
* @return Cli\CliInput
*
* @since 1.6.0
*/
public function getCliInput()
{
return $this->cliInput;
}
/**
* Write a string to standard output.
*
* @param string $text The text to display.
* @param boolean $nl True (default) to append a new line at the end
of the output string.
*
* @return AbstractCliApplication Instance of $this to allow chaining.
*
* @since 1.0
*/
public function out($text = '', $nl = true)
{
$this->getOutput()->out($text, $nl);
return $this;
}
/**
* Get a value from standard input.
*
* @return string The input string from standard input.
*
* @codeCoverageIgnore
* @since 1.0
*/
public function in()
{
return $this->getCliInput()->in();
}
}
PK`;�[]t?1a1aAbstractDaemonApplication.phpnu�[���<?php
/**
* Part of the Joomla Framework Application Package
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All
rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\Application;
use Joomla\Input;
use Joomla\Registry\Registry;
use Psr\Log\LoggerAwareInterface;
/**
* Class to turn Cli applications into daemons. It requires CLI and PCNTL
support built into PHP.
*
* @link https://secure.php.net/manual/en/book.pcntl.php
* @link https://secure.php.net/manual/en/features.commandline.php
* @since 1.0
* @deprecated 2.0 Deprecated without replacement
*/
abstract class AbstractDaemonApplication extends AbstractCliApplication
implements LoggerAwareInterface
{
/**
* @var array The available POSIX signals to be caught by default.
* @link https://secure.php.net/manual/pcntl.constants.php
* @since 1.0
*/
protected static $signals = array(
'SIGHUP',
'SIGINT',
'SIGQUIT',
'SIGILL',
'SIGTRAP',
'SIGABRT',
'SIGIOT',
'SIGBUS',
'SIGFPE',
'SIGUSR1',
'SIGSEGV',
'SIGUSR2',
'SIGPIPE',
'SIGALRM',
'SIGTERM',
'SIGSTKFLT',
'SIGCLD',
'SIGCHLD',
'SIGCONT',
'SIGTSTP',
'SIGTTIN',
'SIGTTOU',
'SIGURG',
'SIGXCPU',
'SIGXFSZ',
'SIGVTALRM',
'SIGPROF',
'SIGWINCH',
'SIGPOLL',
'SIGIO',
'SIGPWR',
'SIGSYS',
'SIGBABY',
'SIG_BLOCK',
'SIG_UNBLOCK',
'SIG_SETMASK',
);
/**
* @var boolean True if the daemon is in the process of exiting.
* @since 1.0
*/
protected $exiting = false;
/**
* @var integer The parent process id.
* @since 1.0
*/
protected $parentId = 0;
/**
* @var integer The process id of the daemon.
* @since 1.0
*/
protected $processId = 0;
/**
* @var boolean True if the daemon is currently running.
* @since 1.0
*/
protected $running = false;
/**
* Class constructor.
*
* @param Input\Cli $input An optional argument to provide
dependency injection for the application's input object. If the
* argument is an Input\Cli object that
object will become the application's input object, otherwise
* a default input object is created.
* @param Registry $config An optional argument to provide
dependency injection for the application's config object. If the
* argument is a Registry object that
object will become the application's config object, otherwise
* a default config object is created.
* @param Cli\CliOutput $output An optional argument to provide
dependency injection for the application's output object. If the
* argument is a Cli\CliOutput object
that object will become the application's input object, otherwise
* a default output object is created.
* @param Cli\CliInput $cliInput An optional argument to provide
dependency injection for the application's CLI input object. If the
* argument is a Cli\CliInput object
that object will become the application's input object, otherwise
* a default input object is created.
*
* @since 1.0
*/
public function __construct(Cli $input = null, Registry $config = null,
Cli\CliOutput $output = null, Cli\CliInput $cliInput = null)
{
// Verify that the process control extension for PHP is available.
// @codeCoverageIgnoreStart
if (!\defined('SIGHUP'))
{
$this->getLogger()->error('The PCNTL extension for PHP is not
available.');
throw new \RuntimeException('The PCNTL extension for PHP is not
available.');
}
// Verify that POSIX support for PHP is available.
if (!\function_exists('posix_getpid'))
{
$this->getLogger()->error('The POSIX extension for PHP is not
available.');
throw new \RuntimeException('The POSIX extension for PHP is not
available.');
}
// @codeCoverageIgnoreEnd
// Call the parent constructor.
parent::__construct($input, $config, $output, $cliInput);
// Set some system limits.
@set_time_limit($this->get('max_execution_time', 0));
if ($this->get('max_memory_limit') !== null)
{
ini_set('memory_limit',
$this->get('max_memory_limit', '256M'));
}
// Flush content immediately.
ob_implicit_flush();
}
/**
* Method to handle POSIX signals.
*
* @param integer $signal The received POSIX signal.
*
* @return void
*
* @since 1.0
* @see pcntl_signal()
* @throws \RuntimeException
*/
public function signal($signal)
{
// Log all signals sent to the daemon.
$this->getLogger()->debug('Received signal: ' . $signal);
// Let's make sure we have an application instance.
if (!is_subclass_of($this, __CLASS__))
{
$this->getLogger()->emergency('Cannot find the application
instance.');
throw new \RuntimeException('Cannot find the application
instance.');
}
// @event onReceiveSignal
switch ($signal)
{
case SIGINT:
case SIGTERM:
// Handle shutdown tasks
if ($this->running && $this->isActive())
{
$this->shutdown();
}
else
{
$this->close();
}
break;
case SIGHUP:
// Handle restart tasks
if ($this->running && $this->isActive())
{
$this->shutdown(true);
}
else
{
$this->close();
}
break;
case SIGCHLD:
// A child process has died
while ($this->pcntlWait($signal, WNOHANG || WUNTRACED) > 0)
{
usleep(1000);
}
break;
case SIGCLD:
while ($this->pcntlWait($signal, WNOHANG) > 0)
{
$signal = $this->pcntlChildExitStatus($signal);
}
break;
default:
break;
}
}
/**
* Check to see if the daemon is active. This does not assume that $this
daemon is active, but
* only if an instance of the application is active as a daemon.
*
* @return boolean True if daemon is active.
*
* @since 1.0
*/
public function isActive()
{
// Get the process id file location for the application.
$pidFile = $this->get('application_pid_file');
// If the process id file doesn't exist then the daemon is obviously
not running.
if (!is_file($pidFile))
{
return false;
}
// Read the contents of the process id file as an integer.
$fp = fopen($pidFile, 'r');
$pid = fread($fp, filesize($pidFile));
$pid = (int) $pid;
fclose($fp);
// Check to make sure that the process id exists as a positive integer.
if (!$pid)
{
return false;
}
// Check to make sure the process is active by pinging it and ensure it
responds.
if (!posix_kill($pid, 0))
{
// No response so remove the process id file and log the situation.
@ unlink($pidFile);
$this->getLogger()->warning('The process found based on PID
file was unresponsive.');
return false;
}
return true;
}
/**
* Load an object or array into the application configuration object.
*
* @param mixed $data Either an array or object to be loaded into the
configuration object.
*
* @return AbstractDaemonApplication Instance of $this to allow
chaining.
*
* @since 1.0
*/
public function loadConfiguration($data)
{
/*
* Setup some application metadata options. This is useful if we ever
want to write out startup scripts
* or just have some sort of information available to share about things.
*/
// The application author name. This string is used in generating
startup scripts and has
// a maximum of 50 characters.
$tmp = (string) $this->get('author_name', 'Joomla
Framework');
$this->set('author_name', (\strlen($tmp) > 50) ?
substr($tmp, 0, 50) : $tmp);
// The application author email. This string is used in generating
startup scripts.
$tmp = (string) $this->get('author_email',
'admin@joomla.org');
$this->set('author_email', filter_var($tmp,
FILTER_VALIDATE_EMAIL));
// The application name. This string is used in generating startup
scripts.
$tmp = (string) $this->get('application_name',
'JApplicationDaemon');
$this->set('application_name', (string)
preg_replace('/[^A-Z0-9_-]/i', '', $tmp));
// The application description. This string is used in generating
startup scripts.
$tmp = (string) $this->get('application_description',
'A generic Joomla Framework application.');
$this->set('application_description', filter_var($tmp,
FILTER_SANITIZE_STRING));
/*
* Setup the application path options. This defines the default
executable name, executable directory,
* and also the path to the daemon process id file.
*/
// The application executable daemon. This string is used in generating
startup scripts.
$tmp = (string) $this->get('application_executable',
basename($this->input->executable));
$this->set('application_executable', $tmp);
// The home directory of the daemon.
$tmp = (string) $this->get('application_directory',
\dirname($this->input->executable));
$this->set('application_directory', $tmp);
// The pid file location. This defaults to a path inside the /tmp
directory.
$name = $this->get('application_name');
$tmp = (string) $this->get('application_pid_file',
strtolower('/tmp/' . $name . '/' . $name .
'.pid'));
$this->set('application_pid_file', $tmp);
/*
* Setup the application identity options. It is important to remember
if the default of 0 is set for
* either UID or GID then changing that setting will not be attempted as
there is no real way to "change"
* the identity of a process from some user to root.
*/
// The user id under which to run the daemon.
$tmp = (int) $this->get('application_uid', 0);
$options = array('options' => array('min_range'
=> 0, 'max_range' => 65000));
$this->set('application_uid', filter_var($tmp,
FILTER_VALIDATE_INT, $options));
// The group id under which to run the daemon.
$tmp = (int) $this->get('application_gid', 0);
$options = array('options' => array('min_range'
=> 0, 'max_range' => 65000));
$this->set('application_gid', filter_var($tmp,
FILTER_VALIDATE_INT, $options));
// Option to kill the daemon if it cannot switch to the chosen identity.
$tmp = (bool) $this->get('application_require_identity', 1);
$this->set('application_require_identity', $tmp);
/*
* Setup the application runtime options. By default our execution time
limit is infinite obviously
* because a daemon should be constantly running unless told otherwise.
The default limit for memory
* usage is 128M, which admittedly is a little high, but remember it is a
"limit" and PHP's memory
* management leaves a bit to be desired :-)
*/
// The maximum execution time of the application in seconds. Zero is
infinite.
$tmp = $this->get('max_execution_time');
if ($tmp !== null)
{
$this->set('max_execution_time', (int) $tmp);
}
// The maximum amount of memory the application can use.
$tmp = $this->get('max_memory_limit', '256M');
if ($tmp !== null)
{
$this->set('max_memory_limit', (string) $tmp);
}
return $this;
}
/**
* Execute the daemon.
*
* @return void
*
* @since 1.0
*/
public function execute()
{
// @event onBeforeExecute
// Enable basic garbage collection.
gc_enable();
$this->getLogger()->info('Starting ' . $this->name);
// Set off the process for becoming a daemon.
if ($this->daemonize())
{
// Declare ticks to start signal monitoring. When you declare ticks,
PCNTL will monitor
// incoming signals after each tick and call the relevant signal handler
automatically.
declare(ticks = 1);
// Start the main execution loop.
while (true)
{
// Perform basic garbage collection.
$this->gc();
// Don't completely overload the CPU.
usleep(1000);
// Execute the main application logic.
$this->doExecute();
}
}
else
{
// We were not able to daemonize the application so log the failure and
die gracefully.
$this->getLogger()->info('Starting ' . $this->name .
' failed');
}
// @event onAfterExecute
}
/**
* Restart daemon process.
*
* @return void
*
* @codeCoverageIgnore
* @since 1.0
*/
public function restart()
{
$this->getLogger()->info('Stopping ' . $this->name);
$this->shutdown(true);
}
/**
* Stop daemon process.
*
* @return void
*
* @codeCoverageIgnore
* @since 1.0
*/
public function stop()
{
$this->getLogger()->info('Stopping ' . $this->name);
$this->shutdown();
}
/**
* Method to change the identity of the daemon process and resources.
*
* @return boolean True if identity successfully changed
*
* @since 1.0
* @see posix_setuid()
*/
protected function changeIdentity()
{
// Get the group and user ids to set for the daemon.
$uid = (int) $this->get('application_uid', 0);
$gid = (int) $this->get('application_gid', 0);
// Get the application process id file path.
$file = $this->get('application_pid_file');
// Change the user id for the process id file if necessary.
if ($uid && (fileowner($file) != $uid) && (!@
chown($file, $uid)))
{
$this->getLogger()->error('Unable to change user ownership of
the process id file.');
return false;
}
// Change the group id for the process id file if necessary.
if ($gid && (filegroup($file) != $gid) && (!@
chgrp($file, $gid)))
{
$this->getLogger()->error('Unable to change group ownership
of the process id file.');
return false;
}
// Set the correct home directory for the process.
if ($uid && ($info = posix_getpwuid($uid)) &&
is_dir($info['dir']))
{
system('export HOME="' . $info['dir'] .
'"');
}
// Change the user id for the process necessary.
if ($uid && (posix_getuid($file) != $uid) && (!@
posix_setuid($uid)))
{
$this->getLogger()->error('Unable to change user ownership of
the proccess.');
return false;
}
// Change the group id for the process necessary.
if ($gid && (posix_getgid($file) != $gid) && (!@
posix_setgid($gid)))
{
$this->getLogger()->error('Unable to change group ownership
of the proccess.');
return false;
}
// Get the user and group information based on uid and gid.
$user = posix_getpwuid($uid);
$group = posix_getgrgid($gid);
$this->getLogger()->info('Changed daemon identity to ' .
$user['name'] . ':' . $group['name']);
return true;
}
/**
* Method to put the application into the background.
*
* @return boolean
*
* @since 1.0
* @throws \RuntimeException
*/
protected function daemonize()
{
// Is there already an active daemon running?
if ($this->isActive())
{
$this->getLogger()->emergency($this->name . ' daemon is
still running. Exiting the application.');
return false;
}
// Reset Process Information
$this->safeMode = !!@ ini_get('safe_mode');
$this->processId = 0;
$this->running = false;
// Detach process!
try
{
// Check if we should run in the foreground.
if (!$this->input->get('f'))
{
// Detach from the terminal.
$this->detach();
}
else
{
// Setup running values.
$this->exiting = false;
$this->running = true;
// Set the process id.
$this->processId = (int) posix_getpid();
$this->parentId = $this->processId;
}
}
catch (\RuntimeException $e)
{
$this->getLogger()->emergency('Unable to fork.');
return false;
}
// Verify the process id is valid.
if ($this->processId < 1)
{
$this->getLogger()->emergency('The process id is invalid; the
fork failed.');
return false;
}
// Clear the umask.
@ umask(0);
// Write out the process id file for concurrency management.
if (!$this->writeProcessIdFile())
{
$this->getLogger()->emergency('Unable to write the pid file
at: ' . $this->get('application_pid_file'));
return false;
}
// Attempt to change the identity of user running the process.
if (!$this->changeIdentity())
{
// If the identity change was required then we need to return false.
if ($this->get('application_require_identity'))
{
$this->getLogger()->critical('Unable to change process
owner.');
return false;
}
$this->getLogger()->warning('Unable to change process
owner.');
}
// Setup the signal handlers for the daemon.
if (!$this->setupSignalHandlers())
{
return false;
}
// Change the current working directory to the application working
directory.
@ chdir($this->get('application_directory'));
return true;
}
/**
* This is truly where the magic happens. This is where we fork the
process and kill the parent
* process, which is essentially what turns the application into a daemon.
*
* @return void
*
* @since 1.0
* @throws \RuntimeException
*/
protected function detach()
{
$this->getLogger()->debug('Detaching the ' .
$this->name . ' daemon.');
// Attempt to fork the process.
$pid = $this->fork();
// If the pid is positive then we successfully forked, and can close this
application.
if ($pid)
{
// Add the log entry for debugging purposes and exit gracefully.
$this->getLogger()->debug('Ending ' . $this->name .
' parent process');
$this->close();
}
else
{
// We are in the forked child process.
// Setup some protected values.
$this->exiting = false;
$this->running = true;
// Set the parent to self.
$this->parentId = $this->processId;
}
}
/**
* Method to fork the process.
*
* @return integer The child process id to the parent process, zero to
the child process.
*
* @since 1.0
* @throws \RuntimeException
*/
protected function fork()
{
// Attempt to fork the process.
$pid = $this->pcntlFork();
// If the fork failed, throw an exception.
if ($pid === -1)
{
throw new \RuntimeException('The process could not be
forked.');
}
if ($pid === 0)
{
// Update the process id for the child.
$this->processId = (int) posix_getpid();
}
else
{
// Log the fork in the parent.
$this->getLogger()->debug('Process forked ' . $pid);
}
// Trigger the onFork event.
$this->postFork();
return $pid;
}
/**
* Method to perform basic garbage collection and memory management in the
sense of clearing the
* stat cache. We will probably call this method pretty regularly in our
main loop.
*
* @return void
*
* @codeCoverageIgnore
* @since 1.0
*/
protected function gc()
{
// Perform generic garbage collection.
gc_collect_cycles();
// Clear the stat cache so it doesn't blow up memory.
clearstatcache();
}
/**
* Method to attach the AbstractDaemonApplication signal handler to the
known signals. Applications
* can override these handlers by using the pcntl_signal() function and
attaching a different
* callback method.
*
* @return boolean
*
* @since 1.0
* @see pcntl_signal()
*/
protected function setupSignalHandlers()
{
// We add the error suppression for the loop because on some platforms
some constants are not defined.
foreach (self::$signals as $signal)
{
// Ignore signals that are not defined.
if (!\defined($signal) || !\is_int(\constant($signal)) ||
(\constant($signal) === 0))
{
// Define the signal to avoid notices.
$this->getLogger()->debug('Signal "' . $signal .
'" not defined. Defining it as null.');
\define($signal, null);
// Don't listen for signal.
continue;
}
// Attach the signal handler for the signal.
if (!$this->pcntlSignal(\constant($signal), array($this,
'signal')))
{
$this->getLogger()->emergency(sprintf('Unable to reroute
signal handler: %s', $signal));
return false;
}
}
return true;
}
/**
* Method to shut down the daemon and optionally restart it.
*
* @param boolean $restart True to restart the daemon on exit.
*
* @return void
*
* @since 1.0
*/
protected function shutdown($restart = false)
{
// If we are already exiting, chill.
if ($this->exiting)
{
return;
}
// If not, now we are.
$this->exiting = true;
// If we aren't already daemonized then just kill the application.
if (!$this->running && !$this->isActive())
{
$this->getLogger()->info('Process was not daemonized yet,
just halting current process');
$this->close();
}
// Only read the pid for the parent file.
if ($this->parentId == $this->processId)
{
// Read the contents of the process id file as an integer.
$fp = fopen($this->get('application_pid_file'),
'r');
$pid = fread($fp,
filesize($this->get('application_pid_file')));
$pid = (int) $pid;
fclose($fp);
// Remove the process id file.
@ unlink($this->get('application_pid_file'));
// If we are supposed to restart the daemon we need to execute the same
command.
if ($restart)
{
$this->close(exec(implode(' ', $GLOBALS['argv'])
. ' > /dev/null &'));
}
else
{
// If we are not supposed to restart the daemon let's just kill
-9.
passthru('kill -9 ' . $pid);
$this->close();
}
}
}
/**
* Method to write the process id file out to disk.
*
* @return boolean
*
* @since 1.0
*/
protected function writeProcessIdFile()
{
// Verify the process id is valid.
if ($this->processId < 1)
{
$this->getLogger()->emergency('The process id is
invalid.');
return false;
}
// Get the application process id file path.
$file = $this->get('application_pid_file');
if (empty($file))
{
$this->getLogger()->error('The process id file path is
empty.');
return false;
}
// Make sure that the folder where we are writing the process id file
exists.
$folder = \dirname($file);
if (!is_dir($folder) && !@ mkdir($folder,
$this->get('folder_permission', 0755)))
{
$this->getLogger()->error('Unable to create directory: '
. $folder);
return false;
}
// Write the process id file out to disk.
if (!file_put_contents($file, $this->processId))
{
$this->getLogger()->error('Unable to write proccess id file:
' . $file);
return false;
}
// Make sure the permissions for the proccess id file are accurate.
if (!chmod($file, $this->get('file_permission', 0644)))
{
$this->getLogger()->error('Unable to adjust permissions for
the proccess id file: ' . $file);
return false;
}
return true;
}
/**
* Method to handle post-fork triggering of the onFork event.
*
* @return void
*
* @since 1.0
*/
protected function postFork()
{
// @event onFork
}
/**
* Method to return the exit code of a terminated child process.
*
* @param integer $status The status parameter is the status parameter
supplied to a successful call to pcntl_waitpid().
*
* @return integer The child process exit code.
*
* @codeCoverageIgnore
* @see pcntl_wexitstatus()
* @since 1.0
*/
protected function pcntlChildExitStatus($status)
{
return pcntl_wexitstatus($status);
}
/**
* Method to return the exit code of a terminated child process.
*
* @return integer On success, the PID of the child process is returned
in the parent's thread
* of execution, and a 0 is returned in the child's
thread of execution. On
* failure, a -1 will be returned in the parent's
context, no child process
* will be created, and a PHP error is raised.
*
* @codeCoverageIgnore
* @see pcntl_fork()
* @since 1.0
*/
protected function pcntlFork()
{
return pcntl_fork();
}
/**
* Method to install a signal handler.
*
* @param integer $signal The signal number.
* @param callable $handler The signal handler which may be the name
of a user created function,
* or method, or either of the two global
constants SIG_IGN or SIG_DFL.
* @param boolean $restart Specifies whether system call restarting
should be used when this
* signal arrives.
*
* @return boolean True on success.
*
* @codeCoverageIgnore
* @see pcntl_signal()
* @since 1.0
*/
protected function pcntlSignal($signal, $handler, $restart = true)
{
return pcntl_signal($signal, $handler, $restart);
}
/**
* Method to wait on or return the status of a forked child.
*
* @param integer $status Status information.
* @param integer $options If wait3 is available on your system
(mostly BSD-style systems),
* you can provide the optional options
parameter.
*
* @return integer The process ID of the child which exited, -1 on error
or zero if WNOHANG
* was provided as an option (on wait3-available
systems) and no child was available.
*
* @codeCoverageIgnore
* @see pcntl_wait()
* @since 1.0
*/
protected function pcntlWait(&$status, $options = 0)
{
return pcntl_wait($status, $options);
}
}
PK`;�[R��llAbstractWebApplication.phpnu�[���<?php
/**
* Part of the Joomla Framework Application Package
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All
rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\Application;
use Joomla\Input\Input;
use Joomla\Registry\Registry;
use Joomla\Session\Session;
use Joomla\Uri\Uri;
/**
* Base class for a Joomla! Web application.
*
* @since 1.0
*/
abstract class AbstractWebApplication extends AbstractApplication
{
/**
* Character encoding string.
*
* @var string
* @since 1.0
*/
public $charSet = 'utf-8';
/**
* Response mime type.
*
* @var string
* @since 1.0
*/
public $mimeType = 'text/html';
/**
* HTTP protocol version.
*
* @var string
* @since 1.9.0
*/
public $httpVersion = '1.1';
/**
* The body modified date for response headers.
*
* @var \DateTime
* @since 1.0
*/
public $modifiedDate;
/**
* The application client object.
*
* @var Web\WebClient
* @since 1.0
*/
public $client;
/**
* The application response object.
*
* @var object
* @since 1.0
*/
protected $response;
/**
* The application session object.
*
* @var Session
* @since 1.0
*/
private $session;
/**
* A map of integer HTTP response codes to the full HTTP Status for the
headers.
*
* @var array
* @since 1.6.0
* @link
https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
*/
private $responseMap = array(
100 => 'HTTP/{version} 100 Continue',
101 => 'HTTP/{version} 101 Switching Protocols',
102 => 'HTTP/{version} 102 Processing',
200 => 'HTTP/{version} 200 OK',
201 => 'HTTP/{version} 201 Created',
202 => 'HTTP/{version} 202 Accepted',
203 => 'HTTP/{version} 203 Non-Authoritative Information',
204 => 'HTTP/{version} 204 No Content',
205 => 'HTTP/{version} 205 Reset Content',
206 => 'HTTP/{version} 206 Partial Content',
207 => 'HTTP/{version} 207 Multi-Status',
208 => 'HTTP/{version} 208 Already Reported',
226 => 'HTTP/{version} 226 IM Used',
300 => 'HTTP/{version} 300 Multiple Choices',
301 => 'HTTP/{version} 301 Moved Permanently',
302 => 'HTTP/{version} 302 Found',
303 => 'HTTP/{version} 303 See other',
304 => 'HTTP/{version} 304 Not Modified',
305 => 'HTTP/{version} 305 Use Proxy',
306 => 'HTTP/{version} 306 (Unused)',
307 => 'HTTP/{version} 307 Temporary Redirect',
308 => 'HTTP/{version} 308 Permanent Redirect',
400 => 'HTTP/{version} 400 Bad Request',
401 => 'HTTP/{version} 401 Unauthorized',
402 => 'HTTP/{version} 402 Payment Required',
403 => 'HTTP/{version} 403 Forbidden',
404 => 'HTTP/{version} 404 Not Found',
405 => 'HTTP/{version} 405 Method Not Allowed',
406 => 'HTTP/{version} 406 Not Acceptable',
407 => 'HTTP/{version} 407 Proxy Authentication Required',
408 => 'HTTP/{version} 408 Request Timeout',
409 => 'HTTP/{version} 409 Conflict',
410 => 'HTTP/{version} 410 Gone',
411 => 'HTTP/{version} 411 Length Required',
412 => 'HTTP/{version} 412 Precondition Failed',
413 => 'HTTP/{version} 413 Payload Too Large',
414 => 'HTTP/{version} 414 URI Too Long',
415 => 'HTTP/{version} 415 Unsupported Media Type',
416 => 'HTTP/{version} 416 Range Not Satisfiable',
417 => 'HTTP/{version} 417 Expectation Failed',
418 => 'HTTP/{version} 418 I\'m a teapot',
421 => 'HTTP/{version} 421 Misdirected Request',
422 => 'HTTP/{version} 422 Unprocessable Entity',
423 => 'HTTP/{version} 423 Locked',
424 => 'HTTP/{version} 424 Failed Dependency',
426 => 'HTTP/{version} 426 Upgrade Required',
428 => 'HTTP/{version} 428 Precondition Required',
429 => 'HTTP/{version} 429 Too Many Requests',
431 => 'HTTP/{version} 431 Request Header Fields Too Large',
451 => 'HTTP/{version} 451 Unavailable For Legal Reasons',
500 => 'HTTP/{version} 500 Internal Server Error',
501 => 'HTTP/{version} 501 Not Implemented',
502 => 'HTTP/{version} 502 Bad Gateway',
503 => 'HTTP/{version} 503 Service Unavailable',
504 => 'HTTP/{version} 504 Gateway Timeout',
505 => 'HTTP/{version} 505 HTTP Version Not Supported',
506 => 'HTTP/{version} 506 Variant Also Negotiates',
507 => 'HTTP/{version} 507 Insufficient Storage',
508 => 'HTTP/{version} 508 Loop Detected',
510 => 'HTTP/{version} 510 Not Extended',
511 => 'HTTP/{version} 511 Network Authentication Required',
);
/**
* Class constructor.
*
* @param Input $input An optional argument to provide
dependency injection for the application's input object. If the
argument
* is an Input object that object will
become the application's input object, otherwise a default input
* object is created.
* @param Registry $config An optional argument to provide
dependency injection for the application's config object. If the
argument
* is a Registry object that object will
become the application's config object, otherwise a default config
* object is created.
* @param Web\WebClient $client An optional argument to provide
dependency injection for the application's client object. If the
argument
* is a Web\WebClient object that object
will become the application's client object, otherwise a default
client
* object is created.
*
* @since 1.0
*/
public function __construct(Input $input = null, Registry $config = null,
Web\WebClient $client = null)
{
$this->client = $client instanceof Web\WebClient ? $client : new
Web\WebClient;
// Setup the response object.
$this->response = new \stdClass;
$this->response->cachable = false;
$this->response->headers = array();
$this->response->body = array();
// Call the constructor as late as possible (it runs `initialise`).
parent::__construct($input, $config);
// Set the system URIs.
$this->loadSystemUris();
}
/**
* Execute the application.
*
* @return void
*
* @since 1.0
*/
public function execute()
{
// @event onBeforeExecute
// Perform application routines.
$this->doExecute();
// @event onAfterExecute
// If gzip compression is enabled in configuration and the server is
compliant, compress the output.
if ($this->get('gzip') &&
!ini_get('zlib.output_compression') &&
(ini_get('output_handler') != 'ob_gzhandler'))
{
$this->compress();
}
// @event onBeforeRespond
// Send the application response.
$this->respond();
// @event onAfterRespond
}
/**
* Checks the accept encoding of the browser and compresses the data
before
* sending it to the client if possible.
*
* @return void
*
* @since 1.0
*/
protected function compress()
{
// Supported compression encodings.
$supported = array(
'x-gzip' => 'gz',
'gzip' => 'gz',
'deflate' => 'deflate',
);
// Get the supported encoding.
$encodings = array_intersect($this->client->encodings,
array_keys($supported));
// If no supported encoding is detected do nothing and return.
if (empty($encodings))
{
return;
}
// Verify that headers have not yet been sent, and that our connection is
still alive.
if ($this->checkHeadersSent() || !$this->checkConnectionAlive())
{
return;
}
// Iterate through the encodings and attempt to compress the data using
any found supported encodings.
foreach ($encodings as $encoding)
{
if (($supported[$encoding] == 'gz') || ($supported[$encoding]
== 'deflate'))
{
// Verify that the server supports gzip compression before we attempt
to gzip encode the data.
// @codeCoverageIgnoreStart
if (!\extension_loaded('zlib') ||
ini_get('zlib.output_compression'))
{
continue;
}
// @codeCoverageIgnoreEnd
// Attempt to gzip encode the data with an optimal level 4.
$data = $this->getBody();
$gzdata = gzencode($data, 4, ($supported[$encoding] == 'gz')
? FORCE_GZIP : FORCE_DEFLATE);
// If there was a problem encoding the data just try the next encoding
scheme.
// @codeCoverageIgnoreStart
if ($gzdata === false)
{
continue;
}
// @codeCoverageIgnoreEnd
// Set the encoding headers.
$this->setHeader('Content-Encoding', $encoding);
$this->setHeader('Vary', 'Accept-Encoding');
$this->setHeader('X-Content-Encoded-By',
'Joomla');
// Replace the output with the encoded data.
$this->setBody($gzdata);
// Compression complete, let's break out of the loop.
break;
}
}
}
/**
* Method to send the application response to the client. All headers
will be sent prior to the main
* application output data.
*
* @return void
*
* @since 1.0
*/
protected function respond()
{
// Send the content-type header.
$this->setHeader('Content-Type', $this->mimeType .
'; charset=' . $this->charSet);
// If the response is set to uncachable, we need to set some appropriate
headers so browsers don't cache the response.
if (!$this->allowCache())
{
// Expires in the past.
$this->setHeader('Expires', 'Wed, 17 Aug 2005 00:00:00
GMT', true);
// Always modified.
$this->setHeader('Last-Modified', gmdate('D, d M Y
H:i:s') . ' GMT', true);
$this->setHeader('Cache-Control', 'no-store, no-cache,
must-revalidate, post-check=0, pre-check=0', false);
// HTTP 1.0
$this->setHeader('Pragma', 'no-cache');
}
else
{
// Expires.
$this->setHeader('Expires', gmdate('D, d M Y
H:i:s', time() + 900) . ' GMT');
// Last modified.
if ($this->modifiedDate instanceof \DateTime)
{
$this->modifiedDate->setTimezone(new
\DateTimeZone('UTC'));
$this->setHeader('Last-Modified',
$this->modifiedDate->format('D, d M Y H:i:s') . '
GMT');
}
}
$this->sendHeaders();
echo $this->getBody();
}
/**
* Redirect to another URL.
*
* If the headers have not been sent the redirect will be accomplished
using a "301 Moved Permanently"
* or "303 See Other" code in the header pointing to the new
location. If the headers have already been
* sent this will be accomplished using a JavaScript statement.
*
* @param string $url The URL to redirect to. Can only be
http/https URL
* @param integer $status The HTTP status code to be provided. 303 is
assumed by default.
*
* @return void
*
* @since 1.0
* @throws \InvalidArgumentException
*/
public function redirect($url, $status = 303)
{
// Check for relative internal links.
if (preg_match('#^index\.php#', $url))
{
$url = $this->get('uri.base.full') . $url;
}
// Perform a basic sanity check to make sure we don't have any CRLF
garbage.
$url = preg_split("/[\r\n]/", $url);
$url = $url[0];
/*
* Here we need to check and see if the URL is relative or absolute.
Essentially, do we need to
* prepend the URL with our base URL for a proper redirect. The
rudimentary way we are looking
* at this is to simply check whether or not the URL string has a valid
scheme or not.
*/
if (!preg_match('#^[a-z]+\://#i', $url))
{
// Get a Uri instance for the requested URI.
$uri = new Uri($this->get('uri.request'));
// Get a base URL to prepend from the requested URI.
$prefix = $uri->toString(array('scheme', 'user',
'pass', 'host', 'port'));
// We just need the prefix since we have a path relative to the root.
if ($url[0] == '/')
{
$url = $prefix . $url;
}
else
{
// It's relative to where we are now, so lets add that.
$parts = explode('/',
$uri->toString(array('path')));
array_pop($parts);
$path = implode('/', $parts) . '/';
$url = $prefix . $path . $url;
}
}
// If the headers have already been sent we need to send the redirect
statement via JavaScript.
if ($this->checkHeadersSent())
{
echo '<script>document.location.href=' .
json_encode($url) . ";</script>\n";
}
else
{
// We have to use a JavaScript redirect here because MSIE doesn't
play nice with utf-8 URLs.
if (($this->client->engine == Web\WebClient::TRIDENT) &&
!static::isAscii($url))
{
$html = '<html><head>';
$html .= '<meta http-equiv="content-type"
content="text/html; charset=' . $this->charSet . '"
/>';
$html .= '<script>document.location.href=' .
json_encode($url) . ';</script>';
$html .=
'</head><body></body></html>';
echo $html;
}
else
{
// Check if we have a boolean for the status variable for compatability
with v1 of the framework
// @deprecated 3.0
if (\is_bool($status))
{
$status = $status ? 301 : 303;
}
if (!\is_int($status) && !$this->isRedirectState($status))
{
throw new \InvalidArgumentException('You have not supplied a
valid HTTP status code');
}
// All other cases use the more efficient HTTP header for redirection.
$this->setHeader('Status', $status, true);
$this->setHeader('Location', $url, true);
}
}
// Set appropriate headers
$this->respond();
// Close the application after the redirect.
$this->close();
}
/**
* Set/get cachable state for the response. If $allow is set, sets the
cachable state of the
* response. Always returns the current state.
*
* @param boolean $allow True to allow browser caching.
*
* @return boolean
*
* @since 1.0
*/
public function allowCache($allow = null)
{
if ($allow !== null)
{
$this->response->cachable = (bool) $allow;
}
return $this->response->cachable;
}
/**
* Method to set a response header. If the replace flag is set then all
headers
* with the given name will be replaced by the new one. The headers are
stored
* in an internal array to be sent when the site is sent to the browser.
*
* @param string $name The name of the header to set.
* @param string $value The value of the header to set.
* @param boolean $replace True to replace any headers with the same
name.
*
* @return AbstractWebApplication Instance of $this to allow chaining.
*
* @since 1.0
*/
public function setHeader($name, $value, $replace = false)
{
// Sanitize the input values.
$name = (string) $name;
$value = (string) $value;
// If the replace flag is set, unset all known headers with the given
name.
if ($replace)
{
foreach ($this->response->headers as $key => $header)
{
if ($name == $header['name'])
{
unset($this->response->headers[$key]);
}
}
// Clean up the array as unsetting nested arrays leaves some junk.
$this->response->headers =
array_values($this->response->headers);
}
// Add the header to the internal array.
$this->response->headers[] = array('name' => $name,
'value' => $value);
return $this;
}
/**
* Method to get the array of response headers to be sent when the
response is sent
* to the client.
*
* @return array
*
* @since 1.0
*/
public function getHeaders()
{
return $this->response->headers;
}
/**
* Method to clear any set response headers.
*
* @return AbstractWebApplication Instance of $this to allow chaining.
*
* @since 1.0
*/
public function clearHeaders()
{
$this->response->headers = array();
return $this;
}
/**
* Send the response headers.
*
* @return AbstractWebApplication Instance of $this to allow chaining.
*
* @since 1.0
*/
public function sendHeaders()
{
if (!$this->checkHeadersSent())
{
foreach ($this->response->headers as $header)
{
if (strtolower($header['name']) == 'status')
{
// 'status' headers indicate an HTTP status, and need to be
handled slightly differently
$status = $this->getHttpStatusValue($header['value']);
$this->header($status, true, (int) $header['value']);
}
else
{
$this->header($header['name'] . ': ' .
$header['value']);
}
}
}
return $this;
}
/**
* Set body content. If body content already defined, this will replace
it.
*
* @param string $content The content to set as the response body.
*
* @return AbstractWebApplication Instance of $this to allow chaining.
*
* @since 1.0
*/
public function setBody($content)
{
$this->response->body = array((string) $content);
return $this;
}
/**
* Prepend content to the body content
*
* @param string $content The content to prepend to the response body.
*
* @return AbstractWebApplication Instance of $this to allow chaining.
*
* @since 1.0
*/
public function prependBody($content)
{
array_unshift($this->response->body, (string) $content);
return $this;
}
/**
* Append content to the body content
*
* @param string $content The content to append to the response body.
*
* @return AbstractWebApplication Instance of $this to allow chaining.
*
* @since 1.0
*/
public function appendBody($content)
{
$this->response->body[] = (string) $content;
return $this;
}
/**
* Return the body content
*
* @param boolean $asArray True to return the body as an array of
strings.
*
* @return mixed The response body either as an array or concatenated
string.
*
* @since 1.0
*/
public function getBody($asArray = false)
{
return $asArray ? $this->response->body : implode((array)
$this->response->body);
}
/**
* Method to get the application session object.
*
* @return Session The session object
*
* @since 1.0
*/
public function getSession()
{
if ($this->session === null)
{
throw new \RuntimeException('A \Joomla\Session\Session object has
not been set.');
}
return $this->session;
}
/**
* Check if a given value can be successfully mapped to a valid http
status value
*
* @param string|int $value The given status as int or string
*
* @return string
*
* @since 1.8.0
*/
protected function getHttpStatusValue($value)
{
$code = (int) $value;
if (array_key_exists($code, $this->responseMap))
{
$value = $this->responseMap[$code];
}
else
{
$value = 'HTTP/{version} ' . $code;
}
return str_replace('{version}', $this->httpVersion, $value);
}
/**
* Check if the value is a valid HTTP status code
*
* @param integer $code The potential status code
*
* @return boolean
*
* @since 1.8.1
*/
public function isValidHttpStatus($code)
{
return array_key_exists($code, $this->responseMap);
}
/**
* Method to check the current client connection status to ensure that it
is alive. We are
* wrapping this to isolate the connection_status() function from our code
base for testing reasons.
*
* @return boolean True if the connection is valid and normal.
*
* @codeCoverageIgnore
* @see connection_status()
* @since 1.0
*/
protected function checkConnectionAlive()
{
return connection_status() === CONNECTION_NORMAL;
}
/**
* Method to check to see if headers have already been sent. We are
wrapping this to isolate the
* headers_sent() function from our code base for testing reasons.
*
* @return boolean True if the headers have already been sent.
*
* @codeCoverageIgnore
* @see headers_sent()
* @since 1.0
*/
protected function checkHeadersSent()
{
return headers_sent();
}
/**
* Method to detect the requested URI from server environment variables.
*
* @return string The requested URI
*
* @since 1.0
*/
protected function detectRequestUri()
{
// First we need to detect the URI scheme.
if ($this->isSslConnection())
{
$scheme = 'https://';
}
else
{
$scheme = 'http://';
}
/*
* There are some differences in the way that Apache and IIS populate
server environment variables. To
* properly detect the requested URI we need to adjust our algorithm
based on whether or not we are getting
* information from Apache or IIS.
*/
$phpSelf =
$this->input->server->getString('PHP_SELF',
'');
$requestUri =
$this->input->server->getString('REQUEST_URI',
'');
// If PHP_SELF and REQUEST_URI are both populated then we will assume
"Apache Mode".
if (!empty($phpSelf) && !empty($requestUri))
{
// The URI is built from the HTTP_HOST and REQUEST_URI environment
variables in an Apache environment.
$uri = $scheme .
$this->input->server->getString('HTTP_HOST') .
$requestUri;
}
else
{
// If not in "Apache Mode" we will assume that we are in an
IIS environment and proceed.
// IIS uses the SCRIPT_NAME variable instead of a REQUEST_URI
variable... thanks, MS
$uri = $scheme .
$this->input->server->getString('HTTP_HOST') .
$this->input->server->getString('SCRIPT_NAME');
$queryHost =
$this->input->server->getString('QUERY_STRING',
'');
// If the QUERY_STRING variable exists append it to the URI string.
if (!empty($queryHost))
{
$uri .= '?' . $queryHost;
}
}
return trim($uri);
}
/**
* Method to send a header to the client. We are wrapping this to isolate
the header() function
* from our code base for testing reasons.
*
* @param string $string The header string.
* @param boolean $replace The optional replace parameter indicates
whether the header should
* replace a previous similar header, or add a
second header of the same type.
* @param integer $code Forces the HTTP response code to the
specified value. Note that
* this parameter only has an effect if the
string is not empty.
*
* @return void
*
* @codeCoverageIgnore
* @see header()
* @since 1.0
*/
protected function header($string, $replace = true, $code = null)
{
header(str_replace(\chr(0), '', $string), $replace, $code);
}
/**
* Checks if a state is a redirect state
*
* @param integer $state The HTTP status code.
*
* @return boolean
*
* @since 1.8.0
*/
protected function isRedirectState($state)
{
$state = (int) $state;
return $state > 299 && $state < 400 &&
array_key_exists($state, $this->responseMap);
}
/**
* Determine if we are using a secure (SSL) connection.
*
* @return boolean True if using SSL, false if not.
*
* @since 1.0
*/
public function isSslConnection()
{
$serverSSLVar =
$this->input->server->getString('HTTPS', '');
if (!empty($serverSSLVar) && strtolower($serverSSLVar) !==
'off')
{
return true;
}
$serverForwarderProtoVar =
$this->input->server->getString('HTTP_X_FORWARDED_PROTO',
'');
return !empty($serverForwarderProtoVar) &&
strtolower($serverForwarderProtoVar) === 'https';
}
/**
* Sets the session for the application to use, if required.
*
* @param Session $session A session object.
*
* @return AbstractWebApplication Returns itself to support chaining.
*
* @since 1.0
*/
public function setSession(Session $session)
{
$this->session = $session;
return $this;
}
/**
* Method to load the system URI strings for the application.
*
* @param string $requestUri An optional request URI to use instead of
detecting one from the
* server environment variables.
*
* @return void
*
* @since 1.0
*/
protected function loadSystemUris($requestUri = null)
{
// Set the request URI.
// @codeCoverageIgnoreStart
if (!empty($requestUri))
{
$this->set('uri.request', $requestUri);
}
else
{
$this->set('uri.request', $this->detectRequestUri());
}
// @codeCoverageIgnoreEnd
// Check to see if an explicit base URI has been set.
$siteUri = trim($this->get('site_uri'));
if ($siteUri != '')
{
$uri = new Uri($siteUri);
$path = $uri->toString(array('path'));
}
else
{
// No explicit base URI was set so we need to detect it. Start with the
requested URI.
$uri = new Uri($this->get('uri.request'));
$requestUri =
$this->input->server->getString('REQUEST_URI',
'');
// If we are working from a CGI SAPI with the
'cgi.fix_pathinfo' directive disabled we use PHP_SELF.
if (strpos(PHP_SAPI, 'cgi') !== false &&
!ini_get('cgi.fix_pathinfo') && !empty($requestUri))
{
// We aren't expecting PATH_INFO within PHP_SELF so this should
work.
$path =
\dirname($this->input->server->getString('PHP_SELF',
''));
}
else
{
// Pretty much everything else should be handled with SCRIPT_NAME.
$path =
\dirname($this->input->server->getString('SCRIPT_NAME',
''));
}
}
// Get the host from the URI.
$host = $uri->toString(array('scheme', 'user',
'pass', 'host', 'port'));
// Check if the path includes "index.php".
if (strpos($path, 'index.php') !== false)
{
// Remove the index.php portion of the path.
$path = substr_replace($path, '', strpos($path,
'index.php'), 9);
}
$path = rtrim($path, '/\\');
// Set the base URI both as just a path and as the full URI.
$this->set('uri.base.full', $host . $path . '/');
$this->set('uri.base.host', $host);
$this->set('uri.base.path', $path . '/');
// Set the extended (non-base) part of the request URI as the route.
if (stripos($this->get('uri.request'),
$this->get('uri.base.full')) === 0)
{
$this->set('uri.route',
substr_replace($this->get('uri.request'), '', 0,
\strlen($this->get('uri.base.full'))));
}
// Get an explicitly set media URI is present.
$mediaURI = trim($this->get('media_uri'));
if ($mediaURI)
{
if (strpos($mediaURI, '://') !== false)
{
$this->set('uri.media.full', $mediaURI);
$this->set('uri.media.path', $mediaURI);
}
else
{
// Normalise slashes.
$mediaURI = trim($mediaURI, '/\\');
$mediaURI = !empty($mediaURI) ? '/' . $mediaURI .
'/' : '/';
$this->set('uri.media.full',
$this->get('uri.base.host') . $mediaURI);
$this->set('uri.media.path', $mediaURI);
}
}
else
{
// No explicit media URI was set, build it dynamically from the base
uri.
$this->set('uri.media.full',
$this->get('uri.base.full') . 'media/');
$this->set('uri.media.path',
$this->get('uri.base.path') . 'media/');
}
}
/**
* Checks for a form token in the request.
*
* Use in conjunction with getFormToken.
*
* @param string $method The request method in which to look for the
token key.
*
* @return boolean True if found and valid, false otherwise.
*
* @since 1.0
*/
public function checkToken($method = 'post')
{
$token = $this->getFormToken();
if (!$this->input->$method->get($token, '',
'alnum'))
{
if ($this->getSession()->isNew())
{
// Redirect to login screen.
$this->redirect('index.php');
$this->close();
}
else
{
return false;
}
}
else
{
return true;
}
}
/**
* Method to determine a hash for anti-spoofing variable names
*
* @param boolean $forceNew If true, force a new token to be created
*
* @return string Hashed var name
*
* @since 1.0
*/
public function getFormToken($forceNew = false)
{
// @todo we need the user id somehow here
$userId = 0;
return md5($this->get('secret') . $userId .
$this->getSession()->getToken($forceNew));
}
/**
* Tests whether a string contains only 7bit ASCII bytes.
*
* You might use this to conditionally check whether a string
* needs handling as UTF-8 or not, potentially offering performance
* benefits by using the native PHP equivalent if it's just ASCII
e.g.;
*
* @param string $str The string to test.
*
* @return boolean True if the string is all ASCII
*
* @since 1.4.0
*/
public static function isAscii($str)
{
// Search for any bytes which are outside the ASCII range...
return preg_match('/(?:[^\x00-\x7F])/', $str) !== 1;
}
}
PK`;�[�ttCli/CliInput.phpnu�[���<?php
/**
* Part of the Joomla Framework Application Package
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All
rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\Application\Cli;
/**
* Class CliInput
*
* @since 1.6.0
* @deprecated 2.0 Use the `joomla/console` package instead
*/
class CliInput
{
/**
* Get a value from standard input.
*
* @return string The input string from standard input.
*
* @codeCoverageIgnore
* @since 1.6.0
*/
public function in()
{
return rtrim(fread(STDIN, 8192), "\n\r");
}
}
PK`;�[3s�JCli/CliOutput.phpnu�[���<?php
/**
* Part of the Joomla Framework Application Package
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All
rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\Application\Cli;
use Joomla\Application\Cli\Output\Processor\ProcessorInterface;
/**
* Class CliOutput
*
* @since 1.0
* @deprecated 2.0 Use the `joomla/console` package instead
*/
abstract class CliOutput
{
/**
* Color processing object
*
* @var ProcessorInterface
* @since 1.0
*/
protected $processor;
/**
* Constructor
*
* @param ProcessorInterface $processor The output processor.
*
* @since 1.1.2
*/
public function __construct(ProcessorInterface $processor = null)
{
$this->setProcessor(($processor instanceof ProcessorInterface) ?
$processor : new Output\Processor\ColorProcessor);
}
/**
* Set a processor
*
* @param ProcessorInterface $processor The output processor.
*
* @return Stdout Instance of $this to allow chaining.
*
* @since 1.0
*/
public function setProcessor(ProcessorInterface $processor)
{
$this->processor = $processor;
return $this;
}
/**
* Get a processor
*
* @return ProcessorInterface
*
* @since 1.0
* @throws \RuntimeException
*/
public function getProcessor()
{
if ($this->processor)
{
return $this->processor;
}
throw new \RuntimeException('A ProcessorInterface object has not
been set.');
}
/**
* Write a string to an output handler.
*
* @param string $text The text to display.
* @param boolean $nl True (default) to append a new line at the end
of the output string.
*
* @return void
*
* @since 1.0
* @codeCoverageIgnore
*/
abstract public function out($text = '', $nl = true);
}
PK`;�[~��u Cli/ColorProcessor.phpnu�[���<?php
/**
* Part of the Joomla Framework Application Package
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All
rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\Application\Cli;
use \Joomla\Application\Cli\Output\Processor\ColorProcessor as
RealColorProcessor;
/**
* Class ColorProcessor.
*
* @since 1.0
* @deprecated 2.0 Use the `joomla/console` package instead
*/
class ColorProcessor extends RealColorProcessor
{
}
PK`;�[MS�**Cli/ColorStyle.phpnu�[���<?php
/**
* Part of the Joomla Framework Application Package
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All
rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\Application\Cli;
/**
* Class ColorStyle
*
* @since 1.0
* @deprecated 2.0 Use the `joomla/console` package instead
*/
final class ColorStyle
{
/**
* Known colors
*
* @var array
* @since 1.0
*/
private static $knownColors = array(
'black' => 0,
'red' => 1,
'green' => 2,
'yellow' => 3,
'blue' => 4,
'magenta' => 5,
'cyan' => 6,
'white' => 7,
);
/**
* Known styles
*
* @var array
* @since 1.0
*/
private static $knownOptions = array(
'bold' => 1,
'underscore' => 4,
'blink' => 5,
'reverse' => 7,
);
/**
* Foreground base value
*
* @var integer
* @since 1.0
*/
private static $fgBase = 30;
/**
* Background base value
*
* @var integer
* @since 1.0
*/
private static $bgBase = 40;
/**
* Foreground color
*
* @var integer
* @since 1.0
*/
private $fgColor = 0;
/**
* Background color
*
* @var integer
* @since 1.0
*/
private $bgColor = 0;
/**
* Array of style options
*
* @var array
* @since 1.0
*/
private $options = array();
/**
* Constructor
*
* @param string $fg Foreground color.
* @param string $bg Background color.
* @param array $options Style options.
*
* @since 1.0
* @throws \InvalidArgumentException
*/
public function __construct($fg = '', $bg = '',
$options = array())
{
if ($fg)
{
if (array_key_exists($fg, static::$knownColors) == false)
{
throw new \InvalidArgumentException(
sprintf('Invalid foreground color "%1$s" [%2$s]',
$fg,
implode(', ', $this->getKnownColors())
)
);
}
$this->fgColor = static::$fgBase + static::$knownColors[$fg];
}
if ($bg)
{
if (array_key_exists($bg, static::$knownColors) == false)
{
throw new \InvalidArgumentException(
sprintf('Invalid background color "%1$s" [%2$s]',
$bg,
implode(', ', $this->getKnownColors())
)
);
}
$this->bgColor = static::$bgBase + static::$knownColors[$bg];
}
foreach ($options as $option)
{
if (array_key_exists($option, static::$knownOptions) == false)
{
throw new \InvalidArgumentException(
sprintf('Invalid option "%1$s" [%2$s]',
$option,
implode(', ', $this->getKnownOptions())
)
);
}
$this->options[] = $option;
}
}
/**
* Convert to a string.
*
* @return string
*
* @since 1.0
*/
public function __toString()
{
return $this->getStyle();
}
/**
* Create a color style from a parameter string.
*
* Example: fg=red;bg=blue;options=bold,blink
*
* @param string $string The parameter string.
*
* @return ColorStyle Instance of $this to allow chaining.
*
* @since 1.0
* @throws \RuntimeException
*/
public static function fromString($string)
{
$fg = '';
$bg = '';
$options = array();
$parts = explode(';', $string);
foreach ($parts as $part)
{
$subParts = explode('=', $part);
if (\count($subParts) < 2)
{
continue;
}
switch ($subParts[0])
{
case 'fg':
$fg = $subParts[1];
break;
case 'bg':
$bg = $subParts[1];
break;
case 'options':
$options = explode(',', $subParts[1]);
break;
default:
throw new \RuntimeException('Invalid option');
break;
}
}
return new self($fg, $bg, $options);
}
/**
* Get the translated color code.
*
* @return string
*
* @since 1.0
*/
public function getStyle()
{
$values = array();
if ($this->fgColor)
{
$values[] = $this->fgColor;
}
if ($this->bgColor)
{
$values[] = $this->bgColor;
}
foreach ($this->options as $option)
{
$values[] = static::$knownOptions[$option];
}
return implode(';', $values);
}
/**
* Get the known colors.
*
* @return string
*
* @since 1.0
*/
public function getKnownColors()
{
return array_keys(static::$knownColors);
}
/**
* Get the known options.
*
* @return array
*
* @since 1.0
*/
public function getKnownOptions()
{
return array_keys(static::$knownOptions);
}
}
PK`;�[h#�ff'Cli/Output/Processor/ColorProcessor.phpnu�[���<?php
/**
* Part of the Joomla Framework Application Package
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All
rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\Application\Cli\Output\Processor;
use Joomla\Application\Cli\ColorStyle;
use Joomla\Application\Cli\Output\Stdout;
/**
* Class ColorProcessor.
*
* @since 1.0
* @deprecated 2.0 Use the `joomla/console` package instead
*/
class ColorProcessor implements ProcessorInterface
{
/**
* Flag to remove color codes from the output
*
* @var boolean
* @since 1.0
*/
public $noColors = false;
/**
* Regex to match tags
*
* @var string
* @since 1.0
*/
protected $tagFilter =
'/<([a-z=;]+)>(.*?)<\/\\1>/s';
/**
* Regex used for removing color codes
*
* @var string
* @since 1.0
*/
protected static $stripFilter = '/<[\/]?[a-z=;]+>/';
/**
* Array of ColorStyle objects
*
* @var array
* @since 1.0
*/
protected $styles = array();
/**
* Class constructor
*
* @param boolean $noColors Defines non-colored mode on construct
*
* @since 1.1.0
*/
public function __construct($noColors = null)
{
if ($noColors === null)
{
/*
* By default windows cmd.exe and PowerShell does not support
ANSI-colored output
* if the variable is not set explicitly colors should be disabled on
Windows
*/
$noColors = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN');
}
$this->noColors = $noColors;
$this->addPredefinedStyles();
}
/**
* Add a style.
*
* @param string $name The style name.
* @param ColorStyle $style The color style.
*
* @return ColorProcessor Instance of $this to allow chaining.
*
* @since 1.0
*/
public function addStyle($name, ColorStyle $style)
{
$this->styles[$name] = $style;
return $this;
}
/**
* Strip color tags from a string.
*
* @param string $string The string.
*
* @return string
*
* @since 1.0
*/
public static function stripColors($string)
{
return preg_replace(static::$stripFilter, '', $string);
}
/**
* Process a string.
*
* @param string $string The string to process.
*
* @return string
*
* @since 1.0
*/
public function process($string)
{
preg_match_all($this->tagFilter, $string, $matches);
if (!$matches)
{
return $string;
}
foreach ($matches[0] as $i => $m)
{
if (array_key_exists($matches[1][$i], $this->styles))
{
$string = $this->replaceColors($string, $matches[1][$i],
$matches[2][$i], $this->styles[$matches[1][$i]]);
}
// Custom format
elseif (strpos($matches[1][$i], '='))
{
$string = $this->replaceColors($string, $matches[1][$i],
$matches[2][$i], ColorStyle::fromString($matches[1][$i]));
}
}
return $string;
}
/**
* Replace color tags in a string.
*
* @param string $text The original text.
* @param string $tag The matched tag.
* @param string $match The match.
* @param ColorStyle $style The color style to apply.
*
* @return mixed
*
* @since 1.0
*/
private function replaceColors($text, $tag, $match, Colorstyle $style)
{
$replace = $this->noColors
? $match
: "\033[" . $style . 'm' . $match .
"\033[0m";
return str_replace('<' . $tag . '>' . $match .
'</' . $tag . '>', $replace, $text);
}
/**
* Adds predefined color styles to the ColorProcessor object
*
* @return Stdout Instance of $this to allow chaining.
*
* @since 1.0
*/
private function addPredefinedStyles()
{
$this->addStyle(
'info',
new ColorStyle('green', '', array('bold'))
);
$this->addStyle(
'comment',
new ColorStyle('yellow', '',
array('bold'))
);
$this->addStyle(
'question',
new ColorStyle('black', 'cyan')
);
$this->addStyle(
'error',
new ColorStyle('white', 'red')
);
return $this;
}
}
PK`;�[?<N}}+Cli/Output/Processor/ProcessorInterface.phpnu�[���<?php
/**
* Part of the Joomla Framework Application Package
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All
rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\Application\Cli\Output\Processor;
/**
* Class ProcessorInterface.
*
* @since 1.1.0
* @deprecated 2.0 Use the `joomla/console` package instead
*/
interface ProcessorInterface
{
/**
* Process the provided output into a string.
*
* @param string $output The string to process.
*
* @return string
*
* @since 1.1.0
*/
public function process($output);
}
PK`;�[�����Cli/Output/Stdout.phpnu�[���<?php
/**
* Part of the Joomla Framework Application Package
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All
rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\Application\Cli\Output;
use Joomla\Application\Cli\CliOutput;
/**
* Class Stdout.
*
* @since 1.0
* @deprecated 2.0 Use the `joomla/console` package instead
*/
class Stdout extends CliOutput
{
/**
* Write a string to standard output
*
* @param string $text The text to display.
* @param boolean $nl True (default) to append a new line at the end
of the output string.
*
* @return Stdout Instance of $this to allow chaining.
*
* @codeCoverageIgnore
* @since 1.0
*/
public function out($text = '', $nl = true)
{
fwrite(STDOUT, $this->getProcessor()->process($text) . ($nl ?
"\n" : null));
return $this;
}
}
PK`;�[��6�QQCli/Output/Xml.phpnu�[���<?php
/**
* Part of the Joomla Framework Application Package
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All
rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\Application\Cli\Output;
use Joomla\Application\Cli\CliOutput;
/**
* Class Xml.
*
* @since 1.0
* @deprecated 2.0 Use the `joomla/console` package instead
*/
class Xml extends CliOutput
{
/**
* Write a string to standard output.
*
* @param string $text The text to display.
* @param boolean $nl True (default) to append a new line at the end
of the output string.
*
* @return void
*
* @since 1.0
* @throws \RuntimeException
* @codeCoverageIgnore
*/
public function out($text = '', $nl = true)
{
fwrite(STDOUT, $text . ($nl ? "\n" : null));
}
}
PK`;�[��u:B:BWeb/WebClient.phpnu�[���<?php
/**
* Part of the Joomla Framework Application Package
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All
rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\Application\Web;
/**
* Class to model a Web Client.
*
* @property-read integer $platform The detected platform on which
the web client runs.
* @property-read boolean $mobile True if the web client is a
mobile device.
* @property-read integer $engine The detected rendering engine
used by the web client.
* @property-read integer $browser The detected browser used by
the web client.
* @property-read string $browserVersion The detected browser version
used by the web client.
* @property-read array $languages The priority order detected
accepted languages for the client.
* @property-read array $encodings The priority order detected
accepted encodings for the client.
* @property-read string $userAgent The web client's user
agent string.
* @property-read string $acceptEncoding The web client's accepted
encoding string.
* @property-read string $acceptLanguage The web client's accepted
languages string.
* @property-read array $detection An array of flags determining
whether or not a detection routine has been run.
* @property-read boolean $robot True if the web client is a
robot
* @property-read array $headers An array of all headers sent
by client
*
* @since 1.0
*/
class WebClient
{
const WINDOWS = 1;
const WINDOWS_PHONE = 2;
const WINDOWS_CE = 3;
const IPHONE = 4;
const IPAD = 5;
const IPOD = 6;
const MAC = 7;
const BLACKBERRY = 8;
const ANDROID = 9;
const LINUX = 10;
const TRIDENT = 11;
const WEBKIT = 12;
const GECKO = 13;
const PRESTO = 14;
const KHTML = 15;
const AMAYA = 16;
const IE = 17;
const FIREFOX = 18;
const CHROME = 19;
const SAFARI = 20;
const OPERA = 21;
const ANDROIDTABLET = 22;
const EDGE = 23;
const BLINK = 24;
const EDG = 25;
/**
* @var integer The detected platform on which the web client runs.
* @since 1.0
*/
protected $platform;
/**
* @var boolean True if the web client is a mobile device.
* @since 1.0
*/
protected $mobile = false;
/**
* @var integer The detected rendering engine used by the web client.
* @since 1.0
*/
protected $engine;
/**
* @var integer The detected browser used by the web client.
* @since 1.0
*/
protected $browser;
/**
* @var string The detected browser version used by the web client.
* @since 1.0
*/
protected $browserVersion;
/**
* @var array The priority order detected accepted languages for the
client.
* @since 1.0
*/
protected $languages = array();
/**
* @var array The priority order detected accepted encodings for the
client.
* @since 1.0
*/
protected $encodings = array();
/**
* @var string The web client's user agent string.
* @since 1.0
*/
protected $userAgent;
/**
* @var string The web client's accepted encoding string.
* @since 1.0
*/
protected $acceptEncoding;
/**
* @var string The web client's accepted languages string.
* @since 1.0
*/
protected $acceptLanguage;
/**
* @var boolean True if the web client is a robot.
* @since 1.0
*/
protected $robot = false;
/**
* @var array An array of flags determining whether or not a detection
routine has been run.
* @since 1.0
*/
protected $detection = array();
/**
* @var array An array of headers sent by client
* @since 1.3.0
*/
protected $headers;
/**
* Class constructor.
*
* @param string $userAgent The optional user-agent string to
parse.
* @param string $acceptEncoding The optional client accept encoding
string to parse.
* @param string $acceptLanguage The optional client accept language
string to parse.
*
* @since 1.0
*/
public function __construct($userAgent = null, $acceptEncoding = null,
$acceptLanguage = null)
{
// If no explicit user agent string was given attempt to use the implicit
one from server environment.
if (empty($userAgent) &&
isset($_SERVER['HTTP_USER_AGENT']))
{
$this->userAgent = $_SERVER['HTTP_USER_AGENT'];
}
else
{
$this->userAgent = $userAgent;
}
// If no explicit acceptable encoding string was given attempt to use the
implicit one from server environment.
if (empty($acceptEncoding) &&
isset($_SERVER['HTTP_ACCEPT_ENCODING']))
{
$this->acceptEncoding = $_SERVER['HTTP_ACCEPT_ENCODING'];
}
else
{
$this->acceptEncoding = $acceptEncoding;
}
// If no explicit acceptable languages string was given attempt to use
the implicit one from server environment.
if (empty($acceptLanguage) &&
isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
{
$this->acceptLanguage = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
}
else
{
$this->acceptLanguage = $acceptLanguage;
}
}
/**
* Magic method to get an object property's value by name.
*
* @param string $name Name of the property for which to return a
value.
*
* @return mixed The requested value if it exists.
*
* @since 1.0
*/
public function __get($name)
{
switch ($name)
{
case 'mobile':
case 'platform':
if (empty($this->detection['platform']))
{
$this->detectPlatform($this->userAgent);
}
break;
case 'engine':
if (empty($this->detection['engine']))
{
$this->detectEngine($this->userAgent);
}
break;
case 'browser':
case 'browserVersion':
if (empty($this->detection['browser']))
{
$this->detectBrowser($this->userAgent);
}
break;
case 'languages':
if (empty($this->detection['acceptLanguage']))
{
$this->detectLanguage($this->acceptLanguage);
}
break;
case 'encodings':
if (empty($this->detection['acceptEncoding']))
{
$this->detectEncoding($this->acceptEncoding);
}
break;
case 'robot':
if (empty($this->detection['robot']))
{
$this->detectRobot($this->userAgent);
}
break;
case 'headers':
if (empty($this->detection['headers']))
{
$this->detectHeaders();
}
break;
}
// Return the property if it exists.
if (isset($this->$name))
{
return $this->$name;
}
}
/**
* Detects the client browser and version in a user agent string.
*
* @param string $userAgent The user-agent string to parse.
*
* @return void
*
* @since 1.0
*/
protected function detectBrowser($userAgent)
{
// Attempt to detect the browser type. Obviously we are only worried
about major browsers.
if ((stripos($userAgent, 'MSIE') !== false) &&
(stripos($userAgent, 'Opera') === false))
{
$this->browser = self::IE;
$patternBrowser = 'MSIE';
}
elseif (stripos($userAgent, 'Trident') !== false)
{
$this->browser = self::IE;
$patternBrowser = ' rv';
}
elseif (stripos($userAgent, 'Edge') !== false)
{
$this->browser = self::EDGE;
$patternBrowser = 'Edge';
}
elseif (stripos($userAgent, 'Edg') !== false)
{
$this->browser = self::EDG;
$patternBrowser = 'Edg';
}
elseif ((stripos($userAgent, 'Firefox') !== false) &&
(stripos($userAgent, 'like Firefox') === false))
{
$this->browser = self::FIREFOX;
$patternBrowser = 'Firefox';
}
elseif (stripos($userAgent, 'OPR') !== false)
{
$this->browser = self::OPERA;
$patternBrowser = 'OPR';
}
elseif (stripos($userAgent, 'Chrome') !== false)
{
$this->browser = self::CHROME;
$patternBrowser = 'Chrome';
}
elseif (stripos($userAgent, 'Safari') !== false)
{
$this->browser = self::SAFARI;
$patternBrowser = 'Safari';
}
elseif (stripos($userAgent, 'Opera') !== false)
{
$this->browser = self::OPERA;
$patternBrowser = 'Opera';
}
// If we detected a known browser let's attempt to determine the
version.
if ($this->browser)
{
// Build the REGEX pattern to match the browser version string within
the user agent string.
$pattern = '#(?<browser>Version|' . $patternBrowser .
')[/ :]+(?<version>[0-9.|a-zA-Z.]*)#';
// Attempt to find version strings in the user agent string.
$matches = array();
if (preg_match_all($pattern, $userAgent, $matches))
{
// Do we have both a Version and browser match?
if (\count($matches['browser']) == 2)
{
// See whether Version or browser came first, and use the number
accordingly.
if (strripos($userAgent, 'Version') <
strripos($userAgent, $patternBrowser))
{
$this->browserVersion = $matches['version'][0];
}
else
{
$this->browserVersion = $matches['version'][1];
}
}
elseif (\count($matches['browser']) > 2)
{
$key = array_search('Version',
$matches['browser']);
if ($key)
{
$this->browserVersion = $matches['version'][$key];
}
}
else
{
// We only have a Version or a browser so use what we have.
$this->browserVersion = $matches['version'][0];
}
}
}
// Mark this detection routine as run.
$this->detection['browser'] = true;
}
/**
* Method to detect the accepted response encoding by the client.
*
* @param string $acceptEncoding The client accept encoding string to
parse.
*
* @return void
*
* @since 1.0
*/
protected function detectEncoding($acceptEncoding)
{
// Parse the accepted encodings.
$this->encodings = array_map('trim', (array)
explode(',', $acceptEncoding));
// Mark this detection routine as run.
$this->detection['acceptEncoding'] = true;
}
/**
* Detects the client rendering engine in a user agent string.
*
* @param string $userAgent The user-agent string to parse.
*
* @return void
*
* @since 1.0
*/
protected function detectEngine($userAgent)
{
if (stripos($userAgent, 'MSIE') !== false ||
stripos($userAgent, 'Trident') !== false)
{
// Attempt to detect the client engine -- starting with the most popular
... for now.
$this->engine = self::TRIDENT;
}
elseif (stripos($userAgent, 'Edge') !== false ||
stripos($userAgent, 'EdgeHTML') !== false)
{
$this->engine = self::EDGE;
}
elseif (stripos($userAgent, 'Edg') !== false)
{
$this->engine = self::BLINK;
}
elseif (stripos($userAgent, 'Chrome') !== false)
{
$result = explode('/', stristr($userAgent,
'Chrome'));
$version = explode(' ', $result[1]);
if ($version[0] >= 28)
{
$this->engine = self::BLINK;
}
else
{
$this->engine = self::WEBKIT;
}
}
elseif (stripos($userAgent, 'AppleWebKit') !== false ||
stripos($userAgent, 'blackberry') !== false)
{
if (stripos($userAgent, 'AppleWebKit') !== false)
{
$result = explode('/', stristr($userAgent,
'AppleWebKit'));
$version = explode(' ', $result[1]);
if ($version[0] === 537.36)
{
// AppleWebKit/537.36 is Blink engine specific, exception is Blink
emulated IEMobile, Trident or Edge
$this->engine = self::BLINK;
}
}
// Evidently blackberry uses WebKit and doesn't necessarily report
it. Bad RIM.
$this->engine = self::WEBKIT;
}
elseif (stripos($userAgent, 'Gecko') !== false &&
stripos($userAgent, 'like Gecko') === false)
{
// We have to check for like Gecko because some other browsers spoof
Gecko.
$this->engine = self::GECKO;
}
elseif (stripos($userAgent, 'Opera') !== false ||
stripos($userAgent, 'Presto') !== false)
{
$version = false;
if (preg_match('/Opera[\/| ]?([0-9.]+)/u', $userAgent,
$match))
{
$version = \floatval($match[1]);
}
if (preg_match('/Version\/([0-9.]+)/u', $userAgent, $match))
{
if (\floatval($match[1]) >= 10)
{
$version = \floatval($match[1]);
}
}
if ($version !== false && $version >= 15)
{
$this->engine = self::BLINK;
}
else
{
$this->engine = self::PRESTO;
}
}
elseif (stripos($userAgent, 'KHTML') !== false)
{
// *sigh*
$this->engine = self::KHTML;
}
elseif (stripos($userAgent, 'Amaya') !== false)
{
// Lesser known engine but it finishes off the major list from Wikipedia
:-)
$this->engine = self::AMAYA;
}
// Mark this detection routine as run.
$this->detection['engine'] = true;
}
/**
* Method to detect the accepted languages by the client.
*
* @param mixed $acceptLanguage The client accept language string to
parse.
*
* @return void
*
* @since 1.0
*/
protected function detectLanguage($acceptLanguage)
{
// Parse the accepted encodings.
$this->languages = array_map('trim', (array)
explode(',', $acceptLanguage));
// Mark this detection routine as run.
$this->detection['acceptLanguage'] = true;
}
/**
* Detects the client platform in a user agent string.
*
* @param string $userAgent The user-agent string to parse.
*
* @return void
*
* @since 1.0
*/
protected function detectPlatform($userAgent)
{
// Attempt to detect the client platform.
if (stripos($userAgent, 'Windows') !== false)
{
$this->platform = self::WINDOWS;
// Let's look at the specific mobile options in the Windows space.
if (stripos($userAgent, 'Windows Phone') !== false)
{
$this->mobile = true;
$this->platform = self::WINDOWS_PHONE;
}
elseif (stripos($userAgent, 'Windows CE') !== false)
{
$this->mobile = true;
$this->platform = self::WINDOWS_CE;
}
}
elseif (stripos($userAgent, 'iPhone') !== false)
{
// Interestingly 'iPhone' is present in all iOS devices so far
including iPad and iPods.
$this->mobile = true;
$this->platform = self::IPHONE;
// Let's look at the specific mobile options in the iOS space.
if (stripos($userAgent, 'iPad') !== false)
{
$this->platform = self::IPAD;
}
elseif (stripos($userAgent, 'iPod') !== false)
{
$this->platform = self::IPOD;
}
}
elseif (stripos($userAgent, 'iPad') !== false)
{
// In case where iPhone is not mentioed in iPad user agent string
$this->mobile = true;
$this->platform = self::IPAD;
}
elseif (stripos($userAgent, 'iPod') !== false)
{
// In case where iPhone is not mentioed in iPod user agent string
$this->mobile = true;
$this->platform = self::IPOD;
}
elseif (preg_match('/macintosh|mac os x/i', $userAgent))
{
// This has to come after the iPhone check because mac strings are also
present in iOS devices.
$this->platform = self::MAC;
}
elseif (stripos($userAgent, 'Blackberry') !== false)
{
$this->mobile = true;
$this->platform = self::BLACKBERRY;
}
elseif (stripos($userAgent, 'Android') !== false)
{
$this->mobile = true;
$this->platform = self::ANDROID;
/**
* Attempt to distinguish between Android phones and tablets
* There is no totally foolproof method but certain rules almost always
hold
* Android 3.x is only used for tablets
* Some devices and browsers encourage users to change their UA string
to include Tablet.
* Google encourages manufacturers to exclude the string Mobile from
tablet device UA strings.
* In some modes Kindle Android devices include the string Mobile but
they include the string Silk.
*/
if (stripos($userAgent, 'Android 3') !== false ||
stripos($userAgent, 'Tablet') !== false
|| stripos($userAgent, 'Mobile') === false ||
stripos($userAgent, 'Silk') !== false)
{
$this->platform = self::ANDROIDTABLET;
}
}
elseif (stripos($userAgent, 'Linux') !== false)
{
$this->platform = self::LINUX;
}
// Mark this detection routine as run.
$this->detection['platform'] = true;
}
/**
* Determines if the browser is a robot or not.
*
* @param string $userAgent The user-agent string to parse.
*
* @return void
*
* @since 1.0
*/
protected function detectRobot($userAgent)
{
if
(preg_match('/http|bot|bingbot|googlebot|robot|spider|slurp|crawler|curl|^$/i',
$userAgent))
{
$this->robot = true;
}
else
{
$this->robot = false;
}
$this->detection['robot'] = true;
}
/**
* Fills internal array of headers
*
* @return void
*
* @since 1.3.0
*/
protected function detectHeaders()
{
if (\function_exists('getallheaders'))
{
// If php is working under Apache, there is a special function
$this->headers = getallheaders();
}
else
{
// Else we fill headers from $_SERVER variable
$this->headers = array();
foreach ($_SERVER as $name => $value)
{
if (substr($name, 0, 5) == 'HTTP_')
{
$this->headers[str_replace(' ', '-',
ucwords(strtolower(str_replace('_', ' ', substr($name,
5)))))] = $value;
}
}
}
// Mark this detection routine as run.
$this->detection['headers'] = true;
}
}
PK�(�[��n��<�<Extension/Featuring.phpnu�[���<?php
/**
* @package Joomla.Plugin
* @subpackage Workflow.featuring
*
* @copyright (C) 2020 Open Source Matters, Inc.
<https://www.joomla.org>
* @license GNU General Public License version 2 or later; see
LICENSE.txt
*/
namespace Joomla\Plugin\Workflow\Featuring\Extension;
use Joomla\CMS\Event\AbstractEvent;
use Joomla\CMS\Event\Model;
use Joomla\CMS\Event\Table\BeforeStoreEvent;
use Joomla\CMS\Event\View\DisplayEvent;
use Joomla\CMS\Event\Workflow\WorkflowFunctionalityUsedEvent;
use Joomla\CMS\Event\Workflow\WorkflowTransitionEvent;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Model\DatabaseModelInterface;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Table\ContentHistory;
use Joomla\CMS\Table\TableInterface;
use Joomla\CMS\Workflow\WorkflowPluginTrait;
use Joomla\CMS\Workflow\WorkflowServiceInterface;
use Joomla\Component\Content\Administrator\Event\Model\FeatureEvent;
use Joomla\Event\EventInterface;
use Joomla\Event\SubscriberInterface;
use Joomla\Registry\Registry;
use Joomla\String\Inflector;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Workflow Featuring Plugin
*
* @since 4.0.0
*/
final class Featuring extends CMSPlugin implements SubscriberInterface
{
use WorkflowPluginTrait;
/**
* Load the language file on instantiation.
*
* @var boolean
* @since 4.0.0
*/
protected $autoloadLanguage = true;
/**
* The name of the supported functionality to check against
*
* @var string
* @since 4.0.0
*/
protected $supportFunctionality = 'core.featured';
/**
* Returns an array of events this subscriber will listen to.
*
* @return array
*
* @since 4.0.0
*/
public static function getSubscribedEvents(): array
{
return [
'onAfterDisplay' =>
'onAfterDisplay',
'onContentBeforeChangeFeatured' =>
'onContentBeforeChangeFeatured',
'onContentBeforeSave' =>
'onContentBeforeSave',
'onContentPrepareForm' =>
'onContentPrepareForm',
'onContentVersioningPrepareTable' =>
'onContentVersioningPrepareTable',
'onTableBeforeStore' =>
'onTableBeforeStore',
'onWorkflowAfterTransition' =>
'onWorkflowAfterTransition',
'onWorkflowBeforeTransition' =>
'onWorkflowBeforeTransition',
'onWorkflowFunctionalityUsed' =>
'onWorkflowFunctionalityUsed',
];
}
/**
* The form event.
*
* @param Model\PrepareFormEvent $event The event
*
* @since 4.0.0
*/
public function onContentPrepareForm(Model\PrepareFormEvent $event)
{
$form = $event->getForm();
$data = $event->getData();
$context = $form->getName();
// Extend the transition form
if ($context === 'com_workflow.transition') {
$this->enhanceWorkflowTransitionForm($form, $data);
return;
}
$this->enhanceItemForm($form, $data);
}
/**
* Disable certain fields in the item form view, when we want to take
over this function in the transition
* Check also for the workflow implementation and if the field exists
*
* @param Form $form The form
* @param object $data The data
*
* @return boolean
*
* @since 4.0.0
*/
protected function enhanceItemForm(Form $form, $data)
{
$context = $form->getName();
if (!$this->isSupported($context)) {
return true;
}
$parts = explode('.', $context);
$component =
$this->getApplication()->bootComponent($parts[0]);
$modelName = $component->getModelName($context);
$table = $component->getMVCFactory()->createModel($modelName,
$this->getApplication()->getName(), ['ignore_request' =>
true])
->getTable();
$fieldname = $table->getColumnAlias('featured');
$options = $form->getField($fieldname)->options;
$value = $data->$fieldname ?? $form->getValue($fieldname,
null, 0);
$text = '-';
$textclass = 'body';
switch ($value) {
case 1:
$textclass = 'success';
break;
case 0:
case -2:
$textclass = 'danger';
}
if (!empty($options)) {
foreach ($options as $option) {
if ($option->value == $value) {
$text = $option->text;
break;
}
}
}
$form->setFieldAttribute($fieldname, 'type',
'spacer');
$label = '<span class="text-' . $textclass .
'">' . htmlentities($text, ENT_COMPAT, 'UTF-8')
. '</span>';
$form->setFieldAttribute(
$fieldname,
'label',
Text::sprintf('PLG_WORKFLOW_FEATURING_FEATURED',
$label)
);
return true;
}
/**
* Manipulate the generic list view
*
* @param DisplayEvent $event
*
* @return void
*
* @since 4.0.0
*/
public function onAfterDisplay(DisplayEvent $event)
{
if
(!$this->getApplication()->isClient('administrator')) {
return;
}
$component = $event->getArgument('extensionName');
$section = $event->getArgument('section');
// We need the single model context for checking for workflow
$singularsection = Inflector::singularize($section);
if (!$this->isSupported($component . '.' .
$singularsection)) {
return;
}
// List of related batch functions we need to hide
$states = [
'featured',
'unfeatured',
];
$js = "
document.addEventListener('DOMContentLoaded', function()
{
var dropdown =
document.getElementById('toolbar-status-group');
if (!dropdown)
{
return;
}
" . json_encode($states) . ".forEach((action) => {
var button =
document.getElementById('status-group-children-' + action);
if (button)
{
button.classList.add('d-none');
}
});
});
";
$this->getApplication()->getDocument()->addScriptDeclaration($js);
}
/**
* Check if we can execute the transition
*
* @param WorkflowTransitionEvent $event
*
* @return boolean
*
* @since 4.0.0
*/
public function onWorkflowBeforeTransition(WorkflowTransitionEvent
$event)
{
$context = $event->getArgument('extension');
$transition = $event->getArgument('transition');
$pks = $event->getArgument('pks');
if (!$this->isSupported($context) ||
!is_numeric($transition->options->get('featuring'))) {
return true;
}
$value = $transition->options->get('featuring');
if (!is_numeric($value)) {
return true;
}
/**
* Here it becomes tricky. We would like to use the component
models featured method, so we will
* Execute the normal "onContentBeforeChangeFeatured"
plugins. But they could cancel the execution,
* So we have to precheck and cancel the whole transition stuff if
not allowed.
*/
$this->getApplication()->set('plgWorkflowFeaturing.' .
$context, $pks);
// Trigger the change state event.
$eventResult =
$this->getApplication()->getDispatcher()->dispatch(
'onContentBeforeChangeFeatured',
AbstractEvent::create(
'onContentBeforeChangeFeatured',
[
'eventClass' =>
'Joomla\Component\Content\Administrator\Event\Model\FeatureEvent',
'subject' => $this,
'extension' => $context,
'pks' => $pks,
'value' => $value,
'abort' => false,
'abortReason' => '',
]
)
);
// Release allowed pks, the job is done
$this->getApplication()->set('plgWorkflowFeaturing.' .
$context, []);
if ($eventResult->getArgument('abort')) {
$event->setStopTransition();
return false;
}
return true;
}
/**
* Change Feature State of an item. Used to disable feature state
change
*
* @param WorkflowTransitionEvent $event
*
* @return void
*
* @since 4.0.0
*/
public function onWorkflowAfterTransition(WorkflowTransitionEvent
$event): void
{
$context = $event->getArgument('extension');
$extensionName = $event->getArgument('extensionName');
$transition = $event->getArgument('transition');
$pks = $event->getArgument('pks');
if (!$this->isSupported($context)) {
return;
}
$component =
$this->getApplication()->bootComponent($extensionName);
$value = $transition->options->get('featuring');
if (!is_numeric($value)) {
return;
}
$options = [
'ignore_request' => true,
// We already have triggered onContentBeforeChangeFeatured, so
use our own
'event_before_change_featured' =>
'onWorkflowBeforeChangeFeatured',
];
$modelName = $component->getModelName($context);
$model = $component->getMVCFactory()->createModel($modelName,
$this->getApplication()->getName(), $options);
$model->featured($pks, $value);
}
/**
* Change Feature State of an item. Used to disable Feature state
change
*
* @param FeatureEvent $event
*
* @return boolean
*
* @throws \Exception
* @since 4.0.0
*/
public function onContentBeforeChangeFeatured(FeatureEvent $event)
{
$extension = $event->getArgument('extension');
$pks = $event->getArgument('pks');
if (!$this->isSupported($extension)) {
return true;
}
// We have allowed the pks, so we're the one who triggered
// With onWorkflowBeforeTransition => free pass
if
($this->getApplication()->get('plgWorkflowFeaturing.' .
$extension) === $pks) {
return true;
}
$event->setAbort('PLG_WORKFLOW_FEATURING_CHANGE_STATE_NOT_ALLOWED');
}
/**
* The save event.
*
* @param Model\BeforeSaveEvent $event
*
* @return boolean
*
* @since 4.0.0
*/
public function onContentBeforeSave(Model\BeforeSaveEvent $event)
{
$context = $event->getContext();
if (!$this->isSupported($context)) {
return true;
}
/** @var TableInterface $table */
$table = $event->getItem();
$data = $event->getData();
$keyName = $table->getColumnAlias('featured');
// Check for the old value
$article = clone $table;
$article->load($table->id);
/**
* We don't allow the change of the feature state when we use
the workflow
* As we're setting the field to disabled, no value should be
there at all
*/
if (isset($data[$keyName])) {
$this->getApplication()->enqueueMessage(
$this->getApplication()->getLanguage()->_('PLG_WORKFLOW_FEATURING_CHANGE_STATE_NOT_ALLOWED'),
'error'
);
return false;
}
return true;
}
/**
* We remove the featured field from the versioning
*
* @param EventInterface $event
*
* @return boolean
*
* @since 4.0.0
*/
public function onContentVersioningPrepareTable(EventInterface $event)
{
$subject = $event->getArgument('subject');
$context = $event->getArgument('extension');
if (!$this->isSupported($context)) {
return true;
}
$parts = explode('.', $context);
$component =
$this->getApplication()->bootComponent($parts[0]);
$modelName = $component->getModelName($context);
$model = $component->getMVCFactory()->createModel($modelName,
$this->getApplication()->getName(), ['ignore_request' =>
true]);
$table = $model->getTable();
$subject->ignoreChanges[] =
$table->getColumnAlias('featured');
}
/**
* Pre-processor for $table->store($updateNulls)
*
* @param BeforeStoreEvent $event The event to handle
*
* @return void
*
* @since 4.0.0
*/
public function onTableBeforeStore(BeforeStoreEvent $event)
{
$subject = $event->getArgument('subject');
if (!($subject instanceof ContentHistory)) {
return;
}
$parts = explode('.', $subject->item_id);
$typeAlias = $parts[0] . (isset($parts[1]) ? '.' .
$parts[1] : '');
if (!$this->isSupported($typeAlias)) {
return;
}
$component =
$this->getApplication()->bootComponent($parts[0]);
$modelName = $component->getModelName($typeAlias);
$model = $component->getMVCFactory()->createModel($modelName,
$this->getApplication()->getName(), ['ignore_request' =>
true]);
$table = $model->getTable();
$field = $table->getColumnAlias('featured');
$versionData = new Registry($subject->version_data);
$versionData->remove($field);
$subject->version_data = $versionData->toString();
}
/**
* Check if the current plugin should execute workflow related
activities
*
* @param string $context
*
* @return boolean
*
* @since 4.0.0
*/
protected function isSupported($context)
{
if (!$this->checkAllowedAndForbiddenlist($context) ||
!$this->checkExtensionSupport($context, $this->supportFunctionality))
{
return false;
}
$parts = explode('.', $context);
// We need at least the extension + view for loading the table
fields
if (\count($parts) < 2) {
return false;
}
$component =
$this->getApplication()->bootComponent($parts[0]);
if (
!$component instanceof WorkflowServiceInterface
|| !$component->isWorkflowActive($context)
||
!$component->supportFunctionality($this->supportFunctionality,
$context)
) {
return false;
}
$modelName = $component->getModelName($context);
$model = $component->getMVCFactory()->createModel($modelName,
$this->getApplication()->getName(), ['ignore_request' =>
true]);
if (!$model instanceof DatabaseModelInterface ||
!method_exists($model, 'featured')) {
return false;
}
$table = $model->getTable();
if (!$table instanceof TableInterface ||
!$table->hasField('featured')) {
return false;
}
return true;
}
/**
* If plugin supports the functionality we set the used variable
*
* @param WorkflowFunctionalityUsedEvent $event
*
* @since 4.0.0
*/
public function
onWorkflowFunctionalityUsed(WorkflowFunctionalityUsedEvent $event)
{
$functionality = $event->getArgument('functionality');
if ($functionality !== 'core.featured') {
return;
}
$event->setUsed();
}
}
PK��[������Service/Category.phpnu�[���<?php
/**
* @package Joomla.Site
* @subpackage com_contact
*
* @copyright (C) 2009 Open Source Matters, Inc.
<https://www.joomla.org>
* @license GNU General Public License version 2 or later; see
LICENSE.txt
*/
namespace Joomla\Component\Contact\Site\Service;
use Joomla\CMS\Categories\Categories;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Contact Component Category Tree
*
* @since 1.6
*/
class Category extends Categories
{
/**
* Class constructor
*
* @param array $options Array of options
*
* @since 1.6
*/
public function __construct($options = [])
{
$options['table'] = '#__contact_details';
$options['extension'] = 'com_contact';
$options['statefield'] = 'published';
parent::__construct($options);
}
}
PK��[D�`W�!�!Service/Router.phpnu�[���<?php
/**
* @package Joomla.Site
* @subpackage com_contact
*
* @copyright (C) 2007 Open Source Matters, Inc.
<https://www.joomla.org>
* @license GNU General Public License version 2 or later; see
LICENSE.txt
*/
namespace Joomla\Component\Contact\Site\Service;
use Joomla\CMS\Application\SiteApplication;
use Joomla\CMS\Categories\CategoryFactoryInterface;
use Joomla\CMS\Categories\CategoryInterface;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Component\Router\RouterView;
use Joomla\CMS\Component\Router\RouterViewConfiguration;
use Joomla\CMS\Component\Router\Rules\MenuRules;
use Joomla\CMS\Component\Router\Rules\NomenuRules;
use Joomla\CMS\Component\Router\Rules\StandardRules;
use Joomla\CMS\Menu\AbstractMenu;
use Joomla\Database\DatabaseInterface;
use Joomla\Database\ParameterType;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Routing class from com_contact
*
* @since 3.3
*/
class Router extends RouterView
{
/**
* Flag to remove IDs
*
* @var boolean
*/
protected $noIDs = false;
/**
* The category factory
*
* @var CategoryFactoryInterface
*
* @since 4.0.0
*/
private $categoryFactory;
/**
* The category cache
*
* @var array
*
* @since 4.0.0
*/
private $categoryCache = [];
/**
* The db
*
* @var DatabaseInterface
*
* @since 4.0.0
*/
private $db;
/**
* Content Component router constructor
*
* @param SiteApplication $app The application
object
* @param AbstractMenu $menu The menu object
to work with
* @param CategoryFactoryInterface $categoryFactory The category
object
* @param DatabaseInterface $db The database
object
*/
public function __construct(SiteApplication $app, AbstractMenu $menu,
CategoryFactoryInterface $categoryFactory, DatabaseInterface $db)
{
$this->categoryFactory = $categoryFactory;
$this->db = $db;
$params = ComponentHelper::getParams('com_contact');
$this->noIDs = (bool) $params->get('sef_ids');
$categories = new RouterViewConfiguration('categories');
$categories->setKey('id');
$this->registerView($categories);
$category = new RouterViewConfiguration('category');
$category->setKey('id')->setParent($categories,
'catid')->setNestable();
$this->registerView($category);
$contact = new RouterViewConfiguration('contact');
$contact->setKey('id')->setParent($category,
'catid');
$this->registerView($contact);
$this->registerView(new
RouterViewConfiguration('featured'));
$form = new RouterViewConfiguration('form');
$form->setKey('id');
$this->registerView($form);
parent::__construct($app, $menu);
$this->attachRule(new MenuRules($this));
$this->attachRule(new StandardRules($this));
$this->attachRule(new NomenuRules($this));
}
/**
* Method to get the segment(s) for a category
*
* @param string $id ID of the category to retrieve the segments
for
* @param array $query The request that is built right now
*
* @return array|string The segments of this item
*/
public function getCategorySegment($id, $query)
{
$category = $this->getCategories()->get($id);
if ($category) {
$path = array_reverse($category->getPath(), true);
$path[0] = '1:root';
if ($this->noIDs) {
foreach ($path as &$segment) {
list($id, $segment) = explode(':', $segment,
2);
}
}
return $path;
}
return [];
}
/**
* Method to get the segment(s) for a category
*
* @param string $id ID of the category to retrieve the segments
for
* @param array $query The request that is built right now
*
* @return array|string The segments of this item
*/
public function getCategoriesSegment($id, $query)
{
return $this->getCategorySegment($id, $query);
}
/**
* Method to get the segment(s) for a contact
*
* @param string $id ID of the contact to retrieve the segments
for
* @param array $query The request that is built right now
*
* @return array|string The segments of this item
*/
public function getContactSegment($id, $query)
{
if (!strpos($id, ':')) {
$id = (int) $id;
$dbquery = $this->db->getQuery(true);
$dbquery->select($this->db->quoteName('alias'))
->from($this->db->quoteName('#__contact_details'))
->where($this->db->quoteName('id') .
' = :id')
->bind(':id', $id, ParameterType::INTEGER);
$this->db->setQuery($dbquery);
$id .= ':' . $this->db->loadResult();
}
if ($this->noIDs) {
list($void, $segment) = explode(':', $id, 2);
return [$void => $segment];
}
return [(int) $id => $id];
}
/**
* Method to get the segment(s) for a form
*
* @param string $id ID of the contact form to retrieve the
segments for
* @param array $query The request that is built right now
*
* @return array|string The segments of this item
*
* @since 4.0.0
*/
public function getFormSegment($id, $query)
{
return $this->getContactSegment($id, $query);
}
/**
* Method to get the id for a category
*
* @param string $segment Segment to retrieve the ID for
* @param array $query The request that is parsed right now
*
* @return mixed The id of this item or false
*/
public function getCategoryId($segment, $query)
{
if (isset($query['id'])) {
$category = $this->getCategories(['access' =>
false])->get($query['id']);
if ($category) {
foreach ($category->getChildren() as $child) {
if ($this->noIDs) {
if ($child->alias == $segment) {
return $child->id;
}
} else {
if ($child->id == (int) $segment) {
return $child->id;
}
}
}
}
}
return false;
}
/**
* Method to get the segment(s) for a category
*
* @param string $segment Segment to retrieve the ID for
* @param array $query The request that is parsed right now
*
* @return mixed The id of this item or false
*/
public function getCategoriesId($segment, $query)
{
return $this->getCategoryId($segment, $query);
}
/**
* Method to get the segment(s) for a contact
*
* @param string $segment Segment of the contact to retrieve the ID
for
* @param array $query The request that is parsed right now
*
* @return mixed The id of this item or false
*/
public function getContactId($segment, $query)
{
if ($this->noIDs) {
$dbquery = $this->db->getQuery(true);
$dbquery->select($this->db->quoteName('id'))
->from($this->db->quoteName('#__contact_details'))
->where(
[
$this->db->quoteName('alias') .
' = :alias',
$this->db->quoteName('catid') .
' = :catid',
]
)
->bind(':alias', $segment)
->bind(':catid', $query['id'],
ParameterType::INTEGER);
$this->db->setQuery($dbquery);
return (int) $this->db->loadResult();
}
return (int) $segment;
}
/**
* Method to get categories from cache
*
* @param array $options The options for retrieving categories
*
* @return CategoryInterface The object containing categories
*
* @since 4.0.0
*/
private function getCategories(array $options = []): CategoryInterface
{
$key = serialize($options);
if (!isset($this->categoryCache[$key])) {
$this->categoryCache[$key] =
$this->categoryFactory->createCategory($options);
}
return $this->categoryCache[$key];
}
}
PK��[]�ƪHelper/AssociationHelper.phpnu�[���<?php
/**
* @package Joomla.Site
* @subpackage com_contact
*
* @copyright (C) 2013 Open Source Matters, Inc.
<https://www.joomla.org>
* @license GNU General Public License version 2 or later; see
LICENSE.txt
*/
namespace Joomla\Component\Contact\Site\Helper;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Associations;
use
Joomla\Component\Categories\Administrator\Helper\CategoryAssociationHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Contact Component Association Helper
*
* @since 3.0
*/
abstract class AssociationHelper extends CategoryAssociationHelper
{
/**
* Method to get the associations for a given item
*
* @param integer $id Id of the item
* @param string $view Name of the view
*
* @return array Array of associations for the item
*
* @since 3.0
*/
public static function getAssociations($id = 0, $view = null)
{
$jinput = Factory::getApplication()->getInput();
$view = $view ?? $jinput->get('view');
$id = empty($id) ? $jinput->getInt('id') : $id;
if ($view === 'contact') {
if ($id) {
$associations =
Associations::getAssociations('com_contact',
'#__contact_details', 'com_contact.item', $id);
$return = [];
foreach ($associations as $tag => $item) {
$return[$tag] =
RouteHelper::getContactRoute($item->id, (int) $item->catid,
$item->language);
}
return $return;
}
}
if ($view === 'category' || $view ===
'categories') {
return self::getCategoryAssociations($id,
'com_contact');
}
return [];
}
}
PK��[�U��P P Helper/RouteHelper.phpnu�[���<?php
/**
* @package Joomla.Site
* @subpackage com_contact
*
* @copyright (C) 2017 Open Source Matters, Inc.
<https://www.joomla.org>
* @license GNU General Public License version 2 or later; see
LICENSE.txt
*/
namespace Joomla\Component\Contact\Site\Helper;
use Joomla\CMS\Categories\CategoryNode;
use Joomla\CMS\Language\Multilanguage;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Contact Component Route Helper
*
* @static
* @package Joomla.Site
* @subpackage com_contact
* @since 1.5
*/
abstract class RouteHelper
{
/**
* Get the URL route for a contact from a contact ID, contact category
ID and language
*
* @param integer $id The id of the contact
* @param integer $catid The id of the contact's category
* @param mixed $language The id of the language being used.
*
* @return string The link to the contact
*
* @since 1.5
*/
public static function getContactRoute($id, $catid, $language = 0)
{
// Create the link
$link =
'index.php?option=com_contact&view=contact&id=' . $id;
if ($catid > 1) {
$link .= '&catid=' . $catid;
}
if ($language && $language !== '*' &&
Multilanguage::isEnabled()) {
$link .= '&lang=' . $language;
}
return $link;
}
/**
* Get the URL route for a contact category from a contact category ID
and language
*
* @param mixed $catid The id of the contact's category
either an integer id or an instance of CategoryNode
* @param mixed $language The id of the language being used.
*
* @return string The link to the contact
*
* @since 1.5
*/
public static function getCategoryRoute($catid, $language = 0)
{
if ($catid instanceof CategoryNode) {
$id = $catid->id;
} else {
$id = (int) $catid;
}
if ($id < 1) {
$link = '';
} else {
// Create the link
$link =
'index.php?option=com_contact&view=category&id=' . $id;
if ($language && $language !== '*' &&
Multilanguage::isEnabled()) {
$link .= '&lang=' . $language;
}
}
return $link;
}
}
PK��[=�$��Dispatcher/Dispatcher.phpnu�[���<?php
/**
* @package Joomla.Site
* @subpackage com_contact
*
* @copyright (C) 2017 Open Source Matters, Inc.
<https://www.joomla.org>
* @license GNU General Public License version 2 or later; see
LICENSE.txt
*/
namespace Joomla\Component\Contact\Site\Dispatcher;
use Joomla\CMS\Dispatcher\ComponentDispatcher;
use Joomla\CMS\Language\Text;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* ComponentDispatcher class for com_contact
*
* @since 4.0.0
*/
class Dispatcher extends ComponentDispatcher
{
/**
* Dispatch a controller task. Redirecting the user if appropriate.
*
* @return void
*
* @since 4.0.0
*/
public function dispatch()
{
if ($this->input->get('view') ===
'contacts' && $this->input->get('layout')
=== 'modal') {
if
(!$this->app->getIdentity()->authorise('core.create',
'com_contact')) {
$this->app->enqueueMessage(Text::_('JERROR_ALERTNOAUTHOR'),
'warning');
return;
}
$this->app->getLanguage()->load('com_contact',
JPATH_ADMINISTRATOR);
}
parent::dispatch();
}
}
PK��[�1����Model/CategoriesModel.phpnu�[���<?php
/**
* @package Joomla.Site
* @subpackage com_contact
*
* @copyright (C) 2008 Open Source Matters, Inc.
<https://www.joomla.org>
* @license GNU General Public License version 2 or later; see
LICENSE.txt
*/
namespace Joomla\Component\Contact\Site\Model;
use Joomla\CMS\Categories\Categories;
use Joomla\CMS\Categories\CategoryNode;
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\Registry\Registry;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* This models supports retrieving lists of contact categories.
*
* @since 1.6
*/
class CategoriesModel extends ListModel
{
/**
* Model context string.
*
* @var string
*/
public $_context = 'com_contact.categories';
/**
* The category context (allows other extensions to derived from this
model).
*
* @var string
*/
protected $_extension = 'com_contact';
/**
* Parent category of the current one
*
* @var CategoryNode|null
*/
private $_parent = null;
/**
* Array of child-categories
*
* @var CategoryNode[]|null
*/
private $_items = null;
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @param string $ordering An optional ordering field.
* @param string $direction An optional direction (asc|desc).
*
* @return void
*
* @since 1.6
*/
protected function populateState($ordering = null, $direction = null)
{
$app = Factory::getApplication();
$this->setState('filter.extension',
$this->_extension);
// Get the parent id if defined.
$parentId = $app->getInput()->getInt('id');
$this->setState('filter.parentId', $parentId);
$params = $app->getParams();
$this->setState('params', $params);
$this->setState('filter.published', 1);
$this->setState('filter.access', true);
}
/**
* Method to get a store id based on model configuration state.
*
* This is necessary because the model is used by the component and
* different modules that might need different sets of data or
different
* ordering requirements.
*
* @param string $id A prefix for the store id.
*
* @return string A store id.
*/
protected function getStoreId($id = '')
{
// Compile the store id.
$id .= ':' .
$this->getState('filter.extension');
$id .= ':' .
$this->getState('filter.published');
$id .= ':' .
$this->getState('filter.access');
$id .= ':' .
$this->getState('filter.parentId');
return parent::getStoreId($id);
}
/**
* Redefine the function and add some properties to make the styling
easier
*
* @return mixed An array of data items on success, false on failure.
*/
public function getItems()
{
if ($this->_items === null) {
$app = Factory::getApplication();
$menu = $app->getMenu();
$active = $menu->getActive();
if ($active) {
$params = $active->getParams();
} else {
$params = new Registry();
}
$options = [];
$options['countItems'] =
$params->get('show_cat_items_cat', 1) ||
!$params->get('show_empty_categories_cat', 0);
$categories =
Categories::getInstance('Contact', $options);
$this->_parent =
$categories->get($this->getState('filter.parentId',
'root'));
if (\is_object($this->_parent)) {
$this->_items = $this->_parent->getChildren();
} else {
$this->_items = false;
}
}
return $this->_items;
}
/**
* Gets the id of the parent category for the selected list of
categories
*
* @return integer The id of the parent category
*
* @since 1.6.0
*/
public function getParent()
{
if (!\is_object($this->_parent)) {
$this->getItems();
}
return $this->_parent;
}
}
PK��[���@@Model/ContactModel.phpnu�[���<?php
/**
* @package Joomla.Site
* @subpackage com_contact
*
* @copyright (C) 2006 Open Source Matters, Inc.
<https://www.joomla.org>
* @license GNU General Public License version 2 or later; see
LICENSE.txt
*/
namespace Joomla\Component\Contact\Site\Model;
use Joomla\CMS\Application\SiteApplication;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Helper\TagsHelper;
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Model\FormModel;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Database\ParameterType;
use Joomla\Database\QueryInterface;
use Joomla\Registry\Registry;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Single item model for a contact
*
* @package Joomla.Site
* @subpackage com_contact
* @since 1.5
*/
class ContactModel extends FormModel
{
/**
* The name of the view for a single item
*
* @var string
* @since 1.6
*/
protected $view_item = 'contact';
/**
* A loaded item
*
* @var \stdClass[]
* @since 1.6
*/
protected $_item = [];
/**
* Model context string.
*
* @var string
*/
protected $_context = 'com_contact.contact';
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @return void
*
* @since 1.6
*/
protected function populateState()
{
/** @var SiteApplication $app */
$app = Factory::getContainer()->get(SiteApplication::class);
if (Factory::getApplication()->isClient('api')) {
// @todo: remove this
$app->loadLanguage();
$this->setState('contact.id',
Factory::getApplication()->getInput()->post->getInt('id'));
} else {
$this->setState('contact.id',
$app->getInput()->getInt('id'));
}
$this->setState('params', $app->getParams());
$user = $this->getCurrentUser();
if ((!$user->authorise('core.edit.state',
'com_contact')) &&
(!$user->authorise('core.edit', 'com_contact'))) {
$this->setState('filter.published', 1);
$this->setState('filter.archived', 2);
}
}
/**
* Method to get the contact form.
* The base form is loaded from XML and then an event is fired
*
* @param array $data An optional array of data for the form
to interrogate.
* @param boolean $loadData True if the form is to load its own
data (default case), false if not.
*
* @return Form A Form object on success, false on failure
*
* @since 1.6
*/
public function getForm($data = [], $loadData = true)
{
$form = $this->loadForm('com_contact.contact',
'contact', ['control' => 'jform',
'load_data' => $loadData]);
if (empty($form)) {
return false;
}
$temp = clone $this->getState('params');
$contact =
$this->getItem($this->getState('contact.id'));
$active =
Factory::getContainer()->get(SiteApplication::class)->getMenu()->getActive();
if ($active) {
// If the current view is the active item and a contact view
for this contact, then the menu item params take priority
if (strpos($active->link, 'view=contact')
&& strpos($active->link, '&id=' . (int)
$contact->id)) {
// $contact->params are the contact params, $temp are
the menu item params
// Merge so that the menu item params take priority
$contact->params->merge($temp);
} else {
// Current view is not a single contact, so the contact
params take priority here
// Merge the menu item params with the contact params so
that the contact params take priority
$temp->merge($contact->params);
$contact->params = $temp;
}
} else {
// Merge so that contact params take priority
$temp->merge($contact->params);
$contact->params = $temp;
}
if (!$contact->params->get('show_email_copy', 0)) {
$form->removeField('contact_email_copy');
}
return $form;
}
/**
* Method to get the data that should be injected in the form.
*
* @return array The default data is an empty array.
*
* @since 1.6.2
*/
protected function loadFormData()
{
$data = (array)
Factory::getApplication()->getUserState('com_contact.contact.data',
[]);
if (empty($data['language']) &&
Multilanguage::isEnabled()) {
$data['language'] =
Factory::getLanguage()->getTag();
}
// Add contact catid to contact form data, so fields plugin can
work properly
if (empty($data['catid'])) {
$data['catid'] = $this->getItem()->catid;
}
$this->preprocessData('com_contact.contact', $data);
return $data;
}
/**
* Gets a contact
*
* @param integer $pk Id for the contact
*
* @return mixed \stdClass or null
*
* @since 1.6.0
*/
public function getItem($pk = null)
{
$pk = $pk ?: (int) $this->getState('contact.id');
if (!isset($this->_item[$pk])) {
try {
$db = $this->getDatabase();
$query = $db->getQuery(true);
$query->select($this->getState('item.select',
'a.*'))
->select($this->getSlugColumn($query,
'a.id', 'a.alias') . ' AS slug')
->select($this->getSlugColumn($query,
'c.id', 'c.alias') . ' AS catslug')
->from($db->quoteName('#__contact_details', 'a'))
// Join on category table.
->select('c.title AS category_title, c.alias AS
category_alias, c.access AS category_access')
->leftJoin($db->quoteName('#__categories', 'c'),
'c.id = a.catid')
// Join over the categories to get parent category
titles
->select('parent.title AS parent_title,
parent.id AS parent_id, parent.path AS parent_route, parent.alias AS
parent_alias')
->leftJoin($db->quoteName('#__categories',
'parent'), 'parent.id = c.parent_id')
->where($db->quoteName('a.id') . '
= :id')
->bind(':id', $pk,
ParameterType::INTEGER);
// Filter by start and end dates.
$nowDate = Factory::getDate()->toSql();
// Filter by published state.
$published =
$this->getState('filter.published');
$archived =
$this->getState('filter.archived');
if (is_numeric($published)) {
$queryString =
$db->quoteName('a.published') . ' = :published';
if ($archived !== null) {
$queryString = '(' . $queryString .
' OR ' . $db->quoteName('a.published') . ' =
:archived)';
$query->bind(':archived', $archived,
ParameterType::INTEGER);
}
$query->where($queryString)
->where('(' .
$db->quoteName('a.publish_up') . ' IS NULL OR ' .
$db->quoteName('a.publish_up') . ' <=
:publish_up)')
->where('(' .
$db->quoteName('a.publish_down') . ' IS NULL OR ' .
$db->quoteName('a.publish_down') . ' >=
:publish_down)')
->bind(':published', $published,
ParameterType::INTEGER)
->bind(':publish_up', $nowDate)
->bind(':publish_down', $nowDate);
}
$db->setQuery($query);
$data = $db->loadObject();
if (empty($data)) {
throw new
\Exception(Text::_('COM_CONTACT_ERROR_CONTACT_NOT_FOUND'), 404);
}
// Check for published state if filter set.
if ((is_numeric($published) || is_numeric($archived))
&& (($data->published != $published) &&
($data->published != $archived))) {
throw new
\Exception(Text::_('COM_CONTACT_ERROR_CONTACT_NOT_FOUND'), 404);
}
/**
* In case some entity params have been set to "use
global", those are
* represented as an empty string and must be
"overridden" by merging
* the component and / or menu params here.
*/
$registry = new Registry($data->params);
$data->params = clone
$this->getState('params');
$data->params->merge($registry);
$registry = new Registry($data->metadata);
$data->metadata = $registry;
// Some contexts may not use tags data at all, so we allow
callers to disable loading tag data
if ($this->getState('load_tags', true)) {
$data->tags = new TagsHelper();
$data->tags->getItemTags('com_contact.contact',
$data->id);
}
// Compute access permissions.
if (($access =
$this->getState('filter.access'))) {
// If the access filter has been set, we already know
this user can view.
$data->params->set('access-view',
true);
} else {
// If no access filter is set, the layout takes some
responsibility for display of limited information.
$user = $this->getCurrentUser();
$groups = $user->getAuthorisedViewLevels();
if ($data->catid == 0 || $data->category_access
=== null) {
$data->params->set('access-view',
\in_array($data->access, $groups));
} else {
$data->params->set('access-view',
\in_array($data->access, $groups) &&
\in_array($data->category_access, $groups));
}
}
$this->_item[$pk] = $data;
} catch (\Exception $e) {
if ($e->getCode() == 404) {
// Need to go through the error handler to allow
Redirect to work.
throw $e;
}
$this->setError($e);
$this->_item[$pk] = false;
}
}
if ($this->_item[$pk]) {
$this->buildContactExtendedData($this->_item[$pk]);
}
return $this->_item[$pk];
}
/**
* Load extended data (profile, articles) for a contact
*
* @param object $contact The contact object
*
* @return void
*/
protected function buildContactExtendedData($contact)
{
$db = $this->getDatabase();
$nowDate = Factory::getDate()->toSql();
$user = $this->getCurrentUser();
$groups = $user->getAuthorisedViewLevels();
$published = $this->getState('filter.published');
$query = $db->getQuery(true);
// If we are showing a contact list, then the contact parameters
take priority
// So merge the contact parameters with the merged parameters
if
($this->getState('params')->get('show_contact_list'))
{
$this->getState('params')->merge($contact->params);
}
// Get the com_content articles by the linked user
if ((int) $contact->user_id &&
$this->getState('params')->get('show_articles'))
{
$query->select('a.id')
->select('a.title')
->select('a.state')
->select('a.access')
->select('a.catid')
->select('a.created')
->select('a.language')
->select('a.publish_up')
->select('a.introtext')
->select('a.images')
->select($this->getSlugColumn($query,
'a.id', 'a.alias') . ' AS slug')
->select($this->getSlugColumn($query,
'c.id', 'c.alias') . ' AS catslug')
->from($db->quoteName('#__content',
'a'))
->leftJoin($db->quoteName('#__categories',
'c') . ' ON a.catid = c.id')
->where($db->quoteName('a.created_by') .
' = :created_by')
->whereIn($db->quoteName('a.access'),
$groups)
->bind(':created_by', $contact->user_id,
ParameterType::INTEGER)
->order('a.publish_up DESC');
// Filter per language if plugin published
if (Multilanguage::isEnabled()) {
$language = [Factory::getLanguage()->getTag(),
'*'];
$query->whereIn($db->quoteName('a.language'), $language,
ParameterType::STRING);
}
if (is_numeric($published)) {
$query->where('a.state IN (1,2)')
->where('(' .
$db->quoteName('a.publish_up') . ' IS NULL' .
' OR ' .
$db->quoteName('a.publish_up') . ' <= :now1)')
->where('(' .
$db->quoteName('a.publish_down') . ' IS NULL' .
' OR ' .
$db->quoteName('a.publish_down') . ' >= :now2)')
->bind([':now1', ':now2'],
$nowDate);
}
// Number of articles to display from config/menu params
$articles_display_num =
$this->getState('params')->get('articles_display_num',
10);
// Use contact setting?
if ($articles_display_num === 'use_contact') {
$articles_display_num =
$contact->params->get('articles_display_num', 10);
// Use global?
if ((string) $articles_display_num === '') {
$articles_display_num =
ComponentHelper::getParams('com_contact')->get('articles_display_num',
10);
}
}
$query->setLimit((int) $articles_display_num);
$db->setQuery($query);
$contact->articles = $db->loadObjectList();
} else {
$contact->articles = null;
}
// Get the profile information for the linked user
$userModel =
$this->bootComponent('com_users')->getMVCFactory()
->createModel('User', 'Administrator',
['ignore_request' => true]);
$data = $userModel->getItem((int) $contact->user_id);
PluginHelper::importPlugin('user');
// Get the form.
Form::addFormPath(JPATH_SITE .
'/components/com_users/forms');
$form = Form::getInstance('com_users.profile',
'profile');
// Trigger the form preparation event.
Factory::getApplication()->triggerEvent('onContentPrepareForm',
[$form, $data]);
// Trigger the data preparation event.
Factory::getApplication()->triggerEvent('onContentPrepareData',
['com_users.profile', $data]);
// Load the data into the form after the plugins have operated.
$form->bind($data);
$contact->profile = $form;
}
/**
* Generate column expression for slug or catslug.
*
* @param QueryInterface $query Current query instance.
* @param string $id Column id name.
* @param string $alias Column alias name.
*
* @return string
*
* @since 4.0.0
*/
private function getSlugColumn($query, $id, $alias)
{
return 'CASE WHEN '
. $query->charLength($alias, '!=', '0')
. ' THEN '
. $query->concatenate([$query->castAsChar($id), $alias],
':')
. ' ELSE '
. $query->castAsChar($id) . ' END';
}
/**
* Increment the hit counter for the contact.
*
* @param integer $pk Optional primary key of the contact to
increment.
*
* @return boolean True if successful; false otherwise and internal
error set.
*
* @since 3.0
*/
public function hit($pk = 0)
{
$input = Factory::getApplication()->getInput();
$hitcount = $input->getInt('hitcount', 1);
if ($hitcount) {
$pk = $pk ?: (int) $this->getState('contact.id');
$table = $this->getTable('Contact');
$table->hit($pk);
}
return true;
}
}
PK��[hTOJRRModel/FeaturedModel.phpnu�[���<?php
/**
* @package Joomla.Site
* @subpackage com_contact
*
* @copyright (C) 2010 Open Source Matters, Inc.
<https://www.joomla.org>
* @license GNU General Public License version 2 or later; see
LICENSE.txt
*/
namespace Joomla\Component\Contact\Site\Model;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\Database\DatabaseQuery;
use Joomla\Database\ParameterType;
use Joomla\Registry\Registry;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Featured contact model class.
*
* @since 1.6.0
*/
class FeaturedModel extends ListModel
{
/**
* Constructor.
*
* @param array $config An optional associative array of
configuration settings.
*
* @since 1.6
*/
public function __construct($config = [])
{
if (empty($config['filter_fields'])) {
$config['filter_fields'] = [
'id', 'a.id',
'name', 'a.name',
'con_position', 'a.con_position',
'suburb', 'a.suburb',
'state', 'a.state',
'country', 'a.country',
'ordering', 'a.ordering',
];
}
parent::__construct($config);
}
/**
* Method to get a list of items.
*
* @return mixed An array of objects on success, false on failure.
*/
public function getItems()
{
// Invoke the parent getItems method to get the main list
$items = parent::getItems();
// Convert the params field into an object, saving original in
_params
for ($i = 0, $n = \count($items); $i < $n; $i++) {
$item = &$items[$i];
if (!isset($this->_params)) {
$item->params = new Registry($item->params);
}
}
return $items;
}
/**
* Method to build an SQL query to load the list data.
*
* @return DatabaseQuery An SQL query
*
* @since 1.6
*/
protected function getListQuery()
{
$user = $this->getCurrentUser();
$groups = $user->getAuthorisedViewLevels();
// Create a new query object.
$db = $this->getDatabase();
$query = $db->getQuery(true);
// Select required fields from the categories.
$query->select($this->getState('list.select',
'a.*'))
->from($db->quoteName('#__contact_details',
'a'))
->where($db->quoteName('a.featured') . ' =
1')
->whereIn($db->quoteName('a.access'), $groups)
->innerJoin($db->quoteName('#__categories',
'c') . ' ON c.id = a.catid')
->whereIn($db->quoteName('c.access'), $groups);
// Filter by category.
if ($categoryId = $this->getState('category.id')) {
$query->where($db->quoteName('a.catid') .
' = :catid');
$query->bind(':catid', $categoryId,
ParameterType::INTEGER);
}
$query->select('c.published as cat_published, c.published
AS parents_published')
->where('c.published = 1');
// Filter by state
$state = $this->getState('filter.published');
if (is_numeric($state)) {
$query->where($db->quoteName('a.published') .
' = :published');
$query->bind(':published', $state,
ParameterType::INTEGER);
// Filter by start and end dates.
$nowDate = Factory::getDate()->toSql();
$query->where('(' .
$db->quoteName('a.publish_up') .
' IS NULL OR ' .
$db->quoteName('a.publish_up') . ' <=
:publish_up)')
->where('(' .
$db->quoteName('a.publish_down') .
' IS NULL OR ' .
$db->quoteName('a.publish_down') . ' >=
:publish_down)')
->bind(':publish_up', $nowDate)
->bind(':publish_down', $nowDate);
}
// Filter by search in title
$search = $this->getState('list.filter');
// Filter by search in title
if (!empty($search)) {
$search = '%' . trim($search) . '%';
$query->where($db->quoteName('a.name') . '
LIKE :name ');
$query->bind(':name', $search);
}
// Filter by language
if ($this->getState('filter.language')) {
$query->whereIn($db->quoteName('a.language'),
[Factory::getLanguage()->getTag(), '*'],
ParameterType::STRING);
}
// Add the list ordering clause.
$query->order($db->escape($this->getState('list.ordering',
'a.ordering')) . ' ' .
$db->escape($this->getState('list.direction',
'ASC')));
return $query;
}
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @param string $ordering An optional ordering field.
* @param string $direction An optional direction (asc|desc).
*
* @return void
*
* @since 1.6
*/
protected function populateState($ordering = null, $direction = null)
{
$app = Factory::getApplication();
$input = $app->getInput();
$params = ComponentHelper::getParams('com_contact');
// List state information
$limit =
$app->getUserStateFromRequest('global.list.limit',
'limit', $app->get('list_limit'), 'uint');
$this->setState('list.limit', $limit);
$limitstart = $input->get('limitstart', 0,
'uint');
$this->setState('list.start', $limitstart);
// Optional filter text
$this->setState('list.filter',
$input->getString('filter-search'));
$orderCol = $input->get('filter_order',
'ordering');
if (!\in_array($orderCol, $this->filter_fields)) {
$orderCol = 'ordering';
}
$this->setState('list.ordering', $orderCol);
$listOrder = $input->get('filter_order_Dir',
'ASC');
if (!\in_array(strtoupper($listOrder), ['ASC',
'DESC', ''])) {
$listOrder = 'ASC';
}
$this->setState('list.direction', $listOrder);
$user = $this->getCurrentUser();
if ((!$user->authorise('core.edit.state',
'com_contact')) &&
(!$user->authorise('core.edit', 'com_contact'))) {
// Limit to published for people who can't edit or
edit.state.
$this->setState('filter.published', 1);
// Filter by start and end dates.
$this->setState('filter.publish_date', true);
}
$this->setState('filter.language',
Multilanguage::isEnabled());
// Load the parameters.
$this->setState('params', $params);
}
}
PK��[vJP�{>{>Model/CategoryModel.phpnu�[���<?php
/**
* @package Joomla.Site
* @subpackage com_contact
*
* @copyright (C) 2006 Open Source Matters, Inc.
<https://www.joomla.org>
* @license GNU General Public License version 2 or later; see
LICENSE.txt
*/
namespace Joomla\Component\Contact\Site\Model;
use Joomla\CMS\Categories\Categories;
use Joomla\CMS\Categories\CategoryNode;
use Joomla\CMS\Factory;
use Joomla\CMS\Helper\TagsHelper;
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\CMS\Table\Table;
use Joomla\Database\ParameterType;
use Joomla\Registry\Registry;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Single item model for a contact
*
* @package Joomla.Site
* @subpackage com_contact
* @since 1.5
*/
class CategoryModel extends ListModel
{
/**
* Category item data
*
* @var CategoryNode
*/
protected $_item;
/**
* Category left and right of this one
*
* @var CategoryNode[]|null
*/
protected $_siblings;
/**
* Array of child-categories
*
* @var CategoryNode[]|null
*/
protected $_children;
/**
* Parent category of the current one
*
* @var CategoryNode|null
*/
protected $_parent;
/**
* The category that applies.
*
* @var object
*/
protected $_category;
/**
* The list of other contact categories.
*
* @var array
*/
protected $_categories;
/**
* Constructor.
*
* @param array $config An optional associative array of
configuration settings.
*
* @since 1.6
*/
public function __construct($config = [])
{
if (empty($config['filter_fields'])) {
$config['filter_fields'] = [
'id', 'a.id',
'name', 'a.name',
'con_position', 'a.con_position',
'suburb', 'a.suburb',
'state', 'a.state',
'country', 'a.country',
'ordering', 'a.ordering',
'sortname',
'sortname1', 'a.sortname1',
'sortname2', 'a.sortname2',
'sortname3', 'a.sortname3',
'featuredordering', 'a.featured',
];
}
parent::__construct($config);
}
/**
* Method to get a list of items.
*
* @return mixed An array of objects on success, false on failure.
*/
public function getItems()
{
// Invoke the parent getItems method to get the main list
$items = parent::getItems();
if ($items === false) {
return false;
}
$taggedItems = [];
// Convert the params field into an object, saving original in
_params
foreach ($items as $item) {
if (!isset($this->_params)) {
$item->params = new Registry($item->params);
}
// Some contexts may not use tags data at all, so we allow
callers to disable loading tag data
if ($this->getState('load_tags', true)) {
$item->tags = new TagsHelper();
$taggedItems[$item->id] = $item;
}
}
// Load tags of all items.
if ($taggedItems) {
$tagsHelper = new TagsHelper();
$itemIds = array_keys($taggedItems);
foreach
($tagsHelper->getMultipleItemTags('com_contact.contact',
$itemIds) as $id => $tags) {
$taggedItems[$id]->tags->itemTags = $tags;
}
}
return $items;
}
/**
* Method to build an SQL query to load the list data.
*
* @return \Joomla\Database\DatabaseQuery An SQL query
*
* @since 1.6
*/
protected function getListQuery()
{
$user = $this->getCurrentUser();
$groups = $user->getAuthorisedViewLevels();
// Create a new query object.
$db = $this->getDatabase();
/** @var \Joomla\Database\DatabaseQuery $query */
$query = $db->getQuery(true);
$query->select($this->getState('list.select',
'a.*'))
->select($this->getSlugColumn($query, 'a.id',
'a.alias') . ' AS slug')
->select($this->getSlugColumn($query, 'c.id',
'c.alias') . ' AS catslug')
/**
* @todo: we actually should be doing it but it's wrong this
way
* . ' CASE WHEN CHAR_LENGTH(a.alias) THEN
CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug, '
* . ' CASE WHEN CHAR_LENGTH(c.alias) THEN
CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END AS catslug ');
*/
->from($db->quoteName('#__contact_details',
'a'))
->leftJoin($db->quoteName('#__categories',
'c') . ' ON c.id = a.catid')
->whereIn($db->quoteName('a.access'), $groups);
// Filter by category.
$categoryId = (int)
$this->getState('category.id');
$includeSubcategories = (int)
$this->getState('filter.max_category_levels', 1) !== 0;
if ($includeSubcategories) {
$levels = (int)
$this->getState('filter.max_category_levels', 1);
// Create a subquery for the subcategory list
$subQuery = $db->getQuery(true)
->select($db->quoteName('sub.id'))
->from($db->quoteName('#__categories',
'sub'))
->join(
'INNER',
$db->quoteName('#__categories',
'this'),
$db->quoteName('sub.lft') . ' >
' . $db->quoteName('this.lft')
. ' AND ' .
$db->quoteName('sub.rgt') . ' < ' .
$db->quoteName('this.rgt')
)
->where($db->quoteName('this.id') . '
= :subCategoryId');
$query->bind(':subCategoryId', $categoryId,
ParameterType::INTEGER);
if ($levels >= 0) {
$subQuery->where($db->quoteName('sub.level') . ' <=
' . $db->quoteName('this.level') . ' +
:levels');
$query->bind(':levels', $levels,
ParameterType::INTEGER);
}
// Add the subquery to the main query
$query->where(
'(' . $db->quoteName('a.catid') .
' = :categoryId OR ' . $db->quoteName('a.catid') .
' IN (' . $subQuery . '))'
);
$query->bind(':categoryId', $categoryId,
ParameterType::INTEGER);
} else {
$query->where($db->quoteName('a.catid') .
' = :acatid')
->whereIn($db->quoteName('c.access'),
$groups);
$query->bind(':acatid', $categoryId,
ParameterType::INTEGER);
}
// Join over the users for the author and modified_by names.
$query->select("CASE WHEN a.created_by_alias > '
' THEN a.created_by_alias ELSE ua.name END AS author")
->select('ua.email AS author_email')
->leftJoin($db->quoteName('#__users',
'ua') . ' ON ua.id = a.created_by')
->leftJoin($db->quoteName('#__users',
'uam') . ' ON uam.id = a.modified_by');
// Filter by state
$state = $this->getState('filter.published');
if (is_numeric($state)) {
$query->where($db->quoteName('a.published') .
' = :published');
$query->bind(':published', $state,
ParameterType::INTEGER);
} else {
$query->whereIn($db->quoteName('c.published'),
[0,1,2]);
}
// Filter by start and end dates.
$nowDate = Factory::getDate()->toSql();
if ($this->getState('filter.publish_date')) {
$query->where('(' .
$db->quoteName('a.publish_up')
. ' IS NULL OR ' .
$db->quoteName('a.publish_up') . ' <=
:publish_up)')
->where('(' .
$db->quoteName('a.publish_down')
. ' IS NULL OR ' .
$db->quoteName('a.publish_down') . ' >=
:publish_down)')
->bind(':publish_up', $nowDate)
->bind(':publish_down', $nowDate);
}
// Filter by search in title
$search = $this->getState('list.filter');
if (!empty($search)) {
$search = '%' . trim($search) . '%';
$query->where($db->quoteName('a.name') . '
LIKE :name ');
$query->bind(':name', $search);
}
// Filter on the language.
if ($this->getState('filter.language')) {
$query->whereIn($db->quoteName('a.language'),
[Factory::getApplication()->getLanguage()->getTag(), '*'],
ParameterType::STRING);
}
// Set sortname ordering if selected
if ($this->getState('list.ordering') ===
'sortname') {
$query->order($db->escape('a.sortname1') .
' ' .
$db->escape($this->getState('list.direction',
'ASC')))
->order($db->escape('a.sortname2') . '
' . $db->escape($this->getState('list.direction',
'ASC')))
->order($db->escape('a.sortname3') . '
' . $db->escape($this->getState('list.direction',
'ASC')));
} elseif ($this->getState('list.ordering') ===
'featuredordering') {
$query->order($db->escape('a.featured') .
' DESC')
->order($db->escape('a.ordering') . '
ASC');
} else {
$query->order($db->escape($this->getState('list.ordering',
'a.ordering')) . ' ' .
$db->escape($this->getState('list.direction',
'ASC')));
}
return $query;
}
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @param string $ordering An optional ordering field.
* @param string $direction An optional direction (asc|desc).
*
* @return void
*
* @since 1.6
*/
protected function populateState($ordering = null, $direction = null)
{
$app = Factory::getApplication();
$input = $app->getInput();
$params = $app->getParams();
$this->setState('params', $params);
// List state information
$format = $input->getWord('format');
if ($format === 'feed') {
$limit = $app->get('feed_limit');
} else {
$limit = $app->getUserStateFromRequest(
'com_contact.category.list.limit',
'limit',
$params->get('contacts_display_num',
$app->get('list_limit')),
'uint'
);
}
$this->setState('list.limit', $limit);
$limitstart = $input->get('limitstart', 0,
'uint');
$this->setState('list.start', $limitstart);
// Optional filter text
$itemid = $input->get('Itemid', 0, 'int');
$search =
$app->getUserStateFromRequest('com_contact.category.list.' .
$itemid . '.filter-search', 'filter-search',
'', 'string');
$this->setState('list.filter', $search);
$orderCol = $input->get('filter_order',
$params->get('initial_sort', 'ordering'));
if (!\in_array($orderCol, $this->filter_fields)) {
$orderCol = 'ordering';
}
$this->setState('list.ordering', $orderCol);
$listOrder = $input->get('filter_order_Dir',
'ASC');
if (!\in_array(strtoupper($listOrder), ['ASC',
'DESC', ''])) {
$listOrder = 'ASC';
}
$this->setState('list.direction', $listOrder);
$id = $input->get('id', 0, 'int');
$this->setState('category.id', $id);
$this->setState('filter.max_category_levels',
$params->get('maxLevel', 1));
$user = $this->getCurrentUser();
if ((!$user->authorise('core.edit.state',
'com_contact')) &&
(!$user->authorise('core.edit', 'com_contact'))) {
// Limit to published for people who can't edit or
edit.state.
$this->setState('filter.published', 1);
// Filter by start and end dates.
$this->setState('filter.publish_date', true);
}
$this->setState('filter.language',
Multilanguage::isEnabled());
}
/**
* Method to get category data for the current category
*
* @return object The category object
*
* @since 1.5
*/
public function getCategory()
{
if (!\is_object($this->_item)) {
$app = Factory::getApplication();
$menu = $app->getMenu();
$active = $menu->getActive();
if ($active) {
$params = $active->getParams();
} else {
$params = new Registry();
}
$options = [];
$options['countItems'] =
$params->get('show_cat_items', 1) ||
$params->get('show_empty_categories', 0);
$categories =
Categories::getInstance('Contact', $options);
$this->_item =
$categories->get($this->getState('category.id',
'root'));
if (\is_object($this->_item)) {
$this->_children = $this->_item->getChildren();
$this->_parent = false;
if ($this->_item->getParent()) {
$this->_parent = $this->_item->getParent();
}
$this->_rightsibling = $this->_item->getSibling();
$this->_leftsibling =
$this->_item->getSibling(false);
} else {
$this->_children = false;
$this->_parent = false;
}
}
return $this->_item;
}
/**
* Get the parent category.
*
* @return mixed An array of categories or false if an error occurs.
*/
public function getParent()
{
if (!\is_object($this->_item)) {
$this->getCategory();
}
return $this->_parent;
}
/**
* Get the sibling (adjacent) categories.
*
* @return mixed An array of categories or false if an error occurs.
*/
public function &getLeftSibling()
{
if (!\is_object($this->_item)) {
$this->getCategory();
}
return $this->_leftsibling;
}
/**
* Get the sibling (adjacent) categories.
*
* @return mixed An array of categories or false if an error occurs.
*/
public function &getRightSibling()
{
if (!\is_object($this->_item)) {
$this->getCategory();
}
return $this->_rightsibling;
}
/**
* Get the child categories.
*
* @return mixed An array of categories or false if an error occurs.
*/
public function &getChildren()
{
if (!\is_object($this->_item)) {
$this->getCategory();
}
return $this->_children;
}
/**
* Generate column expression for slug or catslug.
*
* @param \Joomla\Database\DatabaseQuery $query Current query
instance.
* @param string $id Column id name.
* @param string $alias Column alias name.
*
* @return string
*
* @since 4.0.0
*/
private function getSlugColumn($query, $id, $alias)
{
return 'CASE WHEN '
. $query->charLength($alias, '!=', '0')
. ' THEN '
. $query->concatenate([$query->castAsChar($id), $alias],
':')
. ' ELSE '
. $query->castAsChar($id) . ' END';
}
/**
* Increment the hit counter for the category.
*
* @param integer $pk Optional primary key of the category to
increment.
*
* @return boolean True if successful; false otherwise and internal
error set.
*
* @since 3.2
*/
public function hit($pk = 0)
{
$input = Factory::getApplication()->getInput();
$hitcount = $input->getInt('hitcount', 1);
if ($hitcount) {
$pk = (!empty($pk)) ? $pk : (int)
$this->getState('category.id');
$table = Table::getInstance('Category');
$table->hit($pk);
}
return true;
}
}
PK��[�$�B��Model/FormModel.phpnu�[���<?php
/**
* @package Joomla.Site
* @subpackage com_contact
*
* @copyright (C) 2020 Open Source Matters, Inc.
<https://www.joomla.org>
* @license GNU General Public License version 2 or later; see
LICENSE.txt
*/
namespace Joomla\Component\Contact\Site\Model;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Helper\TagsHelper;
use Joomla\CMS\Language\Associations;
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\Table\Table;
use Joomla\Registry\Registry;
use Joomla\Utilities\ArrayHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Contact Component Contact Model
*
* @since 4.0.0
*/
class FormModel extends
\Joomla\Component\Contact\Administrator\Model\ContactModel
{
/**
* Model typeAlias string. Used for version history.
*
* @var string
*
* @since 4.0.0
*/
public $typeAlias = 'com_contact.contact';
/**
* Name of the form
*
* @var string
*
* @since 4.0.0
*/
protected $formName = 'form';
/**
* Method to get the row form.
*
* @param array $data Data for the form.
* @param boolean $loadData True if the form is to load its own
data (default case), false if not.
*
* @return Form|boolean A Form object on success, false on failure
*
* @since 4.0.0
*/
public function getForm($data = [], $loadData = true)
{
$form = parent::getForm($data, $loadData);
// Prevent messing with article language and category when editing
existing contact with associations
if ($id = $this->getState('contact.id') &&
Associations::isEnabled()) {
$associations =
Associations::getAssociations('com_contact',
'#__contact_details', 'com_contact.item', $id);
// Make fields read only
if (!empty($associations)) {
$form->setFieldAttribute('language',
'readonly', 'true');
$form->setFieldAttribute('language',
'filter', 'unset');
}
}
return $form;
}
/**
* Method to get contact data.
*
* @param integer $itemId The id of the contact.
*
* @return mixed Contact item data object on success, false on
failure.
*
* @throws \Exception
*
* @since 4.0.0
*/
public function getItem($itemId = null)
{
$itemId = (int) (!empty($itemId)) ? $itemId :
$this->getState('contact.id');
// Get a row instance.
$table = $this->getTable();
// Attempt to load the row.
try {
if (!$table->load($itemId)) {
return false;
}
} catch (\Exception $e) {
Factory::getApplication()->enqueueMessage($e->getMessage());
return false;
}
$properties = $table->getProperties();
$value = ArrayHelper::toObject($properties,
\Joomla\CMS\Object\CMSObject::class);
// Convert field to Registry.
$value->params = new Registry($value->params);
// Convert the metadata field to an array.
$registry = new Registry($value->metadata);
$value->metadata = $registry->toArray();
if ($itemId) {
$value->tags = new TagsHelper();
$value->tags->getTagIds($value->id,
'com_contact.contact');
$value->metadata['tags'] = $value->tags;
}
return $value;
}
/**
* Get the return URL.
*
* @return string The return URL.
*
* @since 4.0.0
*/
public function getReturnPage()
{
return base64_encode($this->getState('return_page',
''));
}
/**
* Method to save the form data.
*
* @param array $data The form data.
*
* @return boolean True on success.
*
* @since 4.0.0
*
* @throws \Exception
*/
public function save($data)
{
// Associations are not edited in frontend ATM so we have to
inherit them
if (
Associations::isEnabled() &&
!empty($data['id'])
&& $associations =
Associations::getAssociations('com_contact',
'#__contact_details', 'com_contact.item',
$data['id'])
) {
foreach ($associations as $tag => $associated) {
$associations[$tag] = (int) $associated->id;
}
$data['associations'] = $associations;
}
return parent::save($data);
}
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @return void
*
* @since 4.0.0
*
* @throws \Exception
*/
protected function populateState()
{
$app = Factory::getApplication();
$input = $app->getInput();
// Load state from the request.
$pk = $input->getInt('id');
$this->setState('contact.id', $pk);
$this->setState('contact.catid',
$input->getInt('catid'));
$return = $input->get('return', '',
'base64');
$this->setState('return_page',
base64_decode($return));
// Load the parameters.
$params = $app->getParams();
$this->setState('params', $params);
$this->setState('layout',
$input->getString('layout'));
}
/**
* Allows preprocessing of the JForm object.
*
* @param Form $form The form object
* @param array $data The data to be merged into the form object
* @param string $group The plugin group to be executed
*
* @return void
*
* @since 4.0.0
*/
protected function preprocessForm(Form $form, $data, $group =
'contact')
{
if (!Multilanguage::isEnabled()) {
$form->setFieldAttribute('language',
'type', 'hidden');
$form->setFieldAttribute('language',
'default', '*');
}
parent::preprocessForm($form, $data, $group);
}
/**
* Method to get a table object, load it if necessary.
*
* @param string $name The table name. Optional.
* @param string $prefix The class prefix. Optional.
* @param array $options Configuration array for model. Optional.
*
* @return bool|Table A Table object
*
* @since 4.0.0
* @throws \Exception
*/
public function getTable($name = 'Contact', $prefix =
'Administrator', $options = [])
{
return parent::getTable($name, $prefix, $options);
}
}
PK��[ر��E
E
Controller/DisplayController.phpnu�[���<?php
/**
* @package Joomla.Site
* @subpackage com_contact
*
* @copyright (C) 2006 Open Source Matters, Inc.
<https://www.joomla.org>
* @license GNU General Public License version 2 or later; see
LICENSE.txt
*/
namespace Joomla\Component\Contact\Site\Controller;
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Contact Component Controller
*
* @since 1.5
*/
class DisplayController extends BaseController
{
/**
* @param array $config An optional
associative array of configuration settings.
* Recognized key
values include 'name', 'default_task',
'model_path', and
*
'view_path' (this list is not meant to be comprehensive).
* @param MVCFactoryInterface|null $factory The factory.
* @param CMSApplication|null $app The Application for
the dispatcher
* @param \Joomla\CMS\Input\Input|null $input The Input object
for the request
*
* @since 3.0
*/
public function __construct($config = [], MVCFactoryInterface $factory
= null, $app = null, $input = null)
{
// Contact frontpage Editor contacts proxying.
$input = Factory::getApplication()->getInput();
if ($input->get('view') === 'contacts'
&& $input->get('layout') === 'modal') {
$config['base_path'] = JPATH_COMPONENT_ADMINISTRATOR;
}
parent::__construct($config, $factory, $app, $input);
}
/**
* Method to display a view.
*
* @param boolean $cachable If true, the view output will be
cached
* @param array $urlparams An array of safe URL parameters and
their variable types.
* @see
\Joomla\CMS\Filter\InputFilter::clean() for valid values.
*
* @return DisplayController This object to support chaining.
*
* @since 1.5
*/
public function display($cachable = false, $urlparams = [])
{
if
($this->app->getUserState('com_contact.contact.data') ===
null) {
$cachable = true;
}
// Set the default view name and format from the Request.
$vName = $this->input->get('view',
'categories');
$this->input->set('view', $vName);
if ($this->app->getIdentity()->get('id')) {
$cachable = false;
}
$safeurlparams = [
'catid' => 'INT',
'id' => 'INT',
'cid' => 'ARRAY',
'year' => 'INT',
'month' => 'INT',
'limit' => 'UINT',
'limitstart' => 'UINT',
'showall' => 'INT',
'return' => 'BASE64',
'filter' => 'STRING',
'filter_order' => 'CMD',
'filter_order_Dir' => 'CMD',
'filter-search' => 'STRING',
'print' => 'BOOLEAN',
'lang' => 'CMD',
];
parent::display($cachable, $safeurlparams);
return $this;
}
}
PK��[&}9;9;
Controller/ContactController.phpnu�[���<?php
/**
* @package Joomla.Site
* @subpackage com_contact
*
* @copyright (C) 2010 Open Source Matters, Inc.
<https://www.joomla.org>
* @license GNU General Public License version 2 or later; see
LICENSE.txt
*/
namespace Joomla\Component\Contact\Site\Controller;
use Joomla\CMS\Event\Contact\SubmitContactEvent;
use Joomla\CMS\Event\Contact\ValidateContactEvent;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Log\Log;
use Joomla\CMS\Mail\Exception\MailDisabledException;
use Joomla\CMS\Mail\MailTemplate;
use Joomla\CMS\MVC\Controller\FormController;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Router\Route;
use Joomla\CMS\String\PunycodeHelper;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\User\UserFactoryAwareInterface;
use Joomla\CMS\User\UserFactoryAwareTrait;
use Joomla\CMS\Versioning\VersionableControllerTrait;
use Joomla\Component\Fields\Administrator\Helper\FieldsHelper;
use Joomla\Utilities\ArrayHelper;
use PHPMailer\PHPMailer\Exception as phpMailerException;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Controller for single contact view
*
* @since 1.5.19
*/
class ContactController extends FormController implements
UserFactoryAwareInterface
{
use UserFactoryAwareTrait;
use VersionableControllerTrait;
/**
* The URL view item variable.
*
* @var string
* @since 4.0.0
*/
protected $view_item = 'form';
/**
* The URL view list variable.
*
* @var string
* @since 4.0.0
*/
protected $view_list = 'categories';
/**
* Method to get a model object, loading it if required.
*
* @param string $name The model name. Optional.
* @param string $prefix The class prefix. Optional.
* @param array $config Configuration array for model. Optional.
*
* @return \Joomla\CMS\MVC\Model\BaseDatabaseModel The model.
*
* @since 1.6.4
*/
public function getModel($name = 'form', $prefix =
'', $config = ['ignore_request' => true])
{
return parent::getModel($name, $prefix, ['ignore_request'
=> false]);
}
/**
* Method to submit the contact form and send an email.
*
* @return boolean True on success sending the email. False on
failure.
*
* @since 1.5.19
*/
public function submit()
{
// Check for request forgeries.
$this->checkToken();
$app = $this->app;
$model = $this->getModel('contact');
$stub = $this->input->getString('id');
$id = (int) $stub;
// Get the data from POST
$data = $this->input->post->get('jform', [],
'array');
// Get item
$model->setState('filter.published', 1);
$contact = $model->getItem($id);
if ($contact === false) {
$this->setMessage($model->getError(), 'error');
return false;
}
// Get item params, take menu parameters into account if necessary
$active = $app->getMenu()->getActive();
$stateParams = clone
$model->getState()->get('params');
// If the current view is the active item and a contact view for
this contact, then the menu item params take priority
if ($active && strpos($active->link,
'view=contact') && strpos($active->link,
'&id=' . (int) $contact->id)) {
// $item->params are the contact params, $temp are the menu
item params
// Merge so that the menu item params take priority
$contact->params->merge($stateParams);
} else {
// Current view is not a single contact, so the contact params
take priority here
$stateParams->merge($contact->params);
$contact->params = $stateParams;
}
// Check if the contact form is enabled
if (!$contact->params->get('show_email_form')) {
$this->setRedirect(Route::_('index.php?option=com_contact&view=contact&id='
. $stub . '&catid=' . $contact->catid, false));
return false;
}
// Check for a valid session cookie
if ($contact->params->get('validate_session', 0)) {
if (Factory::getSession()->getState() !==
'active') {
$this->app->enqueueMessage(Text::_('JLIB_ENVIRONMENT_SESSION_INVALID'),
'warning');
// Save the data in the session.
$this->app->setUserState('com_contact.contact.data',
$data);
// Redirect back to the contact form.
$this->setRedirect(Route::_('index.php?option=com_contact&view=contact&id='
. $stub . '&catid=' . $contact->catid, false));
return false;
}
}
// Contact plugins
PluginHelper::importPlugin('contact');
// Validate the posted data.
$form = $model->getForm();
if (!$form) {
throw new \Exception($model->getError(), 500);
}
if (!$model->validate($form, $data)) {
$errors = $model->getErrors();
foreach ($errors as $error) {
$errorMessage = $error;
if ($error instanceof \Exception) {
$errorMessage = $error->getMessage();
}
$app->enqueueMessage($errorMessage, 'error');
}
$app->setUserState('com_contact.contact.data',
$data);
$this->setRedirect(Route::_('index.php?option=com_contact&view=contact&id='
. $stub . '&catid=' . $contact->catid, false));
return false;
}
// Validation succeeded, continue with custom handlers
$results =
$this->getDispatcher()->dispatch('onValidateContact', new
ValidateContactEvent('onValidateContact', [
'subject' => $contact,
'data' => &$data, // @todo: Remove
reference in Joomla 6, @deprecated: Data modification onValidateContact is
not allowed, use onSubmitContact instead
]))->getArgument('result', []);
$passValidation = true;
foreach ($results as $result) {
if ($result instanceof \Exception) {
$passValidation = false;
$app->enqueueMessage($result->getMessage(),
'error');
}
}
if (!$passValidation) {
$app->setUserState('com_contact.contact.data',
$data);
$this->setRedirect(Route::_('index.php?option=com_contact&view=contact&id='
. $id . '&catid=' . $contact->catid, false));
return false;
}
// Passed Validation: Process the contact plugins to integrate with
other applications
$event =
$this->getDispatcher()->dispatch('onSubmitContact', new
SubmitContactEvent('onSubmitContact', [
'subject' => $contact,
'data' => &$data, // @todo: Remove
reference in Joomla 6, see SubmitContactEvent::__constructor()
]));
// Get the final data
$data = $event->getArgument('data', $data);
// Send the email
$sent = false;
if (!$contact->params->get('custom_reply')) {
$sent = $this->_sendEmail($data, $contact,
$contact->params->get('show_email_copy', 0));
}
$msg = '';
// Set the success message if it was a success
if ($sent) {
$msg = Text::_('COM_CONTACT_EMAIL_THANKS');
}
// Flush the data from the session
$this->app->setUserState('com_contact.contact.data', null);
// Redirect if it is set in the parameters, otherwise redirect back
to where we came from
if ($contact->params->get('redirect')) {
$this->setRedirect($contact->params->get('redirect'),
$msg);
} else {
$this->setRedirect(Route::_('index.php?option=com_contact&view=contact&id='
. $stub . '&catid=' . $contact->catid, false), $msg);
}
return true;
}
/**
* Method to get a model object, loading it if required.
*
* @param array $data The data to send in the
email.
* @param \stdClass $contact The user information to send
the email to
* @param boolean $emailCopyToSender True to send a copy of the
email to the user.
*
* @return boolean True on success sending the email, false on
failure.
*
* @since 1.6.4
*/
private function _sendEmail($data, $contact, $emailCopyToSender)
{
$app = $this->app;
if ($contact->email_to == '' &&
$contact->user_id != 0) {
$contact_user =
$this->getUserFactory()->loadUserById($contact->user_id);
$contact->email_to =
$contact_user->get('email');
}
$templateData = [
'sitename' =>
$app->get('sitename'),
'name' => $data['contact_name'],
'contactname' => $contact->name,
'email' =>
PunycodeHelper::emailToPunycode($data['contact_email']),
'subject' =>
$data['contact_subject'],
'body' =>
stripslashes($data['contact_message']),
'url' => Uri::base(),
'customfields' => '',
];
// Load the custom fields
if (!empty($data['com_fields']) && $fields =
FieldsHelper::getFields('com_contact.mail', $contact, true,
$data['com_fields'])) {
$output = FieldsHelper::render(
'com_contact.mail',
'fields.render',
[
'context' => 'com_contact.mail',
'item' => $contact,
'fields' => $fields,
]
);
if ($output) {
$templateData['customfields'] = $output;
}
}
try {
$mailer = new MailTemplate('com_contact.mail',
$app->getLanguage()->getTag());
$mailer->addRecipient($contact->email_to);
$mailer->setReplyTo($templateData['email'],
$templateData['name']);
$mailer->addTemplateData($templateData);
$sent = $mailer->send();
// If we are supposed to copy the sender, do so.
if ($emailCopyToSender == true &&
!empty($data['contact_email_copy'])) {
$mailer = new
MailTemplate('com_contact.mail.copy',
$app->getLanguage()->getTag());
$mailer->addRecipient($templateData['email']);
$mailer->setReplyTo($templateData['email'],
$templateData['name']);
$mailer->addTemplateData($templateData);
$sent = $mailer->send();
}
} catch (MailDisabledException | phpMailerException $exception) {
try {
Log::add(Text::_($exception->getMessage()),
Log::WARNING, 'jerror');
$sent = false;
} catch (\RuntimeException $exception) {
$this->app->enqueueMessage(Text::_($exception->errorMessage()),
'warning');
$sent = false;
}
}
return $sent;
}
/**
* Method override to check if you can add a new record.
*
* @param array $data An array of input data.
*
* @return boolean
*
* @since 4.0.0
*/
protected function allowAdd($data = [])
{
if ($categoryId = ArrayHelper::getValue($data, 'catid',
$this->input->getInt('catid'), 'int')) {
$user = $this->app->getIdentity();
// If the category has been passed in the data or URL check it.
return $user->authorise('core.create',
'com_contact.category.' . $categoryId);
}
// In the absence of better information, revert to the component
permissions.
return parent::allowAdd();
}
/**
* Method override to check if you can edit an existing record.
*
* @param array $data An array of input data.
* @param string $key The name of the key for the primary key;
default is id.
*
* @return boolean
*
* @since 4.0.0
*/
protected function allowEdit($data = [], $key = 'id')
{
$recordId = (int) isset($data[$key]) ? $data[$key] : 0;
if (!$recordId) {
return false;
}
// Need to do a lookup from the model.
$record = $this->getModel()->getItem($recordId);
$categoryId = (int) $record->catid;
if ($categoryId) {
$user = $this->app->getIdentity();
// The category has been set. Check the category permissions.
if ($user->authorise('core.edit', $this->option
. '.category.' . $categoryId)) {
return true;
}
// Fallback on edit.own.
if ($user->authorise('core.edit.own',
$this->option . '.category.' . $categoryId)) {
return ($record->created_by === $user->id);
}
return false;
}
// Since there is no asset tracking, revert to the component
permissions.
return parent::allowEdit($data, $key);
}
/**
* Method to cancel an edit.
*
* @param string $key The name of the primary key of the URL
variable.
*
* @return boolean True if access level checks pass, false otherwise.
*
* @since 4.0.0
*/
public function cancel($key = null)
{
$result = parent::cancel($key);
$this->setRedirect(Route::_($this->getReturnPage(), false));
return $result;
}
/**
* Gets the URL arguments to append to an item redirect.
*
* @param integer $recordId The primary key id for the item.
* @param string $urlVar The name of the URL variable for the
id.
*
* @return string The arguments to append to the redirect URL.
*
* @since 4.0.0
*/
protected function getRedirectToItemAppend($recordId = 0, $urlVar =
'id')
{
// Need to override the parent method completely.
$tmpl = $this->input->get('tmpl');
$append = '';
// Setup redirect info.
if ($tmpl) {
$append .= '&tmpl=' . $tmpl;
}
$append .= '&layout=edit';
$append .= '&' . $urlVar . '=' . (int)
$recordId;
$itemId = $this->input->getInt('Itemid');
$return = $this->getReturnPage();
$catId = $this->input->getInt('catid');
if ($itemId) {
$append .= '&Itemid=' . $itemId;
}
if ($catId) {
$append .= '&catid=' . $catId;
}
if ($return) {
$append .= '&return=' . base64_encode($return);
}
return $append;
}
/**
* Get the return URL.
*
* If a "return" variable has been passed in the request
*
* @return string The return URL.
*
* @since 4.0.0
*/
protected function getReturnPage()
{
$return = $this->input->get('return', null,
'base64');
if (empty($return) || !Uri::isInternal(base64_decode($return))) {
return Uri::base();
}
return base64_decode($return);
}
}
PK��[-�߉||View/Category/FeedView.phpnu�[���<?php
/**
* @package Joomla.Site
* @subpackage com_contact
*
* @copyright (C) 2006 Open Source Matters, Inc.
<https://www.joomla.org>
* @license GNU General Public License version 2 or later; see
LICENSE.txt
*/
namespace Joomla\Component\Contact\Site\View\Category;
use Joomla\CMS\MVC\View\CategoryFeedView;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* HTML View class for the Contact component
*
* @since 1.5
*/
class FeedView extends CategoryFeedView
{
/**
* @var string The name of the view to link individual items to
* @since 3.2
*/
protected $viewName = 'contact';
/**
* Method to reconcile non standard names from components to usage in
this class.
* Typically overridden in the component feed view class.
*
* @param object $item The item for a feed, an element of the
$items array.
*
* @return void
*
* @since 3.2
*/
protected function reconcileNames($item)
{
parent::reconcileNames($item);
$item->description = $item->address;
}
}
PK��[U�Iͮ�View/Category/HtmlView.phpnu�[���<?php
/**
* @package Joomla.Site
* @subpackage com_contact
*
* @copyright (C) 2006 Open Source Matters, Inc.
<https://www.joomla.org>
* @license GNU General Public License version 2 or later; see
LICENSE.txt
*/
namespace Joomla\Component\Contact\Site\View\Category;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Mail\MailHelper;
use Joomla\CMS\MVC\View\CategoryView;
use Joomla\Component\Contact\Site\Helper\RouteHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* HTML View class for the Contacts component
*
* @since 1.5
*/
class HtmlView extends CategoryView
{
/**
* @var string The name of the extension for the category
* @since 3.2
*/
protected $extension = 'com_contact';
/**
* @var string Default title to use for page title
* @since 3.2
*/
protected $defaultPageTitle =
'COM_CONTACT_DEFAULT_PAGE_TITLE';
/**
* @var string The name of the view to link individual items to
* @since 3.2
*/
protected $viewName = 'contact';
/**
* Run the standard Joomla plugins
*
* @var boolean
* @since 3.5
*/
protected $runPlugins = true;
/**
* Execute and display a template script.
*
* @param string $tpl The name of the template file to parse;
automatically searches through the template paths.
*
* @return void
*/
public function display($tpl = null)
{
parent::commonCategoryDisplay();
// Flag indicates to not add limitstart=0 to URL
$this->pagination->hideEmptyLimitstart = true;
// Prepare the data.
// Compute the contact slug.
foreach ($this->items as $item) {
$item->slug = $item->alias ? ($item->id .
':' . $item->alias) : $item->id;
$temp = $item->params;
$item->params = clone $this->params;
$item->params->merge($temp);
if ($item->params->get('show_email_headings',
0) == 1) {
$item->email_to = trim($item->email_to);
if (!empty($item->email_to) &&
MailHelper::isEmailAddress($item->email_to)) {
$item->email_to =
HTMLHelper::_('email.cloak', $item->email_to);
} else {
$item->email_to = '';
}
}
}
parent::display($tpl);
}
/**
* Prepares the document
*
* @return void
*/
protected function prepareDocument()
{
parent::prepareDocument();
parent::addFeed();
if ($this->menuItemMatchCategory) {
// If the active menu item is linked directly to the category
being displayed, no further process is needed
return;
}
// Get ID of the category from active menu item
$menu = $this->menu;
if (
$menu && $menu->component == 'com_contact'
&& isset($menu->query['view'])
&& \in_array($menu->query['view'],
['categories', 'category'])
) {
$id = $menu->query['id'];
} else {
$id = 0;
}
$path = [['title' => $this->category->title,
'link' => '']];
$category = $this->category->getParent();
while ($category !== null && $category->id != $id
&& $category->id !== 'root') {
$path[] = ['title' => $category->title,
'link' => RouteHelper::getCategoryRoute($category->id,
$category->language)];
$category = $category->getParent();
}
$path = array_reverse($path);
foreach ($path as $item) {
$this->pathway->addItem($item['title'],
$item['link']);
}
}
}
PK��[�`�ttView/Contact/VcfView.phpnu�[���<?php
/**
* @package Joomla.Site
* @subpackage com_contact
*
* @copyright (C) 2010 Open Source Matters, Inc.
<https://www.joomla.org>
* @license GNU General Public License version 2 or later; see
LICENSE.txt
*/
namespace Joomla\Component\Contact\Site\View\Contact;
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\View\AbstractView;
use Joomla\CMS\MVC\View\GenericDataException;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* View to create a VCF for a contact item
*
* @since 1.6
*/
class VcfView extends AbstractView
{
/**
* The contact item
*
* @var \stdClass
*/
protected $item;
/**
* Execute and display a template script.
*
* @param string $tpl The name of the template file to parse;
automatically searches through the template paths.
*
* @return void
*
* @throws GenericDataException
*/
public function display($tpl = null)
{
// Get model data.
$item = $this->get('Item');
// Check for errors.
if (\count($errors = $this->get('Errors'))) {
throw new GenericDataException(implode("\n",
$errors), 500);
}
$this->getDocument()->setMimeEncoding('text/directory',
true);
// Compute lastname, firstname and middlename
$item->name = trim($item->name);
// "Lastname, Firstname Middlename" format support
// e.g. "de Gaulle, Charles"
$namearray = explode(',', $item->name);
if (\count($namearray) > 1) {
$lastname = $namearray[0];
$card_name = $lastname;
$name_and_midname = trim($namearray[1]);
$firstname = '';
if (!empty($name_and_midname)) {
$namearray = explode(' ', $name_and_midname);
$firstname = $namearray[0];
$middlename = (\count($namearray) > 1) ? $namearray[1] :
'';
$card_name = $firstname . ' ' . ($middlename ?
$middlename . ' ' : '') . $card_name;
}
} else {
// "Firstname Middlename Lastname" format support
$namearray = explode(' ', $item->name);
$middlename = (\count($namearray) > 2) ? $namearray[1] :
'';
$firstname = array_shift($namearray);
$lastname = \count($namearray) ? end($namearray) :
'';
$card_name = $firstname . ($middlename ? ' ' .
$middlename : '') . ($lastname ? ' ' . $lastname :
'');
}
$rev = date('c', strtotime($item->modified));
Factory::getApplication()->setHeader('Content-disposition',
'attachment; filename="' . $card_name .
'.vcf"', true);
$vcard = [];
$vcard[] = 'BEGIN:VCARD';
$vcard[] = 'VERSION:3.0';
$vcard[] = 'N:' . $lastname . ';' . $firstname
. ';' . $middlename;
$vcard[] = 'FN:' . $item->name;
$vcard[] = 'TITLE:' . $item->con_position;
$vcard[] = 'TEL;TYPE=WORK,VOICE:' . $item->telephone;
$vcard[] = 'TEL;TYPE=WORK,FAX:' . $item->fax;
$vcard[] = 'TEL;TYPE=WORK,MOBILE:' . $item->mobile;
$vcard[] = 'ADR;TYPE=WORK:;;' . $item->address .
';' . $item->suburb . ';' . $item->state .
';' . $item->postcode . ';' . $item->country;
$vcard[] = 'LABEL;TYPE=WORK:' . $item->address .
"\n" . $item->suburb . "\n" . $item->state .
"\n" . $item->postcode . "\n" . $item->country;
$vcard[] = 'EMAIL;TYPE=PREF,INTERNET:' .
$item->email_to;
$vcard[] = 'URL:' . $item->webpage;
$vcard[] = 'REV:' . $rev . 'Z';
$vcard[] = 'END:VCARD';
echo implode("\n", $vcard);
}
}
PK��[2��>�>View/Contact/HtmlView.phpnu�[���<?php
/**
* @package Joomla.Site
* @subpackage com_contact
*
* @copyright (C) 2006 Open Source Matters, Inc.
<https://www.joomla.org>
* @license GNU General Public License version 2 or later; see
LICENSE.txt
*/
namespace Joomla\Component\Contact\Site\View\Contact;
use Joomla\CMS\Categories\Categories;
use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Router\Route;
use Joomla\CMS\User\UserFactoryAwareInterface;
use Joomla\CMS\User\UserFactoryAwareTrait;
use Joomla\Component\Contact\Site\Helper\RouteHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* HTML Contact View class for the Contact component
*
* @since 1.5
*/
class HtmlView extends BaseHtmlView implements UserFactoryAwareInterface
{
use UserFactoryAwareTrait;
/**
* The item model state
*
* @var \Joomla\Registry\Registry
*
* @since 1.6
*/
protected $state;
/**
* The form object for the contact item
*
* @var \Joomla\CMS\Form\Form
*
* @since 1.6
*/
protected $form;
/**
* The item object details
*
* @var \stdClass
*
* @since 1.6
*/
protected $item;
/**
* The page to return to on submission
*
* @var string
*
* @since 1.6
*
* @todo Implement this functionality
*/
protected $return_page = '';
/**
* Should we show a captcha form for the submission of the contact
request?
*
* @var boolean
*
* @since 3.6.3
*/
protected $captchaEnabled = false;
/**
* The page parameters
*
* @var \Joomla\Registry\Registry|null
*
* @since 4.0.0
*/
protected $params = null;
/**
* The user object
*
* @var \Joomla\CMS\User\User
*
* @since 4.0.0
*/
protected $user;
/**
* Other contacts in this contacts category
*
* @var array
*
* @since 4.0.0
*/
protected $contacts;
/**
* The page class suffix
*
* @var string
*
* @since 4.0.0
*/
protected $pageclass_sfx = '';
/**
* The flag to mark if the active menu item is linked to the contact
being displayed
*
* @var boolean
*
* @since 4.0.0
*/
protected $menuItemMatchContact = false;
/**
* Execute and display a template script.
*
* @param string $tpl The name of the template file to parse;
automatically searches through the template paths.
*
* @return void|boolean
*/
public function display($tpl = null)
{
$app = Factory::getApplication();
$user = $this->getCurrentUser();
$state = $this->get('State');
$item = $this->get('Item');
$this->form = $this->get('Form');
$params = $state->get('params');
$contacts = [];
$temp = clone $params;
$active = $app->getMenu()->getActive();
// If the current view is the active item and a contact view for
this contact, then the menu item params take priority
if (
$active
&& $active->component == 'com_contact'
&& isset($active->query['view'],
$active->query['id'])
&& $active->query['view'] ==
'contact'
&& $active->query['id'] == $item->id
) {
$this->menuItemMatchContact = true;
// Load layout from active query (in case it is an alternative
menu item)
if (isset($active->query['layout'])) {
$this->setLayout($active->query['layout']);
} elseif ($layout =
$item->params->get('contact_layout')) {
// Check for alternative layout of contact
$this->setLayout($layout);
}
$item->params->merge($temp);
} else {
// Merge so that contact params take priority
$temp->merge($item->params);
$item->params = $temp;
if ($layout =
$item->params->get('contact_layout')) {
$this->setLayout($layout);
}
}
// Collect extra contact information when this information is
required
if ($item &&
$item->params->get('show_contact_list')) {
// Get Category Model data
/** @var \Joomla\Component\Contact\Site\Model\CategoryModel
$categoryModel */
$categoryModel =
$app->bootComponent('com_contact')->getMVCFactory()
->createModel('Category', 'Site',
['ignore_request' => true]);
$categoryModel->setState('category.id',
$item->catid);
$categoryModel->setState('list.ordering',
'a.name');
$categoryModel->setState('list.direction',
'asc');
$categoryModel->setState('filter.published', 1);
$contacts = $categoryModel->getItems();
}
// Check for errors.
if (\count($errors = $this->get('Errors'))) {
throw new GenericDataException(implode("\n",
$errors), 500);
}
// Check if access is not public
$groups = $user->getAuthorisedViewLevels();
if (!\in_array($item->access, $groups) ||
!\in_array($item->category_access, $groups)) {
$app->enqueueMessage(Text::_('JERROR_ALERTNOAUTHOR'),
'error');
$app->setHeader('status', 403, true);
return false;
}
$options['category_id'] = $item->catid;
$options['order by'] = 'a.default_con DESC,
a.ordering ASC';
/**
* Handle email cloaking
*
* Keep a copy of the raw email address so it can
* still be accessed in the layout if needed.
*/
$item->email_raw = $item->email_to;
if ($item->email_to &&
$item->params->get('show_email')) {
$item->email_to = HTMLHelper::_('email.cloak',
$item->email_to, (bool)
$item->params->get('add_mailto_link', true));
}
if (
$item->params->get('show_street_address') ||
$item->params->get('show_suburb') ||
$item->params->get('show_state')
|| $item->params->get('show_postcode') ||
$item->params->get('show_country')
) {
if (!empty($item->address) || !empty($item->suburb) ||
!empty($item->state) || !empty($item->country) ||
!empty($item->postcode)) {
$item->params->set('address_check', 1);
}
} else {
$item->params->set('address_check', 0);
}
// Manage the display mode for contact detail groups
switch ($item->params->get('contact_icons')) {
case 1:
// Text
$item->params->set('marker_address',
Text::_('COM_CONTACT_ADDRESS') . ': ');
$item->params->set('marker_email',
Text::_('JGLOBAL_EMAIL') . ': ');
$item->params->set('marker_telephone',
Text::_('COM_CONTACT_TELEPHONE') . ': ');
$item->params->set('marker_fax',
Text::_('COM_CONTACT_FAX') . ': ');
$item->params->set('marker_mobile',
Text::_('COM_CONTACT_MOBILE') . ': ');
$item->params->set('marker_webpage',
Text::_('COM_CONTACT_WEBPAGE') . ': ');
$item->params->set('marker_misc',
Text::_('COM_CONTACT_OTHER_INFORMATION') . ': ');
$item->params->set('marker_class',
'jicons-text');
break;
case 2:
// None
$item->params->set('marker_address',
'');
$item->params->set('marker_email',
'');
$item->params->set('marker_telephone',
'');
$item->params->set('marker_mobile',
'');
$item->params->set('marker_fax',
'');
$item->params->set('marker_misc',
'');
$item->params->set('marker_webpage',
'');
$item->params->set('marker_class',
'jicons-none');
break;
default:
if ($item->params->get('icon_address')) {
$item->params->set(
'marker_address',
HTMLHelper::_('image',
$item->params->get('icon_address', ''),
Text::_('COM_CONTACT_ADDRESS'), false)
);
}
if ($item->params->get('icon_email')) {
$item->params->set(
'marker_email',
HTMLHelper::_('image',
$item->params->get('icon_email', ''),
Text::_('COM_CONTACT_EMAIL'), false)
);
}
if ($item->params->get('icon_telephone')) {
$item->params->set(
'marker_telephone',
HTMLHelper::_('image',
$item->params->get('icon_telephone', ''),
Text::_('COM_CONTACT_TELEPHONE'), false)
);
}
if ($item->params->get('icon_fax',
'')) {
$item->params->set(
'marker_fax',
HTMLHelper::_('image',
$item->params->get('icon_fax', ''),
Text::_('COM_CONTACT_FAX'), false)
);
}
if ($item->params->get('icon_misc')) {
$item->params->set(
'marker_misc',
HTMLHelper::_('image',
$item->params->get('icon_misc', ''),
Text::_('COM_CONTACT_OTHER_INFORMATION'), false)
);
}
if ($item->params->get('icon_mobile')) {
$item->params->set(
'marker_mobile',
HTMLHelper::_('image',
$item->params->get('icon_mobile', ''),
Text::_('COM_CONTACT_MOBILE'), false)
);
}
if ($item->params->get('icon_webpage')) {
$item->params->set(
'marker_webpage',
HTMLHelper::_('image',
$item->params->get('icon_webpage', ''),
Text::_('COM_CONTACT_WEBPAGE'), false)
);
}
$item->params->set('marker_class',
'jicons-icons');
break;
}
// Add links to contacts
if ($item->params->get('show_contact_list')
&& \count($contacts) > 1) {
foreach ($contacts as &$contact) {
$contact->link =
Route::_(RouteHelper::getContactRoute($contact->slug,
$contact->catid, $contact->language));
}
$item->link =
Route::_(RouteHelper::getContactRoute($item->slug, $item->catid,
$item->language), false);
}
// Process the content plugins.
PluginHelper::importPlugin('content');
$offset = $state->get('list.offset');
// Fix for where some plugins require a text attribute
$item->text = '';
if (!empty($item->misc)) {
$item->text = $item->misc;
}
$app->triggerEvent('onContentPrepare',
['com_contact.contact', &$item, &$item->params,
$offset]);
// Store the events for later
$item->event = new \stdClass();
$results =
$app->triggerEvent('onContentAfterTitle',
['com_contact.contact', &$item, &$item->params,
$offset]);
$item->event->afterDisplayTitle =
trim(implode("\n", $results));
$results =
$app->triggerEvent('onContentBeforeDisplay',
['com_contact.contact', &$item, &$item->params,
$offset]);
$item->event->beforeDisplayContent =
trim(implode("\n", $results));
$results =
$app->triggerEvent('onContentAfterDisplay',
['com_contact.contact', &$item, &$item->params,
$offset]);
$item->event->afterDisplayContent =
trim(implode("\n", $results));
if (!empty($item->text)) {
$item->misc = $item->text;
}
$contactUser = null;
if ($item->params->get('show_user_custom_fields')
&& $item->user_id && $contactUser =
$this->getUserFactory()->loadUserById($item->user_id)) {
$contactUser->text = '';
$app->triggerEvent('onContentPrepare',
['com_users.user', &$contactUser, &$item->params, 0]);
if (!isset($contactUser->jcfields)) {
$contactUser->jcfields = [];
}
}
// Escape strings for HTML output
$this->pageclass_sfx =
htmlspecialchars($item->params->get('pageclass_sfx',
''));
$this->params = &$item->params;
$this->state = &$state;
$this->item = &$item;
$this->user = &$user;
$this->contacts = &$contacts;
$this->contactUser = $contactUser;
$model = $this->getModel();
$model->hit();
$captchaSet = $item->params->get('captcha',
$app->get('captcha', '0'));
foreach (PluginHelper::getPlugin('captcha') as $plugin) {
if ($captchaSet === $plugin->name) {
$this->captchaEnabled = true;
break;
}
}
$this->_prepareDocument();
parent::display($tpl);
}
/**
* Prepares the document
*
* @return void
*
* @since 1.6
*/
protected function _prepareDocument()
{
$app = Factory::getApplication();
$pathway = $app->getPathway();
// Because the application sets a default page title,
// we need to get it from the menu item itself
$menu = $app->getMenu()->getActive();
if ($menu) {
$this->params->def('page_heading',
$this->params->get('page_title', $menu->title));
} else {
$this->params->def('page_heading',
Text::_('COM_CONTACT_DEFAULT_PAGE_TITLE'));
}
$title = $this->params->get('page_title',
'');
// If the menu item does not concern this contact
if (!$this->menuItemMatchContact) {
// If this is not a single contact menu item, set the page
title to the contact title
if ($this->item->name) {
$title = $this->item->name;
}
// Get ID of the category from active menu item
if (
$menu && $menu->component ==
'com_contact' && isset($menu->query['view'])
&& \in_array($menu->query['view'],
['categories', 'category'])
) {
$id = $menu->query['id'];
} else {
$id = 0;
}
$path = [['title' => $this->item->name,
'link' => '']];
$category =
Categories::getInstance('Contact')->get($this->item->catid);
while ($category !== null && $category->id != $id
&& $category->id !== 'root') {
$path[] = ['title' => $category->title,
'link' => RouteHelper::getCategoryRoute($category->id,
$category->language)];
$category = $category->getParent();
}
$path = array_reverse($path);
foreach ($path as $item) {
$pathway->addItem($item['title'],
$item['link']);
}
}
if (empty($title)) {
$title = $this->item->name;
}
$this->setDocumentTitle($title);
if ($this->item->metadesc) {
$this->getDocument()->setDescription($this->item->metadesc);
} elseif
($this->params->get('menu-meta_description')) {
$this->getDocument()->setDescription($this->params->get('menu-meta_description'));
}
if ($this->params->get('robots')) {
$this->getDocument()->setMetaData('robots',
$this->params->get('robots'));
}
$mdata = $this->item->metadata->toArray();
foreach ($mdata as $k => $v) {
if ($v) {
$this->getDocument()->setMetaData($k, $v);
}
}
}
}
PK��[�q�\WWView/Featured/HtmlView.phpnu�[���<?php
/**
* @package Joomla.Site
* @subpackage com_contact
*
* @copyright (C) 2010 Open Source Matters, Inc.
<https://www.joomla.org>
* @license GNU General Public License version 2 or later; see
LICENSE.txt
*/
namespace Joomla\Component\Contact\Site\View\Featured;
use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Mail\MailHelper;
use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Featured View class
*
* @since 1.6
*/
class HtmlView extends BaseHtmlView
{
/**
* The item model state
*
* @var \Joomla\Registry\Registry
*
* @since 1.6.0
*/
protected $state;
/**
* The item details
*
* @var array
*
* @since 1.6.0
*/
protected $items;
/**
* The pagination object
*
* @var \Joomla\CMS\Pagination\Pagination
*
* @since 1.6.0
*/
protected $pagination;
/**
* The page parameters
*
* @var \Joomla\Registry\Registry|null
*
* @since 4.0.0
*/
protected $params = null;
/**
* The page class suffix
*
* @var string
*
* @since 4.0.0
*/
protected $pageclass_sfx = '';
/**
* Method to display the view.
*
* @param string $tpl The name of the template file to parse;
automatically searches through the template paths.
*
* @return void
*
* @since 1.6
*/
public function display($tpl = null)
{
$app = Factory::getApplication();
$params = $app->getParams();
// Get some data from the models
$state = $this->get('State');
$items = $this->get('Items');
$category = $this->get('Category');
$children = $this->get('Children');
$parent = $this->get('Parent');
$pagination = $this->get('Pagination');
// Flag indicates to not add limitstart=0 to URL
$pagination->hideEmptyLimitstart = true;
// Check for errors.
if (\count($errors = $this->get('Errors'))) {
throw new GenericDataException(implode("\n",
$errors), 500);
}
// Prepare the data.
// Compute the contact slug.
for ($i = 0, $n = \count($items); $i < $n; $i++) {
$item = &$items[$i];
$item->slug = $item->alias ? ($item->id .
':' . $item->alias) : $item->id;
$temp = $item->params;
$item->params = clone $params;
$item->params->merge($temp);
if ($item->params->get('show_email', 0) == 1) {
$item->email_to = trim($item->email_to);
if (!empty($item->email_to) &&
MailHelper::isEmailAddress($item->email_to)) {
$item->email_to =
HTMLHelper::_('email.cloak', $item->email_to);
} else {
$item->email_to = '';
}
}
}
// Escape strings for HTML output
$this->pageclass_sfx =
htmlspecialchars($params->get('pageclass_sfx', ''),
ENT_COMPAT, 'UTF-8');
$maxLevel = $params->get('maxLevel', -1);
$this->maxLevel = &$maxLevel;
$this->state = &$state;
$this->items = &$items;
$this->category = &$category;
$this->children = &$children;
$this->params = &$params;
$this->parent = &$parent;
$this->pagination = &$pagination;
$this->_prepareDocument();
parent::display($tpl);
}
/**
* Prepares the document
*
* @return void
*
* @since 1.6
*/
protected function _prepareDocument()
{
// Because the application sets a default page title,
// we need to get it from the menu item itself
$menu = Factory::getApplication()->getMenu()->getActive();
if ($menu) {
$this->params->def('page_heading',
$this->params->get('page_title', $menu->title));
} else {
$this->params->def('page_heading',
Text::_('COM_CONTACT_DEFAULT_PAGE_TITLE'));
}
$this->setDocumentTitle($this->params->get('page_title',
''));
if ($this->params->get('menu-meta_description')) {
$this->getDocument()->setDescription($this->params->get('menu-meta_description'));
}
if ($this->params->get('robots')) {
$this->getDocument()->setMetaData('robots',
$this->params->get('robots'));
}
}
}
PK��[�5g���View/Form/HtmlView.phpnu�[���<?php
/**
* @package Joomla.Site
* @subpackage com_contact
*
* @copyright (C) 2020 Open Source Matters, Inc.
<https://www.joomla.org>
* @license GNU General Public License version 2 or later; see
LICENSE.txt
*/
namespace Joomla\Component\Contact\Site\View\Form;
use Joomla\CMS\Factory;
use Joomla\CMS\Helper\TagsHelper;
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\Component\Contact\Administrator\Helper\ContactHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* HTML Contact View class for the Contact component
*
* @since 4.0.0
*/
class HtmlView extends BaseHtmlView
{
/**
* @var \Joomla\CMS\Form\Form
* @since 4.0.0
*/
protected $form;
/**
* @var object
* @since 4.0.0
*/
protected $item;
/**
* @var string
* @since 4.0.0
*/
protected $return_page;
/**
* @var string
* @since 4.0.0
*/
protected $pageclass_sfx;
/**
* @var \Joomla\Registry\Registry
* @since 4.0.0
*/
protected $state;
/**
* @var \Joomla\Registry\Registry
* @since 4.0.0
*/
protected $params;
/**
* Execute and display a template script.
*
* @param string $tpl The name of the template file to parse;
automatically searches through the template paths.
*
* @return void|boolean
*
* @throws \Exception
* @since 4.0.0
*/
public function display($tpl = null)
{
$user = $this->getCurrentUser();
$app = Factory::getApplication();
// Get model data.
$this->state = $this->get('State');
$this->item = $this->get('Item');
$this->form = $this->get('Form');
$this->return_page = $this->get('ReturnPage');
if (empty($this->item->id)) {
$authorised = $user->authorise('core.create',
'com_contact') ||
\count($user->getAuthorisedCategories('com_contact',
'core.create'));
} else {
// Since we don't track these assets at the item level,
use the category id.
$canDo =
ContactHelper::getActions('com_contact', 'category',
$this->item->catid);
$authorised = $canDo->get('core.edit') ||
($canDo->get('core.edit.own') &&
$this->item->created_by === $user->id);
}
if ($authorised !== true) {
$app->enqueueMessage(Text::_('JERROR_ALERTNOAUTHOR'),
'error');
$app->setHeader('status', 403, true);
return false;
}
$this->item->tags = new TagsHelper();
if (!empty($this->item->id)) {
$this->item->tags->getItemTags('com_contact.contact',
$this->item->id);
}
// Check for errors.
if (\count($errors = $this->get('Errors'))) {
$app->enqueueMessage(implode("\n", $errors),
'error');
return false;
}
// Create a shortcut to the parameters.
$this->params = $this->state->params;
// Escape strings for HTML output
$this->pageclass_sfx =
htmlspecialchars($this->params->get('pageclass_sfx',
''));
// Override global params with contact specific params
$this->params->merge($this->item->params);
// Propose current language as default when creating new contact
if (empty($this->item->id) &&
Multilanguage::isEnabled()) {
$lang = $this->getLanguage()->getTag();
$this->form->setFieldAttribute('language',
'default', $lang);
}
$this->_prepareDocument();
parent::display($tpl);
}
/**
* Prepares the document
*
* @return void
*
* @throws \Exception
*
* @since 4.0.0
*/
protected function _prepareDocument()
{
$app = Factory::getApplication();
// Because the application sets a default page title,
// we need to get it from the menu item itself
$menu = $app->getMenu()->getActive();
if ($menu) {
$this->params->def('page_heading',
$this->params->get('page_title', $menu->title));
} else {
$this->params->def('page_heading',
Text::_('COM_CONTACT_FORM_EDIT_CONTACT'));
}
$title = $this->params->def('page_title',
Text::_('COM_CONTACT_FORM_EDIT_CONTACT'));
$this->setDocumentTitle($title);
$pathway = $app->getPathWay();
$pathway->addItem($title, '');
if ($this->params->get('menu-meta_description')) {
$this->getDocument()->setDescription($this->params->get('menu-meta_description'));
}
if ($this->params->get('menu-meta_keywords')) {
$this->getDocument()->setMetaData('keywords',
$this->params->get('menu-meta_keywords'));
}
if ($this->params->get('robots')) {
$this->getDocument()->setMetaData('robots',
$this->params->get('robots'));
}
}
}
PK��[�7SPPView/Categories/HtmlView.phpnu�[���<?php
/**
* @package Joomla.Site
* @subpackage com_contact
*
* @copyright (C) 2008 Open Source Matters, Inc.
<https://www.joomla.org>
* @license GNU General Public License version 2 or later; see
LICENSE.txt
*/
namespace Joomla\Component\Contact\Site\View\Categories;
use Joomla\CMS\MVC\View\CategoriesView;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Contact categories view.
*
* @since 1.6
*/
class HtmlView extends CategoriesView
{
/**
* Language key for default page heading
*
* @var string
* @since 3.2
*/
protected $pageHeading = 'COM_CONTACT_DEFAULT_PAGE_TITLE';
/**
* @var string The name of the extension for the category
* @since 3.2
*/
protected $extension = 'com_contact';
}
PK��[q����Rule/ContactEmailRule.phpnu�[���<?php
/**
* @package Joomla.Site
* @subpackage com_contact
*
* @copyright (C) 2017 Open Source Matters, Inc.
<https://www.joomla.org>
* @license GNU General Public License version 2 or later; see
LICENSE.txt
*/
namespace Joomla\Component\Contact\Site\Rule;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Form\Rule\EmailRule;
use Joomla\Registry\Registry;
use Joomla\String\StringHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* FormRule for com_contact to make sure the email address is not blocked.
*
* @since 1.6
*/
class ContactEmailRule extends EmailRule
{
/**
* Method to test for banned email addresses
*
* @param \SimpleXMLElement $element The SimpleXMLElement object
representing the <field /> tag for the form field object.
* @param mixed $value The form field value to
validate.
* @param string $group The field name group control
value. This acts as an array container for the field.
* For example if the field has
name="foo" and the group value is set to "bar" then the
* full field name would end up
being "bar[foo]".
* @param Registry $input An optional Registry object
with the entire data set to validate against the entire form.
* @param Form $form The form object for which the
field is being tested.
*
* @return boolean True if the value is valid, false otherwise.
*/
public function test(\SimpleXMLElement $element, $value, $group = null,
Registry $input = null, Form $form = null)
{
if (!parent::test($element, $value, $group, $input, $form)) {
return false;
}
$params = ComponentHelper::getParams('com_contact');
$banned = $params->get('banned_email');
if ($banned) {
foreach (explode(';', $banned) as $item) {
$item = trim($item);
if ($item != '' &&
StringHelper::stristr($value, $item) !== false) {
return false;
}
}
}
return true;
}
}
PK��[G�#��
Rule/ContactEmailSubjectRule.phpnu�[���<?php
/**
* @package Joomla.Site
* @subpackage com_contact
*
* @copyright (C) 2017 Open Source Matters, Inc.
<https://www.joomla.org>
* @license GNU General Public License version 2 or later; see
LICENSE.txt
*/
namespace Joomla\Component\Contact\Site\Rule;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Form\FormRule;
use Joomla\Registry\Registry;
use Joomla\String\StringHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* FormRule for com_contact to make sure the subject contains no banned
word.
*
* @since 1.6
*/
class ContactEmailSubjectRule extends FormRule
{
/**
* Method to test for a banned subject
*
* @param \SimpleXMLElement $element The SimpleXMLElement object
representing the <field /> tag for the form field object.
* @param mixed $value The form field value to
validate.
* @param string $group The field name group control
value. This acts as an array container for the field.
* For example if the field has
name="foo" and the group value is set to "bar" then the
* full field name would end up
being "bar[foo]".
* @param Registry $input An optional Registry object
with the entire data set to validate against the entire form.
* @param Form $form The form object for which the
field is being tested.
*
* @return boolean True if the value is valid, false otherwise
*/
public function test(\SimpleXMLElement $element, $value, $group = null,
Registry $input = null, Form $form = null)
{
$params = ComponentHelper::getParams('com_contact');
$banned = $params->get('banned_subject');
if ($banned) {
foreach (explode(';', $banned) as $item) {
$item = trim($item);
if ($item != '' &&
StringHelper::stristr($value, $item) !== false) {
return false;
}
}
}
return true;
}
}
PK��[8z�p��
Rule/ContactEmailMessageRule.phpnu�[���<?php
/**
* @package Joomla.Site
* @subpackage com_contact
*
* @copyright (C) 2017 Open Source Matters, Inc.
<https://www.joomla.org>
* @license GNU General Public License version 2 or later; see
LICENSE.txt
*/
namespace Joomla\Component\Contact\Site\Rule;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Form\FormRule;
use Joomla\Registry\Registry;
use Joomla\String\StringHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* FormRule for com_contact to make sure the message body contains no
banned word.
*
* @since 1.6
*/
class ContactEmailMessageRule extends FormRule
{
/**
* Method to test a message for banned words
*
* @param \SimpleXMLElement $element The SimpleXMLElement object
representing the <field /> tag for the form field object.
* @param mixed $value The form field value to
validate.
* @param string $group The field name group control
value. This acts as an array container for the field.
* For example if the field has
name="foo" and the group value is set to "bar" then the
* full field name would end up
being "bar[foo]".
* @param Registry $input An optional Registry object
with the entire data set to validate against the entire form.
* @param Form $form The form object for which the
field is being tested.
*
* @return boolean True if the value is valid, false otherwise.
*/
public function test(\SimpleXMLElement $element, $value, $group = null,
Registry $input = null, Form $form = null)
{
$params = ComponentHelper::getParams('com_contact');
$banned = $params->get('banned_text');
if ($banned) {
foreach (explode(';', $banned) as $item) {
$item = trim($item);
if ($item != '' &&
StringHelper::stristr($value, $item) !== false) {
return false;
}
}
}
return true;
}
}
PK1�[��nnField/TermsField.phpnu�[���<?php
/**
* @package Joomla.Plugin
* @subpackage User.terms
*
* @copyright (C) 2018 Open Source Matters, Inc.
<https://www.joomla.org>
* @license GNU General Public License version 2 or later; see
LICENSE.txt
*/
namespace Joomla\Plugin\User\Terms\Field;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Field\RadioField;
use Joomla\CMS\Language\Associations;
use Joomla\CMS\Language\Text;
use Joomla\Component\Content\Site\Helper\RouteHelper;
use Joomla\Database\ParameterType;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Provides input for privacyterms
*
* @since 3.9.0
*/
class TermsField extends RadioField
{
/**
* The form field type.
*
* @var string
* @since 3.9.0
*/
protected $type = 'terms';
/**
* Method to get the field input markup.
*
* @return string The field input markup.
*
* @since 3.9.0
*/
protected function getInput()
{
// Display the message before the field
echo
$this->getRenderer('plugins.user.terms.message')->render($this->getLayoutData());
return parent::getInput();
}
/**
* Method to get the field label markup.
*
* @return string The field label markup.
*
* @since 3.9.0
*/
protected function getLabel()
{
if ($this->hidden) {
return '';
}
return
$this->getRenderer('plugins.user.terms.label')->render($this->getLayoutData());
}
/**
* Method to get the data to be passed to the layout for rendering.
*
* @return array
*
* @since 3.9.4
*/
protected function getLayoutData()
{
$data = parent::getLayoutData();
$article = false;
$termsArticle = $this->element['article'] > 0 ?
(int) $this->element['article'] : 0;
if ($termsArticle &&
Factory::getApplication()->isClient('site')) {
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select($db->quoteName(['id',
'alias', 'catid', 'language']))
->from($db->quoteName('#__content'))
->where($db->quoteName('id') . ' =
:id')
->bind(':id', $termsArticle,
ParameterType::INTEGER);
$db->setQuery($query);
$article = $db->loadObject();
if (Associations::isEnabled()) {
$termsAssociated =
Associations::getAssociations('com_content',
'#__content', 'com_content.item', $termsArticle);
}
$currentLang = Factory::getLanguage()->getTag();
if (isset($termsAssociated) && $currentLang !==
$article->language && \array_key_exists($currentLang,
$termsAssociated)) {
$article->link = RouteHelper::getArticleRoute(
$termsAssociated[$currentLang]->id,
$termsAssociated[$currentLang]->catid,
$termsAssociated[$currentLang]->language
);
} else {
$slug = $article->alias ? ($article->id .
':' . $article->alias) : $article->id;
$article->link = RouteHelper::getArticleRoute($slug,
$article->catid, $article->language);
}
}
$extraData = [
'termsnote' =>
!empty($this->element['note']) ?
$this->element['note'] :
Text::_('PLG_USER_TERMS_NOTE_FIELD_DEFAULT'),
'options' => $this->getOptions(),
'value' => (string)
$this->value,
'translateLabel' =>
$this->translateLabel,
'translateDescription' =>
$this->translateDescription,
'translateHint' => $this->translateHint,
'termsArticle' => $termsArticle,
'article' => $article,
];
return array_merge($data, $extraData);
}
}
PK1�[��V�[[Extension/Terms.phpnu�[���<?php
/**
* @package Joomla.Plugin
* @subpackage User.terms
*
* @copyright (C) 2018 Open Source Matters, Inc.
<https://www.joomla.org>
* @license GNU General Public License version 2 or later; see
LICENSE.txt
*/
namespace Joomla\Plugin\User\Terms\Extension;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Form\FormHelper;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Component\Actionlogs\Administrator\Model\ActionlogModel;
use Joomla\Utilities\ArrayHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* An example custom terms and conditions plugin.
*
* @since 3.9.0
*/
final class Terms extends CMSPlugin
{
/**
* Adds additional fields to the user registration form
*
* @param Form $form The form to be altered.
* @param mixed $data The associated data for the form.
*
* @return boolean
*
* @since 3.9.0
*/
public function onContentPrepareForm(Form $form, $data)
{
// Check we are manipulating a valid form - we only display this on
user registration form.
$name = $form->getName();
if (!\in_array($name, ['com_users.registration'])) {
return true;
}
// Load plugin language files
$this->loadLanguage();
// Add the terms and conditions fields to the form.
FormHelper::addFieldPrefix('Joomla\\Plugin\\User\\Terms\\Field');
FormHelper::addFormPath(JPATH_PLUGINS . '/' .
$this->_type . '/' . $this->_name . '/forms');
$form->loadFile('terms');
$termsarticle =
$this->params->get('terms_article');
$termsnote = $this->params->get('terms_note');
// Push the terms and conditions article ID into the terms field.
$form->setFieldAttribute('terms', 'article',
$termsarticle, 'terms');
$form->setFieldAttribute('terms', 'note',
$termsnote, 'terms');
}
/**
* Method is called before user data is stored in the database
*
* @param array $user Holds the old user data.
* @param boolean $isNew True if a new user is stored.
* @param array $data Holds the new user data.
*
* @return boolean
*
* @since 3.9.0
* @throws \InvalidArgumentException on missing required data.
*/
public function onUserBeforeSave($user, $isNew, $data)
{
// // Only check for front-end user registration
if
($this->getApplication()->isClient('administrator')) {
return true;
}
$userId = ArrayHelper::getValue($user, 'id', 0,
'int');
// User already registered, no need to check it further
if ($userId > 0) {
return true;
}
// Load plugin language files
$this->loadLanguage();
// Check that the terms is checked if required ie only in
registration from frontend.
$input = $this->getApplication()->getInput();
$option = $input->get('option');
$task = $input->post->get('task');
$form = $input->post->get('jform', [],
'array');
if ($option == 'com_users' && \in_array($task,
['registration.register']) &&
empty($form['terms']['terms'])) {
throw new
\InvalidArgumentException($this->getApplication()->getLanguage()->_('PLG_USER_TERMS_FIELD_ERROR'));
}
return true;
}
/**
* Saves user profile data
*
* @param array $data entered user data
* @param boolean $isNew true if this is a new user
* @param boolean $result true if saving the user worked
* @param string $error error message
*
* @return void
*
* @since 3.9.0
*/
public function onUserAfterSave($data, $isNew, $result, $error): void
{
if (!$isNew || !$result) {
return;
}
$userId = ArrayHelper::getValue($data, 'id', 0,
'int');
$message = [
'action' => 'consent',
'id' => $userId,
'title' => $data['name'],
'itemlink' =>
'index.php?option=com_users&task=user.edit&id=' .
$userId,
'userid' => $userId,
'username' => $data['username'],
'accountlink' =>
'index.php?option=com_users&task=user.edit&id=' .
$userId,
];
/** @var ActionlogModel $model */
$model = $this->getApplication()
->bootComponent('com_actionlogs')
->getMVCFactory()
->createModel('Actionlog',
'Administrator');
$model->addLog([$message],
'PLG_USER_TERMS_LOGGING_CONSENT_TO_TERMS',
'plg_user_terms', $userId);
}
}
PK�3�[֬gsp5p5
Container.phpnu�[���<?php
/**
* Part of the Joomla Framework DI Package
*
* @copyright Copyright (C) 2013 - 2018 Open Source Matters, Inc. All
rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\DI;
use Joomla\DI\Exception\DependencyResolutionException;
use Joomla\DI\Exception\KeyNotFoundException;
use Joomla\DI\Exception\ProtectedKeyException;
use Psr\Container\ContainerInterface;
/**
* The Container class.
*
* @since 1.0
*/
class Container implements ContainerInterface
{
/**
* Holds the key aliases.
*
* @var array
* @since 1.0
*/
protected $aliases = array();
/**
* Holds the shared instances.
*
* @var array
* @since 1.0
*/
protected $instances = array();
/**
* Holds the keys, their callbacks, and whether or not
* the item is meant to be a shared resource.
*
* @var array
* @since 1.0
*/
protected $dataStore = array();
/**
* Parent for hierarchical containers.
*
* @var Container|ContainerInterface
* @since 1.0
*/
protected $parent;
/**
* Holds the service tag mapping.
*
* @var array
* @since 1.5.0
*/
protected $tags = array();
/**
* Constructor for the DI Container
*
* @param ContainerInterface $parent Parent for hierarchical
containers.
*
* @since 1.0
*/
public function __construct(ContainerInterface $parent = null)
{
$this->parent = $parent;
}
/**
* Create an alias for a given key for easy access.
*
* @param string $alias The alias name
* @param string $key The key to alias
*
* @return Container This object for chaining.
*
* @since 1.0
*/
public function alias($alias, $key)
{
$this->aliases[$alias] = $key;
return $this;
}
/**
* Search the aliases property for a matching alias key.
*
* @param string $key The key to search for.
*
* @return string
*
* @since 1.0
*/
protected function resolveAlias($key)
{
if (isset($this->aliases[$key]))
{
return $this->aliases[$key];
}
if ($this->parent instanceof Container)
{
return $this->parent->resolveAlias($key);
}
return $key;
}
/**
* Assign a tag to services.
*
* @param string $tag The tag name
* @param array $keys The service keys to tag
*
* @return Container This object for chaining.
*
* @since 1.5.0
*/
public function tag($tag, array $keys)
{
foreach ($keys as $key)
{
$resolvedKey = $this->resolveAlias($key);
if (!isset($this->tags[$tag]))
{
$this->tags[$tag] = array();
}
$this->tags[$tag][] = $resolvedKey;
}
// Prune duplicates
$this->tags[$tag] = array_unique($this->tags[$tag]);
return $this;
}
/**
* Fetch all services registered to the given tag.
*
* @param string $tag The tag name
*
* @return array The resolved services for the given tag
*
* @since 1.5.0
*/
public function getTagged($tag)
{
$services = array();
if (isset($this->tags[$tag]))
{
foreach ($this->tags[$tag] as $service)
{
$services[] = $this->get($service);
}
}
return $services;
}
/**
* Build an object of class $key;
*
* @param string $key The class name to build.
* @param boolean $shared True to create a shared resource.
*
* @return object|false Instance of class specified by $key with all
dependencies injected.
* Returns an object if the class exists and false
otherwise
*
* @since 1.0
*/
public function buildObject($key, $shared = false)
{
static $buildStack = array();
$resolvedKey = $this->resolveAlias($key);
if (in_array($resolvedKey, $buildStack, true))
{
$buildStack = array();
throw new DependencyResolutionException("Can't resolve
circular dependency");
}
$buildStack[] = $resolvedKey;
if ($this->has($resolvedKey))
{
$resource = $this->get($resolvedKey);
array_pop($buildStack);
return $resource;
}
try
{
$reflection = new \ReflectionClass($resolvedKey);
}
catch (\ReflectionException $e)
{
array_pop($buildStack);
return false;
}
if (!$reflection->isInstantiable())
{
$buildStack = array();
throw new DependencyResolutionException("$resolvedKey can not be
instantiated.");
}
$constructor = $reflection->getConstructor();
// If there are no parameters, just return a new object.
if ($constructor === null)
{
$callback = function () use ($resolvedKey) {
return new $resolvedKey;
};
}
else
{
$newInstanceArgs = $this->getMethodArgs($constructor);
// Create a callable for the dataStore
$callback = function () use ($reflection, $newInstanceArgs) {
return $reflection->newInstanceArgs($newInstanceArgs);
};
}
$this->set($resolvedKey, $callback, $shared);
$resource = $this->get($resolvedKey);
array_pop($buildStack);
return $resource;
}
/**
* Convenience method for building a shared object.
*
* @param string $key The class name to build.
*
* @return object|false Instance of class specified by $key with all
dependencies injected.
* Returns an object if the class exists and false
otherwise
*
* @since 1.0
*/
public function buildSharedObject($key)
{
return $this->buildObject($key, true);
}
/**
* Create a child Container with a new property scope that
* that has the ability to access the parent scope when resolving.
*
* @return Container This object for chaining.
*
* @since 1.0
*/
public function createChild()
{
return new static($this);
}
/**
* Extend a defined service Closure by wrapping the existing one with a
new Closure. This
* works very similar to a decorator pattern. Note that this only works
on service Closures
* that have been defined in the current Provider, not parent providers.
*
* @param string $key The unique identifier for the Closure or
property.
* @param \Closure $callable A Closure to wrap the original service
Closure.
*
* @return void
*
* @since 1.0
* @throws KeyNotFoundException
*/
public function extend($key, \Closure $callable)
{
$key = $this->resolveAlias($key);
$raw = $this->getRaw($key);
if ($raw === null)
{
throw new KeyNotFoundException(sprintf('The requested key %s does
not exist to extend.', $key));
}
$closure = function ($c) use ($callable, $raw) {
return $callable($raw['callback']($c), $c);
};
$this->set($key, $closure, $raw['shared']);
}
/**
* Build an array of constructor parameters.
*
* @param \ReflectionMethod $method Method for which to build the
argument array.
*
* @return array Array of arguments to pass to the method.
*
* @since 1.0
* @throws DependencyResolutionException
*/
protected function getMethodArgs(\ReflectionMethod $method)
{
$methodArgs = array();
foreach ($method->getParameters() as $param)
{
$dependency = $param->getClass();
$dependencyVarName = $param->getName();
// If we have a dependency, that means it has been type-hinted.
if ($dependency !== null)
{
$dependencyClassName = $dependency->getName();
// If the dependency class name is registered with this container or a
parent, use it.
if ($this->getRaw($dependencyClassName) !== null)
{
$depObject = $this->get($dependencyClassName);
}
else
{
$depObject = $this->buildObject($dependencyClassName);
}
if ($depObject instanceof $dependencyClassName)
{
$methodArgs[] = $depObject;
continue;
}
}
// Finally, if there is a default parameter, use it.
if ($param->isOptional())
{
$methodArgs[] = $param->getDefaultValue();
continue;
}
// Couldn't resolve dependency, and no default was provided.
throw new DependencyResolutionException(sprintf('Could not resolve
dependency: %s', $dependencyVarName));
}
return $methodArgs;
}
/**
* Method to set the key and callback to the dataStore array.
*
* @param string $key Name of dataStore key to set.
* @param mixed $value Callable function to run or string to
retrive when requesting the specified $key.
* @param boolean $shared True to create and store a shared
instance.
* @param boolean $protected True to protect this item from being
overwritten. Useful for services.
*
* @return Container This object for chaining.
*
* @since 1.0
* @throws ProtectedKeyException Thrown if the provided key is already
set and is protected.
*/
public function set($key, $value, $shared = false, $protected = false)
{
if (isset($this->dataStore[$key]) &&
$this->dataStore[$key]['protected'] === true)
{
throw new ProtectedKeyException(sprintf("Key %s is protected and
can't be overwritten.", $key));
}
// If the provided $value is not a closure, make it one now for easy
resolution.
if (!is_callable($value))
{
$value = function () use ($value) {
return $value;
};
}
$this->dataStore[$key] = array(
'callback' => $value,
'shared' => $shared,
'protected' => $protected
);
return $this;
}
/**
* Convenience method for creating protected keys.
*
* @param string $key Name of dataStore key to set.
* @param mixed $value Callable function to run or string to
retrive when requesting the specified $key.
* @param boolean $shared True to create and store a shared instance.
*
* @return Container This object for chaining.
*
* @since 1.0
*/
public function protect($key, $value, $shared = false)
{
return $this->set($key, $value, $shared, true);
}
/**
* Convenience method for creating shared keys.
*
* @param string $key Name of dataStore key to set.
* @param mixed $value Callable function to run or string to
retrive when requesting the specified $key.
* @param boolean $protected True to protect this item from being
overwritten. Useful for services.
*
* @return Container This object for chaining.
*
* @since 1.0
*/
public function share($key, $value, $protected = false)
{
return $this->set($key, $value, true, $protected);
}
/**
* Method to retrieve the results of running the $callback for the
specified $key;
*
* @param string $key Name of the dataStore key to get.
* @param boolean $forceNew True to force creation and return of a new
instance.
*
* @return mixed Results of running the $callback for the specified
$key.
*
* @since 1.0
* @throws KeyNotFoundException
*/
public function get($key, $forceNew = false)
{
$key = $this->resolveAlias($key);
$raw = $this->getRaw($key);
if ($raw === null)
{
throw new KeyNotFoundException(sprintf('Key %s has not been
registered with the container.', $key));
}
if ($raw['shared'])
{
if ($forceNew || !isset($this->instances[$key]))
{
$this->instances[$key] = $raw['callback']($this);
}
return $this->instances[$key];
}
return call_user_func($raw['callback'], $this);
}
/**
* Method to check if specified dataStore key exists.
*
* @param string $key Name of the dataStore key to check.
*
* @return boolean True for success
*
* @since 1.5.0
*/
public function has($key)
{
$key = $this->resolveAlias($key);
$exists = (bool) $this->getRaw($key);
if ($exists === false && $this->parent instanceof
ContainerInterface)
{
$exists = $this->parent->has($key);
}
return $exists;
}
/**
* Method to check if specified dataStore key exists.
*
* @param string $key Name of the dataStore key to check.
*
* @return boolean True for success
*
* @since 1.0
* @deprecated 3.0 Use ContainerInterface::has() instead
*/
public function exists($key)
{
return $this->has($key);
}
/**
* Get the raw data assigned to a key.
*
* @param string $key The key for which to get the stored item.
*
* @return mixed
*
* @since 1.0
*/
protected function getRaw($key)
{
if (isset($this->dataStore[$key]))
{
return $this->dataStore[$key];
}
$aliasKey = $this->resolveAlias($key);
if ($aliasKey !== $key && isset($this->dataStore[$aliasKey]))
{
return $this->dataStore[$aliasKey];
}
if ($this->parent instanceof Container)
{
return $this->parent->getRaw($key);
}
if ($this->parent instanceof ContainerInterface &&
$this->parent->has($key))
{
$callback = $this->parent->get($key);
if (!is_callable($callback))
{
$callback = function () use ($callback) {
return $callback;
};
}
return array(
'callback' => $callback,
'shared' => true,
'protected' => true,
);
}
return null;
}
/**
* Method to force the container to return a new instance
* of the results of the callback for requested $key.
*
* @param string $key Name of the dataStore key to get.
*
* @return mixed Results of running the $callback for the specified
$key.
*
* @since 1.0
*/
public function getNewInstance($key)
{
return $this->get($key, true);
}
/**
* Register a service provider to the container.
*
* @param ServiceProviderInterface $provider The service provider to
register.
*
* @return Container This object for chaining.
*
* @since 1.0
*/
public function registerServiceProvider(ServiceProviderInterface
$provider)
{
$provider->register($this);
return $this;
}
/**
* Retrieve the keys for services assigned to this container.
*
* @return array
*
* @since 1.5.0
*/
public function getKeys()
{
return array_unique(array_merge(array_keys($this->aliases),
array_keys($this->dataStore)));
}
}
PK�3�[�BBContainerAwareInterface.phpnu�[���<?php
/**
* Part of the Joomla Framework DI Package
*
* @copyright Copyright (C) 2013 - 2018 Open Source Matters, Inc. All
rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\DI;
/**
* Defines the interface for a Container Aware class.
*
* @since 1.0
*/
interface ContainerAwareInterface
{
/**
* Get the DI container.
*
* @return Container
*
* @since 1.0
* @throws \UnexpectedValueException May be thrown if the container has
not been set.
* @deprecated 2.0 The getter will no longer be part of the interface.
*/
public function getContainer();
/**
* Set the DI container.
*
* @param Container $container The DI container.
*
* @return mixed
*
* @since 1.0
*/
public function setContainer(Container $container);
}
PK�3�[����ContainerAwareTrait.phpnu�[���<?php
/**
* Part of the Joomla Framework DI Package
*
* @copyright Copyright (C) 2013 - 2018 Open Source Matters, Inc. All
rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\DI;
/**
* Defines the trait for a Container Aware Class.
*
* @since 1.2
* @note Traits are available in PHP 5.4+
*/
trait ContainerAwareTrait
{
/**
* DI Container
*
* @var Container
* @since 1.2
*/
private $container;
/**
* Get the DI container.
*
* @return Container
*
* @since 1.2
* @throws \UnexpectedValueException May be thrown if the container has
not been set.
* @note As of 2.0 this method will be protected.
*/
public function getContainer()
{
if ($this->container)
{
return $this->container;
}
throw new \UnexpectedValueException('Container not set in ' .
__CLASS__);
}
/**
* Set the DI container.
*
* @param Container $container The DI container.
*
* @return mixed Returns itself to support chaining.
*
* @since 1.2
*/
public function setContainer(Container $container)
{
$this->container = $container;
return $this;
}
}
PK�3�[y�q��+Exception/DependencyResolutionException.phpnu�[���<?php
/**
* Part of the Joomla Framework DI Package
*
* @copyright Copyright (C) 2013 - 2018 Open Source Matters, Inc. All
rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\DI\Exception;
use Psr\Container\ContainerExceptionInterface;
/**
* Exception class for handling errors in resolving a dependency
*
* @since 1.0
*/
class DependencyResolutionException extends \RuntimeException implements
ContainerExceptionInterface
{
}
PK�3�[��$��"Exception/KeyNotFoundException.phpnu�[���<?php
/**
* Part of the Joomla Framework DI Package
*
* @copyright Copyright (C) 2013 - 2018 Open Source Matters, Inc. All
rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\DI\Exception;
use Psr\Container\NotFoundExceptionInterface;
/**
* No entry was found in the container.
*
* @since 1.5.0
*/
class KeyNotFoundException extends \InvalidArgumentException implements
NotFoundExceptionInterface
{
}
PK�3�[�����#Exception/ProtectedKeyException.phpnu�[���<?php
/**
* Part of the Joomla Framework DI Package
*
* @copyright Copyright (C) 2013 - 2018 Open Source Matters, Inc. All
rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\DI\Exception;
use Psr\Container\ContainerExceptionInterface;
/**
* Attempt to set the value of a protected key, which already is set
*
* @since 1.5.0
*/
class ProtectedKeyException extends \OutOfBoundsException implements
ContainerExceptionInterface
{
}
PK�3�[�td�??ServiceProviderInterface.phpnu�[���<?php
/**
* Part of the Joomla Framework DI Package
*
* @copyright Copyright (C) 2013 - 2018 Open Source Matters, Inc. All
rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\DI;
/**
* Defines the interface for a Service Provider.
*
* @since 1.0
*/
interface ServiceProviderInterface
{
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 1.0
*/
public function register(Container $container);
}
PK�3�[��:���ClientExceptionInterface.phpnu�[���<?php
namespace Psr\Http\Client;
/**
* Every HTTP client related exception MUST implement this interface.
*/
interface ClientExceptionInterface extends \Throwable
{
}
PK�3�[Ҟv��ClientInterface.phpnu�[���<?php
namespace Psr\Http\Client;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
interface ClientInterface
{
/**
* Sends a PSR-7 request and returns a PSR-7 response.
*
* @param RequestInterface $request
*
* @return ResponseInterface
*
* @throws \Psr\Http\Client\ClientExceptionInterface If an error
happens while processing the request.
*/
public function sendRequest(RequestInterface $request):
ResponseInterface;
}
PK�3�["�7��NetworkExceptionInterface.phpnu�[���<?php
namespace Psr\Http\Client;
use Psr\Http\Message\RequestInterface;
/**
* Thrown when the request cannot be completed because of network issues.
*
* There is no response object as this exception is thrown when no response
has been received.
*
* Example: the target host name can not be resolved or the connection
failed.
*/
interface NetworkExceptionInterface extends ClientExceptionInterface
{
/**
* Returns the request.
*
* The request object MAY be a different object from the one passed to
ClientInterface::sendRequest()
*
* @return RequestInterface
*/
public function getRequest(): RequestInterface;
}
PK�3�[�E�uJJRequestExceptionInterface.phpnu�[���<?php
namespace Psr\Http\Client;
use Psr\Http\Message\RequestInterface;
/**
* Exception for when a request failed.
*
* Examples:
* - Request is invalid (e.g. method is missing)
* - Runtime request errors (e.g. the body stream is not seekable)
*/
interface RequestExceptionInterface extends ClientExceptionInterface
{
/**
* Returns the request.
*
* The request object MAY be a different object from the one passed to
ClientInterface::sendRequest()
*
* @return RequestInterface
*/
public function getRequest(): RequestInterface;
}
PKDe�[P���>�>LdapClient.phpnu�[���<?php
/**
* Part of the Joomla Framework LDAP Package
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All
rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\Ldap;
/**
* LDAP client class
*
* @since 1.0
* @deprecated The joomla/ldap package is deprecated
*/
class LdapClient
{
/**
* Hostname of LDAP server
*
* @var string
* @since 1.0
*/
public $host;
/**
* Authorization Method to use
*
* @var boolean
* @since 1.0
*/
public $auth_method;
/**
* Port of LDAP server
*
* @var integer
* @since 1.0
*/
public $port;
/**
* Base DN (e.g. o=MyDir)
*
* @var string
* @since 1.0
*/
public $base_dn;
/**
* User DN (e.g. cn=Users,o=MyDir)
*
* @var string
* @since 1.0
*/
public $users_dn;
/**
* Search String
*
* @var string
* @since 1.0
*/
public $search_string;
/**
* Use LDAP Version 3
*
* @var boolean
* @since 1.0
*/
public $use_ldapV3;
/**
* No referrals (server transfers)
*
* @var boolean
* @since 1.0
*/
public $no_referrals;
/**
* Negotiate TLS (encrypted communications)
*
* @var boolean
* @since 1.0
*/
public $negotiate_tls;
/**
* Ignore TLS Certificate (encrypted communications)
*
* @var boolean
* @since 1.5.0
*/
public $ignore_reqcert_tls;
/**
* Enable LDAP debug
*
* @var boolean
* @since 1.5.0
*/
public $ldap_debug;
/**
* Username to connect to server
*
* @var string
* @since 1.0
*/
public $username;
/**
* Password to connect to server
*
* @var string
* @since 1.0
*/
public $password;
/**
* LDAP Resource Identifier
*
* @var resource
* @since 1.0
*/
private $resource;
/**
* Current DN
*
* @var string
* @since 1.0
*/
private $dn;
/**
* Flag tracking whether the connection has been bound
*
* @var boolean
* @since 1.3.0
*/
private $isBound = false;
/**
* Constructor
*
* @param object $configObj An object of configuration variables
*
* @since 1.0
*/
public function __construct($configObj = null)
{
if (\is_object($configObj))
{
$vars = get_class_vars(\get_class($this));
foreach (array_keys($vars) as $var)
{
if (substr($var, 0, 1) != '_')
{
$param = $configObj->get($var);
if ($param)
{
$this->$var = $param;
}
}
}
}
}
/**
* Class destructor.
*
* @since 1.3.0
*/
public function __destruct()
{
$this->close();
}
/**
* Connect to an LDAP server
*
* @return boolean
*
* @since 1.0
*/
public function connect()
{
if ($this->host == '')
{
return false;
}
if ($this->ignore_reqcert_tls)
{
putenv('LDAPTLS_REQCERT=never');
}
if ($this->ldap_debug)
{
ldap_set_option(null, LDAP_OPT_DEBUG_LEVEL, 7);
}
$this->resource = ldap_connect($this->host, $this->port);
if (!$this->resource)
{
return false;
}
if ($this->use_ldapV3 && !ldap_set_option($this->resource,
LDAP_OPT_PROTOCOL_VERSION, 3))
{
return false;
}
if (!ldap_set_option($this->resource, LDAP_OPT_REFERRALS, (int)
$this->no_referrals))
{
return false;
}
if ($this->negotiate_tls &&
!ldap_start_tls($this->resource))
{
return false;
}
return true;
}
/**
* Close the connection
*
* @return void
*
* @since 1.0
*/
public function close()
{
if ($this->isConnected())
{
$this->unbind();
}
$this->resource = null;
}
/**
* Sets the DN with some template replacements
*
* @param string $username The username
* @param string $nosub ...
*
* @return void
*
* @since 1.0
*/
public function setDn($username, $nosub = 0)
{
if ($this->users_dn == '' || $nosub)
{
$this->dn = $username;
}
elseif (\strlen($username))
{
$this->dn = str_replace('[username]', $username,
$this->users_dn);
}
else
{
$this->dn = '';
}
}
/**
* Get the configured DN
*
* @return string
*
* @since 1.0
*/
public function getDn()
{
return $this->dn;
}
/**
* Anonymously binds to LDAP directory
*
* @return boolean
*
* @since 1.0
*/
public function anonymous_bind()
{
if (!$this->isConnected())
{
if (!$this->connect())
{
return false;
}
}
$this->isBound = ldap_bind($this->resource);
return $this->isBound;
}
/**
* Binds to the LDAP directory
*
* @param string $username The username
* @param string $password The password
* @param string $nosub ...
*
* @return boolean
*
* @since 1.0
*/
public function bind($username = null, $password = null, $nosub = 0)
{
if (!$this->isConnected())
{
if (!$this->connect())
{
return false;
}
}
if ($username === null)
{
$username = $this->username;
}
if ($password === null)
{
$password = $this->password;
}
$this->setDn($username, $nosub);
$this->isBound = ldap_bind($this->resource, $this->getDn(),
$password);
return $this->isBound;
}
/**
* Unbinds from the LDAP directory
*
* @return boolean
*
* @since 1.3.0
*/
public function unbind()
{
if ($this->isBound && $this->resource &&
\is_resource($this->resource))
{
return ldap_unbind($this->resource);
}
return true;
}
/**
* Perform an LDAP search using comma separated search strings
*
* @param string $search search string of search values
*
* @return array Search results
*
* @since 1.0
*/
public function simple_search($search)
{
$results = explode(';', $search);
foreach ($results as $key => $result)
{
$results[$key] = '(' . $result . ')';
}
return $this->search($results);
}
/**
* Performs an LDAP search
*
* @param array $filters Search Filters (array of strings)
* @param string $dnoverride DN Override
* @param array $attributes An array of attributes to return (if
empty, all fields are returned).
*
* @return array Multidimensional array of results
*
* @since 1.0
*/
public function search(array $filters, $dnoverride = null, array
$attributes = array())
{
$result = array();
if (!$this->isBound || !$this->isConnected())
{
return $result;
}
if ($dnoverride)
{
$dn = $dnoverride;
}
else
{
$dn = $this->base_dn;
}
foreach ($filters as $searchFilter)
{
$searchResult = ldap_search($this->resource, $dn, $searchFilter,
$attributes);
if ($searchResult && ($count =
ldap_count_entries($this->resource, $searchResult)) > 0)
{
for ($i = 0; $i < $count; $i++)
{
$result[$i] = array();
if (!$i)
{
$firstentry = ldap_first_entry($this->resource, $searchResult);
}
else
{
$firstentry = ldap_next_entry($this->resource, $firstentry);
}
// Load user-specified attributes
$attributeResult = ldap_get_attributes($this->resource,
$firstentry);
// LDAP returns an array of arrays, fit this into attributes result
array
foreach ($attributeResult as $ki => $ai)
{
if (\is_array($ai))
{
$subcount = $ai['count'];
$result[$i][$ki] = array();
for ($k = 0; $k < $subcount; $k++)
{
$result[$i][$ki][$k] = $ai[$k];
}
}
}
$result[$i]['dn'] = ldap_get_dn($this->resource,
$firstentry);
}
}
}
return $result;
}
/**
* Replace attribute values with new ones
*
* @param string $dn The DN which contains the attribute you
want to replace
* @param string $attribute The attribute values you want to replace
*
* @return boolean
*
* @since 1.0
*/
public function replace($dn, $attribute)
{
if (!$this->isBound || !$this->isConnected())
{
return false;
}
return ldap_mod_replace($this->resource, $dn, $attribute);
}
/**
* Modify an LDAP entry
*
* @param string $dn The DN which contains the attribute you
want to modify
* @param string $attribute The attribute values you want to modify
*
* @return boolean
*
* @since 1.0
*/
public function modify($dn, $attribute)
{
if (!$this->isBound || !$this->isConnected())
{
return false;
}
return ldap_modify($this->resource, $dn, $attribute);
}
/**
* Delete attribute values from current attributes
*
* @param string $dn The DN which contains the attribute you
want to remove
* @param string $attribute The attribute values you want to remove
*
* @return boolean
*
* @since 1.0
*/
public function remove($dn, $attribute)
{
if (!$this->isBound || !$this->isConnected())
{
return false;
}
return ldap_mod_del($this->resource, $dn, $attribute);
}
/**
* Compare value of attribute found in entry specified with DN
*
* @param string $dn The DN which contains the attribute you
want to compare
* @param string $attribute The attribute whose value you want to
compare
* @param string $value The value you want to check against the
LDAP attribute
*
* @return boolean|integer Boolean result of the comparison or -1 on
error
*
* @since 1.0
*/
public function compare($dn, $attribute, $value)
{
if (!$this->isBound || !$this->isConnected())
{
return false;
}
return ldap_compare($this->resource, $dn, $attribute, $value);
}
/**
* Read attributes of a given DN
*
* @param string $dn The DN of the object you want to read
*
* @return array|boolean Array of attributes for the given DN or boolean
false on failure
*
* @since 1.0
*/
public function read($dn)
{
if (!$this->isBound || !$this->isConnected())
{
return false;
}
$base = substr($dn, strpos($dn, ',') + 1);
$cn = substr($dn, 0, strpos($dn, ','));
$result = ldap_read($this->resource, $base, $cn);
if ($result === false)
{
return false;
}
return ldap_get_entries($this->resource, $result);
}
/**
* Delete an entry from a directory
*
* @param string $dn The DN of the object you want to delete
*
* @return boolean
*
* @since 1.0
*/
public function delete($dn)
{
if (!$this->isBound || !$this->isConnected())
{
return false;
}
return ldap_delete($this->resource, $dn);
}
/**
* Add entries to LDAP directory
*
* @param string $dn The DN where you want to put the object
* @param array $entries An array of arrays describing the object to
add
*
* @return boolean
*
* @since 1.0
*/
public function create($dn, array $entries)
{
if (!$this->isBound || !$this->isConnected())
{
return false;
}
return ldap_add($this->resource, $dn, $entries);
}
/**
* Add attribute values to current attributes
*
* @param string $dn The DN of the entry to add the attribute
* @param array $entry An array of arrays with attributes to add
*
* @return boolean
*
* @since 1.0
*/
public function add($dn, array $entry)
{
if (!$this->isBound || !$this->isConnected())
{
return false;
}
return ldap_mod_add($this->resource, $dn, $entry);
}
/**
* Modify the name of an entry
*
* @param string $dn The DN of the entry at the moment
* @param string $newdn The DN of the entry should be (only
cn=newvalue)
* @param string $newparent The full DN of the parent (null by
default)
* @param boolean $deleteolddn Delete the old values (default)
*
* @return boolean
*
* @since 1.0
*/
public function rename($dn, $newdn, $newparent, $deleteolddn)
{
if (!$this->isBound || !$this->isConnected())
{
return false;
}
return ldap_rename($this->resource, $dn, $newdn, $newparent,
$deleteolddn);
}
/**
* Escape a string
*
* @param string $value The subject string
* @param string $ignore Characters to ignore when escaping.
* @param integer $flags The context the escaped string will be used
in LDAP_ESCAPE_FILTER or LDAP_ESCAPE_DN
*
* @return string
*
* @since 1.2.0
*/
public function escape($value, $ignore = '', $flags = 0)
{
return ldap_escape($value, $ignore, $flags);
}
/**
* Return the LDAP error message of the last LDAP command
*
* @return string
*
* @since 1.0
*/
public function getErrorMsg()
{
if (!$this->isBound || !$this->isConnected())
{
return '';
}
return ldap_error($this->resource);
}
/**
* Check if the connection is established
*
* @return boolean
*
* @since 1.3.0
*/
public function isConnected()
{
return $this->resource && \is_resource($this->resource);
}
/**
* Converts a dot notation IP address to net address (e.g. for Netware,
etc)
*
* @param string $ip IP Address (e.g. xxx.xxx.xxx.xxx)
*
* @return string
*
* @since 1.0
*/
public static function ipToNetAddress($ip)
{
$parts = explode('.', $ip);
$address = '1#';
foreach ($parts as $int)
{
$tmp = dechex($int);
if (\strlen($tmp) != 2)
{
$tmp = '0' . $tmp;
}
$address .= '\\' . $tmp;
}
return $address;
}
/**
* Extract readable network address from the LDAP encoded networkAddress
attribute.
*
* Please keep this document block and author attribution in place.
*
* Novell Docs, see:
http://developer.novell.com/ndk/doc/ndslib/schm_enu/data/sdk5624.html#sdk5624
* for Address types:
http://developer.novell.com/ndk/doc/ndslib/index.html?page=/ndk/doc/ndslib/schm_enu/data/sdk4170.html
* LDAP Format, String:
* taggedData = uint32String "#" octetstring
* byte 0 = uint32String = Address Type: 0= IPX Address; 1 = IP Address
* byte 1 = char = "#" - separator
* byte 2+ = octetstring - the ordinal value of the address
* Note: with eDirectory 8.6.2, the IP address (type 1) returns
* correctly, however, an IPX address does not seem to. eDir 8.7 may
correct this.
* Enhancement made by Merijn van de Schoot:
* If addresstype is 8 (UDP) or 9 (TCP) do some additional parsing like
still returning the IP address
*
* @param string $networkaddress The network address
*
* @return array
*
* @author Jay Burrell, Systems & Networks, Mississippi State
University
* @since 1.0
*/
public static function ldapNetAddr($networkaddress)
{
$addr = '';
$addrtype = (int) substr($networkaddress, 0, 1);
// Throw away bytes 0 and 1 which should be the addrtype and the
"#" separator
$networkaddress = substr($networkaddress, 2);
if (($addrtype == 8) || ($addrtype = 9))
{
// TODO 1.6: If UDP or TCP, (TODO fill addrport and) strip portnumber
information from address
$networkaddress = substr($networkaddress, (\strlen($networkaddress) -
4));
}
$addrtypes = array(
'IPX',
'IP',
'SDLC',
'Token Ring',
'OSI',
'AppleTalk',
'NetBEUI',
'Socket',
'UDP',
'TCP',
'UDP6',
'TCP6',
'Reserved (12)',
'URL',
'Count',
);
$len = \strlen($networkaddress);
if ($len > 0)
{
for ($i = 0; $i < $len; $i++)
{
$byte = substr($networkaddress, $i, 1);
$addr .= \ord($byte);
if (($addrtype == 1) || ($addrtype == 8) || ($addrtype = 9))
{
// Dot separate IP addresses...
$addr .= '.';
}
}
if (($addrtype == 1) || ($addrtype == 8) || ($addrtype = 9))
{
// Strip last period from end of $addr
$addr = substr($addr, 0, \strlen($addr) - 1);
}
}
else
{
$addr .= 'Address not available.';
}
return array('protocol' => $addrtypes[$addrtype],
'address' => $addr);
}
/**
* Generates a LDAP compatible password
*
* @param string $password Clear text password to encrypt
* @param string $type Type of password hash, either md5 or SHA
*
* @return string
*
* @since 1.0
*/
public static function generatePassword($password, $type =
'md5')
{
switch (strtolower($type))
{
case 'sha':
return '{SHA}' . base64_encode(pack('H*',
sha1($password)));
case 'md5':
default:
return '{MD5}' . base64_encode(pack('H*',
md5($password)));
}
}
}
PK`;�[q�Z��AbstractApplication.phpnu�[���PK`;�[N�K�YY�AbstractCliApplication.phpnu�[���PK`;�[]t?1a1a�"AbstractDaemonApplication.phpnu�[���PK`;�[R��ll�AbstractWebApplication.phpnu�[���PK`;�[�ttq�Cli/CliInput.phpnu�[���PK`;�[3s�J%�Cli/CliOutput.phpnu�[���PK`;�[~��u ��Cli/ColorProcessor.phpnu�[���PK`;�[MS�**�Cli/ColorStyle.phpnu�[���PK`;�[h#�ff'@Cli/Output/Processor/ColorProcessor.phpnu�[���PK`;�[?<N}}+�Cli/Output/Processor/ProcessorInterface.phpnu�[���PK`;�[������
Cli/Output/Stdout.phpnu�[���PK`;�[��6�QQ�$Cli/Output/Xml.phpnu�[���PK`;�[��u:B:B=(Web/WebClient.phpnu�[���PK�(�[��n��<�<�jExtension/Featuring.phpnu�[���PK��[������٧Service/Category.phpnu�[���PK��[D�`W�!�!��Service/Router.phpnu�[���PK��[]�ƪ��Helper/AssociationHelper.phpnu�[���PK��[�U��P P *�Helper/RouteHelper.phpnu�[���PK��[=�$����Dispatcher/Dispatcher.phpnu�[���PK��[�1������Model/CategoriesModel.phpnu�[���PK��[���@@��Model/ContactModel.phpnu�[���PK��[hTOJRR$5Model/FeaturedModel.phpnu�[���PK��[vJP�{>{>�OModel/CategoryModel.phpnu�[���PK��[�$�B���Model/FormModel.phpnu�[���PK��[ر��E
E
��Controller/DisplayController.phpnu�[���PK��[&}9;9;
�Controller/ContactController.phpnu�[���PK��[-�߉||��View/Category/FeedView.phpnu�[���PK��[U�Iͮ�e�View/Category/HtmlView.phpnu�[���PK��[�`�tt]View/Contact/VcfView.phpnu�[���PK��[2��>�>View/Contact/HtmlView.phpnu�[���PK��[�q�\WWZSView/Featured/HtmlView.phpnu�[���PK��[�5g����eView/Form/HtmlView.phpnu�[���PK��[�7SPP
zView/Categories/HtmlView.phpnu�[���PK��[q�����}Rule/ContactEmailRule.phpnu�[���PK��[G�#��
܆Rule/ContactEmailSubjectRule.phpnu�[���PK��[8z�p��
��Rule/ContactEmailMessageRule.phpnu�[���PK1�[��nn��Field/TermsField.phpnu�[���PK1�[��V�[[7�Extension/Terms.phpnu�[���PK�3�[֬gsp5p5
պContainer.phpnu�[���PK�3�[�BB��ContainerAwareInterface.phpnu�[���PK�3�[�����ContainerAwareTrait.phpnu�[���PK�3�[y�q��+�Exception/DependencyResolutionException.phpnu�[���PK�3�[��$��"7�Exception/KeyNotFoundException.phpnu�[���PK�3�[�����#b�Exception/ProtectedKeyException.phpnu�[���PK�3�[�td�??��ServiceProviderInterface.phpnu�[���PK�3�[��:���5ClientExceptionInterface.phpnu�[���PK�3�[Ҟv��,ClientInterface.phpnu�[���PK�3�["�7��cNetworkExceptionInterface.phpnu�[���PK�3�[�E�uJJBRequestExceptionInterface.phpnu�[���PKDe�[P���>�>�
LdapClient.phpnu�[���PK22f�I