text:
package com.samstarling.prometheusfinagle.metrics

import com.samstarling.prometheusfinagle.UnitTest
import com.samstarling.prometheusfinagle.helper.CollectorHelper
import io.prometheus.client.CollectorRegistry
import org.specs2.specification.Scope

import scala.collection.JavaConverters._
import scala.collection.mutable

class TelemetrySpec extends UnitTest {

  trait Context extends Scope {
    val registry = new CollectorRegistry(true)
    val telemetry = new Telemetry(registry, "test")
  }

  /**
    * It's not possible to fetch the name, help or labels from Counter/Histogram/Gauge objects themselves, so we
    * have to perform an action against them (such as incrementing a counter) and inspect the resulting metrics
    * and/or samples to ensure that everything is as we expect it.
    */
  "#counter" >> {

    trait CounterContext extends Context {
      val name = "widgets_total"
      val help = "Number of widgets"
      val labelNames = Seq("type", "colour")
      val counter = telemetry.counter(name, help, labelNames)
      counter.labels("sprocket", "red").inc(1)
    }

    "does not try to register duplicates" in new CounterContext {
      // The CollectorRegistry will not allow duplicates to be registered.
      val secondCounter = telemetry.counter(name, help, labelNames)
    }

    "returns a counter with" >> {
      "the correct name" in new CounterContext {
        CollectorHelper.firstMetricFor(counter).map { metric =>
          metric.name ==== "test_widgets_total"
        }
      }

      "the correct help label" in new CounterContext {
        CollectorHelper.firstMetricFor(counter).map { metric =>
          metric.help ==== "Number of widgets"
        }
      }

      "the correct label names" in new CounterContext {
        CollectorHelper.firstSampleFor(counter).map { sample =>
          sample.labelNames.asScala ==== mutable.Buffer("type", "colour")
        }
      }

      "the correct label values" in new CounterContext {
        CollectorHelper.firstSampleFor(counter).map { sample =>
          sample.labelValues.asScala ==== mutable.Buffer("sprocket", "red")
        }
      }
    }
  }

  "#gauge" >> {

    trait GaugeContext extends Context {
      val name = "current_population"
      val help = "Current population of a country"
      val labelNames = Seq("country", "continent")
      val gauge = telemetry.gauge(name, help, labelNames)
      gauge.labels("Germany", "Europe").inc(1)
    }

    "does not try to register duplicates" in new GaugeContext {
      // The CollectorRegistry will not allow duplicates to be registered.
      val secondCounter = telemetry.gauge(name, help, labelNames)
    }

    "returns a gauge with" >> {
      "the correct name" in new GaugeContext {
        CollectorHelper.firstMetricFor(gauge).map { metric =>
          metric.name ==== "test_current_population"
        }
      }

      "the correct help label" in new GaugeContext {
        CollectorHelper.firstMetricFor(gauge).map { metric =>
          metric.help ==== "Current population of a country"
        }
      }

      "the correct label names" in new GaugeContext {
        CollectorHelper.firstSampleFor(gauge).map { sample =>
          sample.labelNames.asScala ==== mutable.Buffer("country", "continent")
        }
      }

      "the correct label values" in new GaugeContext {
        CollectorHelper.firstSampleFor(gauge).map { sample =>
          sample.labelValues.asScala ==== mutable.Buffer("Germany", "Europe")
        }
      }
    }
  }

  "#histogram" >> {

    trait HistogramContext extends Context {
      val name = "request_latency"
      val help = "The latency of a request made"
      val labelNames = Seq("path")
      val gauge = telemetry.histogram(name, help, labelNames)
      gauge.labels("/foo/bar").observe(0.5)
    }

    "does not try to register duplicates" in new HistogramContext {
      // The CollectorRegistry will not allow duplicates to be registered.
      val secondCounter = telemetry.histogram(name, help, labelNames)
    }
  }
}


text:
module BlobViewer
  class Download < Base
    include Simple
    include Static

    self.partial_name = 'download'
    self.binary = true
  end
end

redpajama_set_name: RedPajamaGithub


text:
<?php

if ( ! defined( 'IN_IPB' ) )
{
	print "
Incorrect access
You cannot access this file directly. If you have recently upgraded, make sure you upgraded all the relevant files.";
	exit();
}

class public_forums_forums_topics extends ipsCommand
{
	/**
	 * First post content
	 *
	 * @var		string
	 */
	protected $_firstPostContent = '';

	/**
	 * Number of posts so far (offset)
	 *
	 * @var		integer
	 */
	public $post_count	 = 0;

	/**
	 * First post id
	 *
	 * @var		integer
	 */
	public $first		= 0;

	/**
	 * Quoted post ids
	 *
	 * @var		string
	 */
	public $qpids		= "";

	/**
	 * Can rate a topic permission
	 *
	 * @var		boolean
	 */
	public $can_rate	= false;

	/**
	 * Is this a poll only (disallow replies)?
	 *
	 * @var		boolean
	 */
	public $poll_only	= false;

	/**
	 * Can we edit at least one post?
	 *
	 * @var		boolean
	 */
 	protected $_canEditAPost	= false;

	/**
	 * Attachments library
	 *
	 * @var		object
	 */
	public $class_attach;

	/**
	 * Soft deleted PIDS
	 */
	protected $_sdPids = array();

	/**
	 * Permissions array
	 *
	 */
	protected $permissions = array();

	/**
	 * Max post date for this page
	 *
	 */
	protected $_maxPostDate = 0;

	/**
	 * Parser object
	 *
	 */
	protected $_textParser = '';

	/**
	 * Mod actions
	 *
	 * @var		array
	 */
	protected $mod_action = array(	'CLOSE_TOPIC'   => '00',
									'OPEN_TOPIC'	=> '01',
									'MOVE_TOPIC'	=> '02',
									'HIDE_TOPIC'	=> '03',
									'UNHIDE_TOPIC'	=> 'sundelete',
									'DELETE_TOPIC'  => '08',
									'EDIT_TOPIC'	=> '05',
									'PIN_TOPIC'	    => '15',
									'UNPIN_TOPIC'   => '16',
									'UNSUBBIT'	    => '30',
									'MERGE_TOPIC'   => '60',
									'TOPIC_HISTORY' => '90',
								);

