Пример #1
0
    public function convert_serialize_to_json()
    {
        if (!function_exists('obtain_portal_config')) {
            include $this->phpbb_root_path . 'ext/board3/portal/includes/functions.' . $this->php_ext;
            define('PORTAL_CONFIG_TABLE', $this->table_prefix . 'portal_config');
        }
        $portal_config = obtain_portal_config();
        $sql = 'SELECT module_id, module_classname
			FROM ' . $this->table_prefix . 'portal_modules
			WHERE ' . $this->db->sql_in_set('module_classname', array('\\board3\\portal\\modules\\calendar', '\\board3\\portal\\modules\\links', '\\board3\\portal\\modules\\main_menu'));
        $result = $this->db->sql_query($sql);
        while ($row = $this->db->sql_fetchrow($result)) {
            switch ($row['module_classname']) {
                case '\\board3\\portal\\modules\\calendar':
                    $setting = 'board3_calendar_events_' . $row['module_id'];
                    break;
                case '\\board3\\portal\\modules\\links':
                    $setting = 'board3_links_array_' . $row['module_id'];
                    break;
                case '\\board3\\portal\\modules\\main_menu':
                    $setting = 'board3_menu_array_' . $row['module_id'];
                    break;
                default:
                    // nothing
            }
            // Do not try to unserialize empty data
            if (empty($setting) || empty($portal_config[$setting])) {
                continue;
            }
            // Save json encoded setting
            set_portal_config($setting, json_encode($this->utf_unserialize($portal_config[$setting])));
        }
        $this->db->sql_freeresult($result);
    }
Пример #2
0
$auth->acl($user->data);
$user->setup('mods/portal');

/**
* Make sure we do an isset first, 
* else we will get errors if someone uninstalls the portal and forgets to remove portal.php
*/
if (!isset($config['board3_enable']) || !$config['board3_enable'] || !$auth->acl_get('u_view_portal'))
{
	redirect(append_sid($phpbb_root_path . 'index.' . $phpEx));
}

/**
* get initial data
*/
$portal_config = obtain_portal_config();
$portal_modules = obtain_portal_modules();

/**
* set up column_count array
* with this we can hide unneeded parts of the portal
*/
$module_count = array(
	'total' 	=> 0,
	'top'		=> 0,
	'left'		=> 0,
	'center'	=> 0,
	'right'		=> 0,
	'bottom'	=> 0,
);
Пример #3
0
 /**
  * Reset module settings to default options
  *
  * @param int $id ID of the acp_portal module
  * @param string|int $mode Mode of the acp_portal module
  * @param int $module_id ID of the module that should be reset
  * @param array $module_data Array containing the module's database row
  */
 public function reset_module($id, $mode, $module_id, $module_data)
 {
     if (confirm_box(true)) {
         $module_data = $this->get_move_module_data($module_id);
         $this->get_module($module_data['module_classname']);
         $affected_rows = $this->database_handler->reset_module($this->module, $module_id);
         if (empty($affected_rows)) {
             // We need to return to the module config
             meta_refresh(3, $this->get_module_link('config', $module_id));
             trigger_error($this->user->lang['MODULE_NOT_EXISTS'] . adm_back_link($this->u_action . "&module_id={$module_id}"), E_USER_WARNING);
         }
         $this->cache->destroy('config');
         $this->cache->destroy('portal_config');
         obtain_portal_config();
         // we need to prevent duplicate entry errors
         $this->module->install($module_id);
         $this->cache->purge();
         // We need to return to the module config
         meta_refresh(3, $this->get_module_link('config', $module_id));
         trigger_error($this->user->lang['MODULE_RESET_SUCCESS'] . adm_back_link($this->u_action . "&module_id={$module_id}"));
     } else {
         $confirm_text = isset($this->user->lang[$module_data['module_name']]) ? sprintf($this->user->lang['MODULE_RESET_CONFIRM'], $this->user->lang[$module_data['module_name']]) : sprintf($this->user->lang['DELETE_MODULE_CONFIRM'], utf8_normalize_nfc($module_data['module_name']));
         confirm_box(false, $confirm_text, build_hidden_fields(array('i' => $id, 'mode' => $mode, 'module_reset' => true, 'module_id' => $module_id)));
     }
 }
Пример #4
0
    /**
     * Reset module settings to default options
     *
     * @param int $id ID of the acp_portal module
     * @param string|int $mode Mode of the acp_portal module
     * @param int $module_id ID of the module that should be reset
     * @param array $module_data Array containing the module's database row
     */
    protected function reset_module($id, $mode, $module_id, $module_data)
    {
        if (confirm_box(true)) {
            $sql_ary = array('module_name' => $this->c_class->name, 'module_image_src' => $this->c_class->image_src, 'module_group_ids' => '', 'module_image_height' => 16, 'module_image_width' => 16, 'module_status' => B3_MODULE_ENABLED);
            $sql = 'UPDATE ' . PORTAL_MODULES_TABLE . ' 
					SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' 
					WHERE module_id = ' . (int) $module_id;
            $this->db->sql_query($sql);
            $affected_rows = $this->db->sql_affectedrows();
            if (empty($affected_rows)) {
                // We need to return to the module config
                meta_refresh(3, reapply_sid($this->u_action . "&module_id={$module_id}"));
                trigger_error($this->user->lang['MODULE_NOT_EXISTS'] . adm_back_link($this->u_action . "&module_id={$module_id}"), E_USER_WARNING);
            }
            $this->cache->destroy('config');
            $this->cache->destroy('portal_config');
            $portal_config = obtain_portal_config();
            // we need to prevent duplicate entry errors
            $this->c_class->install($module_id);
            $this->cache->purge();
            // We need to return to the module config
            meta_refresh(3, reapply_sid($this->u_action . "&module_id={$module_id}"));
            trigger_error($this->user->lang['MODULE_RESET_SUCCESS'] . adm_back_link($this->u_action . "&module_id={$module_id}"));
        } else {
            $confirm_text = isset($this->user->lang[$module_data['module_name']]) ? sprintf($this->user->lang['MODULE_RESET_CONFIRM'], $this->user->lang[$module_data['module_name']]) : sprintf($this->user->lang['DELETE_MODULE_CONFIRM'], utf8_normalize_nfc($module_data['module_name']));
            confirm_box(false, $confirm_text, build_hidden_fields(array('i' => $id, 'mode' => $mode, 'module_reset' => true, 'module_id' => $module_id)));
        }
    }
