public function onPrepareModuleList(&$modules)
 {
     // return if is not frontend
     if (!JFactory::getApplication()->isSite()) {
         return;
     }
     jimport('joomla.filesystem.file');
     require_once JPATH_PLUGINS . '/system/nnframework/helpers/parameters.php';
     $parameters = NNParameters::getInstance();
     require_once JPATH_PLUGINS . '/system/nnframework/helpers/assignments.php';
     $assignments_helper = new NNFrameworkAssignmentsHelper();
     require_once JPATH_ADMINISTRATOR . '/components/com_advancedmodules/models/module.php';
     $model = new AdvancedModulesModelModule();
     $xmlfile_assignments = JPATH_ADMINISTRATOR . '/components/com_advancedmodules/assignments.xml';
     $modules = is_null($modules) ? $this->getModuleList() : $modules;
     if (is_array($modules) && empty($modules)) {
         return;
     }
     $filtered_modules = array();
     foreach ($modules as $module) {
         $module->name = substr($module->module, 4);
         if (!isset($module->mirror_id)) {
             $module->mirror_id = $this->getMirrorModuleIdById($module->id);
         }
         if (!isset($module->advancedparams)) {
             $module->advancedparams = $this->getAdvancedParamsById($module->id);
         }
         $module->advancedparams = json_decode($module->advancedparams);
         if (is_null($module->advancedparams)) {
             $module->advancedparams = new stdClass();
         }
         if (!isset($module->advancedparams->assignto_menuitems) || isset($module->advancedparams->assignto_urls_selection_sef) || !is_array($module->advancedparams->assignto_menuitems) && strpos($module->advancedparams->assignto_menuitems, '|') !== false) {
             $module->advancedparams = (object) $model->initAssignments($module->id, $module);
         }
         $module->advancedparams = $parameters->getParams($module->advancedparams, $xmlfile_assignments);
         if ($module->advancedparams === 0) {
             if (isset($module->published) && !$module->published) {
                 continue;
             }
             $filtered_modules[] = $module;
             continue;
         }
         $module->reverse = 0;
         $this->setMirrorParams($module, $xmlfile_assignments);
         $this->removeDisabledAssignments($module->advancedparams);
         $assignments = $assignments_helper->getAssignmentsFromParams($module->advancedparams);
         $module->published = $assignments_helper->passAll($assignments, $module->advancedparams->match_method);
         if ($module->reverse) {
             $module->published = !$module->published;
         }
         if (isset($module->published) && !$module->published) {
             continue;
         }
         $filtered_modules[] = $module;
     }
     $modules = array_values($filtered_modules);
     unset($filtered_modules);
 }
 public function onPrepareModuleList(&$modules)
 {
     // return if is not frontend
     if (!JFactory::getApplication()->isSite() || empty($modules)) {
         return;
     }
     jimport('joomla.filesystem.file');
     require_once JPATH_PLUGINS . '/system/nnframework/helpers/parameters.php';
     $parameters = NNParameters::getInstance();
     require_once JPATH_PLUGINS . '/system/nnframework/helpers/assignments.php';
     $assignments = new NNFrameworkAssignmentsHelper();
     $xmlfile_assignments = JPATH_ADMINISTRATOR . '/components/com_advancedmodules/assignments.xml';
     // set params for all loaded modules first
     // and make it an associated array (array id = module id)
     $new_modules = array();
     require_once JPATH_ADMINISTRATOR . '/components/com_advancedmodules/models/module.php';
     $model = new AdvancedModulesModelModule();
     foreach ($modules as $id => $module) {
         if (!isset($module->mirror_id)) {
             $module->mirror_id = $this->getMirrorModuleIdById($id);
         }
         if (!isset($module->advancedparams)) {
             $module->advancedparams = $this->getAdvancedParamsById($id);
         }
         $module->advancedparams = json_decode($module->advancedparams);
         if (is_null($module->advancedparams)) {
             $module->advancedparams = new stdClass();
         }
         if (!isset($module->advancedparams->assignto_menuitems) || isset($module->advancedparams->assignto_urls_selection_sef) || !is_array($module->advancedparams->assignto_menuitems) && strpos($module->advancedparams->assignto_menuitems, '|') !== false) {
             $module->advancedparams = (object) $model->initAssignments($module->id, $module);
         }
         $module->advancedparams = $parameters->getParams($module->advancedparams, $xmlfile_assignments);
         $new_modules[$module->id] = $module;
     }
     $modules = $new_modules;
     unset($new_modules);
     foreach ($modules as $id => $module) {
         if ($module->advancedparams === 0) {
             continue;
         }
         $module->reverse = 0;
         if (!isset($module->published)) {
             $module->published = 0;
         }
         if ($module->published) {
             $this->setMirrorParams($module, $xmlfile_assignments);
             $this->removeDisabledAssignments($module->advancedparams);
             $ass = $assignments->getAssignmentsFromParams($module->advancedparams);
             $pass = $assignments->passAll($ass, $module->advancedparams->match_method);
             if (!$pass) {
                 $module->published = 0;
             }
             if ($module->reverse) {
                 $module->published = $module->published ? 0 : 1;
             }
         }
         $modules[$id] = $module;
     }
 }