	/**
	 * Main Execution Function
	 *
	 * @param	object		Registry reference
	 * @return	@e void		[Outputs to screen/redirects]
	 */
	public function doExecute( ipsRegistry $registry )
	{
		//-----------------------------------------
		// INIT
		//-----------------------------------------

		$post_data = array();
		$poll_data = '';
		$function  = '';

		/* Print CSS */
		$this->registry->output->addToDocumentHead( 'raw', "<link rel='stylesheet' type='text/css' title='Main' media='print' href='{$this->settings['css_base_url']}style_css/{$this->registry->output->skin['_csscacheid']}/ipb_print.css' />" );

		/* Followed stuffs */
		require_once( IPS_ROOT_PATH . 'sources/classes/like/composite.php' );/*noLibHook*/
		$this->_like = classes_like::bootstrap( 'forums', 'topics' );

		/* Init */
		if ( ! $this->registry->isClassLoaded('topics') )
		{
			$classToLoad = IPSLib::loadLibrary( IPSLib::getAppDir( 'forums' ) . "/sources/classes/topics.php", 'app_forums_classes_topics', 'forums' );
			$this->registry->setClass( 'topics', new $classToLoad( $this->registry ) );
		}

		try
		{
			/* Load up the data dudes */
			$this->registry->getClass('topics')->autoPopulate( null, false );
		}
		catch( Exception $crowdCheers )
		{
			$msg = str_replace( 'EX_', '', $crowdCheers->getMessage() );

			$this->registry->output->showError( $msg, 10340, null, null, 404 );
		}

		/* Shortcut */
		$this->forumClass = $this->registry->getClass('class_forums');

		/* Setup basics for this method */
		$topicData      = $this->registry->getClass('topics')->getTopicData();

		$forumData      = $this->forumClass->getForumById( $topicData['forum_id'] );

		/* VigLink */
		if ( !$forumData['viglink'] )
		{
			$this->settings['viglink_enabled'] = FALSE;
		}

		/* Rating */
		$this->can_rate = $this->memberData['member_id'] ? intval( $this->memberData['g_topic_rate_setting'] ) : 0;

		/* Set up topic */
		$topicData = $this->topicSetUp( $topicData );

		/* Get Posts */
		$_NOW = IPSDebug::getMemoryDebugFlag();

		if ( $this->registry->getClass('topics')->isArchived( $topicData ) && $this->registry->class_forums->fetchArchiveTopicType( $topicData ) != 'working' )
		{
			/* Load up archive class */
			$classToLoad = IPSLib::loadLibrary( IPS_ROOT_PATH . 'sources/classes/archive/reader.php', 'classes_archive_reader' );
			$this->archiveReader = new $classToLoad();

			$this->archiveReader->setApp('forums');

			$postData = $this->archiveReader->get( array( 'parentData'  => $topicData,
														  'goNative'    => true,
														  'offset'      => intval( $this->registry->getClass('topics')->pageToSt( $this->request['page'] ) ),
														  'limit'       => intval( $this->settings['display_max_posts'] ),
														  'sortKey'     => $this->settings['post_order_column'],
														  'sortOrder'   => $this->settings['post_order_sort'] ) );
		}
		else
		{
			$postData = $this->_getPosts();
		}

		/* Finish off post Data */
		if ( count( $postData ) )
		{
			foreach( $postData as $pid => $data )
			{
				$postData[ $pid ] = $this->parsePostRow( $data );
			}
		}

		/* Do we have a P parameter, and if so, is it actually in this set of results? */
		if ( ! $this->request['view'] && ( $this->request['p'] && ! in_array( $this->request['p'], array_keys( $postData ) ) ) )
		{
				/* Go find it */
				$this->request['view'] = 'findpost';
				/* Do view check is called next */
		}

		/* Specific view? */
		$this->_doViewCheck();

		unset( $this->cached_members );

		/* Status? */
		if ( $topicData['_ppd_ok'] === TRUE )
		{
			/* status from PPD */
			if ( $this->forumClass->ppdStatusMessage )
			{
				$topicData['_fastReplyStatusMessage'][] = $this->forumClass->ppdStatusMessage;
			}
		}

		$topicData['_fastReplyModAll'] = FALSE;
		switch( intval( $forumData['preview_posts'] ) )
		{
			case 1:
			case 3:
				$topicData['_fastReplyModAll'] = TRUE;
			break;
		}

		//-----------------------------------------
		// Update the item marker
		//-----------------------------------------

		if ( ! $this->request['view'] && ! $this->registry->getClass('topics')->isArchived( $topicData ) )
		{
			/* If we marked page 2 but land back on page 1 again we don't want to unmark it! */
			$lastMarked = $this->registry->classItemMarking->fetchTimeLastMarked( array( 'forumID' => $forumData['id'], 'itemID' => $topicData['tid'] ) );

			/* is this the very last page? */
			if ( $this->registry->getClass('topics')->isOnLastPage() )
			{
				/* ...then make the timestamp 'NOW' so polls will be cleared correctly */
				$this->_maxPostDate = IPS_UNIX_TIME_NOW;
			}

			if ( $lastMarked < $this->_maxPostDate )
			{
				$this->registry->getClass('classItemMarking')->markRead( array( 'forumID' => $forumData['id'], 'itemID' => $topicData['tid'], 'markDate' => $this->_maxPostDate, 'containerLastActivityDate' => $forumData['last_post'] ) );
			}
		}

		/* add meta update time */
		if ( $this->_maxPostDate )
		{
			$this->registry->output->addMetaTag( 'og:updated_time', $this->_maxPostDate, false );
		}

		/* Set has unread flag */
		$forumData['_hasUnreadTopics'] = $this->registry->getClass('class_forums')->getHasUnread( $forumData['id'] );

		IPSDebug::setMemoryDebugFlag( "TOPICS: Parsed Posts - Completed", $_NOW );

		//-----------------------------------------
		// Generate template
		//-----------------------------------------

		$topicData['id'] = $topicData['forum_id'];

		//-----------------------------------------
		// This has to be called first to set $this->poll_only
		//-----------------------------------------

		$poll_data = ( $topicData['poll_state'] ) ? $this->_generatePollOutput() : array( 'html' => '', 'poll' => '' );

		$displayData = array( 'fast_reply'		      => $this->_getFastReplyData(),
							  'multi_mod'			  => $this->registry->getClass('topics')->getMultiModerationData(),
							  'reply_button'		  => $this->_getReplyButtonData(),
							  'active_users'		  => $this->_getActiveUserData(),
							  'mod_links'			  => ( $this->registry->getClass('topics')->isArchived( $topicData ) ) ? '' : $this->_generateModerationPanel(),
							  'follow_data' 		  => ( $this->registry->getClass('topics')->isArchived( $topicData ) or $topicData['_isDeleted'] ) ? '' : $this->_like->render( 'summary', $topicData['tid'] ),
							  'same_tagged'			  => ( $this->registry->getClass('topics')->isArchived( $topicData ) ) ? '' : $this->_getSameTaggedData(),
							  'poll_data'			  => $poll_data,
							  'load_editor_js'		  => ( $this->_getFastReplyData() && $topicData['_isDeleted'] ) ? true : false,
							  'smilies'				  => '',
							  'best_answer_post_data' => $this->_getBestAnswerFeature( $postData, $topicData ) );

		//-----------------------------------------
		// If we can edit, but not reply, load JS still
		//-----------------------------------------

		if( !( $displayData['fast_reply'] and $displayData['reply_button']['url'] ) AND $this->_canEditAPost )
		{
			$displayData['load_editor_js']	= true;

			$classToLoad			= IPSLib::loadLibrary( IPS_ROOT_PATH . 'sources/classes/editor/composite.php', 'classes_editor_composite' );
			$editor					= new $classToLoad();
			$displayData['smilies']	= $editor->fetchEmoticons();
		}

		$postData = $this->_parseAttachments( $postData );

		/* Rules */
		if( $forumData['show_rules'] == 2 )
		{
			IPSText::getTextClass( 'bbcode' )->parse_smilies			= 1;
			IPSText::getTextClass( 'bbcode' )->parse_html				= 1;
			IPSText::getTextClass( 'bbcode' )->parse_nl2br				= 1;
			IPSText::getTextClass( 'bbcode' )->parse_bbcode				= 1;
			IPSText::getTextClass( 'bbcode' )->parsing_section			= 'topics';
			IPSText::getTextClass( 'bbcode' )->parsing_mgroup			= $this->memberData['member_group_id'];
			IPSText::getTextClass( 'bbcode' )->parsing_mgroup_others	= $this->memberData['mgroup_others'];

			$forumData['rules_text'] = IPSText::getTextClass( 'bbcode' )->preDisplayParse( $forumData['rules_text'] );
		}

		/* Got soft delete pids? */
		if ( is_array( $this->_sdPids ) AND count( $this->_sdPids ) )
		{
			$displayData['sdData'] = IPSDeleteLog::fetchEntries( $this->_sdPids, 'post', false );
		}
		if ( $topicData['_isDeleted'] )
		{
			$topicData['sdData'] = IPSDeleteLog::fetchEntries( array( $topicData['tid'] ), 'topic', false );
			$topicData['sdData'] = $topicData['sdData'][ $topicData['tid'] ];
		}

		if( $topicData['starter_id'] )
		{
			$topicData['_starter']	= IPSMember::buildDisplayData( IPSMember::load( $topicData['starter_id'] ) );
		}
		else
		{
			$topicData['_starter']  = IPSMember::buildDisplayData( IPSMember::setUpGuest( $topicData['starter_name'] ? $this->settings['guest_name_pre'] . $topicData['starter_name'] . $this->settings['guest_name_suf'] : '' ) );
		}

		/* Can we report? */
		$classToLoad	= IPSLib::loadLibrary( IPSLib::getAppDir('core') . '/sources/classes/reportLibrary.php', 'reportLibrary', 'core' );
		$reports		= new $classToLoad( $this->registry );

		$topicData['_canReport']	= $reports->canReport( 'post' );

		/* No likey no lighty */
		require_once( IPS_ROOT_PATH . 'sources/classes/like/composite.php' );/*noLibHook*/
		$_like	= classes_like::bootstrap( 'forums','topics' );
		$topicData['_isLiked']	= ( $this->memberData['member_id'] ) ? $_like->isLiked( $topicData['tid'], $this->memberData['member_id'] ) : false;

		$template = $this->registry->output->getTemplate('topic')->topicViewTemplate( $forumData, $topicData, $postData, $displayData );

		//-----------------------------------------
		// Send for output
		//-----------------------------------------

		$this->registry->output->setTitle( strip_tags( $topicData['title'] ) . '<%pageNumber%> - ' . $forumData['name'] . ' - ' . $this->settings['board_name']);
		$this->registry->output->addContent( $template );

		if ( is_array( $this->nav ) AND count( $this->nav ) )
		{
			foreach( $this->nav as $_nav )
			{
				$this->registry->output->addNavigation( $_nav[0], $_nav[1], $_nav[2], $_nav[3] );
			}
		}

		/**
		 * Add navigational links
		 */
		$this->registry->output->addToDocumentHead( 'raw', "<link rel='up' href='" . $this->registry->output->buildSEOUrl( 'showforum=' . $topicData['forum_id'], 'publicNoSession', $forumData['name_seo'], 'showforum' ) . "' />" );
		$this->registry->output->addToDocumentHead( 'raw', "<link rel='author' href='" . $this->registry->output->buildSEOUrl( 'showuser=' . $topicData['starter_id'], 'publicNoSession', $topicData['seo_first_name'], 'showuser' ) . "' />" );

		/* Add Meta Content */
		if ( $this->_firstPostContent )
		{
			/* Strip tags on title to ensure multi-mod added code isn't displayed */
			$this->registry->output->addMetaTag( 'keywords', strip_tags( trim( $topicData['title'] ) . ' ' . str_replace( "\n", " ", str_replace( "\r", "", strip_tags( $this->_firstPostContent ) ) ) ), TRUE );
		}

		$pageData = $this->registry->output->getPaginationProcessedData();
		$pageMeta = ( $pageData['pages'] > 1 ) ? sprintf( $this->lang->words['topic_meta_pages'], $pageData['current_page'], $pageData['pages'] ) .' ' : '';

		# Trim to 155 chars based on Dan's recommendation
		$this->registry->output->addMetaTag( 'description', trim( $pageMeta . sprintf( $this->lang->words['topic_meta_description'], strip_tags( $topicData['title'] ), $forumData['name'], str_replace( "\r", "", $this->_firstPostContent ) ) ), FALSE );

		/* Set Ad code for the board index */
		if( $this->registry->getClass('IPSAdCode')->userCanViewAds() )
		{
			$this->registry->getClass('IPSAdCode')->setGlobalCode( 'header', 'ad_code_topic_view_header' );
			$this->registry->getClass('IPSAdCode')->setGlobalCode( 'footer', 'ad_code_topic_view_footer' );
		}

		$this->registry->output->sendOutput();
	}

	/**
	 * Builds an array of post data for output
	 *
	 * @param	array	$row	Array of post data
	 * @return	array
	 */
	public function parsePostRow( $row = array() )
	{
		/* Init */
		$topicData      = $this->registry->getClass('topics')->getTopicData();
		$forumData      = $this->forumClass->getForumById( $topicData['forum_id'] );
		$permissionData = $this->registry->getClass('topics')->getPermissionData();

		/* Parse post */
		$parsed = $this->registry->getClass('topics')->parsePost( $row );

		if( $parsed['post']['_can_edit'] )
		{
			$this->_canEditAPost	= true;
		}

		/* Collect PIDS of soft deleted posts */
		if ( $parsed['post']['_isDeleted'] AND $parsed['post']['_softDeleteSee'] )
		{
			$this->_sdPids[] = $parsed['post']['pid'];
		}

		/* Grab first post */
		if ( $topicData['topic_firstpost'] == $parsed['post']['pid'] )
		{
			$this->_firstPostContent = $parsed['post']['post'];
		}
		else if( $this->request['page'] AND ! $this->_firstPostContent )
		{
			$this->_firstPostContent = $parsed['post']['post'];
		}

		/* Anything to highlight? */
		if ( isset($this->request['hl']) AND $this->request['hl'] )
		{
			$parsed['post']['post'] = IPSText::searchHighlight( $parsed['post']['post'], $this->request['hl'] );
		}

		/* Multi quote */
		if ( $this->qpids )
		{
			if ( strstr( ','.$this->qpids.',', ','.$parsed['post']['pid'].',' ) )
			{
				$parsed['post']['_mq_selected'] = 1;
			}
		}

		/* Mod PIDS */
		if ( $this->memberData['is_mod'] )
		{
			if ( $this->request['selectedpids'] )
			{
				if ( strstr( ','.$this->request['selectedpids'].',', ','.$parsed['post']['pid'].',' ) )
				{
					$parsed['post']['_pid_selected'] = 1;
				}

				$this->request['selectedpidcount'] =  count( explode( ",", $this->request['selectedpids']  ) );
			}
		}

		/* Post number */
		$this->post_count++;

		$parsed['post']['post_count'] = ( $this->request['page'] > 1 ) ? ( intval($this->request['page'] - 1) * $this->settings['display_max_posts'] ) + $this->post_count : $this->post_count;

		if ( $parsed['post']['_isDeleted'] )
		{
			$this->post_count--;
		}

		/* Post max date for item marking*/
		if ( $row['post_date'] > $this->_maxPostDate )
		{
			$this->_maxPostDate = $row['post_date'];
		}

		return $parsed;
	}