Пример #5
0
    /**
     * Manage events
     *
     * @param mixed $value Value of input
     * @param string $key Key name
     * @param int $module_id Module ID
     *
     * @return null
     */
    public function manage_events($value, $key, $module_id)
    {
        $action = $this->request->variable('action', '');
        $action = $this->request->is_set_post('add') ? 'add' : $action;
        $action = $this->request->is_set_post('save') ? 'save' : $action;
        $link_id = $this->request->variable('id', 99999999);
        // 0 will trigger unwanted behavior, therefore we set a number we should never reach
        $portal_config = obtain_portal_config();
        $events = strlen($portal_config['board3_calendar_events_' . $module_id]) >= 1 ? json_decode($portal_config['board3_calendar_events_' . $module_id], true) : array();
        // append_sid() adds adm/ already, no need to add it here
        $u_action = append_sid('index.' . $this->php_ext, 'i=-board3-portal-acp-portal_module&mode=config&module_id=' . $module_id);
        switch ($action) {
            // Save changes
            case 'save':
                if (!check_form_key('acp_portal')) {
                    trigger_error($this->user->lang['FORM_INVALID'] . adm_back_link($u_action), E_USER_WARNING);
                }
                $event_title = $this->request->variable('event_title', '', true);
                $event_desc = $this->request->variable('event_desc', '', true);
                $event_start_date = trim($this->request->variable('event_start_date', ''));
                $event_end_date = trim($this->request->variable('event_end_date', ''));
                $event_all_day = $this->request->variable('event_all_day', false);
                // default to false
                $event_url = $this->request->variable('event_url', '');
                $event_permission = $this->request->variable('permission-setting-calendar', array(0 => ''));
                $groups_ary = array();
                // Now get the unix timestamps out of the entered information
                $start_time = $this->date_to_time($event_start_date);
                $end_time = !$event_all_day ? $this->date_to_time($event_end_date) : '';
                if (!$start_time) {
                    trigger_error($this->user->lang['ACP_PORTAL_CALENDAR_START_INCORRECT'] . adm_back_link($u_action), E_USER_WARNING);
                } else {
                    if (!$event_all_day && !$end_time) {
                        trigger_error($this->user->lang['ACP_PORTAL_CALENDAR_END_INCORRECT'] . adm_back_link($u_action), E_USER_WARNING);
                    }
                }
                if ($end_time <= time() && !($start_time + self::TIME_DAY >= time() && $event_all_day)) {
                    trigger_error($this->user->lang['ACP_PORTAL_CALENDAR_EVENT_PAST'] . adm_back_link($u_action), E_USER_WARNING);
                } else {
                    if ($end_time < $start_time && !$event_all_day) {
                        trigger_error($this->user->lang['ACP_PORTAL_CALENDAR_EVENT_START_FIRST'] . adm_back_link($u_action), E_USER_WARNING);
                    }
                }
                // get groups and check if the selected groups actually exist
                $sql = 'SELECT group_id
						FROM ' . GROUPS_TABLE . '
						ORDER BY group_id ASC';
                $result = $this->db->sql_query($sql);
                while ($row = $this->db->sql_fetchrow($result)) {
                    $groups_ary[] = $row['group_id'];
                }
                $this->db->sql_freeresult($result);
                $event_permission = array_intersect($event_permission, $groups_ary);
                $event_permission = implode(',', $event_permission);
                // Check for errors
                if (!$event_title) {
                    trigger_error($this->user->lang['NO_EVENT_TITLE'] . adm_back_link($u_action), E_USER_WARNING);
                }
                // overwrite already existing events and make sure we don't try to save an event outside of the normal array size of $events
                if (isset($link_id) && $link_id < sizeof($events)) {
                    $message = $this->user->lang['EVENT_UPDATED'];
                    $events[$link_id] = array('title' => $event_title, 'desc' => $event_desc, 'start_time' => $start_time, 'end_time' => $end_time, 'all_day' => $event_all_day, 'permission' => $event_permission, 'url' => htmlspecialchars_decode($event_url));
                    $this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_PORTAL_EVENT_UPDATED', false, array($event_title));
                } else {
                    $message = $this->user->lang['EVENT_ADDED'];
                    $events[] = array('title' => $event_title, 'desc' => $event_desc, 'start_time' => $start_time, 'end_time' => $end_time, 'all_day' => $event_all_day, 'permission' => $event_permission, 'url' => $event_url);
                    $this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_PORTAL_EVENT_ADDED', false, array($event_title));
                }
                $time_ary = array();
                // we sort the $events array by the start time
                foreach ($events as $key => $cur_event) {
                    $time_ary[$key] = $cur_event['start_time'];
                }
                array_multisort($time_ary, SORT_NUMERIC, $events);
                $board3_events_array = json_encode($events);
                set_portal_config('board3_calendar_events_' . $module_id, $board3_events_array);
                trigger_error($message . adm_back_link($u_action));
                break;
                // Delete link
            // Delete link
            case 'delete':
                if (!isset($link_id) && $link_id >= sizeof($events)) {
                    trigger_error($this->user->lang['NO_EVENT'] . adm_back_link($u_action), E_USER_WARNING);
                }
                if (confirm_box(true)) {
                    $cur_event_title = $events[$link_id]['title'];
                    // delete the selected link and reset the array numbering afterwards
                    array_splice($events, $link_id, 1);
                    $events = array_merge($events);
                    $board3_events_array = json_encode($events);
                    set_portal_config('board3_calendar_events_' . $module_id, $board3_events_array);
                    $this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_PORTAL_EVENT_REMOVED', false, array($cur_event_title));
                } else {
                    confirm_box(false, $this->user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('link_id' => $link_id, 'action' => 'delete')));
                }
                break;
                // Edit or add menu item
            // Edit or add menu item
            case 'edit':
            case 'add':
                $event_all_day = isset($events[$link_id]['all_day']) && $events[$link_id]['all_day'] == true ? true : false;
                $date_format = str_replace(array('D '), '', $this->user->data['user_dateformat']);
                $this->template->assign_vars(array('EVENT_TITLE' => isset($events[$link_id]['title']) && $action != 'add' ? $events[$link_id]['title'] : '', 'EVENT_DESC' => isset($events[$link_id]['desc']) && $action != 'add' ? $events[$link_id]['desc'] : '', 'EVENT_START_DATE' => $action != 'add' ? $this->user->format_date($events[$link_id]['start_time'], $date_format) : '', 'EVENT_END_DATE' => $action != 'add' && !$event_all_day ? $this->user->format_date($events[$link_id]['end_time'], $date_format) : '', 'EVENT_ALL_DAY' => isset($events[$link_id]['all_day']) && $events[$link_id]['all_day'] == true ? true : false, 'EVENT_URL' => isset($events[$link_id]['url']) && $action != 'add' ? $events[$link_id]['url'] : '', 'B3P_U_ACTION' => $u_action . '&amp;id=' . $link_id, 'S_EDIT' => true));
                $groups_ary = isset($events[$link_id]['permission']) ? explode(',', $events[$link_id]['permission']) : array();
                // get group info from database and assign the block vars
                $sql = 'SELECT group_id, group_name
						FROM ' . GROUPS_TABLE . '
						ORDER BY group_id ASC';
                $result = $this->db->sql_query($sql);
                while ($row = $this->db->sql_fetchrow($result)) {
                    $this->template->assign_block_vars('permission_setting_calendar', array('SELECTED' => in_array($row['group_id'], $groups_ary) ? true : false, 'GROUP_NAME' => isset($this->user->lang['G_' . $row['group_name']]) ? $this->user->lang['G_' . $row['group_name']] : $row['group_name'], 'GROUP_ID' => $row['group_id']));
                }
                $this->db->sql_freeresult($result);
                return;
        }
        for ($i = 0; $i < sizeof($events); $i++) {
            $event_all_day = $events[$i]['all_day'] == true ? true : false;
            $this->template->assign_block_vars('events', array('EVENT_TITLE' => $action != 'add' ? isset($this->user->lang[$events[$i]['title']]) ? $this->user->lang[$events[$i]['title']] : $events[$i]['title'] : '', 'EVENT_DESC' => $action != 'add' ? $events[$i]['desc'] : '', 'EVENT_START' => $action != 'add' ? $this->user->format_date($events[$i]['start_time']) : '', 'EVENT_END' => $action != 'add' && !$event_all_day && !empty($end_time_format) ? $this->user->format_date($events[$i]['end_time']) : '', 'EVENT_URL' => $action != 'add' && isset($events[$i]['url']) && !empty($events[$i]['url']) ? $this->validate_url($events[$i]['url']) : '', 'EVENT_URL_RAW' => $action != 'add' && isset($events[$i]['url']) && !empty($events[$i]['url']) ? $events[$i]['url'] : '', 'U_EDIT' => $u_action . '&amp;action=edit&amp;id=' . $i, 'U_DELETE' => $u_action . '&amp;action=delete&amp;id=' . $i, 'EVENT_ALL_DAY' => $event_all_day));
        }
    }
