/** * Sets internal data based on data fetched from a join * @param array $data */ public function setFromSqlJoin($data, $app = '') { $app = $app ? $app : IPS_APP_COMPONENT; $data = $this->_fetchModule($app)->convertData($data); $_key = array(); $_data = array(); /* Check key */ if (empty($data['item_key'])) { return $data; } foreach ($this->_dbFields as $field) { if (isset($data[$field])) { $_data[$field] = $data[$field]; unset($data[$field]); } } if (count($_data) && empty($_data['item_is_deleted'])) { if (IPSLib::isSerialized($_data['item_read_array'])) { $_data['item_read_array'] = unserialize($_data['item_read_array']); } $this->_itemMarkers[$app][$_data['item_key']] = $_data; } /* Recommend you always use the returned array as it removes the marking data to reduce memory footprint */ return $data; }
/** * Show the add forum dialog */ protected function _showAddForumDialog() { $type = trim($this->request['type']); $rules = $this->archiveWriter->getRulesFromDb(); $current = array(); if (IPSLib::isSerialized($rules[$type]['forum']['text'])) { $current = unserialize($rules[$type]['forum']['text']); } $multiSelect = $this->registry->class_forums->forumsForumJump(1, 0, 1, $current, true); $this->returnHtml($this->html->showAddForumDialog($multiSelect, $type)); }
/** * Save the form * * @return @e void [Outputs to screen] */ protected function save() { //----------------------------------------- // INIT //----------------------------------------- $name = trim(IPSText::alphanumericalClean($this->request['name'])); $this->hookId = intval($this->request['id']); $this->hook = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'core_hooks', 'where' => 'hook_id=' . $this->hookId)); $this->data = IPSLib::isSerialized($this->hook['hook_extra_data']) ? unserialize($this->hook['hook_extra_data']) : array('display' => array()); $output = ''; //----------------------------------------- // Got a hook? //----------------------------------------- if (!$this->hook['hook_id']) { $this->returnJsonError($this->lang->words['hook_cannot_load']); } //----------------------------------------- // Run the proper operation //----------------------------------------- switch ($name) { case 'settings': $_settingGroups = $this->hooksFunctions->getSettingGroups(); $_settings = $this->hooksFunctions->getSettings(); $toSave = array(); $toDisplay = array(); $toSave['settingGroups'] = array(); $toSave['settings'] = array(); if (is_array($this->request['setting_groups']) and count($this->request['setting_groups'])) { $toSave['settingGroups'] = $this->request['setting_groups']; foreach ($_settingGroups as $data) { if (in_array($data[0], $toSave['settingGroups'])) { $toDisplay['settingGroups'][] = $data[1]; } } } if (is_array($this->request['settings']) and count($this->request['settings'])) { $toSave['settings'] = $this->request['settings']; foreach ($_settings as $data) { if (in_array($data[0], $toSave['settings'])) { $toDisplay['settings'][] = $data[1]; } } } if (count($toSave['settingGroups'])) { $this->data['settingGroups'] = $toSave['settingGroups']; } else { unset($this->data['settingGroups']); } if (count($toSave['settings'])) { $this->data['settings'] = $toSave['settings']; } else { unset($this->data['settings']); } if (count($toDisplay['settingGroups'])) { $output .= "{$this->lang->words['hook_setting_groups']} " . implode(', ', $toDisplay['settingGroups']); } if (count($toDisplay['settings'])) { if (count($toDisplay['settingGroups'])) { $output .= '<br />'; } $output .= "{$this->lang->words['hook_settings']} " . implode(', ', $toDisplay['settings']); } if ($output) { $this->data['display']['settings'] = $output; } else { $output = $this->lang->words['hook_no_settings']; if (isset($this->data['display']['settings'])) { unset($this->data['display']['settings']); } } break; case 'language': $_langFiles = $this->hooksFunctions->getLanguageFiles(); $ids = array(); $files = array(); $strings = array(); $toDisplay = array(); $this->data['language'] = array(); foreach ($_POST as $k => $v) { if (preg_match("/^language_(\\d+)\$/", $k, $matches)) { $files[$matches[1]] = $v; $strings[$matches[1]] = $this->request['strings_' . $matches[1]]; $ids[$matches[1]] = $matches[1]; } } foreach ($ids as $id) { if ($files[$id] and $strings[$id]) { $this->data['language'][$files[$id]] = $strings[$id]; $toDisplay[] = "{$this->lang->words['hook_from']} {$files[$id]}: " . implode(', ', $strings[$id]); } } if (!count($this->data['language'])) { unset($this->data['language']); } if (count($toDisplay)) { $output .= implode('<br />', $toDisplay); } if ($output) { $this->data['display']['language'] = $output; } else { $output = $this->lang->words['hook_no_language']; if (isset($this->data['display']['language'])) { unset($this->data['display']['language']); } } break; case 'modules': $_modules = $this->hooksFunctions->getModules(); $toSave = array(); $toDisplay = array(); if (is_array($this->request['modules']) and count($this->request['modules'])) { $toSave = $this->request['modules']; } foreach ($_modules as $data) { if (in_array($data[0], $toSave)) { $toDisplay[] = $data[1]; } } if (count($toDisplay)) { $output .= "{$this->lang->words['hook_modules']} " . implode(', ', $toDisplay); } if (count($toSave)) { $this->data['modules'] = $toSave; } else { unset($this->data['modules']); } if ($output) { $this->data['display']['modules'] = $output; } else { $output = $this->lang->words['hook_no_modules']; if (isset($this->data['display']['modules'])) { unset($this->data['display']['modules']); } } break; case 'help': $_help = $this->hooksFunctions->getHelpFiles(); $toSave = array(); $toDisplay = array(); if (is_array($this->request['help']) and count($this->request['help'])) { $toSave = $this->request['help']; } foreach ($_help as $data) { if (in_array($data[0], $toSave)) { $toDisplay[] = $data[1]; } } if (count($toDisplay)) { $output .= "{$this->lang->words['hook_help']} " . implode(', ', $toDisplay); } if (count($toSave)) { $this->data['help'] = $toSave; } else { unset($this->data['help']); } if ($output) { $this->data['display']['help'] = $output; } else { $output = $this->lang->words['hook_no_help']; if (isset($this->data['display']['help'])) { unset($this->data['display']['help']); } } break; case 'skins': $_skinFiles = $this->hooksFunctions->getSkinGroups(); $ids = array(); $files = array(); $templates = array(); $toDisplay = array(); $this->data['templates'] = array(); foreach ($_POST as $k => $v) { if (preg_match("/^skin_(\\d+)\$/", $k, $matches)) { $files[$matches[1]] = $v; $_templates = array(); foreach ($this->request['templates_' . $matches[1]] as $v) { if ($v) { $templates[$matches[1]][] = $v; } } $ids[$matches[1]] = $matches[1]; } } foreach ($ids as $id) { if ($files[$id] and $templates[$id]) { $this->data['templates'][$files[$id]] = $templates[$id]; $toDisplay[] = "{$this->lang->words['hook_from']} {$files[$id]}: " . implode(', ', $templates[$id]); } } if (!count($this->data['templates'])) { unset($this->data['templates']); } if (count($toDisplay)) { $output .= implode('<br />', $toDisplay); } if ($output) { $this->data['display']['templates'] = $output; } else { $output = $this->lang->words['hook_no_skin']; if (isset($this->data['display']['templates'])) { unset($this->data['display']['templates']); } } break; case 'css': /* INIT */ $_cssFiles = $this->hooksFunctions->getCSSFiles(); $toSave = array(); $toDisplay = array(); /* Check to see if any were selected */ if (is_array($this->request['css']) && count($this->request['css'])) { $toSave = $this->request['css']; } /* Output */ foreach ($_cssFiles as $data) { if (in_array($data[0], $toSave)) { $toDisplay[] = $data[1]; } } if (count($toDisplay)) { $output .= "{$this->lang->words['hook_css']} " . implode(', ', $toDisplay); } /* Save */ if (count($toSave)) { $this->data['css'] = $toSave; } else { unset($this->data['css']); } if ($output) { $this->data['display']['css'] = $output; } else { $output = $this->lang->words['hook_no_css']; if (isset($this->data['display']['css'])) { unset($this->data['display']['css']); } } break; case 'replacements': /* INIT */ $_replacements = $this->hooksFunctions->getSkinReplacements(); $toSave = array(); $toDisplay = array(); /* Check to see if any were selected */ if (is_array($this->request['replacements']) && count($this->request['replacements'])) { $toSave = $this->request['replacements']; } /* Output */ foreach ($_replacements as $data) { if (in_array($data[0], $toSave)) { $toDisplay[] = $data[1]; } } if (count($toDisplay)) { $output .= "{$this->lang->words['hook_replacements']} " . implode(', ', $toDisplay); } /* Save */ if (count($toSave)) { $this->data['replacements'] = $toSave; } else { unset($this->data['replacements']); } if ($output) { $this->data['display']['replacements'] = $output; } else { $output = $this->lang->words['hook_no_replacements']; if (isset($this->data['display']['replacements'])) { unset($this->data['display']['replacements']); } } break; case 'tasks': $_tasks = $this->hooksFunctions->getTasks(); $toSave = array(); $toDisplay = array(); if (is_array($this->request['tasks']) and count($this->request['tasks'])) { $toSave = $this->request['tasks']; } foreach ($_tasks as $data) { if (in_array($data[0], $toSave)) { $toDisplay[] = $data[1]; } } if (count($toDisplay)) { $output .= "{$this->lang->words['hook_tasks']} " . implode(', ', $toDisplay); } if (count($toSave)) { $this->data['tasks'] = $toSave; } else { unset($this->data['tasks']); } if ($output) { $this->data['display']['tasks'] = $output; } else { $output = $this->lang->words['hook_no_tasks']; if (isset($this->data['display']['tasks'])) { unset($this->data['display']['tasks']); } } break; case 'database': $types = array(array('0', $this->lang->words['hook_db_select']), array('create', $this->lang->words['hook_db_create']), array('alter', $this->lang->words['hook_db_alter']), array('update', $this->lang->words['hook_db_update']), array('insert', $this->lang->words['hook_db_insert'])); $alters = array(array('add', $this->lang->words['hook_db_addnew']), array('change', $this->lang->words['hook_db_change']), array('remove', $this->lang->words['hook_db_drop'])); $ids = array(); $toDisplay = array(); $this->data['database'] = array(); /* Since this is more complicated, just get ids for now... */ foreach ($_POST as $k => $v) { if (preg_match("/^type_(\\d+)\$/", $k, $matches)) { $ids[$matches[1]] = $matches[1]; } } /* Now loop through and set stuff properly.. */ foreach ($ids as $id) { $type = $this->request['type_' . $id]; if (!$type) { continue; } switch ($type) { case 'create': $name = $this->request['name_' . $id]; $fields = IPSText::br2nl($_POST['fields_' . $id]); $tabletype = $this->request['tabletype_' . $id]; if (!$name or !$fields) { continue; } $this->data['database']['create'][] = array('name' => $name, 'fields' => $fields, 'tabletype' => $tabletype); $text = "CREATE TABLE {$name} (\r\r\n\t\t\t\t\t\t\t\t\t\t{$fields}\r\r\n\t\t\t\t\t\t\t\t\t\t)"; if ($tabletype) { $text .= " ENGINE=" . $tabletype; } $toDisplay[] = nl2br($text); break; case 'alter': $altertype = $this->request['altertype_' . $id]; $table = $this->request['table_' . $id]; $field = $this->request['field_' . $id]; $newfield = $this->request['newfield_' . $id]; $fieldtype = $this->request['fieldtype_' . $id]; $default = $_POST['default_' . $id]; if (!$altertype or !$table or !$field) { continue; } $this->data['database']['alter'][] = array('altertype' => $altertype, 'table' => $table, 'field' => $field, 'newfield' => $newfield, 'fieldtype' => $fieldtype, 'default' => $default); $text = "ALTER TABLE {$table}"; switch ($altertype) { case 'add': $text .= " ADD {$field} {$fieldtype}"; if ($default !== '') { $text .= " DEFAULT {$default}"; } break; case 'change': $text .= " CHANGE {$field} {$newfield} {$fieldtype}"; if ($default !== '') { $text .= " DEFAULT {$default}"; } break; case 'remove': $text .= " DROP {$field}"; break; } $toDisplay[] = nl2br($text); break; case 'update': $table = $this->request['table_' . $id]; $field = $this->request['field_' . $id]; $newvalue = $_POST['newvalue_' . $id]; $oldvalue = $_POST['oldvalue_' . $id]; $where = $_POST['where_' . $id]; if (!$table or !$field or !$newvalue) { continue; } $this->data['database']['update'][] = array('table' => $table, 'field' => $field, 'newvalue' => $newvalue, 'oldvalue' => $oldvalue, 'where' => $where); $text = "UPDATE {$table} SET {$field}='{$newvalue}'"; if ($where) { $text .= " WHERE " . $where; } $toDisplay[] = nl2br($text); break; case 'insert': $table = $this->request['table_' . $id]; $updates = $_POST['updates_' . $id]; $fordelete = $_POST['fordelete_' . $id]; if (!$table or !$updates) { continue; } $this->data['database']['insert'][] = array('table' => $table, 'updates' => $updates, 'fordelete' => $fordelete); $cols = array(); $vals = array(); $index = 0; $toins = explode(',', $updates); foreach ($toins as $insertQuery) { $piece = explode('=', $insertQuery); $cols[$index] = $piece[0]; $vals[$index] = $piece[1]; $index++; } $text = "INSERT INTO {$table} ("; $text .= implode(', ', $cols); $text .= ") VALUES ('"; $text .= implode("', '", $vals); $text .= "')"; $toDisplay[] = nl2br($text); break; } } if (!count($this->data['database'])) { unset($this->data['database']); } if (count($toDisplay)) { $output .= implode('<br />', $toDisplay); } if ($output) { $this->data['display']['database'] = $output; } else { $output = $this->lang->words['hook_no_db']; if (isset($this->data['display']['database'])) { unset($this->data['display']['database']); } } break; case 'custom': $toSave = ''; $toDisplay = ''; if ($this->request['custom']) { $toSave = $this->request['custom']; $toDisplay = $this->request['custom']; } if ($toDisplay) { $output .= "install_" . $toDisplay; } if ($toSave) { $this->data['custom'] = $toSave; } else { unset($this->data['custom']); } if ($output) { $this->data['display']['custom'] = $output; } else { $output = $this->lang->words['hook_no_custom']; if (isset($this->data['display']['custom'])) { unset($this->data['display']['custom']); } } break; } /* Handle array data and save to DB */ if (empty($this->data['display'])) { unset($this->data['display']); } $this->DB->update('core_hooks', array('hook_extra_data' => count($this->data) ? serialize($this->data) : ''), 'hook_id=' . $this->hookId); //----------------------------------------- // Print... //----------------------------------------- $return = array('success' => true, 'message' => $output); $this->returnJsonArray($return); }
/** * Edit a post * * Usage: * $post->setForumID(1); * $post->setTopicID(5); * $post->setPostID(100); * $post->setAuthor( $member ); * * $post->setPostContent( "Hello [b]there![/b]" ); * # Optional: No bbcode, etc parsing will take place * # $post->setPostContentPreFormatted( "Hello <b>there!</b>" ); * $post->editPost(); * * Exception Error Codes: * NO_POSTING_PPD : No post ID set * NO_CONTENT : No post content set * CONTENT_TOO_LONG : Post is too long * * @return mixed */ public function editPost() { //----------------------------------------- // Global checks and functions //----------------------------------------- try { $this->globalSetUp(); } catch (Exception $error) { $e = $error->getMessage(); if ($e != 'NO_POSTING_PPD') { $this->_postErrors = $error->getMessage(); } } if ($this->_bypassPermChecks !== TRUE && IPSMember::isOnModQueue($this->getAuthor()) === NULL) { $this->_postErrors = 'warnings_restrict_post_perm'; } if (!$this->getPostContent() and !$this->getPostContentPreFormatted()) { $this->_postErrors = 'NO_CONTENT'; } //----------------------------------------- // Get topic //----------------------------------------- try { $topic = $this->editSetUp(); } catch (Exception $error) { $this->_postErrors = $error->getMessage(); } //----------------------------------------- // Parse the post, and check for any errors. //----------------------------------------- $post = $this->compilePostData(); //----------------------------------------- // Do we have a valid post? //----------------------------------------- if (strlen(trim(IPSText::removeControlCharacters(IPSText::br2nl($post['post'])))) < 1) { $this->_postErrors = 'NO_CONTENT'; } if (IPSText::mbstrlen($post['post']) > $this->settings['max_post_length'] * 1024) { $this->_postErrors = 'CONTENT_TOO_LONG'; } if ($this->_postErrors != "") { //----------------------------------------- // Show the form again //----------------------------------------- return FALSE; } //----------------------------------------- // Ajax specifics //----------------------------------------- if ($this->getIsAjax() === TRUE) { # Prevent polls from being edited $this->can_add_poll = 0; # Prevent titles from being edited $this->edit_title = 0; # Prevent open time from being edited $this->can_set_open_time = 0; # Prevent close time from being edited $this->can_set_close_time = 0; # Set Settings $this->setSettings(array('enableSignature' => $this->_originalPost['use_sig'] ? 1 : 0, 'enableEmoticons' => $this->_originalPost['use_emo'] ? 1 : 0, 'post_htmlstatus' => $this->getSettings('post_htmlstatus'))); if (!$this->getAuthor('g_append_edit')) { $this->request['add_edit'] = ($this->_originalPost['append_edit'] or !$this->getAuthor('g_append_edit') ? 1 : 0); } } //----------------------------------------- // Compile the poll //----------------------------------------- if ($this->can_add_poll) { //----------------------------------------- // Load the poll from the DB //----------------------------------------- $this->poll_data = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'polls', 'where' => "tid=" . intval($topic['tid']))); $this->poll_answers = !empty($this->poll_data['choices']) && IPSLib::isSerialized($this->poll_data['choices']) ? IPSLib::safeUnserialize(stripslashes($this->poll_data['choices'])) : array(); } //----------------------------------------- // Compile the poll //----------------------------------------- $this->poll_questions = $this->compilePollData(); if ($this->_postErrors != "" or $this->getIsPreview() === TRUE) { //----------------------------------------- // Show the form again //----------------------------------------- return FALSE; } /* Got a topics table to update? */ $updateTopicTable = array(); //----------------------------------------- // Reset some data //----------------------------------------- $post['ip_address'] = $this->_originalPost['ip_address']; $post['topic_id'] = $this->_originalPost['topic_id']; $post['author_id'] = $this->_originalPost['author_id']; $post['post_date'] = $this->_originalPost['post_date']; $post['author_name'] = $this->_originalPost['author_name']; $post['queued'] = $this->_originalPost['queued']; $post['edit_time'] = $this->getDate() ? $this->getDate() : IPS_UNIX_TIME_NOW; $post['edit_name'] = $this->getAuthor('members_display_name'); if ($this->_originalPost['new_topic'] == 1) { /* Tagging */ if (isset($_POST['ipsTags'])) { $this->registry->tags->replace($_POST['ipsTags'], array('meta_id' => $topic['tid'], 'meta_parent_id' => $topic['forum_id'], 'member_id' => $this->memberData['member_id'], 'meta_visible' => $topic['approved'])); } /* Like if not ajax edit */ if (!IPS_IS_AJAX) { $this->addTopicToTracker($topic['tid']); } //----------------------------------------- // Update open and close times //----------------------------------------- if ($this->can_set_open_time and $this->times['open']) { $updateTopicTable['topic_open_time'] = intval($this->times['open']); if ($topic['topic_open_time'] and $this->times['open']) { $updateTopicTable['state'] = 'closed'; if (IPS_UNIX_TIME_NOW > $topic['topic_open_time']) { if (IPS_UNIX_TIME_NOW < $topic['topic_close_time']) { $updateTopicTable['state'] = 'open'; } } } if (!$this->times['open'] and $topic['topic_open_time']) { if ($topic['state'] == 'closed') { $updateTopicTable['state'] = 'open'; } } } else { if ($this->can_set_open_time and $topic['topic_open_time']) { $updateTopicTable['topic_open_time'] = 0; } } if ($this->can_set_close_time and $this->times['close']) { $updateTopicTable['topic_close_time'] = intval($this->times['close']); //----------------------------------------- // Was a close time, but not now? //----------------------------------------- if (!$this->times['close'] and $topic['topic_close_time']) { if ($topic['state'] == 'closed') { $updateTopicTable['state'] = 'open'; } } } else { if ($this->can_set_close_time and $topic['topic_close_time']) { $updateTopicTable['topic_close_time'] = 0; } } if ($this->edit_title) { if ($this->getForumID() != $topic['forum_id']) { $updateTopicTable['forum_id'] = $this->getForumID(); } } } //----------------------------------------- // Update poll //----------------------------------------- if ($this->can_add_poll) { if (is_array($this->poll_questions) and count($this->poll_questions)) { $poll_only = 0; if ($this->settings['ipb_poll_only'] and $this->request['poll_only'] == 1) { $poll_only = 1; } $poll_view_voters = !$this->poll_data['votes'] ? $this->request['poll_view_voters'] : $this->poll_data['poll_view_voters']; if ($topic['poll_state']) { $_pollData = array('votes' => intval($this->poll_total_votes), 'choices' => addslashes(serialize($this->poll_questions)), 'poll_question' => IPSText::stripAttachTag($this->request['poll_question']), 'poll_only' => $poll_only, 'poll_view_voters' => intval($poll_view_voters)); /* Data Hook Location */ IPSLib::doDataHooks($_pollData, 'editPostUpdatePoll'); $this->DB->update('polls', $_pollData, 'tid=' . $topic['tid']); if ($this->poll_data['choices'] != serialize($this->poll_questions) or $this->poll_data['votes'] != intval($this->poll_total_votes)) { $this->DB->insert('moderator_logs', array('forum_id' => $this->getForumData('id'), 'topic_id' => $topic['tid'], 'post_id' => $this->_originalPost['pid'], 'member_id' => $this->getAuthor('member_id'), 'member_name' => $this->getAuthor('members_display_name'), 'ip_address' => $this->ip_address, 'http_referer' => htmlspecialchars(my_getenv('HTTP_REFERER')), 'ctime' => IPS_UNIX_TIME_NOW, 'topic_title' => $topic['title'], 'action' => $this->lang->words['edited_poll'], 'query_string' => htmlspecialchars(my_getenv('QUERY_STRING')))); } } else { $_pollData = array('tid' => $topic['tid'], 'forum_id' => $this->getForumData('id'), 'start_date' => IPS_UNIX_TIME_NOW, 'choices' => addslashes(serialize($this->poll_questions)), 'starter_id' => $this->getAuthor('member_id'), 'votes' => 0, 'poll_question' => IPSText::stripAttachTag($this->request['poll_question']), 'poll_only' => $poll_only, 'poll_view_voters' => intval($poll_view_voters)); /* Data Hook Location */ IPSLib::doDataHooks($_pollData, 'editPostAddPoll'); $this->DB->insert('polls', $_pollData); $this->DB->insert('moderator_logs', array('forum_id' => $this->getForumData('id'), 'topic_id' => $topic['tid'], 'post_id' => $this->_originalPost['pid'], 'member_id' => $this->getAuthor('member_id'), 'member_name' => $this->getAuthor('members_display_name'), 'ip_address' => $this->ip_address, 'http_referer' => htmlspecialchars(my_getenv('HTTP_REFERER')), 'ctime' => IPS_UNIX_TIME_NOW, 'topic_title' => $topic['title'], 'action' => sprintf($this->lang->words['added_poll'], $this->request['poll_question']), 'query_string' => htmlspecialchars(my_getenv('QUERY_STRING')))); /* Update topics table later */ $updateTopicTable['poll_state'] = 1; $updateTopicTable['last_vote'] = 0; } } else { /* Remove the poll */ $this->DB->delete('polls', 'tid=' . $topic['tid']); $this->DB->delete('voters', 'tid=' . $topic['tid']); /* Update topics table later */ $updateTopicTable['poll_state'] = 0; $updateTopicTable['last_vote'] = 0; } } //----------------------------------------- // Update topic title? //----------------------------------------- if ($this->edit_title == 1) { //----------------------------------------- // Update topic title //----------------------------------------- if ($this->_topicTitle != "") { if ($this->_topicTitle != $topic['title'] or !$topic['title_seo']) { $updateTopicTable['title'] = $this->_topicTitle; $updateTopicTable['title_seo'] = IPSText::makeSeoTitle($this->_topicTitle); $_forumUpdate = array(); if ($topic['tid'] == $this->getForumData('last_id')) { $_forumUpdate['last_title'] = $updateTopicTable['title']; $_forumUpdate['seo_last_title'] = $updateTopicTable['title_seo']; } if ($topic['tid'] == $this->getForumData('newest_id')) { $_forumUpdate['newest_title'] = $updateTopicTable['title']; } if (count($_forumUpdate)) { $this->DB->update('forums', $_forumUpdate, 'id=' . $this->getForumData('id')); } if ($this->moderator['edit_topic'] == 1 or $this->getAuthor('g_is_supmod') == 1) { $this->DB->insert('moderator_logs', array('forum_id' => $this->getForumData('id'), 'topic_id' => $topic['tid'], 'post_id' => $this->_originalPost['pid'], 'member_id' => $this->getAuthor('member_id'), 'member_name' => $this->getAuthor('members_display_name'), 'ip_address' => $this->ip_address, 'http_referer' => htmlspecialchars(my_getenv('HTTP_REFERER')), 'ctime' => IPS_UNIX_TIME_NOW, 'topic_title' => $topic['title'], 'action' => sprintf($this->lang->words['edited_topic_title'], $topic['title'], $this->_topicTitle), 'query_string' => htmlspecialchars(my_getenv('QUERY_STRING')))); } } } } //----------------------------------------- // Reason for edit? //----------------------------------------- if ($this->_bypassPermChecks or isset($this->moderator['edit_post']) && $this->moderator['edit_post'] or $this->getAuthor('g_is_supmod')) { $post['post_edit_reason'] = trim($this->request['post_edit_reason']); } //----------------------------------------- // Update the database (ib_forum_post) //----------------------------------------- $post['append_edit'] = 1; if ($this->_bypassPermChecks or $this->getAuthor('g_append_edit')) { if ($this->request['add_edit'] != 1) { $post['append_edit'] = 0; } } /* HTML Status */ $post['post_htmlstate'] = $this->getSettings('post_htmlstatus'); /* Typecast */ $this->DB->setDataType('post_edit_reason', 'string'); /* Data Hook Location */ IPSLib::doDataHooks($post, 'editPostData'); $this->DB->update('posts', $post, 'pid=' . $this->_originalPost['pid']); /* Got a topic to update? */ $updateTopicTable['post_data'] = $post; $updateTopicTable['forum_data'] = $this->getForumData(); IPSLib::doDataHooks($updateTopicTable, 'editPostTopicData'); unset($updateTopicTable['post_data'], $updateTopicTable['forum_data']); // Remove added data if (count($updateTopicTable)) { $this->DB->update('topics', $updateTopicTable, 'tid=' . $topic['tid']); } /* remove saved content */ if ($this->memberData['member_id']) { $this->editor->removeAutoSavedContent(array('member_id' => $this->memberData['member_id'], 'autoSaveKey' => 'edit-' . intval($this->_originalPost['pid']))); } /* Add to cache */ IPSContentCache::update($this->_originalPost['pid'], 'post', $this->formatPostForCache($post['post'])); /* Upload Attachments */ $this->uploadAttachments($this->post_key, $this->_originalPost['pid']); //----------------------------------------- // Make attachments "permanent" //----------------------------------------- $this->makeAttachmentsPermanent($this->post_key, $this->_originalPost['pid'], 'post', array('topic_id' => $topic['tid'])); //----------------------------------------- // Make sure paperclip symbol is OK //----------------------------------------- $this->recountTopicAttachments($topic['tid']); //----------------------------------------- // Leave data for other apps //----------------------------------------- $this->setTopicData($topic); $this->setPostData(array_merge($this->_originalPost, $post)); return TRUE; }
/** * Get a user's session * @param int $skinSetId */ public function getSessionBySkinId($skinSetId) { $session = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'skin_generator_sessions', 'where' => 'sg_skin_set_id=' . intval($skinSetId))); if (!empty($session['sg_session_id'])) { if (IPSLib::isSerialized($session['sg_data'])) { $session['sg_data_array'] = unserialize($session['sg_data']); if (IPSLib::isSerialized($session['sg_data_array']['set_skin_gen_data'])) { $session['skin_gen_data'] = unserialize($session['sg_data_array']['set_skin_gen_data']); } } return $session; } else { return false; } }
/** * Rebuilds the mobile user agents from the skin set data */ public function rebuildMobileSkinUserAgentsFromSetDataXml() { /* Init */ $mobileSkinSet = $this->fetchSkinData($this->fetchSetIdByKey('mobile', true), true); $xmlData = array(); /* Grab xml */ require_once IPS_KERNEL_PATH . 'classXML.php'; /*noLibHook*/ $xml = new classXML('UTF-8'); /* Skin Set Data */ $xml->load(IPS_ROOT_PATH . 'setup/xml/skins/setsData.xml'); foreach ($xml->fetchElements('set') as $xmlelement) { $data = $xml->fetchElementsFromRecord($xmlelement); if ($data['set_key'] == 'mobile') { $xmlData = $data; break; } } /* Update */ if ($xmlData['set_key'] && IPSLib::isSerialized($xmlData['set_locked_uagent']) && IPSLib::isSerialized($mobileSkinSet['set_locked_uagent'])) { $new = unserialize($xmlData['set_locked_uagent']); $old = unserialize($mobileSkinSet['set_locked_uagent']); /* Merge them */ foreach ($new['groups'] as $group) { if (!in_array($group, $old['groups'])) { $old['groups'][] = $group; } } foreach ($new['uagents'] as $agent => $version) { if (!in_array($agent, $new['uagents'])) { $old['uagents'][$agent] = $version; } } } if (is_array($old) && count($old)) { $this->DB->update('skin_collections', array('set_locked_uagent' => serialize($old)), "set_key='mobile'"); } }
/** * Return a cached item * @param string $key */ public function get($key) { $data = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'cache_simple', 'where' => 'cache_id=\'' . $this->DB->addSlashes($this->_makeId($key)) . '\' AND cache_perm_key=\'' . $this->DB->addSlashes($this->_makePermKey()) . '\'')); if (!empty($data['cache_id'])) { if (!$this->_isStale($data)) { /* Do we need to unserialize this? */ $data['cache_data'] = IPSLib::isSerialized($data['cache_data']) ? unserialize($data['cache_data']) : $data['cache_data']; return array('data' => $data['cache_data'], 'time' => $data['cache_time']); } } return null; }
/** * Check if the hook meets all the requirements * * @param mixed $hook Can be an hook ID or an array of the hook data * @return @e array Errors found */ public function checkHookRequirements($hook) { /* Init vars */ $hookData = array(); $reqsData = array(); $errors = array(); /* We already have some data? */ if (is_array($hook) && count($hook)) { $hookData = $hook; } elseif (is_int($hook)) { $hookData = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'core_hooks', 'where' => 'hook_id=' . $hook)); } /* Requirements are still serialized? */ if (IPSLib::isSerialized($hookData['hook_requirements'])) { $hookData['hook_requirements'] = unserialize($hookData['hook_requirements']); } /* Make our var shorter... */ $reqsData =& $hookData['hook_requirements']; /* Old data? - @todo: remove this check around 3.3(4?) */ if (!isset($reqsData['required_applications']['core']) && isset($reqsData['hook_ipb_version_min']) && ($reqsData['hook_ipb_version_min'] > 0 || $reqsData['hook_ipb_version_max'] > 0)) { $reqsData['hook_ipb_version_min'] = $reqsData['hook_ipb_version_min'] < 30000 ? 30000 : $reqsData['hook_ipb_version_min']; $reqsData['required_applications']['core'] = array('min_version' => intval($reqsData['hook_ipb_version_min']), 'max_version' => intval($reqsData['hook_ipb_version_max'])); } //----------------------------------------- // Let's start checking requirements //----------------------------------------- /* PHP */ if ($reqsData['hook_php_version_min'] or $reqsData['hook_php_version_max']) { if ($reqsData['hook_php_version_min'] and version_compare(PHP_VERSION, $reqsData['hook_php_version_min'], '<') == true) { $errors['php_min'] = sprintf($this->lang->words['h_phpold'], $reqsData['hook_php_version_min']); } if ($reqsData['hook_php_version_max'] and version_compare(PHP_VERSION, $reqsData['hook_php_version_max'], '>') == true) { $errors['php_max'] = sprintf($this->lang->words['h_phpnew'], $reqsData['hook_php_version_max']); } } /* Additional applications */ if (is_array($reqsData['required_applications']) && count($reqsData['required_applications'])) { /* Get the setup class */ require_once IPS_ROOT_PATH . 'setup/sources/base/setup.php'; /*noLibHook*/ /* Loop through all apps */ foreach ($reqsData['required_applications'] as $appKey => $appData) { /* Versions file doesn't exist? */ if (!is_file(IPSLib::getAppDir($appKey) . '/xml/versions.xml')) { $errors[$appKey . '_app'] = sprintf($this->lang->words['hook_require_appnotfound'], $appData['app_name']); } elseif (!IPSLib::appIsInstalled($appKey)) { $errors[$appKey . '_app'] = sprintf($this->lang->words['hook_require_appdisabled'], ipsRegistry::$applications[$appKey]['app_title']); } elseif ($appData['min_version'] or $appData['max_version']) { /* Fetch and check versions */ if (!isset($this->cachedVersions[$appKey])) { $this->cachedVersions[$appKey] = IPSSetUp::fetchXmlAppVersions($appKey); } $versions = $this->cachedVersions[$appKey]; if (is_array($versions) && count($versions)) { if (!isset($this->cachedUpgradeInfo[$appKey])) { $_key = in_array($appKey, array('forums', 'members')) ? 'core' : $appKey; $this->cachedUpgradeInfo[$_key] = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'upgrade_history', 'where' => "upgrade_app='{$_key}'", 'order' => 'upgrade_version_id DESC', 'limit' => array(1))); /* Extra caching for the three core apps */ if (in_array($appKey, array('core', 'forums', 'members'))) { $this->cachedUpgradeInfo['core'] = $this->cachedUpgradeInfo[$_key]; $this->cachedUpgradeInfo['forums'] = $this->cachedUpgradeInfo[$_key]; $this->cachedUpgradeInfo['members'] = $this->cachedUpgradeInfo[$_key]; } } /* Do we meet tha requirements? */ if ($appData['min_version'] and $this->cachedUpgradeInfo[$appKey]['upgrade_version_id'] < $appData['min_version']) { $errors[$appKey . '_min'] = sprintf($this->lang->words['hook_require_tooold'], isset($versions[$appData['min_version']]) ? $versions[$appData['min_version']] : $appData['min_version']); } if ($appData['max_version'] and $this->cachedUpgradeInfo[$appKey]['upgrade_version_id'] > $appData['max_version']) { $errors[$appKey . '_max'] = sprintf($this->lang->words['hook_require_toonew'], isset($versions[$appData['max_version']]) ? $versions[$appData['max_version']] : $appData['max_version']); } } } } } return $errors; }
/** * Formats cached data * @param array $tags * @return array */ protected function _formatCachedData($tags) { if (!is_array($tags) or !count($tags) or empty($tags['tag_cache_text'])) { return null; } /* Unserialise */ if (!IPSLib::isSerialized($tags['tag_cache_text'])) { return null; } $tagData = unserialize($tags['tag_cache_text']); $tagData['formatted'] = array(); if (is_array($tagData['tags']) and count($tagData['tags'])) { $tagData['formatted'] = $this->formatTagsForDisplay($tagData['tags'], $tags['tag_cache_key']); $tagData['formatted']['prefix'] = false; } else { return null; } if (!empty($tagData['prefix'])) { $tagData['formatted']['prefix'] = $this->registry->output->getTemplate($this->skin())->tagPrefix($tagData['prefix'], $this->getApp(), $this->getSearchSection()); } return $tagData; }
/** * Build a WHERE segment * @param string $key * @param data $data * @param boolean $archiveOn Archive = true, skip = false */ protected function _buildQueryBit($key, $data, $archiveOn) { $strOp = $archiveOn ? '=' : '!='; $inOp = $archiveOn ? 'IN' : 'NOT IN'; switch ($key) { case 'state': if ($data['value'] != '' && $data['value'] != '-') { return $this->getDbFieldFromKey($key) . $strOp . "'" . $data['value'] . "'"; } break; case 'pinned': case 'approved': case 'poll': if ($data['value'] != '' && $data['value'] != '-') { return $this->getDbFieldFromKey($key) . $strOp . intval($data['value']); } break; case 'post': case 'view': case 'rating': if (is_numeric($data['text']) && $data['text'] > 0) { return $this->getDbFieldFromKey($key) . $data['value'] . intval($data['text']); } break; case 'lastpost': if (is_numeric($data['text']) && $data['text'] > 0) { switch ($data['unit']) { case 'd': $seconds = 86400; break; case 'm': $seconds = 2592000; break; case 'y': $seconds = 31536000; break; } $time = IPS_UNIX_TIME_NOW - $seconds * intval($data['text']); /* Switch around for skipping */ $data['value'] = $archiveOn ? $data['value'] : ($data['value'] == '>' ? '<' : '>'); return $this->getDbFieldFromKey($key) . ' ' . $data['value'] . ' ' . $time; } break; case 'forum': case 'member': if ($data['text']) { if (IPSLib::isSerialized($data['text'])) { $ids = unserialize($data['text']); } else { $ids = array(); } $inOp = $data['value'] == '+' ? 'IN' : 'NOT IN'; if (is_array($ids) && count($ids)) { return $this->getDbFieldFromKey($key) . ' ' . $inOp . '(' . implode(',', $ids) . ')'; } } break; } return null; }
/** * Get restore data */ public function getRestoreData() { $data = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'core_archive_restore')); if (IPSLib::isSerialized($data['restore_manual_tids'])) { $data['restore_manual_tids'] = unserialize($data['restore_manual_tids']); } else { $data['restore_manual_tids'] = array(); } return $data; }
/** * Sets items to the cache * @param MIXED (int or memberData ) $member * @param array $store */ public static function setToMemberCache($member, $store) { $cache = array(); if (is_integer($member)) { $member = self::load($member, 'core'); } elseif ($member['member_id'] and !isset($member['members_cache'])) { $member = self::load($member['member_id'], 'core'); } /* Check */ if (empty($member['member_id']) or !is_array($store)) { return false; } /* fetch current cache */ if (IPSLib::isSerialized($member['members_cache'])) { $cache = IPSLib::safeUnserialize($member['members_cache']); } /* loop and update */ foreach ($store as $k => $v) { $cache[$k] = $v; } /* Save */ ipsRegistry::DB()->update('members', array('members_cache' => serialize($cache)), 'member_id=' . $member['member_id']); /* Update local cache */ if (self::$data['member_id'] == $member['member_id']) { self::$data['_cache'] = $cache; self::$data['members_cache'] = serialize($cache); } }
/** * Archive Rules overview * * @return @e void */ protected function _archiveRules() { /* Get archive count so far */ $counts = $this->archiveWriter->getArchivePossibleCount(); $rules = $this->archiveWriter->getRulesFromDb(); if ($counts['count'] < 1) { $textString = $this->lang->words['archive_no_query']; } else { $textString = sprintf($this->lang->words['archive_x_query'], $counts['percentage'], $this->lang->formatNumber($counts['count']), $this->lang->formatNumber($counts['total'])); } /* Post process */ foreach (array('archive', 'skip') as $type) { if (!empty($rules[$type]['forum']['text'])) { $ids = IPSLib::isSerialized($rules[$type]['forum']['text']) ? unserialize($rules[$type]['forum']['text']) : array(); if (count($ids)) { foreach ($ids as $fid) { $data = $this->registry->class_forums->getForumbyId($fid); if ($data['id']) { $rules[$type]['forum']['_parseData'][$fid] = array('data' => $this->registry->class_forums->getForumbyId($fid), 'nav' => $this->html->buildForumNav($this->registry->class_forums->forumsBreadcrumbNav($fid, 'showforum=', true))); } } } } if (!empty($rules[$type]['member']['text'])) { $ids = IPSLib::isSerialized($rules[$type]['member']['text']) ? unserialize($rules[$type]['member']['text']) : array(); if (count($ids)) { $members = IPSMember::load($ids, 'all'); foreach ($members as $id => $data) { $members[$id] = IPSMember::buildProfilePhoto($members[$id]); $members[$id]['photoTag'] = IPSMember::buildPhotoTag($members[$id], 'inset'); } foreach ($ids as $fid) { $rules[$type]['member']['_parseData']['count'] = count($members); $rules[$type]['member']['_parseData']['data'] = $members; } } } } /* Show rules page */ $this->registry->output->html .= $this->html->archiveRules(IPSText::jsonEncodeForTemplate($rules), $textString); }
/** * Gets 'like' data for this item * * @param array ( id, type, app ) * @return array * */ public function getLikeData($data) { $store = array('cache_data' => array()); $expired = false; if (IPSLib::isSerialized($data['rep_like_cache'])) { $store = unserialize($data['rep_like_cache']); if (empty($store['cache_expire']) or time() >= $store['cache_expire']) { $expired = true; $store = array(); } } if (!isset($data['rep_like_cache']) or $expired === true) { unset($data['rep_like_cache']); $store = $this->getLikeRawData($data); $this->DB->replace('reputation_cache', array('app' => $data['app'], 'type' => $data['type'], 'type_id' => $data['id'], 'rep_points' => intval($store['cache_data']['count']), 'cache_date' => time(), 'rep_like_cache' => serialize($store)), array('app', 'type', 'type_id')); } return $store['cache_data']; }