function plgSystemAdvancedModulesPrepareModuleList(&$modules)
{
    $client = JFactory::getApplication()->getClientId();
    if ($client == 0) {
        jimport('joomla.filesystem.file');
        require_once JPATH_PLUGINS . '/system/nnframework/helpers/parameters.php';
        $parameters = NNParameters::getInstance();
        require_once JPATH_PLUGINS . '/system/nnframework/helpers/assignments.php';
        $assignments = new NNFrameworkAssignmentsHelper();
        $xmlfile_assignments = JPATH_ADMINISTRATOR . '/components/com_advancedmodules/assignments.xml';
        $config = plgSystemAdvancedModulesConfig();
        // set params for all loaded modules first
        // and make it an associated array (array id = module id)
        $new_modules = array();
        require_once JPATH_ADMINISTRATOR . '/components/com_advancedmodules/models/module.php';
        $model = new AdvancedModulesModelModule();
        foreach ($modules as $id => $module) {
            if (!isset($module->adv_params)) {
                $module->adv_params = plgSystemAdvancedModulesGetAdvancedParams($id);
            }
            $registry = new JRegistry();
            if (strpos($module->adv_params, '"assignto_menuitems"') === false) {
                $module->adv_params = $model->initAssignments($module->id, $module, $module->adv_params);
                $registry->loadArray($module->adv_params);
            } else {
                $registry->loadString($module->adv_params);
            }
            $module->adv_params = $registry->toObject();
            $module->adv_params = $parameters->getParams($module->adv_params, $xmlfile_assignments);
            $new_modules[$module->id] = $module;
        }
        $modules = $new_modules;
        unset($new_modules);
        foreach ($modules as $id => $module) {
            if ($module->adv_params === 0) {
                continue;
            }
            $module->reverse = 0;
            if (!isset($module->published)) {
                $module->published = 0;
            }
            // Check if module should mirror another modules assignment settings
            if ($module->published) {
                $count = 0;
                while ($count++ < 10 && isset($module->adv_params->mirror_module) && $module->adv_params->mirror_module && isset($module->adv_params->mirror_moduleid) && $module->adv_params->mirror_moduleid) {
                    $mirror_moduleid = (int) $module->adv_params->mirror_moduleid;
                    $module->reverse = $module->adv_params->mirror_module == 2;
                    if ($mirror_moduleid) {
                        if ($mirror_moduleid == $id) {
                            $empty = new stdClass();
                            $module->adv_params = $parameters->getParams($empty, $xmlfile_assignments);
                        } else {
                            if (isset($modules[$mirror_moduleid])) {
                                if (!isset($modules[$mirror_moduleid]->adv_param)) {
                                    $modules[$mirror_moduleid]->adv_param = plgSystemAdvancedModulesGetAdvancedParams($mirror_moduleid);
                                    $modules[$mirror_moduleid]->adv_param = $parameters->getParams($module->adv_params, $xmlfile_assignments);
                                }
                                $module->adv_params = $modules[$mirror_moduleid]->adv_params;
                            } else {
                                $module->adv_params = plgSystemAdvancedModulesGetAdvancedParams($mirror_moduleid);
                                $module->adv_params = $parameters->getParams($module->adv_params, $xmlfile_assignments);
                            }
                        }
                    }
                }
            }
            if ($module->published) {
                if (!$config->show_assignto_homepage) {
                    $module->adv_params->assignto_homepage = 0;
                }
                if (!$config->show_assignto_usergrouplevels) {
                    $module->adv_params->assignto_usergrouplevels = 0;
                }
                if (!$config->show_assignto_date) {
                    $module->adv_params->assignto_date = 0;
                }
                if (!$config->show_assignto_languages) {
                    $module->adv_params->assignto_languages = 0;
                }
                if (!$config->show_assignto_templates) {
                    $module->adv_params->assignto_templates = 0;
                }
                if (!$config->show_assignto_urls) {
                    $module->adv_params->assignto_urls = 0;
                }
                if (!$config->show_assignto_os) {
                    $module->adv_params->assignto_os = 0;
                }
                if (!$config->show_assignto_browsers) {
                    $module->adv_params->assignto_browsers = 0;
                }
                if (!$config->show_assignto_components) {
                    $module->adv_params->assignto_components = 0;
                }
                if (!$config->show_assignto_content) {
                    $module->adv_params->assignto_contentpagetypes = 0;
                    $module->adv_params->assignto_cats = 0;
                    $module->adv_params->assignto_articles = 0;
                }
                $ass = $assignments->getAssignmentsFromParams($module->adv_params);
                $pass = $assignments->passAll($ass, $module->adv_params->match_method);
                if (!$pass) {
                    $module->published = 0;
                }
                if ($module->reverse) {
                    $module->published = $module->published ? 0 : 1;
                }
            }
            $modules[$id] = $module;
        }
    }
}
 public function onPrepareModuleList(&$modules)
 {
     // return if is not frontend
     if (!JFactory::getApplication()->isSite() || empty($modules)) {
         return;
     }
     jimport('joomla.filesystem.file');
     require_once JPATH_PLUGINS . '/system/nnframework/helpers/parameters.php';
     $parameters = NNParameters::getInstance();
     require_once JPATH_PLUGINS . '/system/nnframework/helpers/assignments.php';
     $assignments = new NNFrameworkAssignmentsHelper();
     $xmlfile_assignments = JPATH_ADMINISTRATOR . '/components/com_advancedmodules/assignments.xml';
     $config = $this->getConfig();
     // set params for all loaded modules first
     // and make it an associated array (array id = module id)
     $new_modules = array();
     require_once JPATH_ADMINISTRATOR . '/components/com_advancedmodules/models/module.php';
     $model = new AdvancedModulesModelModule();
     foreach ($modules as $id => $module) {
         if (!isset($module->advancedparams)) {
             $module->advancedparams = $this->getAdvancedParams($id);
         }
         $module->advancedparams = json_decode($module->advancedparams);
         if (is_null($module->advancedparams)) {
             $module->advancedparams = new stdClass();
         }
         if (!isset($module->advancedparams->assignto_menuitems) || isset($module->advancedparams->assignto_urls_selection_sef) || !is_array($module->advancedparams->assignto_menuitems) && strpos($module->advancedparams->assignto_menuitems, '|') !== false) {
             $module->advancedparams = (object) $model->initAssignments($module->id, $module);
         }
         $module->advancedparams = $parameters->getParams($module->advancedparams, $xmlfile_assignments);
         $new_modules[$module->id] = $module;
     }
     $modules = $new_modules;
     unset($new_modules);
     foreach ($modules as $id => $module) {
         if ($module->advancedparams === 0) {
             continue;
         }
         $module->reverse = 0;
         if (!isset($module->published)) {
             $module->published = 0;
         }
         // Check if module should mirror another modules assignment settings
         if ($module->published) {
             $count = 0;
             while ($count++ < 10 && !empty($module->advancedparams->mirror_module) && !empty($module->advancedparams->mirror_moduleid)) {
                 if (is_array($module->advancedparams->mirror_moduleid)) {
                     $module->advancedparams->mirror_moduleid = (int) $module->advancedparams->mirror_moduleid['0'];
                 }
                 $mirror_moduleid = (int) $module->advancedparams->mirror_moduleid;
                 $module->reverse = $module->advancedparams->mirror_module == 2;
                 if (!$mirror_moduleid) {
                     continue;
                 }
                 if ($mirror_moduleid == $id) {
                     $empty = new stdClass();
                     $mirror_params = $parameters->getParams($empty, $xmlfile_assignments);
                 } else {
                     if (isset($modules[$mirror_moduleid])) {
                         if (!isset($modules[$mirror_moduleid]->adv_param)) {
                             $modules[$mirror_moduleid]->adv_param = $this->getAdvancedParams($mirror_moduleid);
                             $modules[$mirror_moduleid]->adv_param = $parameters->getParams($modules[$mirror_moduleid]->adv_param, $xmlfile_assignments);
                         }
                         $mirror_params = $modules[$mirror_moduleid]->advancedparams;
                     } else {
                         $mirror_params = $this->getAdvancedParams($mirror_moduleid);
                         $mirror_params = $parameters->getParams($mirror_params, $xmlfile_assignments);
                     }
                 }
                 // Keep the advanced settings that shouldn't be mirrored
                 $settings_to_keep = array('hideempty', 'color');
                 foreach ($settings_to_keep as $key) {
                     if (!isset($module->advancedparams->{$key})) {
                         continue;
                     }
                     $mirror_params->{$key} = $module->advancedparams->{$key};
                 }
                 $module->advancedparams = $mirror_params;
             }
         }
         if ($module->published) {
             if (!$config->show_assignto_homepage) {
                 $module->advancedparams->assignto_homepage = 0;
             }
             if (!$config->show_assignto_usergrouplevels) {
                 $module->advancedparams->assignto_usergrouplevels = 0;
             }
             if (!$config->show_assignto_date) {
                 $module->advancedparams->assignto_date = 0;
             }
             if (!$config->show_assignto_languages) {
                 $module->advancedparams->assignto_languages = 0;
             }
             if (!$config->show_assignto_templates) {
                 $module->advancedparams->assignto_templates = 0;
             }
             if (!$config->show_assignto_urls) {
                 $module->advancedparams->assignto_urls = 0;
             }
             if (!$config->show_assignto_os) {
                 $module->advancedparams->assignto_os = 0;
             }
             if (!$config->show_assignto_browsers) {
                 $module->advancedparams->assignto_browsers = 0;
             }
             if (!$config->show_assignto_components) {
                 $module->advancedparams->assignto_components = 0;
             }
             if (!$config->show_assignto_tags) {
                 $module->advancedparams->show_assignto_tags = 0;
             }
             if (!$config->show_assignto_content) {
                 $module->advancedparams->assignto_contentpagetypes = 0;
                 $module->advancedparams->assignto_cats = 0;
                 $module->advancedparams->assignto_articles = 0;
             }
             $ass = $assignments->getAssignmentsFromParams($module->advancedparams);
             $pass = $assignments->passAll($ass, $module->advancedparams->match_method);
             if (!$pass) {
                 $module->published = 0;
             }
             if ($module->reverse) {
                 $module->published = $module->published ? 0 : 1;
             }
         }
         $modules[$id] = $module;
     }
 }