	/**
	 * Redirects to new post
	 * @param mixed $topicData
	 */
	public function returnNewPost( $topicData=false )
	{
		$topicData      = ( $topicData === false ) ? $this->registry->getClass('topics')->getTopicData() : $topicData;
		$forumData      = $this->forumClass->getForumById( $topicData['forum_id'] );
		$permissionData = $this->registry->getClass('topics')->getPermissionData();
		$st             = 0;
		$pid	        = "";
		$last_time      = $this->registry->classItemMarking->fetchTimeLastMarked( array( 'forumID' => $forumData['id'], 'itemID' => $topicData['tid'] ) );
		$query          = ' 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 */
				$query = ' AND ' . $this->registry->class_forums->fetchPostHiddenQuery( array( 'approved', 'sdeleted', 'hidden' ) );
			}
			else
			{
				/* Otherwise, see queued and approved */
				$query = ' AND ' . $this->registry->class_forums->fetchPostHiddenQuery( array( 'visible', 'hidden' ) );
			}
		}
		else
		{
			/* We cannot see hidden posts */
			if ( $permissionData['softDeleteSee'] )
			{
				/* See queued and soft deleted */
				$query = ' AND ' . $this->registry->class_forums->fetchPostHiddenQuery( array('approved', 'sdeleted') );
			}
		}

		$this->DB->build( array( 'select' => 'MIN(pid) as pid',
								 'from'   => 'posts',
								 'where'  => "topic_id={$topicData['tid']} AND post_date > " . intval( $last_time ) . $query,
								 'limit'  => array( 0,1 ) )	);
		$this->DB->execute();

		$post = $this->DB->fetch();

		if ( $post['pid'] )
		{
			$pid = "#entry".$post['pid'];

			$this->DB->build( array( 'select' => 'COUNT(*) as posts', 'from' => 'posts', 'where' => "topic_id={$topicData['tid']} AND pid <= {$post['pid']}" . $query ) );
			$this->DB->execute();

			$cposts = $this->DB->fetch();

			if ( (($cposts['posts']) % $this->settings['display_max_posts']) == 0 )
			{
				$pages = ($cposts['posts']) / $this->settings['display_max_posts'];
			}
			else
			{
				$number = ( ($cposts['posts']) / $this->settings['display_max_posts'] );
				$pages = ceil( $number);
			}

			$st = ($pages - 1) * $this->settings['display_max_posts'];

			if( $this->settings['post_order_sort'] == 'desc' )
			{
				$st = (ceil(($topicData['posts']/$this->settings['display_max_posts'])) - $pages) * $this->settings['display_max_posts'];
			}

			$stUrlParam = ( $st ) ? '&page=' . $this->registry->getClass('topics')->stToPage( $st ) : '';

			$this->registry->output->silentRedirect( $this->settings['base_url']."showtopic=".$topicData['tid'].$stUrlParam.$pid, $topicData['title_seo'], 302, 'showtopic' );
		}
		else
		{
			$this->returnLastPost( $topicData );
		}
	}

	/**
	 * Return last post
	 *
	 * @return	@e void
	 */
	public function returnLastPost( $topicData=false )
	{
		/* Init */
		$topicData      = ( $topicData === false ) ? $this->registry->getClass('topics')->getTopicData() : $topicData;
		$forumData      = $this->forumClass->getForumById( $topicData['forum_id'] );
		$permissionData = $this->registry->getClass('topics')->getPermissionData();
		$st             = 0;
		$query          = ' AND ' . $this->registry->class_forums->fetchPostHiddenQuery('visible');
		$_posts			= $topicData['posts'];

		if( $this->registry->class_forums->canQueuePosts( $topicData['forum_id'] ) )
		{
			$_posts	+= intval($topicData['topic_queuedposts']);
		}

		if( $permissionData['softDeleteSee'] )
		{
			$_posts	+= intval($topicData['topic_deleted_posts']);
		}

		/* Can we deal with hidden posts? */
		if ( $this->registry->class_forums->canQueuePosts( $topicData['forum_id'] ) )
		{
			if ( $permissionData['softDeleteSee'] )
			{
				/* See queued and soft deleted */
				$query = ' AND ' . $this->registry->class_forums->fetchPostHiddenQuery( array( 'approved', 'sdeleted', 'hidden' ) );
			}
			else
			{
				/* Otherwise, see queued and approved */
				$query = ' AND ' . $this->registry->class_forums->fetchPostHiddenQuery( array( 'visible', 'hidden' ) );
			}
		}
		else
		{
			/* We cannot see hidden posts */
			if ( $permissionData['softDeleteSee'] )
			{
				/* See queued and soft deleted */
				$query = ' AND ' . $this->registry->class_forums->fetchPostHiddenQuery( array('approved', 'sdeleted') );
			}
		}

		if( $_posts )
		{
			if ( (($_posts + 1) % $this->settings['display_max_posts']) == 0 )
			{
				$pages = ($_posts + 1) / $this->settings['display_max_posts'];
			}
			else
			{
				$number = ( ($_posts + 1) / $this->settings['display_max_posts'] );
				$pages = ceil( $number );
			}

			$st = ($pages - 1) * $this->settings['display_max_posts'];

			if( $this->settings['post_order_sort'] == 'desc' )
			{
				$st = (ceil(($_posts/$this->settings['display_max_posts'])) - $pages) * $this->settings['display_max_posts'];
			}
		}

		$this->DB->build( array(  'select' => 'pid',
								  'from'   => 'posts',
								  'where'  => "topic_id=".$topicData['tid'] . $query,
								  'order'  => $this->settings['post_order_column'].' DESC',
								  'limit'  => array( 0,1 ) ) );

		$this->DB->execute();

		$post = $this->DB->fetch();

		$stUrlParam = ( $st ) ? '&page=' . $this->registry->getClass('topics')->stToPage( $st ) : '';
		$this->registry->output->silentRedirect($this->settings['base_url']."showtopic=".$topicData['tid']. $stUrlParam ."#entry".$post['pid'], $topicData['title_seo'], 302, 'showtopic' );
	}

	/**
	* Parse attachments
	*
	* @param	array	Array of post data
	* @return	string	HTML parsed by attachment class
	*/
	public function _parseAttachments( $postData )
	{
		/* Init */
		$topicData = $this->registry->getClass('topics')->getTopicData();
		$forumData = $this->forumClass->getForumById( $topicData['forum_id'] );

		//-----------------------------------------
		// No attachments?  Then what are you doing here?
		//-----------------------------------------

		if ( ! $topicData['topic_hasattach'] )
		{
			return $postData;
		}

		//-----------------------------------------
		// INIT. Yes it is
		//-----------------------------------------

		$postHTML = array();

		//-----------------------------------------
		// Separate out post content
		//-----------------------------------------

		foreach( $postData as $id => $post )
		{
			$postHTML[ $id ] = $post['post']['post'];
		}

		//-----------------------------------------
		// ATTACHMENTS!!!
		//-----------------------------------------

		if ( ! is_object( $this->class_attach ) )
		{
			//-----------------------------------------
			// Grab render attach class
			//-----------------------------------------

			$classToLoad = IPSLib::loadLibrary( IPSLib::getAppDir( 'core' ) . '/sources/classes/attach/class_attach.php', 'class_attach' );
			$this->class_attach		   =  new $classToLoad( $this->registry );
		}

		//-----------------------------------------
		// Not got permission to view downloads?
		//-----------------------------------------

		if ( $this->registry->permissions->check( 'download', $this->registry->class_forums->forum_by_id[ $topicData['forum_id'] ] ) === FALSE )
		{
			$this->settings['show_img_upload'] =  0 ;
		}

		//-----------------------------------------
		// Continue...
		//-----------------------------------------

		$this->class_attach->type  = 'post';
		$this->class_attach->init();

		$attachHTML = $this->class_attach->renderAttachments( $postHTML, array_keys( $postData ) );

		/* Now parse back in the rendered posts */
		if( is_array($attachHTML) AND count($attachHTML) )
		{
			foreach( $attachHTML as $id => $data )
			{
				/* Get rid of any lingering attachment tags */
				if ( stristr( $data['html'], "[attachment=" ) )
				{
					$data['html'] = IPSText::stripAttachTag( $data['html'] );
				}

				$postData[ $id ]['post']['post']			= $data['html'];
				$postData[ $id ]['post']['attachmentHtml']	= $data['attachmentHtml'];
			}
		}

		return $postData;
	}

	/**
	 * Generate the Poll output
	 *
	 * @return	string
	 */
	public function _generatePollOutput()
	{
		/* Init */
		$topicData   = $this->registry->getClass('topics')->getTopicData();
		$forumData   = $this->forumClass->getForumById( $topicData['forum_id'] );
		$showResults = 0;
		$pollData    = array();

		//-----------------------------------------
		// Get the poll information...
		//-----------------------------------------

		$this->DB->build( array( 'select' => '*', 'from' => 'polls', 'where' => 'tid=' . $topicData['tid'] ) );
		$this->DB->execute();

		$poll = $this->DB->fetch();

		//-----------------------------------------
		// check we have a poll
		//-----------------------------------------

		if ( ! $poll['pid'] )
		{
			return array( 'html' => '', 'poll' => '' );
		}

		//-----------------------------------------
		// Do we have a poll question?
		//-----------------------------------------

		if ( ! $poll['poll_question'] )
		{
			$poll['poll_question'] = $topicData['title'];
		}

		//-----------------------------------------
		// Poll only?
		//-----------------------------------------

		if ( $poll['poll_only'] == 1 )
		{
			$this->registry->getClass('topics')->setTopicData( 'poll_only', true );
		}

		//-----------------------------------------
		// Additional Poll Vars
		//-----------------------------------------

		$poll['_totalVotes']  = 0;
		$poll['_memberVoted'] = 0;
		$memberChoices        = array();

		//-----------------------------------------
		// Have we voted in this poll?
		//-----------------------------------------

		/* Save a join @link http://community.invisionpower.com/tracker/issue-35773-pollsvoters-voters-table-joining-to-million-plus-rows/ */
		if ( $poll['poll_view_voters'] AND $this->settings['poll_allow_public'] )
		{
			$this->DB->build( array( 'select'   => 'v.*',
									 'from'     => array( 'voters' => 'v' ),
									 'where'    => 'v.tid=' . $topicData['tid'],
									 'add_join' => array( array( 'select' => 'm.*',
																 'from'   => array( 'members' => 'm' ),
																 'where'  => 'm.member_id=v.member_id',
																 'type'   => 'left' ) ) ) );
		}
		else
		{
			$this->DB->build( array( 'select'   => '*',
									 'from'     => 'voters',
									 'where'    => 'tid=' . $topicData['tid'] ) );
		}

		$this->DB->execute();

		while( $voter = $this->DB->fetch() )
		{
			$poll['_totalVotes']++;

			if ( $voter['member_id'] == $this->memberData['member_id'] )
			{
				$poll['_memberVoted'] = 1;
			}

			/* Member choices */
			if ( $voter['member_choices'] AND ( ( $poll['poll_view_voters'] AND $this->settings['poll_allow_public'] ) OR $voter['member_id'] == $this->memberData['member_id'] ) )
			{
				$_choices = IPSLib::safeUnserialize( $voter['member_choices'] );

				if ( is_array( $_choices ) AND count( $_choices ) )
				{
					$memberData = array( 'member_id'            => $voter['member_id'],
										 'members_seo_name'     => ( $voter['member_id'] == $this->memberData['member_id'] ) ? $this->memberData['members_seo_name'] : $voter['members_seo_name'],
										 'members_display_name' => ( $voter['member_id'] == $this->memberData['member_id'] ) ? $this->memberData['members_display_name'] : $voter['members_display_name'],
										 'members_colored_name' => str_replace( '"', '\"', ( $voter['member_id'] == $this->memberData['member_id'] ) ? IPSMember::makeNameFormatted( $this->memberData['members_display_name'], $this->memberData['member_group_id'] ) : IPSMember::makeNameFormatted( $voter['members_display_name'], $voter['member_group_id'] ) ),
										 '_last'                => 0 );

					foreach( $_choices as $_questionID => $data )
					{
						foreach( $data as $_choice )
						{
							$memberChoices[ $_questionID ][ $_choice ][ $voter['member_id'] ] = $memberData;
						}
					}
				}
			}
		}

		//-----------------------------------------
		// Already Voted
		//-----------------------------------------

		if ( $poll['_memberVoted'] )
		{
			$showResults = 1;
		}

		//-----------------------------------------
		// Created poll and can't vote in it
		//-----------------------------------------

		if ( ($poll['starter_id'] == $this->memberData['member_id']) and ($this->settings['allow_creator_vote'] != 1) )
		{
			$showResults = 1;
		}

		//-----------------------------------------
		// Guest, but can view results without voting
		//-----------------------------------------

		if ( ! $this->memberData['member_id'] AND $this->settings['allow_result_view'] )
		{
			$showResults = 1;
		}

		//-----------------------------------------
		// is the topic locked?
		//-----------------------------------------

		if ( $topicData['state'] == 'closed' )
		{
			$showResults = 1;
		}

		//-----------------------------------------
		// Can we see the poll before voting?
		//-----------------------------------------

		if ( $this->settings['allow_result_view'] == 1 AND $this->request['mode'] == 'show' )
		{
			$showResults = 1;
		}

		//-----------------------------------------
		// Stop the parser killing images
		// 'cos there are too many
		//-----------------------------------------

		$tmp_max_images			      = $this->settings['max_images'];
		$this->settings['max_images'] = 0;

		//-----------------------------------------
		// Parse it
		//-----------------------------------------

		$poll_answers 	 = IPSLib::safeUnserialize(stripslashes($poll['choices']));

		if( !is_array($poll_answers) OR !count($poll_answers) )
		{
			$poll_answers = IPSLib::safeUnserialize( preg_replace( '!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", stripslashes( $poll['choices'] ) ) );
		}
		if( !is_array($poll_answers) OR !count($poll_answers) )
		{
			$poll_answers = array();
		}

		reset($poll_answers);

		foreach ( $poll_answers as $id => $data )
		{
			if( !is_array($data['choice']) OR !count($data['choice']) )
			{
				continue;
			}

			//-----------------------------------------
			// Get the question
			//-----------------------------------------

			$pollData[ $id ]['question'] = $data['question'];

			$tv_poll = 0;

			# Get total votes for this question
			if( is_array($poll_answers[ $id ]['votes']) AND count($poll_answers[ $id ]['votes']) )
			{
				foreach( $poll_answers[ $id ]['votes'] as $number)
				{
					$tv_poll += intval( $number );
				}
			}

			//-----------------------------------------
			// Get the choices for this question
			//-----------------------------------------

			foreach( $data['choice'] as $choice_id => $text )
			{
				$choiceData = array();
				$choice     = $text;
				$voters     = array();

				# Get total votes for this question -> choice
				$votes   = intval($data['votes'][ $choice_id ]);

				if ( strlen($choice) < 1 )
				{
					continue;
				}

				if ( stristr( $choice, '[img' ) || stristr( $choice, '[url' ) || stristr( $text, '[sharedmedia' ) )
				{
					if ( ! is_object( $this->_textParser ) )
					{
						/* Load parser */
						$classToLoad = IPSLib::loadLibrary( IPS_ROOT_PATH . 'sources/classes/text/parser.php', 'classes_text_parser' );
						$this->_textParser = new $classToLoad();
					}

					$choice = $this->_textParser->parsePollTags( $choice );
				}

				if ( $showResults )
				{
					$percent = $votes == 0 ? 0 : $votes / $tv_poll * 100;
					$percent = sprintf( '%.2F' , $percent );
					$width   = $percent > 0 ? intval($percent * 2) : 0;

					/* Voters */
					if ( $memberChoices[ $id ][ $choice_id ] )
					{
						$voters = $memberChoices[ $id ][ $choice_id ];
						$_tmp   = $voters;

						$lastDude = array_pop( $_tmp );

						$voters[ $lastDude['member_id'] ]['_last'] = 1;
					}

					$pollData[ $id ]['choices'][ $choice_id ] = array( 'votes'   => $votes,
													  				   'choice'  => $choice,
																	   'percent' => $percent,
																	   'width'   => $width,
																	   'voters'  => $voters );
				}
				else
				{
					$pollData[ $id ]['choices'][ $choice_id ] =  array( 'type'   => !empty($data['multi']) ? 'multi' : 'single',
													   					'votes'  => $votes,
																		'choice' => $choice );
				}
			}
		}

		$_editPoll	= $this->registry->getClass('topics')->canEditPost( array( 'member_id' => $topicData['starter_id'], 'post_date' => $topicData['start_date'] ) );

		$html = $this->registry->output->getTemplate('topic')->pollDisplay( $poll, $topicData, $forumData, $pollData, $showResults, $_editPoll );

		$this->settings['max_images'] = $tmp_max_images;

		return array( 'html' => $html, 'poll' => $poll );
	}

	/**
	 * Tests to see if we're viewing a post, etc
	 *
	 * @return	@e void
	 */
	protected function _doViewCheck()
	{
		/* Init */
		$topicData      = $this->registry->getClass('topics')->getTopicData();
		$forumData      = $this->forumClass->getForumById( $topicData['forum_id'] );
		$permissionData = $this->registry->getClass('topics')->getPermissionData();

		if ( $this->request['view'] )
		{
			/* Determine what we can see */
			$_approved	= $this->registry->class_forums->fetchTopicHiddenQuery( array( 'visible' ), '' );

			/* Can we deal with hidden posts? */
			if ( $this->registry->class_forums->canQueuePosts( $topicData['forum_id'] ) )
			{
				if ( $permissionData['TopicSoftDeleteSee'] )
				{
					/* See queued and soft deleted */
					$_approved = $this->registry->class_forums->fetchTopicHiddenQuery( array( 'approved', 'sdeleted', 'hidden' ), '' );
				}
				else
				{
					/* Otherwise, see queued and approved */
					$_approved = $this->registry->class_forums->fetchTopicHiddenQuery( array( 'visible', 'hidden' ), '' );
				}
			}
			else
			{
				/* We cannot see hidden posts */
				if ( $permissionData['TopicSoftDeleteSee'] )
				{
					/* See queued and soft deleted */
					$_approved = $this->registry->class_forums->fetchTopicHiddenQuery( array( 'approved', 'sdeleted' ), '' );
				}
			}

			if ( $this->request['view'] == 'getnextunread' )
			{
				$tid   = $this->registry->getClass('topics')->getNextUnreadTopicId();

				if ( $tid )
				{
					$topic = $this->registry->getClass('topics')->getTopicById( $tid );

					$this->returnNewPost( $topic );
				}
				else
				{
					$this->registry->output->showError( 'topics_none_newer', 10356, null, null, 404 );
				}
			}
			else if ($this->request['view'] == 'new')
			{
				//-----------------------------------------
				// Newer
				//-----------------------------------------

				$this->DB->build( array(
												'select' => 'tid, title_seo',
												'from'   => 'topics',
												'where'  => "forum_id={$forumData['id']} AND {$_approved} AND state <> 'link' AND last_post > {$topicData['last_post']}",
												'order'  => 'last_post',
												'limit'  => array( 0,1 )
									)	);
				$this->DB->execute();

				if ( $this->DB->getTotalRows() )
				{
					$this->topic = $this->DB->fetch();

					$this->registry->output->silentRedirect( $this->settings['base_url']."showtopic=".$topicData['tid'], $topicData['title_seo'], 302, 'showtopic' );
				}
				else
				{
					$this->registry->output->showError( 'topics_none_newer', 10356, null, null, 404 );
				}
			}
			else if ($this->request['view'] == 'old')
			{
				//-----------------------------------------
				// Older
				//-----------------------------------------

				$this->DB->build( array(
												'select' => 'tid, title_seo',
												'from'   => 'topics',
												'where'  => "forum_id={$forumData['id']} AND {$_approved} AND state <> 'link' AND last_post < {$topicData['last_post']}",
												'order'  => 'last_post DESC',
												'limit'  => array( 0,1 )
									)	);

				$this->DB->execute();

				if ( $this->DB->getTotalRows() )
				{
					$this->topic = $this->DB->fetch();

					$this->registry->output->silentRedirect( $this->settings['base_url']."showtopic=".$topicData['tid'], $topicData['title_seo'], 302, 'showtopic' );
				}
				else
				{
					$this->registry->output->showError( 'topics_none_older', 10357, null, null, 404 );
				}
			}
			else if ($this->request['view'] == 'getlastpost')
			{
				//-----------------------------------------
				// Last post
				//-----------------------------------------

				$this->returnLastPost();
			}
			else if ($this->request['view'] == 'getnewpost')
			{
				$this->returnNewPost();
			}
			else if ($this->request['view'] == 'findpost')
			{
				//-----------------------------------------
				// Find a post
				//-----------------------------------------

				$pid	= intval($this->request['p']);

				$search_hl = '';

				if ( ! empty( $this->request['hl'] ) )
				{
					$search_hl .= "&hl=" . urlencode( $this->request['hl'] );
				}

				/* Can we deal with hidden posts? */
				$_perms = array( 'visible' );

				if ( $this->registry->getClass('class_forums')->canSeeSoftDeletedPosts( false ) )
				{
					$_perms[] = 'sdelete';
				}

				if ( $this->registry->getClass('class_forums')->canQueuePosts( false ) )
				{
					$_perms[] = 'hidden';
				}

				if ( $this->registry->getClass('topics')->isArchived( $topicData ) && $this->registry->class_forums->fetchArchiveTopicType( $topicData ) != 'working' )
				{
					$cposts['posts'] = $this->archiveReader->getPostCount( $topicData['tid'], $_perms );
				}
				else
				{
					$query	= ' AND ' . $this->registry->class_forums->fetchPostHiddenQuery('visible');

					$query = $this->registry->class_forums->fetchPostHiddenQuery( $_perms );

					if ( $pid > 0 )
					{
						$sort_value = $pid;
						$sort_field = ($this->settings['post_order_column'] == 'pid') ? 'pid' : 'post_date';

						if($sort_field == 'post_date')
						{
							$date = $this->DB->buildAndFetch( array( 'select' => 'post_date', 'from' => 'posts', 'where' => 'pid=' . $pid ) );

							$sort_value = $date['post_date'];
						}

						$this->DB->build( array( 'select' => 'COUNT(*) as posts', 'from' => 'posts', 'where' => "topic_id={$topicData['tid']} AND {$sort_field} <=" . intval( $sort_value ) . ' AND ' . $query ) );
						$this->DB->execute();

						$cposts = $this->DB->fetch();
					}
					else
					{
						$this->returnLastPost();
					}
				}

				if ( (($cposts['posts']) % $this->settings['display_max_posts']) == 0 )
				{
					$pages = ($cposts['posts']) / $this->settings['display_max_posts'];
				}
				else
				{
					$number = ( ($cposts['posts']) / $this->settings['display_max_posts'] );
					$pages = ceil($number);
				}

				$st = ($pages - 1) * $this->settings['display_max_posts'];

				if( $this->settings['post_order_sort'] == 'desc' )
				{
					$st = (ceil(($topicData['posts']/$this->settings['display_max_posts'])) - $pages) * $this->settings['display_max_posts'];
				}

				$stUrlParam = ( $st ) ? '&page=' . $this->registry->getClass('topics')->stToPage( $st ) : '';

				$this->registry->output->silentRedirect( $this->settings['base_url']."showtopic=".$topicData['tid']."{$stUrlParam}{$search_hl}"."#entry".$pid, $topicData['title_seo'], 302, 'showtopic' );
			}
		}
	}

	/**
	 * Fetch data tagged the same
	 * @return array
	 */
	protected function _getSameTaggedData()
	{
		/* Init */
		$topicData = $this->registry->getClass('topics')->getTopicData();
		$results   = array();
		$final     = array();

		/* Have we got tags? */
		if ( $this->settings['forums_enabled_also_tagged'] && $this->settings['tags_enabled'] && count( $topicData['tags']['tags'] ) )
		{
			$results = $this->registry->tags->search( $topicData['tags']['tags'], array( 'meta_app'        => 'forums',
																						 'meta_area'       => 'topics',
																						 'meta_parent_id'  => false,
																						 'not_meta_id'     => $topicData['tid'],
																						 'sortKey'		   => 'tg.tag_meta_id',
																						 'sortOrder'	   => 'desc',
																						 'limit'		   => 100,
																						 'joins'		   => array( array( 'select' => 't.*, t.approved, t.title as topic_title, t.posts as topic_posts, t.last_post as topic_last_post', 'from' => array( 'topics' => 't' ), 'where' => 't.tid=tg.tag_meta_id' ),
																													 array( 'select' => 'm.*', 'from' => array( 'members' => 'm' ), 'where' => 'last_poster_id=m.member_id' ),
																													 array( 'select' => 'p.*', 'from' => array( 'profile_portal' => 'p' ), 'where' => 'p.pp_member_id=m.member_id' ),
																													 $this->registry->tags->getCacheJoin( array( 'meta_id_field' => 't.tid' ) ) ),
																						 'isViewable'      => true ) );
		}

		/* Limit to 5 unique topics */
		if ( is_array( $results ) AND count( $results ) )
		{
			$_tmp    = $results;
			$results = array();
			$loadIds = array();
			$members = array();

			foreach( $_tmp as $_id => $_data )
			{
				if ( ! isset($results[ $_data['tid'] ]) )
				{
					if ( $this->registry->class_forums->fetchHiddenTopicType( $_data ) != 'visible' )
					{
						continue;
					}

					if ( ! $this->registry->permissions->check( 'view', $this->registry->class_forums->forum_by_id[ $_data['forum_id'] ] ) )
					{
						continue;
					}

					if ( ! $this->registry->class_forums->forumsCheckAccess( $_data['forum_id'], 0, 'forum', array(), true ) )
					{
						continue;
					}

					if( $_data['starter_id'] )					{
						$loadIds[ $_data['starter_id'] ] = $_data['starter_id'];					}

					$results[ $_data['tid'] ] = $_data;
					/* Alreay got our 5 results? */
					if ( count( $results ) == 5 )
					{
						break;					}
				}
			}

			if ( count($loadIds) )
			{
				$members = IPSMember::load( $loadIds );
			}

			/* Finally parse our results */
			foreach( $results as $id => $data )
			{
				if( $data['starter_id'] && isset($members[ $data['starter_id'] ]) )
				{
					$data['_starter'] = IPSMember::buildDisplayData( $members[ $data['starter_id'] ] );
				}
				else
				{
					$data['_starter'] = IPSMember::buildDisplayData( IPSMember::setUpGuest( $data['starter_name'] ? $this->settings['guest_name_pre'] . $data['starter_name'] . $this->settings['guest_name_suf'] : '' ) );
				}

				$data = $this->registry->topics->parseTopicForLineEntry( $data );

				/* Sort out navigation */
				$data['nav'] = $this->registry->class_forums->forumsBreadcrumbNav( $data['forum_id'] );

				if ( $data['last_poster_id'] )
				{
					$final[ $data['tid'] ] = IPSMember::buildDisplayData( $data, array( 'photoTagSize' => 'mini' ) );
				}
				else
				{
					$final[ $data['tid'] ] = $data;
				}
			}
		}

		return $final;
	}

	/**
	 * Get reply button data
	 *
	 * @return	array
	 */
	public function _getReplyButtonData()
	{
		/* Init */
		$topicData = $this->registry->getClass('topics')->getTopicData();
		$forumData = $this->forumClass->getForumById( $topicData['forum_id'] );

		$image = $this->registry->getClass('topics')->getReplyStatus();
		$url   = ( $image == 'reply' OR ( $image == 'locked' AND $this->memberData['g_post_closed'] ) ) ? $this->settings['base_url_with_app'] . "module=post&section=post&do=reply_post&f=".$forumData['id']."&t=".$topicData['tid'] : '';

		return array( 'image' => $image, 'url' => $url );
	}

	/**
	 * Get fast reply status
	 *
	 * @return	string
	 */
	public function _getFastReplyData()
	{
		/* Hang on, can we post? */
		if ( $this->memberData['member_id'] )
		{
			if ( $this->memberData['unacknowledged_warnings'] AND !$this->memberData['restrict_post'] )
			{
				//return false;
			}
			elseif ( $this->memberData['restrict_post'] )
			{
				$data = IPSMember::processBanEntry( $this->memberData['restrict_post'] );
				if ( $data['date_end'] )
				{
					if ( time() >= $data['date_end'] )
					{
						IPSMember::save( $this->memberData['member_id'], array( 'core' => array( 'restrict_post' => 0 ) ) );
					}
					else
					{
						return false;
					}
				}
				else
				{
					return false;
				}
			}
		}

		/* Init */
		$topicData = $this->registry->getClass('topics')->getTopicData();
		$forumData = $this->forumClass->getForumById( $topicData['forum_id'] );
		$show      = false;

		if (
		       ( $this->registry->permissions->check( 'reply', $forumData ) == TRUE )
		   and ( $topicData['state'] != 'closed' OR $this->memberData['g_post_closed'] )
		   and ( $topicData['_ppd_ok'] === TRUE )
		   and ( ! $topicData['poll_only'] ) )
		{
			$show  = true;
		}

		return $show;
	}

	/**
	 * Returns a list of the active user in the topic
	 *
	 * @return	@e array
	 */
	public function _getActiveUserData()
	{
		$topicData = $this->registry->getClass('topics')->getTopicData();

		/* Nothing to retrieve? */
		if( $this->registry->getClass('topics')->isArchived( $topicData ) || $this->settings['no_au_topic'] )
		{
			return array();
		}

		$classToLoad = IPSLib::loadLibrary( IPS_ROOT_PATH . "sources/classes/session/api.php", 'session_api' );
		$sessionClass = new $classToLoad( $this->registry );

		$users = $sessionClass->getUsersIn( 'forums', array( 'skipParsing' => true, 'addWhere' => array( "s.location_1_type='topic'", "s.location_1_id={$topicData['tid']}" ) ) );

		/* Got any posting classes to add? */
		if ( ! empty($users['stats']['members']) && is_array($users['rows']['members']) && count($users['rows']['members']) )
		{
			foreach( $users['rows']['members'] as $sid => $sdata )
			{
				if ( isset($users['names'][ $sid ]) && $sdata['member_id'] != $this->memberData['member_id'] && $sdata['current_module'] == 'post' )
				{
					$users['names'][ $sid ] = "" . $users['names'][ $sid ] . "";
				}
			}
		}

		return $users;
	}

	/**
	 * Generate the moderation panel
	 * $skcusgej, still. After all this time
	 *
	 * @return	array
	 */
	public function _generateModerationPanel()
	{
		/* Init */
		$topicData = $this->registry->getClass('topics')->getTopicData();
		$forumData = $this->forumClass->getForumById( $topicData['forum_id'] );
		$moderator = $this->registry->getClass('topics')->getModeratorData();
		$mod_links = array();
		$_got_data = 0;
		$actions   = array( 'edit_topic', 'pin_topic', 'unpin_topic', 'close_topic', 'open_topic', 'move_topic', 'merge_topic', 'hide_topic', 'unhide_topic', 'delete_topic', 'unsubbit' );

		if ( ! $this->memberData['member_id'] )
		{
			return;
		}

		if ( $this->memberData['member_id'] == $topicData['starter_id'] )
		{
			$_got_data = 1;
		}

		if ( $this->memberData['g_is_supmod'] == 1 )
		{
			$_got_data = 1;
		}

		if ( !empty( $moderator['mid'] ) )
		{
			$_got_data = 1;
		}

		if ( $_got_data == 0 )
		{
		   	return;
		}

		//-----------------------------------------
		// Add on approve/unapprove topic fing
		//-----------------------------------------

		if ( $this->registry->class_forums->canQueuePosts( $forumData['id'] ) )
		{
			if ( $topicData['approved'] != 1 )
			{
				$mod_links[] = array( 'option' => 'topic_approve',
									  'value'  => $this->lang->words['cpt_approvet'] );
			}
			/*else
			{
				$mod_links[] = array( 'option' => 'topic_unapprove',
									  'value'  => $this->lang->words['cpt_unapprovet'] );
			}*/
		}

		foreach( $actions as $key )
		{
			if( is_array($this->_addModLink($key)) )
			{
				if ($this->memberData['g_is_supmod'])
				{
					$mod_links[] = $this->_addModLink($key);
				}
				elseif ( $key == 'hide_topic' )
				{
					if ( $this->registry->getClass('class_forums')->canSoftDeleteTopics( $forumData['id'], $topicData ) )
					{
						$mod_links[] = $this->_addModLink($key);
					}
				}
				elseif ( $key == 'unhide_topic' )
				{
					if ( $this->registry->getClass('class_forums')->can_Un_SoftDeleteTopics( $forumData['id'], $topicData ) )
					{
						$mod_links[] = $this->_addModLink($key);
					}
				}
				elseif ( $key == 'delete_topic' )
				{
					if ( $this->registry->getClass('class_forums')->canHardDeleteTopics( $forumData['id'], $topicData ) )
					{
						$mod_links[] = $this->_addModLink($key);
					}
				}
				elseif ( !empty($moderator['mid']) )
				{
					if ($key == 'merge_topic' or $key == 'split_topic')
					{
						if ($moderator['split_merge'] == 1)
						{
							$mod_links[] = $this->_addModLink($key);
						}
					}
					else if ( !empty($moderator[ $key ]) )
					{
						$mod_links[] = $this->_addModLink($key);
					}

					// What if member is a mod, but doesn't have these perms as a mod?

					elseif ($key == 'open_topic' or $key == 'close_topic')
					{
						if ($this->memberData['g_open_close_posts'])
						{
							$mod_links[] = $this->_addModLink($key);
						}
					}
				}
				elseif ($key == 'open_topic' or $key == 'close_topic')
				{
					if ($this->memberData['g_open_close_posts'])
					{
						$mod_links[] = $this->_addModLink($key);
					}
				}
			}
		}

		if ($this->memberData['g_access_cp'] == 1)
		{
			$mod_links[] = $this->_addModLink('topic_history');
		}

		return $mod_links;
	}

	/**
	 * Append mod links
	 *
	 * @param	string	$key
	 * @return	array 	Options
	 */
	public function _addModLink( $key="" )
	{
		/* Init */
		$topicData = $this->registry->getClass('topics')->getTopicData();
		$forumData = $this->forumClass->getForumById( $topicData['forum_id'] );

		if ($key == "") return "";

		if ($topicData['state'] == 'open'   and $key == 'open_topic') return "";
		if ($topicData['state'] == 'closed' and $key == 'close_topic') return "";
		if ($topicData['state'] == 'moved'  and ($key == 'close_topic' or $key == 'move_topic')) return "";
		if ($topicData['pinned'] == 1 and $key == 'pin_topic')   return "";
		if ($topicData['pinned'] == 0 and $key == 'unpin_topic') return "";
		if ($topicData['approved'] != -1 and $key == 'unhide_topic' ) return "";
		if ($topicData['approved'] == -1 and $key == 'hide_topic' ) return "";

		return array( 'option' => $this->mod_action[ strtoupper($key) ],
					  'value'  => $this->lang->words[ strtoupper($key) ] );
	}

	/**
	 * 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'] )
						or
						$this->memberData['forumsModeratorData'][ $forumData['id'] ]['split_merge']
					)
				)
			)
			{
				$row['moddable'] = TRUE;
			}

			/* Add to array */
			$row['member_id']     = $row['mid'];
			$posts[ $row['pid'] ] = $row;
		}

		/* Return */
		return $posts;
	}

	/**
	 * Returns the data for the best answer
	 * @param array $postData
	 */
	protected function _getBestAnswerFeature( array $postData, $topicData )
	{
		if ( $this->registry->class_forums->answerTopicsEnabled( $topicData['forum_id'] ) !== true )
		{
			return false;
		}

		if ( empty( $topicData['topic_answered_pid'] ) )
		{
			return false;
		}

		if ( in_array( $topicData['topic_answered_pid'], array_keys( $postData ) ) )
		{
			$postData[ $topicData['topic_answered_pid'] ]['post']['post'] = IPSText::stripAttachTag( $postData[ $topicData['topic_answered_pid'] ]['post']['post'] );

			return $postData[ $topicData['topic_answered_pid'] ];
		}
		else
		{
			$result	= $this->registry->topics->parsePost( $this->registry->topics->getPostById( $topicData['topic_answered_pid'] ) );

			/* Hasn't been deleted has it? */
			if ( ! $result['post']['pid'] )
			{
				$result	= array();
			}

			$result[ $topicData['topic_answered_pid'] ]['post']['post'] = IPSText::stripAttachTag( $result[ $topicData['topic_answered_pid'] ]['post']['post'] );

			return $result;
		}
	}

	/**
	 * Topic set up ya'll
	 *
	 * @return	@e void
	 */
	public function topicSetUp( $topicData )
	{
		/* Init */
		$topicData      = ( $topicData['tid'] ) ? $topicData : $this->registry->getClass('topics')->getTopicData();
		$forumData      = $this->forumClass->getForumById( $topicData['forum_id'] );
		$permissionData = $this->registry->getClass('topics')->getPermissionData();

		//-----------------------------------------
		// Memory...
		//-----------------------------------------

		$_before = IPSDebug::getMemoryDebugFlag();

		//-----------------------------------------
		// INIT
		//-----------------------------------------

		$this->request['start']	= ! empty( $this->request['start'] )	? intval( $this->request['start'] )	: '';
		$this->request['page']	= ! empty( $this->request['page'] )		? intval( $this->request['page'] )	: '';

		$this->settings['post_order_column'] = ( $this->settings['post_order_column'] != 'post_date' ) ? 'pid' : 'post_date';
		$this->settings['post_order_sort']   = ( $this->settings['post_order_sort']   != 'desc' )      ? 'asc' : 'desc';
		$this->settings['au_cutoff']         = ( empty( $this->settings['au_cutoff'] ) ) ? 15 : $this->settings['au_cutoff'];

		//-----------------------------------------
		// Compile the language file
		//-----------------------------------------

		$this->registry->class_localization->loadLanguageFile( array( 'public_boards', 'public_topic' ) );
		$this->registry->class_localization->loadLanguageFile( array( 'public_editors' ), 'core' );

		//-----------------------------------------
 		// Get all the member groups and
 		// member title info
 		//-----------------------------------------

		if ( ! is_array( $this->cache->getCache('ranks') ) )
		{
			$this->cache->rebuildCache( 'ranks', 'global' );
		}

		//-----------------------------------------
		// Are we actually a moderator for this forum?
		//-----------------------------------------

		if ( ! $this->memberData['g_is_supmod'] )
		{
			$moderator = $this->memberData['forumsModeratorData'];

			if ( !isset($moderator[ $forumData['id'] ]) OR !is_array( $moderator[ $forumData['id'] ] ) )
			{
				$this->memberData['is_mod'] = 0;
			}
		}

		$this->settings['_base_url'] = $this->settings['base_url'];
		$this->first				 = $this->registry->getClass('topics')->pageToSt( $this->request['page'] );
		$this->request['view']	     = ! empty( $this->request['view'] ) ? $this->request['view'] : NULL ;

		//-----------------------------------------
		// Check viewing permissions, private forums,
		// password forums, etc
		//-----------------------------------------

		if ( ( ! $this->memberData['g_other_topics'] ) AND ( $topicData['starter_id'] != $this->memberData['member_id'] ) )
		{
			$this->registry->output->showError( 'topics_not_yours', 10359, null, null, 403 );
		}
		else if( (!$forumData['can_view_others'] AND !$this->memberData['is_mod'] ) AND ( $topicData['starter_id'] != $this->memberData['member_id'] ) )
		{
			$this->registry->output->showError( 'topics_not_yours2', 10360, null, null, 403 );
		}
		else if( $forumData['redirect_on'] AND $forumData['redirect_url'] )
		{
			$this->registry->output->silentRedirect( $forumData['redirect_url'] );
		}

		//-----------------------------------------
		// Update the topic views counter
		//-----------------------------------------

		if ( ! $this->request['view'] AND $topicData['state'] != 'link' )
		{
			if ( $this->settings['update_topic_views_immediately'] )
			{
				$this->DB->update( 'topics', 'views=views+1', "tid=".$topicData['tid'], true, true );
			}
			else
			{
				$this->DB->insert( 'topic_views', array( 'views_tid' => $topicData['tid'] ), true );
			}
		}

		//-----------------------------------------
		// Need to update this topic?
		//-----------------------------------------

		if ( $topicData['state'] == 'open' )
		{
			if( !$topicData['topic_open_time'] OR $topicData['topic_open_time'] < $topicData['topic_close_time'] )
			{
				if ( $topicData['topic_close_time'] AND ( $topicData['topic_close_time'] <= time() AND ( time() >= $topicData['topic_open_time'] OR !$topicData['topic_open_time'] ) ) )
				{
					$topicData['state'] = 'closed';

					$this->DB->update( 'topics', array( 'state' => 'closed' ), 'tid='.$topicData['tid'], true );
				}
			}
			else if( $topicData['topic_open_time'] OR $topicData['topic_open_time'] > $topicData['topic_close_time'] )
			{
				if ( $topicData['topic_close_time'] AND ( $topicData['topic_close_time'] <= time() AND time() <= $topicData['topic_open_time'] ) )
				{
					$topicData['state'] = 'closed';

					$this->DB->update( 'topics', array( 'state' => 'closed' ), 'tid='.$topicData['tid'], true );
				}
			}
		}
		else if ( $topicData['state'] == 'closed' )
		{
			if( !$topicData['topic_close_time'] OR $topicData['topic_close_time'] < $topicData['topic_open_time'] )
			{
				if ( $topicData['topic_open_time'] AND ( $topicData['topic_open_time'] <= time() AND ( time() >= $topicData['topic_close_time'] OR !$topicData['topic_close_time'] ) ) )
				{
					$topicData['state'] = 'open';

					$this->DB->update( 'topics', array( 'state' => 'open' ), 'tid='.$topicData['tid'], true );
				}
			}
			else if( $topicData['topic_close_time'] OR $topicData['topic_close_time'] > $topicData['topic_open_time'] )
			{

				if ( $topicData['topic_open_time'] AND ( $topicData['topic_open_time'] <= time() AND time() <= $topicData['topic_close_time'] ) )
				{
					$topicData['state'] = 'open';

					$this->DB->update( 'topics', array( 'state' => 'open' ), 'tid='.$topicData['tid'], true );
				}
			}
		}

		//-----------------------------------------
		// Current topic rating value
		//-----------------------------------------

		$topicData['_rate_show']  = 0;
		$topicData['_rate_int']   = 0;
		$topicData['_rate_img']   = '';

		if ( $topicData['state'] != 'open' )
		{
			$topicData['_allow_rate'] = 0;
		}
		else
		{
			$topicData['_allow_rate'] = $this->can_rate;
		}

		if ( $forumData['forum_allow_rating'] )
		{
			$rating = $this->DB->buildAndFetch( array( 'select' => '*', 'from' => 'topic_ratings', 'where' => "rating_tid={$topicData['tid']} and rating_member_id=".$this->memberData['member_id'] ) );

			if ( $rating['rating_value'] AND $this->memberData['g_topic_rate_setting'] != 2 )
			{
				$topicData['_allow_rate'] = 0;
			}

			$topicData['_rate_id']	   = 0;
			$topicData['_rating_value']  = $rating['rating_value'] ? $rating['rating_value'] : -1;

			if ( $topicData['topic_rating_total'] )
			{
				$topicData['_rate_int'] = round( $topicData['topic_rating_total'] / $topicData['topic_rating_hits'] );
			}

			//-----------------------------------------
			// Show image?
			//-----------------------------------------

			if ( ( $topicData['topic_rating_hits'] >= $this->settings['topic_rating_needed'] ) AND ( $topicData['_rate_int'] ) )
			{
				$topicData['_rate_id']   = $topicData['_rate_int'];
				$topicData['_rate_show'] = 1;
			}
		}
		else
		{
			$topicData['_allow_rate'] = 0;
		}

		//-----------------------------------------
		// If this forum is a link, then
		// redirect them to the new location
		//-----------------------------------------

		if ( $topicData['state'] == 'link' AND $topicData['moved_to'] )
		{
			$f_stuff	= explode("&", $topicData['moved_to']);
			$_topic		= $this->DB->buildAndFetch( array( 'select' => 'title_seo', 'from' => 'topics', 'where' => 'tid=' . $f_stuff[0] ) );

			/**
			 * Mark redirect links as read too
			 *
			 * @link	http://community.invisionpower.com/tracker/issue-36985-linked-topics-readunread-status/
			 */
			$this->registry->getClass('classItemMarking')->markRead( array( 'forumID' => $forumData['id'], 'itemID' => $topicData['tid'] ), 'forums' );

			$this->registry->output->silentRedirect( $this->settings['base_url'] . "showtopic={$f_stuff[0]}", $_topic['title_seo'], true, 'showtopic' );
		}

		//-----------------------------------------
		// If this is a sub forum, we need to get
		// the cat details, and parent details
		//-----------------------------------------

	   	$this->nav = $this->registry->class_forums->forumsBreadcrumbNav( $forumData['id'] );

		//-----------------------------------------
		// Hi! Light?
		//-----------------------------------------

		$hl = !empty( $this->request['hl'] ) ? '&hl=' . $this->request['hl'] : '';

		//-----------------------------------------
		// If we can see queued topics, add count
		//-----------------------------------------

		if ( $this->registry->class_forums->canQueuePosts($forumData['id']) )
		{
			if( isset( $this->request['modfilter'] ) AND $this->request['modfilter'] == 'invisible_posts' )
			{
				$topicData['posts'] = intval( $topicData['topic_queuedposts'] );
			}
			else
			{
				$topicData['posts'] += intval( $topicData['topic_queuedposts'] );
			}
		}

		if ( $permissionData['softDeleteSee'] AND $topicData['topic_deleted_posts'] )
		{
			$topicData['posts'] += intval( $topicData['topic_deleted_posts'] );
		}

		//-----------------------------------------
		// Generate the forum page span links
		//-----------------------------------------

		if( $this->request['modfilter'] )
		{
			$hl	.= "&modfilter=" . $this->request['modfilter'];
		}

		$topicData['SHOW_PAGES']
			= $this->registry->output->generatePagination( array(   'totalItems'		=> ($topicData['posts']+1),
																	'itemsPerPage'		=> $this->settings['display_max_posts'],
																	'currentPage'	    => intval( $this->request['page'] ),
																	'seoTitle'			=> $topicData['title_seo'],
																	'realTitle'			=> $topicData['title'],
																	'isPagesMode'		=> true,
																	'seoTemplate'		=> 'showtopic',
 																	'baseUrl'			=> "showtopic=".$topicData['tid'].$hl ) );

		//-----------------------------------------
		// Fix up some of the words
		//-----------------------------------------

		$topicData['TOPIC_START_DATE'] = $this->registry->class_localization->getDate( $topicData['start_date'], 'LONG' );

		$this->lang->words['topic_stats'] = str_replace( "<#START#>", $topicData['TOPIC_START_DATE'], $this->lang->words['topic_stats']);
		$this->lang->words['topic_stats'] = str_replace( "<#POSTS#>", $topicData['posts']		   , $this->lang->words['topic_stats']);

		//-----------------------------------------
		// Multi Quoting?
		//-----------------------------------------

		$this->qpids = IPSCookie::get('mqtids');

		//-----------------------------------------
		// Multi PIDS?
		//-----------------------------------------

		$this->request['selectedpids'] = ! empty( $this->request['selectedpids'] ) ? $this->request['selectedpids'] : IPSCookie::get('modpids');
		$this->request['selectedpidcount'] = 0 ;

		IPSCookie::set('modpids', '', 0);

		IPSDebug::setMemoryDebugFlag( "TOPIC: topics.php::topicSetUp", $_before );

		return $topicData;
	}
}


