/**
  * Run this task
  * 
  * @return	@e void
  */
 public function runTask()
 {
     /* Run it */
     $itemsRemoved = IPSContentCache::prune();
     $log = $itemsRemoved === FALSE ? $this->lang->words['errorcleaningcontentcache'] : sprintf($this->lang->words['contentcache_cleaned'], $itemsRemoved);
     $this->class->appendTaskLog($this->task, $log);
     $this->class->unlockTask($this->task);
 }
Example #2
0
 /**
  * Formats / grabs extra data for results
  * Takes an array of IDS (can be IDs from anything) and returns an array of expanded data.
  *
  * @param	array 	$ids			Ids
  * @param	array	$followData		Retrieve the follow meta data
  * @return array
  */
 public function processResults($ids, $followData = array())
 {
     /* INIT */
     $sort_by = IPSSearchRegistry::get('in.search_sort_by');
     $sort_order = IPSSearchRegistry::get('in.search_sort_order');
     $search_term = IPSSearchRegistry::get('in.clean_search_term');
     $content_title_only = IPSSearchRegistry::searchTitleOnly();
     $_post_joins = array();
     $members = array();
     $results = array();
     $topicIds = array();
     $dots = array();
     $sortKey = '';
     $sortType = '';
     $_sdTids = array();
     $_sdPids = array();
     /* Set up some basic permissions */
     $permissions['PostSoftDeleteSee'] = $this->registry->getClass('class_forums')->canSeeSoftDeletedPosts(0);
     $permissions['TopicSoftDeleteSee'] = $this->registry->getClass('class_forums')->canSeeSoftDeletedTopics(0);
     $permissions['canQueue'] = $this->registry->getClass('class_forums')->canQueuePosts(0);
     $permissions['SoftDeleteReason'] = $this->registry->getClass('class_forums')->canSeeSoftDeleteReason(0);
     $permissions['SoftDeleteContent'] = $this->registry->getClass('class_forums')->canSeeSoftDeleteContent(0);
     $permissions['PostSoftDeleteRestore'] = $this->registry->getClass('class_forums')->can_Un_SoftDeletePosts(0);
     $permissions['TopicSoftDeleteRestore'] = $this->registry->getClass('class_forums')->can_Un_SoftDeleteTopics(0);
     /* Got some? */
     if (count($ids)) {
         /* Cache? */
         if (IPSContentCache::isEnabled()) {
             if (IPSContentCache::fetchSettingValue('post')) {
                 $_post_joins[] = IPSContentCache::join('post', 'p.' . $this->table['pid']);
             }
             if (IPSContentCache::fetchSettingValue('sig')) {
                 $_post_joins[] = IPSContentCache::join('sig', 'p.' . $this->table['author_id'], 'ccb', 'left', 'ccb.cache_content as cache_content_sig, ccb.cache_updated as cache_updated_sig');
             }
         }
         if ($this->registry->tags->isEnabled()) {
             $_post_joins[] = $this->registry->tags->getCacheJoin(array('meta_id_field' => 't.tid'));
         }
         /* Sorting */
         switch ($sort_by) {
             default:
             case 'date':
                 $sortKey = IPSSearchRegistry::get('set.returnType') == 'tids' ? 'last_post' : $this->table['post_date'];
                 $sortType = 'numerical';
                 break;
             case 'title':
                 $sortKey = 'title';
                 $sortType = 'string';
                 break;
             case 'posts':
                 $sortKey = 'posts';
                 $sortType = 'numerical';
                 break;
             case 'views':
                 $sortKey = 'views';
                 $sortType = 'numerical';
                 break;
         }
         /* Set vars */
         IPSSearch::$ask = $sortKey;
         IPSSearch::$aso = strtolower($sort_order);
         IPSSearch::$ast = $sortType;
         /* If we are search in titles only, then the ID array will be TIDs */
         if (IPSSearchRegistry::get('set.returnType') == 'tids') {
             $k = 'tid';
             $this->DB->build(array('select' => "t.*", 'from' => array('topics' => 't'), 'where' => 't.tid IN( ' . implode(',', $ids) . ')', 'add_join' => array_merge(array(array('select' => 'p.*', 'from' => array($this->table['_table_'] => 'p'), 'where' => 'p.' . $this->table['pid'] . '=t.topic_firstpost', 'type' => 'left'), array('select' => 'm.member_id, m.members_display_name, m.members_seo_name', 'from' => array('members' => 'm'), 'where' => 'm.member_id=p.' . $this->table['author_id'], 'type' => 'left')), $_post_joins)));
         } else {
             $k = $this->table['pid'];
             $this->DB->build(array('select' => "p.*", 'from' => array($this->table['_table_'] => 'p'), 'where' => 'p.' . $this->table['pid'] . ' IN( ' . implode(',', $ids) . ')', 'add_join' => array_merge(array(array('select' => 't.*', 'from' => array('topics' => 't'), 'where' => 't.tid=p.' . $this->table['topic_id'], 'type' => 'left'), array('select' => 'm.member_id, m.members_display_name, m.members_seo_name', 'from' => array('members' => 'm'), 'where' => 'm.member_id=p.' . $this->table['author_id'], 'type' => 'left')), $_post_joins)));
         }
         /* Grab data */
         $this->DB->execute();
         /* Grab the results */
         while ($row = $this->DB->fetch()) {
             $_rows[$row[$k]] = $this->searchArchives ? $this->archiveReader->archiveToNativeFields($row) : $row;
         }
         /* Get the 'follow' meta data? */
         if (count($followData)) {
             $followData = classes_like_meta::get($followData);
             /* Merge the data from the follow class into the results */
             foreach ($followData as $_formatted) {
                 $_rows[$_formatted['like_rel_id']]['_followData'] = $_formatted;
             }
         }
         /* Sort */
         if (count($_rows)) {
             usort($_rows, array("IPSSearch", "usort"));
             foreach ($_rows as $id => $row) {
                 /* Prevent member from stepping on it */
                 $row['topic_title'] = $row['title'];
                 /* Get author data? */
                 if ($k == 'tid') {
                     if (!empty($row['last_poster_id'])) {
                         $members[$row['last_poster_id']] = $row['last_poster_id'];
                     }
                 } else {
                     if (!empty($row['author_id'])) {
                         $members[$row['author_id']] = $row['author_id'];
                     }
                 }
                 /* Topic ids? */
                 if (!empty($row['topic_id'])) {
                     $topicIds[$row['topic_id']] = $row['topic_id'];
                 }
                 /* If we're using sphinx, check forum permissions again as the 15 minute delta rebuild could expose a moved topic before deltas rebuild.
                    We don't need to do this for SQL search as the results are delivered live and lets face it, we can do without the load  */
                 if ($this->settings['search_method'] != 'traditional') {
                     /* Can we read? */
                     if (!$this->registry->permissions->check('view', $this->registry->class_forums->forum_by_id[$row['forum_id']])) {
                         continue;
                     }
                     /* Can read, but is it password protected, etc? */
                     if (!$this->registry->class_forums->forumsCheckAccess($row['forum_id'], 0, 'forum', array(), true)) {
                         continue;
                     }
                 }
                 $row['cleanSearchTerm'] = urlencode($search_term);
                 $row['topicPrefix'] = $row['pinned'] ? $this->registry->getClass('output')->getTemplate('forum')->topicPrefixWrap($this->lang->words['pre_pinned']) : '';
                 $row['_isVisible'] = $this->registry->getClass('class_forums')->fetchHiddenTopicType($row) == 'visible' ? true : false;
                 $row['_isHidden'] = $this->registry->getClass('class_forums')->fetchHiddenTopicType($row) == 'hidden' ? true : false;
                 $row['_isDeleted'] = $this->registry->getClass('class_forums')->fetchHiddenTopicType($row) == 'sdelete' ? true : false;
                 $row['_p_isVisible'] = $this->registry->getClass('class_forums')->fetchHiddenType($row) == 'visible' ? true : false;
                 $row['_p_isHidden'] = $this->registry->getClass('class_forums')->fetchHiddenType($row) == 'hidden' ? true : false;
                 $row['_p_isDeleted'] = $this->registry->getClass('class_forums')->fetchHiddenType($row) == 'sdelete' ? true : false;
                 /* Hidden and we do not have permission? */
                 if ($row['_isHidden'] and !$permissions['canQueue']) {
                     continue;
                 }
                 /* Is the topic deleted? If so, then the first post will appear as such */
                 if ($row['_isDeleted'] and $permissions['TopicSoftDeleteSee']) {
                     $row['_p_isDeleted'] = true;
                     $_sdPids[$row['pid']] = $row['pid'];
                 }
                 /* Collect TIDS of soft deleted topics */
                 if ($row['_isDeleted']) {
                     if ($permissions['TopicSoftDeleteSee']) {
                         $_sdTids[$row['tid']] = $row['tid'];
                     } else {
                         continue;
                     }
                 }
                 /* Collect TIDS of soft deleted topics */
                 if ($row['_p_isDeleted']) {
                     if ($permissions['PostSoftDeleteSee']) {
                         $_sdPids[$row['pid']] = $row['pid'];
                     } else {
                         continue;
                     }
                 }
                 /* Tags */
                 if (!empty($row['tag_cache_key'])) {
                     $row['tags'] = $this->registry->tags->formatCacheJoinData($row);
                 }
                 $results[$k == 'tid' ? $row['tid'] : $row['pid']] = $this->genericizeResults($row);
             }
         }
         /* Need to load members? */
         if (count($members)) {
             $mems = IPSMember::load($members, 'all');
             $mems[0] = array();
             foreach ($results as $id => $r) {
                 $_memberIdColumn = IPSSearchRegistry::get('set.returnType') == 'tids' ? 'last_poster_id' : 'author_id';
                 if (isset($mems[$r[$_memberIdColumn]])) {
                     $mems[$r[$_memberIdColumn]]['m_posts'] = $mems[$r[$_memberIdColumn]]['posts'];
                     unset($mems[$r[$_memberIdColumn]]['last_post']);
                     if (isset($r['cache_content_sig'])) {
                         $mems[$r[$_memberIdColumn]]['cache_content'] = $r['cache_content_sig'];
                         $mems[$r[$_memberIdColumn]]['cache_updated'] = $r['cache_updated_sig'];
                     }
                     $_mem = IPSMember::buildDisplayData($mems[$r[$_memberIdColumn]], array('reputation' => 0, 'warn' => 0));
                     unset($_mem['cache_content'], $_mem['cache_updated']);
                     $results[$id]['_realPosts'] = $results[$id]['posts'];
                     $results[$id] = array_merge($results[$id], $_mem);
                     $results[$id]['posts'] = $results[$id]['_realPosts'];
                 }
             }
         }
         /* Generate 'dot' folder icon */
         if ($this->settings['show_user_posted'] and count($topicIds)) {
             $_queued = $this->registry->class_forums->fetchPostHiddenQuery(array('visible'), '');
             $this->DB->build(array('select' => 'author_id, topic_id', 'from' => 'posts', 'where' => $_queued . ' AND author_id=' . $this->memberData['member_id'] . ' AND topic_id IN(' . implode(',', $topicIds) . ')'));
             $this->DB->execute();
             while ($p = $this->DB->fetch()) {
                 $dots[$p['topic_id']] = 1;
             }
             /* Merge into results */
             foreach ($results as $id => $r) {
                 if (isset($dots[$r['topic_id']])) {
                     $results[$id]['_hasPosted'] = 1;
                 }
             }
         }
         /* Got any deleted items */
         if (count($_sdTids)) {
             $sData = IPSDeleteLog::fetchEntries($_sdTids, 'topic', false);
             if (count($sData)) {
                 foreach ($results as $id => $data) {
                     if (isset($_sdTids[$data['tid']])) {
                         $results[$id]['sData'] = $sData[$data['tid']];
                         $results[$id]['permissions'] = $permissions;
                     }
                 }
             }
         }
         /* Got any deleted items */
         if (count($_sdPids)) {
             $sData = IPSDeleteLog::fetchEntries($_sdPids, 'post', false);
             if (count($sData)) {
                 foreach ($results as $id => $data) {
                     if (isset($_sdPids[$data['pid']]) and !isset($results[$id]['sData'])) {
                         $results[$id]['sData'] = $sData[$data['pid']];
                         $results[$id]['permissions'] = $permissions;
                     }
                 }
             }
         }
     }
     return $results;
 }
 /**
  * Delete a topic
  *
  * @access	public
  * @param	mixed 		Topic id | Array of topic ids
  * @param	boolean		Skip updating the stats
  * @return	boolean
  */
 public function topicDelete($id, $nostats = 0)
 {
     $posts = array();
     $attach = array();
     $this->error = "";
     if (is_array($id)) {
         $id = IPSLib::cleanIntArray($id);
         if (count($id) > 0) {
             $tid = " IN(" . implode(",", $id) . ")";
         } else {
             return false;
         }
     } else {
         if (intval($id)) {
             $tid = "={$id}";
         } else {
             return false;
         }
     }
     //-----------------------------------------
     // Remove polls assigned to this topic
     //-----------------------------------------
     $this->DB->delete('polls', "tid" . $tid);
     $this->DB->delete('voters', "tid" . $tid);
     $this->DB->delete('tracker', "topic_id" . $tid);
     $this->DB->delete('topic_ratings', "rating_tid" . $tid);
     $this->DB->delete('topic_views', "views_tid" . $tid);
     $this->DB->delete('topics', "tid" . $tid);
     //-----------------------------------------
     // Get PIDS for attachment deletion
     //-----------------------------------------
     $this->DB->build(array('select' => 'pid', 'from' => 'posts', 'where' => "topic_id" . $tid));
     $this->DB->execute();
     while ($r = $this->DB->fetch()) {
         $posts[] = $r['pid'];
     }
     /* Remove cache content */
     IPSContentCache::drop('post', $posts);
     //-----------------------------------------
     // Remove the attachments
     //-----------------------------------------
     require_once IPSLib::getAppDir('core') . '/sources/classes/attach/class_attach.php';
     $class_attach = new class_attach($this->registry);
     $class_attach->type = 'post';
     $class_attach->init();
     $class_attach->bulkRemoveAttachment($posts);
     //-----------------------------------------
     // Remove the posts
     //-----------------------------------------
     $this->DB->delete('posts', "topic_id" . $tid);
     $this->DB->delete('search_index', "type='forum' AND type_2='topic' AND type_id_2 " . $tid);
     $this->DB->delete('reputation_cache', "app='forums' AND type='pid' AND type_id " . $tid);
     $this->DB->delete('reputation_index', "app='forums' AND type='pid' AND type_id " . $tid);
     //-----------------------------------------
     // Recount forum...
     //-----------------------------------------
     if (!$nostats) {
         if ($this->forum['id']) {
             $this->registry->class_forums->allForums[$this->forum['id']]['_update_deletion'] = 1;
             $this->forumRecount($this->forum['id']);
         }
         $this->statsRecount();
     }
     return TRUE;
 }
Example #4
0
 /**
  * Post multi-mod: Merge posts
  *
  * @return	@e void		[Outputs to screen]
  */
 protected function _multiMergePost()
 {
     $this->_resetModerator($this->topic['forum_id']);
     $this->_genericPermissionCheck('split_merge');
     if (count($this->pids) < 2) {
         $this->_showError('mod_only_one_pid', 10383);
     }
     //-----------------------------------------
     // Form or print?
     //-----------------------------------------
     if (!$this->request['checked']) {
         //-----------------------------------------
         // Get post data
         //-----------------------------------------
         $master_post = "";
         $dropdown = array();
         $authors = array();
         $seen_author = array();
         $upload_html = "";
         $seoTitle = '';
         //-----------------------------------------
         // Grab teh posts
         //-----------------------------------------
         $this->DB->build(array('select' => 'p.*', 'from' => array('posts' => 'p'), 'where' => "p.pid IN (" . implode(",", $this->pids) . ")", 'add_join' => array(array('select' => 't.forum_id, t.title_seo', 'from' => array('topics' => 't'), 'where' => 't.tid=p.topic_id', 'type' => 'left'))));
         $outer = $this->DB->execute();
         while ($p = $this->DB->fetch($outer)) {
             if (IPSMember::checkPermissions('read', $p['forum_id']) == TRUE) {
                 $master_post .= $p['post'] . "<br /><br />";
                 $dropdown[] = array($p['pid'], ipsRegistry::getClass('class_localization')->getDate($p['post_date'], 'LONG') . " (#{$p['pid']})");
                 if (!in_array($p['author_id'], $seen_author)) {
                     $authors[] = array($p['author_id'], "{$p['author_name']} (#{$p['pid']})");
                     $seen_author[] = $p['author_id'];
                 }
                 $seoTitle = $p['title_seo'];
             }
         }
         //-----------------------------------------
         // Get Attachment Data
         //-----------------------------------------
         $this->DB->build(array('select' => '*', 'from' => 'attachments', 'where' => "attach_rel_module='post' AND attach_rel_id IN (" . implode(",", $this->pids) . ")"));
         $this->DB->execute();
         while ($row = $this->DB->fetch()) {
             $row['image'] = $this->caches['attachtypes'][$row['attach_ext']]['atype_img'];
             $row['size'] = IPSLib::sizeFormat($row['attach_filesize']);
             $row['attach_file'] = IPSText::truncate($row['attach_file'], 50);
             $attachments[] = $row;
         }
         //-----------------------------------------
         // Print form
         //-----------------------------------------
         /* Load editor stuff */
         $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/editor/composite.php', 'classes_editor_composite');
         $_editor = new $classToLoad();
         $_editor->setContent(trim($master_post));
         $editor = $_editor->show('Post', array('autoSaveKey' => md5('merge-' . $this->topic['tid']), 'height' => 350));
         $this->output .= $this->registry->getClass('output')->getTemplate('mod')->mergePostForm($editor, $dropdown, $authors, $attachments, $seoTitle);
         if ($this->topic['tid']) {
             $this->registry->getClass('output')->addNavigation($this->topic['title'], "showtopic={$this->topic['tid']}", $this->topic['title_seo'], 'showtopic');
         }
         $this->registry->getClass('output')->addNavigation($this->lang->words['cm_title'], '');
         $this->registry->getClass('output')->setTitle($this->lang->words['cm_title'] . ' - ' . ipsRegistry::$settings['board_name']);
         $this->registry->output->addContent($this->output);
         $this->registry->getClass('output')->sendOutput();
     } else {
         //-----------------------------------------
         // DO THE THING, WITH THE THING!!
         //-----------------------------------------
         $this->request['postdate'] = intval($this->request['postdate']);
         if (empty($this->request['selectedpids']) || empty($this->request['postdate']) || empty($this->request['Post'])) {
             $this->_showError('mod_merge_posts', 10384);
         }
         /* Load editor stuff */
         $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/editor/composite.php', 'classes_editor_composite');
         $_editor = new $classToLoad();
         /* remove saved content */
         if ($this->memberData['member_id']) {
             $_editor->removeAutoSavedContent(array('member_id' => $this->memberData['member_id'], 'autoSaveKey' => md5('merge-' . $this->topic['tid'])));
         }
         IPSText::getTextClass('bbcode')->parse_smilies = 1;
         IPSText::getTextClass('bbcode')->parse_html = 0;
         IPSText::getTextClass('bbcode')->parse_bbcode = 1;
         IPSText::getTextClass('bbcode')->parsing_section = 'topics';
         $post = $_editor->process($_POST['Post']);
         $post = IPSText::getTextClass('bbcode')->preDbParse($post);
         //-----------------------------------------
         // Post to keep...
         //-----------------------------------------
         $posts = array();
         $author = array();
         $post_to_delete = array();
         $new_post_key = md5(time());
         $topics = array();
         $forums = array();
         $append_edit = 0;
         //-----------------------------------------
         // Grab teh posts
         //-----------------------------------------
         $this->DB->build(array('select' => 'p.*', 'from' => array('posts' => 'p'), 'where' => "p.pid IN (" . implode(",", $this->pids) . ")", 'add_join' => array(array('select' => 't.forum_id', 'from' => array('topics' => 't'), 'where' => 't.tid=p.topic_id', 'type' => 'left'))));
         $outer = $this->DB->execute();
         while ($p = $this->DB->fetch($outer)) {
             $posts[$p['pid']] = $p;
             $topics[$p['topic_id']] = $p['topic_id'];
             $forums[$p['forum_id']] = $p['forum_id'];
             if ($p['author_id'] == $this->request['postauthor']) {
                 $author = array('id' => $p['author_id'], 'name' => $p['author_name']);
             }
             if ($p['pid'] != $this->request['postdate']) {
                 $post_to_delete[] = $p['pid'];
             }
             if ($p['append_edit']) {
                 $append_edit = 1;
             }
         }
         //-----------------------------------------
         // Update main post...
         //-----------------------------------------
         $this->DB->update('posts', array('author_id' => $author['id'], 'author_name' => $author['name'], 'post' => $post, 'post_key' => $new_post_key, 'edit_time' => time(), 'edit_name' => $this->memberData['members_display_name'], 'append_edit' => ($append_edit or !$this->memberData['g_append_edit']) ? 1 : 0), 'pid=' . $this->request['postdate']);
         /* Run moderation sync */
         $this->modLibrary->runModSync('postMerge', $this->pids, $this->request['postdate']);
         //-----------------------------------------
         // Fix attachments
         //-----------------------------------------
         $attach_keep = array();
         $attach_kill = array();
         foreach ($_POST as $key => $value) {
             if (preg_match('/^attach_(\\d+)$/', $key, $match)) {
                 if ($this->request[$match[0]] == 'keep') {
                     $attach_keep[] = $match[1];
                 } else {
                     $attach_kill[] = $match[1];
                 }
             }
         }
         $attach_keep = IPSLib::cleanIntArray($attach_keep);
         $attach_kill = IPSLib::cleanIntArray($attach_kill);
         //-----------------------------------------
         // Keep
         //-----------------------------------------
         if (count($attach_keep)) {
             $this->DB->update('attachments', array('attach_rel_id' => $this->request['postdate'], 'attach_post_key' => $new_post_key, 'attach_member_id' => $author['id']), 'attach_id IN(' . implode(",", $attach_keep) . ')');
         }
         //-----------------------------------------
         // Kill Attachments
         //-----------------------------------------
         if (count($attach_kill)) {
             $classToLoad = IPSLib::loadLibrary(IPSLib::getAppDir('core') . '/sources/classes/attach/class_attach.php', 'class_attach');
             $class_attach = new $classToLoad($this->registry);
             $class_attach->type = 'post';
             $class_attach->init();
             $class_attach->bulkRemoveAttachment($attach_kill, 'attach_id');
         }
         //-----------------------------------------
         // Kill old posts
         //-----------------------------------------
         if (count($post_to_delete)) {
             $this->DB->delete('posts', 'pid IN(' . implode(",", $post_to_delete) . ')');
             IPSDeleteLog::removeEntries($post_to_delete, 'post', TRUE);
             /* Handle Rep */
             $this->DB->delete('reputation_cache', "app='forums' AND type='pid' AND type_id IN(" . implode(",", $post_to_delete) . ")");
             $this->DB->delete('reputation_index', "app='forums' AND type='pid' AND type_id IN(" . implode(",", $post_to_delete) . ")");
             foreach ($post_to_delete as $post) {
                 $this->DB->delete('reputation_totals', "rt_key=MD5('forums;pid;" . $post . "') AND rt_type_id=" . $post);
             }
         }
         foreach ($topics as $t) {
             $this->modLibrary->rebuildTopic($t, 0);
         }
         foreach ($forums as $f) {
             $this->modLibrary->forumRecount($f);
         }
         $this->cache->rebuildCache('stats', 'global');
         /* Clear the content cache */
         IPSContentCache::drop('post', $this->pids);
         $this->_addModeratorLog(sprintf($this->lang->words['acp_merged_posts'], implode(", ", $this->pids)));
     }
 }
