Ejemplo n.º 1
0
 /**
  * Method to enable/disable updates stream
  *
  * @param   object  $element	The JXMLElement 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   object  $input		An optional JRegistry object with the entire data set to validate
  * 								against the entire form.
  * @param   object  $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  JException on invalid rule.
  */
 public function test(&$element, $value, $group = null, &$input = null, &$form = null)
 {
     require_once JPATH_ROOT . '/modules/mod_pwebcontact/helpers/updateserver.php';
     $updateServer = new modPWebContactUpdateServer();
     if ($value == 1 or $value == 2) {
         $updateServer->add();
         // 2nd argument: null = commercial, false = free
     } else {
         $updateServer->delete();
     }
     // change option in other instances of module
     $db = JFactory::getDBO();
     $query = $db->getQuery(true);
     $query->select('id, params')->from('#__modules')->where('module = ' . $db->quote('mod_pwebcontact'))->where('params NOT LIKE ' . $db->quote('%' . $db->escape('"feed":"' . $value . '"') . '%'))->where('id != ' . (int) JFactory::getApplication()->input->getInt('id'));
     $db->setQuery($query);
     try {
         $modules = $db->loadObjectList();
     } catch (Exception $e) {
         $modules = false;
     }
     if ($modules) {
         foreach ($modules as $module) {
             $module->params = preg_replace('/"feed":"\\d+"/i', '"feed":"' . $value . '"', $module->params);
             $query->clear()->update('#__modules')->set('params = ' . $db->quote($db->escape($module->params)))->where('id = ' . (int) $module->id);
             $db->setQuery($query);
             try {
                 $db->execute();
             } catch (Exception $e) {
             }
         }
     }
     return true;
 }
Ejemplo n.º 2
0
 /**
  * Called after any type of action
  *
  * @param   string  $route  Which action is happening (install|uninstall|discover_install|update)
  * @param   JAdapterInstance  $adapter  The object responsible for running this script
  *
  * @return  boolean  True on success
  */
 public function postflight($route, JAdapterInstance $adapter)
 {
     $parent = $adapter->getParent();
     // install update server for new installation or when updating module older than 3.2.4
     require_once $parent->getPath('source') . '/helpers/updateserver.php';
     $version = $parent->getManifest()->version;
     $updateServer = new modPWebContactUpdateServer();
     // delete old md5 files
     $updateServer->deleteMd5($parent->getPath('extension_root') . '/form');
     // add new md5 file
     if ($download_id = $updateServer->getMd5($parent->getPath('source'))) {
         $buffer = '';
         JFile::write($parent->getPath('extension_root') . '/form/' . $download_id, $buffer);
     }
     $updateServer->add($version, $download_id);
 }