Пример #6
0
	public function manage_links($value, $key, $module_id)
	{
		global $config, $phpbb_admin_path, $user, $phpEx, $db, $template;

		$action = request_var('action', '');
		$action = (isset($_POST['add'])) ? 'add' : $action;
		$action = (isset($_POST['save'])) ? 'save' : $action;
		$link_id = request_var('id', 99999999); // 0 will trigger unwanted behavior, therefore we set a number we should never reach
		$portal_config = obtain_portal_config();

		$links = array();

		$links = $this->utf_unserialize($portal_config['board3_menu_array_' . $module_id]);

		$u_action = append_sid($phpbb_admin_path . 'index.' . $phpEx, 'i=portal&amp;mode=config&amp;module_id=' . $module_id);

		switch ($action)
		{
			// Save changes
			case 'save':
				if (!check_form_key('acp_portal'))
				{
					trigger_error($user->lang['FORM_INVALID']. adm_back_link($u_action), E_USER_WARNING);
				}

				$link_title = utf8_normalize_nfc(request_var('link_title', ' ', true));
				$link_is_cat = request_var('link_is_cat', false);
				$link_type = (!$link_is_cat) ? request_var('link_type', self::LINK_INT) : self::LINK_CAT;
				$link_url = ($link_is_cat) ? ' ' : utf8_normalize_nfc(request_var('link_url', ' ', true));
				$link_url = str_replace('&amp;', '&', $link_url);
				$link_permission = request_var('permission-setting-menu', array(0 => ''));
				$groups_ary = array();

				// get groups and check if the selected groups actually exist
				$sql = 'SELECT group_id
						FROM ' . GROUPS_TABLE . '
						ORDER BY group_id ASC';
				$result = $db->sql_query($sql);
				while($row = $db->sql_fetchrow($result))
				{
					$groups_ary[] = $row['group_id'];
				}
				$db->sql_freeresult($result);

				$link_permissions = array_intersect($link_permission, $groups_ary);
				$link_permissions = implode(',', $link_permissions);

				// Check for errors
				if (!$link_title)
				{
					trigger_error($user->lang['NO_LINK_TITLE'] . adm_back_link($u_action), E_USER_WARNING);
				}

				if (!$link_is_cat && !$link_url)
				{
					trigger_error($user->lang['NO_LINK_URL'] . adm_back_link($u_action), E_USER_WARNING);
				}

				// overwrite already existing links and make sure we don't try to save a link outside of the normal array size of $links
				if (isset($link_id) && $link_id < sizeof($links))
				{
					$message = $user->lang['LINK_UPDATED'];

					$links[$link_id] = array(
						'title' 		=> $link_title,
						'url'			=> htmlspecialchars_decode($link_url),
						'type'			=> $link_type,
						'permission'	=> $link_permissions,
					);

					add_log('admin', 'LOG_PORTAL_LINK_UPDATED', $link_title);
				}
				else
				{
					$message = $user->lang['LINK_ADDED'];

					if($link_type != self::LINK_CAT && sizeof($links) < 1)
					{
						trigger_error($user->lang['ACP_PORTAL_MENU_CREATE_CAT'] . adm_back_link($u_action), E_USER_WARNING);
					}
					$links[] = array(
						'title' 		=> $link_title,
						'url'			=> htmlspecialchars_decode($link_url),
						'type'			=> $link_type,
						'permission'	=> $link_permissions,
					);
					add_log('admin', 'LOG_PORTAL_LINK_ADDED', $link_title);
				}

				$board3_menu_array = serialize($links);
				set_portal_config('board3_menu_array_' . $module_id, $board3_menu_array);

				trigger_error($message . adm_back_link($u_action));

			break;

			// Delete link
			case 'delete':

				if (!isset($link_id) && $link_id >= sizeof($links))
				{
					trigger_error($user->lang['MUST_SELECT_LINK'] . adm_back_link($u_action), E_USER_WARNING);
				}

				if (confirm_box(true))
				{
					$cur_link_title = $links[$link_id]['title'];
					// delete the selected link and reset the array numbering afterwards
					array_splice($links, $link_id, 1);
					$links = array_merge($links);

					$board3_menu_array = serialize($links);
					set_portal_config('board3_menu_array_' . $module_id, $board3_menu_array);

					add_log('admin', 'LOG_PORTAL_LINK_REMOVED', $cur_link_title);
				}
				else
				{
					confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
						'link_id'	=> $link_id,
						'action'	=> 'delete',
					)));
				}

			break;

			// Move items up or down
			case 'move_up':
			case 'move_down':

				if (!isset($link_id) && $link_id >= sizeof($links))
				{
					trigger_error($user->lang['MUST_SELECT_LINK'] . adm_back_link($u_action), E_USER_WARNING);
				}

				// make sure we don't try to move a link where it can't be moved
				if (($link_id == 0 && $action == 'move_up') || ($link_id == (sizeof($links) - 1) && $action == 'move_down'))
				{
					break;
				}

				/* 
				* on move_down, switch position with next order_id...
				* on move_up, switch position with previous order_id...
				* move up means a lower ID, move down means a higher ID
				*/
				$switch_order_id = ($action == 'move_down') ? $link_id + 1 : $link_id - 1;

				// back up the info of the link we want to move
				$cur_link = array(
					'title' 		=> $links[$link_id]['title'],
					'url'			=> $links[$link_id]['url'],
					'type'			=> $links[$link_id]['type'],
					'permission'	=> $links[$link_id]['permission'],
				);

				// move the info of the links we replace in the order
				$links[$link_id] = array(
					'title'			=> $links[$switch_order_id]['title'],
					'url'			=> $links[$switch_order_id]['url'],
					'type'			=> $links[$switch_order_id]['type'],
					'permission'	=> $links[$switch_order_id]['permission'],
				);

				// insert the info of the moved link
				$links[$switch_order_id] = $cur_link;

				$board3_menu_array = serialize($links);
				set_portal_config('board3_menu_array_' . $module_id, $board3_menu_array);

			break;

			// Edit or add menu item
			case 'edit':
			case 'add':
				$template->assign_vars(array(
					'LINK_TITLE'	=> (isset($links[$link_id]['title']) && $action != 'add') ? $links[$link_id]['title'] : '',
					'LINK_URL'		=> (isset($links[$link_id]['url']) && $links[$link_id]['type'] != self::LINK_CAT && $action != 'add') ? str_replace('&', '&amp;', $links[$link_id]['url']) : '',

					//'U_BACK'	=> $u_action,
					'U_ACTION'	=> $u_action . '&amp;id=' . $link_id,

					'S_EDIT'				=> true,
					'S_LINK_IS_CAT'			=> (!isset($links[$link_id]['type']) || $links[$link_id]['type'] == self::LINK_CAT) ? true : false,
					'S_LINK_IS_INT'			=> (isset($links[$link_id]['type']) && $links[$link_id]['type'] == self::LINK_INT) ? true : false,
				));

				$groups_ary = (isset($links[$link_id]['permission'])) ? explode(',', $links[$link_id]['permission']) : array();

				// get group info from database and assign the block vars
				$sql = 'SELECT group_id, group_name 
						FROM ' . GROUPS_TABLE . '
						ORDER BY group_id ASC';
				$result = $db->sql_query($sql);
				while($row = $db->sql_fetchrow($result))
				{
					$template->assign_block_vars('permission_setting_menu', array(
						'SELECTED'		=> (in_array($row['group_id'], $groups_ary)) ? true : false,
						'GROUP_NAME'	=> (isset($user->lang['G_' . $row['group_name']])) ? $user->lang['G_' . $row['group_name']] : $row['group_name'],
						'GROUP_ID'		=> $row['group_id'],
					));
				}
				$db->sql_freeresult($result);

				return;

			break;
		}

		for ($i = 0; $i < sizeof($links); $i++)
		{
			$template->assign_block_vars('links', array(
				'LINK_TITLE'	=> ($action != 'add') ? ((isset($user->lang[$links[$i]['title']])) ? $user->lang[$links[$i]['title']] : $links[$i]['title']) : '',
				'LINK_URL'		=> ($action != 'add') ? str_replace('&', '&amp;', $links[$i]['url']) : '',

				'U_EDIT'		=> $u_action . '&amp;action=edit&amp;id=' . $i,
				'U_DELETE'		=> $u_action . '&amp;action=delete&amp;id=' . $i,
				'U_MOVE_UP'		=> $u_action . '&amp;action=move_up&amp;id=' . $i,
				'U_MOVE_DOWN'	=> $u_action . '&amp;action=move_down&amp;id=' . $i,

				'S_LINK_IS_CAT'	=> ($links[$i]['type'] == self::LINK_CAT) ? true : false,
			));
		}
	}