text:
module XMPP ( -- * The XMPP monad
              module XMPPMonad
              -- * XML functions
            , XMLElem(..)
            , xmlPath
            , getAttr
            , getCdata
            , xmlToString
              -- * Stanza manipulation
            , module Stanzas
              -- * JID functions
            , module JID
              -- * Authentication
            , module Auth
              -- * TCP connections
            , module TCPConnection
              -- * Abstract connections
            , module XMPPConnection
            )
    where

import Auth
import JID
import Stanzas
import TCPConnection
import XMLParse
import XMPPConnection hiding ( sendStanza )
import XMPPMonad


text:
package nl.esciencecenter.xenon;

import org.junit.internal.AssumptionViolatedException;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class XenonTestWatcher extends TestWatcher {
    private static final Logger logger = LoggerFactory.getLogger(XenonTestWatcher.class);

    @Override
    public void starting(Description description) {
        logger.info("Running test {}", description.getMethodName());
    }

    @Override
    public void failed(Throwable reason, Description description) {
        logger.info("Test {} failed due to exception", description.getMethodName(), reason);
    }

    @Override
    public void succeeded(Description description) {
        logger.info("Test {} succeeded", description.getMethodName());
    }

    @Override
    public void skipped(AssumptionViolatedException reason, Description description) {
        logger.info("Test {} skipped due to failed assumption", description.getMethodName(), reason);
    }
}