Example #5
0
 /**
  * Delete a topic
  *
  * @param	mixed 		Topic id | Array of topic ids
  * @param	boolean		Skip updating the stats
  * @return	boolean
  */
 public function topicDeleteFromDB($id, $nostats = 0)
 {
     $posts = array();
     $attach = array();
     $this->error = "";
     $ids = array();
     if (is_array($id)) {
         $id = IPSLib::cleanIntArray($id);
         if (count($id) > 0) {
             $ids = $id;
             $tid = " IN(" . implode(",", $id) . ")";
         } else {
             return false;
         }
     } else {
         if (intval($id)) {
             $ids = array($id);
             $tid = "={$id}";
         } else {
             return false;
         }
     }
     /* GET AND EXAMINE */
     $topics = $this->registry->topics->getTopics(array('topicId' => $ids, 'archiveState' => array('not', 'exclude'), 'topicType' => array('all')));
     if (!count($topics)) {
         return false;
     } else {
         $ids = array_keys($topics);
         $tid = " IN(" . implode(",", $ids) . ")";
     }
     /* Remove from deletion log */
     IPSDeleteLog::removeEntries($ids, 'topic', TRUE);
     /* Tagging */
     $this->registry->tags->deleteByMetaId($ids);
     /* Delete from recent posts */
     $this->registry->topics->deleteRecentPost(array('post_topic_id' => $ids));
     //-----------------------------------------
     // Remove polls assigned to this topic
     //-----------------------------------------
     $this->DB->delete('polls', "tid" . $tid);
     $this->DB->delete('voters', "tid" . $tid);
     $this->DB->delete('topic_ratings', "rating_tid" . $tid);
     $this->DB->delete('topic_views', "views_tid" . $tid);
     $this->DB->delete('topics', "tid" . $tid);
     //-----------------------------------------
     // Like class
     //-----------------------------------------
     require_once IPS_ROOT_PATH . 'sources/classes/like/composite.php';
     /*noLibHook*/
     $_like = classes_like::bootstrap('forums', 'topics');
     $_like->remove($ids);
     //-----------------------------------------
     // Get PIDS for attachment deletion
     //-----------------------------------------
     $this->DB->build(array('select' => 'pid', 'from' => 'posts', 'where' => "topic_id" . $tid));
     $this->DB->execute();
     while ($r = $this->DB->fetch()) {
         $posts[] = $r['pid'];
     }
     /* Remove cache content */
     IPSContentCache::drop('post', $posts);
     //-----------------------------------------
     // Remove the attachments
     //-----------------------------------------
     $classToLoad = IPSLib::loadLibrary(IPSLib::getAppDir('core') . '/sources/classes/attach/class_attach.php', 'class_attach');
     $class_attach = new $classToLoad($this->registry);
     $class_attach->type = 'post';
     $class_attach->init();
     $class_attach->bulkRemoveAttachment($posts);
     //-----------------------------------------
     // Remove the posts
     //-----------------------------------------
     $this->DB->delete('posts', "topic_id" . $tid);
     if (count($posts)) {
         $this->DB->delete('reputation_cache', "app='forums' AND type='pid' AND type_id IN (" . implode(',', $posts) . ")");
         $this->DB->delete('reputation_index', "app='forums' AND type='pid' AND type_id IN (" . implode(',', $posts) . ")");
         $this->DB->delete('reputation_totals', "rt_key=MD5('forums;pid') AND rt_type_id IN (" . implode(',', $posts) . ")");
     }
     //-----------------------------------------
     // Recount forum...
     //-----------------------------------------
     if (!$nostats) {
         if ($this->forum['id']) {
             $this->registry->class_forums->allForums[$this->forum['id']]['_update_deletion'] = 1;
             $this->forumRecount($this->forum['id']);
         }
         $this->cache->rebuildCache('stats', 'global');
     }
     /* Run moderation sync */
     $this->runModSync('topicDelete', $ids);
     return TRUE;
 }
Example #6
0
 /**
  * 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;
 }
Example #7
0
 public function recacheAndLog($action, $message = null)
 {
     if ($action) {
         // log our message
         $this->logMessage($action, $message);
         // recache our stuff.
         switch ($action) {
             case 'attachments':
                 $this->cache->rebuildCache('attachtypes', 'forums');
                 break;
             case 'attachments_type':
                 break;
             case 'announcements':
                 break;
             case 'custom_bbcode':
                 break;
             case 'emoticons':
                 break;
             case 'forums':
                 break;
             case 'forum_perms':
                 break;
             case 'groups':
                 break;
             case 'ignored_users':
                 break;
             case 'members':
                 break;
             case 'moderators':
                 break;
             case 'posts':
                 IPSContentCache::truncate($type);
                 break;
             case 'polls':
                 break;
             case 'pms':
                 break;
             case 'profile_friends':
                 break;
             case 'profile_comments':
                 break;
             case 'pfields':
                 break;
             case 'tags':
                 break;
             case 'topics':
                 IPSContentCache::truncate($type);
                 break;
             case 'topic_ratings':
                 break;
             case 'reputation_index':
                 break;
             case 'ranks':
                 break;
             case 'warn_logs':
                 break;
             case 'finalize':
                 // recache all
                 break;
             default:
                 break;
         }
     }
 }
 /**
  * UserCP Save Form: Signature
  *
  * @return	array	Errors
  */
 public function saveSignature()
 {
     /* Load editor stuff */
     $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/editor/composite.php', 'classes_editor_composite');
     $this->editor = new $classToLoad();
     $this->editor->setLegacyMode(false);
     $isHtml = intval($this->request['sig_htmlstatus']);
     //-----------------------------------------
     // Check to make sure that we can edit profiles..
     //-----------------------------------------
     $sig_restrictions = explode(':', $this->memberData['g_signature_limits']);
     if (!$this->memberData['g_edit_profile'] or $sig_restrictions[0] and !$this->memberData['g_sig_unit']) {
         $this->registry->getClass('output')->showError('members_profile_disabled', 1028, null, null, 403);
     }
     //-----------------------------------------
     // Post process the editor
     // Now we have safe HTML and bbcode
     //-----------------------------------------
     /* Set content in editor */
     $this->editor->setAllowBbcode(true);
     $this->editor->setAllowSmilies(true);
     $this->editor->setIsHtml($this->memberData['g_dohtml'] && $isHtml);
     $this->editor->setBbcodeSection('signatures');
     $this->editor->setContent($this->memberData['signature']);
     $signature = $this->editor->process($_POST['Post']);
     //-----------------------------------------
     // Parse post
     //-----------------------------------------
     /* Load parser */
     $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/text/parser.php', 'classes_text_parser');
     $parser = new $classToLoad();
     $parser->testForParsingLimits($signature, array('quote', 'emoticons', 'urls'));
     if (is_array($parser->getErrors()) && count($parser->getErrors())) {
         $this->lang->loadLanguageFile(array('public_post'), 'forums');
         $_error = array_pop($parser->getErrors());
         $this->registry->getClass('output')->showError($_error, 10210);
     }
     //-----------------------------------------
     // Signature restrictions...
     //-----------------------------------------
     $sig_errors = array();
     //-----------------------------------------
     // Max number of images...
     //-----------------------------------------
     if (isset($sig_restrictions[1]) and $sig_restrictions[1] !== '') {
         if ($parser->getImageCount($signature) > $sig_restrictions[1]) {
             $sig_errors[] = sprintf($this->lang->words['sig_toomanyimages'], $sig_restrictions[1]);
         }
     }
     //-----------------------------------------
     // Max number of urls...
     //-----------------------------------------
     if (isset($sig_restrictions[4]) and $sig_restrictions[4] !== '') {
         if ($parser->getUrlCount($signature) > $sig_restrictions[4]) {
             $sig_errors[] = sprintf($this->lang->words['sig_toomanyurls'], $sig_restrictions[4]);
         } else {
             preg_match_all('#(^|\\s|>)((http|https|news|ftp)://\\w+[^\\s\\[\\]\\<]+)#is', $signature, $matches);
             if (count($matches[1]) > $sig_restrictions[4]) {
                 $sig_errors[] = sprintf($this->lang->words['sig_toomanyurls'], $sig_restrictions[4]);
             }
         }
     }
     $this->settings['signature_line_length'] = $this->settings['signature_line_length'] > 0 ? $this->settings['signature_line_length'] : 200;
     /* You can't wordwrap on HTML http://community.invisionpower.com/resources/bugs.html/_/ip-board/signature-url-bbcode-r41254 */
     //$signature	= wordwrap( $signature, $this->settings['signature_line_length'], '</p>', true );
     // http://community.invisionpower.com/tracker/issue-35105-signature-restriction-minor-bug
     $signature = preg_replace('#^\\s*(</p>)+#i', '', $signature);
     $signature = preg_replace('#(</p>)+?\\s*$#i', '', $signature);
     //-----------------------------------------
     // Max number of lines of text...
     //-----------------------------------------
     if (isset($sig_restrictions[5]) and $sig_restrictions[5] !== '') {
         $lineCount = substr_count($signature, "</p>") + substr_count($signature, "br>");
         if ($lineCount >= $sig_restrictions[5]) {
             $sig_errors[] = sprintf($this->lang->words['sig_toomanylines'], $sig_restrictions[5]);
         }
     }
     //-----------------------------------------
     // Now the crappy part..
     //-----------------------------------------
     if (isset($sig_restrictions[2]) and $sig_restrictions[2] !== '' and isset($sig_restrictions[3]) and $sig_restrictions[3] !== '') {
         preg_match_all('/\\<img([^>]+?)>/i', $signature, $allImages);
         if (count($allImages[1])) {
             foreach ($allImages[1] as $foundImage) {
                 preg_match('#src=[\'"]([^\'"]+?)[\'"]#i', $foundImage, $url);
                 $imageProperties = @getimagesize($url[1]);
                 if (is_array($imageProperties) and count($imageProperties)) {
                     if ($imageProperties[0] > $sig_restrictions[2] or $imageProperties[1] > $sig_restrictions[3]) {
                         $sig_errors[] = sprintf($this->lang->words['sig_imagetoobig'], $url[1], $sig_restrictions[2], $sig_restrictions[3]);
                     }
                 } else {
                     $sig_errors[] = $this->lang->words['sig_imagenotretrievable'];
                 }
             }
         }
     }
     if (count($sig_errors)) {
         $this->registry->getClass('output')->showError(implode('<br />', $sig_errors), 10211);
     }
     /* Save HTML status */
     $members_bitoptions = IPSBWOptions::thaw($this->memberData['members_bitoptions'], 'members', 'global');
     $members_bitoptions['bw_html_sig'] = $isHtml;
     //-----------------------------------------
     // Write it to the DB.
     //-----------------------------------------
     IPSMember::save($this->memberData['member_id'], array('members' => $members_bitoptions, 'extendedProfile' => array('signature' => $signature)));
     /* Update cache */
     IPSContentCache::update($this->memberData['member_id'], 'sig', $parser->display($signature));
     return TRUE;
 }
 /**
  * Get Threaded Topic Data
  *
  * @access	public
  * @return	array
  **/
 public function _getTopicDataThreaded()
 {
     //-----------------------------------------
     // Grab the posts we'll need
     //-----------------------------------------
     $pc_join = array();
     $first = intval($this->request['start']);
     $last = $this->settings['threaded_per_page'] ? $this->settings['threaded_per_page'] : 250;
     //-----------------------------------------
     // GET meh pids
     //-----------------------------------------
     if ($first > 0) {
         // we're on a page, make sure init val is there
         $this->topics->pids[0] = $this->topics->topic['topic_firstpost'];
         $this->structured_pids[0][] = $this->topics->topic['topic_firstpost'];
     }
     $this->DB->build(array('select' => 'pid, post_parent', 'from' => 'posts', 'where' => 'topic_id=' . $this->topics->topic['tid'] . ' and queued != 1', 'order' => 'pid', 'limit' => array($first, $last)));
     $this->DB->execute();
     while ($p = $this->DB->fetch()) {
         $this->topics->pids[] = $p['pid'];
         // Force to be children of 'root' post
         if (!$p['post_parent'] and $p['pid'] != $this->topics->topic['topic_firstpost']) {
             $p['post_parent'] = $this->topics->topic['topic_firstpost'];
         }
         $this->structured_pids[$p['post_parent']][] = $p['pid'];
     }
     /* Ignored Users */
     $ignored_users = array();
     foreach ($this->member->ignored_users as $_i) {
         if ($_i['ignore_topics']) {
             $ignored_users[] = $_i['ignore_ignore_id'];
         }
     }
     //-----------------------------------------
     // Get post bodah
     //-----------------------------------------
     if (count($this->topics->pids)) {
         $this->DB->build(array('select' => 'pid, post, author_id, author_name, post_date, post_title, post_parent, topic_id, icon_id', 'from' => 'posts', 'where' => 'pid IN(' . implode(',', $this->topics->pids) . ')', 'order' => 'pid'));
         $this->DB->execute();
         while ($p = $this->DB->fetch()) {
             if (!$p['post_parent'] and $p['pid'] != $this->topics->topic['topic_firstpost']) {
                 $p['post_parent'] = $this->topics->topic['topic_firstpost'];
             }
             $this->post_cache[$p['pid']] = $p;
             $this->last_id = $p['pid'];
         }
     }
     //-----------------------------------------
     // Force root in cache
     //-----------------------------------------
     $this->post_cache[0] = array('id' => 1);
     $this->post_cache[$this->topics->topic['topic_firstpost']]['post_title'] = $this->topics->topic['title'];
     //-----------------------------------------
     // Are we viewing Posts?
     //-----------------------------------------
     $post_id = intval($this->request['pid']);
     if ($post_id && !in_array($post_id, $this->topics->pids)) {
         $this->registry->output->showError('topics_post_not_in_topic', 10358, true);
     }
     $postid_array = array(1 => $post_id);
     if ($post_id and $post_id != $this->topics->topic['topic_firstpost']) {
         $parents = $this->_threadedPostGetParents($post_id);
         if (count($parents)) {
             foreach ($parents as $pid) {
                 if ($pid != $this->topics->topic['topic_firstpost']) {
                     $postid_array[] = $pid;
                 }
             }
         }
     }
     /* Join Queries */
     $_post_joins = array(array('select' => 'm.member_id as mid,m.name,m.member_group_id,m.email,m.joined,m.posts, m.last_visit, m.last_activity,m.login_anonymous,m.title,m.hide_email, m.warn_level, m.warn_lastwarn, m.members_display_name, m.members_seo_name, m.has_gallery, m.has_blog, m.members_bitoptions', 'from' => array('members' => 'm'), 'where' => 'm.member_id=p.author_id', 'type' => 'left'), array('select' => 'pp.*', 'from' => array('profile_portal' => 'pp'), 'where' => 'm.member_id=pp.pp_member_id', 'type' => 'left'));
     /* Reputation system enabled? */
     if ($this->settings['reputation_enabled']) {
         /* Add the join to figure out if the user has already rated the post */
         $_post_joins[] = $this->registry->repCache->getUserHasRatedJoin('pid', 'p.pid', 'forums');
         /* Add the join to figure out the total ratings for each post */
         if ($this->settings['reputation_show_content']) {
             $_post_joins[] = $this->registry->repCache->getTotalRatingJoin('pid', 'p.pid', 'forums');
         }
     }
     /* Cache? */
     if (IPSContentCache::isEnabled()) {
         if (IPSContentCache::fetchSettingValue('post')) {
             $_post_joins[] = IPSContentCache::join('post', 'p.pid');
         }
         if (IPSContentCache::fetchSettingValue('sig')) {
             $_post_joins[] = IPSContentCache::join('sig', 'm.member_id', 'ccb', 'left', 'ccb.cache_content as cache_content_sig, ccb.cache_updated as cache_updated_sig');
         }
     }
     if ($this->settings['custom_profile_topic'] == 1) {
         $_post_joins[] = array('select' => 'pc.*', 'from' => array('pfields_content' => 'pc'), 'where' => 'pc.member_id=p.author_id', 'type' => 'left');
     }
     if (count($postid_array)) {
         //-----------------------------------------
         // Get root post and children of clicked
         //-----------------------------------------
         $this->used_post_ids = ',' . implode(",", $postid_array) . ',';
         $postid_array[0] = $this->topics->topic['topic_firstpost'];
         $this->DB->build(array('select' => 'p.*', 'from' => array('posts' => 'p'), 'where' => "p.pid IN(" . implode(',', $postid_array) . ")", 'order' => 'pid asc', 'add_join' => $_post_joins));
     } else {
         //-----------------------------------------
         // Just get root
         //-----------------------------------------
         $this->DB->build(array('select' => 'p.*', 'from' => array('posts' => 'p'), 'where' => "p.pid=" . $this->topics->topic['topic_firstpost'], 'order' => 'pid asc', 'add_join' => $_post_joins));
     }
     //-----------------------------------------
     // Attachment PIDS
     //-----------------------------------------
     $this->topics->attach_pids = $postid_array;
     //-----------------------------------------
     // Render the original post
     //-----------------------------------------
     $outer = $this->DB->execute();
     //-----------------------------------------
     // Format and print out the topic list
     //-----------------------------------------
     $post_data = array();
     $num_rows = $this->DB->getTotalRows($outer);
     while ($row = $this->DB->fetch($outer)) {
         $return = $this->topics->parsePostRow($row);
         $poster = $return['poster'];
         $row = $return['row'];
         /* Reputation */
         if ($this->settings['reputation_enabled']) {
             $row['pp_reputation_points'] = $row['pp_reputation_points'] ? $row['pp_reputation_points'] : 0;
             $row['has_given_rep'] = $row['has_given_rep'] ? $row['has_given_rep'] : 0;
             $row['rep_points'] = $row['rep_points'] ? $row['rep_points'] : 0;
         }
         $post_data[$row['pid']] = array('post' => $row, 'author' => $poster);
         //-----------------------------------------
         // Are we giving this bloke a good ignoring?
         //-----------------------------------------
         if (isset($ignored_users) && is_array($ignored_users) && count($ignored_users)) {
             if (in_array($poster['member_id'], $ignored_users)) {
                 if (!strstr($this->settings['cannot_ignore_groups'], ',' . $poster['member_group_id'] . ',')) {
                     $post_data[$row['pid']]['post']['_ignored'] = 1;
                     continue;
                 }
             }
         }
         if (!$this->printed and $num_rows > 1) {
             $post_data[$row['pid']]['post']['_end_first_post'] = 1;
             $this->printed = 1;
         }
     }
     //-----------------------------------------
     // Sort out pagination
     //-----------------------------------------
     $total_replies = $this->topics->topic['posts'];
     $show_replies = count($this->structured_pids) - 1;
     $this->topics->topic['SHOW_PAGES'] = '';
     $this->topics->topic['threaded_pages'] = $this->registry->output->generatePagination(array('totalItems' => $total_replies, 'itemsPerPage' => $last, 'currentStartValue' => $this->request['start'], 'baseUrl' => "showtopic=" . $this->topics->topic['tid'], 'startValueKey' => 'start'));
     //-----------------------------------------
     // START GETTING THE OUTLINE LIST
     //-----------------------------------------
     $this->_threaded_posts[0]['child'] = $this->_threadedLoopGetChildren();
     $this->topics->topic['_threaded_posts'] = $this->_buildThreadedOutput($this->_threaded_posts[0]);
     return $post_data;
 }