Пример #7
0
	public function manage_events($value, $key, $module_id)
	{
		global $db, $portal_config, $config, $template, $user, $phpEx, $phpbb_admin_path;

		$action = request_var('action', '');
		$action = (isset($_POST['add'])) ? 'add' : $action;
		$action = (isset($_POST['save'])) ? 'save' : $action;
		$link_id = request_var('id', 99999999); // 0 will trigger unwanted behavior, therefore we set a number we should never reach
		$portal_config = obtain_portal_config();

		$events = (strlen($portal_config['board3_calendar_events_' . $module_id]) >= 1) ? $this->utf_unserialize($portal_config['board3_calendar_events_' . $module_id]) : array();

		$u_action = append_sid($phpbb_admin_path . 'index.' . $phpEx, 'i=portal&amp;mode=config&amp;module_id=' . $module_id);

		switch($action)
		{
			// Save changes
			case 'save':
				if (!check_form_key('acp_portal'))
				{
					trigger_error($user->lang['FORM_INVALID']. adm_back_link($u_action), E_USER_WARNING);
				}

				$event_title = utf8_normalize_nfc(request_var('event_title', ' ', true));
				$event_desc = utf8_normalize_nfc(request_var('event_desc', ' ', true));
				$event_start_day = trim(request_var('event_start_day', ''));
				$event_start_time = trim(request_var('event_start_time', ''));
				$event_end_day = trim(request_var('event_end_day', ''));
				$event_end_time = trim(request_var('event_end_time', ''));
				$event_all_day = request_var('event_all_day', false); // default to false
				$event_url = request_var('event_url', ' ');
				$event_permission = request_var('permission-setting-calendar', array(0 => ''));
				$groups_ary = array();

				/* 
				* parse the event time
				* first check for obvious errors, we don't want to waste server resources
				*/
				if(strlen($event_start_day) < 9 || strlen($event_start_day) > 10 || (strlen($event_start_time) < 4 && !$event_all_day) || strlen($event_start_time) > 5)
				{
					trigger_error($user->lang['ACP_PORTAL_CALENDAR_START_INCORRECT']. adm_back_link($u_action), E_USER_WARNING);
				}
				elseif((strlen($event_end_day) < 9 || strlen($event_end_day) > 10 || strlen($event_end_time) < 4 || strlen($event_end_time) > 5) && !$event_all_day)
				{
					trigger_error($user->lang['ACP_PORTAL_CALENDAR_END_INCORRECT']. adm_back_link($u_action), E_USER_WARNING);
				}
				// Now get the needed numbers out of the entered information
				$first_start_hyphen = strpos($event_start_day, '-', 0);
				$second_start_hyphen = strpos($event_start_day, '-', $first_start_hyphen + 1);
				$start_colon_pos = strpos($event_start_time, ':', 0);
				$start_day_length = strlen($event_start_day);
				$start_time_length = strlen($event_start_time);
				$start_day = (int) substr($event_start_day, 0, $first_start_hyphen);
				$start_month =  (int) substr($event_start_day, $first_start_hyphen + 1, ($second_start_hyphen - $first_start_hyphen - 1));
				$start_year = (int) substr($event_start_day, $second_start_hyphen + 1, $start_day_length - $second_start_hyphen);
				$start_hour = (int) substr($event_start_time, 0, $start_colon_pos);
				$start_minute = (int) substr($event_start_time, $start_colon_pos + 1, ($start_time_length - $start_colon_pos) - 1);

				if(!$event_all_day)
				{
					$first_end_hyphen = strpos($event_end_day, '-', 0);
					$second_end_hyphen = strpos($event_end_day, '-', $first_end_hyphen + 1);
					$end_colon_pos = strpos($event_end_time, ':', 0);
					$end_day_length = strlen($event_end_day);
					$end_time_length = strlen($event_end_time);
					$end_day = (int) substr($event_end_day, 0, $first_end_hyphen);
					$end_month = (int) substr($event_end_day, $first_end_hyphen + 1, ($second_end_hyphen - $first_end_hyphen - 1));
					$end_year = (int) substr($event_end_day, $second_end_hyphen + 1, $end_day_length - $second_end_hyphen);
					$end_hour = (int) substr($event_end_time, 0, $end_colon_pos);
					$end_minute = (int) substr($event_end_time, $end_colon_pos + 1, ($end_time_length - $end_colon_pos) - 1);
				}

				// UNIX timestamps
				$start_time = gmmktime($start_hour, $start_minute, 0, $start_month, $start_day, $start_year) - $user->timezone - $user->dst;
				$end_time = (!$event_all_day) ? gmmktime($end_hour, $end_minute, 0, $end_month, $end_day, $end_year) - $user->timezone - $user->dst : '';

				if(($end_time) <= time() && !(($start_time + self::TIME_DAY) >= time() && $event_all_day))
				{
					trigger_error($user->lang['ACP_PORTAL_CALENDAR_EVENT_PAST']. adm_back_link($u_action), E_USER_WARNING);
				}
				elseif($end_time < $start_time && !$event_all_day)
				{
					trigger_error($user->lang['ACP_PORTAL_CALENDAR_EVENT_START_FIRST']. adm_back_link($u_action), E_USER_WARNING);
				}

				// get groups and check if the selected groups actually exist
				$sql = 'SELECT group_id
						FROM ' . GROUPS_TABLE . '
						ORDER BY group_id ASC';
				$result = $db->sql_query($sql);
				while($row = $db->sql_fetchrow($result))
				{
					$groups_ary[] = $row['group_id'];
				}
				$db->sql_freeresult($result);

				$event_permission = array_intersect($event_permission, $groups_ary);
				$event_permission = implode(',', $event_permission);

				// Check for errors
				if (!$event_title)
				{
					trigger_error($user->lang['NO_EVENT_TITLE'] . adm_back_link($u_action), E_USER_WARNING);
				}

				if (!$start_time || $start_time == 0)
				{
					trigger_error($user->lang['NO_EVENT_START'] . adm_back_link($u_action), E_USER_WARNING);
				}

				// overwrite already existing events and make sure we don't try to save an event outside of the normal array size of $events
				if (isset($link_id) && $link_id < sizeof($events))
				{
					$message = $user->lang['EVENT_UPDATED'];

					$events[$link_id] = array(
						'title' 		=> $event_title,
						'desc'			=> $event_desc,
						'start_time'	=> $start_time,
						'end_time'		=> $end_time,
						'all_day'		=> $event_all_day,
						'permission'	=> $event_permission,
						'url'			=> htmlspecialchars_decode($event_url),
					);

					add_log('admin', 'LOG_PORTAL_EVENT_UPDATED', $event_title);
				}
				else
				{
					$message = $user->lang['EVENT_ADDED'];

					$events[] = array(
						'title'			=> $event_title,
						'desc'			=> $event_desc,
						'start_time'	=> $start_time,
						'end_time'		=> $end_time,
						'all_day'		=> $event_all_day,
						'permission'	=> $event_permission,
						'url'			=> $event_url, // optional
					);
					add_log('admin', 'LOG_PORTAL_EVENT_ADDED', $event_title);
				}

				// we sort the $events array by the start time
				foreach($events as $key => $cur_event)
				{
					$time_ary[$key] = $cur_event['start_time'];
				}
				array_multisort($time_ary, SORT_NUMERIC, $events);
				$board3_events_array = serialize($events);
				set_portal_config('board3_calendar_events_' . $module_id, $board3_events_array);

				trigger_error($message . adm_back_link($u_action));

			break;

			// Delete link
			case 'delete':

				if (!isset($link_id) && $link_id >= sizeof($events))
				{
					trigger_error($user->lang['NO_EVENT'] . adm_back_link($u_action), E_USER_WARNING);
				}

				if (confirm_box(true))
				{
					$cur_event_title = $events[$link_id]['title'];
					// delete the selected link and reset the array numbering afterwards
					array_splice($events, $link_id, 1);
					$events = array_merge($events);

					$board3_events_array = serialize($events);
					set_portal_config('board3_calendar_events_' . $module_id, $board3_events_array);

					add_log('admin', 'LOG_PORTAL_EVENT_REMOVED', $cur_event_title);
				}
				else
				{
					confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
						'link_id'	=> $link_id,
						'action'	=> 'delete',
					)));
				}

			break;

			// Edit or add menu item
			case 'edit':
			case 'add':
				$event_all_day = (isset($events[$link_id]['all_day']) && $events[$link_id]['all_day'] == true) ? true : false;

				$template->assign_vars(array(
					'EVENT_TITLE'		=> (isset($events[$link_id]['title']) && $action != 'add') ? $events[$link_id]['title'] : '',
					'EVENT_DESC'		=> (isset($events[$link_id]['desc']) && $action != 'add') ? $events[$link_id]['desc'] : '',
					'EVENT_START_DAY'	=> ($action != 'add') ? $user->format_date($events[$link_id]['start_time'], 'd-m-Y') : '',
					'EVENT_START_TIME'	=> ($action != 'add') ? $user->format_date($events[$link_id]['start_time'], 'G:i') : '',
					'EVENT_END_DAY'		=> ($action != 'add' && !$event_all_day) ? $user->format_date($events[$link_id]['end_time'], 'd-m-Y') : '',
					'EVENT_END_TIME'	=> ($action != 'add' && !$event_all_day) ? $user->format_date($events[$link_id]['end_time'], 'G:i') : '',
					'EVENT_ALL_DAY'		=> (isset($events[$link_id]['all_day']) && $events[$link_id]['all_day'] == true) ? true : false,
					'EVENT_URL'			=> (isset($events[$link_id]['url']) && $action != 'add') ? $events[$link_id]['url'] : '',

					//'U_BACK'	=> $u_action,
					'U_ACTION'	=> $u_action . '&amp;id=' . $link_id,

					'S_EDIT'				=> true,
				));

				$groups_ary = (isset($events[$link_id]['permission'])) ? explode(',', $events[$link_id]['permission']) : array();

				// get group info from database and assign the block vars
				$sql = 'SELECT group_id, group_name 
						FROM ' . GROUPS_TABLE . '
						ORDER BY group_id ASC';
				$result = $db->sql_query($sql);
				while($row = $db->sql_fetchrow($result))
				{
					$template->assign_block_vars('permission_setting_calendar', array(
						'SELECTED'		=> (in_array($row['group_id'], $groups_ary)) ? true : false,
						'GROUP_NAME'	=> (isset($user->lang['G_' . $row['group_name']])) ? $user->lang['G_' . $row['group_name']] : $row['group_name'],
						'GROUP_ID'		=> $row['group_id'],
					));
				}
				$db->sql_freeresult($result);

				return;

			break;		
		}

		for ($i = 0; $i < sizeof($events); $i++)
		{
			$event_all_day = ($events[$i]['all_day'] == true) ? true : false;
			$start_time_format = (!intval($user->format_date($events[$i]['start_time'], 'H')) && !intval($user->format_date($events[$i]['start_time'], 'i'))) ? 'j. M Y' : 'j. M Y, H:i';
			$end_time_format = (!intval($user->format_date($events[$i]['end_time'], 'H')) && !intval($user->format_date($events[$i]['end_time'], 'i'))) ? 'j. M Y' : 'j. M Y, H:i';

			$template->assign_block_vars('events', array(
				'EVENT_TITLE'	=> ($action != 'add') ? ((isset($user->lang[$events[$i]['title']])) ? $user->lang[$events[$i]['title']] : $events[$i]['title']) : '',
				'EVENT_DESC'	=> ($action != 'add') ? $events[$i]['desc'] : '',
				'EVENT_START'	=> ($action != 'add') ? $user->format_date($events[$i]['start_time'], $start_time_format) : '',
				'EVENT_END'		=> ($action != 'add' && !$event_all_day) ? $user->format_date($events[$i]['end_time'], $end_time_format) : '',
				'EVENT_URL'		=> ($action != 'add' && isset($events[$i]['url']) && !empty($events[$i]['url'])) ? $this->validate_url($events[$i]['url']) : '',
				'EVENT_URL_RAW'	=> ($action != 'add' && isset($events[$i]['url']) && !empty($events[$i]['url'])) ? $events[$i]['url'] : '',
				'U_EDIT'		=> $u_action . '&amp;action=edit&amp;id=' . $i,
				'U_DELETE'		=> $u_action . '&amp;action=delete&amp;id=' . $i,
				'EVENT_ALL_DAY'	=> $event_all_day,
			));
		}

	}