text:
<?php

/****************
 *		Log		*
 ****************/
require_once('Gen/Log.php');
Gen_Log::$_debug = APP_DEBUG;
Gen_Log::log('Initialization', 'init.php');

/***************************
 *     PDO / Dao config    *
 ***************************/
require_once('Gen/Dao/Abstract.php');
Gen_Dao_Abstract::config(DB_DRIVER, DB_HOST, DB_NAME, DB_USER, DB_PASSWORD);

/********************
 *		I18n		*
 ********************/
require_once('Gen/I18n.php');
Gen_I18n::$_path = LOCALE_DIR;
Gen_I18n::setLocale(APP_DEFAULT_LANG);

/***************************
 * Front Controller config *
 ***************************/
require_once ('Gen/Controller/Front.php');
$frontController = Gen_Controller_Front::getInstance();

Gen_Controller_Front::$env = APP_ENV;
Gen_Controller_Front::$debug = APP_DEBUG;
Gen_Controller_Front::$appName = APP_NAME;
Gen_Controller_Front::$appMail = APP_MAIL;
Gen_Controller_Front::$controllerDir = APP_CONTROLLER_DIR;
Gen_Controller_Front::setViewDir(APP_VIEW_DIR);

/***************************
 *      Router config      *
 ***************************/
include(APP_DIR . 'router.php');
$r->setBaseUrl(BASE_URL);
$r->setServerName(SERVER_NAME);
$frontController->setRouter($r);

