/system/core/core.messages.php
PHP | 5494 lines | 4770 code | 404 blank | 320 comment | 215 complexity | 02e09200b7cfe6ae7e8fdcad36141dc1 MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- <?php
- /*
- =====================================================
- ExpressionEngine - by EllisLab
- -----------------------------------------------------
- http://expressionengine.com/
- -----------------------------------------------------
- Copyright (c) 2003 - 2010 EllisLab, Inc.
- =====================================================
- THIS IS COPYRIGHTED SOFTWARE
- PLEASE READ THE LICENSE AGREEMENT
- http://expressionengine.com/docs/license.html
- =====================================================
- File: core.messages.php
- -----------------------------------------------------
- Purpose: Private Messages
- =====================================================
- */
- if ( ! defined('EXT'))
- {
- exit('Invalid file request');
- }
- class Messages {
- // URL Writing
- var $allegiance = 'cp'; // Side of the divide: cp or user
- var $CP = FALSE; // CP Object
- var $base_url = ''; // Base URL used throughout
- var $form_url = ''; // For CP Forms, since Rick was a doofus and changed how they work
- var $path = 'member/'; // User Side Path
- var $request = 'inbox'; // User Side Request
- var $cur_id = ''; // User Side ID, if any
- var $theme_class = 'profile_theme';
- var $images_folder = ''; // Location of Forum Images
- // Member Specific
- var $member_id = '';
- var $private_messages = '0'; // Number of unread private messages
- var $block_tracking = 'n'; // Block Sender Tracking
-
- // Member Group Specific
- var $allow_pm = 'y'; // Allowed to PM?
- var $attach_allowed = 'y'; // Attachments allowed?
-
- // Private Message Preferences
- var $storage_limit = 60; // Limit for messages to store per user (does not count deleted)
- var $send_limit = 20; // Limit for messages sent a day
- var $upload_path = ''; // Upload path for files
- var $attach_maxsize = 250; // Max size for attachments (KB)
- var $attach_total = 100; // Maximum amount for all PM attachments (MB)
- var $html_format = 'safe'; // HTML Formatting?
- var $auto_links = 'y'; // Auto convert URLs to links
- var $max_chars = 6000; // Maximum number of characters in a messages
- var $max_attachments = 1; // Maximum number of attachments per message
-
- // User Data Variables
- var $total_messages = ''; // Total Store Messages for User
- var $current_folder = '1'; // If any...
- var $folders = array(); // Folders for User
- var $hide_preview = FALSE; // Whether to show the Preview of Message
- var $attachments = array(); // Attachments for current message
- var $baddies = array(); // Blocked List; IDs only
- var $goodies = array(); // Buddies List; IDs only
- var $blocked = FALSE; // Blocked List
- var $buddies = FALSE; // Buddies List
- var $invalid_name = FALSE; // Invalid name submitted?
-
- // Menu Content
- var $menu_items = array(); // Abstracted data for creating menu
- var $menu = ''; // Menu fully formed
-
- // Processing and Returned Data
- var $title = ''; // Title of Page
- var $crumb = ''; // Crumb text for page
- var $return_data = ''; // Output data
- var $header_javascript = ''; // User Side Header JavaScript
- var $error = ''; // Submission Error
- var $single_parts = array(); // Parts of a page: text, form, images, content
- var $conditionals = array(); // Conditionals
- var $mimes = '';
-
- // Changeable Class Variables
- var $default_folders = array('Inbox', 'Sent');
- var $max_folders = 10; // Maximum number of folders per user
- var $per_page = 25; // Messages on a Folder's Page
- var $graph_width = '300'; // Width of Total Messages Graph
- var $emoticons_per_row = 5; // Number of Images Per Table Row
- var $delete_expiration = 30; // Erase deleted messages after X days
- var $disable_emoticons = 'n'; // Disable the showing of emoticons
- var $spellcheck_enabled = TRUE; // Enabled Spellcheck?
- /** -----------------------------------
- /** Constructor
- /** -----------------------------------*/
- function Messages()
- {
- global $IN, $LANG, $FNS, $PREFS, $SESS;
-
- /** -----------------------------------
- /** A Few Things to Define, Batman
- /** -----------------------------------*/
-
- $this->member_id = $SESS->userdata['member_id'];
- $this->allow_pm = ($SESS->userdata['group_id'] == '1') ? 'y' : $SESS->userdata['can_send_private_messages'];
- $this->allow_pm = ($this->allow_pm == 'y' && $SESS->userdata['accept_messages'] == 'y') ? 'y' : 'n';
-
- $this->attach_allowed = $SESS->userdata('can_attach_in_private_messages');
-
- $this->storage_limit = ($SESS->userdata['group_id'] == '1') ? 0 : $SESS->userdata['prv_msg_storage_limit'];
- $this->send_limit = $SESS->userdata['prv_msg_send_limit'];
- if ( ! defined('AMP')) define('AMP', '&');
- if ( ! defined('BR')) define('BR', '<br />');
- if ( ! defined('NL')) define('NL', "\n");
- if ( ! defined('NBS')) define('NBS', " ");
-
- $prefs = array( 'prv_msg_attach_maxsize',
- 'prv_msg_attach_total',
- 'prv_msg_html_format',
- 'prv_msg_auto_links',
- 'prv_msg_max_chars',
- 'prv_msg_max_attachments'
- );
-
- for($i=0, $t = sizeof($prefs); $i < $t; ++$i)
- {
- if (FALSE !== ($value = $PREFS->ini($prefs[$i])))
- {
- $name = str_replace('prv_msg_', '', $prefs[$i]);
-
- $this->{$name} = $value;
- }
- }
- $this->upload_path = $PREFS->ini('prv_msg_upload_path', TRUE);
-
- // -----------------------------------
- // Nearly every page requires this,
- // so just load it for all of them
- // -----------------------------------
-
- $LANG->fetch_language_file('messages');
-
- $this->title = $LANG->line('private_messages');
- $this->crumb = $LANG->line('private_messages');
-
- $this->images_folder = $PREFS->ini('theme_folder_url', TRUE).'cp_global_images/';
-
- $this->single_parts['path']['image_url'] = $this->images_folder;
-
- /** -----------------------------------
- /** Maintenance
- /** -----------------------------------*/
-
- srand(time());
-
- if ((rand() % 100) < 5)
- {
- $this->maintenance();
- }
- }
- /* END */
-
- /** -----------------------------------
- /** Determine request
- /** -----------------------------------*/
-
- function _determine_request()
- {
- global $IN;
-
- if ($this->allegiance == 'cp')
- {
- $this->base_url = BASE.AMP.'C=myaccount'.AMP.'M=messages'.AMP.'P=';
- $this->form_url = 'C=myaccount'.AMP.'M=messages'.AMP.'P=';
- $this->request = ($IN->GBL('P') !== FALSE) ? $IN->GBL('P') : 'inbox';
- }
- else
- {
- $this->form_url = $this->base_url;
- }
- }
- /* END */
-
-
-
- /** -----------------------------------
- /** Create Path
- /** -----------------------------------*/
- function _create_path($uri='', $hidden='')
- {
- if ($this->allegiance == 'user')
- {
- return $this->base_url.$uri.'/';
- }
- else
- {
- return $this->base_url.$uri.$hidden;
- }
- }
- /* END */
-
- // -----------------------------------
- // Process Page :
- // Convert and Template into Content
- // -----------------------------------
- function _process_template($template, $data = '')
- {
- global $LANG, $REGX;
-
- /** -------------------------------
- /** Process Conditionals
- /** -------------------------------*/
-
- if (sizeof($this->conditionals) > 0)
- {
- foreach($this->conditionals as $key => $value)
- {
- if ($value == 'y')
- {
- $template = preg_replace("/\{if\s+".$key."\}(.+?)\{\/if\}/si", "\\1", $template);
- $template = preg_replace("/\{if\s+not_".$key."\}(.+?)\{\/if\}/si", '', $template);
- }
- else
- {
- $template = preg_replace("/\{if\s+".$key."\}.+?\{\/if\}/si", '', $template);
- $template = preg_replace("/\{if\s+not_".$key."\}(.+?)\{\/if\}/si", "\\1", $template);
- }
- }
- }
-
-
- /** --------------------------
- /** Process any sent data
- /** --------------------------*/
-
- if (is_array($data) && sizeof($data) > 0)
- {
- foreach($data as $key => $value)
- {
- $template = str_replace(LD.$key.RD, $value, $template);
- }
- }
-
- /** -----------------------------
- /** Process any universal data
- /** -----------------------------*/
-
- if (sizeof($this->single_parts) > 0)
- {
- foreach($this->single_parts as $key => $value)
- {
- if (is_array($value) && sizeof($value) > 0)
- {
- foreach($value as $key2 => $value2)
- {
- if (is_array($value2) && sizeof($value2) > 0)
- {
- foreach($value2 as $key3 => $value3)
- {
- $template = str_replace(LD.$key.':'.$key2.':'.$key3.RD, $value3, $template);
- }
- }
- else
- {
- if ($key == 'input' && $key2 == 'body')
- {
- $value2 = $REGX->encode_ee_tags($value2, TRUE);
- }
-
- $template = str_replace(LD.$key.':'.$key2.RD,
- ($key == 'input' && $key2 != 'body' && $key2 != 'folder_name') ? htmlspecialchars($value2, ENT_QUOTES) : $value2,
- $template);
- }
- }
- }
- elseif( ! is_array($value))
- {
- if ($key != 'title' && ! stristr($value, '<option')) $value = htmlspecialchars($value, ENT_QUOTES); // {title} is link title for message menu
-
- $template = str_replace(LD.$key.RD, $value, $template);
- }
- }
- }
-
- /** -------------------------------------
- /** Finally, process all language text
- /** -------------------------------------*/
-
- if (isset($LANG->language) && is_array($LANG->language) && sizeof($LANG->language) > 0)
- {
- foreach($LANG->language as $key => $value)
- {
- $template = str_replace(LD.'lang:'.$key.RD, $value, $template);
- }
- }
-
- return $template;
- }
- /* END */
-
-
- /** -----------------------------------
- /** Manage Request
- /** -----------------------------------*/
- function manager()
- {
- global $PREFS;
-
- if ($this->allow_pm != 'y')
- {
- return;
- }
-
- $this->_determine_request();
-
- if (sizeof($this->folders) == 0)
- {
- $this->fetch_folders();
- }
-
- if ($this->disable_emoticons == 'y')
- {
- $PREFS->core_ini['enable_emoticons'] = 'n';
- }
-
- /** -----------------------------------
- /** Call request
- /** -----------------------------------*/
-
- if (method_exists($this, $this->request))
- {
- $this->{$this->request}();
- }
- else
- {
- $this->inbox();
- }
-
- /* -----------------------------------
- /* Member Module - Fixeroo
- /* - Rick has some legacy code in the member module that converts
- /* certain path variables automatically. We, however, do not want that
- /* in our most precious Private Messages, and so we do a bit of conversion
- /* -----------------------------------*/
-
- $this->return_data = preg_replace("/".LD."\s*path=(.*?)".RD."/", '{path=\\1}', $this->return_data);
- $this->return_data = preg_replace("#".LD."\s*(profile_path\s*=.*?)".RD."#", '{\\1}', $this->return_data);
-
- /** -----------------------------------
- /** Name to ID in Form Switch - Fixeroo
- /** -----------------------------------*/
-
- $this->return_data = str_replace('opener.document.submit_message.', "opener.document.getElementById('submit_message').", $this->return_data);
- }
- /* END */
-
-
- /** -----------------------------------
- /** Fetch Buddy and Block Lists
- /** -----------------------------------*/
-
- function fetch_lists($which='')
- {
- global $DB;
-
- if ($which == 'buddy')
- {
- $this->goodies = array();
- $this->buddies = array();
- }
- elseif($which == 'blocked')
- {
- $this->baddies = array();
- $this->blocked = array();
- }
- else
- {
- $this->goodies = array();
- $this->buddies = array();
- $this->baddies = array();
- $this->blocked = array();
- }
-
- $extra = ($which != '') ? "AND l.listed_type = '{$which}'" : '';
-
- $query = $DB->query("SELECT l.*, m.username, m.screen_name, m.member_id
- FROM exp_message_listed l, exp_members m
- WHERE l.listed_member = m.member_id
- AND l.member_id = '{$this->member_id}'
- $extra");
-
- if ($query->num_rows > 0)
- {
- foreach($query->result as $row)
- {
- if (empty($row['username']))
- {
- continue;
- }
-
- if ($row['listed_type'] == 'buddy')
- {
- $this->buddies[] = array($row['listed_member'], $row['username'], $row['screen_name'], $row['listed_description'], $row['listed_id'], $row['member_id']);
- $this->goodies[] = $row['listed_member'];
- }
- else
- {
- $this->blocked[] = array($row['listed_member'], $row['username'], $row['screen_name'], $row['listed_description'], $row['listed_id'], $row['member_id']);
- $this->baddies[] = $row['listed_member'];
- }
- }
- }
- }
- /* END */
-
-
- /** -----------------------------------
- /** Determine Folders for this User
- /** -----------------------------------*/
-
- function fetch_folders()
- {
- global $DB, $REGX;
-
- $this->folders = array();
-
- $query = $DB->query("SELECT * FROM exp_message_folders WHERE member_id = '{$this->member_id}'");
-
- if ($query->num_rows == 0)
- {
- $DB->query($DB->insert_string('exp_message_folders', array('member_id' => $this->member_id)));
-
- $this->folders['1'] = array($this->default_folders['0'], '0');
- $this->folders['2'] = array($this->default_folders['1'], '0');
- }
- else
- {
- $required = array('1' => array($query->row['folder1_name'], '0'), '2' => array($query->row['folder2_name'], '0'));
-
- for($i=3; $i <= $this->max_folders; $i++)
- {
- $this->folders[$i] = htmlspecialchars($query->row['folder'.$i.'_name'], ENT_QUOTES);
- }
-
- asort($this->folders);
-
- foreach($this->folders as $key => $value)
- {
- $this->folders[$key] = array($value, '0');
- }
-
- $this->folders = $required + $this->folders;
-
- $results = $DB->query("SELECT COUNT(*) AS count, message_folder FROM exp_message_copies
- WHERE recipient_id = '{$this->member_id}'
- AND message_deleted = 'n'
- GROUP BY message_folder");
-
- if ($results->num_rows > 0)
- {
- foreach($results->result as $row)
- {
- $this->folders[$row['message_folder']]['1'] = $row['count'];
- }
- }
- }
- }
- /* END */
-
-
- /** -----------------------------------
- /** Edit Folders
- /** -----------------------------------*/
-
- function folders()
- {
- global $LANG, $FNS;
-
- $template = $this->retrieve_template('message_edit_folders');
- $rows = $this->retrieve_template('message_edit_folders_row');
-
- $form_details = array('action' => $this->base_url.'edit_folders',
- 'id' => 'edit_folders',
- 'secure' => ($this->allegiance == 'cp') ? FALSE : TRUE
- );
-
- $this->single_parts['form']['form_declaration']['edit_folders'] = $FNS->form_declaration($form_details);
- $this->single_parts['include']['current_folders'] = '';
- $this->single_parts['include']['new_folder'] = '';
-
- if ( ! isset($this->single_parts['include']['success_message']))
- {
- $this->single_parts['include']['success_message'] = '';
- }
-
- /** -----------------------------------------
- /** Create Folder Rows
- /** -----------------------------------------*/
-
- $t=1;
-
- foreach($this->folders as $key => $value)
- {
- if ($value['0'] == '')
- {
- continue;
- }
-
- $t++;
- $this->single_parts['lang']['required'] = ($key < 3) ? $LANG->line('folder_required') : '';
- $this->single_parts['input']['folder_name'] = $value['0'];
- $this->single_parts['input']['folder_id'] = $key;
- $this->single_parts['style'] = ($t % 2) ? 'tableCellOne' : 'tableCellTwo';
-
- $this->single_parts['include']['current_folders'] .= $this->_process_template($rows);
- }
-
- /** -----------------------------------------
- /** Create New Folder Row, If Allowed
- /** -----------------------------------------*/
-
- if ($t <= $this->max_folders)
- {
- $t++;
- $this->single_parts['lang']['required'] = '';
- $this->single_parts['input']['folder_name'] = '';
- $this->single_parts['input']['folder_id'] = 'new';
- $this->single_parts['style'] = ($t % 2) ? 'tableCellOne' : 'tableCellTwo';
-
- $this->single_parts['include']['new_folder'] = $this->_process_template($rows);
- }
-
- /** ----------------------------------------
- /** Return the Folder's Contents
- /** ----------------------------------------*/
-
- $this->title = $LANG->line('edit_folders');
- $this->crumb = $LANG->line('edit_folders');
- $this->return_data = $this->_process_template($template);
- }
- /* END */
-
-
-
- /** -----------------------------------
- /** Edit Folders
- /** -----------------------------------*/
-
- function edit_folders()
- {
- global $REGX, $DB, $LANG;
-
- /** -----------------------------------
- /** Check Required
- /** -----------------------------------*/
-
- if ( ! isset($_POST['folder_1']) OR ! isset($_POST['folder_2']) OR $_POST['folder_1'] == '' OR $_POST['folder_2'] == '')
- {
- return $this->_error_page('missing_required_field');
- }
-
- /** -----------------------------------
- /** Get Our Modified Data
- /** -----------------------------------*/
-
- for($i=1, $data = array(); $i <= $this->max_folders; $i++)
- {
- if ( ! isset($_POST['folder_'.$i]) OR $_POST['folder_'.$i] == '')
- {
- $data['folder'.$i.'_name'] = '';
- $DB->query("UPDATE exp_message_copies SET message_deleted = 'y'
- WHERE recipient_id = '{$this->member_id}' AND message_folder = '{$i}'");
-
- if ( ! isset($empty)) $empty = 'folder'.$i.'_name';
- }
- else
- {
- $data['folder'.$i.'_name'] = $REGX->xss_clean($_POST['folder_'.$i]);
- }
- }
-
- /** -----------------------------------
- /** Get Our New Folder
- /** -----------------------------------*/
-
- if (isset($_POST['folder_new']) && $_POST['folder_new'] != '' && isset($empty))
- {
- $data[$empty] = $REGX->xss_clean($_POST['folder_new']);
- }
-
- $DB->query($DB->update_string('exp_message_folders', $data, "member_id = '{$this->member_id}'"));
-
- $this->fetch_folders();
-
- /** -----------------------------------
- /** Success Message
- /** -----------------------------------*/
-
- $this->single_parts['lang']['message'] = $LANG->line('folders_updated');
- $this->single_parts['include']['success_message'] = $this->_process_template($this->retrieve_template('message_success'));
-
- /** ----------------------------------------
- /** Return us back to Oz
- /** ----------------------------------------*/
-
- return $this->folders();
- }
- /* END */
-
-
-
- /** -----------------------------------
- /** Abstracted Default Menu
- /** -----------------------------------*/
- function abstract_menu()
- {
- global $LANG, $DB, $SESS, $LOC;
-
- /** ------------------------------
- /** Bulletin Board
- /** ------------------------------*/
-
- $style = ($SESS->userdata['last_view_bulletins'] <= $SESS->userdata['last_bulletin_date']) ? 'defaultBold' : '';
-
- $this->menu_items['single_items']['bulletin_board'] = array('text' => $LANG->line('bulletin_board'),
- 'link' => $this->_create_path('bulletin_board'),
- 'image' => '',
- 'style' => $style);
-
- /** ------------------------
- /** Compose New Message
- /** ------------------------*/
-
- $this->menu_items['single_items']['compose_message'] = array('text' => $LANG->line('compose_message'),
- 'link' => $this->_create_path('compose'),
- 'image' => '',
- 'style' => 'defaultBold');
-
-
- /** ------------------------
- /** Drafts Folder
- /** ------------------------*/
-
- $query = $DB->query("SELECT COUNT(*) AS count FROM exp_message_data
- WHERE sender_id = '{$this->member_id}'
- AND message_status = 'draft'");
-
- if ($query->row['count'] > 0)
- {
- $this->menu_items['repeat_items']['folders'][] = array('text' => $LANG->line('draft_messages') .' ('.$query->row['count'].')',
- 'link' => $this->_create_path('drafts'),
- 'image' => '',
- 'style' => '');
- }
-
-
- /** -------------------------------
- /** User Folders
- /** -------------------------------*/
-
- if (sizeof($this->folders) == 0)
- {
- $this->fetch_folders();
- }
-
- foreach($this->folders as $key => $value)
- {
- if ($value['0'] != '')
- {
- if ($this->allegiance == 'user')
- {
- $url = $this->base_url.'view_folder/'.$key.'/';
- }
- else
- {
- $url = $this->base_url.'view_folder'.AMP.'folder='.$key;
- }
-
- $this->menu_items['repeat_items']['folders'][] = array('text' => ' - '.$value['0'].' ('.$value['1'].')',
- 'link' => $url,
- 'image' => '',
- 'style' => '');
- }
- }
-
- /** ------------------------
- /** Deleted Folder
- /** ------------------------*/
-
- $query = $DB->query("SELECT COUNT(*) AS count FROM exp_message_copies
- WHERE recipient_id = '{$this->member_id}'
- AND message_deleted = 'y'");
-
- $this->menu_items['repeat_items']['folders'][] = array('text' => $LANG->line('deleted_messages').' ('.$query->row['count'].')',
- 'link' => $this->_create_path('deleted'),
- 'image' => '',
- 'style' => '');
-
- /* ------------------------
- // Message Tracking
- // ------------------------
-
- $this->menu_items['single_items']['track_messages'] = array('text' => $LANG->line('track_messages'),
- 'link' => $this->_create_path('track'),
- 'image' => '',
- 'style' => '');
- */
- /** ------------------------
- /** Edit Message Folders
- /** ------------------------*/
-
- $this->menu_items['single_items']['edit_folders'] = array('text' => $LANG->line('edit_folders'),
- 'link' => $this->_create_path('folders'),
- 'image' => '',
- 'style' => '');
-
- /** ------------------------
- /** Buddy List
- /** ------------------------*/
- $this->menu_items['single_items']['buddy_list'] = array('text' => $LANG->line('buddy_list'),
- 'link' => $this->_create_path('buddies'),
- 'image' => '',
- 'style' => '');
-
- /** ------------------------
- /** Block List
- /** ------------------------*/
-
- $this->menu_items['single_items']['block_list'] = array('text' => $LANG->line('blocked_list'),
- 'link' => $this->_create_path('blocked'),
- 'image' => '',
- 'style' => '');
-
- }
- /* END */
- /** -----------------------------------
- /** Create Messages Menu
- /** -----------------------------------*/
- function create_menu()
- {
- global $DB, $DSP, $IN, $LANG;
-
- if ($this->allow_pm == 'n')
- {
- return;
- }
-
- $this->_determine_request();
-
- $this->abstract_menu();
-
- /** --------------------------------
- /** Open/Close JavaScript
- /** --------------------------------*/
-
- if ($IN->GBL('myaccount_messages', 'COOKIE') && $IN->GBL('myaccount_messages', 'COOKIE') == 'on')
- {
- $text = '[-]';
- $hidden_style = '';
- }
- else
- {
- $text = '[+]';
- $hidden_style = 'display: none; padding:0;';
- }
-
- $hidden_link = '<a href="javascript:void(0);" id="extLink1" class="altLinks" onclick="showHide(1,this);return false;">'.$text.'</a>';
-
- /** --------------------------------
- /** Create Menu
- /** --------------------------------*/
-
- $map = array('bulletin_board', 'compose_message', 'folders', 'edit_folders', 'buddy_list', 'block_list');
-
- if ($this->allegiance == 'cp')
- {
- /** --------------------------------
- /** Menu Section + JavaScript
- /** --------------------------------*/
-
- $expand = '<img src="'.PATH_CP_IMG.'expand.gif" border="0" width="10" height="10" alt="Expand" /> ';
- $collapse = '<img src="'.PATH_CP_IMG.'collapse.gif" border="0" width="10" height="10" alt="Collapse" /> ';
-
- $pm_state = ($IN->GBL('M') == 'messages') ? TRUE : FALSE;
-
- $this->menu .= '<div id="menu_pm_h" style="display: '.(($pm_state == TRUE) ? 'none' : 'block').'; padding:0; margin: 0;">';
- $js = ' onclick="showhide_menu(\'menu_pm\');return false;" onmouseover="navTabOn(\'pmx\', \'tableHeadingAlt\', \'tableHeadingAltHover\');" onmouseout="navTabOff(\'pmx\', \'tableHeadingAlt\', \'tableHeadingAltHover\');" ';
- $this->menu .= $DSP->div();
- $this->menu .= "<div class='tableHeadingAlt' id='pmx' ".$js.">";
- $this->menu .= $expand.$LANG->line('private_messages');
- $this->menu .= $DSP->div_c();
- $this->menu .= $DSP->div_c();
- $this->menu .= $DSP->div_c();
-
- $this->menu .= '<div id="menu_pm_b" style="display: '.(($pm_state == TRUE) ? 'block' : 'none').'; padding:0; margin: 0;">';
-
- $js = ' onclick="showhide_menu(\'menu_pm\');return false;" onmouseover="navTabOn(\'pmx2\', \'tableHeadingAlt\', \'tableHeadingAltHover\');" onmouseout="navTabOff(\'pmx2\', \'tableHeadingAlt\', \'tableHeadingAltHover\');" ';
- $this->menu .= $DSP->div();
- $this->menu .= "<div class='tableHeadingAlt' id='pmx2' ".$js.">";
- $this->menu .= $collapse.$LANG->line('private_messages');
- $this->menu .= $DSP->div_c();
- $this->menu .= $DSP->div('profileMenuInner');
- /** --------------------------------
- /** Create Menu Based on Item Map
- /** --------------------------------*/
-
- foreach($map as $item)
- {
- if (isset($this->menu_items['repeat_items'][$item]))
- {
- foreach($this->menu_items['repeat_items'][$item] as $item_member)
- {
- $this->create_item($item_member);
- }
- }
- else
- {
- $this->create_item($this->menu_items['single_items'][$item]);
- }
- }
-
- $this->menu .= $DSP->div_c().$DSP->div_c().$DSP->div_c();
- }
- else
- {
- $template = $this->retrieve_template('message_menu');
- $rows = $this->retrieve_template('message_menu_rows');
-
- $this->single_parts['include']['hide_menu_style'] = $hidden_style;
- $this->single_parts['include']['hide_menu_link'] = $hidden_link;
- $this->single_parts['include']['hide_menu_js'] = $this->showhide_js();
-
- $this->single_parts['include']['menu_items'] = '';
-
- foreach($map as $item)
- {
- if (isset($this->menu_items['repeat_items'][$item]))
- {
- foreach($this->menu_items['repeat_items'][$item] as $item_member)
- {
- $this->single_parts['title'] = $item_member['text'];
- $this->single_parts['link'] = $item_member['link'];
-
- $this->single_parts['include']['menu_items'] .= $this->_process_template($rows);
- }
- }
- else
- {
- $this->single_parts['title'] = $this->menu_items['single_items'][$item]['text'];
- $this->single_parts['link'] = $this->menu_items['single_items'][$item]['link'];
-
- $this->single_parts['include']['menu_items'] .= $this->_process_template($rows);
- }
- }
-
- $this->menu = $this->_process_template($template);
- }
- }
- /* END */
-
-
- /** -----------------------------------
- /** Create Menu Item
- /** -----------------------------------*/
- function create_item($data)
- {
- global $DB, $DSP;
-
- $this->menu .= $DSP->div(($data['style'] != '') ? $data['style'] : 'navPad').
- $DSP->anchor($data['link'], $data['text']).
- $DSP->div_c();
- }
- /* END */
-
- // -----------------------------------
- // Inbox
- // This function is kind of superfluous, but I find it comforting
- // to know that there is an inbox function for a messaging system.
- // Besides, it makes it a tad easier to understand certain parts
- // of the code to have this function called opposed to what is
- // really being calling. That is all, move along now...
- // -----------------------------------
- function inbox()
- {
- $this->view_folder('1');
- }
- /* END */
-
- /** -----------------------------------
- /** Deleted Messages
- /** -----------------------------------*/
- function deleted()
- {
- $this->view_folder('0');
- }
- /* END */
- /** -----------------------------------
- /** View Folder Contents
- /** -----------------------------------*/
- function drafts()
- {
- global $LANG, $DB, $OUT, $IN, $LOC, $PREFS;
-
- $row_count = 0; // How many rows shown this far (i.e. offset)
-
- if ($this->allegiance == 'user')
- {
- $row_count = $this->cur_id;
- }
- else
- {
- $row_count = ($IN->GBL('page', 'GP') === false) ? 0 : $IN->GBL('page', 'GP');
- }
-
- if ( ! is_numeric($row_count))
- {
- $row_count = 0;
- }
-
- $this->single_parts['lang']['folder_id'] = '1';
- $this->single_parts['lang']['folder_name'] = $LANG->line('draft_messages');
- $this->conditionals['paginate'] = 'n';
-
- $this->conditionals['drafts_folder'] = 'y';
- $this->conditionals['sent_folder'] = 'n';
- $this->conditionals['trash_folder'] = 'n';
- $this->conditionals['regular_folder'] = 'n';
-
- /** ---------------------------------------
- /** Retrieve Folder Contents Query
- /** ---------------------------------------*/
-
- $dql = "SELECT
- exp_message_data.sender_id,
- exp_message_data.message_date,
- exp_message_data.message_id,
- exp_message_data.message_subject,
- exp_message_data.message_recipients,
- exp_message_data.message_cc,
- exp_message_data.message_attachments,
- exp_members.screen_name as sender,
- exp_members.username as sender_username ";
-
- $sql = "FROM exp_message_data
- LEFT JOIN exp_members ON exp_members.member_id = exp_message_data.sender_id
- WHERE exp_message_data.message_status = 'draft'
- AND exp_message_data.sender_id = '{$this->member_id}'
- ORDER BY exp_message_data.message_date ";
-
- /** ----------------------------------------
- /** Run "count" query for pagination
- /** ----------------------------------------*/
-
- $query = $DB->query("SELECT COUNT(exp_message_data.message_id) AS count ".$sql);
-
- /** ----------------------------------------
- /** If No Messages, we say so.
- /** ----------------------------------------*/
-
- if ($query->row['count'] == 0)
- {
- $this->title = $LANG->line('draft_messages');
- $this->crumb = $LANG->line('draft_messages');
-
- $this->single_parts['include']['folder_rows'] = $this->retrieve_template('message_no_folder_rows');
- $this->single_parts['form']['form_declaration']['modify_messages'] = '';
-
- $this->return_data = $this->folder_wrapper(($folder_id == '0') ? 'n' : 'y');
-
- return;
- }
-
- /** ----------------------------------------
- /** Determine Current Page
- /** ----------------------------------------*/
-
- $current_page = ($row_count / $this->per_page) + 1;
-
- $total_pages = intval($query->row['count'] / $this->per_page);
-
- if ($query->row['count'] % $this->per_page)
- {
- $total_pages++;
- }
-
- $this->single_parts['include']['page_count'] = $LANG->line('folder_page').' '.$current_page.' '.$LANG->line('of').' '.$total_pages;
-
- /** -----------------------------
- /** Do we need pagination?
- /** -----------------------------*/
-
- $pager = '';
-
- if ($query->row['count'] > $this->per_page)
- {
- if ( ! class_exists('Paginate'))
- {
- require PATH_CORE.'core.paginate'.EXT;
- }
-
- $PGR = new Paginate();
-
- if ($this->allegiance == 'user')
- {
- $PGR->path = $this->_create_path('drafts');
- }
- else
- {
- $PGR->base_url = $this->_create_path('drafts');
- $PGR->qstr_var = 'page';
- }
-
- $PGR->total_count = $query->row['count'];
- $PGR->per_page = $this->per_page;
- $PGR->cur_page = $row_count;
-
- $this->single_parts['include']['pagination_link'] = $PGR->show_links();
- $this->conditionals['paginate'] = 'y';
-
- $sql .= " LIMIT ".$row_count.", ".$this->per_page;
- }
-
- /** ----------------------------------------
- /** Retrieve Folder Contents
- /** ----------------------------------------*/
-
- $folder_rows_template = $this->retrieve_template('message_folder_rows');
- $r = '';
- $i = 0;
- $censor = FALSE;
-
- if ($PREFS->ini('enable_censoring') == 'y' && $PREFS->ini('censored_words') != '')
- {
- if ( ! class_exists('Typography'))
- {
- require PATH_CORE.'core.typography'.EXT;
- }
-
- $TYPE = new Typography(0);
- $censor = TRUE;
- }
-
- $query = $DB->query($dql.$sql);
-
- foreach($query->result as $row)
- {
- ++$i;
- $data = $row;
- $data['msg_id'] = 'd'.$row['message_id'];
- $data['message_date'] = $LOC->set_human_time($data['message_date']);
- $data['style'] = ($i % 2) ? 'tableCellTwo' : 'tableCellOne';
- $data['message_subject'] = ($censor === FALSE) ? $data['message_subject'] : $TYPE->filter_censored_words($data['message_subject']);
-
-
- if ($this->allegiance == 'user')
- {
- $data['message_url'] = $this->base_url.'compose/'.$row['message_id'].'/';
- }
- else
- {
- $data['message_url'] = $this->base_url.'compose'.AMP.'msg='.$row['message_id'];
- }
-
- $data['message_status'] = '';
-
- // This Requires Extra Queries and Processing
- // So We Only Do It When Those Variables Are Found
-
- if (stristr($folder_rows_template, '{recipients}') !== FALSE)
- {
- $data['recipients'] = htmlspecialchars($this->convert_recipients($row['message_recipients']), ENT_QUOTES);
- }
-
- if (stristr($folder_rows_template, '{cc}') !== FALSE)
- {
- $data['cc'] = htmlspecialchars($this->convert_recipients($row['message_cc']), ENT_QUOTES);
- }
-
- $r .= $this->_process_template($folder_rows_template, $data);
- }
-
- $this->single_parts['include']['folder_rows'] = $r;
-
- /** ----------------------------------------
- /** Return the Folder's Contents
- /** ----------------------------------------*/
-
- $this->title = $LANG->line('draft_messages');
- $this->crumb = $LANG->line('draft_messages');
- $this->return_data = $this->folder_wrapper('y', 'n', 'n');
- }
- /* END */
-
-
- /** -----------------------------------
- /** View Folder Contents
- /** -----------------------------------*/
- function view_folder($folder_id='')
- {
- global $LANG, $DB, $OUT, $IN, $LOC, $PREFS;
-
- // ---------------------------------
- // Find Requested Folder ID
- // $IN->QSTR - User
- // $IN->GBL('folder', 'GP') - CP
- // ---------------------------------
-
- $row_count = 0; // How many rows shown this far (i.e. offset)
-
- if ($folder_id == '')
- {
- if ($this->allegiance == 'user')
- {
- // Unknown, probably will have to do something similar to
- // the list of members where we have to create
- // a pseudo-query string in one of the URI segments
- // folder_pagenum : 1_1
-
- if ($this->cur_id == '')
- {
- $folder_id = 1;
- }
- else
- {
- $x = explode('_', $this->cur_id);
-
- $folder_id = ( ! is_numeric($x['0'])) ? 1 : $x['0'];
- $row_count = ( ! isset($x['1']) OR ! is_numeric($x['1'])) ? 0 : $x['1'];
- }
- }
- else
- {
- $folder_id = ($IN->GBL('folder', 'GP') === false) ? '1' : $IN->GBL('folder', 'GP');
- $row_count = ($IN->GBL('page', 'GP') === false) ? 0 : $IN->GBL('page', 'GP');
- }
- }
-
- if ( ! is_numeric($folder_id) OR $folder_id > $this->max_folders)
- {
- $folder_id = '1';
- }
-
- if ( ! is_numeric($row_count))
- {
- $row_count = 0;
- }
-
-
- /** ---------------------------------------
- /** Retrieve Folder Name for User
- /** ---------------------------------------*/
-
- if ($folder_id == '0')
- {
- $folder_name = $LANG->line('deleted_messages');
- }
- elseif ( ! isset($this->folders[$folder_id]['0']) OR $this->folders[$folder_id]['0'] == '')
- {
- if ($this->allegiance == 'cp')
- {
- return $DSP->no_access_message();
- }
- else
- {
- return $OUT->show_user_error('general', array($LANG->line('not_authorized')));
- }
- }
- else
- {
- $folder_name = $this->folders[$folder_id]['0'];
- }
-
- $this->single_parts['lang']['folder_name'] = $LANG->line('messages_folder').' - '.$folder_name;
- $this->single_parts['lang']['folder_id'] = $folder_id;
- $this->current_folder = $folder_id;
- $this->conditionals['paginate'] = 'n';
-
- /** -----------------------------------
- /** Folder Conditionals
- /** -----------------------------------*/
-
- $this->conditionals['drafts_folder'] = 'n';
- $this->conditionals['sent_folder'] = 'n';
- $this->conditionals['trash_folder'] = 'n';
- $this->conditionals['regular_folder'] = 'n';
-
- if ($folder_id == '0')
- {
- $this->conditionals['trash_folder'] = 'y';
- }
- elseif ($folder_id == '2')
- {
- $this->conditionals['sent_folder'] = 'y';
- }
- else
- {
- $this->conditionals['regular_folder'] = 'y';
- }
-
- /** ---------------------------------------
- /** Retrieve Folder Contents Query
- /** ---------------------------------------*/
-
- $dql = "SELECT
- exp_message_copies.message_status,
- exp_message_copies.message_id,
- exp_message_copies.message_read,
- exp_message_copies.copy_id as msg_id,
- exp_message_data.sender_id,
- exp_message_data.message_date,
- exp_message_data.message_subject,
- exp_message_data.message_recipients,
- exp_message_data.message_cc,
- exp_message_data.message_attachments,
- exp_members.screen_name as sender,
- exp_members.username as sender_username ";
-
- $sql = "FROM exp_message_copies
- LEFT JOIN exp_message_data ON exp_message_data.message_id = exp_message_copies.message_id
- LEFT JOIN exp_members ON exp_members.member_id = exp_message_copies.sender_id
- WHERE exp_message_copies.recipient_id = '{$this->member_id}' ";
-
- if ($folder_id == '0')
- {
- $sql .= "AND exp_message_copies.message_deleted = 'y' ";
- }
- else
- {
- $sql .= "AND exp_message_copies.message_folder = '{$folder_id}'
- AND exp_message_copies.message_deleted = 'n' ";
- }
-
- $sql .= "AND exp_message_data.message_status = 'sent'
- ORDER BY exp_message_data.message_date desc";
-
- /** ----------------------------------------
- /** Run "count" query for pagination
- /** ----------------------------------------*/
-
- $query = $DB->query("SELECT COUNT(exp_message_copies.copy_id) AS count ".$sql);
-
- /** ----------------------------------------
- /** If No Messages, we say so.
- /** ----------------------------------------*/
-
- if ($query->row['count'] == 0)
- {
- $this->title = $folder_name;
- $this->crumb = $folder_name;
-
- $this->single_parts['include']['folder_rows'] = $this->retrieve_template('message_no_folder_rows');
- $this->single_parts['form']['form_declaration']['modify_messages'] = '';
-
- $this->return_data = $this->folder_wrapper(($folder_id == '0') ? 'n' : 'y');
-
- return;
- }
-
- /** ----------------------------------------
- /** Determine Current Page
- /** ----------------------------------------*/
-
- $current_page = ($row_count / $this->per_page) + 1;
-
- $total_pages = intval($query->row['count'] / $this->per_page);
-
- if ($query->row['count'] % $this->per_page)
- {
- $total_pages++;
- }
-
- $this->single_parts['include']['page_count'] = $LANG->line('folder_page').' '.$current_page.' '.$LANG->line('of').' '.$total_pages;
-
- /** -----------------------------
- /** Do we need pagination?
- /** -----------------------------*/
-
- $pager = '';
-
- if ($query->row['count'] > $this->per_page)
- {
- if ( ! class_exists('Paginate'))
- {
- require PATH_CORE.'core.paginate'.EXT;
- }
-
- $PGR = new Paginate();
-
- if ($this->allegiance == 'user')
- {
- $PGR->path = $this->base_url.'view_folder/'.$folder_id.'_';
- }
- else
- {
- $PGR->base_url = $this->base_url.'view_folder'.AMP.'folder='.$folder_id;
- $PGR->qstr_var = 'page';
- }
-
- $PGR->total_count = $query->row['count'];
- $PGR->per_page = $this->per_page;
- $PGR->cur_page = $row_count;
-
- $this->single_parts['include']['pagination_link'] = $PGR->show_links();
- $this->conditionals['paginate'] = 'y';
-
- $sql .= " LIMIT ".$row_count.", ".$this->per_page;
- }
-
- $censor = FALSE;
-
- if ($PREFS->ini('enable_censoring') == 'y' && $PREFS->ini('censored_words') != '')
- {
- $censor = TRUE;
-
- if ( ! class_exists('Typography'))
- {
- require PATH_CORE.'core.typography'.EXT;
- }
-
- $TYPE = new Typography(0);
- }
- /** ----------------------------------------
- /** Retrieve Folder Contents
- /** ----------------------------------------*/
-
- $message_ids = array();
- $folder_rows_template = $this->retrieve_template('message_folder_rows');
- $i = 0;
- $r = '';
-
- $query = $DB->query($dql.$sql);
-
- foreach($query->result as $row)
- {
- $i++;
- $data = $row;
- $message_ids[] = $row['message_id'];
- $data['msg_id'] = ($row['message_read'] == 'n') ? 'u'.$row['msg_id'] : $row['msg_id'];
- $data['buddy_list_link'] = '';
- $data['block_list_link'] = '';
- $data['message_date'] = $LOC->set_human_time($data['message_date']);
- $data['style'] = ($i % 2) ? 'tableCellTwo' : 'tableCellOne';
-
- if ($censor == TRUE)
- {
- $data['message_subject'] = $TYPE->filter_censored_words($row['message_subject']);
- }
- if ($this->allegiance == 'user')
- {
- $data['message_url'] = $this->base_url.'view_message/'.$row['msg_id'].'/';
- //$data['buddy_list_link'] = $this->_create_path('add_buddy').$row['sender_id'].'/';
- //$data['block_list_link'] = $this->_create_path('add_block').$row['sender_id'].'/';
- }
- else
- {
- $data['message_url'] = $this->base_url.'view_message'.AMP.'msg='.$row['msg_id'];
- //$data['buddy_list_link'] = $this->_create_path('add_buddy').AMP.'id='.$row['sender_id'];
- //$data['block_list_link'] = $this->_create_path('add_block').AMP.'id='.$row['sender_id'];
- }
-
- // --------------------------------
- // Message Status Entities:
- // • - unread
- // → - forwarded
- // ↵ - Reply
- // --------------------------------
-
- if ($row['message_status'] == 'replied')
- {
- $data['message_status'] = '↵';
- }
- elseif ($row['message_status'] == 'forwarded')
- {
- $data['message_status'] = '→';
- }
- elseif ($row['message_read'] == 'y')
- {
- $data['message_status'] = '';
- }
- elseif($row['message_read'] == 'n')
- {
- $data['message_status'] = '•';
- }
-
- // This Requires Extra Queries and Processing
- // So We Only Do It When Those Variables Are Found
-
- if (stristr($folder_rows_template, '{recipients}') !== FALSE)
- {
- $data['recipients'] = htmlspecialchars($this->convert_recipients($row['message_recipients']), ENT_QUOTES);
- }
-
- if (stristr($folder_rows_template, '{cc}') !== FALSE)
- {
- $data['cc'] = htmlspecialchars($this->convert_recipients($row['message_cc']), ENT_QUOTES);
- }
-
- $r .= $this->_process_template($folder_rows_template, $data);
- }
-
- $this->single_parts['include']['folder_rows'] = $r;
-
- /** ----------------------------------------
- /** If Displayed, Messages are Received (not read)
- /** ----------------------------------------*/
-
- if (sizeof($message_ids) > 0 && $this->block_tracking == 'n')
- {
- $DB->query("UPDATE exp_message_copies SET message_received = 'y'
- WHERE recipient_id = '{$this->member_id}'
- AND message_id IN ('".implode("','",$message_ids)."')");
- }
-
- /** ----------------------------------------
- /** Return the Folder's Contents
- /** ----------------------------------------*/
-
- $this->title = $folder_name;
- $this->crumb = $folder_name;
- $this->return_data = $this->folder_wrapper(($folder_id == '0') ? 'n' : 'y');
- }
- /* END */
-
-
-
-
-
-
- /** ----------------------------------------
- /** Wrapper for a Folder and its Contents
- /** ----------------------------------------*/
- function folder_wrapper($deleted='y', $moved='y', $copied = 'y')
- {
- global $FNS;
-
- $folder_template = $this->retrieve_template('message_folder');
-
- $this->folders_pulldown();
-
- $this->single_parts['include']['hidden_js'] = $this->hidden_js();
- $this->single_parts['include']['toggle_js'] = $this->toggle_js();
- $this->single_parts['path']['compose_message'] = $this->_create_path('compose');
- $this->single_parts['path']['erase_messages'] = $this->_create_path('erase');
-
- $details = array('hidden_fields' => array('this_folder' => $this->single_parts['lang']['folder_id'], 'daction' => ''),
- 'action' => $this->_create_path('modify_messages'),
- 'id' => 'target',
- 'enctype' => 'multi',
- 'secure' => ($this->allegiance == 'cp') ? FALSE : TRUE
- );
-
- $this->single_parts['form']['form_declaration']['modify_messages'] = $FNS->form_declaration($details);
- /** ---------------------------------
- /** Move, Copy, Delete Buttons
- /** ---------------------------------*/
-
- $this->_buttons($deleted, $moved, $copied);
-
- /** -------------------------------
- /** Storage Graph
- /** -------------------------------*/
-
- if ( ! isset($this->single_parts['image']['messages_graph']))
- {
- $this->storage_graph();
- }
-
- return $this->_process_template($folder_template);
- }
- /* END */
-
-
- /** ----------------------------------------
- /** Buttons for Various Pages
- /** ----------------------------------------*/
- function _buttons($deleted='y', $moved='y', $copied = 'y')
- {
- global $LANG;
-
- $style = 'buttons';
-
-
- /** ---------------------------------
- /** Move, Copy, Delete Buttons
- /** ---------------------------------*/
-
- if ($deleted == 'n')
- {
- $this->single_parts['form']['delete_button'] = '';
- }
- else
- {
- $this->single_parts['form']['delete_button'] = "<button type='submit' id='delete' name='delete' value='delete' ".
- "class='{$style}' title='{lang:delete_selected}' ".
- "onclick='dynamic_action(\"delete\");'>".
- "{lang:messages_delete}</button> ";
- }
-
- if ($moved == 'n')
- {
- $this->single_parts['form']['move_button'] = '';
- }
- else
- {
- $this->single_parts['form']['move_button'] = "<button type='submit' id='move' name='move' value='move' ".
- "class='{$style}' title='{lang:move_selected}' ".
- "onclick='dynamic_move();return false;'>".
- "{lang:messages_move}</button>".NBS.NBS;
- }
-
- if ($copied == 'n')
- {
- $this->single_parts['form']['copy_button'] = '';
- }
- else
- {
- $this->single_parts['form']['copy_button'] = "<button type='submit' id='copy' name='copy' value='copy' ".
- "class='{$style}' title='{lang:copy_selected}' ".
- "onclick='dynamic_copy();return false;'>".
- "{lang:messages_copy}</button>".NBS.NBS;
- }
-
- $this->single_parts['form']['forward_button'] = "<button type='submit' id='forward' name='forward' value='forward' ".
- "…
Large files files are truncated, but you can click here to view the full file