Пример #8
0
    /**
     * Manage the links
     *
     * @param mixed $value Value of input
     * @param string $key Key name
     * @param int $module_id Module ID
     *
     * @return null
     */
    public function manage_links($value, $key, $module_id)
    {
        $action = $this->request->variable('action', '');
        $action = $this->request->is_set_post('add') ? 'add' : $action;
        $action = $this->request->is_set_post('save') ? 'save' : $action;
        $link_id = $this->request->variable('id', 99999999);
        // 0 will trigger unwanted behavior, therefore we set a number we should never reach
        $portal_config = obtain_portal_config();
        $links = json_decode($portal_config['board3_links_array_' . $module_id], true);
        $u_action = append_sid('index.' . $this->php_ext, 'i=-board3-portal-acp-portal_module&amp;mode=config&amp;module_id=' . $module_id);
        switch ($action) {
            // Save changes
            case 'save':
                if (!check_form_key('acp_portal')) {
                    trigger_error($this->user->lang['FORM_INVALID'] . adm_back_link($u_action), E_USER_WARNING);
                }
                $link_title = $this->request->variable('link_title', ' ', true);
                $link_type = $this->request->variable('link_type', 2);
                // default to B3_LINK_EXT, no categories in Links block
                $link_url = $this->request->variable('link_url', ' ', true);
                $link_url = str_replace('&amp;', '&', $link_url);
                $link_permission = $this->request->variable('permission-setting-link', array(0 => ''));
                $groups_ary = array();
                // get groups and check if the selected groups actually exist
                $sql = 'SELECT group_id
						FROM ' . GROUPS_TABLE . '
						ORDER BY group_id ASC';
                $result = $this->db->sql_query($sql);
                while ($row = $this->db->sql_fetchrow($result)) {
                    $groups_ary[] = $row['group_id'];
                }
                $this->db->sql_freeresult($result);
                $link_permissions = array_intersect($link_permission, $groups_ary);
                $link_permissions = implode(',', $link_permissions);
                // Check for errors
                if (!$link_title) {
                    trigger_error($this->user->lang['NO_LINK_TITLE'] . adm_back_link($u_action), E_USER_WARNING);
                }
                if (!$link_url) {
                    trigger_error($this->user->lang['NO_LINK_URL'] . adm_back_link($u_action), E_USER_WARNING);
                }
                // overwrite already existing links and make sure we don't try to save a link outside of the normal array size of $links
                if (isset($link_id) && $link_id < sizeof($links)) {
                    $message = $this->user->lang['LINK_UPDATED'];
                    $links[$link_id] = array('title' => $link_title, 'url' => htmlspecialchars_decode($link_url), 'type' => $link_type, 'permission' => $link_permissions);
                    $this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_PORTAL_LINK_UPDATED', false, array($link_title));
                } else {
                    $message = $this->user->lang['LINK_ADDED'];
                    $links[] = array('title' => $link_title, 'url' => htmlspecialchars_decode($link_url), 'type' => $link_type, 'permission' => $link_permissions);
                    $this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_PORTAL_LINK_ADDED', false, array($link_title));
                }
                $board3_links_array = json_encode($links);
                set_portal_config('board3_links_array_' . $module_id, $board3_links_array);
                trigger_error($message . adm_back_link($u_action));
                break;
                // Delete link
            // Delete link
            case 'delete':
                if (!isset($link_id) && $link_id >= sizeof($links)) {
                    trigger_error($this->user->lang['MUST_SELECT_LINK'] . adm_back_link($u_action), E_USER_WARNING);
                }
                if (confirm_box(true)) {
                    $cur_link_title = $links[$link_id]['title'];
                    // delete the selected link and reset the array numbering afterwards
                    array_splice($links, $link_id, 1);
                    $links = array_merge($links);
                    $board3_links_array = json_encode($links);
                    set_portal_config('board3_links_array_' . $module_id, $board3_links_array);
                    $this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_PORTAL_LINK_REMOVED', false, array($cur_link_title));
                } else {
                    confirm_box(false, $this->user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('link_id' => $link_id, 'action' => 'delete')));
                }
                break;
                // Move items up or down
            // Move items up or down
            case 'move_up':
            case 'move_down':
                if (!isset($link_id) && $link_id >= sizeof($links)) {
                    trigger_error($this->user->lang['MUST_SELECT_LINK'] . adm_back_link($u_action), E_USER_WARNING);
                }
                // make sure we don't try to move a link where it can't be moved
                if ($link_id == 0 && $action == 'move_up' || $link_id == sizeof($links) - 1 && $action == 'move_down') {
                    break;
                }
                /*
                 * on move_down, switch position with next order_id...
                 * on move_up, switch position with previous order_id...
                 * move up means a lower ID, move down means a higher ID
                 */
                $switch_order_id = $action == 'move_down' ? $link_id + 1 : $link_id - 1;
                // back up the info of the link we want to move
                $cur_link = array('title' => $links[$link_id]['title'], 'url' => $links[$link_id]['url'], 'type' => $links[$link_id]['type'], 'permission' => $links[$link_id]['permission']);
                // move the info of the links we replace in the order
                $links[$link_id] = array('title' => $links[$switch_order_id]['title'], 'url' => $links[$switch_order_id]['url'], 'type' => $links[$switch_order_id]['type'], 'permission' => $links[$switch_order_id]['permission']);
                // insert the info of the moved link
                $links[$switch_order_id] = $cur_link;
                $board3_links_array = json_encode($links);
                set_portal_config('board3_links_array_' . $module_id, $board3_links_array);
                break;
                // Edit or add menu item
            // Edit or add menu item
            case 'edit':
            case 'add':
                $this->template->assign_vars(array('LINK_TITLE' => isset($links[$link_id]['title']) && $action != 'add' ? $links[$link_id]['title'] : '', 'LINK_URL' => isset($links[$link_id]['url']) && $action != 'add' ? str_replace('&', '&amp;', $links[$link_id]['url']) : '', 'S_EDIT' => true, 'S_LINK_IS_INT' => isset($links[$link_id]['type']) && $links[$link_id]['type'] == self::LINK_INT ? true : false, 'LINK_ID' => $link_id));
                $groups_ary = isset($links[$link_id]['permission']) ? explode(',', $links[$link_id]['permission']) : array();
                // get group info from database and assign the block vars
                $sql = 'SELECT group_id, group_name 
						FROM ' . GROUPS_TABLE . '
						ORDER BY group_id ASC';
                $result = $this->db->sql_query($sql);
                while ($row = $this->db->sql_fetchrow($result)) {
                    $this->template->assign_block_vars('permission_setting_link', array('SELECTED' => in_array($row['group_id'], $groups_ary) ? true : false, 'GROUP_NAME' => isset($this->user->lang['G_' . $row['group_name']]) ? $this->user->lang['G_' . $row['group_name']] : $row['group_name'], 'GROUP_ID' => $row['group_id']));
                }
                $this->db->sql_freeresult($result);
                return;
        }
        for ($i = 0; $i < sizeof($links); $i++) {
            $this->template->assign_block_vars('links', array('LINK_TITLE' => $action != 'add' ? isset($this->user->lang[$links[$i]['title']]) ? $this->user->lang[$links[$i]['title']] : $links[$i]['title'] : '', 'LINK_URL' => $action != 'add' ? str_replace('&', '&amp;', $links[$i]['url']) : '', 'U_EDIT' => $u_action . '&amp;action=edit&amp;id=' . $i, 'U_DELETE' => $u_action . '&amp;action=delete&amp;id=' . $i, 'U_MOVE_UP' => $u_action . '&amp;action=move_up&amp;id=' . $i, 'U_MOVE_DOWN' => $u_action . '&amp;action=move_down&amp;id=' . $i));
        }
    }