/************************
 *		Acl config		*
 ************************/
include(APP_DIR . 'acl.php');
$frontController->setAcl($a);

/****************************
 *		Observer config		*
 ****************************/
require_once ('Gen/Controller/Event/Dispatcher.php');
Gen_Controller_Event_Dispatcher::$observerDir = APP_CONTROLLER_DIR;
include(APP_DIR. 'event_dispatcher.php');
$frontController->setEventDispatcher($e);


text:
/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.addthis.hydra.job.spawn;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import com.addthis.hydra.job.mq.HostState;

import org.apache.curator.framework.CuratorFramework;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static com.addthis.hydra.job.store.SpawnDataStoreKeys.MINION_DEAD_PATH;
import static com.addthis.hydra.job.store.SpawnDataStoreKeys.MINION_UP_PATH;

public class HostManager {
    private static final Logger log = LoggerFactory.getLogger(HostManager.class);

    @Nonnull final ConcurrentMap<String, HostState> monitored;
    @Nonnull final SetMembershipListener minionMembers;
    @Nonnull final SetMembershipListener deadMinionMembers;

    public HostManager(CuratorFramework zkClient) {
        this.monitored = new ConcurrentHashMap<>();
        this.minionMembers = new SetMembershipListener(zkClient, MINION_UP_PATH);
        this.deadMinionMembers = new SetMembershipListener(zkClient, MINION_DEAD_PATH);
    }