Example #10
0
 /**
  * Edit Settings
  */
 public function editSettings()
 {
     require_once IPS_ROOT_PATH . 'sources/classes/skins/skinFunctions.php';
     /*noLibHook*/
     require_once IPS_ROOT_PATH . 'sources/classes/skins/skinCaching.php';
     /*noLibHook*/
     $skinFunctions = new skinCaching(ipsRegistry::instance());
     if (ipsRegistry::$request['recache']) {
         $skinFunctions->flushipscdn();
         ipsRegistry::getClass('output')->redirect(ipsRegistry::$settings['_base_url'] . "app=core&amp;module=applications&amp;section=enhancements&amp;do=edit&amp;service=enhancements_core_ipscdn", ipsRegistry::getClass('class_localization')->words['cdn_recached']);
     }
     if (ipsRegistry::$request['disable']) {
         IPSLib::updateSettings(array('ips_cdn' => FALSE, 'ipb_img_url' => '', 'ipb_css_url' => '', 'ipb_js_url' => '', 'upload_url' => ''));
         if (IPSLib::appIsInstalled('gallery')) {
             $this_script = str_replace('\\', '/', getenv('SCRIPT_FILENAME'));
             $url = ipsRegistry::$settings['_original_base_url'];
             if ($this_script) {
                 $this_script = str_replace('/' . CP_DIRECTORY . '/index.php', '', $this_script);
                 if (substr(ipsRegistry::$settings['gallery_images_path'], 0, strlen($this_script)) === $this_script) {
                     $url = str_replace('\\', '/', str_replace($this_script, $url, ipsRegistry::$settings['gallery_images_path']));
                 }
             } else {
                 $url .= '/uploads';
             }
             IPSLib::updateSettings(array('gallery_images_path' => $url));
         }
         IPSContentCache::truncate('post');
         IPSContentCache::truncate('sig');
         /* Set skin sets to recache */
         $skinFunctions->flagSetForRecache();
         ipsRegistry::getClass('output')->redirect(ipsRegistry::$settings['_base_url'] . "app=core&amp;module=applications&amp;section=enhancements", ipsRegistry::getClass('class_localization')->words['cdn_disabled']);
         return;
     }
     if (!ipsRegistry::$settings['ipb_reg_number']) {
         ipsRegistry::getClass('output')->showError(sprintf(ipsRegistry::getClass('class_localization')->words['enhancements_ipscdn_error_nokey'], ipsRegistry::getClass('output')->buildUrl('app=core&module=tools&section=licensekey', 'admin')));
     }
     $classToLoad = IPSLib::loadLibrary(IPS_KERNEL_PATH . 'classFileManagement.php', 'classFileManagement');
     $file = new $classToLoad();
     $return = NULL;
     if ($json = @json_decode($ping, TRUE)) {
         if ($json['ENABLED'] and $json['BYTES'] > 0) {
             if (!ipsRegistry::$settings['ips_cdn'] and !ipsRegistry::$request['enable']) {
                 return $this->html->cdnInactive($json);
             } else {
                 $settings = array('ips_cdn' => TRUE, 'ipb_img_url' => $json['URL'], 'ipb_css_url' => rtrim($json['URL'], '/') . '/', 'ipb_js_url' => rtrim($json['URL'], '/') . '/', 'upload_url' => $json['URL'] . '/uploads');
                 if (IPSLib::appIsInstalled('downloads')) {
                     if (substr(ipsRegistry::$settings['idm_localsspath'], 0, 11) === '{root_path}') {
                         $settings['idm_screenshot_url'] = str_replace('{root_path}', $json['URL'], ipsRegistry::$settings['idm_localsspath']);
                     }
                 }
                 if (IPSLib::appIsInstalled('gallery')) {
                     $this_script = str_replace('\\', '/', getenv('SCRIPT_FILENAME'));
                     if ($this_script) {
                         $this_script = str_replace('/' . CP_DIRECTORY . '/index.php', '', $this_script);
                         if (substr(ipsRegistry::$settings['gallery_images_path'], 0, strlen($this_script)) === $this_script) {
                             $settings['gallery_images_url'] = str_replace('\\', '/', str_replace($this_script, $json['URL'], ipsRegistry::$settings['gallery_images_path']));
                         }
                     }
                 }
                 $_settings = array();
                 foreach ($settings as $k => $v) {
                     if (ipsRegistry::$settings[$k] != $v) {
                         $_settings[$k] = $v;
                     }
                 }
                 if (!empty($_settings)) {
                     IPSLib::updateSettings($settings);
                 }
                 /* Set skin sets to recache */
                 $skinFunctions->flagSetForRecache();
             }
         } else {
             $licenseData = ipsRegistry::cache()->getCache('licenseData');
             if ($licenseData['key']['url'] != ipsRegistry::$settings['board_url']) {
                 ipsRegistry::getClass('output')->showError(ipsRegistry::getClass('class_localization')->words['enhancements_ipscdn_error_url']);
             }
             /* Set skin sets to recache */
             $skinFunctions->flagSetForRecache();
             return $this->html->cdnNotEnabled($json);
         }
     } else {
         ipsRegistry::getClass('output')->showError(sprintf(ipsRegistry::getClass('class_localization')->words['enhancements_ipscdn_error_key'], ipsRegistry::getClass('output')->buildUrl('app=core&module=tools&section=licensekey', 'admin')));
     }
     return $this->html->cdnOverview($json);
 }
 /**
  * Manage validating members
  *
  * @access	private
  * @return	void		[Outputs to screen]
  */
 private function _manageValidating()
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $ids = array();
     //-----------------------------------------
     // GET checkboxes
     //-----------------------------------------
     foreach ($this->request as $k => $v) {
         if (preg_match("/^mid_(\\d+)\$/", $k, $match)) {
             if ($v) {
                 $ids[] = $match[1];
             }
         }
     }
     $ids = IPSLib::cleanIntArray($ids);
     //-----------------------------------------
     // Check
     //-----------------------------------------
     if (count($ids) < 1) {
         $this->registry->output->showError($this->lang->words['t_nomemsel'], 11247);
     }
     //-----------------------------------------
     // APPROVE
     //-----------------------------------------
     if ($this->request['type'] == 'approve') {
         IPSText::getTextClass('email')->getTemplate("complete_reg");
         $approved = array();
         //-----------------------------------------
         // Get members
         //-----------------------------------------
         $this->DB->build(array('select' => 'v.*', 'from' => array('validating' => 'v'), 'where' => "m.member_id IN(" . implode(",", $ids) . ")", 'add_join' => array(array('select' => 'm.member_id, m.members_display_name, m.name, m.email, m.member_group_id', 'from' => array('members' => 'm'), 'where' => 'm.member_id=v.member_id', 'type' => 'left'))));
         $main = $this->DB->execute();
         while ($row = $this->DB->fetch($main)) {
             $approved[] = $row['name'];
             //-----------------------------------------
             // Only approve if the user is validating
             //-----------------------------------------
             if ($row['member_group_id'] != $this->settings['auth_group']) {
                 continue;
             }
             //-----------------------------------------
             // Don't approve if no real_group set
             //-----------------------------------------
             if (!$row['real_group']) {
                 //$row['real_group'] = $this->settings['member_group'];
                 continue;
             }
             //-----------------------------------------
             // We don't approve lost pass requests
             //-----------------------------------------
             if ($row['lost_pass'] == 1) {
                 continue;
             }
             try {
                 IPSMember::save($row['member_id'], array('core' => array('member_group_id' => $row['real_group'])));
             } catch (Exception $error) {
                 $this->registry->output->showError($error->getMessage(), 11247);
             }
             IPSText::getTextClass('email')->buildMessage(array());
             //-----------------------------------------
             // Using 'name' on purpose
             // @see http://forums./index.php?autocom=tracker&showissue=11564&view=findpost&p=45269
             //-----------------------------------------
             IPSText::getTextClass('email')->subject = sprintf($this->lang->words['subject__complete_reg'], $row['name'], $this->settings['board_name']);
             IPSText::getTextClass('email')->to = $row['email'];
             IPSText::getTextClass('email')->sendMail();
             IPSLib::runMemberSync('onGroupChange', $row['member_id'], $row['real_group']);
         }
         $this->DB->delete('validating', "member_id IN(" . implode(",", $ids) . ")");
         ipsRegistry::getClass('adminFunctions')->saveAdminLog(count($ids) . $this->lang->words['t_memregapp2'] . implode(", ", $approved));
         //-----------------------------------------
         // Stats to Update?
         //-----------------------------------------
         $this->cache->rebuildCache('stats', 'global');
         $this->registry->output->global_message = count($ids) . $this->lang->words['t_memregapp'];
         if ($this->request['_return']) {
             $this->registry->output->silentRedirectWithMessage($this->settings['base_url'] . 'app=members&module=members&section=members&do=viewmember&member_id=' . $this->request['_return']);
         }
         $this->_viewQueue('validating');
         return;
     } else {
         if ($this->request['type'] == 'resend') {
             $reset = array();
             $cant = array();
             $main_msgs = array();
             //-----------------------------------------
             // Get members
             //-----------------------------------------
             $this->DB->build(array('select' => 'v.*', 'from' => array('validating' => 'v'), 'where' => "m.member_id IN(" . implode(",", $ids) . ")", 'add_join' => array(array('select' => 'm.member_id, m.members_display_name, m.email, m.member_group_id', 'from' => array('members' => 'm'), 'where' => 'm.member_id=v.member_id', 'type' => 'left'))));
             $main = $this->DB->execute();
             while ($row = $this->DB->fetch($main)) {
                 if ($row['member_group_id'] != $this->settings['auth_group']) {
                     continue;
                 }
                 if ($row['lost_pass']) {
                     IPSText::getTextClass('email')->getTemplate("lost_pass");
                     IPSText::getTextClass('email')->buildMessage(array('NAME' => $row['members_display_name'], 'THE_LINK' => $this->settings['board_url'] . "/index.php?app=core&module=global&section=lostpass&do=sendform&uid=" . $row['member_id'] . "&aid=" . $val['vid'], 'MAN_LINK' => $this->settings['board_url'] . "/index.php?app=core&module=global&section=lostpass", 'EMAIL' => $row['email'], 'ID' => $row['member_id'], 'CODE' => $row['vid'], 'IP_ADDRESS' => $row['ip_address']));
                     IPSText::getTextClass('email')->subject = $this->lang->words['t_passwordrec'] . $this->settings['board_name'];
                     IPSText::getTextClass('email')->to = $row['email'];
                     IPSText::getTextClass('email')->sendMail();
                 } else {
                     if ($row['new_reg']) {
                         if ($row['user_verified']) {
                             $cant[] = $row['members_display_name'];
                             continue;
                         }
                         IPSText::getTextClass('email')->getTemplate("reg_validate");
                         IPSText::getTextClass('email')->buildMessage(array('THE_LINK' => $this->settings['board_url'] . "/index.php?app=core&module=global&section=register&do=auto_validate&uid=" . $row['member_id'] . "&aid=" . $row['vid'], 'NAME' => $row['members_display_name'], 'MAN_LINK' => $this->settings['board_url'] . "/index.php?app=core&module=global&section=register&do=05", 'EMAIL' => $row['email'], 'ID' => $row['member_id'], 'CODE' => $row['vid']));
                         IPSText::getTextClass('email')->subject = $this->lang->words['t_regat'] . $this->settings['board_name'];
                         IPSText::getTextClass('email')->to = $row['email'];
                         IPSText::getTextClass('email')->sendMail();
                     } else {
                         if ($row['email_chg']) {
                             IPSText::getTextClass('email')->getTemplate("newemail");
                             IPSText::getTextClass('email')->buildMessage(array('NAME' => $row['members_display_name'], 'THE_LINK' => $this->settings['board_url'] . "/index.php?app=core&module=global&section=register&do=auto_validate&type=newemail&uid=" . $row['member_id'] . "&aid=" . $row['vid'], 'ID' => $row['member_id'], 'MAN_LINK' => $this->settings['board_url'] . "/index.php?app=core&module=global&section=register&do=user_validate", 'CODE' => $row['vid']));
                             IPSText::getTextClass('email')->subject = $this->lang->words['t_emailchange'] . $this->settings['board_name'];
                             IPSText::getTextClass('email')->to = $row['email'];
                             IPSText::getTextClass('email')->sendMail();
                         }
                     }
                 }
                 $resent[] = $row['members_display_name'];
             }
             if (count($resent)) {
                 ipsRegistry::getClass('adminFunctions')->saveAdminLog(count($resent) . $this->lang->words['tools_val_resent_log'] . implode(", ", $resent));
                 $main_msgs[] = count($resent) . $this->lang->words['t_vallog'] . implode(", ", $resent);
             }
             if (count($cant)) {
                 $main_msgs[] = $this->lang->words['t_valcannot'] . implode(", ", $cant);
             }
             $this->registry->output->global_message = count($main_msgs) ? implode("<br />", $main_msgs) : '';
             $this->_viewQueue('validating');
             return;
         } else {
             if ($this->request['type'] == 'ban') {
                 $this->DB->update('members', array('member_banned' => 1), "member_id IN(" . implode(",", $ids) . ")");
                 $this->DB->delete('validating', "member_id IN(" . implode(",", $ids) . ")");
                 ipsRegistry::getClass('adminFunctions')->saveAdminLog(count($ids) . $this->lang->words['t_membanned']);
                 $this->registry->output->global_message = count($ids) . $this->lang->words['t_membanned'];
                 $this->_viewQueue('validating');
                 return;
             } else {
                 if ($this->request['type'] == 'spam') {
                     /* Grab members */
                     $members = IPSMember::load($ids);
                     /* Load moderator's library */
                     require IPSLib::getAppDir('forums') . '/sources/classes/moderate.php';
                     $modLibrary = new moderatorLibrary($this->registry);
                     /* Load custom fields class */
                     require_once IPS_ROOT_PATH . 'sources/classes/customfields/profileFields.php';
                     $fields = new customProfileFields();
                     /* Load language file */
                     $this->registry->getClass('class_localization')->loadLanguageFile(array('public_mod'), 'forums');
                     foreach ($members as $member_id => $member) {
                         $toSave = array('core' => array('bw_is_spammer' => 1, 'member_group_id' => $this->settings['member_group']));
                         /* Protected group? */
                         if (strstr(',' . $this->settings['warn_protected'] . ',', ',' . $member['member_group_id'] . ',')) {
                             continue;
                         }
                         /* What do to.. */
                         if ($this->settings['spm_option']) {
                             switch ($this->settings['spm_option']) {
                                 case 'disable':
                                     $toSave['core']['restrict_post'] = 1;
                                     $toSave['core']['members_disable_pm'] = 2;
                                     break;
                                 case 'unapprove':
                                     $toSave['core']['restrict_post'] = 1;
                                     $toSave['core']['members_disable_pm'] = 2;
                                     /* Unapprove posts and topics */
                                     $modLibrary->toggleApproveMemberContent($member_id, FALSE, 'all', intval($this->settings['spm_post_days']) * 24);
                                     break;
                                 case 'ban':
                                     /* Unapprove posts and topics */
                                     $modLibrary->toggleApproveMemberContent($member_id, FALSE, 'all', intval($this->settings['spm_post_days']) * 24);
                                     $toSave = array('core' => array('member_banned' => 1, 'title' => '', 'bw_is_spammer' => 1), 'extendedProfile' => array('signature' => '', 'pp_bio_content' => '', 'pp_about_me' => '', 'pp_status' => ''));
                                     //-----------------------------------------
                                     // Avatar
                                     //-----------------------------------------
                                     $toSave['extendedProfile']['avatar_location'] = "";
                                     $toSave['extendedProfile']['avatar_size'] = "";
                                     try {
                                         IPSMember::getFunction()->removeAvatar($member['member_id']);
                                     } catch (Exception $e) {
                                         // Maybe should show an error or something
                                     }
                                     //-----------------------------------------
                                     // Photo
                                     //-----------------------------------------
                                     IPSMember::getFunction()->removeUploadedPhotos($member['member_id']);
                                     $toSave['extendedProfile'] = array_merge($toSave['extendedProfile'], array('pp_main_photo' => '', 'pp_main_width' => '', 'pp_main_height' => '', 'pp_thumb_photo' => '', 'pp_thumb_width' => '', 'pp_thumb_height' => ''));
                                     //-----------------------------------------
                                     // Profile fields
                                     //-----------------------------------------
                                     $fields->member_data = $member;
                                     $fields->initData('edit');
                                     $fields->parseToSave(array());
                                     if (count($fields->out_fields)) {
                                         $toSave['customFields'] = $fields->out_fields;
                                     }
                                     //-----------------------------------------
                                     // Update signature content cache
                                     //-----------------------------------------
                                     IPSContentCache::update($member['member_id'], 'sig', '');
                                     break;
                             }
                         }
                         /* Send an email */
                         if ($this->settings['spm_notify'] and $this->settings['email_out'] != $this->memberData['email']) {
                             IPSText::getTextClass('email')->getTemplate('possibleSpammer');
                             IPSText::getTextClass('email')->buildMessage(array('DATE' => $this->registry->class_localization->getDate($member['joined'], 'LONG', 1), 'MEMBER_NAME' => $member['members_display_name'], 'IP' => $member['ip_address'], 'EMAIL' => $member['email'], 'LINK' => $this->registry->getClass('output')->buildSEOUrl("showuser="******"member_id IN(" . implode(",", $ids) . ")");
                         $this->registry->output->global_message = count($ids) . ' ' . $this->lang->words['t_setasspammers'];
                         $this->_viewQueue('validating');
                         return;
                     }
                 } else {
                     $denied = array();
                     $this->DB->build(array('select' => 'members_display_name', 'from' => 'members', 'where' => "member_id IN(" . implode(",", $ids) . ")"));
                     $this->DB->execute();
                     while ($r = $this->DB->fetch()) {
                         $denied[] = $r['members_display_name'];
                     }
                     try {
                         IPSMember::remove($ids);
                     } catch (Exception $error) {
                         $this->registry->output->showError($error->getMessage(), 11247);
                     }
                     ipsRegistry::getClass('adminFunctions')->saveAdminLog(count($ids) . $this->lang->words['t_regdenied'] . implode(", ", $denied));
                     $this->registry->output->global_message = count($ids) . $this->lang->words['t_removedmem'];
                     $this->_viewQueue('validating');
                     return;
                 }
             }
         }
     }
 }
Example #12
0
 /**
  * Get Topic Data
  *
  * @return	array
  */
 public function _getPosts()
 {
     /* Init */
     $topicData = $this->registry->getClass('topics')->getTopicData();
     $forumData = $this->forumClass->getForumById($topicData['forum_id']);
     $permissionData = $this->registry->getClass('topics')->getPermissionData();
     $first = $this->registry->getClass('topics')->pageToSt($this->request['page']);
     /* Default - just see all visible posts */
     $queued_query_bit = ' AND ' . $this->registry->class_forums->fetchPostHiddenQuery('visible', '');
     /* Can we deal with hidden posts? */
     if ($this->registry->class_forums->canQueuePosts($topicData['forum_id'])) {
         if ($permissionData['softDeleteSee']) {
             /* See queued and soft deleted */
             $queued_query_bit = ' AND ' . $this->registry->class_forums->fetchPostHiddenQuery(array('visible', 'hidden', 'sdeleted'), '');
         } else {
             /* Otherwise, see queued and approved */
             $queued_query_bit = ' AND ' . $this->registry->class_forums->fetchPostHiddenQuery(array('visible', 'hidden'), '');
         }
         /* Specifically requesting to see queued posts only */
         if ($this->request['modfilter'] and $this->request['modfilter'] == 'invisible_posts') {
             $queued_query_bit = ' AND ' . $this->registry->class_forums->fetchPostHiddenQuery('hidden', '');
         }
     } else {
         /* We cannot see hidden posts */
         if ($permissionData['softDeleteSee']) {
             /* See queued and soft deleted */
             $queued_query_bit = ' AND ' . $this->registry->class_forums->fetchPostHiddenQuery(array('approved', 'sdeleted'), '');
         }
     }
     /* Did we specifically want to see soft deleted posts? */
     if ($this->request['modfilter'] == 'deleted_posts' and $permissionData['softDeleteSee']) {
         $queued_query_bit = ' AND ' . $this->registry->class_forums->fetchPostHiddenQuery('sdeleted', '');
     }
     /* Data Hook Location */
     $dataHook = array('members' => array(), 'postJoins' => array());
     IPSLib::doDataHooks($dataHook, 'topicViewQuery');
     //-----------------------------------------
     // Joins
     //-----------------------------------------
     $_extraMember = is_array($dataHook['members']) && count($dataHook['members']) ? ',m.' . implode(',m.', $dataHook['members']) : '';
     $_post_joins = array(array('select' => '', 'from' => array('posts' => 'p'), 'where' => 'p.pid=z.pid'), array('select' => 'm.member_id as mid,m.name,m.member_group_id,m.email,m.joined,m.posts, m.last_visit, m.last_activity,m.login_anonymous,m.title as member_title, m.warn_level, m.warn_lastwarn, m.members_display_name, m.members_seo_name, m.member_banned, m.has_gallery, m.has_blog, m.members_bitoptions,m.mgroup_others' . $_extraMember, 'from' => array('members' => 'm'), 'where' => 'm.member_id=p.author_id', 'type' => 'left'), array('select' => 'pp.*', 'from' => array('profile_portal' => 'pp'), 'where' => 'm.member_id=pp.pp_member_id', 'type' => 'left'));
     /* Warn system enabled? */
     if ($this->settings['warn_on'] == 1) {
         $_post_joins[] = array('select' => 'w.wl_id', 'from' => array('members_warn_logs' => 'w'), 'where' => 'w.wl_content_app=\'forums\' and w.wl_content_id1=p.pid');
     }
     /* Add data hook joins */
     if (is_array($dataHook['postJoins']) && count($dataHook['postJoins'])) {
         $_post_joins = array_merge($_post_joins, $dataHook['postJoins']);
     }
     /* Add custom fields join? */
     if ($this->settings['custom_profile_topic'] == 1) {
         $_post_joins[] = array('select' => 'pc.*', 'from' => array('pfields_content' => 'pc'), 'where' => 'pc.member_id=p.author_id', 'type' => 'left');
     }
     /* Reputation system enabled? */
     if ($this->settings['reputation_enabled']) {
         /* Add the join to figure out if the user has already rated the post */
         $_post_joins[] = $this->registry->repCache->getUserHasRatedJoin('pid', 'p.pid', 'forums');
         /* Add the join to figure out the total ratings for each post */
         if ($this->settings['reputation_show_content']) {
             $_post_joins[] = $this->registry->repCache->getTotalRatingJoin('pid', 'p.pid', 'forums');
         }
     }
     /* Cache? */
     if (IPSContentCache::isEnabled()) {
         if (IPSContentCache::fetchSettingValue('post')) {
             $_post_joins[] = IPSContentCache::join('post', 'p.pid');
         }
         if (IPSContentCache::fetchSettingValue('sig')) {
             $_post_joins[] = IPSContentCache::join('sig', 'm.member_id', 'ccb', 'left', 'ccb.cache_content as cache_content_sig, ccb.cache_updated as cache_updated_sig');
         }
     }
     /* Ignored Users */
     $ignored_users = array();
     foreach ($this->member->ignored_users as $_i) {
         if ($_i['ignore_topics']) {
             $ignored_users[] = $_i['ignore_ignore_id'];
         }
     }
     //-----------------------------------------
     // Get posts
     // See http://community.invisionpower.com/resources/bugs.html/_/ip-board/big-topics-i-mean-big-topics-r36577 for an explanation why this a bit odd
     //-----------------------------------------
     $this->DB->build(array('select' => 'p.*', 'from' => array('( ****FROM**** )' => 'z'), 'add_join' => $_post_joins));
     $query = $this->DB->fetchSqlString();
     $this->DB->flushQuery();
     $this->DB->build(array('select' => 'pid, post_date', 'from' => 'posts', 'where' => 'topic_id=' . $topicData['tid'] . $queued_query_bit, 'order' => $this->settings['post_order_column'] . ' ' . $this->settings['post_order_sort'], 'limit' => array($first, $this->settings['display_max_posts'])));
     $query = str_replace('****FROM****', $this->DB->fetchSqlString(), $query) . " ORDER BY z." . $this->settings['post_order_column'] . " " . $this->settings['post_order_sort'];
     $query = str_replace($this->settings['sql_tbl_prefix'] . '(', '(', $query);
     $this->DB->flushQuery();
     $this->DB->allow_sub_select = TRUE;
     $oq = $this->DB->query($query);
     if (!$this->DB->getTotalRows()) {
         if ($first >= $this->settings['display_max_posts']) {
             //-----------------------------------------
             // AUTO FIX: Get the correct number of replies...
             //-----------------------------------------
             $this->DB->build(array('select' => 'COUNT(*) as pcount', 'from' => 'posts', 'where' => "topic_id=" . $topicData['tid'] . " and queued=0"));
             $newq = $this->DB->execute();
             $pcount = $this->DB->fetch($newq);
             $pcount['pcount'] = $pcount['pcount'] > 0 ? $pcount['pcount'] - 1 : 0;
             //-----------------------------------------
             // Update the post table...
             //-----------------------------------------
             if ($pcount['pcount'] > 1) {
                 $this->DB->update('topics', array('posts' => $pcount['pcount']), "tid=" . $topicData['tid']);
             }
             // This is now handled in app_class_forums::incorrectPageCallback to redirect to correct post */
             //$this->registry->output->silentRedirect($this->settings['base_url']."showtopic={$topicData['tid']}&view=getlastpost");
         }
     }
     //-----------------------------------------
     // Render the page top
     //-----------------------------------------
     $topicData['go_new'] = isset($topicData['go_new']) ? $topicData['go_new'] : '';
     //-----------------------------------------
     // Format and print out the topic list
     //-----------------------------------------
     $modAll = ($this->memberData['g_is_supmod'] or isset($this->memberData['forumsModeratorData'][$forumData['id']]) and ($this->memberData['forumsModeratorData'][$forumData['id']]['delete_post'] or $this->memberData['forumsModeratorData'][$forumData['id']]['split_move']));
     $this->registry->getClass('topics')->setTopicData('adCodeSet', false);
     $this->registry->getClass('topics')->setTopicData('ignoredUsers', $ignored_users);
     $posts = array();
     $this->DB->allow_sub_select = TRUE;
     while ($row = $this->DB->fetch($oq)) {
         /* Should we display the moderate checkbox for this post? */
         $row['moddable'] = FALSE;
         if ($modAll or isset($this->memberData['forumsModeratorData'][$forumData['id']]) and ($row['approved'] == 0 and $this->memberData['forumsModeratorData'][$forumData['id']]['post_q'] or $row['queued'] == 2 and $this->memberData['forumsModeratorData'][$forumData['id']]['bw_mod_un_soft_delete'] or $row['queued'] == 0 and $this->memberData['forumsModeratorData'][$forumData['id']]['bw_mod_soft_delete'])) {
             $row['moddable'] = TRUE;
         }
         /* Add to array */
         $row['member_id'] = $row['mid'];
         $posts[$row['pid']] = $row;
     }
     /* Return */
     return $posts;
 }
 /**
  * UserCP Save Form: Signature
  *
  * @access	public
  * @return	array	Errors
  */
 public function saveSignature()
 {
     //-----------------------------------------
     // Check to make sure that we can edit profiles..
     //-----------------------------------------
     $sig_restrictions = explode(':', $this->memberData['g_signature_limits']);
     if (!$this->memberData['g_edit_profile'] or $sig_restrictions[0] and !$this->memberData['g_sig_unit']) {
         $this->registry->getClass('output')->showError('members_profile_disabled', 1028);
     }
     //-----------------------------------------
     // Check length
     //-----------------------------------------
     if (IPSText::mbstrlen($_POST['Post']) > $this->settings['max_sig_length'] and $this->settings['max_sig_length']) {
         $this->registry->getClass('output')->showError('members_sig_too_long', 1029);
     }
     //-----------------------------------------
     // Remove board tags
     //-----------------------------------------
     $this->request['Post'] = IPSText::removeMacrosFromInput($this->request['Post']);
     //-----------------------------------------
     // Post process the editor
     // Now we have safe HTML and bbcode
     //-----------------------------------------
     $signature = IPSText::getTextClass('editor')->processRawPost('Post');
     //-----------------------------------------
     // Parse post
     //-----------------------------------------
     IPSText::getTextClass('bbcode')->parse_smilies = 0;
     IPSText::getTextClass('bbcode')->parse_html = intval($this->settings['sig_allow_html']);
     IPSText::getTextClass('bbcode')->parse_bbcode = intval($this->settings['sig_allow_ibc']);
     IPSText::getTextClass('bbcode')->parsing_section = 'signatures';
     $signature = IPSText::getTextClass('bbcode')->preDbParse($signature);
     $testSignature = IPSText::getTextClass('bbcode')->preDisplayParse($signature);
     if (IPSText::getTextClass('bbcode')->error != "") {
         $this->registry->getClass('output')->showError(IPSText::getTextClass('bbcode')->error, 10210);
     }
     //-----------------------------------------
     // Signature restrictions...
     //-----------------------------------------
     $sig_errors = array();
     //-----------------------------------------
     // Max number of images...
     //-----------------------------------------
     if ($sig_restrictions[1] !== '') {
         if (substr_count(strtolower($signature), "[img]") > $sig_restrictions[1]) {
             $sig_errors[] = sprintf($this->lang->words['sig_toomanyimages'], $sig_restrictions[1]);
         }
     }
     //-----------------------------------------
     // Max number of urls...
     //-----------------------------------------
     if ($sig_restrictions[4] !== '') {
         if (substr_count(strtolower($signature), "[url") > $sig_restrictions[4]) {
             $sig_errors[] = sprintf($this->lang->words['sig_toomanyurls'], $sig_restrictions[4]);
         } else {
             preg_match_all("#(^|\\s|>)((http|https|news|ftp)://\\w+[^\\s\\[\\]\\<]+)#is", $signature, $matches);
             if (count($matches[1]) > $sig_restrictions[4]) {
                 $sig_errors[] = sprintf($this->lang->words['sig_toomanyurls'], $sig_restrictions[4]);
             }
         }
     }
     //-----------------------------------------
     // Max number of lines of text...
     //-----------------------------------------
     if ($sig_restrictions[5] !== '') {
         $testSig = IPSText::getTextClass('bbcode')->wordWrap($signature, $this->settings['post_wordwrap'], '<br />');
         if (substr_count($testSig, "<br />") >= $sig_restrictions[5]) {
             $sig_errors[] = sprintf($this->lang->words['sig_toomanylines'], $sig_restrictions[5]);
         }
     }
     //-----------------------------------------
     // Now the crappy part..
     //-----------------------------------------
     if ($sig_restrictions[2] !== '' and $sig_restrictions[3] !== '') {
         preg_match_all("/\\[img\\](.+?)\\[\\/img\\]/i", $signature, $allImages);
         if (count($allImages[1])) {
             foreach ($allImages[1] as $foundImage) {
                 $imageProperties = @getimagesize($foundImage);
                 if (is_array($imageProperties) and count($imageProperties)) {
                     if ($imageProperties[0] > $sig_restrictions[2] or $imageProperties[1] > $sig_restrictions[3]) {
                         $sig_errors[] = sprintf($this->lang->words['sig_imagetoobig'], $foundImage, $sig_restrictions[2], $sig_restrictions[3]);
                     }
                 }
             }
         }
     }
     if (count($sig_errors)) {
         $this->registry->getClass('output')->showError(implode('<br />', $sig_errors), 10211);
     }
     //-----------------------------------------
     // Write it to the DB.
     //-----------------------------------------
     IPSMember::save($this->memberData['member_id'], array('extendedProfile' => array('signature' => $signature)));
     /* Update cache */
     IPSContentCache::update($this->memberData['member_id'], 'sig', $testSignature);
     return TRUE;
 }
Example #14
0
 /**
  * Save the member updates
  *
  * @return	@e void
  * @todo 	[Future] Determine what items should be editable and allow moderators to edit them
  */
 protected function _doEditMember()
 {
     $this->loadData();
     //-----------------------------------------
     // Check permissions
     //-----------------------------------------
     if (!$this->memberData['g_is_supmod']) {
         $this->registry->output->showError('mod_only_supermods', 10370, true, null, 403);
     }
     if (!$this->memberData['g_access_cp'] and $this->warn_member['g_access_cp']) {
         $this->registry->output->showError('mod_admin_edit', 3032, true, null, 403);
     }
     if ($this->request['auth_key'] != $this->member->form_hash) {
         $this->registry->output->showError('no_permission', 3032.1, null, null, 403);
     }
     //-----------------------------------------
     // Init
     //-----------------------------------------
     $editable = array();
     $isHtml = intval($this->request['sig_htmlstatus']);
     //-----------------------------------------
     // Signature and about me
     //-----------------------------------------
     /* Load parser */
     $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/text/parser.php', 'classes_text_parser');
     $parser = new $classToLoad();
     $this->editor->setLegacyMode(false);
     //-----------------------------------------
     // Parse signature
     //-----------------------------------------
     /* Set content in editor */
     $this->editor->setAllowBbcode(true);
     $this->editor->setAllowSmilies(false);
     $this->editor->setIsHtml($this->caches['group_cache'][$this->warn_member['member_group_id']]['g_dohtml'] && $isHtml);
     $this->editor->setBbcodeSection('signatures');
     $signature = $this->editor->process($_POST['Post']);
     /* About Me */
     $aboutme = $this->editor->process($_POST['aboutme']);
     //-----------------------------------------
     // Add to array to save
     //-----------------------------------------
     $save['extendedProfile'] = array('signature' => $signature, 'pp_about_me' => $aboutme);
     $save['members'] = array('title' => $this->request['title']);
     //-----------------------------------------
     // Removing photo?
     //-----------------------------------------
     if ($this->request['photo'] == 1) {
         $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/member/photo.php', 'classes_member_photo');
         $photos = new $classToLoad($this->registry);
         $photos->remove($this->warn_member['member_id']);
     }
     //-----------------------------------------
     // Removing Restrictions?
     //-----------------------------------------
     if ($this->request['modpreview'] == 1) {
         $save['core']['mod_posts'] = 0;
     }
     if ($this->request['postingrestriction'] == 1) {
         $save['core']['restrict_post'] = 0;
     }
     if ($this->request['remove_suspension'] == 1) {
         $save['core']['temp_ban'] = 0;
     }
     //-----------------------------------------
     // Profile fields
     //-----------------------------------------
     $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/customfields/profileFields.php', 'customProfileFields');
     $fields = new $classToLoad();
     $fields->member_data = $this->warn_member;
     $fields->initData('edit');
     $fields->parseToSave($_POST);
     if (count($fields->out_fields)) {
         $save['customFields'] = $fields->out_fields;
     }
     //-----------------------------------------
     // Bitwise
     //-----------------------------------------
     if (isset($this->request['status_updates'])) {
         $bw = IPSBWOptions::thaw($this->warn_member['members_bitoptions'], 'members');
         $bw['bw_no_status_update'] = $this->request['status_updates'] ? 0 : 1;
         $save['core']['members_bitoptions'] = IPSBWOptions::freeze($bw, 'members');
     }
     //-----------------------------------------
     // Write it to the DB.
     //-----------------------------------------
     IPSMember::save($this->warn_member['member_id'], $save);
     //-----------------------------------------
     // Update signature content cache
     //-----------------------------------------
     /* Update cache */
     IPSContentCache::update($this->warn_member['member_id'], 'sig', $parser->display($signature));
     //-----------------------------------------
     // Add a mod log entry and redirect
     //-----------------------------------------
     $this->getModLibrary()->addModerateLog(0, 0, 0, 0, $this->lang->words['acp_edited_profile'] . " " . $this->warn_member['members_display_name']);
     $this->_redirect($this->lang->words['acp_edited_profile'] . " " . $this->warn_member['members_display_name']);
 }
 /**
  * Run this task
  * 
  * @access	public
  * @return	void
  */
 public function runTask()
 {
     /* Run it */
     $itemsRemoved = IPSContentCache::prune();
     $this->class->appendTaskLog($this->task, "Cleaned up content cache - " . $itemsRemoved . " items removed");
     $this->class->unlockTask($this->task);
 }
Example #16
0
 /**
  * Edit a member [process]
  *
  * @return	@e void
  */
 protected function _memberDoEdit()
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $this->request['member_id'] = intval($this->request['member_id']);
     //-----------------------------------------
     // Send to form if this isn't a POST request
     //-----------------------------------------
     if ($this->request['request_method'] != 'post') {
         $this->_memberView();
         return;
     }
     //-----------------------------------------
     // Auth check...
     //-----------------------------------------
     ipsRegistry::getClass('adminFunctions')->checkSecurityKey($this->request['secure_key']);
     //-----------------------------------------
     // Load and config the std/rte editors
     //-----------------------------------------
     IPSText::getTextClass('editor')->from_acp = 1;
     //-----------------------------------------
     // Get member
     //-----------------------------------------
     $member = IPSMember::load($this->request['member_id'], 'all');
     //-----------------------------------------
     // Allowed to edit administrators?
     //-----------------------------------------
     if ($member['member_id'] != $this->memberData['member_id'] and $member['g_access_cp'] and !$this->registry->getClass('class_permissions')->checkPermission('member_edit_admin')) {
         $this->registry->output->global_message = $this->lang->words['m_editadmin'];
         $this->_memberView();
         return;
     }
     //-----------------------------------------
     // Allowed to change an admin's groups?
     //-----------------------------------------
     if ($member['g_access_cp'] and !$this->registry->getClass('class_permissions')->checkPermission('member_move_admin1')) {
         $same = false;
         if ($this->request['member_group_id'] == $member['member_group_id']) {
             $member['mgroup_others'] = IPSText::cleanPermString($member['mgroup_others']);
             $omgroups = $member['mgroup_others'] ? explode(',', $member['mgroup_others']) : array();
             $groups = $this->request['mgroup_others'] ? $this->request['mgroup_others'] : array();
             if (!count(array_diff($omgroups, $groups)) and !count(array_diff($groups, $omgroups))) {
                 $same = true;
             }
         }
         if (!$same) {
             $this->registry->output->global_message = $this->lang->words['m_admindemote'];
             $this->_memberView();
             return;
         }
     }
     //-----------------------------------------
     // What about promoting to admin?
     //-----------------------------------------
     if (!$member['g_access_cp'] and !$this->registry->getClass('class_permissions')->checkPermission('member_move_admin2')) {
         $groups = $_POST['mgroup_others'] ? $_POST['mgroup_others'] : array();
         $groups[] = intval($this->request['member_group_id']);
         foreach ($groups as $group_id) {
             if ($this->caches['group_cache'][$group_id]['g_access_cp']) {
                 $this->registry->output->global_message = $this->lang->words['m_adminpromote'];
                 $this->_memberView();
                 return;
             }
         }
     }
     //-----------------------------------------
     // What about moving member in general?
     //-----------------------------------------
     if ($this->request['member_group_id'] != $member['member_group_id'] and !$this->registry->getClass('class_permissions')->checkPermission('member_move')) {
         $this->registry->output->global_message = $this->lang->words['m_movemembers'];
         $this->_memberView();
         return;
     }
     //-----------------------------------------
     // Restricted?
     //-----------------------------------------
     $restricted = (is_array($this->registry->getClass('class_permissions')->restrictions_row) and count($this->registry->getClass('class_permissions')->restrictions_row)) ? true : false;
     /* Load editor stuff */
     $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/editor/composite.php', 'classes_editor_composite');
     $_editor = new $classToLoad();
     /* Load parser */
     $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/text/parser.php', 'classes_text_parser');
     $parser = new $classToLoad();
     /* Get signature */
     $_editor->setAllowBbcode(true);
     $_editor->setAllowSmilies(false);
     $_editor->setIsHtml($this->request['bw_html_sig'] && $member['g_dohtml']);
     $_editor->setAllowHtml($member['g_dohtml']);
     $_editor->setBbcodeSection('signatures');
     $signature = $_editor->process($_POST['signature']);
     $cacheSignature = $parser->display($signature);
     /* About me editor */
     $_editor->setAllowBbcode(true);
     $_editor->setAllowSmilies(true);
     $_editor->setAllowHtml($member['g_dohtml']);
     $_editor->setBbcodeSection('aboutme');
     $aboutme = $_editor->process($_POST['aboutme']);
     //-----------------------------------------
     // Ok? Load interface and child classes
     //-----------------------------------------
     $additionalCore = array();
     $additionalExtended = array();
     $additionalMCache = array();
     IPSLib::loadInterface('admin/member_form.php');
     foreach (IPSLib::getEnabledApplications() as $app_dir => $app_data) {
         if (is_file(IPSLib::getAppDir($app_dir) . '/extensions/admin/member_form.php')) {
             $_class = IPSLib::loadLibrary(IPSLib::getAppDir($app_dir) . '/extensions/admin/member_form.php', 'admin_member_form__' . $app_dir, $app_dir);
             $_object = new $_class($this->registry);
             $remote = $_object->getForSave();
             $additionalCore = is_array($remote['core']) ? array_merge($remote['core'], $additionalCore) : $additionalCore;
             $additionalExtended = is_array($remote['extendedProfile']) ? array_merge($remote['extendedProfile'], $additionalExtended) : $additionalExtended;
             $additionalMCache = is_array($remote['member_cache']) ? array_merge($remote['member_cache'], $additionalMCache) : $additionalMCache;
         }
     }
     //-----------------------------------------
     // Fix custom title
     // @see	http://forums.invisionpower.com/index.php?app=tracker&showissue=17383
     //-----------------------------------------
     $memberTitle = $this->request['title'];
     $rankCache = ipsRegistry::cache()->getCache('ranks');
     if (is_array($rankCache) && count($rankCache)) {
         foreach ($rankCache as $k => $v) {
             if ($member['posts'] >= $v['POSTS']) {
                 /* If this is the title passed to us from the form, we didn't have a custom title */
                 if ($v['TITLE'] == $memberTitle) {
                     $memberTitle = '';
                 }
                 break;
             }
         }
     }
     //-----------------------------------------
     // Start array
     //-----------------------------------------
     $newMember = array('member_group_id' => intval($this->request['member_group_id']), 'title' => $memberTitle, 'time_offset' => floatval($this->request['time_offset']), 'members_auto_dst' => intval($this->request['dstCheck']), 'dst_in_use' => intval($this->request['dstOption']), 'language' => $this->request['language'], 'skin' => intval($this->request['skin']), 'allow_admin_mails' => intval($this->request['allow_admin_mails']), 'view_sigs' => intval($this->request['view_sigs']), 'posts' => intval($this->request['posts']), 'bday_day' => intval($this->request['bday_day']), 'bday_month' => intval($this->request['bday_month']), 'bday_year' => intval($this->request['bday_year']), 'warn_level' => intval($this->request['warn_level']), 'members_disable_pm' => intval($this->request['members_disable_pm']), 'mgroup_others' => $this->request['mgroup_others'] ? ',' . implode(",", $this->request['mgroup_others']) . ',' : '', 'members_bitoptions' => IPSBWOPtions::freeze($this->request, 'members', 'global'), 'member_uploader' => $this->request['member_uploader']);
     //-----------------------------------------
     // Notifications library
     //-----------------------------------------
     $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . '/sources/classes/member/notifications.php', 'notifications');
     $notifyLibrary = new $classToLoad($this->registry);
     $notifyLibrary->setMember($member);
     //-----------------------------------------
     // Show the form
     //-----------------------------------------
     $_basicOptions = array(array('email', $this->lang->words['notopt__email']), array('inline', $this->lang->words['notopt__inline']), array('mobile', $this->lang->words['notopt__mobile']));
     $_configOptions = $notifyLibrary->getNotificationData();
     $_notifyConfig = $notifyLibrary->getMemberNotificationConfig($newMember);
     $_defaultConfig = $notifyLibrary->getDefaultNotificationConfig();
     $_saveConfig = array();
     foreach ($_configOptions as $option) {
         $_saveConfig[$option['key']] = array();
         $_saveConfig[$option['key']]['selected'] = array();
         //-----------------------------------------
         // Loop through and mark what we selected.
         // Do not allow changing of stuff from disable_override
         //	and disabled, however
         //-----------------------------------------
         if (is_array($this->request['config_' . $option['key']]) and count($this->request['config_' . $option['key']])) {
             foreach ($this->request['config_' . $option['key']] as $_selected) {
                 if (!is_array($_defaultConfig[$option['key']]['disabled']) or !in_array($_selected, $_defaultConfig[$option['key']]['disabled'])) {
                     $_saveConfig[$option['key']]['selected'][] = $_selected;
                 }
             }
         }
         if ($_defaultConfig[$option['key']]['disable_override']) {
             $_saveConfig[$option['key']]['selected'] = $_defaultConfig[$option['key']]['selected'];
         }
     }
     //-----------------------------------------
     // Save
     //-----------------------------------------
     IPSMember::packMemberCache($member['member_id'], array_merge($additionalMCache, array('notifications' => $_saveConfig, 'show_notification_popup' => intval($this->request['show_notification_popup']))), $member['members_cache']);
     //-----------------------------------------
     // Topic preferences
     //-----------------------------------------
     $_trackChoice = '';
     if ($this->request['auto_track']) {
         if (in_array($this->request['auto_track_method'], array('none', 'immediate', 'offline', 'daily', 'weekly'))) {
             $_trackChoice = $this->request['auto_track_method'];
         }
     }
     $newMember['auto_track'] = $_trackChoice;
     //-----------------------------------------
     // Custom profile field stuff
     //-----------------------------------------
     $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/customfields/profileFields.php', 'customProfileFields');
     $fields = new $classToLoad();
     $fields->initData('edit');
     $fields->parseToSave($_POST);
     /* Check the website url field */
     $website_field = $fields->getFieldIDByKey('website');
     if ($website_field && $fields->out_fields['field_' . $website_field]) {
         if (stristr($fields->out_fields['field_' . $website_field], 'http://') === FALSE && stristr($fields->out_fields['field_' . $website_field], 'https://') === FALSE) {
             $fields->out_fields['field_' . $website_field] = 'http://' . $fields->out_fields['field_' . $website_field];
         }
     }
     //-----------------------------------------
     // Throw to the DB
     //-----------------------------------------
     IPSMember::save($this->request['member_id'], array('core' => array_merge($newMember, $additionalCore), 'extendedProfile' => array_merge(array('pp_about_me' => $aboutme, 'signature' => $signature, 'pp_reputation_points' => intval($this->request['pp_reputation_points']), 'pp_setting_count_visitors' => intval($this->request['pp_setting_count_visitors']), 'pp_setting_count_comments' => intval($this->request['pp_setting_count_comments']), 'pp_setting_count_friends' => intval($this->request['pp_setting_count_friends']), 'pp_setting_moderate_comments' => intval($this->request['pp_setting_moderate_comments']), 'pp_setting_moderate_friends' => intval($this->request['pp_setting_moderate_friends']), 'pp_customization' => $this->request['removeCustomization'] ? serialize(array()) : $member['pp_customization']), $additionalExtended), 'customFields' => count($fields->out_fields) ? $fields->out_fields : array()));
     if ($member['member_group_id'] != $newMember['member_group_id']) {
         IPSLib::runMemberSync('onGroupChange', $this->request['member_id'], $newMember['member_group_id'], $member['member_group_id']);
         //-----------------------------------------
         // Remove restrictions if member demoted
         // Commenting out as this may cause more problems than it's worth
         // e.g. if you had accidentally changed their group, you'd need to reconfigure all restrictions
         //-----------------------------------------
         /*if( !$this->caches['group_cache'][ $newMember['member_group_id'] ]['g_access_cp'] )
         		{
         			$this->DB->delete( 'admin_permission_rows', 'row_id=' . $member['member_id'] . " AND row_id_type='member'" );
         		}*/
         //-----------------------------------------
         // Restriction permissions stuff
         //-----------------------------------------
         $is_admin = 0;
         $groups = ipsRegistry::cache()->getCache('group_cache');
         if (is_array($this->request['mgroup_others']) and count($this->request['mgroup_others'])) {
             foreach ($this->request['mgroup_others'] as $omg) {
                 if ($groups[intval($omg)]['g_access_cp']) {
                     $is_admin = 1;
                     break;
                 }
             }
         }
         if ($groups[intval($this->request['member_group_id'])]['g_access_cp']) {
             $is_admin = 1;
         }
         if ($is_admin && $restricted) {
             //-------------------------------------------------
             // Copy restrictions if they do not have any yet...
             //-------------------------------------------------
             $check = $this->DB->buildAndFetch(array('select' => 'row_updated', 'from' => 'admin_permission_rows', 'where' => "row_id_type='member' AND row_id=" . $this->request['member_id']));
             if (!$check['row_updated']) {
                 $this->DB->replace('admin_permission_rows', array('row_id' => $this->request['member_id'], 'row_id_type' => 'member', 'row_perm_cache' => serialize($this->registry->getClass('class_permissions')->restrictions_row), 'row_updated' => time()), array('row_id', 'row_id_type'));
             }
         }
     }
     //-----------------------------------------
     // Moved from validating group?
     //-----------------------------------------
     if ($member['member_group_id'] == $this->settings['auth_group']) {
         if ($this->request['member_group_id'] != $this->settings['auth_group']) {
             //-----------------------------------------
             // Yes...
             //-----------------------------------------
             $this->DB->delete('validating', "member_id=" . $this->request['member_id']);
         }
     }
     /* Update cache */
     IPSContentCache::update($this->request['member_id'], 'sig', $cacheSignature);
     /* Rebuild birthday cache */
     $this->cache->rebuildCache('birthdays', 'calendar');
     //-----------------------------------------
     // Redirect
     //-----------------------------------------
     ipsRegistry::getClass('adminFunctions')->saveAdminLog(sprintf($this->lang->words['m_editedlog'], $member['members_display_name']));
     $this->registry->output->global_message = $this->lang->words['m_edited'];
     if ($is_admin) {
         if (!$restricted) {
             $member = IPSMember::load($member['member_id']);
             $this->_showAdminForm($member, array());
             $this->_memberView();
         } else {
             $this->registry->output->global_message = $this->lang->words['m_edited_restricted'];
             $this->registry->output->silentRedirectWithMessage($this->settings['base_url'] . $this->form_code . '&do=viewmember&member_id=' . $this->request['member_id']);
         }
     } else {
         $this->registry->output->silentRedirectWithMessage($this->settings['base_url'] . $this->form_code . '&do=viewmember&member_id=' . $this->request['member_id']);
     }
 }