Пример #9
0
	public function manage_welcome($value, $key, $module_id)
	{
		global $db, $portal_config, $config, $template, $user, $phpEx, $phpbb_admin_path, $phpbb_root_path;

		$action = (isset($_POST['reset'])) ? 'reset' : '';
		$action = (isset($_POST['submit'])) ? 'save' : $action;
		$action = (isset($_POST['preview'])) ? 'preview' : $action;

		$portal_config = obtain_portal_config();

		$u_action = append_sid($phpbb_admin_path . 'index.' . $phpEx, 'i=portal&amp;mode=config&amp;module_id=' . $module_id);

		switch($action)
		{
			// Save changes
			case 'save':
				if (!check_form_key('acp_portal'))
				{
					trigger_error($user->lang['FORM_INVALID']. adm_back_link($u_action), E_USER_WARNING);
				}

				$welcome_message = utf8_normalize_nfc(request_var('welcome_message', '', true));
				$uid = $bitfield = $flags = '';
				$options = 7;
				generate_text_for_storage($welcome_message, $uid, $bitfield, $flags, true, true, true);

				// first check for obvious errors, we don't want to waste server resources
				if(empty($welcome_message))
				{
					trigger_error($user->lang['ACP_PORTAL_WELCOME_MESSAGE_SHORT']. adm_back_link($u_action), E_USER_WARNING);
				}

				add_log('admin', 'LOG_PORTAL_CONFIG', $user->lang['PORTAL_WELCOME']);

				// set_portal_config will take care of escaping the welcome message
				set_portal_config('board3_welcome_message_' . $module_id, $welcome_message);
				set_config('board3_welcome_message_uid_' . $module_id, $uid);
				set_config('board3_welcome_message_bitfield_' . $module_id, $bitfield);
			break;

			case 'preview':
				$welcome_message = $text = utf8_normalize_nfc(request_var('welcome_message', '', true));

				if (!class_exists('parse_message'))
				{
					include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
				}

				$bbcode_options = OPTION_FLAG_BBCODE + OPTION_FLAG_SMILIES + OPTION_FLAG_LINKS;
				$uid  =  (isset($config['board3_welcome_message_uid_' . $module_id])) ? $config['board3_welcome_message_uid_' . $module_id] : '';
				$bitfield = (isset($config['board3_welcome_message_bitfield_' . $module_id])) ? $config['board3_welcome_message_bitfield_' . $module_id] : '';
				$options = OPTION_FLAG_BBCODE + OPTION_FLAG_SMILIES + OPTION_FLAG_LINKS;
				generate_text_for_storage($text, $uid, $bitfield, $options, true, true, true);

				$text = generate_text_for_display($text, $uid, $bitfield, $options);

				$template->assign_vars(array(
					'PREVIEW_TEXT'		=> $text,
					'S_PREVIEW'			=> true,
				));

			// Edit or add menu item
			case 'reset':
			default:
				if(!isset($welcome_message))
				{
					$welcome_message = generate_text_for_edit($portal_config['board3_welcome_message_' . $module_id], $config['board3_welcome_message_uid_' . $module_id], '');
				}

				$template->assign_vars(array(
					'WELCOME_MESSAGE'		=> (is_array($welcome_message)) ? $welcome_message['text'] : $welcome_message,
					//'U_BACK'				=> $u_action,
					'U_ACTION'				=> $u_action,
					'S_EDIT'				=> true,
					'S_LINKS_ALLOWED'       => true,
					'S_BBCODE_IMG'          => true,
					'S_BBCODE_FLASH'		=> true,
					'S_BBCODE_QUOTE'		=> true,
					'S_BBCODE_ALLOWED'		=> true,
					'MAX_FONT_SIZE'			=> (int) $config['max_post_font_size'],
				));

				if(!function_exists('display_forums'))
				{
					include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
				}

				// Build custom bbcodes array
				display_custom_bbcodes();
				$user->add_lang('posting');

			break;		
		}
	}