    public HostState getHostState(String hostUuid) {
        if (hostUuid == null) {
            return null;
        }
        synchronized (monitored) {
            return monitored.get(hostUuid);
        }
    }

    public void updateHostState(HostState state) {
        synchronized (monitored) {
            if (!deadMinionMembers.getMemberSet().contains(state.getHostUuid())) {
                log.debug("Updating host state for : {}", state.getHost());
                monitored.put(state.getHostUuid(), state);
            }
        }
    }

    /**
     * List all hosts belonging to a particular minion type.
     *
     * @param minionType The minion type to find. If null, return all hosts.
     * @return A list of hoststates
     */
    public List<HostState> listHostStatus(@Nullable String minionType) {
        synchronized (monitored) {
            Set<String> availableMinions = minionMembers.getMemberSet();
            Set<String> deadMinions = deadMinionMembers.getMemberSet();
            List<HostState> allMinions = new ArrayList<>();
            for (HostState minion : monitored.values()) {
                if (availableMinions.contains(minion.getHostUuid()) && !deadMinions.contains(minion.getHostUuid())) {
                    minion.setUp(true);
                } else {
                    minion.setUp(false);
                }
                if ((minionType == null) || minion.hasType(minionType)) {
                    allMinions.add(minion);
                }
            }
            return allMinions;
        }
    }

    public List<HostState> getLiveHosts(@Nullable String minionType) {
        List<HostState> allHosts = listHostStatus(minionType);
        List<HostState> rv = new ArrayList<>(allHosts.size());
        for (HostState host : allHosts) {
            if (host.isUp() && !host.isDead()) {
                rv.add(host);
            }
        }
        return rv;
    }
}


text:
//
//  MyStructs.h
//  SPH
//
//  Created by Sam Hunter on 03/11/2014.
//  Copyright (c) 2014 Sam Hunter. All rights reserved.
//

#ifndef __SPH__MyStructs__
#define __SPH__MyStructs__

#include <iostream>
#include <array>

struct infoModule{

    std::array<double, 6> domain;
    double deltax;
    double h;
    double rho0;
    double cs;
    double x;
    double y;

    double simTime;
    double finishTime;
    double deltat;
    double timeCounter;
    double outputTime;

    int nDim;
    int nWallPar;
    int neighbourRefresh; // how often the loop will use the recursive search before the brute force
    int fileN;
    int iterationN;
    int finishIteration;
    int outputIteration;

};

#endif /* defined(__SPH__MyStructs__) */


text:
<?xml version="1.0" encoding="UTF-8"?>
<eventPublisher name="SampleEventPublisher" statistics="disable" trace="disable"
               xmlns="http://wso2.org/carbon/eventpublisher">
    <from streamName="delayedFlightStream" version="1.0.0"/>
    <mapping type="text" customMapping="enable">
        <inline>Delayed Flight Details

            Flight Name : {{flightName}}
            Flight No : {{flightId}}
            Flight Type : {{flightType}}
            Flight Arrival Time : {{arrivalTime}}
            Track No : {{trackNo}}
        </inline>
    </mapping>
    <to eventAdapterType="logger">
        <property name="uniqueId">WarnMessage</property>
    </to>
</eventPublisher>


text:
/**
 *
 */
package org.openntf.domino.ext;

/**
 * OpenNTF extensiosn to outlineEntry class
 *
 * @author withersp
 *
 */
public interface OutlineEntry {

}


text:
"""
Illustrates three strategies for persisting and querying XML
documents as represented by ElementTree in a relational
database. The techniques do not apply any mappings to the
ElementTree objects directly, so are compatible with the
native cElementTree as well as lxml, and can be adapted to
suit any kind of DOM representation system. Querying along
xpath-like strings is illustrated as well.

E.g.::

    # parse an XML file and persist in the database
    doc = ElementTree.parse("test.xml")
    session.add(Document(file, doc))
    session.commit()

    # locate documents with a certain path/attribute structure
    for document in find_document('/somefile/header/field2[@attr=foo]'):
        # dump the XML
        print document

.. autosource::
    :files: pickle.py, adjacency_list.py, optimized_al.py

"""


text:
require "spec_helper"

describe ScopedSearch::Definition do

  before(:each) do
    @klass      = mock_activerecord_class
    @definition = ScopedSearch::Definition.new(@klass)
    @definition.stub(:setup_adapter)
  end

  describe ScopedSearch::Definition::Field do
    describe '#column' do
      it "should raise an exception when using an unknown field" do
        lambda {
          @definition.define(:on => 'nonexisting').column
        }.should raise_error(ActiveRecord::UnknownAttributeError)
      end

      it "should not raise an exception when using an unknown field" do
        lambda {
          @definition.define(:on => 'existing').column
        }.should_not raise_error
      end
    end
  end

  describe '#initialize' do
    it "should create the named scope when" do
      @klass.should_receive(:scope).with(:search_for, instance_of(Proc))
      ScopedSearch::Definition.new(@klass)
    end

    it "should not create the named scope if it already exists" do
      @klass.stub(:search_for)
      @klass.should_not_receive(:scope)
      ScopedSearch::Definition.new(@klass)
    end
  end
