Your IP : 216.73.217.11


Current Path : /home/azimutno/www/demo/modules/mod_pwebbox/form/rules/
Upload File :
Current File : /home/azimutno/www/demo/modules/mod_pwebbox/form/rules/pwebdlid.php

<?php
/**
 * @package     pwebbox
 * @version 	2.0.0
 *
 * @copyright   Copyright (C) 2015 Perfect Web. All rights reserved. http://www.perfect-web.co
 * @license     GNU General Public Licence http://www.gnu.org/licenses/gpl-3.0.html
 */

defined('_JEXEC') or die('Restricted access');

jimport('joomla.form.formrule');

/**
 * Form Rule class for the Joomla Framework.
 *
 * @package     Joomla.Platform
 * @subpackage  Form
 * @since       11.1
 */
class JFormRulePwebDlid extends JFormRule
{

    /**
     * Method to test the value.
     *
     * @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 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   JForm             $form     The form object for which the field is being tested.
     *
     * @return  boolean  True if the value is valid, false otherwise.
     *
     * @since   11.1
     * @throws  UnexpectedValueException if rule is invalid.
     */
    public function test(SimpleXMLElement $element, $value, $group = null, $input = null, $form = null)
    {
        if (!JFactory::getUser()->authorise('core.manage', 'com_installer')) {
            return true;
        }

        if( !preg_match('/([a-f0-9]{25,32})/i', $value) AND strlen($value) )
            return false;

        $db = JFactory::getDBO();
        $query = $db->getQuery(true);

        $isJ32 = version_compare(JVERSION, '3.2.2', '>=');

        // Load Download ID from update server location or extra query
        $query->select('us.update_site_id AS id, ' . ($isJ32 ? 'us.extra_query' : 'us.location') . ' AS server')
            ->from('#__extensions AS e')
            ->leftJoin('#__update_sites_extensions AS ue ON ue.extension_id = e.extension_id')
            ->leftJoin('#__update_sites AS us ON us.update_site_id = ue.update_site_id')
            ->where(array(
                'e.type = ' . $db->quote($element['ext_type']),
                'e.element = ' . $db->quote($element['ext_element']),
                'e.folder = ' . $db->quote($element['ext_folder']),
                'e.client_id = ' . $db->quote($element['ext_client'])
            ));

        $db->setQuery($query);
        try {
            $update_site = $db->loadObject();
        } catch (Exception $e) {
            $update_site = null;
        }

        $obj = new stdClass();

        if ($isJ32) {

            //parse url of extra_query ( basically extracting vars )
            $url = parse_url($update_site->server);

            //if empty path, be sure to create path
            $url['path'] = isset($url['path']) ? $url['path'] : '';
            //extract vars from path
            parse_str($url['path'], $url_vars);

            //update jversion
            $url_vars['jversion'] = JVERSION;

            //update dlid
            $url_vars['dlid'] = $value;

            //put a glue on it
            $url['path'] = http_build_query($url_vars);

            //and update extra_query
            $obj->extra_query = $url['path'];
        } else {

            //parse url of extra_query ( basically extracting vars )
            $url = parse_url($update_site->server);

            //if empty query, be sure to create query
            $url['query'] = isset($url['query']) ? $url['query'] : '';
            //extract vars from query
            parse_str($url['query'], $url_vars);

            //update jversion
            $url_vars['jversion'] = JVERSION;

            //update dlid
            $url_vars['dlid'] = $value;

            //put a glue on it
            $url['query'] = http_build_query($url_vars);

            //and create proper location
            $obj->location = $url['scheme'] . '://' . $url['host'] . $url['path'] . '?' . $url['query'];
        }

        $obj->update_site_id = $update_site->id;
        $db->updateObject('#__update_sites', $obj, 'update_site_id');

        $this->setPluginsDlid($value);
    }

    /**
     * Method to set for all everythin_in_everyway plugins their update server info.
     *
     * @param   string $value  		The download id of user.
     */    
    protected function setPluginsDlid($value)
    {
        $db = JFactory::getDBO();
        $query = $db->getQuery(true);
        
        $isJ32 = version_compare(JVERSION, '3.2.2', '>='); 
        
        // Load Download ID from update server location or extra query
        $query->select('us.update_site_id AS id, ' . ($isJ32 ? 'us.extra_query' : 'us.location') . ' AS server')
                ->from('#__extensions AS e')
                ->leftJoin('#__update_sites_extensions AS ue ON ue.extension_id = e.extension_id')
                ->leftJoin('#__update_sites AS us ON us.update_site_id = ue.update_site_id')
                ->where(array(
                    'e.type = ' . $db->quote('plugin'),
                    'e.folder = ' . $db->quote('everything_in_everyway')
        ));        
        
        $db->setQuery($query);

        try
        {
            $update_sites = $db->loadObjectList();
        }
        catch (Exception $e)
        {
            $update_sites = null;
        }  

        foreach ($update_sites as $update_site)
        {


            $obj = new stdClass();

            if ($isJ32) {

                //parse url of extra_query ( basically extracting vars )
                $url = parse_url($update_site->server);

                //if empty path, be sure to create path
                $url['path'] = isset($url['path']) ? $url['path'] : '';
                //extract vars from path
                parse_str($url['path'], $url_vars);

                //update jversion
                $url_vars['jversion'] = JVERSION;

                //update dlid
                $url_vars['dlid'] = $value;

                //put a glue on it
                $url['path'] = http_build_query($url_vars);

                //and update extra_query
                $obj->extra_query = $url['path'];
            } else {

                //parse url of extra_query ( basically extracting vars )
                $url = parse_url($update_site->server);

                //if empty query, be sure to create query
                $url['query'] = isset($url['query']) ? $url['query'] : '';
                //extract vars from query
                parse_str($url['query'], $url_vars);

                //update jversion
                $url_vars['jversion'] = JVERSION;

                //update dlid
                $url_vars['dlid'] = $value;

                //put a glue on it
                $url['query'] = http_build_query($url_vars);

                //and create proper location
                $obj->location = $url['scheme'] . '://' . $url['host'] . $url['path'] . '?' . $url['query'];
            }

            $obj->update_site_id = $update_site->id;
            $db->updateObject('#__update_sites', $obj, 'update_site_id');
        }
    }
}