Exemple #1
0
 function onAfterRoute()
 {
     $redirectlink = trim(JRequest::getString('redirectlink'));
     $fromSubscribe = JRequest::getVar('fromSubscribe', '');
     // this is either we have a redirect setup or we come from the module
     if (empty($fromSubscribe) || empty($redirectlink)) {
         return '';
     }
     if (strtolower(substr(JPATH_ROOT, strlen(JPATH_ROOT) - 13)) == 'administrator') {
         $adminPath = strtolower(substr(JPATH_ROOT, strlen(JPATH_ROOT) - 13));
     } else {
         $adminPath = JPATH_ROOT;
     }
     if (!@(include_once $adminPath . DS . 'components' . DS . 'com_jnews' . DS . 'defines.php')) {
         return;
     }
     include_once JNEWSPATH_CLASS . 'class.jnews.php';
     require_once JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'administrator' . DS . 'components' . DS . JNEWS_OPTION . DS . 'classes' . DS . 'class.subscribers.php';
     require_once JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'administrator' . DS . 'components' . DS . JNEWS_OPTION . DS . 'classes' . DS . 'class.listssubscribers.php';
     jimport('joomla.html.parameter');
     $db = JFactory::getDBO();
     $plugin = JPluginHelper::getPlugin('system', 'vmjnewssubs');
     $registry = new JRegistry();
     if (!method_exists($registry, 'loadString')) {
         $data = trim($plugin->params);
         $options = array('processSections' => false);
         if (substr($data, 0, 1) != '{' && substr($data, -1, 1) != '}') {
             $ini = JRegistryFormat::getInstance('INI');
             $obj = $ini->stringToObject($data, $options);
         } else {
             $obj = json_decode($data);
         }
         $registry->loadObject($obj);
     } else {
         $registry->loadString($plugin->params);
     }
     $params = $registry;
     $reqfield = $params->get('reqfield', 'user_email');
     $email = JRequest::getString('email');
     $reqvalue = $reqfield == 'user_email' ? $email : JRequest::get($reqfield);
     if (is_array($reqvalue)) {
         //if we find any no we do no
         if (empty($reqvalue)) {
             return '';
         }
         foreach ($reqvalue as $resultArVal) {
             if (empty($resultArVal)) {
                 return '';
             }
         }
     } else {
         if (empty($reqvalue) || empty($email) || in_array(strtolower($reqvalue), array('', '0', 'n', 'no', 'none', 'nein', 'non'))) {
             return;
         }
     }
     $user_id = JRequest::getInt('user_id');
     $email = trim(strip_tags($email));
     $fname = JRequest::getString('first_name', '');
     $mname = JRequest::getString('middle_name', '');
     $lname = JRequest::getString('last_name', '');
     $name = '';
     if (!empty($fname)) {
         $name .= $fname . ' ';
     }
     if (!empty($mname)) {
         $name .= $mname . ' ';
     }
     if (!empty($lname)) {
         $name .= $lname;
     }
     $name = trim($name);
     if (empty($name)) {
         $name = JRequest::getVar('username');
     }
     $subscriber = new stdClass();
     $subscriber->user_id = $user_id;
     $subscriber->name = $name;
     $subscriber->email = $email;
     $subscriber->ip = jNews_Subscribers::getIP();
     $subscriber->receive_html = 1;
     $subscriber->confirmed = $GLOBALS[JNEWS . 'require_confirmation'] == '1' ? 0 : 1;
     $subscriber->subscribe_date = time();
     $subscriber->language_iso = 'eng';
     $subscriber->timezone = '00:00:00';
     $subscriber->blacklist = 0;
     $subscriber->params = '';
     $subscriber->admin_id = 62;
     $status = jNews_Subscribers::saveSubscriber($subscriber, $user_id, true);
     if (!$status) {
         return;
     }
     $listsToSubscribe = $params->get('lists', '');
     $listsToSubscribe = str_replace(' ', '', $listsToSubscribe);
     if (!empty($listsToSubscribe)) {
         $condition = ' WHERE `id` IN (' . $listsToSubscribe . ')';
     } else {
         $condition = '';
     }
     $query = 'SELECT `id`, `list_type`,`params` from `#__jnews_lists`' . $condition;
     $db->setQuery($query);
     $lsidstoinsert = $db->loadObjectList();
     $error = $db->getErrorMsg();
     if (!empty($error)) {
         echo $error;
         return false;
     } else {
         //use for masterlists
         $listsA = array();
         foreach ($lsidstoinsert as $lsid) {
             $d['email'] = $subscriber->email;
             //get the subscriber id which is newly inserted
             jNews_Subscribers::getSubscriberIdFromEmail($d);
             //subscriber_id from the inserted subscriber
             if ($d['subscriberId'] > 0) {
                 $subscriber->id = $d['subscriberId'];
             } else {
                 $subscriber->id = $subscriber->user_id;
             }
             if (!empty($lsid->params)) {
                 //use for masterlists
                 $listsA[] = $lsid->id;
             } else {
                 //for non-masterlists
                 $subscriber->list_id = $lsid->id;
                 jNews_ListsSubs::saveToListSubscribers($subscriber);
             }
             if ($lsid->list_type == 2) {
                 $subscribe = array();
                 $subscribe[] = $lsid->id;
                 if (!empty($subscribe)) {
                     jNews_ListsSubs::subscribeARtoQueue($subscriber->id, $subscribe);
                 }
             }
         }
         //end of foreach
         if (!empty($listsA)) {
             //we check if the social class file exists for the implementation of master lists
             if (@(include_once JNEWSPATH_ADMIN . 'social' . DS . 'class.social.php')) {
                 if (class_exists('jNews_Social')) {
                     $listidSubsA = array();
                     $masterListSubscriber = new stdClass();
                     //we check if configuration for master lists is enabled
                     if ($GLOBALS[JNEWS . 'use_masterlists']) {
                         if ($GLOBALS[JNEWS . 'level'] > 1) {
                             //we validate if the user can be subscribed to the list then we return the masterlistid
                             //1 - MasterLists for all Potential Users
                             $listidSubsA[] = jNews_Social::includeMasterListIds($subscriber->id, 1, $listsA);
                             //2 - MasterLists for all Registered Subscribers
                             $listidSubsA[] = jNews_Social::includeMasterListIds($subscriber->id, 2, $listsA);
                         }
                         if ($GLOBALS[JNEWS . 'level'] > 2) {
                             //we validate if the user can be subscribed to the list then we return the masterlistid
                             //3 - MasterLists for all Front-end Subscribers
                             $listidSubsA[] = jNews_Social::includeMasterListIds($subscriber->id, 3, $listsA);
                         }
                     }
                     //we check first if $listidSubsA and if not empty we do the subscription to the lists
                     if (!empty($listidSubsA)) {
                         $masterListSubscriber->id = $subscriber->id;
                         $masterListSubscriber->list_id = $listidSubsA;
                         jNews_ListsSubs::saveToListSubscribers($masterListSubscriber);
                     }
                 }
             }
         }
     }
 }
