PK       ! n  n    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);
    }
}
PK       ! )0k_      PackageField.phpnu [        <?php

/**
 * @package     Joomla.Administrator
 * @subpackage  com_installer
 *
 * @copyright   (C) 2022 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\Component\Installer\Administrator\Field;

use Joomla\CMS\Form\Field\ListField;
use Joomla\Component\Installer\Administrator\Helper\InstallerHelper;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
 * Package field.
 *
 * Selects the extension ID of an extension of the "package" type.
 *
 * @since 4.2.0
 */
class PackageField extends ListField
{
    /**
     * Method to get the field options.
     *
     * @return  array  The field option objects.
     * @since   4.2.0
     */
    protected function getOptions()
    {
        $options = InstallerHelper::getPackageOptions();

        return array_merge(parent::getOptions(), $options);
    }
}
PK       ! iu      ExtensionstatusField.phpnu [        <?php

/**
 * @package     Joomla.Administrator
 * @subpackage  com_installer
 *
 * @copyright   (C) 2015 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\Component\Installer\Administrator\Field;

use Joomla\CMS\Form\Field\ListField;
use Joomla\Component\Installer\Administrator\Helper\InstallerHelper;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
 * Extension Status field.
 *
 * @since  3.5
 */
class ExtensionstatusField extends ListField
{
    /**
     * The form field type.
     *
     * @var    string
     * @since  3.5
     */
    protected $type = 'ExtensionStatus';

    /**
     * Method to get the field options.
     *
     * @return  array  The field option objects.
     *
     * @since   3.5
     */
    public function getOptions()
    {
        $options = InstallerHelper::getStateOptions();

        return array_merge(parent::getOptions(), $options);
    }
}
PK       ! 2      FolderField.phpnu [        <?php

/**
 * @package     Joomla.Administrator
 * @subpackage  com_installer
 *
 * @copyright   (C) 2015 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\Component\Installer\Administrator\Field;

use Joomla\CMS\Form\Field\ListField;
use Joomla\Component\Installer\Administrator\Helper\InstallerHelper;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
 * Folder field.
 *
 * @since  3.5
 */
class FolderField extends ListField
{
    /**
     * The form field type.
     *
     * @var    string
     * @since  3.5
     */
    protected $type = 'Folder';

    /**
     * Method to get the field options.
     *
     * @return  array  The field option objects.
     *
     * @since   3.5
     */
    public function getOptions()
    {
        $options = InstallerHelper::getExtensionGroups();

        return array_merge(parent::getOptions(), $options);
    }
}
PK       ! wm      LocationField.phpnu [        <?php

/**
 * @package     Joomla.Administrator
 * @subpackage  com_installer
 *
 * @copyright   (C) 2015 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\Component\Installer\Administrator\Field;

use Joomla\CMS\Form\Field\ListField;
use Joomla\Component\Installer\Administrator\Helper\InstallerHelper;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
 * Location field.
 *
 * @since  3.5
 */
class LocationField extends ListField
{
    /**
     * The form field type.
     *
     * @var    string
     * @since  3.5
     */
    protected $type = 'Location';

    /**
     * Method to get the field options.
     *
     * @return  array  The field option objects.
     *
     * @since   3.5
     */
    public function getOptions()
    {
        $options = InstallerHelper::getClientOptions();

        return array_merge(parent::getOptions(), $options);
    }
}
PK       ! Z      TypeField.phpnu [        <?php

/**
 * @package     Joomla.Administrator
 * @subpackage  com_installer
 *
 * @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\Installer\Administrator\Field;

use Joomla\CMS\Form\Field\ListField;
use Joomla\Component\Installer\Administrator\Helper\InstallerHelper;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
 * Form field for a list of extension types.
 *
 * @since  3.5
 */
class TypeField extends ListField
{
    /**
     * The form field type.
     *
     * @var    string
     * @since  3.5
     */
    protected $type = 'Type';

    /**
     * Method to get the field options.
     *
     * @return  array  The field option objects.
     *
     * @since   3.5
     */
    public function getOptions()
    {
        $options = InstallerHelper::getExtensionTypes();

        return array_merge(parent::getOptions(), $options);
    }
}
PK       ! K
V  V    JoomlatokenField.phpnu [        <?php

/**
 * @package     Joomla.Plugin
 * @subpackage  User.token
 *
 * @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\User\Token\Field;

use Joomla\CMS\Factory;
use Joomla\CMS\Form\Field\TextField;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
 * Joomlatoken field class
 *
 * @since  4.0.0
 */
class JoomlatokenField extends TextField
{
    /**
     * Name of the layout being used to render the field
     *
     * @var    string
     * @since  4.0.0
     */
    protected $layout = 'plugins.user.token.token';

    /**
     * Method to attach a Form object to the field.
     *
     * @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]".
     *
     * @return  boolean  True on success.
     *
     * @see     FormField::setup()
     * @since   4.0.0
     */
    public function setup(\SimpleXMLElement $element, $value, $group = null)
    {
        $ret = parent::setup($element, $value, $group);

        /**
         * Security and privacy precaution: do not display the token field when the user being
         * edited is not the same as the logged in user. Tokens are conceptually a combination of
         * a username and password, therefore they should be treated in the same mode of
         * confidentiality and privacy as passwords i.e. you can reset them for other users but NOT
         * be able to see them, thus preventing impersonation attacks by a malicious administrator.
         */
        $userId = $this->form->getData()->get('id');

        if ($userId != $this->getCurrentUser()->id) {
            $this->hidden = true;
        }

        return $ret;
    }

    /**
     * Method to get the field input markup.
     *
     * @return  string  The field input markup.
     *
     * @since   4.0.0
     */
    protected function getInput()
    {
        // Do not display the token field when the user being edited is not the same as the logged in user
        if ($this->hidden) {
            return '';
        }

        return parent::getInput();
    }

    /**
     * Returns the token formatted suitably for the user to copy.
     *
     * @param   string  $tokenSeed  The token seed data stored in the database
     *
     * @return  string
     * @since   4.0.0
     */
    private function getTokenForDisplay(string $tokenSeed): string
    {
        if (empty($tokenSeed)) {
            return '';
        }

        $algorithm = $this->getAttribute('algo', 'sha256');

        try {
            $siteSecret = Factory::getApplication()->get('secret');
        } catch (\Exception) {
            $siteSecret = '';
        }

        // NO site secret? You monster!
        if (empty($siteSecret)) {
            return '';
        }

        $rawToken  = base64_decode($tokenSeed);
        $tokenHash = hash_hmac($algorithm, $rawToken, $siteSecret);
        $userId    = $this->form->getData()->get('id');
        $message   = base64_encode("$algorithm:$userId:$tokenHash");

        if ($userId != $this->getCurrentUser()->id) {
            $message = '';
        }

        return $message;
    }

    /**
     * Get the data for the layout
     *
     * @return  array
     *
     * @since   4.0.0
     */
    protected function getLayoutData()
    {
        $data          = parent::getLayoutData();
        $data['value'] = $this->getTokenForDisplay($this->value);

        return $data;
    }
}
PK         ! n  n                  TermsField.phpnu [        PK         ! )0k_                  PackageField.phpnu [        PK         ! iu                  ExtensionstatusField.phpnu [        PK         ! 2                  FolderField.phpnu [        PK         ! wm                X  LocationField.phpnu [        PK         ! Z                   TypeField.phpnu [        PK         ! K
V  V              $  JoomlatokenField.phpnu [        PK      7  5    