Example #17
0
 /**
  * List all of the current caches
  *
  * @return	@e void		[Outputs to screen]
  */
 public function cacheOverview()
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $content = "";
     $db_caches = array();
     $lib_caches = array();
     $cacheContent = array();
     $total = 0;
     //-----------------------------------------
     // Get stored caches
     //-----------------------------------------
     $this->DB->build(array('select' => '*', 'from' => 'cache_store'));
     $this->DB->execute();
     while ($r = $this->DB->fetch()) {
         $db_caches[$r['cs_key']] = $r;
     }
     //-----------------------------------------
     // Get core cache list
     //-----------------------------------------
     foreach ($this->registry->_fetchCoreVariables('cache') as $cache_name => $cache_data) {
         $cache_data['cache_name'] = $cache_name;
         $cache_data['_cache_size'] = IPSLib::sizeFormat(IPSLib::strlenToBytes(strlen($db_caches[$cache_name]['cs_value'])));
         $cache_data['_cs_init_load'] = $db_caches[$cache_name]['cs_init_load'];
         $total += IPSLib::strlenToBytes(strlen($db_caches[$cache_name]['cs_value']));
         $lib_caches['global'][$cache_name] = $cache_data;
     }
     //-----------------------------------------
     // Get all application's cache lists
     //-----------------------------------------
     foreach (IPSLib::getEnabledApplications() as $app_dir => $app_data) {
         $_file = IPSLib::getAppDir($app_dir) . '/extensions/coreVariables.php';
         if (is_file($_file)) {
             $CACHE = array();
             require $_file;
             /*maybeLibHook*/
             foreach ($CACHE as $cache_name => $cache_data) {
                 $cache_data['cache_name'] = $cache_name;
                 $cache_data['_cache_size'] = IPSLib::sizeFormat(IPSLib::strlenToBytes(strlen($db_caches[$cache_name]['cs_value'])));
                 $cache_data['_cs_init_load'] = $db_caches[$cache_name]['cs_init_load'];
                 $total += IPSLib::strlenToBytes(strlen($db_caches[$cache_name]['cs_value']));
                 $lib_caches[$app_dir][$cache_name] = $cache_data;
             }
         }
     }
     foreach ($lib_caches as $app => $data) {
         ksort($lib_caches[$app]);
     }
     $total = IPSLib::sizeFormat($total);
     /* Content Cache Stuffs */
     if (IPSContentCache::isEnabled()) {
         /* Get all posts */
         $statsCache = ipsRegistry::cache()->getCache('stats');
         $cacheContent['posts'] = array('count' => intval($statsCache['total_replies'] + $statsCache['total_topics']));
         /* Get all members */
         $cacheContent['members'] = $this->DB->buildAndFetch(array('select' => 'COUNT(*) as count', 'from' => 'members'));
         /* Get cached post count */
         $cacheContent['cachedPosts'] = $this->DB->buildAndFetch(array('select' => 'COUNT(*) as count', 'from' => 'content_cache_posts'));
         /* Get cached sig count */
         $cacheContent['cachedSigs'] = $this->DB->buildAndFetch(array('select' => 'COUNT(*) as count', 'from' => 'content_cache_sigs'));
         /* Work out percentages */
         $cacheContent['postPercent'] = ($cacheContent['posts']['count'] and $cacheContent['cachedPosts']['count']) ? sprintf("%.0f", $cacheContent['cachedPosts']['count'] / $cacheContent['posts']['count'] * 100) : 0;
         $cacheContent['sigPercent'] = ($cacheContent['members']['count'] and $cacheContent['cachedSigs']['count']) ? sprintf("%.0f", $cacheContent['cachedSigs']['count'] / $cacheContent['members']['count'] * 100) : 0;
     }
     $this->registry->output->html .= $this->html->cache_entry_wrapper($lib_caches, $total, $cacheContent);
 }