Exemple #2
0
 public static function showLists($subscriberId, $listId, $lisType, $action, $task)
 {
     $Itemid = JRequest::getInt('Itemid');
     if (empty($Itemid)) {
         $Itemid = $GLOBALS[JNEWS . 'itemidAca'];
     }
     // we initialize the listType with one
     if (empty($lisType)) {
         $lisType = 1;
     }
     $mainframe = JFactory::getApplication();
     $my = JFactory::getUser();
     $gid = !empty($GLOBALS[JNEWS . 'list_creatorfe']) ? $GLOBALS[JNEWS . 'list_creatorfe'] : 0;
     if (version_compare(JVERSION, '1.6.0', '<')) {
         $listsAddEdit = jNews_Lists::getIDswithacclevel($my->gid);
     } else {
         $groups = JAccess::getGroupsByUser($my->id);
         $listsAddEdit = jNews_Lists::getIDswithacclevel($groups);
     }
     if (!empty($my->id)) {
         $ownedlists = jNews_Lists::getOwnedlists($my->id);
         //UPDATE321
         $lists = jNews_Lists::getLists(0, 0, true);
         $access = false;
         foreach ($lists as $list) {
             $bit = jnews::checkPermissions($list->acc_level);
             if ($bit) {
                 $access = true;
                 break;
             }
         }
         if (!$access && empty($listsAddEdit) && empty($ownedlists) && !jnews::checkPermissions('admin') && !jnews::checkPermissions($gid)) {
             frontHTML::showPanel();
             return true;
         }
     }
     //for popup window
     JHTML::_('behavior.modal');
     switch ($task) {
         case 'new':
         case 'add':
             $access = 'admin';
             $id = 0;
             if ($GLOBALS[JNEWS . 'enable_jsub']) {
                 if (!empty($my->id)) {
                     $ownedlists = jNews_Lists::getOwnedlists($my->id);
                 }
                 if (!empty($ownedlists)) {
                     $access = strtolower($my->usertype);
                 }
                 $id = $my->id;
             }
             if (jnews::checkPermissions($access) || jnews::checkPermissions($gid)) {
                 //traces
                 $task = 'save';
                 $subscriber = jNews_Subscribers::getSubscriberInfoFromUserId($my->id);
                 if (version_compare(JVERSION, '1.6.0', '<')) {
                     //j15
                     $acl = JFactory::getACL();
                     $groups = $acl->get_group_children_tree(null, 'USERS', false);
                 } else {
                     //j16
                     $db = JFactory::getDBO();
                     $db->setQuery('SELECT a.*, a.title as text, a.id as value  FROM #__usergroups AS a ORDER BY a.lft ASC');
                     $groups = $db->loadObjectList();
                 }
                 $allGroupIds = array();
                 foreach ($groups as $oneGroup) {
                     $allGroupIds[] = $oneGroup->value;
                 }
                 $newList = new stdClass();
                 $newList->id = '';
                 $newList->html = 1;
                 $newList->new_letter = 1;
                 $newList->list_name = '';
                 $newList->list_desc = '';
                 if (empty($subscriber)) {
                     $newList->sendername = '';
                     $newList->senderemail = '';
                     $newList->bounceadres = '';
                     //$GLOBALS[JNEWS.'sendmail_from'];
                 } else {
                     $newList->sendername = $subscriber->name;
                     $newList->senderemail = $subscriber->email;
                     $newList->bounceadres = $subscriber->email;
                 }
                 $newList->hidden = 1;
                 $newList->auto_add = 0;
                 $newList->list_type = $lisType;
                 $newList->delay_min = 1;
                 $newList->delay_max = 7;
                 $newList->user_choose = 0;
                 $newList->cat_id = '0:0';
                 $newList->follow_up = '';
                 $newList->notify_id = 0;
                 $newList->owner = $my->id;
                 $newList->acc_level = '24,25,7,8';
                 $newList->acc_id = implode(',', $allGroupIds);
                 $newList->published = 1;
                 $newList->start_date = date('Y-m-d', jnews::getNow(0, true));
                 $newList->next_date = jnews::getNow(0, true);
                 $newList->subscribemessage = _JNEWS_DEFAULT_SUBSCRIBE_MESS;
                 $newList->unsubscribemessage = _JNEWS_DEFAULT_UNSUBSCRIBE_MESS;
                 $newList->notifyadminmsg = _JNEWS_UNSUBSCRIBE_ADMIN_NOTIFICATION;
                 $newList->subnotifymsg = _JNEWS_SUBSDEFAULT_NOTIFYMSG;
                 $newList->subnotifysend = 1;
                 $newList->unsubscribesend = 1;
                 $newList->unsubscribenotifyadmin = 1;
                 $newList->footer = 1;
                 $linkForm = 'option=' . JNEWS_OPTION;
                 $linkForm = jNews_Tools::completeLink($linkForm, false, false);
                 $mainLink = JRoute::_('index.php?option=' . JNEWS_OPTION);
                 $forms['main'] = "<form action='{$mainLink}' method='post' name='adminForm' enctype='multipart/form-data' onsubmit='submitbutton();return false;' id=\"adminForm\">";
                 $show = jNews_ListType::showType($lisType, 'editlist');
                 // menus for list edit
                 // menu save
                 $linkForm = jNews_Tools::completeLink($linkForm, true);
                 $linkForm = '#';
                 $menuSave = new stdClass();
                 $menuSave->popup = new stdClass();
                 $menuSave->popup->isPop = false;
                 $menuSave->link = $linkForm;
                 $menuSave->action = 'save';
                 $menuSave->onclick = new stdClass();
                 $menuSave->onclick->custom = false;
                 $menuSave->onclick->js = '';
                 $menuSave->title = _JNEWS_SAVE;
                 // menu cancel
                 $menuCancel = new stdClass();
                 $menuCancel->popup = new stdClass();
                 $menuCancel->popup->isPop = false;
                 $menuCancel->link = jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=list&Itemid=' . $Itemid, false);
                 $menuCancel->action = 'cancel';
                 $menuCancel->onclick = new stdClass();
                 $menuCancel->onclick->custom = true;
                 $menuCancel->onclick->js = '';
                 $menuCancel->title = _JNEWS_CANCEL;
                 $link = 'option=' . JNEWS_OPTION;
                 $link = jNews_Tools::completeLink($link, false);
                 $menuCpanel = new stdClass();
                 $menuCpanel->popup = new stdClass();
                 $menuCpanel->popup->isPop = false;
                 $menuCpanel->popup->isPop = false;
                 $menuCpanel->link = $link;
                 $menuCpanel->action = 'cpanel';
                 $menuCpanel->onclick = new stdClass();
                 $menuCpanel->onclick->custom = false;
                 $menuCpanel->onclick->js = '';
                 $menuCpanel->title = _JNEWS_MENU_CPANEL;
                 $menuA = array();
                 $menuA['save'] = $menuSave;
                 $menuA['cancel'] = $menuCancel;
                 $menuA['cpanel'] = $menuCpanel;
                 frontHTML::formStart(_JNEWS_EDIT_A . @constant($GLOBALS[JNEWS . 'listname' . $lisType]) . ' ' . _JNEWS_LIST, $newList->html, 'listedit', $menuA);
                 jNews_ListsHTML::editList($newList, $forms, $show, $lisType);
                 $go[] = jnews::makeObj('list_id', $newList->id);
                 $go[] = jnews::makeObj('act', $action);
                 $go[] = jnews::makeObj('task', '');
                 $go[] = jnews::makeObj('listype', JRequest::getInt('listype'));
                 frontHTML::formEndFN(null, $go);
             }
             break;
         case 'edit':
             $access = 'admin';
             $id = 0;
             if ($GLOBALS[JNEWS . 'enable_jsub']) {
                 if (!empty($my->id)) {
                     $ownedlists = jNews_Lists::getOwnedlists($my->id);
                 }
                 if (!empty($ownedlists)) {
                     $access = strtolower($my->usertype);
                 }
                 $id = $my->id;
             }
             if (jnews::checkPermissions($access) || jnews::checkPermissions($gid)) {
                 //traces
                 $task = 'update';
                 $list = jNews_Lists::getLists($listId, $lisType, $subscriberId, '', false, false, false);
                 $listEdit = $list[0];
                 $listEdit->new_letter = 0;
                 if (!empty($listEdit)) {
                     $linkForm = 'option=' . JNEWS_OPTION;
                     $linkForm = jNews_Tools::completeLink($linkForm, false, false);
                     $mainLink = JRoute::_('index.php?option=' . JNEWS_OPTION);
                     $forms['main'] = "<form action='{$mainLink}' method='post' name='adminForm' enctype='multipart/form-data' onsubmit='submitbutton();return false;' id=\"adminForm\">";
                     $show = jNews_ListType::showType($listEdit->list_type, 'editlist');
                     // menus for list edit
                     // menu save
                     $linkForm = 'option=' . JNEWS_OPTION . '&act=list&listid=' . $listId . '&listype=' . $lisType . '&siteend=1&Itemid=' . $Itemid;
                     $linkForm = jNews_Tools::completeLink($linkForm, false);
                     $menuSave = new stdClass();
                     $menuSave->popup = new stdClass();
                     $menuSave->popup->isPop = false;
                     $menuSave->link = $linkForm;
                     $menuSave->action = 'save';
                     $menuSave->onclick = new stdClass();
                     $menuSave->onclick->custom = false;
                     $menuSave->onclick->js = '';
                     $menuSave->title = _JNEWS_SAVE;
                     // menu cancel
                     $menuCancel = new stdClass();
                     $menuCancel->popup = new stdClass();
                     $menuCancel->popup->isPop = false;
                     $menuCancel->link = jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=list&Itemid=' . $Itemid, false);
                     $menuCancel->action = 'cancel';
                     $menuCancel->onclick = new stdClass();
                     $menuCancel->onclick->custom = true;
                     $menuCancel->onclick->js = '';
                     $menuCancel->title = _JNEWS_CANCEL;
                     $link = 'option=' . JNEWS_OPTION;
                     $link = jNews_Tools::completeLink($link, false);
                     $menuCpanel = new stdClass();
                     $menuCpanel->popup = new stdClass();
                     $menuCpanel->popup->isPop = false;
                     $menuCpanel->popup->isPop = false;
                     $menuCpanel->link = $link;
                     $menuCpanel->action = 'cpanel';
                     $menuCpanel->onclick = new stdClass();
                     $menuCpanel->onclick->custom = false;
                     $menuCpanel->onclick->js = '';
                     $menuCpanel->title = _JNEWS_MENU_CPANEL;
                     $menuA = array();
                     if (@(include_once JNEWSPATH_ADMIN . 'social' . DS . 'class.social.php')) {
                         if (class_exists('jNews_Social')) {
                             $menuA['save'] = $menuSave;
                             $menuA['cancel'] = $menuCancel;
                         }
                     }
                     $menuA['cpanel'] = $menuCpanel;
                     frontHTML::formStart(_JNEWS_EDIT_A . @constant($GLOBALS[JNEWS . 'listname' . $lisType]) . ' ' . _JNEWS_LIST, $listEdit->html, 'listedit', $menuA);
                     jNews_ListsHTML::editList($listEdit, $forms, $show, $lisType);
                     $go[] = jnews::makeObj('list_id', $listEdit->id);
                     $go[] = jnews::makeObj('act', $action);
                     $go[] = jnews::makeObj('task', 'update');
                     frontHTML::formEndFN(null, $go);
                 }
             }
             break;
         case 'save':
             JRequest::checkToken() or die('Invalid Token');
             if (empty($listId)) {
                 if (@(include_once JNEWSPATH_ADMIN . 'social' . DS . 'class.social.php')) {
                     if (class_exists('jNews_Social')) {
                         $status = jNews_Social::createFrontendList($action, $task, $lisType);
                     }
                 }
                 $msgtype = $status ? 'ok' : 'no';
                 $message = jnews::printYN($msgtype, _JNEWS_LIST_ADDED, _JNEWS_ERROR);
                 if ($mainframe->isAdmin()) {
                     jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=list&listype=' . $lisType . '&siteend=1');
                 } else {
                     $mainLink = JRoute::_('index.php?option=' . JNEWS_OPTION . '&act=list&listype=' . $lisType . '&siteend=1');
                     jNews_Tools::redirect($mainLink);
                 }
                 echo $message;
             } else {
                 $lisType = jNews_Lists::getListType($listId);
                 $message = jnews::printYN(jNews_Lists::updateListFromEdit($listId, '', false, $lisType), _JNEWS_LIST_UPDATED, _JNEWS_ERROR);
                 //						jNews_Tools::redirect('index.php?option='.JNEWS_OPTION.'&act=list&listype='.$lisType.'&siteend=1');
                 if ($mainframe->isAdmin()) {
                     jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION . '&act=list&listype=' . $lisType . '&siteend=1');
                 } else {
                     $mainLink = JRoute::_('index.php?option=' . JNEWS_OPTION . '&act=list&listype=' . $lisType . '&siteend=1');
                     jNews_Tools::redirect($mainLink);
                 }
                 echo $message;
                 $listId = 0;
             }
             break;
         case 'ownerslists':
             $ownerid = JRequest::getVar('ownerid', 0);
             $item = JRequest::getInt('Itemid');
             $ownerslists = jNews_Lists::getSpecifiedLists(0, '', $ownerid);
             $module = new jnews_module();
             $module->lists = $ownerslists;
             $module->showListName = true;
             $module->defaultchecked = true;
             $module->dropdown = false;
             $module->shownamefield = true;
             $HTML = $module->create();
             echo $HTML;
             break;
         case 'make':
         case 'forms':
             if (class_exists('jNews_CreateForm')) {
                 jNews_CreateForm::taskOptions($task);
                 $showLists = false;
             } else {
                 $showLists = true;
             }
             break;
         case 'cpanel':
             jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION);
             break;
         default:
             $my = JFactory::getUser();
             $show = jNews_ListType::showType($lisType, 'showListsFront');
             $msgtype = JRequest::getVar('msg', '');
             if (!empty($msgtype)) {
                 if ($msgtype == 'no') {
                     echo jnews::printM($msgtype, _JNEWS_ERROR);
                 } else {
                     echo jnews::printM($msgtype, _JNEWS_LIST_ADDED);
                 }
             }
             $mainLink = JRoute::_('index.php?option=' . JNEWS_OPTION);
             $forms['main'] = '<form method="post" action="' . $mainLink . '" onsubmit="submitbutton();return false;" name="mosForm" >' . "\n\r";
             //$link
             $forms['main'] .= '<input type="hidden" name="Itemid" value="' . $Itemid . '" />';
             $order = 'listnameA';
             $id = 0;
             if ($GLOBALS[JNEWS . 'enable_jsub']) {
                 if (!empty($my->id)) {
                     $ownedlists = jNews_Lists::getOwnedlists($my->id);
                 }
                 if (!empty($ownedlists)) {
                     $id = $my->id;
                 }
             }
             if (jnews::checkPermissions('admin') || jnews::checkPermissions($gid) || !empty($listsAddEdit)) {
                 if ($mainframe->isAdmin()) {
                     $lists = jNews_Lists::getLists($listId, $lisType, $subscriberId, $order, false, false, false);
                 } else {
                     $lists = jNews_Lists::getLists($listId, $lisType, $subscriberId, $order, false, true, false, false, true);
                 }
             } else {
                 if ($mainframe->isAdmin()) {
                     if ($lisType == 0) {
                         $lists1 = jNews_Lists::getLists($listId, 1, $subscriberId, $order, false, true, false);
                         $lists2 = jNews_Lists::getLists($listId, 2, $subscriberId, $order, false, true, false);
                         $lists7 = jNews_Lists::getLists($listId, 7, $subscriberId, $order, false, true, false);
                         $lists = array_merge($lists1, $lists2, $lists7);
                     } elseif ($lisType == 1 or $lisType == 2 or $lisType == 7) {
                         $lists = jNews_Lists::getLists($listId, $lisType, $subscriberId, $order, false, true, false);
                     } else {
                         $lists = '';
                     }
                 } else {
                     if ($lisType == 0) {
                         //get the owned list of the logged user
                         $ownedlists = 0;
                         if ($GLOBALS[JNEWS . 'enable_jsub']) {
                             $my = JFactory::getUser();
                             if (!empty($my->id)) {
                                 $ownedlists = jNews_Lists::getOwnedlists($my->id);
                             }
                             if (!empty($ownedlists)) {
                                 $access = true;
                             }
                         }
                         $lists1 = jNews_Lists::getLists($listId, 1, $subscriberId, $order, false, true, false, false, true, '', '', $ownedlists, $my->id);
                         $lists2 = jNews_Lists::getLists($listId, 2, $subscriberId, $order, false, true, false, false, true);
                         $lists7 = jNews_Lists::getLists($listId, 7, $subscriberId, $order, false, true, false, false, true);
                         $lists = array_merge($lists1, $lists2, $lists7);
                     } elseif ($lisType == 1 or $lisType == 2 or $lisType == 7) {
                         $lists = jNews_Lists::getLists($listId, $lisType, $subscriberId, $order, false, true, false, false, true);
                     } else {
                         $lists = '';
                     }
                 }
             }
             if (!empty($lists) || jnews::checkPermissions($gid)) {
                 $menuA = null;
                 if ($my->id > 0) {
                     $link = 'option=' . JNEWS_OPTION;
                     $link = jNews_Tools::completeLink($link, false);
                     $menuCpanel = new stdClass();
                     $menuCpanel->popup = new stdClass();
                     $menuCpanel->popup->isPop = false;
                     $menuCpanel->popup->isPop = false;
                     $menuCpanel->link = $link;
                     $menuCpanel->action = 'cpanel';
                     $menuCpanel->onclick = new stdClass();
                     $menuCpanel->onclick->custom = false;
                     $menuCpanel->onclick->js = '';
                     $menuCpanel->title = _JNEWS_MENU_CPANEL;
                     $menuShare = new stdClass();
                     $menuForms = new stdClass();
                     $menuNew = new stdClass();
                     $itemId = $GLOBALS[JNEWS . 'itemidAca'];
                     if ($GLOBALS[JNEWS . 'enable_jsub'] && !empty($ownedlists) || jnews::checkPermissions('admin') || jnews::checkPermissions($gid)) {
                         $linkShare = 'option=' . JNEWS_OPTION . '&act=list&task=ownerslists&ownerid=' . $my->id . '&Itemid=' . $itemId;
                         $linkShare = jNews_Tools::completeLink($linkShare, false);
                         $menuShare = new stdClass();
                         $menuShare->popup = new stdClass();
                         $menuShare->popup->isPop = false;
                         $menuShare->link = $linkShare;
                         $menuShare->action = 'share';
                         $menuShare->onclick = new stdClass();
                         $menuShare->onclick->custom = false;
                         $menuShare->onclick->js = '';
                         $menuShare->title = 'Share';
                         $menuBack = new stdClass();
                         $menuBack->popup = new stdClass();
                         $menuBack->popup = new stdClass();
                         $menuBack->popup->isPop = false;
                         $menuBack->link = jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=list&Itemid=' . $Itemid, false);
                         $menuBack->action = 'back';
                         $menuBack->onclick = new stdClass();
                         $menuBack->onclick->custom = true;
                         $menuBack->onclick->js = '';
                         $menuBack->title = _JNEWS_MENU_BACK;
                         $menuDelete = new stdClass();
                         $menuDelete->popup = new stdClass();
                         $menuDelete->popup->isPop = false;
                         $menuDelete->link = '#';
                         $menuDelete->action = 'delete';
                         $menuDelete->onclick = new stdClass();
                         $menuDelete->onclick->custom = false;
                         $menuDelete->onclick->js = '';
                         $menuDelete->title = _JNEWS_DELETE;
                         $menuForms = new stdClass();
                         $menuNew = new stdClass();
                         if ($GLOBALS[JNEWS . 'enable_jsub'] && !empty($ownedlists)) {
                             $linkForm = jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=list&task=make', false, false, true);
                             $menuForms->link = $linkForm;
                             $menuForms->popup = new stdClass();
                             $menuForms->popup->isPop = true;
                             $menuForms->popup->rel = true;
                             $menuForms->popup->x = 750;
                             $menuForms->popup->y = 500;
                             $menuForms->action = 'form';
                             $menuForms->title = 'Create Form';
                             $linknew = 'option=com_jsubscription&view=jsubscription&task=listing&Itemid=' . $itemId;
                             $menuNew = new stdClass();
                             $menuNew->popup = new stdClass();
                             $menuNew->popup->isPop = false;
                             $menuNew->action = 'new';
                             $menuNew->onclick = new stdClass();
                             $menuNew->onclick->custom = true;
                             $menuNew->onclick->js = '';
                             $menuNew->title = 'New';
                             $menuNew->link = $linknew;
                         } else {
                             if (@(include_once JNEWSPATH_ADMIN . 'social' . DS . 'class.social.php')) {
                                 if (class_exists('jNews_Social')) {
                                     //									if($lisType == 1){
                                     $linkForm = jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=list&task=make', true, false, true);
                                     $menuForms->link = $linkForm;
                                     $menuForms->popup = new stdClass();
                                     $menuForms->popup->isPop = true;
                                     $menuForms->popup->rel = true;
                                     $menuForms->popup->x = 750;
                                     $menuForms->popup->y = 500;
                                     $menuForms->action = 'form';
                                     $menuForms->title = 'Create Form';
                                     //										$linknew = 'option='.JNEWS_OPTION.'&act=list&task=new&listype='.$lisType.'&siteend=1&Itemid='.$itemId;
                                     $mainLink = JRoute::_('index.php?option=' . JNEWS_OPTION);
                                     $menuNew = new stdClass();
                                     $menuNew->popup = new stdClass();
                                     $menuNew->popup->isPop = false;
                                     //										$linknew = jNews_Tools::completeLink($linknew,false);
                                     $linknew = '#';
                                     // #
                                     $menuNew->action = 'new';
                                     $menuNew->onclick = new stdClass();
                                     $menuNew->onclick->custom = true;
                                     $menuNew->onclick->js = "javascript: submitbutton('new')";
                                     $menuNew->title = 'New';
                                     $menuNew->link = $linknew;
                                 }
                                 //								}
                             }
                         }
                         $menuUnpub = new stdClass();
                         $menuUnpub->popup = new stdClass();
                         $menuUnpub->popup->isPop = false;
                         $menuUnpub->link = '#';
                         $menuUnpub->action = 'unpublished';
                         $menuUnpub->onclick = new stdClass();
                         $menuUnpub->onclick->custom = true;
                         $menuUnpub->onclick->js = 'javascript:history.go(-1)';
                         $menuUnpub->title = 'Unpublished';
                         $menuPub = new stdClass();
                         $menuPub->popup = new stdClass();
                         $menuPub->popup->isPop = false;
                         $menuPub->link = '#';
                         $menuPub->action = 'published';
                         $menuPub->onclick = new stdClass();
                         $menuPub->onclick->custom = true;
                         $menuPub->onclick->js = 'javascript:history.go(-1)';
                         $menuPub->title = 'Published';
                         $menuCopy = new stdClass();
                         $menuCopy->popup = new stdClass();
                         $menuCopy->popup->isPop = false;
                         $menuCopy->link = '#';
                         $menuCopy->action = 'copy';
                         $menuCopy->onclick = new stdClass();
                         $menuCopy->onclick->custom = true;
                         $menuCopy->onclick->js = 'javascript:history.go(-1)';
                         $menuCopy->title = 'Copy';
                         $menuDivider = new stdClass();
                         $menuDivider->divider = true;
                     }
                     $menuA = array();
                     if ($lisType == '2') {
                         $menuA['new'] = $menuNew;
                         $menuA['cpanel'] = $menuCpanel;
                     } else {
                         if ($GLOBALS[JNEWS . 'enable_jsub']) {
                             $menuA['share'] = $menuShare;
                         }
                         $menuA['form'] = $menuForms;
                         $menuA['new'] = $menuNew;
                         $menuA['cpanel'] = $menuCpanel;
                     }
                 }
                 if ($lisType == 1) {
                     $title = _JNEWS_EMAIL_LISTS;
                 } else {
                     $title = 'Auto-responders';
                 }
                 if (empty($my->id)) {
                     $title = _JNEWS_SUBSCRIBE_LIST2;
                 }
                 if (empty($ownedlists) && !empty($my->id)) {
                     $title = _JNEWS_SUBSCRIBE_LIST2;
                 }
                 $gid = !empty($GLOBALS[JNEWS . 'list_creatorfe']) ? $GLOBALS[JNEWS . 'list_creatorfe'] : 0;
                 frontHTML::formStart($title, 0, '', $menuA);
                 frontHTML::FEmenu();
                 if ($show['list_type']) {
                     $show['list_type'] = jNews_ListType::checkOthers();
                 }
                 $setSort = new stdClass();
                 $setSort->orderDir = '';
                 $setSort->orderValue = '';
                 if (class_exists('jNews_Pro')) {
                     $id = 0;
                     if ($GLOBALS[JNEWS . 'enable_jsub']) {
                         if (!empty($my->id)) {
                             $ownedlists = jNews_Lists::getOwnedlists($my->id);
                         }
                         if (!empty($ownedlists)) {
                             $id = $my->id;
                         }
                     }
                     $access = false;
                     foreach ($lists as $list) {
                         $bit = jnews::checkPermissions($list->acc_level);
                         if ($bit) {
                             $access = true;
                             break;
                         }
                     }
                     $my = JFactory::getUser();
                     //owner of the list to access the list
                     if ($GLOBALS[JNEWS . 'enable_jsub']) {
                         if (!empty($my->id)) {
                             $ownedlists = jNews_Lists::getOwnedlists($my->id);
                         }
                         if (!empty($ownedlists)) {
                             $access = true;
                             $usertype = strtolower($my->usertype);
                         }
                     }
                     if ($access) {
                         jNews_Pro::showListingLists($lists, $action, 'edit', $forms, $show, $my->id);
                         $go[] = jnews::makeObj('listype', JRequest::getInt('listype'));
                     } else {
                         jNews_ListsHTML::showListingLists($lists, $action, 'edit', $forms, $show, '', 0, null, null, $setSort);
                         $go[] = jnews::makeObj('listype', JRequest::getInt('listype'));
                     }
                 } else {
                     jNews_ListsHTML::showListingLists($lists, $action, 'edit', $forms, $show, '', 0, null, null, $setSort);
                 }
                 $go[] = jnews::makeObj('act', $action);
                 frontHTML::formEnd('', $go);
             } else {
                 frontHTML::FEmenu();
             }
             break;
     }
 }
