Skip to content

Commit

Permalink
enable pinkes and notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
daleharvey committed Jun 18, 2012
1 parent d866281 commit 18c0bcc
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 60 deletions.
105 changes: 55 additions & 50 deletions application/controllers/thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,31 @@ function Thread()

// if the just throw in /thread into the address bar
// throw them home
function index()
{
function index() {
redirect('/');
}

function load($thread_id)
{
$segments = $this->uri->segment_array();
$segments = $this->uri->segment_array();

while($seg = next($segments))
$page = $seg == 'p' ? (int) next($segments) : 0;

while($seg = next($segments))
$page = $seg == 'p' ? (int) next($segments) : 0;
$thread = $this->thread_model->get_thread($thread_id, $this->meta, $page);

$thread = $this->thread_model->get_thread($thread_id, $this->meta, $page);

$uri = '/thread/'. $thread_id .'/'. url_title($thread->information->subject, 'dash', TRUE);
$uri = '/thread/'. $thread_id .'/'.
url_title($thread->information->subject, 'dash', TRUE);

// if they roll in with something unexpected
// or the thread doesnt exist
// or the thread doesnt exist
// send them home
if ($thread == null)
redirect('/');
// if the thread is closed then we're not accepting any new data
if (!$thread->information->closed || $thread->information->author_acquaintance_type == 2)
{

// if the thread is closed then we're not accepting any new data
if (!$thread->information->closed ||
$thread->information->author_acquaintance_type == 2) {
// we're going to go ahead and do the form processing for the reply now
// if they're submitting data, we're going to refresh the page anyways
// so theres no point in running the query below the form validation
Expand All @@ -50,7 +50,7 @@ function load($thread_id)

$content = $this->form_validation->set_value('content');
$ajax = $this->form_validation->set_value('ajax');

$this->thread_model->new_comment((object) array(
'thread_id' => $thread_id,
'user_id' => $this->meta['user_id'],
Expand All @@ -62,11 +62,12 @@ function load($thread_id)

$shown = $this->meta['comments_shown'];

$last_page = (ceil(($thread->information->comment_count + 1) / $this->meta['comments_shown'])
* $this->meta['comments_shown']) - $this->meta['comments_shown'];

$redirection = $uri .'/p/'. $last_page .'#bottom';

$last_page = (ceil(($thread->information->comment_count + 1) /
$this->meta['comments_shown'])
* $this->meta['comments_shown']) - $this->meta['comments_shown'];

$redirection = $uri .'/p/'. $last_page .'#bottom';

if ($ajax) {
return send_json($this->output, 201, array('ok' => true, 'url' => $redirection));
} else {
Expand All @@ -75,37 +76,41 @@ function load($thread_id)
}
}

$this->pagination->initialize(array(
'num_links' => 3,
'base_url' => $uri .= '/p/',
'total_rows' => $thread->information->comment_count,
'uri_segment' => 5,
'per_page' => $this->meta['comments_shown'],
'full_tag_open' => '<div class="main-pagination">',
'full_tag_close' => '</div>',
'cur_tag_open' => '<div class="selected-page">',
'cur_tag_close' => '</div>',
'num_tag_open' => '',
'num_tag_close' => ''
));

$uri .= isset($uri_assoc['p']) ? (int) $uri_assoc['p'] : 0;

$thread->pagination = (object) array(
'links' => $this->pagination->create_links(),
'lower_limit' => $page + 1,
'upper_limit' => min(array($page + $this->meta['comments_shown'], $thread->information->comment_count)),
'category' => '<a href="/f/'. strtolower($thread->information->category) .'">'. $thread->information->category .'</a>',
'thread' => '<a href="/thread/'. $thread_id .'/'. url_title($thread->information->subject, 'dash', TRUE) .'">'. $thread->information->subject .'</a>'
);

$thread->information->page = $page;

$this->load->helper('content_render');

$this->load->view('shared/header', array('page_title' => $thread->information->subject));
$this->load->view('thread', $thread);
$this->load->view('shared/footer');
$this->pagination->initialize(array(
'num_links' => 3,
'base_url' => $uri .= '/p/',
'total_rows' => $thread->information->comment_count,
'uri_segment' => 5,
'per_page' => $this->meta['comments_shown'],
'full_tag_open' => '<div class="main-pagination">',
'full_tag_close' => '</div>',
'cur_tag_open' => '<div class="selected-page">',
'cur_tag_close' => '</div>',
'num_tag_open' => '',
'num_tag_close' => ''
));

$uri .= isset($uri_assoc['p']) ? (int) $uri_assoc['p'] : 0;

$thread->pagination = (object) array(
'links' => $this->pagination->create_links(),
'lower_limit' => $page + 1,
'upper_limit' => min(array($page + $this->meta['comments_shown'],
$thread->information->comment_count)),
'category' => '<a href="/f/'. strtolower($thread->information->category) .'">'.
$thread->information->category .'</a>',
'thread' => '<a href="/thread/'. $thread_id .'/'.
url_title($thread->information->subject, 'dash', TRUE) .'">'.
$thread->information->subject .'</a>'
);

$thread->information->page = $page;

$this->load->helper('content_render');

$this->load->view('shared/header', array('page_title' => $thread->information->subject));
$this->load->view('thread', $thread);
$this->load->view('shared/footer');
}
}

Expand Down
55 changes: 45 additions & 10 deletions application/views/thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div id="thread">
<div id="main-title"<?=$information->owner && $information->editable ? ' class="changeling"' : '' ?>>
<h3><?=htmlspecialchars($information->subject) ?></h3>

<?php if ($logged_in) { ?>
<a class="favourite<?=$information->favorite ? ' added' : '' ?>" rel="<?=$information->thread_id ?>"></a>
<a class="hide-thread<?=$information->hidden ? ' added' : '' ?>" rel="<?=$information->thread_id ?>"></a>
Expand All @@ -24,14 +24,14 @@

<div class="pagination top">
<?=$pagination->links ?>

<span class="paging-text">
<?=$pagination->lower_limit ?> - <?=$pagination->upper_limit ?> of <?=$information->comment_count ?>
in <a href="/">Threads</a>
&gt; <?=$pagination->category ?>
&gt; <?=$pagination->thread ?>
</span>

<?php if ($information->enemies > 0) { ?>
<div class="toggle-enemy">
<?=$information->enemies ?> ENEMY POST<?=($information->enemies == 1 ? '' : 'S') ?> IGNORED
Expand Down Expand Up @@ -74,10 +74,10 @@
{
if ($this->meta['hide_enemy_posts'] === '1')
continue;

?>
<div id="ignore-for-<?=$row->comment_id ?>" class="ignore-container" onclick="$('#comment-container-<?=$row->comment_id ?>').toggle();"></div>
<?php
<?php
} ?>

<div id="comment-<?=$row->comment_id ?>" class="comment userid-<?=$row->author_id, $row->author_acquaintance_name, ($row->owner ? ' mycomment' : '') ?>">
Expand Down Expand Up @@ -165,7 +165,7 @@

<div class="pagination bottom">
<?=$pagination->links ?>

<span class="paging-text">
<?=$pagination->lower_limit ?> - <?=$pagination->upper_limit ?> of <?=$information->comment_count ?>
in <a href="/">Threads</a>
Expand All @@ -186,7 +186,7 @@

<div class="dotted-bar replypad"></div>
<?php
if (!$logged_in || $information->closed === '1' || $information->author_acquaintance_type === 2)
if (!$logged_in || $information->closed === '1' || $information->author_acquaintance_type === 2)
{
if ($information->closed === '1')
{
Expand Down Expand Up @@ -217,7 +217,6 @@
</div>
<div id="reply-rc">
<div id="pinkies">
<?php /*
<a href="javascript:insertAtCaret('thread-content-input', '[:)]');">
<img src="/img/pinkies/11.gif" /></a>
<a href="javascript:insertAtCaret('thread-content-input', '[:(]');">
Expand Down Expand Up @@ -260,7 +259,6 @@
<img src="/img/pinkies/26.gif" /></a>
<a href="javascript:insertAtCaret('thread-content-input', '[fbm]');">
<img src="/img/pinkies/21.gif" /></a>
*/?>
</div>

<form method="post" action="<?=uri_string() ?>" id="comment-form">
Expand All @@ -270,7 +268,7 @@
'name' => 'content',
'id' => 'thread-content-input',
'value' => set_value('content')
)); ?>
)); ?>
</div>
<p>I, <?=$this->meta['username'] ?>, do solemnly swear that in posting this comment I promise to be nice.</p>
<button type="submit" id="submit-button" tabindex="2">Agree &amp; Post</button>
Expand Down Expand Up @@ -300,5 +298,42 @@
</div>
<?php } ?>

<div id="notifications">
<a id="closenotify"></a>
</div>

<script type="text/javascript">
var originalTitle = document.title,
currentNotification;

function thread_notifier() {
$.ajax({
url: '/ajax/thread_notifier/<?php echo $information->thread_id; ?>/<?php echo $information->comment_count; ?>',
success: function(data)
{
if (data)
{
var text = $(data).text();
document.title = text.replace(" added", "") + " | " + originalTitle;
if (text !== currentNotification)
{
$("#notifier").remove();
currentNotification = text;
$('#notifications').append(data).show();
}
}
}
});
}

$("#closenotify").live("click", function() {
$('#notifications').remove();
clearTimeout(notification);
document.title = originalTitle;
});

var notification = setInterval(thread_notifier, 10000);
</script>

<script type="text/javascript" src="/js/thread.js?v=<?php echo $this->config->item('version'); ?>"></script>
</div>

0 comments on commit 18c0bcc

Please sign in to comment.