Example #18
0
 /**
  * Builds an array of post data for output
  *
  * @param	array	$row	Array of post data
  * @return	array
  */
 public function parsePost(array $post)
 {
     /* Init */
     $topicData = $this->getTopicData();
     $forumData = $this->registry->getClass('class_forums')->getForumById($topicData['forum_id']);
     $permissionData = $this->getPermissionData();
     /* Start memory debug */
     $_NOW = IPSDebug::getMemoryDebugFlag();
     $poster = array();
     /* Bitwise options */
     $_tmp = IPSBWOptions::thaw($post['post_bwoptions'], 'posts', 'forums');
     if (count($_tmp)) {
         foreach ($_tmp as $k => $v) {
             $post[$k] = $v;
         }
     }
     /* Is this a member? */
     if ($post['author_id'] != 0) {
         $poster = $this->parseMember($post);
     } else {
         /* Sort out guest */
         $post['author_name'] = $this->settings['guest_name_pre'] . $post['author_name'] . $this->settings['guest_name_suf'];
         $poster = IPSMember::setUpGuest($post['author_name']);
         $poster['members_display_name'] = $post['author_name'];
         $poster['_members_display_name'] = $post['author_name'];
         $poster['custom_fields'] = "";
         $poster['warn_img'] = "";
         $poster = IPSMember::buildProfilePhoto($poster);
     }
     /* Memory debug */
     IPSDebug::setMemoryDebugFlag("PID: " . $post['pid'] . " - Member Parsed", $_NOW);
     /* Update permission */
     $this->registry->getClass('class_forums')->setMemberData($this->getMemberData());
     $permissionData['softDelete'] = $this->registry->getClass('class_forums')->canSoftDeletePosts($topicData['forum_id'], $post);
     /* Soft delete */
     $post['_softDelete'] = $post['pid'] != $topicData['topic_firstpost'] ? $permissionData['softDelete'] : FALSE;
     $post['_softDeleteRestore'] = $permissionData['softDeleteRestore'];
     $post['_softDeleteSee'] = $permissionData['softDeleteSee'];
     $post['_softDeleteReason'] = $permissionData['softDeleteReason'];
     $post['_softDeleteContent'] = $permissionData['softDeleteContent'];
     $post['_isVisible'] = $this->registry->getClass('class_forums')->fetchHiddenType($post) == 'visible' ? true : false;
     $post['_isHidden'] = $this->registry->getClass('class_forums')->fetchHiddenType($post) == 'hidden' ? true : false;
     $post['_isDeleted'] = $this->registry->getClass('class_forums')->fetchHiddenType($post) == 'sdelete' ? true : false;
     /* Answered post */
     try {
         $post['_isMarkedAnswered'] = $this->postIsAnswer($post, $topicData) ? true : false;
     } catch (Exception $e) {
         $post['_isMarkedAnswered'] = false;
     }
     $post['_canMarkUnanswered'] = $post['_isMarkedAnswered'] === true && $this->canUnanswerTopic($topicData) ? true : false;
     $post['_canAnswer'] = $post['_isMarkedAnswered'] === false && $this->canAnswerTopic($topicData) ? true : false;
     $post['PermalinkUrlBit'] = '';
     /* Queued */
     if ($topicData['topic_firstpost'] == $post['pid'] and ($post['_isHidden'] or $topicData['_isHidden'])) {
         $post['queued'] = 1;
         $post['_isHidden'] = true;
     }
     if ($topicData['topic_queuedposts'] || $topicData['topic_deleted_posts']) {
         if ($topicData['topic_queuedposts'] && $topicData['Perms']['canQueuePosts']) {
             /* We have hidden data that is viewable */
             $post['PermalinkUrlBit'] = '&amp;p=' . $post['pid'];
         }
         if ($topicData['topic_deleted_posts'] && $post['_softDeleteSee']) {
             /* We have hidden data that is viewable */
             $post['PermalinkUrlBit'] = '&amp;p=' . $post['pid'];
         }
     }
     /* Edited stuff */
     $post['edit_by'] = "";
     if ($post['append_edit'] == 1 and $post['edit_time'] != "" and $post['edit_name'] != "") {
         $e_time = $this->registry->class_localization->getDate($post['edit_time'], 'LONG');
         $post['edit_by'] = sprintf($this->lang->words['edited_by'], $post['edit_name'], $e_time);
     }
     /* Now parse the post */
     if (!isset($post['cache_content']) or !$post['cache_content']) {
         $_NOW2 = IPSDebug::getMemoryDebugFlag();
         /* Grab the parser file */
         if ($this->_parser === null) {
             /* Load parser */
             $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/text/parser.php', 'classes_text_parser');
             $this->_parser = new $classToLoad();
         }
         /* set up parser */
         $this->_parser->set(array('memberData' => array('member_id' => $post['member_id'], 'member_group_id' => $post['member_group_id'], 'mgroup_others' => $post['mgroup_others']), 'parseBBCode' => $forumData['use_ibc'], 'parseHtml' => ($forumData['use_html'] and $poster['g_dohtml'] and $post['post_htmlstate']) ? 1 : 0, 'parseEmoticons' => $post['use_emo'], 'parseArea' => 'topics'));
         $post['post'] = $this->_parser->display($post['post']);
         IPSDebug::setMemoryDebugFlag("topics::parsePostRow - bbcode parse - Completed", $_NOW2);
         IPSContentCache::update($post['pid'], 'post', $post['post']);
     } else {
         $post['post'] = '<!--cached-' . gmdate('r', $post['cache_updated']) . '-->' . $post['cache_content'];
     }
     /* Buttons */
     $post['_can_delete'] = $post['pid'] != $topicData['topic_firstpost'] ? $this->canDeletePost($post) : FALSE;
     $post['_can_edit'] = $this->canEditPost($post);
     $post['_show_ip'] = $this->canSeeIp();
     $post['_canReply'] = $this->getReplyStatus() == 'reply' ? true : false;
     /* Signatures */
     $post['signature'] = "";
     if (!empty($poster['signature'])) {
         if ($post['use_sig'] == 1) {
             if (!$this->memberData['view_sigs'] || $poster['author_id'] && $this->memberData['member_id'] && !empty($this->member->ignored_users[$poster['author_id']]['ignore_signatures']) && IPSMember::isIgnorable($poster['member_group_id'], $poster['mgroup_others'])) {
                 $post['signature'] = '<!--signature.hidden.' . $post['pid'] . '-->';
             } else {
                 $post['signature'] = $this->registry->output->getTemplate('global')->signature_separator($poster['signature'], $poster['author_id'], IPSMember::isIgnorable($poster['member_group_id'], $poster['mgroup_others']));
             }
         }
     }
     $post['forum_id'] = $topicData['forum_id'];
     /* Reputation */
     if ($this->settings['reputation_enabled'] and !$this->isArchived($topicData)) {
         /* Load the class */
         if (!$this->registry->isClassLoaded('repCache')) {
             $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/class_reputation_cache.php', 'classReputationCache');
             $this->registry->setClass('repCache', new $classToLoad());
         }
         $this->memberData['_members_cache']['rep_filter'] = isset($this->memberData['_members_cache']['rep_filter']) ? $this->memberData['_members_cache']['rep_filter'] : '*';
         $post['pp_reputation_points'] = $post['pp_reputation_points'] ? $post['pp_reputation_points'] : 0;
         $post['has_given_rep'] = $post['has_given_rep'] ? $post['has_given_rep'] : 0;
         $post['rep_points'] = $this->registry->repCache->getRepPoints(array('app' => 'forums', 'type' => 'pid', 'type_id' => $post['pid'], 'rep_points' => $post['rep_points']));
         $post['_repignored'] = 0;
         if (!($this->settings['reputation_protected_groups'] && in_array($this->memberData['member_group_id'], explode(',', $this->settings['reputation_protected_groups']))) && $this->memberData['_members_cache']['rep_filter'] !== '*') {
             if ($this->settings['reputation_show_content'] && $post['rep_points'] < $this->memberData['_members_cache']['rep_filter'] && $this->settings['reputation_point_types'] != 'like') {
                 $post['_repignored'] = 1;
             }
         }
         if ($this->registry->repCache->isLikeMode()) {
             $post['like'] = $this->registry->repCache->getLikeFormatted(array('app' => 'forums', 'type' => 'pid', 'id' => $post['pid'], 'rep_like_cache' => $post['rep_like_cache']));
         }
     }
     /* Ignore stuff */
     $post['_ignored'] = 0;
     if ($post['author_id'] && isset($topicData['ignoredUsers']) && is_array($topicData['ignoredUsers']) && count($topicData['ignoredUsers'])) {
         if (in_array($post['author_id'], $topicData['ignoredUsers'])) {
             if (!strstr($this->settings['cannot_ignore_groups'], ',' . $post['member_group_id'] . ',')) {
                 $post['_ignored'] = 1;
             }
         }
     }
     /* AD Code */
     $post['_adCode'] = '';
     if ($this->registry->getClass('IPSAdCode')->userCanViewAds() && !$this->getTopicData('adCodeSet') && !IPS_IS_AJAX) {
         $post['_adCode'] = $this->registry->getClass('IPSAdCode')->getAdCode('ad_code_topic_view_code');
         if ($post['_adCode']) {
             $this->setTopicData('adCodeSet', true);
         }
     }
     /* Memory debug */
     IPSDebug::setMemoryDebugFlag("PID: " . $post['pid'] . " - Completed", $_NOW);
     /* Excerpt */
     $post['_excerpt'] = IPSText::truncate(str_replace(array('<br />', '<br>', "\n", '</p>', '<p>'), ' ', $post['post']), 500);
     return array('post' => $post, 'author' => $poster);
 }