Пример #10
0
	public function manage_custom($value, $key, $module_id)
	{
		global $db, $portal_config, $config, $template, $user, $phpEx, $phpbb_admin_path, $phpbb_root_path;

		$action = (isset($_POST['reset'])) ? 'reset' : '';
		$action = (isset($_POST['submit'])) ? 'save' : $action;
		$action = (isset($_POST['preview'])) ? 'preview' : $action;

		$portal_config = obtain_portal_config();

		$u_action = append_sid($phpbb_admin_path . 'index.' . $phpEx, 'i=portal&amp;mode=config&amp;module_id=' . $module_id);

		switch($action)
		{
			// Save changes
			case 'save':
				if (!check_form_key('acp_portal'))
				{
					trigger_error($user->lang['FORM_INVALID']. adm_back_link($u_action), E_USER_WARNING);
				}

				$custom_code = utf8_normalize_nfc(request_var('custom_code', '', true));
				$custom_bbcode = request_var('custom_use_bbcode', 1); // default to BBCode
				$custom_permission = request_var('permission-setting', array(0 => ''));
				$custom_title = utf8_normalize_nfc(request_var('module_name', '', true));
				$custom_image_src = utf8_normalize_nfc(request_var('module_image', ''));
				$groups_ary = array();
				$uid = $bitfield = $flags = '';
				$options = 7;
				if($custom_bbcode)
				{
					generate_text_for_storage($custom_code, $uid, $bitfield, $flags, true, true, true);
				}

				// first check for obvious errors, we don't want to waste server resources
				if(empty($custom_code))
				{
					trigger_error($user->lang['ACP_PORTAL_CUSTOM_CODE_SHORT']. adm_back_link($u_action), E_USER_WARNING);
				}

				// get groups and check if the selected groups actually exist
				$sql = 'SELECT group_id
						FROM ' . GROUPS_TABLE . '
						ORDER BY group_id ASC';
				$result = $db->sql_query($sql);
				while($row = $db->sql_fetchrow($result))
				{
					$groups_ary[] = $row['group_id'];
				}
				$db->sql_freeresult($result);

				$custom_permission = array_intersect($custom_permission, $groups_ary);
				$custom_permission = implode(',', $custom_permission);

				if (isset($user->lang[$custom_title]))
				{
					$log_title =  $user->lang[$custom_title];
				}
				else
				{
					$log_title = $custom_title;
				}

				add_log('admin', 'LOG_PORTAL_CONFIG', $user->lang['PORTAL_CUSTOM'] . ':&nbsp;' . $log_title);

				// set_portal_config will take care of escaping the welcome message
				set_portal_config('board3_custom_' . $module_id . '_code', $custom_code);
				set_config('board3_custom_' . $module_id . '_bbcode', $custom_bbcode);
				set_config('board3_custom_' . $module_id . '_title', $custom_title);
				set_config('board3_custom_' . $module_id . '_image_src', $custom_image_src);
				set_config('board3_custom_' . $module_id . '_uid', $uid);
				set_config('board3_custom_' . $module_id . '_bitfield', $bitfield);
				set_config('board3_custom_' . $module_id . '_permission', $custom_permission);

				//trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link(($module_id) ? append_sid("{$phpbb_admin_path}index.$phpEx", 'i=portal&mode=modules') : $u_action));

			break;

			case 'preview':
				$custom_code = $text = utf8_normalize_nfc(request_var('custom_code', '', true));
				$custom_bbcode = request_var('custom_use_bbcode', 1); // default to BBCode
				$custom_permission = request_var('permission-setting', array(0 => ''));
				$custom_title = utf8_normalize_nfc(request_var('module_name', ''));
				$custom_image_src = utf8_normalize_nfc(request_var('module_image', ''));
				$groups_ary = array();

				// first check for obvious errors, we don't want to waste server resources
				if(empty($custom_code))
				{
					trigger_error($user->lang['ACP_PORTAL_CUSTOM_CODE_SHORT']. adm_back_link($u_action), E_USER_WARNING);
				}

				if (!class_exists('parse_message'))
				{
					include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
				}
				if($custom_bbcode)
				{
					$bbcode_options = OPTION_FLAG_BBCODE + OPTION_FLAG_SMILIES + OPTION_FLAG_LINKS;
					$uid  =  (isset($config['board3_custom_' . $module_id . '_uid'])) ? $config['board3_custom_' . $module_id . '_uid'] : '';
					$bitfield = (isset($config['board3_custom_' . $module_id . '_bitfield'])) ? $config['board3_custom_' . $module_id . '_bitfield'] : '';
					$options = OPTION_FLAG_BBCODE + OPTION_FLAG_SMILIES + OPTION_FLAG_LINKS;
					generate_text_for_storage($text, $uid, $bitfield, $options, true, true, true);

					$text = generate_text_for_display($text, $uid, $bitfield, $options);
				}
				else
				{
					$text = htmlspecialchars_decode($text, ENT_QUOTES);
				}

				$template->assign_vars(array(
					'PREVIEW_TEXT'		=> $text,
					'S_PREVIEW'			=> true,
				));

				// get groups and check if the selected groups actually exist
				$sql = 'SELECT group_id
						FROM ' . GROUPS_TABLE . '
						ORDER BY group_id ASC';
				$result = $db->sql_query($sql);
				while($row = $db->sql_fetchrow($result))
				{
					$groups_ary[] = $row['group_id'];
				}
				$db->sql_freeresult($result);

				$temp_permissions = array_intersect($custom_permission, $groups_ary);

			// Edit or add menu item
			case 'reset':
			default:
				if(!isset($custom_code))
				{
					$custom_code = generate_text_for_edit($portal_config['board3_custom_' . $module_id . '_code'], $config['board3_custom_' . $module_id . '_uid'], '');
				}

				$template->assign_vars(array(
					'CUSTOM_CODE'			=> (is_array($custom_code)) ? $custom_code['text'] : $custom_code,
					'CUSTOM_USE_BBCODE'		=> (isset($custom_bbcode)) ? $custom_bbcode : (($config['board3_custom_' . $module_id . '_bbcode'] != '') ? $config['board3_custom_' . $module_id . '_bbcode'] : true), // BBCodes are selected by default
					//'U_BACK'				=> $u_action,
					'U_ACTION'				=> $u_action,
					'S_EDIT'				=> true,
					'S_LINKS_ALLOWED'       => true,
					'S_BBCODE_IMG'          => true,
					'S_BBCODE_FLASH'		=> true,
					'S_BBCODE_QUOTE'		=> true,
					'S_BBCODE_ALLOWED'		=> true,
					'MAX_FONT_SIZE'			=> (int) $config['max_post_font_size'],
				));

				$groups_ary = (isset($temp_permissions)) ? $temp_permissions : ((isset($config['board3_custom_' . $module_id . '_permission'])) ? explode(',', $config['board3_custom_' . $module_id . '_permission']) : array());

				// get group info from database and assign the block vars
				$sql = 'SELECT group_id, group_name 
						FROM ' . GROUPS_TABLE . '
						ORDER BY group_id ASC';
				$result = $db->sql_query($sql);
				while($row = $db->sql_fetchrow($result))
				{
					$template->assign_block_vars('permission_setting', array(
						'SELECTED'		=> (in_array($row['group_id'], $groups_ary)) ? true : false,
						'GROUP_NAME'	=> (isset($user->lang['G_' . $row['group_name']])) ? $user->lang['G_' . $row['group_name']] : $row['group_name'],
						'GROUP_ID'		=> $row['group_id'],
					));
				}
				$db->sql_freeresult($result);

				if(!function_exists('display_forums'))
				{
					include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
				}

				// Build custom bbcodes array
				display_custom_bbcodes();
				$user->add_lang('posting');

			break;		
		}
	}