end


text:
package com.horn.common.cache;

import javax.inject.Inject;
import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;

/**
 * @author LesinSA
 */
@Cached
@Interceptor
public class CacheInterceptor {

    @Inject
    private CDICacheLocator cacheLocator;
    private CacheIntermediator intermediator;

    @AroundInvoke
    public Object aroundInvoke(InvocationContext ctx) throws Exception {
        return getIntermediator().proceed(ctx.getMethod(), ctx::proceed, ctx.getParameters());
    }

    private CacheIntermediator getIntermediator() {
        if (intermediator == null) {
            intermediator = new CacheIntermediator(cacheLocator);
        }
        return intermediator;
    }

}


text:
ActiveRecord::Schema.define(version: 20150816132327) do

  # These are extensions that must be enabled in order to support this database
  enable_extension "plpgsql"

  create_table "users", force: :cascade do |t|
    t.string   "provider",               default: "email", null: false
    t.string   "uid",                    default: "",      null: false
    t.string   "encrypted_password",     default: "",      null: false
    t.string   "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.integer  "sign_in_count",          default: 0,       null: false
    t.datetime "current_sign_in_at"
    t.datetime "last_sign_in_at"
    t.string   "current_sign_in_ip"
    t.string   "last_sign_in_ip"
    t.string   "confirmation_token"
    t.datetime "confirmed_at"
    t.datetime "confirmation_sent_at"
    t.string   "unconfirmed_email"
    t.string   "name"
    t.string   "last_name"
    t.string   "email"
    t.json     "tokens"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree
  add_index "users", ["email"], name: "index_users_on_email", using: :btree
  add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
  add_index "users", ["uid", "provider"], name: "index_users_on_uid_and_provider", unique: true, using: :btree

end


text:
package <%= appPackage %>.statistics;

import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import <%= appPackage %>.TestUseCaseScheduler;
import <%= appPackage %>.UseCaseHandler;
import <%= appPackage %>.tasks.domain.model.Task;
import <%= appPackage %>.data.source.TasksDataSource;
import <%= appPackage %>.data.source.TasksRepository;
import <%= appPackage %>.statistics.domain.usecase.GetStatistics;
import com.google.common.collect.Lists;

import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.util.List;

/**
 * Unit tests for the implementation of {@link StatisticsPresenter}
 */
public class StatisticsPresenterTest {

    private static List<Task> TASKS;

    @Mock
    private TasksRepository mTasksRepository;

    @Mock
    private StatisticsContract.View mStatisticsView;

    /**
     * {@link ArgumentCaptor} is a powerful Mockito API to capture argument values and use them to
     * perform further actions or assertions on them.
     */
    @Captor
    private ArgumentCaptor<TasksDataSource.LoadTasksCallback> mLoadTasksCallbackCaptor;

    private StatisticsPresenter mStatisticsPresenter;

    @Before
    public void setupStatisticsPresenter() {
        // Mockito has a very convenient way to inject mocks by using the @Mock annotation. To
        // inject the mocks in the test the initMocks method needs to be called.
        MockitoAnnotations.initMocks(this);

        // Get a reference to the class under test
        mStatisticsPresenter = givenStatisticsPresenter();

        // The presenter won't update the view unless it's active.
        when(mStatisticsView.isActive()).thenReturn(true);

        // We start the tasks to 3, with one active and two completed
        TASKS = Lists.newArrayList(new Task("Title1", "Description1"),
                new Task("Title2", "Description2", true), new Task("Title3", "Description3", true));
    }

    @Test
    public void loadEmptyTasksFromRepository_CallViewToDisplay() {
        // Given an initialized StatisticsPresenter with no tasks
        TASKS.clear();

        // When loading of Tasks is requested
        mStatisticsPresenter.start();

        //Then progress indicator is shown
        verify(mStatisticsView).setProgressIndicator(true);

        // Callback is captured and invoked with stubbed tasks
        verify(mTasksRepository).getTasks(mLoadTasksCallbackCaptor.capture());
        mLoadTasksCallbackCaptor.getValue().onTasksLoaded(TASKS);

        // Then progress indicator is hidden and correct data is passed on to the view
        verify(mStatisticsView).setProgressIndicator(false);
        verify(mStatisticsView).showStatistics(0, 0);
    }

    @Test
    public void loadNonEmptyTasksFromRepository_CallViewToDisplay() {
        // Given an initialized StatisticsPresenter with 1 active and 2 completed tasks

        // When loading of Tasks is requested
        mStatisticsPresenter.start();

        //Then progress indicator is shown
        verify(mStatisticsView).setProgressIndicator(true);

        // Callback is captured and invoked with stubbed tasks
        verify(mTasksRepository).getTasks(mLoadTasksCallbackCaptor.capture());
        mLoadTasksCallbackCaptor.getValue().onTasksLoaded(TASKS);

        // Then progress indicator is hidden and correct data is passed on to the view
        verify(mStatisticsView).setProgressIndicator(false);
        verify(mStatisticsView).showStatistics(1, 2);
    }

    @Test
    public void loadStatisticsWhenTasksAreUnavailable_CallErrorToDisplay() {
        // When statistics are loaded
        mStatisticsPresenter.start();

        // And tasks data isn't available
        verify(mTasksRepository).getTasks(mLoadTasksCallbackCaptor.capture());
        mLoadTasksCallbackCaptor.getValue().onDataNotAvailable();

        // Then an error message is shown
        verify(mStatisticsView).showLoadingStatisticsError();
    }

    private StatisticsPresenter givenStatisticsPresenter() {
        UseCaseHandler useCaseHandler = new UseCaseHandler(new TestUseCaseScheduler());
        GetStatistics getStatistics = new GetStatistics(mTasksRepository);

        return new StatisticsPresenter(useCaseHandler, mStatisticsView, getStatistics);
    }
}


text:
/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#ifndef __ASM_ARCH_MXC_BOARD_QONG_H__
#define __ASM_ARCH_MXC_BOARD_QONG_H__

/* NOR FLASH */
#define QONG_NOR_SIZE		(128*1024*1024)

#endif /* __ASM_ARCH_MXC_BOARD_QONG_H__ */


text:
import {Component, OnInit} from '@angular/core';
import {HeroService} from './hero.service';
import {Hero} from './hero';
import { Router } from '@angular/router';

@Component({
    selector: 'my-dashboard',
    templateUrl: 'app/dashboard.component.html',
    styleUrls:['app/dashboard.component.css']
})

export class DashboardComponent implements OnInit {
    heroes: Hero[] = [];

    constructor(private heroService:HeroService, private router:Router){

    }

    ngOnInit(): void{
        this.heroService.getHeroes().then(heroes => this.heroes = heroes.slice(1,5));
    }

    gotoDetail(hero:Hero):void{
        let link = ['/detail', hero.id];
        this.router.navigate(link);
    }
}


text:
"""Encrypt PDF paranoia

Using :func:`os.walk`, write a script that will go through every PDF
in a folder (and its subfolders) and encrypt the PDFs using a password provided
on the command line. Save each encrypted PDF with an _encrypted.pdf suffix added
to the original filename.

Before deleting the original file, have the program attempt to read and decrypt the
file to ensure that it was encrypted correctly.

Notes:
    * Default folder is parent directory.
    * Default suffix is '_encrypted.pdf'.
    * Running in debug mode, uncomment to delete original file.

"""

def main():
    import PyPDF4, os
    from PyPDF4.utils import PdfReadError

    FOLDER = "../"
    SUFFIX = "_encrypted.pdf"

    # Get all PDF files in FOLDER
    files = []
    for folderName, subfolders, filenames in os.walk(FOLDER):
        for filename in filenames:
            # If file is in subdirectory, append backslash to folderName
            if folderName.endswith('/'):
                filepath = folderName + filename
            else:
                filepath = folderName + '/' + filename

            if filename.lower().endswith(".pdf") and not PyPDF4.PdfFileReader(open(filepath, "rb")).isEncrypted:
                files.append(filepath)

    # Get password from user
    password = input("Please input encryption password:\n")

    # Encrypt list of PDF files with password
    for file in files:
        pdfFile = open(file, "rb")
        pdfReader = PyPDF4.PdfFileReader(pdfFile)
        pdfWriter = PyPDF4.PdfFileWriter()
        for pageNum in range(pdfReader.numPages):
            pdfWriter.addPage(pdfReader.getPage(pageNum))

        pdfWriter.encrypt(password)

        # Append SUFFIX when saving encrypted file
        newfile = file[:-4] + SUFFIX
        resultPdf = open(newfile, "wb")
        pdfWriter.write(resultPdf)
        resultPdf.close()

        # Attempt to read and decrypt encrypted file
        pdfReader = PyPDF4.PdfFileReader(open(newfile, "rb"))
        pdfReader.decrypt(password)
        # If the first page cannot be read, print error and move to next file
        try:
            pdfReader.getPage(0)
        except PdfReadError as err:
            print("PdfReadError: %s" % err)
            print("Skipping: %s" % file)
            continue

        # Delete original file
        print("Deleting: %s" % file)  # DEBUG
        #os.remove(file)  # uncomment if sure

if __name__ == '__main__':
    main()


text:
require File.dirname(__FILE__) + '/../spec_helper'

describe Conversation do

  before(:each) do
    @conversation = conversations(:one)
  end

  it "should have many messages" do
    @conversation.should respond_to(:messages)
  end

  it "should order messages by most recent first" do
    sorted_messages = @conversation.messages.sort_by(&:created_at)
    @conversation.messages.should == sorted_messages
  end
end


text:
require "basic_support"
require "active_support/all"


text:
date: 2015-01-13
layout: post
title: Authy Window Size
tags:
- chrome
- extension
- authy
---

I use [Authy](https://chrome.google.com/webstore/detail/authy/gaedmjdfmmahhbjefcbgaolhhanlaolb) for my google authenticator code generation. I like the desktop chrome app and extension, but the popup window is too small and I usually have to scroll it.

I found all the places you have to change to make the window taller.

Open [chrome://extensions/](chrome://extensions/) and find the authy extension and look for the `ID:`. It's a 32 character string. Now you need to go to the extension's directory. Note: my authy is installed in my default chrome profile (also know as People), you might need to replace `Default` with `Profile\ 1` or something.

```bash
cd ~/Library/Application Support/Google/Chrome/Default/Extensions/abcdefghijklmnopqrstuvwxyzabcdefg/1.0.7_0
ADD=410; \
perl -p -i~ -e "s/:(590)/':' . (\$1 + $ADD)/ge" js/background.js js/app.js; \
perl -p -i~ -e "s/(max-height:)(544)(px;)/\$1 . (\$2 + $ADD) . \$3/ge" css/app.css
```

Now hit cmd-r on the chrome extensions page and click the authy button again (authy must be closed).

A height of 1000 (adding 410 pixels to each) worked great for 12 accounts.

If you want to go back to how it was, this should do it. Then you can use your command history to go back and edit the ADD variable.

```bash
for f in js/app.js js/background.js css/app.css; do \mv -fv ${f}~ ${f}; done
```

You'll know when authy gets updated because this'll break and you'll have to go do it again. You _could_ disable updates by messing with the update_url in manifest.json if you like. I'd rather get the update and apply this fix again.

Sorry, I got a bit wanky with the command lines there...