Example #19
0
 /**
  * Write single entry to DB
  * @param	array	INTS
  */
 public function getData($data = array())
 {
     if (!$this->remoteDB) {
         return;
     }
     /* Init */
     $topicData = $data['parentData'];
     $forumData = $this->registry->getClass('class_forums')->getForumById($topicData['forum_id']);
     $permissionData = $this->registry->getClass('topics')->getPermissionData();
     $first = $data['offset'];
     $end = $data['limit'];
     $fields = $this->getFields();
     /* Default - just see all visible posts */
     $queued_query_bit = ' AND ' . $this->registry->class_forums->fetchPostHiddenQuery('visible', 'archive_');
     /* Can we deal with hidden posts? */
     if ($this->registry->class_forums->canQueuePosts($topicData['forum_id'])) {
         if ($permissionData['softDeleteSee']) {
             /* See queued and soft deleted */
             $queued_query_bit = ' AND ' . $this->registry->class_forums->fetchPostHiddenQuery(array('visible', 'hidden', 'sdeleted'), 'archive_');
         } else {
             /* Otherwise, see queued and approved */
             $queued_query_bit = ' AND ' . $this->registry->class_forums->fetchPostHiddenQuery(array('visible', 'hidden'), 'archive_');
         }
     } else {
         /* We cannot see hidden posts */
         if ($permissionData['softDeleteSee']) {
             /* See queued and soft deleted */
             $queued_query_bit = ' AND ' . $this->registry->class_forums->fetchPostHiddenQuery(array('approved', 'sdeleted'), 'archive_');
         }
     }
     /* Set up */
     /* Ignored Users */
     $ignored_users = array();
     foreach ($this->member->ignored_users as $_i) {
         if ($_i['ignore_topics']) {
             $ignored_users[] = $_i['ignore_ignore_id'];
         }
     }
     /* Format */
     $this->registry->getClass('topics')->setTopicData('adCodeSet', false);
     $this->registry->getClass('topics')->setTopicData('ignoredUsers', $ignored_users);
     $posts = array();
     $cached = array();
     /* Get posts separately */
     if (IPSLib::isUsingRemoteArchiveDB()) {
         /* Get posts */
         $this->remoteDB->build(array('select' => '*', 'from' => 'forums_archive_posts', 'where' => 'archive_topic_id=' . $topicData['tid'] . $queued_query_bit, 'order' => $fields[$data['sortKey']] . ' ' . $data['sortOrder'], 'limit' => array($first, $end)));
         $ab = $this->remoteDB->execute();
         $mids = array();
         while ($p = $this->remoteDB->fetch($ab)) {
             $posts[$p['archive_id']] = $p;
             $mids[$p['archive_author_id']] = $p['archive_author_id'];
         }
         if (count($posts)) {
             /* Get cached posts */
             $this->DB->build(array('select' => 'cache_content_id, cache_content', 'from' => 'content_cache_posts', 'where' => 'cache_content_id IN (' . implode(',', array_keys($posts)) . ')'));
             $this->DB->execute();
             while ($row = $this->DB->fetch()) {
                 $cached[$row['cache_content_id']] = $row['cache_content'];
             }
             /* Get members */
             $members = IPSMember::load($mids, 'all');
             foreach ($posts as $pid => $pdata) {
                 $pdata['member_id'] = $pdata['archive_author_id'];
                 if ($data['goNative']) {
                     $pdata = $this->archiveToNativeFields($pdata);
                 }
                 if ($pdata['author_id']) {
                     $members[$pdata['author_id']]['cache_content_sig'] = $members[$pdata['author_id']]['cache_content'];
                     unset($members[$pdata['author_id']]['cache_content']);
                     $posts[$pid] = array_merge($members[$pdata['author_id']], $pdata);
                 } else {
                     $posts[$pid] = $pdata;
                 }
                 /* Cached */
                 if (isset($cached[$pid])) {
                     $posts[$pid]['cache_content'] = $cached[$pid];
                 }
             }
         }
     } else {
         /* Joins */
         $_post_joins = array(array('select' => 'm.member_id as mid,m.name,m.member_group_id,m.email,m.joined,m.posts, m.last_visit, m.last_activity,m.login_anonymous,m.title as member_title, m.warn_level, m.warn_lastwarn, m.members_display_name, m.members_seo_name, m.has_gallery, m.has_blog, m.members_bitoptions,m.mgroup_others', 'from' => array('members' => 'm'), 'where' => 'm.member_id=a.archive_author_id', 'type' => 'left'), array('select' => 'pp.*', 'from' => array('profile_portal' => 'pp'), 'where' => 'm.member_id=pp.pp_member_id', 'type' => 'left'));
         /* Cache? */
         if (IPSContentCache::isEnabled()) {
             if (IPSContentCache::fetchSettingValue('post')) {
                 $_post_joins[] = IPSContentCache::join('post', 'a.archive_id');
             }
             if (IPSContentCache::fetchSettingValue('sig')) {
                 $_post_joins[] = IPSContentCache::join('sig', 'm.member_id', 'ccb', 'left', 'ccb.cache_content as cache_content_sig, ccb.cache_updated as cache_updated_sig');
             }
         }
         /* Get posts */
         $this->remoteDB->build(array('select' => 'a.*', 'from' => array('forums_archive_posts' => 'a'), 'where' => 'archive_topic_id=' . $topicData['tid'] . $queued_query_bit, 'order' => $fields[$data['sortKey']] . ' ' . $data['sortOrder'], 'limit' => array($first, $end), 'add_join' => $_post_joins));
         $oq = $this->remoteDB->execute();
         while ($row = $this->remoteDB->fetch($oq)) {
             $row['member_id'] = $row['archive_author_id'];
             if ($data['goNative']) {
                 $row = $this->archiveToNativeFields($row);
             }
             $posts[$row['pid']] = $row;
         }
     }
     /* Return */
     return $posts;
 }
 /**
  * Post a reply
  * Very simply posts a reply. Simple.
  *
  * Usage:
  * $post->setFopicID(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_TOPIC_ID       : No topic ID set
  * NO_FORUM_ID		: No forum ID set
  * NO_AUTHOR_SET	    : No Author set
  * NO_CONTENT        : No post content set
  * CONTENT_TOO_LONG  : Post is too long
  * NO_SUCH_TOPIC     : No such topic
  * NO_SUCH_FORUM		: No such forum
  * NO_REPLY_PERM     : Author cannot reply to this topic
  * TOPIC_LOCKED		: The topic is locked
  * NO_REPLY_POLL     : Cannot reply to this poll only topic
  * TOPIC_LOCKED		: The topic is locked
  * NO_REPLY_POLL		: This is a poll only topic
  * NO_POST_FORUM		: Unable to post in that forum
  * FORUM_LOCKED		: Forum read only
  *
  * @access	public
  * @return	mixed
  */
 public function editPost()
 {
     //-----------------------------------------
     // Set up
     //-----------------------------------------
     $topic_id = intval($this->getTopicID());
     $forum_id = intval($this->getForumID());
     //-----------------------------------------
     // Global checks and functions
     //-----------------------------------------
     try {
         $this->globalSetUp();
     } catch (Exception $error) {
         $this->_postErrors = $error->getMessage();
     }
     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($postContent) > $this->settings['max_post_length'] * 1024) {
         $this->_postErrors = 'CONTENT_TOO_LONG';
     }
     //-----------------------------------------
     // 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;
         # Set Settings
         $this->setSettings(array('enableSignature' => $this->_originalPost['use_sig'] ? 1 : 0, 'enableEmoticons' => $this->_originalPost['use_emo'] ? 1 : 0, 'post_htmlstatus' => intval($this->_originalPost['post_htmlstate'])));
         $this->request['iconid'] = $this->_originalPost['icon_id'];
         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=" . $topic['tid']));
         $this->DB->execute();
         $this->poll_answers = $this->poll_data['choices'] ? unserialize(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;
     }
     //-----------------------------------------
     // Grab the edit time
     //-----------------------------------------
     $time = ipsRegistry::getClass('class_localization')->getDate(time(), 'LONG');
     //-----------------------------------------
     // 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'] = time();
     $post['edit_name'] = $this->getAuthor('members_display_name');
     //-----------------------------------------
     // If the post icon has changed, update the topic post icon
     //-----------------------------------------
     if ($this->_originalPost['new_topic'] == 1) {
         if ($post['icon_id'] != $this->_originalPost['icon_id']) {
             $this->DB->update('topics', array('icon_id' => $post['icon_id']), 'tid=' . $topic['tid']);
         }
     }
     //-----------------------------------------
     // Update open and close times
     //-----------------------------------------
     if ($this->_originalPost['new_topic'] == 1) {
         $times = array();
         if ($this->can_set_open_time and $this->times['open']) {
             $times['topic_open_time'] = intval($this->times['open']);
             if ($topic['topic_open_time'] and $this->times['open']) {
                 $times['state'] = "closed";
                 if (time() > $topic['topic_open_time']) {
                     if (time() < $topic['topic_close_time']) {
                         $times['state'] = "open";
                     }
                 }
             }
             if (!$this->times['open'] and $topic['topic_open_time']) {
                 if ($topic['state'] == 'closed') {
                     $times['state'] = 'open';
                 }
             }
         }
         if ($this->can_set_close_time and $this->times['close']) {
             $times['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') {
                     $times['state'] = 'open';
                 }
             }
         }
         if (count($times)) {
             $this->DB->update('topics', $times, "tid=" . $topic['tid']);
         }
     }
     //-----------------------------------------
     // 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']) {
                 $this->DB->update('polls', 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)), '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' => my_getenv('HTTP_REFERER'), 'ctime' => time(), 'topic_title' => $topic['title'], 'action' => "Edited poll", 'query_string' => my_getenv('QUERY_STRING')));
                 }
             } else {
                 $this->DB->insert('polls', array('tid' => $topic['tid'], 'forum_id' => $this->getForumData('id'), 'start_date' => time(), '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)));
                 $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' => my_getenv('HTTP_REFERER'), 'ctime' => time(), 'topic_title' => $topic['title'], 'action' => "Added a poll to the topic titled '" . $this->request['poll_question'] . "'", 'query_string' => my_getenv('QUERY_STRING')));
                 $this->DB->update('topics', array('poll_state' => 1, 'last_vote' => 0, 'total_votes' => 0), 'tid=' . $topic['tid']);
             }
         } else {
             //-----------------------------------------
             // Remove the poll
             //-----------------------------------------
             $this->DB->buildAndFetch(array('delete' => 'polls', 'where' => "tid=" . $topic['tid']));
             $this->DB->buildAndFetch(array('delete' => 'voters', 'where' => "tid=" . $topic['tid']));
             $this->DB->update('topics', array('poll_state' => 0, 'last_vote' => 0, 'total_votes' => 0), 'tid=' . $topic['tid']);
         }
     }
     //-----------------------------------------
     // Update topic title?
     //-----------------------------------------
     if ($this->edit_title == 1) {
         //-----------------------------------------
         // Update topic title
         //-----------------------------------------
         if ($this->_topicTitle != "") {
             if ($this->_topicTitle != $topic['title'] or $this->_topicDescription != $topic['description'] or !$topic['title_seo']) {
                 $this->DB->update('topics', array('title' => $this->_topicTitle, 'title_seo' => IPSText::makeSeoTitle($this->_topicTitle), 'description' => $this->_topicDescription), "tid=" . $topic['tid']);
                 if ($topic['tid'] == $this->getForumData('last_id')) {
                     $this->DB->update('forums', array('last_title' => $this->_topicTitle), 'id=' . $this->getForumData('id'));
                     //ipsRegistry::getClass('class_forums')->updateForumCache();
                 }
                 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' => my_getenv('HTTP_REFERER'), 'ctime' => time(), 'topic_title' => $topic['title'], 'action' => "Edited topic title or description '{$topic['title']}' to '" . $this->_topicTitle . "' via post form", 'query_string' => my_getenv('QUERY_STRING')));
                 }
             }
         }
     }
     //-----------------------------------------
     // Reason for edit?
     //-----------------------------------------
     if ($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->getAuthor('g_append_edit')) {
         if ($this->request['add_edit'] != 1) {
             $post['append_edit'] = 0;
         }
     }
     $this->DB->force_data_type = array('post_edit_reason' => 'string');
     $this->DB->update('posts', $post, 'pid=' . $this->_originalPost['pid']);
     if ($this->_originalPost['topic_firstpost']) {
         $pid = 0;
         $title = $r['title'];
     } else {
         $pid = serialize(array('pid' => $r['pid'], 'title' => $r['title']));
         $title = '';
     }
     /* Remove from the search index */
     $this->registry->class_forums->removePostFromSearchIndex($post['topic_id'], $this->_originalPost['pid'], $topic['posts'] ? 0 : 1);
     /* Update the search index */
     $topic_title = $this->_topicTitle ? $this->_topicTitle : $topic['title'];
     /* 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;
 }
 /**
  * Parse a member for display
  *
  * @access	public
  * @param	mixed	Either array of member data, or member ID to self load
  * @param	array 	Array of flags to parse: 'signature', 'customFields', 'avatar', 'warn'
  * @return	array 	Parsed member data
  */
 public static function buildDisplayData($member, $_parseFlags = array())
 {
     $_NOW = IPSDebug::getMemoryDebugFlag();
     //-----------------------------------------
     // Figure out parse flags
     //-----------------------------------------
     $parseFlags = array('signature' => isset($_parseFlags['signature']) ? $_parseFlags['signature'] : 0, 'customFields' => isset($_parseFlags['customFields']) ? $_parseFlags['customFields'] : 0, 'avatar' => isset($_parseFlags['avatar']) ? $_parseFlags['avatar'] : 1, 'warn' => isset($_parseFlags['warn']) ? $_parseFlags['warn'] : 1, 'cfSkinGroup' => isset($_parseFlags['cfSkinGroup']) ? $_parseFlags['cfSkinGroup'] : '', 'cfGetGroupData' => isset($_parseFlags['cfGetGroupData']) ? $_parseFlags['cfGetGroupData'] : '', 'cfLocation' => isset($_parseFlags['cfLocation']) ? $_parseFlags['cfLocation'] : '', 'checkFormat' => isset($_parseFlags['checkFormat']) ? $_parseFlags['checkFormat'] : 0);
     if (isset($_parseFlags['__all__'])) {
         foreach ($parseFlags as $k => $v) {
             $parseFlags[$k] = 1;
         }
         $parseFlags['cfSkinGroup'] = '';
     }
     //-----------------------------------------
     // Load the member?
     //-----------------------------------------
     if (!is_array($member) and ($member == intval($member) and $member > 0)) {
         $member = self::load($member, 'all');
     }
     if (!$member['member_group_id']) {
         $member['member_group_id'] = ipsRegistry::$settings['guest_group'];
     }
     /* Unpack bitwise if required */
     if (!isset($member['bw_is_spammer'])) {
         $member = self::buildBitWiseOptions($member);
     }
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $rank_cache = ipsRegistry::cache()->getCache('ranks');
     $group_cache = ipsRegistry::cache()->getCache('group_cache');
     $group_name = IPSLib::makeNameFormatted($group_cache[$member['member_group_id']]['g_title'], $member['member_group_id']);
     $pips = 0;
     $topic_id = intval(isset(ipsRegistry::$request['t']) ? ipsRegistry::$request['t'] : 0);
     $forum_id = intval(isset(ipsRegistry::$request['f']) ? ipsRegistry::$request['f'] : 0);
     //-----------------------------------------
     // SEO Name
     //-----------------------------------------
     $member['members_seo_name'] = self::fetchSeoName($member);
     //-----------------------------------------
     // Avatar
     //-----------------------------------------
     if ($parseFlags['avatar']) {
         $member['avatar'] = self::buildAvatar($member);
     }
     $member['_group_formatted'] = $group_name;
     //-----------------------------------------
     // Ranks
     //-----------------------------------------
     if (is_array($rank_cache) and count($rank_cache)) {
         foreach ($rank_cache as $k => $v) {
             if ($member['posts'] >= $v['POSTS']) {
                 if (!isset($member['title']) || $member['title'] === '' || is_null($member['title'])) {
                     $member['title'] = $v['TITLE'];
                 }
                 $pips = $v['PIPS'];
                 break;
             }
         }
     }
     //-----------------------------------------
     // Group image
     //-----------------------------------------
     $member['member_rank_img'] = '';
     $member['member_rank_img_i'] = '';
     if ($group_cache[$member['member_group_id']]['g_icon']) {
         $_img = $group_cache[$member['member_group_id']]['g_icon'];
         if (substr($_img, 0, 4) != 'http') {
             $_img = ipsRegistry::$settings['_original_base_url'] . '/' . ltrim($_img, '/');
         }
         $member['member_rank_img_i'] = 'img';
         $member['member_rank_img'] = $_img;
     } else {
         if ($pips) {
             if (is_numeric($pips)) {
                 for ($i = 1; $i <= $pips; ++$i) {
                     $member['member_rank_img_i'] = 'pips';
                     $member['member_rank_img'] .= ipsRegistry::getClass('output')->getReplacement('pip_pip');
                 }
             } else {
                 $member['member_rank_img_i'] = 'img';
                 $member['member_rank_img'] = ipsRegistry::$settings['public_dir'] . 'style_extra/team_icons/' . $pips;
             }
         }
     }
     //-----------------------------------------
     // Spammer status
     //-----------------------------------------
     $member['spamStatus'] = NULL;
     $member['spamImage'] = NULL;
     $moderator = ipsRegistry::member()->getProperty('forumsModeratorData');
     if (isset($moderator[$forum_id]['bw_flag_spammers']) and $moderator[$forum_id]['bw_flag_spammers'] or ipsRegistry::member()->getProperty('g_is_supmod') == 1) {
         if (!ipsRegistry::$settings['warn_on'] or !strstr(',' . ipsRegistry::$settings['warn_protected'] . ',', ',' . $member['member_group_id'] . ',')) {
             if ($member['bw_is_spammer']) {
                 $member['spamStatus'] = TRUE;
             } else {
                 $member['spamStatus'] = FALSE;
             }
         }
     }
     //-----------------------------------------
     // Warny porny?
     //-----------------------------------------
     if ($parseFlags['warn'] and $member['member_id']) {
         $member['warn_percent'] = NULL;
         $member['can_edit_warn'] = false;
         $member['warn_img'] = NULL;
         if (ipsRegistry::$settings['warn_on'] and !strstr(',' . ipsRegistry::$settings['warn_protected'] . ',', ',' . $member['member_group_id'] . ',')) {
             /* Warnings */
             if (isset($moderator[$forum_id]['allow_warn']) and $moderator[$forum_id]['allow_warn'] or ipsRegistry::member()->getProperty('g_is_supmod') == 1 or ipsRegistry::$settings['warn_show_own'] and ipsRegistry::member()->getProperty('member_id') == $member['member_id']) {
                 // Work out which image to show.
                 if ($member['warn_level'] <= ipsRegistry::$settings['warn_min']) {
                     $member['warn_img'] = '{parse replacement="warn_0"}';
                     $member['warn_percent'] = 0;
                 } else {
                     if ($member['warn_level'] >= ipsRegistry::$settings['warn_max']) {
                         $member['warn_img'] = '{parse replacement="warn_5"}';
                         $member['warn_percent'] = 100;
                     } else {
                         $member['warn_percent'] = $member['warn_level'] ? sprintf("%.0f", $member['warn_level'] / ipsRegistry::$settings['warn_max'] * 100) : 0;
                         if ($member['warn_percent'] > 100) {
                             $member['warn_percent'] = 100;
                         }
                         if ($member['warn_percent'] >= 81) {
                             $member['warn_img'] = '{parse replacement="warn_5"}';
                         } else {
                             if ($member['warn_percent'] >= 61) {
                                 $member['warn_img'] = '{parse replacement="warn_4"}';
                             } else {
                                 if ($member['warn_percent'] >= 41) {
                                     $member['warn_img'] = '{parse replacement="warn_3"}';
                                 } else {
                                     if ($member['warn_percent'] >= 21) {
                                         $member['warn_img'] = '{parse replacement="warn_2"}';
                                     } else {
                                         if ($member['warn_percent'] >= 1) {
                                             $member['warn_img'] = '{parse replacement="warn_1"}';
                                         } else {
                                             $member['warn_img'] = '{parse replacement="warn_0"}';
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 if ($member['warn_percent'] < 1) {
                     $member['warn_percent'] = 0;
                 }
                 /* Bug 14770 - Change so you can't warn yourself */
                 if ((isset($moderator[$forum_id]['allow_warn']) and $moderator[$forum_id]['allow_warn'] or ipsRegistry::member()->getProperty('g_is_supmod') == 1) and $member['member_id'] != ipsRegistry::member()->getProperty('member_id')) {
                     $member['can_edit_warn'] = true;
                 }
             }
         }
     }
     //-----------------------------------------
     // Profile fields stuff
     //-----------------------------------------
     $member['custom_fields'] = "";
     if ($parseFlags['customFields'] == 1 and $member['member_id']) {
         if (isset(self::$_parsedCustomFields[$member['member_id']])) {
             $member['custom_fields'] = self::$_parsedCustomFields[$member['member_id']];
             if ($parseFlags['cfGetGroupData'] and isset(self::$_parsedCustomGroups[$member['member_id']]) and is_array(self::$_parsedCustomGroups[$member['member_id']])) {
                 $member['custom_field_groups'] = self::$_parsedCustomGroups[$member['member_id']];
             }
         } else {
             if (!is_object(self::$custom_fields_class)) {
                 require_once IPS_ROOT_PATH . 'sources/classes/customfields/profileFields.php';
                 self::$custom_fields_class = new customProfileFields();
             }
             if (self::$custom_fields_class) {
                 self::$custom_fields_class->member_data = $member;
                 self::$custom_fields_class->skinGroup = $parseFlags['cfSkinGroup'];
                 self::$custom_fields_class->initData();
                 self::$custom_fields_class->parseToView($parseFlags['checkFormat'], $parseFlags['cfLocation']);
                 $member['custom_fields'] = self::$custom_fields_class->out_fields;
                 self::$_parsedCustomFields[$member['member_id']] = $member['custom_fields'];
                 if ($parseFlags['cfGetGroupData']) {
                     $member['custom_field_groups'] = self::$custom_fields_class->fetchGroupTitles();
                     self::$_parsedCustomGroups[$member['member_id']] = $member['custom_field_groups'];
                 }
             }
         }
     }
     //-----------------------------------------
     // Profile photo
     //-----------------------------------------
     $member = self::buildProfilePhoto($member);
     //-----------------------------------------
     // Personal statement 'bbcode'
     //-----------------------------------------
     if (stripos($member['pp_bio_content'], '[b]') !== false) {
         if (stripos($member['pp_bio_content'], '[/b]') > stripos($member['pp_bio_content'], '[b]')) {
             $member['pp_bio_content'] = str_ireplace('[b]', '<strong>', $member['pp_bio_content']);
             $member['pp_bio_content'] = str_ireplace('[/b]', '</strong>', $member['pp_bio_content']);
         }
     }
     if (stripos($member['pp_bio_content'], '[i]') !== false) {
         if (stripos($member['pp_bio_content'], '[/i]') > stripos($member['pp_bio_content'], '[i]')) {
             $member['pp_bio_content'] = str_ireplace('[i]', '<em>', $member['pp_bio_content']);
             $member['pp_bio_content'] = str_ireplace('[/i]', '</em>', $member['pp_bio_content']);
         }
     }
     if (stripos($member['pp_bio_content'], '[u]') !== false) {
         if (stripos($member['pp_bio_content'], '[/u]') > stripos($member['pp_bio_content'], '[u]')) {
             $member['pp_bio_content'] = str_ireplace('[u]', '<span class="underscore">', $member['pp_bio_content']);
             $member['pp_bio_content'] = str_ireplace('[/u]', '</span>', $member['pp_bio_content']);
         }
     }
     //-----------------------------------------
     // Signature bbcode
     //-----------------------------------------
     if (isset($member['signature']) and $member['signature'] and $parseFlags['signature']) {
         if (isset(self::$_parsedSignatures[$member['member_id']])) {
             $member['signature'] = self::$_parsedSignatures[$member['member_id']];
         } else {
             if ($member['cache_content']) {
                 $member['signature'] = '<!--cached-' . gmdate('r', $member['cache_updated']) . '-->' . $member['cache_content'];
             } else {
                 IPSText::getTextClass('bbcode')->parse_bbcode = ipsRegistry::$settings['sig_allow_ibc'];
                 IPSText::getTextClass('bbcode')->parse_smilies = 1;
                 IPSText::getTextClass('bbcode')->parse_html = ipsRegistry::$settings['sig_allow_html'];
                 IPSText::getTextClass('bbcode')->parse_nl2br = 1;
                 IPSText::getTextClass('bbcode')->parsing_section = 'signatures';
                 IPSText::getTextClass('bbcode')->parsing_mgroup = $member['member_group_id'];
                 IPSText::getTextClass('bbcode')->parsing_mgroup_others = $member['mgroup_others'];
                 $member['signature'] = IPSText::getTextClass('bbcode')->preDisplayParse($member['signature']);
                 IPSContentCache::update($member['member_id'], 'sig', $member['signature']);
             }
             self::$_parsedSignatures[$member['member_id']] = $member['signature'];
         }
     }
     //-----------------------------------------
     // If current session, reset last_activity
     //-----------------------------------------
     if (!empty($member['running_time'])) {
         $member['last_activity'] = $member['running_time'] > $member['last_activity'] ? $member['running_time'] : $member['last_activity'];
     }
     //-----------------------------------------
     // Online?
     //-----------------------------------------
     $time_limit = time() - ipsRegistry::$settings['au_cutoff'] * 60;
     $member['_online'] = 0;
     if (!ipsRegistry::$settings['disable_anonymous'] and isset($member['login_anonymous'])) {
         list($be_anon, $loggedin) = explode('&', $member['login_anonymous']);
     } else {
         $be_anon = 0;
         $loggedin = $member['last_activity'] > $time_limit ? 1 : 0;
     }
     $bypass_anon = 0;
     $our_mgroups = array();
     if (ipsRegistry::member()->getProperty('mgroup_others')) {
         $our_mgroups = explode(",", IPSText::cleanPermString(ipsRegistry::member()->getProperty('mgroup_others')));
     }
     $our_mgroups[] = ipsRegistry::member()->getProperty('member_group_id');
     if (ipsRegistry::member()->getProperty('g_access_cp') and !ipsRegistry::$settings['disable_admin_anon']) {
         $bypass_anon = 1;
     }
     if (($member['last_visit'] > $time_limit or $member['last_activity'] > $time_limit) and ($be_anon != 1 or $bypass_anon == 1) and $loggedin == 1) {
         $member['_online'] = 1;
     }
     //-----------------------------------------
     // Last Active
     //-----------------------------------------
     $member['_last_active'] = ipsRegistry::getClass('class_localization')->getDate($member['last_activity'], 'SHORT');
     if ($be_anon == 1) {
         // Member last logged in anonymous
         if (!ipsRegistry::member()->getProperty('g_access_cp') or ipsRegistry::$settings['disable_admin_anon']) {
             $member['_last_active'] = ipsRegistry::getClass('class_localization')->words['private'];
         }
     }
     //-----------------------------------------
     // Rating
     //-----------------------------------------
     $member['_pp_rating_real'] = intval($member['pp_rating_real']);
     //-----------------------------------------
     // Long display names
     //-----------------------------------------
     $member['members_display_name_short'] = IPSText::truncate($member['members_display_name'], 16);
     //-----------------------------------------
     // Reputation
     //-----------------------------------------
     if (!ipsRegistry::isClassLoaded('repCache')) {
         require_once IPS_ROOT_PATH . 'sources/classes/class_reputation_cache.php';
         ipsRegistry::setClass('repCache', new classReputationCache());
     }
     $member['pp_reputation_points'] = $member['pp_reputation_points'] ? $member['pp_reputation_points'] : 0;
     $member['author_reputation'] = ipsRegistry::getClass('repCache')->getReputation($member['pp_reputation_points']);
     //-----------------------------------------
     // Other stuff not worthy of individual comments
     //-----------------------------------------
     $member['members_profile_views'] = isset($member['members_profile_views']) ? $member['members_profile_views'] : 0;
     $member['_pp_profile_views'] = ipsRegistry::getClass('class_localization')->formatNumber($member['members_profile_views']);
     IPSDebug::setMemoryDebugFlag("IPSMember::buildDisplayData: " . $member['member_id'] . " - Completed", $_NOW);
     return $member;
 }
 /**
  * Flag an account as spammer
  *
  * @param	int|array	$member				Member Data
  * @param	array		$marker				The person marking this person a spammer
  * @param	bool		$resetLastMember	If FALSE skips resetting the last registered member
  * @return	void
  */
 public static function flagMemberAsSpammer($member, $marker = NULL, $resetLastMember = TRUE)
 {
     //-----------------------------------------
     // Init
     //-----------------------------------------
     /* Load Member */
     if (!is_array($member)) {
         $member = self::load($member);
     }
     /* Load moderator library (we'll need this to unapprove posts and log) */
     $classToLoad = IPSLib::loadLibrary(IPSLib::getAppDir('forums') . '/sources/classes/moderate.php', 'moderatorLibrary', 'forums');
     $modLibrary = new $classToLoad(ipsRegistry::instance());
     //-----------------------------------------
     // Do it
     //-----------------------------------------
     $toSave = array();
     $toSave['core']['bw_is_spammer'] = TRUE;
     /* Shut off twitter/FB status importing */
     $bwOptions = IPSBWOptions::thaw($member['tc_bwoptions'], 'twitter');
     $bwOptions['tc_si_status'] = 0;
     $twitter = IPSBWOptions::freeze($bwOptions, 'twitter');
     $bwOptions = IPSBWOptions::thaw($member['fb_bwoptions'], 'facebook');
     $bwOptions['fbc_si_status'] = 0;
     $facebook = IPSBWOptions::freeze($bwOptions, 'facebook');
     $toSave['extendedProfile']['tc_bwoptions'] = $twitter;
     $toSave['extendedProfile']['fb_bwoptions'] = $facebook;
     /* Do any disabling, unapproving, banning - no breaks here since if we ban, we also want to unapprove posts, etc. */
     /* Note that there are DELIBERATELY no breaks in this switch since the options are cascading (if you ban, you also want to unapprove content) */
     switch (ipsRegistry::$settings['spm_option']) {
         /* Empty profile and ban account */
         case 'ban':
             // ban
             $toSave['core']['member_banned'] = TRUE;
             // wipe data
             $toSave['core']['title'] = '';
             $toSave['extendedProfile']['signature'] = '';
             $toSave['extendedProfile']['pp_about_me'] = '';
             // wipe photo
             $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/member/photo.php', 'classes_member_photo');
             $photos = new $classToLoad(ipsRegistry::instance());
             $photos->remove($member['member_id']);
             // wipe custom fields
             $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/customfields/profileFields.php', 'customProfileFields');
             $fields = new $classToLoad();
             $fields->member_data = $member;
             $fields->initData('edit');
             $fields->parseToSave(array());
             if (count($fields->out_fields)) {
                 $toSave['customFields'] = $fields->out_fields;
             }
             // wipe signature
             IPSContentCache::update($member['member_id'], 'sig', '');
             /* Unapprove posts */
         /* Unapprove posts */
         case 'unapprove':
             $modLibrary->deleteMemberContent($member['member_id'], 'all', intval(ipsRegistry::$settings['spm_post_days']) * 24);
             /* Disable Post/PM permission */
         /* Disable Post/PM permission */
         case 'disable':
             $toSave['core']['restrict_post'] = 1;
             $toSave['core']['members_disable_pm'] = 2;
     }
     self::save($member['member_id'], $toSave);
     //-----------------------------------------
     // Run memberSync
     //-----------------------------------------
     IPSLib::runMemberSync('onSetAsSpammer', array_merge($member, $toSave));
     //-----------------------------------------
     // Let the admin know if necessary
     //-----------------------------------------
     if ($marker !== NULL and ipsRegistry::$settings['spm_notify'] and ipsRegistry::$settings['email_in'] != $marker['email']) {
         ipsRegistry::getClass('class_localization')->loadLanguageFile(array('public_mod'), 'forums');
         ipsRegistry::getClass('class_localization')->loadLanguageFile(array('admin_member'), 'members');
         IPSText::getTextClass('email')->getTemplate('possibleSpammer');
         IPSText::getTextClass('email')->buildMessage(array('DATE' => ipsRegistry::getClass('class_localization')->getDate($member['joined'], 'LONG', 1), 'MEMBER_NAME' => $member['members_display_name'], 'IP' => $member['ip_address'], 'EMAIL' => $member['email'], 'LINK' => ipsRegistry::getClass('output')->buildSEOUrl("showuser=" . $member['member_id'], 'public', $member['members_seo_name'], 'showuser')));
         IPSText::getTextClass('email')->subject = sprintf(ipsRegistry::getClass('class_localization')->words['new_registration_email_spammer'], ipsRegistry::$settings['board_name']);
         IPSText::getTextClass('email')->to = ipsRegistry::$settings['email_in'];
         IPSText::getTextClass('email')->sendMail();
     }
     /* Reset last member? */
     if ($resetLastMember) {
         self::resetLastRegisteredMember();
     }
     //-----------------------------------------
     // Let IPS know
     //-----------------------------------------
     if (ipsRegistry::$settings['spam_service_send_to_ips']) {
         self::querySpamService($member['email'], $member['ip_address'], 'markspam');
     }
     //-----------------------------------------
     // Log
     //-----------------------------------------
     ipsRegistry::getClass('class_localization')->loadLanguageFile(array('public_modcp'), 'core');
     $modLibrary->addModerateLog(0, 0, 0, 0, ipsRegistry::getClass('class_localization')->words['flag_spam_done'] . ': ' . $member['member_id'] . ' - ' . $member['email']);
 }
 /**
  * Edit a member [process]
  *
  * @access	private
  * @return	void		[Outputs to screen]
  */
 private function _memberDoEdit()
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $this->request['member_id'] = intval($this->request['member_id']);
     //-----------------------------------------
     // Auth check...
     //-----------------------------------------
     ipsRegistry::getClass('adminFunctions')->checkSecurityKey($this->request['secure_key']);
     //-----------------------------------------
     // Load and config the std/rte editors
     //-----------------------------------------
     IPSText::getTextClass('editor')->from_acp = 1;
     //-----------------------------------------
     // Get member
     //-----------------------------------------
     $member = IPSMember::load($this->request['member_id'], 'all');
     //-----------------------------------------
     // Allowed to edit administrators?
     //-----------------------------------------
     if ($member['member_id'] != $this->memberData['member_id'] and $member['g_access_cp'] and !$this->registry->getClass('class_permissions')->checkPermission('member_edit_admin')) {
         $this->registry->output->global_message = $this->lang->words['m_editadmin'];
         $this->_memberView();
         return;
     }
     //-----------------------------------------
     // Allowed to change an admin's groups?
     //-----------------------------------------
     if ($member['g_access_cp'] and !$this->registry->getClass('class_permissions')->checkPermission('member_move_admin1')) {
         $same = false;
         if ($this->request['member_group_id'] == $member['member_group_id']) {
             $omgroups = explode(',', IPSText::cleanPermString($member['mgroup_others']));
             $groups = $_POST['mgroup_others'] ? $_POST['mgroup_others'] : array();
             if (!count(array_diff($omgroups, $groups))) {
                 $same = true;
             }
         }
         if (!$same) {
             $this->registry->output->global_message = $this->lang->words['m_admindemote'];
             $this->_memberView();
             return;
         }
     }
     //-----------------------------------------
     // What about promoting to admin?
     //-----------------------------------------
     if (!$member['g_access_cp'] and !$this->registry->getClass('class_permissions')->checkPermission('member_move_admin2')) {
         $groups = $_POST['mgroup_others'] ? $_POST['mgroup_others'] : array();
         $groups[] = intval($this->request['member_group_id']);
         foreach ($groups as $group_id) {
             if ($this->caches['group_cache'][$group_id]['g_access_cp']) {
                 $this->registry->output->global_message = $this->lang->words['m_adminpromote'];
                 $this->_memberView();
                 return;
             }
         }
     }
     if ($this->request['identity_url']) {
         $account = $this->DB->buildAndFetch(array('select' => 'member_id', 'from' => 'members', 'where' => "identity_url='" . trim($this->request['identity_url']) . "' AND member_id<>" . $member['member_id']));
         if ($account['member_id']) {
             $this->registry->output->global_message = $this->lang->words['identity_url_inuse'];
             $this->_memberView();
             return;
         }
     }
     //-----------------------------------------
     // Convert sig
     //-----------------------------------------
     $signature = IPSText::getTextClass('editor')->processRawPost('signature');
     IPSText::getTextClass('bbcode')->parse_smilies = 0;
     IPSText::getTextClass('bbcode')->parse_bbcode = $this->settings['sig_allow_ibc'];
     IPSText::getTextClass('bbcode')->parse_html = $this->settings['sig_allow_html'];
     IPSText::getTextClass('bbcode')->parse_nl2br = 1;
     IPSText::getTextClass('bbcode')->parsing_section = 'signatures';
     $signature = IPSText::getTextClass('bbcode')->preDbParse($signature);
     $cacheSignature = IPSText::getTextClass('bbcode')->preDisplayParse($signature);
     //-----------------------------------------
     // And 'About Me'
     //-----------------------------------------
     $aboutme = IPSText::getTextClass('editor')->processRawPost('aboutme');
     IPSText::getTextClass('bbcode')->parse_smilies = $this->settings['aboutme_emoticons'];
     IPSText::getTextClass('bbcode')->parse_bbcode = $this->settings['aboutme_bbcode'];
     IPSText::getTextClass('bbcode')->parse_html = $this->settings['aboutme_html'];
     IPSText::getTextClass('bbcode')->parse_nl2br = 1;
     IPSText::getTextClass('bbcode')->parsing_section = 'aboutme';
     $aboutme = IPSText::getTextClass('bbcode')->preDbParse($aboutme);
     //-----------------------------------------
     // Ok? Load interface and child classes
     //-----------------------------------------
     $additionalCore = array();
     $additionalExtended = array();
     IPSLib::loadInterface('admin/member_form.php');
     foreach (ipsRegistry::$applications as $app_dir => $app_data) {
         if (!IPSLib::appIsInstalled($app_dir)) {
             continue;
         }
         if (file_exists(IPSLib::getAppDir($app_dir) . '/extensions/admin/member_form.php')) {
             require_once IPSLib::getAppDir($app_dir) . '/extensions/admin/member_form.php';
             $_class = 'admin_member_form__' . $app_dir;
             $_object = new $_class($this->registry);
             $remote = $_object->getForSave();
             $additionalCore = array_merge($remote['core'], $additionalCore);
             $additionalExtended = array_merge($remote['extendedProfile'], $additionalExtended);
         }
     }
     //-----------------------------------------
     // Fix custom title
     // @see	http://forums./index.php?app=tracker&showissue=17383
     //-----------------------------------------
     $memberTitle = $this->request['title'];
     $rankCache = ipsRegistry::cache()->getCache('ranks');
     if (is_array($rankCache) && count($rankCache)) {
         foreach ($rankCache as $k => $v) {
             if ($member['posts'] >= $v['POSTS']) {
                 /* If this is the title passed to us from the form, we didn't have a custom title */
                 if ($v['TITLE'] == $memberTitle) {
                     $memberTitle = '';
                 }
                 break;
             }
         }
     }
     $newMember = array('member_group_id' => intval($this->request['member_group_id']), 'title' => $memberTitle, 'time_offset' => floatval($this->request['time_offset']), 'language' => $this->request['language'], 'skin' => intval($this->request['skin']), 'hide_email' => intval($this->request['hide_email']), 'allow_admin_mails' => intval($this->request['allow_admin_mails']), 'view_sigs' => intval($this->request['view_sigs']), 'view_pop' => intval($this->request['view_pop']), 'email_pm' => intval($this->request['email_pm']), 'posts' => intval($this->request['posts']), 'bday_day' => intval($this->request['bday_day']), 'bday_month' => intval($this->request['bday_month']), 'bday_year' => intval($this->request['bday_year']), 'warn_level' => intval($this->request['warn_level']), 'members_disable_pm' => intval($this->request['members_disable_pm']), 'mgroup_others' => $_POST['mgroup_others'] ? ',' . implode(",", $_POST['mgroup_others']) . ',' : '', 'identity_url' => trim($this->request['identity_url']));
     //-----------------------------------------
     // Throw to the DB
     //-----------------------------------------
     IPSMember::save($this->request['member_id'], array('core' => array_merge($newMember, $additionalCore), 'extendedProfile' => array_merge(array('pp_gender' => $this->request['pp_gender'] == 'male' ? 'male' : ($this->request['pp_gender'] == 'female' ? 'female' : ''), 'pp_bio_content' => IPSText::mbsubstr(nl2br($this->request['pp_bio_content']), 0, 300), 'pp_about_me' => $aboutme, 'signature' => $signature, 'pp_reputation_points' => intval($this->request['pp_reputation_points']), 'pp_status' => $this->request['pp_status'], 'pp_setting_count_visitors' => intval($this->request['pp_setting_count_visitors']), 'pp_setting_count_comments' => intval($this->request['pp_setting_count_comments']), 'pp_setting_count_friends' => intval($this->request['pp_setting_count_friends']), 'pp_setting_notify_comments' => $this->request['pp_setting_notify_comments'], 'pp_setting_notify_friend' => $this->request['pp_setting_notify_friend'], 'pp_setting_moderate_comments' => intval($this->request['pp_setting_moderate_comments']), 'pp_setting_moderate_friends' => intval($this->request['pp_setting_moderate_friends'])), $additionalExtended)));
     if ($member['member_group_id'] != $newMember['member_group_id']) {
         IPSLib::runMemberSync('onGroupChange', $this->request['member_id'], $newMember['member_group_id']);
         //-----------------------------------------
         // Remove restrictions if member demoted
         // Commenting out as this may cause more problems than it's worth
         // e.g. if you had accidentally changed their group, you'd need to reconfigure all restrictions
         //-----------------------------------------
         /*if( !$this->caches['group_cache'][ $newMember['member_group_id'] ]['g_access_cp'] )
         		{
         			$this->DB->delete( 'admin_permission_rows', 'row_id=' . $member['member_id'] . " AND row_id_type='member'" );
         		}*/
     }
     //-----------------------------------------
     // Restriction permissions stuff
     //-----------------------------------------
     if (is_array($this->registry->getClass('class_permissions')->restrictions_row) and count($this->registry->getClass('class_permissions')->restrictions_row)) {
         $is_admin = 0;
         $groups = ipsRegistry::cache()->getCache('group_cache');
         if (is_array($this->request['mgroup_others']) and count($this->request['mgroup_others'])) {
             foreach ($this->request['mgroup_others'] as $omg) {
                 if ($groups[intval($omg)]['g_access_cp']) {
                     $is_admin = 1;
                     break;
                 }
             }
         }
         if ($groups[intval($this->request['member_group_id'])]['g_access_cp']) {
             $is_admin = 1;
         }
         if ($is_admin) {
             //-------------------------------------------------
             // Copy restrictions if they do not have any yet...
             //-------------------------------------------------
             $check = $this->DB->buildAndFetch(array('select' => 'row_updated', 'from' => 'admin_permission_rows', 'where' => "row_id_type='member' AND row_id=" . $this->request['member_id']));
             if (!$check['row_updated']) {
                 $this->DB->replace('admin_permission_rows', array('row_id' => $this->request['member_id'], 'row_id_type' => 'member', 'row_perm_cache' => serialize($this->registry->getClass('class_permissions')->restrictions_row), 'row_updated' => time()), array('row_id', 'row_id_type'));
             }
         }
     }
     //-----------------------------------------
     // Moved from validating group?
     //-----------------------------------------
     if ($member['member_group_id'] == $this->settings['auth_group']) {
         if ($this->request['member_group_id'] != $this->settings['auth_group']) {
             //-----------------------------------------
             // Yes...
             //-----------------------------------------
             $this->DB->delete('validating', "member_id=" . $this->request['member_id']);
         }
     }
     //-----------------------------------------
     // Custom profile field stuff
     //-----------------------------------------
     require_once IPS_ROOT_PATH . 'sources/classes/customfields/profileFields.php';
     $fields = new customProfileFields();
     $fields->initData('edit');
     $fields->parseToSave($_POST);
     //-----------------------------------------
     // Custom profile field stuff
     //-----------------------------------------
     if (count($fields->out_fields)) {
         //-----------------------------------------
         // Do we already have an entry in
         // the content table?
         //-----------------------------------------
         $test = $this->DB->buildAndFetch(array('select' => 'member_id', 'from' => 'pfields_content', 'where' => 'member_id=' . $this->request['member_id']));
         if ($test['member_id']) {
             //-----------------------------------------
             // We have it, so simply update
             //-----------------------------------------
             $this->DB->force_data_type = array();
             foreach ($fields->out_fields as $_field => $_data) {
                 $this->DB->force_data_type[$_field] = 'string';
             }
             $this->DB->update('pfields_content', $fields->out_fields, 'member_id=' . $this->request['member_id']);
         } else {
             $this->DB->force_data_type = array();
             foreach ($fields->out_fields as $_field => $_data) {
                 $this->DB->force_data_type[$_field] = 'string';
             }
             $fields->out_fields['member_id'] = $this->request['member_id'];
             $this->DB->insert('pfields_content', $fields->out_fields);
         }
     }
     /* Update cache */
     IPSContentCache::update($this->request['member_id'], 'sig', $cacheSignature);
     //-----------------------------------------
     // Redirect
     //-----------------------------------------
     ipsRegistry::getClass('adminFunctions')->saveAdminLog(sprintf($this->lang->words['m_editedlog'], $member['members_display_name']));
     $this->registry->output->global_message = $this->lang->words['m_edited'];
     $newMember['member_id'] = $this->request['member_id'];
     $newMember['members_display_name'] = $member['members_display_name'];
     $triggerGroups = $member['mgroup_others'] ? implode(',', array_merge(is_array($member['mgroup_others']) ? $member['mgroup_others'] : array(), array($member['member_group_id']))) : $member['member_group_id'];
     //$this->_memberView();
     $this->registry->output->silentRedirectWithMessage($this->settings['base_url'] . $this->form_code . '&do=viewmember&trigger=' . $triggerGroups . '&member_id=' . $this->request['member_id']);
 }
Example #24
0
 /**
  * Feturn HTML block
  *
  * @param	array		Member information
  * @return	string		HTML block
  */
 public function return_html_block($member = array())
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $content = '';
     $last_x = 5;
     $forumIdsOk = array(0 => 0);
     $date_cut = '';
     //-----------------------------------------
     // Got a member?
     //-----------------------------------------
     if (!is_array($member) or !count($member)) {
         return $this->registry->getClass('output')->getTemplate('profile')->tabNoContent('err_no_posts_to_show');
     }
     //-----------------------------------------
     // Some words
     //-----------------------------------------
     $this->registry->class_localization->loadLanguageFile(array('public_topic'), 'forums');
     //-----------------------------------------
     // Can view other member's topics?
     //-----------------------------------------
     if (!$this->memberData['g_other_topics'] and $this->memberData['member_id'] != $member['member_id']) {
         return $this->registry->getClass('output')->getTemplate('profile')->tabNoContent('err_no_posts_to_show');
     }
     /* Get list of good forum IDs */
     $forumIdsOk = $this->registry->class_forums->fetchSearchableForumIds();
     //-----------------------------------------
     // Get last X posts
     //-----------------------------------------
     if (is_array($forumIdsOk) and count($forumIdsOk)) {
         /* Init vars */
         $pids = array();
         $parseAttachments = false;
         /* Set up joins */
         $_post_joins = array(array('select' => 't.*', 'from' => array('topics' => 't'), 'where' => 't.tid=p.topic_id', 'type' => 'left'), array('select' => 'm.member_group_id, m.mgroup_others', 'from' => array('members' => 'm'), 'where' => 'm.member_id=p.author_id', 'type' => 'left'));
         /* Cache? */
         if (IPSContentCache::isEnabled()) {
             if (IPSContentCache::fetchSettingValue('post')) {
                 $_post_joins[] = IPSContentCache::join('post', 'p.pid');
             }
         }
         if ($this->settings['search_ucontent_days']) {
             $_date_cut = ($member['last_post'] ? $member['last_post'] : time()) - 86400 * intval($this->settings['search_ucontent_days']);
             $date_cut = ' AND p.post_date > ' . $_date_cut;
         }
         $_queued = $this->registry->class_forums->fetchPostHiddenQuery(array('visible'), 'p.');
         $_approved = $this->registry->getClass('class_forums')->fetchTopicHiddenQuery(array('visible'), 't.');
         /* Let's just run this if the member has posted within the cutoff period */
         if ($member['last_post'] > $_date_cut) {
             $this->DB->build(array('select' => 'p.*', 'from' => array('posts' => 'p'), 'where' => $_queued . " AND " . $_approved . " AND p.author_id={$member['member_id']} AND p.new_topic=0 AND t.forum_id IN (" . implode(",", $forumIdsOk) . ") " . $date_cut, 'order' => 'p.pid DESC', 'limit' => array(0, $last_x), 'add_join' => $_post_joins));
             $o = $this->DB->execute();
             while ($row = $this->DB->fetch($o)) {
                 $pids[$row['pid']] = $row['pid'];
                 if ($row['topic_hasattach']) {
                     $parseAttachments = true;
                 }
                 if (!$row['cache_content']) {
                     IPSText::getTextClass('bbcode')->parse_smilies = $row['use_emo'];
                     IPSText::getTextClass('bbcode')->parse_html = ($row['use_html'] and $this->caches['group_cache'][$row['member_group_id']]['g_dohtml'] and $row['post_htmlstate']) ? 1 : 0;
                     IPSText::getTextClass('bbcode')->parse_nl2br = $row['post_htmlstate'] == 2 ? 1 : 0;
                     IPSText::getTextClass('bbcode')->parse_bbcode = 1;
                     IPSText::getTextClass('bbcode')->parsing_section = 'topics';
                     IPSText::getTextClass('bbcode')->parsing_mgroup = $row['member_group_id'];
                     IPSText::getTextClass('bbcode')->parsing_mgroup_others = $row['mgroup_others'];
                     $row['post'] = IPSText::getTextClass('bbcode')->preDisplayParse($row['post']);
                     IPSContentCache::update($row['pid'], 'post', $row['post']);
                 } else {
                     $row['post'] = $row['cache_content'];
                 }
                 $row['_post_date'] = ipsRegistry::getClass('class_localization')->getDate($row['post_date'], 'SHORT');
                 $row['_raw_date'] = $row['post_date'];
                 $row['_date_array'] = IPSTime::date_getgmdate($row['post_date'] + ipsRegistry::getClass('class_localization')->getTimeOffset());
                 $row['post'] .= "\n<!--IBF.ATTACHMENT_" . $row['pid'] . "-->";
                 $url = $this->registry->output->buildSEOUrl("showtopic={$row['topic_id']}&amp;view=findpost&amp;p={$row['pid']}", 'public', $row['title_seo'], 'showtopic');
                 $content .= $this->registry->getClass('output')->getTemplate('profile')->tabSingleColumn($row, $this->lang->words['profile_read_topic'], $url, $this->lang->words['profile_in_topic'] . $row['title']);
             }
             //-----------------------------------------
             // Attachments (but only if necessary)
             //-----------------------------------------
             if ($parseAttachments and !is_object($this->class_attach)) {
                 $classToLoad = IPSLib::loadLibrary(IPSLib::getAppDir('core') . '/sources/classes/attach/class_attach.php', 'class_attach');
                 $this->class_attach = new $classToLoad($this->registry);
                 $this->class_attach->type = 'post';
                 $this->class_attach->init();
                 if (IPSMember::checkPermissions('download') === false) {
                     $this->settings['show_img_upload'] = 0;
                 }
                 $content = $this->class_attach->renderAttachments($content, $pids);
                 $content = $content[0]['html'];
             }
             //-----------------------------------------
             // Macros...
             //-----------------------------------------
             $content = $this->registry->output->replaceMacros($content);
         }
     }
     //-----------------------------------------
     // Return content..
     //-----------------------------------------
     return $content ? $this->registry->getClass('output')->getTemplate('profile')->tabPosts($content) : $this->registry->getClass('output')->getTemplate('profile')->tabNoContent('err_no_posts_to_show');
 }
    /**
     * BBCode add/edit form
     *
     * @param	string		Type (add|edit)
     * @param	array 		BBcode info
     * @param	array 		Sections to edit in
     * @return	string		HTML
     */
    public function bbcodeForm($type, $bbcode, $sections)
    {
        //-----------------------------------------
        // Set some of the form variables
        //-----------------------------------------
        $form_code = $type == 'edit' ? 'bbcode_doedit' : 'bbcode_doadd';
        $button = $type == 'edit' ? $this->lang->words['edit_bbcode'] : $this->lang->words['addnew_bbcode'];
        $secure_key = ipsRegistry::getClass('adminFunctions')->getSecurityKey();
        $all_groups = array(0 => array('all', $this->lang->words['all_groups']));
        foreach ($this->cache->getCache('group_cache') as $group_data) {
            $all_groups[] = array($group_data['g_id'], $group_data['g_title']);
        }
        $ss_dropdown = array(0 => array('all', $this->lang->words['available_sections']));
        if (is_array($sections) and count($sections)) {
            foreach ($sections as $sect_key => $sect_value) {
                $ss_dropdown[] = array($sect_key, $sect_value);
            }
        }
        $form = array();
        $form['bbcode_title'] = $this->registry->output->formInput('bbcode_title', $this->request['bbcode_title'] ? $this->request['bbcode_title'] : $bbcode['bbcode_title']);
        $form['bbcode_desc'] = $this->registry->output->formTextarea('bbcode_desc', $this->request['bbcode_desc'] ? $this->request['bbcode_desc'] : $bbcode['bbcode_desc']);
        $form['bbcode_example'] = $this->registry->output->formTextarea('bbcode_example', $this->request['bbcode_example'] ? $this->request['bbcode_example'] : $bbcode['bbcode_example']);
        $form['bbcode_tag'] = '[ ' . $this->registry->output->formSimpleInput('bbcode_tag', $this->request['bbcode_tag'] ? $this->request['bbcode_tag'] : $bbcode['bbcode_tag'], 10) . ' ]';
        $form['bbcode_useoption'] = $this->registry->output->formYesNo('bbcode_useoption', $this->request['bbcode_useoption'] ? $this->request['bbcode_useoption'] : $bbcode['bbcode_useoption']);
        $form['bbcode_switch_option'] = $this->registry->output->formYesNo('bbcode_switch_option', $this->request['bbcode_switch_option'] ? $this->request['bbcode_switch_option'] : $bbcode['bbcode_switch_option']);
        $form['bbcode_replace'] = $this->registry->output->formTextarea('bbcode_replace', htmlspecialchars($_POST['bbcode_replace'] ? $_POST['bbcode_replace'] : $bbcode['bbcode_replace']));
        $form['bbcode_menu_option_text'] = $this->registry->output->formSimpleInput('bbcode_menu_option_text', $this->request['bbcode_menu_option_text'] ? $this->request['bbcode_menu_option_text'] : $bbcode['bbcode_menu_option_text'], 50);
        $form['bbcode_menu_content_text'] = $this->registry->output->formSimpleInput('bbcode_menu_content_text', $this->request['bbcode_menu_content_text'] ? $this->request['bbcode_menu_content_text'] : $bbcode['bbcode_menu_content_text'], 50);
        $form['bbcode_single_tag'] = $this->registry->output->formYesNo('bbcode_single_tag', $this->request['bbcode_single_tag'] ? $this->request['bbcode_single_tag'] : $bbcode['bbcode_single_tag']);
        $form['bbcode_groups'] = $this->registry->output->formMultiDropdown("bbcode_groups[]", $all_groups, $this->request['bbcode_groups'] ? $this->request['bbcode_groups'] : explode(",", $bbcode['bbcode_groups']));
        $form['bbcode_sections'] = $this->registry->output->formMultiDropdown("bbcode_sections[]", $ss_dropdown, $this->request['bbcode_sections'] ? $this->request['bbcode_sections'] : explode(",", $bbcode['bbcode_sections']));
        $form['bbcode_php_plugin'] = $this->registry->output->formInput('bbcode_php_plugin', $this->request['bbcode_php_plugin'] ? $this->request['bbcode_php_plugin'] : $bbcode['bbcode_php_plugin']);
        $form['bbcode_no_parsing'] = $this->registry->output->formYesNo('bbcode_no_parsing', $this->request['bbcode_no_parsing'] ? $this->request['bbcode_no_parsing'] : $bbcode['bbcode_no_parsing']);
        $form['bbcode_protected'] = $this->registry->output->formYesNo('bbcode_protected', $this->request['bbcode_protected'] ? $this->request['bbcode_protected'] : $bbcode['bbcode_protected']);
        $form['bbcode_custom_regex'] = $this->registry->output->formTextarea('bbcode_custom_regex', htmlspecialchars($_POST['bbcode_custom_regex'] ? $_POST['bbcode_custom_regex'] : $bbcode['bbcode_custom_regex']));
        $apps = array();
        /* Application drop down options */
        foreach (ipsRegistry::$applications as $app_dir => $app_data) {
            $apps[] = array($app_dir, $app_data['app_title']);
        }
        $form['bbcode_app'] = $this->registry->output->formDropdown('bbcode_app', $apps, $this->request['bbcode_app'] ? $this->request['bbcode_app'] : $bbcode['bbcode_app']);
        $form['bbcode_optional_option'] = $this->registry->output->formYesNo('bbcode_optional_option', $this->request['bbcode_optional_option'] ? $this->request['bbcode_optional_option'] : $bbcode['bbcode_optional_option']);
        $form['bbcode_aliases'] = $this->registry->output->formTextarea('bbcode_aliases', $this->request['bbcode_aliases'] ? $this->request['bbcode_aliases'] : $bbcode['bbcode_aliases']);
        $form['bbcode_image'] = $this->registry->output->formInput('bbcode_image', $this->request['bbcode_image'] ? $this->request['bbcode_image'] : $bbcode['bbcode_image']);
        /* Content cache is enabled? */
        if ($type == 'edit' and IPSContentCache::isEnabled()) {
            $_cacheCount = IPSContentCache::count();
            $form['drop_cache'] = $this->registry->output->formYesNo('drop_cache', $this->request['drop_cache']);
            $this->lang->words['bbcache_action'] = sprintf($this->lang->words['bbcache_action'], $_cacheCount);
        }
        $IPBHTML = "";
        //--starthtml--//
        $IPBHTML .= <<<EOF

<div class='section_title'>
\t<h2>{$this->lang->words['custom_bbcode_head']}</h2>
</div>

<form action='{$this->settings['base_url']}&amp;{$this->form_code}&amp;do={$form_code}&amp;secure_key={$secure_key}' method='post'>
<input type='hidden' name='id' value='{$bbcode['bbcode_id']}' />
EOF;
        if ($form['drop_cache']) {
            $IPBHTML .= <<<EOF

\t\t<div class='warning'>
\t\t <h4>{$this->lang->words['bbcache_title']}</h4>
\t\t {$this->lang->words['bbcache_desc']}
\t\t<p><strong>{$this->lang->words['bbcache_action']}</strong> {$form['drop_cache']}</p>
\t\t</div>
\t\t<br />
EOF;
        }
        $IPBHTML .= <<<EOF

<div class="acp-box">
\t<h3>{$button}</h3>
\t<table class='ipsTable double_pad'>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_title']}</span></td>
\t\t\t<td class='field_field'>{$form['bbcode_title']}</td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_description']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_desc']} <br /><span class='desctext'>{$this->lang->words['bbcode_usedinguide']}</span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_example']}</strong>
\t\t\t<td class='field_field'>{$form['bbcode_example']}<span class='desctext'>{$this->lang->words['bbcode_usedinguide']}<br />{$this->lang->words['bbcode_example_info']}</span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_tag']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_tag']} <br /><span class='desctext'>{$this->lang->words['bbcode_tag_info']}</span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_aliases']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_aliases']} <br /><span class='desctext'>{$this->lang->words['bbcode_aliases_info']}</span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_singletag']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_single_tag']} <br /><span class='desctext'>{$this->lang->words['bbcode_singletag_info']}</span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_useoption']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_useoption']} <br /><span class='desctext'>{$this->lang->words['bbcode_useoption_info']}</span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_customregex']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_custom_regex']} <br /><span class='desctext'>{$this->lang->words['bbcode_customregex_info']}</span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_optional']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_optional_option']} <br /><span class='desctext'>{$this->lang->words['bbcode_optional_info']}</span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_switch']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_switch_option']} <br /><span class='desctext'>{$this->lang->words['bbcode_switch_info']}</span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_noparse']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_no_parsing']} <br /><span class='desctext'>{$this->lang->words['bbcode_noparse_info']}</span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_replace']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_replace']} <br /><span class='desctext'>{$this->lang->words['bbcode_replace_info']}</span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_php']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_php_plugin']}<br /><span class='desctext'>{$this->lang->words['bbcode_php_info_loc']} <br />{$this->lang->words['bbcode_php_info']}</span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_groups']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_groups']} <br /><span class='desctext'>{$this->lang->words['bbcode_groups_info']}</span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_whereused']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_sections']} <br /><span class='desctext'>{$this->lang->words['bbcode_whereused_info']}</span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_assoc_app']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_app']}</td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_image']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_image']}<br /> <span class='desctext'>{$this->lang->words['bbcode_image_info_loc']} <br />{$this->lang->words['bbcode_image_info']}</span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_optdial']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_menu_option_text']} <br /><span class='desctext'>{$this->lang->words['bbcode_optdial_info']}</span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_contdial']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_menu_content_text']} <br /><span class='desctext'>{$this->lang->words['bbcode_contdial_info']}</span></td>
\t\t</tr>
EOF;
        if (IN_DEV) {
            $IPBHTML .= <<<EOF

\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_protected']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_protected']} <br /><span class='desctext'>{$this->lang->words['bbcode_protected_info']}</span></td>
\t\t</tr>
EOF;
        }
        $IPBHTML .= <<<EOF