Пример #11
0
 /**
  * Parse template for custom blocks
  *
  * @param int $module_id	Module ID of current module
  * @param string $type	Type of module (center or side), default to
  *			center to not show module image unless wanted
  * @return array		An array containing the custom module data
  */
 protected function parse_template($module_id, $type = 'center')
 {
     $portal_config = obtain_portal_config();
     /*
      * Run generate_text_for_display if the user uses BBCode for designing his custom block
      * HTML won't be parsed if the user chooses to use BBCodes in the ACP
      * If BBCodes are turned off, the custom Block code will be directly assigned and HTML will be parsed
      */
     if ($this->config['board3_custom_' . $module_id . '_bbcode']) {
         // Generate text for display and assign template vars
         $uid = $this->config['board3_custom_' . $module_id . '_uid'];
         $bitfield = $this->config['board3_custom_' . $module_id . '_bitfield'];
         $bbcode_options = OPTION_FLAG_BBCODE + OPTION_FLAG_SMILIES + OPTION_FLAG_LINKS;
         $assign_code = generate_text_for_display($portal_config['board3_custom_' . $module_id . '_code'], $uid, $bitfield, $bbcode_options);
     } else {
         $assign_code = htmlspecialchars_decode($portal_config['board3_custom_' . $module_id . '_code'], ENT_QUOTES);
     }
     $title = !empty($this->config['board3_custom_' . $module_id . '_title']) ? isset($this->user->lang[$this->config['board3_custom_' . $module_id . '_title']]) ? $this->user->lang[$this->config['board3_custom_' . $module_id . '_title']] : $this->config['board3_custom_' . $module_id . '_title'] : $this->user->lang[$this->name];
     if (!empty($assign_code)) {
         return array('template' => 'custom_' . $type . '.html', 'title' => $title, 'code' => $assign_code, 'image_src' => $type === 'center' ? '' : (!empty($this->config['board3_custom_' . $module_id . '_image_src']) ? $this->config['board3_custom_' . $module_id . '_image_src'] : $this->image_src));
     }
 }
Пример #12
0
 /**
  * Manage welcome message
  *
  * @param mixed $value Value of input
  * @param string $key Key name
  * @param int $module_id Module ID
  *
  * @return null
  */
 public function manage_welcome($value, $key, $module_id)
 {
     $action = $this->request->is_set_post('reset') ? 'reset' : '';
     $action = $this->request->is_set_post('submit') ? 'save' : $action;
     $action = $this->request->is_set_post('preview') ? 'preview' : $action;
     $portal_config = obtain_portal_config();
     $u_action = append_sid('index.' . $this->php_ext, 'i=-board3-portal-acp-portal_module&amp;mode=config&amp;module_id=' . $module_id);
     switch ($action) {
         // Save changes
         case 'save':
             if (!check_form_key('acp_portal')) {
                 trigger_error($this->user->lang['FORM_INVALID'] . adm_back_link($u_action), E_USER_WARNING);
             }
             $welcome_message = $this->request->variable('welcome_message', '', true);
             $uid = $bitfield = $flags = '';
             generate_text_for_storage($welcome_message, $uid, $bitfield, $flags, true, true, true);
             // first check for obvious errors, we don't want to waste server resources
             if (empty($welcome_message)) {
                 trigger_error($this->user->lang['ACP_PORTAL_WELCOME_MESSAGE_SHORT'] . adm_back_link($u_action), E_USER_WARNING);
             }
             // set_portal_config will take care of escaping the welcome message
             set_portal_config('board3_welcome_message_' . $module_id, $welcome_message);
             $this->config->set('board3_welcome_message_uid_' . $module_id, $uid);
             $this->config->set('board3_welcome_message_bitfield_' . $module_id, $bitfield);
             break;
         case 'preview':
             $welcome_message = $text = $this->request->variable('welcome_message', '', true);
             $bbcode_options = OPTION_FLAG_BBCODE + OPTION_FLAG_SMILIES + OPTION_FLAG_LINKS;
             $uid = isset($this->config['board3_welcome_message_uid_' . $module_id]) ? $this->config['board3_welcome_message_uid_' . $module_id] : '';
             $bitfield = isset($this->config['board3_welcome_message_bitfield_' . $module_id]) ? $this->config['board3_welcome_message_bitfield_' . $module_id] : '';
             $options = OPTION_FLAG_BBCODE + OPTION_FLAG_SMILIES + OPTION_FLAG_LINKS;
             generate_text_for_storage($text, $uid, $bitfield, $options, true, true, true);
             $text = generate_text_for_display($text, $uid, $bitfield, $options);
             $this->template->assign_vars(array('PREVIEW_TEXT' => $text, 'S_PREVIEW' => true));
             // Edit or add menu item
         // Edit or add menu item
         case 'reset':
         default:
             if (!isset($welcome_message)) {
                 $welcome_message = generate_text_for_edit($portal_config['board3_welcome_message_' . $module_id], $this->config['board3_welcome_message_uid_' . $module_id], '');
             }
             $this->template->assign_vars(array('WELCOME_MESSAGE' => is_array($welcome_message) ? $welcome_message['text'] : $welcome_message, 'U_ACTION' => $u_action, 'S_EDIT' => true, 'S_LINKS_ALLOWED' => true, 'S_BBCODE_IMG' => true, 'S_BBCODE_FLASH' => true, 'S_BBCODE_QUOTE' => true, 'S_BBCODE_ALLOWED' => true, 'MAX_FONT_SIZE' => (int) $this->config['max_post_font_size']));
             if (!function_exists('display_forums')) {
                 include $this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext;
             }
             // Build custom bbcodes array
             display_custom_bbcodes();
             $this->user->add_lang('posting');
             break;
     }
 }
Пример #13
0
 /**
  * Run initial tasks that are required for a properly setup extension
  *
  * @return null
  */
 public function run_initial_tasks()
 {
     // Check for permissions first
     $this->check_permission();
     // Load language file
     $this->user->add_lang_ext('board3/portal', 'portal');
     // Obtain portal config
     obtain_portal_config();
 }