Exemple #3
0
function com_install()
{
    if (defined('JPATH_ROOT') and class_exists('JFactory')) {
        define('JNEWS_JPATH_ROOT', JPATH_ROOT);
    }
    if (!defined('DS')) {
        define('DS', DIRECTORY_SEPARATOR);
    }
    if (is_dir(JNEWS_JPATH_ROOT . DS . "administrator" . DS . "components" . DS . "com_jnews" . DS)) {
        $filename_for_del = JNEWS_JPATH_ROOT . DS . "administrator" . DS . "components" . DS . "com_jnews" . DS . "admin.jnews.php";
        if (file_exists($filename_for_del)) {
            if (is_writable($filename_for_del)) {
                unlink($filename_for_del);
            }
        }
    }
    if (!defined('DS')) {
        define('DS', DIRECTORY_SEPARATOR);
    }
    require_once JNEWS_JPATH_ROOT . DS . 'components' . DS . 'com_jnews' . DS . 'defines.php';
    require_once JNEWSPATH_ADMIN . 'classes' . DS . 'config.php';
    require_once JNEWSPATH_ADMIN . 'admin.jnews.html.php';
    require_once JNEWSPATH_CLASS . DS . 'class.jnews.php';
    @ini_set('max_execution_time', 0);
    //If memory_limit less than 128M
    $limit = jnews::convertToBytes(@ini_get('memory_limit'));
    if ($limit < jnews::convertToBytes('128M')) {
        @ini_set('memory_limit', '128M');
    }
    $xf = new jNews_Config();
    $return = '';
    //we install the jNews Menus
    installMenu();
    $database = JFactory::getDBO();
    $q = " SELECT `text` FROM `#__jnews_xonfig` WHERE `akey` = 'version' ";
    $database->setQuery($q);
    $vers = $database->loadResult();
    $err = $database->getErrorMsg();
    $version = jnews::getVersion();
    //we check if availability column exists in jnews_templates
    $q = "SHOW FIELDS FROM `#__jnews_templates`";
    $database->setQuery($q);
    $templateFields = $database->loadObjectList('Field');
    if (!empty($version) and $version < '7.3.0') {
        $query[] = "ALTER TABLE `#__jnews_listssubscribers` ADD `params` TEXT NOT NULL";
        $query[] = "ALTER TABLE `#__jnews_queue` ADD `params` TEXT NOT NULL";
    }
    if (!empty($version) and $version < '7.2.0') {
        $query[] = "UPDATE `#__jnews_xonfig` SET `text`='jNews_Newsletter' WHERE `text`='newsletter' AND `akey`='classes1' ";
        $query[] = "UPDATE `#__jnews_xonfig` SET `text`='jNews_Autoresponder' WHERE `text`='autoresponder' AND `akey`='classes2' ";
        $query[] = "UPDATE `#__jnews_xonfig` SET `text`='jNews_Autonews' WHERE `text`='autonews' AND `akey`='classes7' ";
    }
    if (!empty($version) && $version < '7.1.0') {
        $query[] = "ALTER TABLE `#__jnews_lists` ADD `subnotifysend` TINYINT(1) NOT NULL DEFAULT '1', ADD `subnotifymsg` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL";
        $query[] = "ALTER TABLE `#__jnews_templates` ADD `csstyle` TEXT NOT NULL";
        $query[] = "UPDATE `#__jnews_templates` SET `body` = REPLACE(`body`,'components/com_jnews/templates/','media/com_jnews/templates/')";
    }
    if (!empty($version) && $version < '7.0.2') {
        $xf->insert('cron_pass', 'ibHrqqFb');
        $xf->insert('nextdate', '0');
        $xf->insert('lastdate', '0');
    }
    if (!empty($version) && $version < '6.1.2') {
        $xf->insert('url_pass', 'xfr1tyh6', 0);
        $xf->insert('create_newsubsrows', '5', 0);
        $xf->insert('use_backendview', '0', 0);
        $xf->insert('terms_condition', '0', 0);
        $xf->insert('show_terms', '0', 0);
        $xf->insert('check_terms', '0', 0);
    }
    if (empty($err) and !empty($version) and $version < '6.0.2') {
        if (@(include_once JNEWSPATH_ADMIN . 'social' . DS . 'class.social.php')) {
            if (class_exists('jNews_Social')) {
                $query[] = "ALTER TABLE `#__jnews_lists` ADD `siteend` TINYINT( 3 ) UNSIGNED NOT NULL DEFAULT '0'";
            }
        }
        $query[] = "ALTER TABLE `#__jnews_lists` CHANGE `acc_id` `acc_id` VARCHAR( 200 ) NOT NULL DEFAULT 'all'";
        $query[] = "ALTER TABLE `#__jnews_lists` CHANGE `acc_level` `acc_level` VARCHAR( 200 ) NOT NULL DEFAULT '24,25,7,8'";
        $query[] = "UPDATE `#__jnews_lists` SET `acc_id`= 'all' WHERE `acc_id`= 29";
        $query[] = "UPDATE `#__jnews_lists` SET `acc_level`='24,25,7,8' WHERE `acc_level`=25";
        $xf->insert('use_tags', '1', 0);
        $xf->insert('allow_sn', '0', 0);
        $xf->insert('show_sub_email', '0', 0);
        $xf->insert('red_subscription', '0', 0);
        $xf->insert('module_message', '0', 0);
        $xf->update('upload_url', '/components/com_jnews/upload');
    }
    if (empty($err) && !empty($version) && $version <= '4.2.2') {
        //alter the table template with the column availabiltity
        if (is_array($templateFields) && array_key_exists('availability', $templateFields) == false) {
            $query[] = "ALTER TABLE `#__jnews_templates` ADD `availability` TINYINT( 1 ) NOT NULL DEFAULT '1' ";
        }
        $xf->insert('captcha_width', '80', 0);
        $xf->insert('captcha_height', '25', 0);
    }
    if (empty($err) and !empty($version) and $version < '5.1.0') {
        //alter the table queue, we also add the type in the unique key
        $query[] = 'ALTER TABLE `#__jnews_queue` DROP INDEX `sub_mail` ,
					ADD UNIQUE `sub_mail` ( `subscriber_id` , `mailing_id` , `type` )';
        $xf->insert('forced_html', '1', 0);
    }
    if (empty($err) and !empty($version) and $version >= '1.2.0' and $version < '2.2.2') {
        $query[] = 'ALTER TABLE `#__jnews_lists` ADD `notifyadminmsg` text NOT NULL';
        $xf->insert('j_cron', '1', 0);
    }
    if (empty($err) and !empty($version) and $version < '4.0.2') {
        //delete the params column
        $q = "SHOW FIELDS FROM `#__jnews_queue`";
        $database->setQuery($q);
        $queueFields = $database->loadObjectList('Field');
        $q = "SHOW FIELDS FROM `#__jnews_lists`";
        $database->setQuery($q);
        $listFields = $database->loadObjectList('Field');
        if (version_compare(JVERSION, '1.6.0', '<')) {
            //j15
            //for the update in the jos_components table for the menu auto-responder
            $query[] = 'UPDATE `#__components`' . ' SET admin_menu_link = \'option=' . JNEWS_OPTION . '&act=arlist&listype=2\'' . ' WHERE `option`=\'com_jnews\'' . ' AND `name`=\'Auto-responders\'';
            //delete the name import in the _components table
            $query[] = 'DELETE FROM `#__components` WHERE `name`=\'Import\' AND `option`=\'com_jnews\'';
        }
        //update max_attempts to 5
        $query[] = 'UPDATE `#__jnews_xonfig` SET `text` = 5 WHERE `akey`=\'max_attempts\'';
        //update sched_prior to 5
        $query[] = 'UPDATE `#__jnews_xonfig` SET `text` = 5 WHERE `akey`=\'sched_prior\'';
        //update ar_prior
        $query[] = 'UPDATE `#__jnews_xonfig` SET `text` = 1 WHERE `akey`=\'ar_prior\'';
        //update sm_prior
        $query[] = 'UPDATE `#__jnews_xonfig` SET `text` = 5 WHERE `akey`=\'sm_prior\'';
        $xf->insert('priord_list', '0', 0);
        $xf->insert('priord_subs', '0', 0);
        $xf->insert('show_unsubscribe', '0', 0);
        $xf->insert('show_unsubscribelink', '1', 0);
        $xf->insert('show_subscriptionlink', '1', 0);
        $xf->insert('queue_status', '1', 0);
    }
    if (empty($err) and !empty($version) and $version <= '4.1.2') {
        $xf->insert('smtp_port', '25', 0);
        $xf->insert('smart_queue', '0', 0);
        $xf->insert('sub_info_fields', '0', 0);
        $xf->insert('enable_jsub', '0', 0);
    }
    if (!empty($version) && $version <= '7.2.2') {
        //add params column if not exists
        $q = "SHOW FIELDS FROM `#__jnews_mailings`";
        $database->setQuery($q);
        $queueFields = $database->loadObjectList('Field');
        //we drop the column params in the table jnews_queue
        if (!array_key_exists('params', $queueFields)) {
            $query[] = 'ALTER TABLE `#__jnews_mailings` ADD `params` TEXT NOT NULL';
        }
        $q = "SHOW FIELDS FROM `#__jnews_lists`";
        $database->setQuery($q);
        $queueFields = $database->loadObjectList('Field');
        //we drop the column params in the table jnews_queue
        if (!array_key_exists('params', $queueFields)) {
            $query[] = 'ALTER TABLE `#__jnews_lists` ADD `params` TEXT NOT NULL';
        }
        $xf->insert('smtp_secure', '', 0);
    }
    if (!empty($version) && $version <= '7.3.9') {
        $xf->insert('lasttime_cron_triggerred', '0', 0);
        $xf->insert('show_unsubscribe_all', '1', 0);
        $xf->insert('send_log_email', '0', 0);
        $query[] = 'ALTER TABLE `#__jnews_queue` ADD `block` TINYINT NOT NULL DEFAULT 0';
        //add block column in the queue table
        //we get the values of red_subscription, module_message, enable_captcha, captcha_width, captcha_height, show_terms, check_terms, terms_condition from config table to be able to insert it the module params
        $red_subscription = $xf->getKeyValues("red_subscripition");
        $module_message = $xf->getKeyValues("module_message");
        $enable_captcha = $xf->getKeyValues("enable_captcha");
        $captcha_width = $xf->getKeyValues("captcha_width");
        $captcha_height = $xf->getKeyValues("captcha_height");
        $show_terms = $xf->getKeyValues("show_terms");
        $check_terms = $xf->getKeyValues("check_terms");
        $terms_condition = $xf->getKeyValues("terms_condition");
        $additionalParams = '';
        $additionalParams .= "use_new=0" . "\n";
        $additionalParams .= "red_subscripition=" . $red_subscription . "\n";
        $additionalParams .= "module_message=" . $module_message . "\n";
        $additionalParams .= "enable_captcha=" . $enable_captcha . "\n";
        $additionalParams .= "captcha_width=" . $captcha_width . "\n";
        $additionalParams .= "captcha_height=" . $captcha_height . "\n";
        $additionalParams .= "show_terms=" . $show_terms . "\n";
        $additionalParams .= "check_terms=" . $check_terms . "\n";
        $additionalParams .= "terms_condition=" . $terms_condition . "\n";
        //we get the module params from the modules table and append with the values we get from above
        $db = JFactory::getDBO();
        $queryParam = "SELECT `id`,`params` FROM `#__modules` WHERE `module`='mod_jnews'";
        $db->setQuery($queryParam);
        $db->query();
        $jnewsModuleParamsO = $db->loadObjectList('id');
        if (!empty($jnewsModuleParamsO)) {
            foreach ($jnewsModuleParamsO as $key => $value) {
                $params = '';
                $params .= $value->params;
                $params .= $additionalParams;
                //we update the params of the module
                $queryUpdateParam = "UPDATE `#__modules` SET `params`='" . $params . "' WHERE `id`=" . $key;
                $db->setQuery($queryUpdateParam);
                $db->query();
            }
        }
        //we insert here the simplicity template
        $templatessql = 'simplicitytemplate.sql';
        //to be changed if we packaged the superpack
        $buffer = file_get_contents(JNEWSPATH_ADMIN . DS . $templatessql);
        // Graceful exit and rollback if read not successful
        if ($buffer) {
            // Create an array of queries from the sql file
            jimport('joomla.installer.helper');
            $queries = JInstallerHelper::splitSql($buffer);
            // No queries to process
            if (count($queries) != 0) {
                // Process each query in the $queries array (split out of sql file).
                foreach ($queries as $simplicityquery) {
                    $simplicityquery = trim($simplicityquery);
                    if ($simplicityquery != '' && $simplicityquery[0] != '#') {
                        $database->setQuery($simplicityquery);
                        if (!$database->query()) {
                            JError::raiseWarning(1, 'JInstaller::install: ' . JText::_('SQL Error') . " " . $database->stderr(true));
                        }
                    }
                }
                //endfoearch
            }
        }
    }
    if (!empty($version) && $version <= '7.4.5') {
        if (version_compare(JVERSION, '1.6.0', '>=')) {
            //j16
            $query[] = 'UPDATE `#__assets` SET `rules`=\'{"core.admin":{"1":1},"core.manage":{"1":1}}\' WHERE `name`=\'com_jnews\'';
        }
    }
    // ALTER TABLE `jos_jnews_mailings` CHANGE `cat_id` `cat_id` VARCHAR( 250 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '0:0'
    if (empty($version) || $version < '7.5.0') {
        $xf->update('show_unsubscribelink', '1');
        $xf->update('show_subscriptionlink', '1');
        $xf->update('upload_url', '/media/com_jnews/upload');
        $q = "SHOW FIELDS FROM `#__jnews_mailings`";
        $database->setQuery($q);
        $queueFields = $database->loadObjectList('Field');
        if (!array_key_exists('smart_date', $queueFields)) {
            $query[] = 'ALTER TABLE `#__jnews_mailings` ADD `smart_date` TINYINT UNSIGNED NOT NULL DEFAULT 0';
        }
        $q = "SHOW FIELDS FROM `#__jnews_queue`";
        $database->setQuery($q);
        $queueFields = $database->loadObjectList('Field');
        if (!array_key_exists('params', $queueFields)) {
            $query[] = 'ALTER TABLE `#__jnews_queue` ADD `params` TEXT NOT NULL';
        }
        if (!array_key_exists('block', $queueFields)) {
            $query[] = 'ALTER TABLE `#__jnews_queue` ADD `block` TINYINT NOT NULL DEFAULT 0';
        }
    }
    if (empty($version) || version_compare($version, '7.6.0', '<')) {
        $xf->insert('sntag_norequired', '1');
        $conf = JFactory::getConfig();
        $xf->insert('sendmail_email', $conf->get('config.mailfrom'));
        $xf->insert('subs_redirect_url', '');
        $xf->insert('subscribe_notification', '');
        $xf->insert('unsubscribe_notification', '');
        $xf->insert('component_theme', 'joobilist');
        $xf->insert('allow_fe_autoresponder', '0');
    }
    if (empty($version) || version_compare($version, '7.7.0', '<')) {
        $xf->insert('archive_link', 'standard');
    }
    //Query to quickly synchronise all your subscribers during the install!
    $query[] = "INSERT IGNORE INTO `#__jnews_subscribers` ( `user_id` , `name` , `email` , `receive_html` , `confirmed` , `blacklist` , `subscribe_date` )" . "SELECT U.id, U.name, U.email, '1', '1', U.block , UNIX_TIMESTAMP(U.registerDate) from `#__users` as U;";
    if (empty($vers)) {
        if (version_compare(JVERSION, '1.6.0', '<')) {
            //j15
            $query[] = "UPDATE #__components SET ordering = -2147483800 WHERE admin_menu_link='option=com_jnews'";
            //		}else{ //j16
            //			$query[] = "UPDATE #__extensions SET ordering = -2147483800 WHERE element='option=com_jnews'";
        }
    }
    //We publish back the module
    $query[] = "UPDATE `#__modules` SET `published`= 1 WHERE `module` LIKE '%jnews%' ";
    $size = sizeof($query);
    for ($index = 0; $index < $size; $index++) {
        $database->setQuery($query[$index]);
        $database->query();
    }
    if (@(include_once JNEWSPATH_ADMIN . 'social' . DS . 'class.social.php')) {
        if (class_exists('jNews_Social')) {
            if (!empty($version) && $version < '6.0.2') {
                $xf->insert('use_masterlists', '1', 0);
                $xf->insert('list_creatorfe', '24,25,7,8', 0);
            }
            jNews_Social::createMasterList(1);
            jNews_Social::createMasterList(2);
            jNews_Social::createMasterList(3);
            jNews_Social::createMasterList(4);
        }
    }
    //we call sql file for the additional templates
    if (is_array($templateFields) && array_key_exists('availability', $templateFields)) {
        //line to be removed code #7321011
        $templatessql = 'dwntemplates.sql';
        //to be changed if we packaged the superpack
        $buffer = file_get_contents(JNEWSPATH_ADMIN . DS . $templatessql);
        // Graceful exit and rollback if read not successful
        if ($buffer) {
            // Create an array of queries from the sql file
            jimport('joomla.installer.helper');
            $queries = JInstallerHelper::splitSql($buffer);
            // No queries to process
            if (count($queries) != 0) {
                // Process each query in the $queries array (split out of sql file).
                foreach ($queries as $query) {
                    $query = trim($query);
                    if ($query != '' && $query[0] != '#') {
                        $database->setQuery($query);
                        if (!$database->query()) {
                            JError::raiseWarning(1, 'JInstaller::install: ' . JText::_('SQL Error') . " " . $database->stderr(true));
                            //return false;
                        }
                    }
                }
                //endfoearch
            }
        }
    }
    if (empty($vers)) {
        $xf->filetoDatabase($confiX);
    }
    //create the upload directory
    jnews::createDirectory(JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'media' . DS . JNEWS_OPTION . DS . 'upload' . DS);
    //check if CSS file exist if not move it
    jimport('joomla.filesystem.folder');
    $cssLocation = JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'media' . DS . JNEWS_OPTION . DS . 'modules' . DS;
    if (!JFolder::exists($cssLocation)) {
        JFolder::copy(JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'components' . DS . JNEWS_OPTION . DS . 'modules' . DS, $cssLocation);
    }
    if (empty($vers)) {
        setupMaiOptions($confiX);
    }
    //we install the default templates
    installDefTemplate();
    //we install the extensions
    installExtensions();
    //we send a welcome message to the admin/logged in user of the site that jNews is successfully installed
    //we will only send email at fresh install
    if (empty($version)) {
        sendWelcomeEmail();
    }
    if (jnews::checkCB()) {
        installPlugin();
    }
    jNews_Subscribers::updateCBSubscribers(true, true);
    $xf->update('component', $confiX['component']);
    $xf->update('type', $confiX['type']);
    $xf->update('version', $confiX['version']);
    $xf->update('level', $confiX['level']);
    if (!($confiX['type'] == 'GPL' || $confiX['type'] == 'CORE')) {
        $message = jnews::M('noimage', _JNEWS_THANKYOU, false);
    }
    if (empty($message)) {
        $message = '';
    }
    backHTML::_header(_JNEWS_MENU_INSTALL, 'install.png', $message, '', '');
    $html = '';
    $link = 'index.php?option=' . JNEWS_OPTION . '&act=start';
    $docuLink = 'http://www.joobi.co/index.php?option=com_content&view=article&id=7871:installation-errors&catid=29:jnews&Itemid=72';
    $html .= '&nbsp;' . _JNEWS_INSTALL_ERRORN . ' <a href="' . $docuLink . '">' . _JNEWS_INSTALL_DOC . '</a>';
    // if acajoom component exist... means this would be an update
    // display an update button
    require_once JNEWSPATH_CLASS . 'class.update.php';
    if (jNews_Update::checkAcajoom()) {
        //check if acajoom data are already transferred to jnews tables
        if (!jNews_Update::checkAcaUpdate()) {
            $html .= '<div style="border: 5px groove #F0F8FF; padding: 10px; position: fixed; right: 1px; top: 150px; background-color: #F0F8FF;">';
            $html .= '<img border="0" align="right" alt="jNews Logo" src="components/' . JNEWS_OPTION . '/images/jnewsletter.png" width="25">';
            $html .= '<br><br><span style="font-size:15px;text-decoration:none;">' . _JNEWS_INSTALL_ACAUPDATEMSG . '</span></b>';
            $html .= '<a href="index.php?option=' . JNEWS_OPTION . '&amp;act=acaupdate">';
            $html .= '<div style="background-image: url(' . JNEWS_PATH_ADMIN_IMAGES2 . 'btn_orange.png); background-repeat:no-repeat; height: 15px; width: 170px; border:none; padding:13px 40px 15px; position:relative; left:50px; top:10px;">';
            $html .= '<span style="color: #FFF; font-weight: bold; padding-right:30px; margin-top: 5px; text-decoration: none;"> ' . _JNEWS_INSTALL_ACAUPDATEBTN . ' </span>';
            $html .= '</div></a>';
            $html .= '<br><br>';
            $html .= '<b>' . _JNEWS_INSTALL_ACAUPDATENOTE . '</b>';
            $html .= '<br><br>';
            $html .= '</div>';
        }
    }
    $html .= '<div style="float:center;padding: 20px; width:470px; margin-right: 10px;"><center>' . '<a href="index.php?option=' . JNEWS_OPTION . '&amp;act=start">
				<div style="background-image: url(' . JNEWS_PATH_ADMIN_IMAGES2 . 'btn_orange.png); background-repeat:no-repeat; height: 40px; width: 232px; border:none; padding:12px 0 15px 0;">
				<span style="color: #FFF; font-weight: bold; padding-right:30px; margin-top: 5px; text-decoration: none;">' . _JNEWS_INSTALL_CLICKSTART . '</span></div>
				</a></center></div><div style="clear:both;"></div>';
    if ($confiX['level'] > 2) {
        backHTML::about();
        echo '<center>' . $html;
        echo $return . '</center>';
    } elseif ($confiX['level'] > 1) {
        backHTML::installPRO($html, $return);
    } else {
        backHTML::installPlus($html, $return);
    }
    return $return;
}
 function onAfterStoreUser($user, $isnew, $success, $msg)
 {
     if ($success === false) {
         return false;
     }
     if (strtolower(substr(JPATH_ROOT, strlen(JPATH_ROOT) - 13)) == 'administrator') {
         $adminPath = strtolower(substr(JPATH_ROOT, strlen(JPATH_ROOT) - 13));
     } else {
         $adminPath = JPATH_ROOT;
     }
     if (!@(include_once $adminPath . DS . 'components' . DS . 'com_jnews' . DS . 'defines.php')) {
         return;
     }
     include_once JNEWSPATH_CLASSN . 'class.jnews.php';
     require_once JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'administrator' . DS . 'components' . DS . JNEWS_OPTION . DS . 'classes' . DS . 'class.subscribers.php';
     require_once JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'administrator' . DS . 'components' . DS . JNEWS_OPTION . DS . 'classes' . DS . 'class.listssubscribers.php';
     jimport('joomla.html.parameter');
     $plugin =& JPluginHelper::getPlugin('user', 'jnewssyncuser');
     $params = new JParameter($plugin->params);
     $db =& JFactory::getDBO();
     $subscriber = null;
     $confirmed = 1;
     if ($user['block']) {
         $confirmed = 0;
     }
     $subscriber->email = trim(strip_tags($user['email']));
     if (!empty($user['name'])) {
         $subscriber->name = trim(strip_tags($user['name']));
     }
     if (empty($user['block'])) {
         $subscriber->confirmed = 1;
     }
     $subscriber->user_id = $user['id'];
     $subscriber->ip = jNews_Subscribers::getIP();
     $subscriber->receive_html = 1;
     $subscriber->confirmed = $confirmed;
     $subscriber->subscribe_date = jnews::getNow();
     $subscriber->language_iso = 'eng';
     $subscriber->timezone = '00:00:00';
     $subscriber->blacklist = 0;
     //check if the version of jnews is pro
     if ($GLOBALS[JNEWS . 'type'] == 'PRO') {
         $subscriber->column1 = '';
         $subscriber->column2 = '';
         $subscriber->column3 = '';
         $subscriber->column4 = '';
         $subscriber->column5 = '';
     }
     //end if check if the version is pro
     if (!$isnew and !empty($this->oldUser['email']) and $user['email'] != $this->oldUser['email']) {
         $d['email'] = $this->oldUser['email'];
         $infos = jNews_Subscribers::getSubscriberIdFromEmail($this->oldUser);
         $subscriber->id = $infos['subscriberId'];
     }
     if ($isnew) {
         //new registered user
         $status = jNews_Subscribers::saveSubscriber($subscriber, $subscriber->user_id, true);
         if (empty($subscriber->id)) {
             $subscriber->id = jNews_Subscribers::getSubscriberIdFromUserId($subscriber->user_id);
         }
         if (!$status) {
             return;
         }
         $listsToSubscribe = $params->get('lists', '');
         if (!empty($listsToSubscribe)) {
             $condition = ' WHERE `id` IN (' . $listsToSubscribe . ')';
         } else {
             $condition = ' WHERE `auto_add` > 0';
         }
         //get list ids of auto_add lists
         $query = 'SELECT `id`, `list_type`, `params` from `#__jnews_lists`' . $condition;
         $db->setQuery($query);
         $autoListId = $db->loadObjectList();
         $error = $db->getErrorMsg();
         if (!empty($error)) {
             echo $error;
             return false;
         } else {
             //use for masterlists
             $listsA = array();
             foreach ($autoListId as $autoId) {
                 if (!empty($autoId->params)) {
                     //use for masterlists
                     $listsA[] = $autoId->id;
                 } else {
                     //for non-masterlists
                     $subscriber->list_id = $autoId->id;
                     jNews_ListsSubs::saveToListSubscribers($subscriber);
                 }
                 if ($autoId->list_type == 2) {
                     $subscribe = array();
                     $subscribe[] = $autoId->id;
                     if (!empty($subscribe)) {
                         jNews_ListsSubs::subscribeARtoQueue($subscriber->id, $subscribe);
                     }
                 }
             }
             //end of foreach
         }
         if (!empty($listsA)) {
             //we check if the social class file exists for the implementation of master lists
             if (@(include_once JNEWSPATH_ADMIN . 'social' . DS . 'class.social.php')) {
                 if (class_exists('social')) {
                     $listidSubsA = array();
                     $masterListSubscriber = null;
                     //we check if configuration for master lists is enabled
                     if ($GLOBALS[JNEWS . 'use_masterlists']) {
                         if ($GLOBALS[JNEWS . 'type'] == 'PLUS' || $GLOBALS[JNEWS . 'type'] == 'PRO') {
                             //we validate if the user can be subscribed to the list then we return the masterlistid
                             //1 - MasterLists for all Potential Users
                             $listidSubsA[] = jNews_Social::includeMasterListIds($subscriber->id, 1, $listsA);
                             //2 - MasterLists for all Registered Subscribers
                             $listidSubsA[] = jNews_Social::includeMasterListIds($subscriber->id, 2, $listsA);
                         }
                         if ($GLOBALS[JNEWS . 'type'] == 'PRO') {
                             //we validate if the user can be subscribed to the list then we return the masterlistid
                             //3 - MasterLists for all Front-end Subscribers
                             $listidSubsA[] = jNews_Social::includeMasterListIds($subscriber->id, 3, $listsA);
                         }
                     }
                     $masterListSubscriber->id = $subscriber->id;
                     $masterListSubscriber->list_id = $listidSubsA;
                     jNews_ListsSubs::saveToListSubscribers($masterListSubscriber);
                 }
             }
         }
     } else {
         //confirmed registered user
         //			if(!empty($this->oldUser['block']) AND !empty($subscriber->confirmed)){
         if (empty($subscriber->id)) {
             $subscriber->id = jNews_Subscribers::getSubscriberIdFromUserId($subscriber->user_id);
         }
         plgUserjNewssyncuser::_confirmUserSubscription($subscriber->id);
         //			}
     }
     //endelse
     return true;
 }
 /**
  * This public static function will save entries to listSubscibers
  * @param object $subsListInfo subcriberInfo
  * -> user_id
  * ->array sub_list_id  all lists IDs
  * ->array subscribed only subscribed
  * ->acc_level
  */
 public static function updateSubscriptionToLists($suscription)
 {
     if (empty($suscription->sub_list_id)) {
         return false;
     }
     $db = JFactory::getDBO();
     $listidSubsA = array();
     //subscribe lists
     $listidUnsubsA = array();
     //unsubscribe lists
     $mainframe = JFactory::getApplication();
     //cehck if one of the list is attached to an auto-responder
     //if so make sure we subscribe to it
     $query = 'SELECT `followup_id` FROM `#__jnews_followup`  ';
     $query .= ' WHERE `list_id` IN ( ' . implode($suscription->sub_list_id, ',') . ')';
     $db->setQuery($query);
     $loadResultArray = $db->loadObjectList();
     $attachedList2AutoResponderA = jnews::convertObjectList2Array($loadResultArray);
     if (!empty($attachedList2AutoResponderA)) {
         foreach ($attachedList2AutoResponderA as $oneAutoList) {
             if (!in_array($oneAutoList, $suscription->sub_list_id)) {
                 $suscription->sub_list_id[] = $oneAutoList;
                 $suscription->subscribed[] = 1;
             }
         }
     }
     //get the current state of subscriptions
     $query = 'SELECT `unsubscribe`,`list_id` FROM `#__jnews_listssubscribers`  ';
     $query .= ' WHERE `subscriber_id`= ' . $suscription->user_id;
     $db->setQuery($query);
     $existingSubcriptionsA = $db->loadObjectList('list_id');
     foreach ($suscription->subscribed as $oneID => $checked) {
         $listID2 = (int) $suscription->sub_list_id[$oneID];
         if (isset($existingSubcriptionsA[$listID2])) {
             if ($existingSubcriptionsA[$listID2]->unsubscribe) {
                 //currently unsubscribed
                 if ($checked) {
                     $listidSubsA[] = $listID2;
                 }
             } else {
                 //already subscribed
                 if (!$checked) {
                     $listidUnsubsA[] = $listID2;
                 }
             }
         } else {
             if ($checked) {
                 $listidSubsA[] = $listID2;
             }
         }
     }
     //endfroeach
     //we check if frontend or not
     if (!$mainframe->isAdmin()) {
         //we check if current subscription is not empty
         if (!empty($listidSubsA)) {
             if (@(include_once JNEWSPATH_ADMIN . 'social' . DS . 'class.social.php')) {
                 //we check if the social class file exists for the implementation of master lists
                 if (class_exists('jNews_Social')) {
                     //we check if configuration for master lists is enabled
                     if ($GLOBALS[JNEWS . 'use_masterlists']) {
                         if ($GLOBALS[JNEWS . 'level'] > 1) {
                             //we validate if the user can be subscribed to the list then we return the masterlistid
                             //1 - MasterLists for all Potential Users
                             $listidSubsA[] = jNews_Social::includeMasterListIds($suscription->user_id, 1, $listidSubsA);
                             //3 - MasterLists for all Registered Subscribers
                             $listidSubsA[] = jNews_Social::includeMasterListIds($suscription->user_id, 2, $listidSubsA);
                         }
                         if ($GLOBALS[JNEWS . 'level'] > 2) {
                             //we validate if the user can be subscribed to the list then we return the masterlistid
                             //3 - MasterLists for all Front-end Subscribers
                             $listidSubsA[] = jNews_Social::includeMasterListIds($suscription->user_id, 3, $listidSubsA);
                         }
                         //we remove here the masterlistids from the $listidUnsubsA
                         //so that masterlist entries won't get updated to unsubscribe
                         foreach ($listidUnsubsA as $key => $lsidunsub) {
                             if (in_array($lsidunsub, $listidSubsA)) {
                                 unset($listidUnsubsA[$key]);
                             }
                         }
                     }
                 }
             }
         }
     }
     //update
     jNews_ListsSubs::_applyChangedSubscription($suscription->user_id, $listidSubsA, $listidUnsubsA);
     $allListsForAR = array();
     if (!empty($listidSubsA)) {
         foreach ($listidSubsA as $id) {
             $allListsForAR[$id] = true;
         }
     }
     if (!empty($listidUnsubsA)) {
         foreach ($listidUnsubsA as $id) {
             $allListsForAR[$id] = false;
         }
     }
     if (empty($allListsForAR)) {
         return true;
     }
     $allListsForARkeysA = array_keys($allListsForAR);
     //we need to separate the ARs from the Lists (From the Subscriptions that were changed)
     $query = 'SELECT `id` FROM `#__jnews_lists` WHERE `list_type`=1 AND `id` IN (' . implode(',', $allListsForARkeysA) . ')';
     $db->setQuery($query);
     $loadResultArray = $db->loadObjectList();
     $listA = jnews::convertObjectList2Array($loadResultArray);
     if (!empty($listA)) {
         $changedARA = array_diff($allListsForARkeysA, $listA);
         //we get the records from  the followup table
         $query = 'SELECT * FROM `#__jnews_followup` WHERE `list_id` IN (' . implode(',', $listA) . ')';
         $db->setQuery($query);
         $followupLists = $db->loadObjectList();
         if (empty($followupLists)) {
             $query = 'SELECT `id` FROM `#__jnews_lists` WHERE `list_type`=2 AND `id` IN (' . implode(',', $allListsForARkeysA) . ')';
             $db->setQuery($query);
             $loadResultArray = $db->loadObjectList();
             $subscribeARA = jnews::convertObjectList2Array($loadResultArray);
             $query = 'SELECT `id` FROM `#__jnews_lists` WHERE `list_type`=2 AND `id` NOT IN (' . implode(',', $allListsForARkeysA) . ')';
             $db->setQuery($query);
             $loadResultArray = $db->loadObjectList();
             $unsubscribeARA = jnews::convertObjectList2Array($loadResultArray);
         } else {
             $subscribeARA = array();
             $unsubscribeARA = array();
             jNews_ListsSubs::_resolveListAndARConflicts($subscribeARA, $unsubscribeARA, $followupLists, $allListsForAR, $changedARA);
         }
     } else {
         $subscribeARA = $listidSubsA;
         $unsubscribeARA = $listidUnsubsA;
     }
     if (!empty($subscribeARA)) {
         jNews_ListsSubs::subscribeARtoQueue($suscription->user_id, $subscribeARA);
     }
     if (!empty($unsubscribeARA)) {
         jNews_ListsSubs::unsubscribeARtoQueue($suscription->user_id, $unsubscribeARA);
     }
     return true;
 }