\t</table>
\t<div class="acp-actionbar">
\t\t<input type='submit' value='{$button}' class="button primary" />
\t</div>
</div>\t
</form>
EOF;
        //--endhtml--//
        return $IPBHTML;
    }
 /**
  * Get Linear Topic Data
  *
  * @access	public
  * @return	array
  **/
 public function _getTopicDataLinear()
 {
     //-----------------------------------------
     // Grab the posts we'll need
     //-----------------------------------------
     $first = intval($this->request['st']) >= 0 ? intval($this->request['st']) : 0;
     $pc_join = array();
     if ($this->settings['post_order_column'] != 'post_date') {
         $this->settings['post_order_column'] = 'pid';
     }
     if ($this->settings['post_order_sort'] != 'desc') {
         $this->settings['post_order_sort'] = 'asc';
     }
     if ($this->settings['au_cutoff'] == "") {
         $this->settings['au_cutoff'] = 15;
     }
     //-----------------------------------------
     // Moderator?
     //-----------------------------------------
     $queued_query_bit = ' and queued=0';
     if ($this->registry->class_forums->canQueuePosts($this->topic['forum_id'])) {
         $queued_query_bit = '';
         if ($this->request['modfilter'] and $this->request['modfilter'] == 'invisible_posts') {
             $queued_query_bit = ' and queued=1';
         }
     }
     //-----------------------------------------
     // Using "new" mode?
     //-----------------------------------------
     if ($this->topic_view_mode == 'linearplus' and $this->topic['topic_firstpost']) {
         $this->topic['new_mode_start'] = $first + 1;
         if ($first) {
             $this->topic['new_mode_start']--;
         }
         if ($first + $this->settings['display_max_posts'] > $this->topic['posts'] + 1) {
             $this->topic['new_mode_end'] = $this->topic['posts'];
         } else {
             $this->topic['new_mode_end'] = $first + ($this->settings['display_max_posts'] - 1);
         }
         if ($first) {
             $this->pids = array(0 => $this->topic['topic_firstpost']);
         }
         //-----------------------------------------
         // Get PIDS of this page/topic
         //-----------------------------------------
         $this->DB->build(array('select' => 'pid,topic_id', 'from' => 'posts', 'where' => 'topic_id=' . $this->topic['tid'] . $queued_query_bit, 'order' => 'pid asc', 'limit' => array($first, $this->settings['display_max_posts'])));
         $this->DB->execute();
         while ($p = $this->DB->fetch()) {
             $this->pids[$p['pid']] = $p['pid'];
         }
     } else {
         //-----------------------------------------
         // Run query
         //-----------------------------------------
         $this->topic_view_mode = 'linear';
         # We don't need * but if we don't use it, it won't use the correct index
         $this->DB->build(array('select' => 'pid', 'from' => 'posts', 'where' => 'topic_id=' . $this->topic['tid'] . $queued_query_bit, 'order' => $this->settings['post_order_column'] . ' ' . $this->settings['post_order_sort'], 'limit' => array($first, $this->settings['display_max_posts'])));
         $this->DB->execute();
         while ($p = $this->DB->fetch()) {
             $this->pids[$p['pid']] = $p['pid'];
         }
     }
     //-----------------------------------------
     // Do we have any PIDS?
     //-----------------------------------------
     if (!count($this->pids)) {
         if ($first) {
             //-----------------------------------------
             // Add dummy PID, AUTO FIX
             // will catch this below...
             //-----------------------------------------
             $this->pids[] = 0;
         }
         if ($this->request['modfilter'] == 'invisible_posts') {
             $this->pids[] = 0;
         }
     }
     //-----------------------------------------
     // Attachment PIDS
     //-----------------------------------------
     $this->attach_pids = $this->pids;
     //-----------------------------------------
     // Fail safe
     //-----------------------------------------
     if (!is_array($this->pids) or !count($this->pids)) {
         $this->pids = array(0 => 0);
     }
     //-----------------------------------------
     // Joins
     //-----------------------------------------
     $_post_joins = array(array('select' => 'm.member_id as mid,m.name,m.member_group_id,m.email,m.joined,m.posts, m.last_visit, m.last_activity,m.login_anonymous,m.title,m.hide_email, m.warn_level, m.warn_lastwarn, m.members_display_name, m.members_seo_name, m.has_gallery, m.has_blog, m.members_bitoptions', 'from' => array('members' => 'm'), 'where' => 'm.member_id=p.author_id', 'type' => 'left'), array('select' => 'pp.*', 'from' => array('profile_portal' => 'pp'), 'where' => 'm.member_id=pp.pp_member_id', 'type' => 'left'), array('select' => 'g.g_access_cp', 'from' => array('groups' => 'g'), 'where' => 'g.g_id=m.member_group_id', 'type' => 'left'));
     /* Add custom fields join? */
     if ($this->settings['custom_profile_topic'] == 1) {
         $_post_joins[] = array('select' => 'pc.*', 'from' => array('pfields_content' => 'pc'), 'where' => 'pc.member_id=p.author_id', 'type' => 'left');
     }
     /* Reputation system enabled? */
     if ($this->settings['reputation_enabled']) {
         /* Add the join to figure out if the user has already rated the post */
         $_post_joins[] = $this->registry->repCache->getUserHasRatedJoin('pid', 'p.pid', 'forums');
         /* Add the join to figure out the total ratings for each post */
         if ($this->settings['reputation_show_content']) {
             $_post_joins[] = $this->registry->repCache->getTotalRatingJoin('pid', 'p.pid', 'forums');
         }
     }
     /* Cache? */
     if (IPSContentCache::isEnabled()) {
         if (IPSContentCache::fetchSettingValue('post')) {
             $_post_joins[] = IPSContentCache::join('post', 'p.pid');
         }
         if (IPSContentCache::fetchSettingValue('sig')) {
             $_post_joins[] = IPSContentCache::join('sig', 'm.member_id', 'ccb', 'left', 'ccb.cache_content as cache_content_sig, ccb.cache_updated as cache_updated_sig');
         }
     }
     /* Ignored Users */
     $ignored_users = array();
     foreach ($this->member->ignored_users as $_i) {
         if ($_i['ignore_topics']) {
             $ignored_users[] = $_i['ignore_ignore_id'];
         }
     }
     //-----------------------------------------
     // Get posts
     //-----------------------------------------
     $this->DB->build(array('select' => 'p.*', 'from' => array('posts' => 'p'), 'where' => "p.pid IN(" . implode(',', $this->pids) . ")", 'order' => $this->settings['post_order_column'] . ' ' . $this->settings['post_order_sort'], 'add_join' => $_post_joins));
     $oq = $this->DB->execute();
     if (!$this->DB->getTotalRows()) {
         if ($first >= $this->settings['display_max_posts']) {
             //-----------------------------------------
             // AUTO FIX: Get the correct number of replies...
             //-----------------------------------------
             $this->DB->build(array('select' => 'COUNT(*) as pcount', 'from' => 'posts', 'where' => "topic_id=" . $this->topic['tid'] . " and queued !=1"));
             $newq = $this->DB->execute();
             $pcount = $this->DB->fetch($newq);
             $pcount['pcount'] = $pcount['pcount'] > 0 ? $pcount['pcount'] - 1 : 0;
             //-----------------------------------------
             // Update the post table...
             //-----------------------------------------
             if ($pcount['pcount'] > 1) {
                 $this->DB->update('topics', array('posts' => $pcount['pcount']), "tid=" . $this->topic['tid']);
             }
             $this->registry->output->silentRedirect($this->settings['base_url'] . "showtopic={$this->topic['tid']}&view=getlastpost");
         }
     }
     //-----------------------------------------
     // Render the page top
     //-----------------------------------------
     $this->topic['go_new'] = isset($this->topic['go_new']) ? $this->topic['go_new'] : '';
     //-----------------------------------------
     // Format and print out the topic list
     //-----------------------------------------
     $post_data = array();
     while ($row = $this->DB->fetch($oq)) {
         $row['member_id'] = $row['mid'];
         $return = $this->parsePostRow($row);
         $poster = $return['poster'];
         $row = $return['row'];
         $poster['member_id'] = $poster['mid'];
         /* Reputation */
         if ($this->settings['reputation_enabled']) {
             $row['pp_reputation_points'] = $row['pp_reputation_points'] ? $row['pp_reputation_points'] : 0;
             $row['has_given_rep'] = $row['has_given_rep'] ? $row['has_given_rep'] : 0;
             $row['rep_points'] = $row['rep_points'] ? $row['rep_points'] : 0;
         }
         $post_data[$row['pid']] = array('post' => $row, 'author' => $poster);
         //-----------------------------------------
         // Are we giving this bloke a good ignoring?
         //-----------------------------------------
         if (isset($ignored_users) && is_array($ignored_users) && count($ignored_users)) {
             if (in_array($poster['member_id'], $ignored_users)) {
                 if (!strstr($this->settings['cannot_ignore_groups'], ',' . $poster['member_group_id'] . ',')) {
                     $post_data[$row['pid']]['post']['_ignored'] = 1;
                     continue;
                 }
             }
         }
         //-----------------------------------------
         // What about rep, are we ignoring?
         //-----------------------------------------
         $this->memberData['_members_cache']['rep_filter'] = isset($this->memberData['_members_cache']['rep_filter']) ? $this->memberData['_members_cache']['rep_filter'] : false;
         if ($this->settings['reputation_enabled']) {
             if (!($this->settings['reputation_protected_groups'] && in_array($this->memberData['member_group_id'], explode(',', $this->settings['reputation_protected_groups']))) && $this->memberData['_members_cache']['rep_filter'] != '*') {
                 if ($this->settings['reputation_show_content'] && $post_data[$row['pid']]['post']['rep_points'] < $this->memberData['_members_cache']['rep_filter']) {
                     $post_data[$row['pid']]['post']['_repignored'] = 1;
                 }
             }
         }
         //-----------------------------------------
         // Show end first post
         //-----------------------------------------
         if ($this->topic_view_mode == 'linearplus' and $this->first_printed == 0 and $row['pid'] == $this->topic['topic_firstpost'] and $this->topic['posts'] > 0) {
             $post_data[$row['pid']]['post']['_end_first_post'] = 1;
         }
         $post_data[$row['pid']]['post']['rep_points'] = $post_data[$row['pid']]['post']['rep_points'] ? $post_data[$row['pid']]['post']['rep_points'] : 0;
     }
     //-----------------------------------------
     // Print the footer
     //-----------------------------------------
     return $post_data;
 }
Example #27
0
 /**
  * Save a bbcode [add|edit]
  *
  * @param	string		[add|edit]
  * @return	@e void		[Outputs to screen]
  */
 protected function _bbcodeSave($type = 'add')
 {
     if ($type == 'edit') {
         if (!$this->request['id']) {
             $this->registry->output->global_message = $this->lang->words['no_bbcode_found_edit'];
             $this->_bbcodeForm($type);
             return;
         }
         $bbcode = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'custom_bbcode', 'where' => 'bbcode_id=' . intval($this->request['id'])));
         if (!$bbcode['bbcode_id']) {
             $this->registry->output->showError($this->lang->words['no_bbcode_found_edit'], 111162);
         }
         if ($this->request['bbcode_tag']) {
             $duplicate = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'custom_bbcode', 'where' => "bbcode_tag='{$this->request['bbcode_tag']}'"));
             if ($duplicate['bbcode_id'] && $duplicate['bbcode_id'] != $this->request['id']) {
                 $this->registry->output->global_message = $this->lang->words['tag_already'];
                 $this->_bbcodeForm($type);
                 return;
             }
             /* Check aliases */
             $this->DB->build(array('select' => '*', 'from' => 'custom_bbcode', 'where' => 'bbcode_aliases LIKE \'%' . $this->DB->addSlashes($this->request['bbcode_tag']) . '%\''));
             $this->DB->execute();
             while ($row = $this->DB->fetch()) {
                 if ($row['bbcode_id'] == $this->request['id']) {
                     continue;
                 }
                 foreach (explode(',', $row['bbcode_aliases']) as $alias) {
                     if (strtolower($alias) == strtolower($this->request['bbcode_tag'])) {
                         $this->registry->output->global_message = sprintf($this->lang->words['tag_already_alias'], $this->request['bbcode_tag'], $row['bbcode_tag']);
                         $this->_bbcodeForm($type);
                         return;
                     }
                 }
             }
         }
     } else {
         $bbcode = array();
         if ($this->request['bbcode_tag']) {
             $duplicate = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'custom_bbcode', 'where' => "bbcode_tag='{$this->request['bbcode_tag']}'"));
             if ($duplicate['bbcode_id']) {
                 $this->registry->output->global_message = $this->lang->words['tag_already'];
                 $this->_bbcodeForm($type);
                 return;
             }
             /* Check aliases */
             $this->DB->build(array('select' => '*', 'from' => 'custom_bbcode', 'where' => 'bbcode_aliases LIKE \'%' . $this->DB->addSlashes($this->request['bbcode_tag']) . '%\''));
             $this->DB->execute();
             while ($row = $this->DB->fetch()) {
                 foreach (explode(',', $row['bbcode_aliases']) as $alias) {
                     if (strtolower($alias) == strtolower($this->request['bbcode_tag'])) {
                         $this->registry->output->global_message = sprintf($this->lang->words['tag_already_alias'], $this->request['bbcode_tag'], $row['bbcode_tag']);
                         $this->_bbcodeForm($type);
                         return;
                     }
                 }
             }
         }
     }
     //-----------------------------------------
     // Fix BR tags
     //-----------------------------------------
     $this->request['bbcode_aliases'] = str_replace(array(' ', "\n"), '', IPSText::br2nl($this->request['bbcode_aliases']));
     //-----------------------------------------
     // check...
     //-----------------------------------------
     if (!$this->request['bbcode_title'] or !$this->request['bbcode_tag'] or !$this->request['bbcode_replace'] and !$this->request['bbcode_php_plugin']) {
         $this->registry->output->global_message = $this->lang->words['complete_form'];
         $this->_bbcodeForm($type);
         return;
     }
     if (!$this->request['bbcode_single_tag'] and !strstr($this->request['bbcode_replace'], '{content}') and !$this->request['bbcode_php_plugin']) {
         $this->registry->output->global_message = $this->lang->words['must_use_content'];
         $this->_bbcodeForm($type);
         return;
     }
     if (!strstr($this->request['bbcode_replace'], '{option}') and $this->request['bbcode_useoption'] and !$this->request['bbcode_php_plugin']) {
         $this->registry->output->global_message = $this->lang->words['must_use_option'];
         $this->_bbcodeForm($type);
         return;
     }
     if (preg_match("/[^a-zA-Z0-9_]/", $this->request['bbcode_tag'])) {
         $this->registry->output->global_message = $this->lang->words['bbcode_alpha_num'];
         $this->_bbcodeForm($type);
         return;
     }
     $_aliases = explode(",", $this->request['bbcode_aliases']);
     foreach ($_aliases as $_alias) {
         if (preg_match("/[^a-zA-Z0-9_]/", $_alias)) {
             $this->registry->output->global_message = $this->lang->words['bbcode_alpha_num'];
             $this->_bbcodeForm($type);
             return;
         }
     }
     $array = array('bbcode_title' => $this->request['bbcode_title'], 'bbcode_desc' => IPSText::safeslashes($_POST['bbcode_desc']), 'bbcode_tag' => preg_replace("/[^a-zA-Z0-9_]/", "", $this->request['bbcode_tag']), 'bbcode_replace' => IPSText::safeslashes($_POST['bbcode_replace']), 'bbcode_example' => IPSText::safeslashes($_POST['bbcode_example']), 'bbcode_useoption' => $this->request['bbcode_useoption'], 'bbcode_switch_option' => intval($this->request['bbcode_switch_option']), 'bbcode_menu_option_text' => trim($this->request['bbcode_menu_option_text']), 'bbcode_menu_content_text' => trim($this->request['bbcode_menu_content_text']), 'bbcode_single_tag' => intval($this->request['bbcode_single_tag']), 'bbcode_groups' => is_array($this->request['bbcode_groups']) ? implode(',', $this->request['bbcode_groups']) : '', 'bbcode_sections' => is_array($this->request['bbcode_sections']) ? implode(',', $this->request['bbcode_sections']) : '', 'bbcode_php_plugin' => trim($this->request['bbcode_php_plugin']), 'bbcode_no_parsing' => intval($this->request['bbcode_no_parsing']), 'bbcode_optional_option' => intval($this->request['bbcode_optional_option']), 'bbcode_aliases' => $this->request['bbcode_aliases'], 'bbcode_image' => $this->request['bbcode_image'], 'bbcode_app' => $this->request['bbcode_app'], 'bbcode_protected' => intval($this->request['bbcode_protected']), 'bbcode_custom_regex' => str_replace("&#092;", '\\', IPSText::stripslashes($_POST['bbcode_custom_regex'])));
     if ($type == 'add') {
         $check = $this->DB->buildAndFetch(array('select' => 'bbcode_tag', 'from' => 'custom_bbcode', 'where' => "bbcode_tag='{$array['bbcode_tag']}'"));
         if ($check['bbcode_tag']) {
             $this->registry->output->global_message = $this->lang->words['must_use_unique_btag'];
             $this->_bbcodeForm($type);
             return;
         }
         $this->DB->insert('custom_bbcode', $array);
         $this->registry->output->global_message = $this->lang->words['new_bbcode'];
     } else {
         $check = $this->DB->buildAndFetch(array('select' => 'bbcode_tag', 'from' => 'custom_bbcode', 'where' => "bbcode_tag='{$array['bbcode_tag']}' AND bbcode_id<>" . intval($this->request['id'])));
         if ($check['bbcode_tag']) {
             $this->registry->output->global_message = $this->lang->words['must_use_unique_btag'];
             $this->_bbcodeForm($type);
             return;
         }
         if ($this->request['drop_cache']) {
             IPSContentCache::truncate();
         }
         $this->DB->update('custom_bbcode', $array, 'bbcode_id=' . intval($this->request['id']));
         $this->registry->output->global_message = $this->lang->words['edited_bbcode'];
     }
     $this->bbcodeRebuildCache();
     $this->_bbcodeStart();
 }
 /**
  * Post multi-mod: Merge posts
  *
  * @access	private
  * @return	void		[Outputs to screen]
  */
 private function _multiMergePost()
 {
     $this->_resetModerator($this->topic['forum_id']);
     $this->_genericPermissionCheck('delete_post');
     if (count($this->pids) < 2) {
         $this->_showError('mod_only_one_pid', 10383);
     }
     //-----------------------------------------
     // Form or print?
     //-----------------------------------------
     if (!$this->request['checked']) {
         //-----------------------------------------
         // Get post data
         //-----------------------------------------
         $master_post = "";
         $dropdown = array();
         $authors = array();
         $seen_author = array();
         $upload_html = "";
         $seoTitle = '';
         //-----------------------------------------
         // Grab teh posts
         //-----------------------------------------
         $this->DB->build(array('select' => 'p.*', 'from' => array('posts' => 'p'), 'where' => "p.pid IN (" . implode(",", $this->pids) . ")", 'add_join' => array(array('select' => 't.forum_id, t.title_seo', 'from' => array('topics' => 't'), 'where' => 't.tid=p.topic_id', 'type' => 'left'))));
         $outer = $this->DB->execute();
         while ($p = $this->DB->fetch($outer)) {
             if (IPSMember::checkPermissions('read', $p['forum_id']) == TRUE) {
                 $master_post .= "<br /><br />" . $p['post'];
                 $dropdown[] = array($p['pid'], ipsRegistry::getClass('class_localization')->getDate($p['post_date'], 'LONG') . " (#{$p['pid']})");
                 if (!in_array($p['author_id'], $seen_author)) {
                     $authors[] = array($p['author_id'], "{$p['author_name']} (#{$p['pid']})");
                     $seen_author[] = $p['author_id'];
                 }
                 $seoTitle = $p['title_seo'];
             }
         }
         //-----------------------------------------
         // Get Attachment Data
         //-----------------------------------------
         $this->DB->build(array('select' => '*', 'from' => 'attachments', 'where' => "attach_rel_module='post' AND attach_rel_id IN (" . implode(",", $this->pids) . ")"));
         $this->DB->execute();
         while ($row = $this->DB->fetch()) {
             $row['image'] = $this->caches['attachtypes'][$row['attach_ext']]['atype_img'];
             $row['size'] = IPSLib::sizeFormat($row['attach_filesize']);
             $row['attach_file'] = IPSText::truncate($row['attach_file'], 50);
             $attachments[] = $row;
         }
         //-----------------------------------------
         // Print form
         //-----------------------------------------
         if (IPSText::getTextClass('editor')->method == 'rte') {
             IPSText::getTextClass('bbcode')->parse_wordwrap = 0;
             IPSText::getTextClass('bbcode')->parse_html = 0;
             $master_post = IPSText::getTextClass('bbcode')->convertForRTE(trim($master_post));
         } else {
             IPSText::getTextClass('bbcode')->parse_html = 0;
             IPSText::getTextClass('bbcode')->parse_nl2br = 0;
             IPSText::getTextClass('bbcode')->parse_smilies = 1;
             IPSText::getTextClass('bbcode')->parse_bbcode = 1;
             IPSText::getTextClass('bbcode')->parsing_section = 'topics';
             if (IPSText::getTextClass('bbcode')->parse_html) {
                 if (!IPSText::getTextClass('bbcode')->parse_nl2br) {
                     $master_post = str_replace(array('<br />', '<br>'), "", trim($master_post));
                 }
             }
             $master_post = IPSText::getTextClass('bbcode')->preEditParse($master_post);
         }
         $editor = IPSText::getTextClass('editor')->showEditor($master_post, 'Post');
         $this->output .= $this->registry->getClass('output')->getTemplate('mod')->mergePostForm($editor, $dropdown, $authors, $attachments, $seoTitle);
         if ($this->topic['tid']) {
             $this->registry->getClass('output')->addNavigation($this->topic['title'], "{$this->settings['_base_url']}showtopic={$this->topic['tid']}");
         }
         $this->registry->getClass('output')->addNavigation($this->lang->words['cm_title'], '');
         $this->registry->getClass('output')->setTitle($this->lang->words['cm_title']);
         $this->registry->output->addContent($this->output);
         $this->registry->getClass('output')->sendOutput();
     } else {
         //-----------------------------------------
         // DO THE THING, WITH THE THING!!
         //-----------------------------------------
         $this->request['postdate'] = intval($this->request['postdate']);
         if (!$this->request['selectedpids'] or !$this->request['postdate'] or !$this->request['postauthor'] or !$this->request['Post']) {
             $this->_showError('mod_merge_posts', 10384);
         }
         IPSText::getTextClass('bbcode')->parse_smilies = 1;
         IPSText::getTextClass('bbcode')->parse_html = 0;
         IPSText::getTextClass('bbcode')->parse_bbcode = 1;
         IPSText::getTextClass('bbcode')->parsing_section = 'topics';
         $post = IPSText::getTextClass('editor')->processRawPost('Post');
         $post = IPSText::getTextClass('bbcode')->preDbParse($post);
         //-----------------------------------------
         // Post to keep...
         //-----------------------------------------
         $posts = array();
         $author = array();
         $post_to_delete = array();
         $new_post_key = md5(time());
         $topics = array();
         $forums = array();
         $append_edit = 0;
         //-----------------------------------------
         // Grab teh posts
         //-----------------------------------------
         $this->DB->build(array('select' => 'p.*', 'from' => array('posts' => 'p'), 'where' => "p.pid IN (" . implode(",", $this->pids) . ")", 'add_join' => array(array('select' => 't.forum_id', 'from' => array('topics' => 't'), 'where' => 't.tid=p.topic_id', 'type' => 'left'))));
         $outer = $this->DB->execute();
         while ($p = $this->DB->fetch($outer)) {
             $posts[$p['pid']] = $p;
             $topics[$p['topic_id']] = $p['topic_id'];
             $forums[$p['forum_id']] = $p['forum_id'];
             if ($p['author_id'] == $this->request['postauthor']) {
                 $author = array('id' => $p['author_id'], 'name' => $p['author_name']);
             }
             if ($p['pid'] != $this->request['postdate']) {
                 $post_to_delete[] = $p['pid'];
             }
             if ($p['append_edit']) {
                 $append_edit = 1;
             }
         }
         //-----------------------------------------
         // Update main post...
         //-----------------------------------------
         $this->DB->update('posts', array('author_id' => $author['id'], 'author_name' => $author['name'], 'post' => $post, 'post_key' => $new_post_key, 'post_parent' => 0, 'edit_time' => time(), 'edit_name' => $this->memberData['members_display_name'], 'append_edit' => ($append_edit or !$this->memberData['g_append_edit']) ? 1 : 0), 'pid=' . $this->request['postdate']);
         //-----------------------------------------
         // Fix attachments
         //-----------------------------------------
         $attach_keep = array();
         $attach_kill = array();
         foreach ($_POST as $key => $value) {
             if (preg_match("/^attach_(\\d+)\$/", $key, $match)) {
                 if ($this->request[$match[0]] == 'keep') {
                     $attach_keep[] = $match[1];
                 } else {
                     $attach_kill[] = $match[1];
                 }
             }
         }
         $attach_keep = IPSLib::cleanIntArray($attach_keep);
         $attach_kill = IPSLib::cleanIntArray($attach_kill);
         //-----------------------------------------
         // Keep
         //-----------------------------------------
         if (count($attach_keep)) {
             $this->DB->update('attachments', array('attach_rel_id' => $this->request['postdate'], 'attach_post_key' => $new_post_key, 'attach_member_id' => $author['id']), 'attach_id IN(' . implode(",", $attach_keep) . ')');
         }
         //-----------------------------------------
         // Kill Attachments
         //-----------------------------------------
         if (count($attach_kill)) {
             require_once IPSLib::getAppDir('core') . '/sources/classes/attach/class_attach.php';
             $class_attach = new class_attach($this->registry);
             $class_attach->type = $rel_module;
             $class_attach->attach_post_key = $post_key;
             $class_attach->attach_rel_id = $rel_id;
             $class_attach->init();
             $class_attach->bulkRemoveAttachment($attach_kill, 'attach_id');
         }
         //-----------------------------------------
         // Kill old posts
         //-----------------------------------------
         if (count($post_to_delete)) {
             $this->DB->delete('posts', 'pid IN(' . implode(",", $post_to_delete) . ')');
         }
         foreach ($topics as $t) {
             $this->modLibrary->rebuildTopic($t, 0);
         }
         foreach ($forums as $f) {
             $this->modLibrary->forumRecount($f);
         }
         $this->modLibrary->statsRecount();
         /* Clear the content cache */
         IPSContentCache::drop('post', $this->pids);
         $this->_addModeratorLog(sprintf($this->lang->words['acp_merged_posts'], implode(", ", $this->pids)));
     }
 }