2017-06-05 22:29:52 +00:00
< ? php
class Archive {
// Archive thread and replies
static public function archiveThread ( $thread_id ) {
global $config , $board ;
// If archiving is turned off return
if ( ! $config [ 'archive' ][ 'threads' ])
return ;
// Check if it is a thread
2017-07-17 01:30:31 +00:00
$thread_query = prepare ( sprintf ( " SELECT `thread`, `subject`, `body_nomarkup`, `trip` FROM ``posts_%s`` WHERE `id` = :id " , $board [ 'uri' ]));
2017-06-05 22:29:52 +00:00
$thread_query -> bindValue ( ':id' , $thread_id , PDO :: PARAM_INT );
$thread_query -> execute () or error ( db_error ( $thread_query ));
$thread_data = $thread_query -> fetch ( PDO :: FETCH_ASSOC );
if ( $thread_data [ 'thread' ] !== NULL )
error ( $config [ 'error' ][ 'invalidpost' ]);
// Create Snippet of thread text
$thread_data [ 'snippet_body' ] = strtok ( $thread_data [ 'body_nomarkup' ], " \r \n " );
$thread_data [ 'snippet_body' ] = substr ( $thread_data [ 'snippet_body' ], 0 , $config [ 'archive' ][ 'snippet_len' ] - strlen ( $thread_data [ 'subject' ]));
archive_list_markup ( $thread_data [ 'snippet_body' ]);
$thread_data [ 'snippet' ] = '<b>' . $thread_data [ 'subject' ] . '</b> ' ;
$thread_data [ 'snippet' ] .= $thread_data [ 'snippet_body' ];
// Select thread and replies in one query
$query = prepare ( sprintf ( " SELECT `id`,`thread`,`files`,`slug` FROM ``posts_%s`` WHERE `id` = :id OR `thread` = :id " , $board [ 'uri' ]));
$query -> bindValue ( ':id' , $thread_id , PDO :: PARAM_INT );
$query -> execute () or error ( db_error ( $query ));
// List of files associated with thread
$file_list = array ();
while ( $post = $query -> fetch ( PDO :: FETCH_ASSOC )) {
// Copy Static HTML page for Thread
if ( ! $post [ 'thread' ]) {
// Read Content of HTML
$thread_file_content = @ file_get_contents ( $board [ 'dir' ] . $config [ 'dir' ][ 'res' ] . link_for ( $post ));
// Replace links and posting mode to Archived
$thread_file_content = str_replace ( sprintf ( 'src="/' . $config [ 'board_path' ], $board [ 'uri' ]), sprintf ( 'src="/' . $config [ 'board_path' ] . $config [ 'dir' ][ 'archive' ], $board [ 'uri' ]), $thread_file_content );
$thread_file_content = str_replace ( sprintf ( 'href="/' . $config [ 'board_path' ], $board [ 'uri' ]), sprintf ( 'href="/' . $config [ 'board_path' ] . $config [ 'dir' ][ 'archive' ], $board [ 'uri' ]), $thread_file_content );
$thread_file_content = str_replace ( 'Posting mode: Reply' , 'Archived thread' , $thread_file_content );
// Remove Post Form from HTML (First Form)
$thread_file_content = preg_replace ( " /<form name= \" post \" (.*?)< \ /form>/i " , " " , $thread_file_content );
2017-06-11 12:24:11 +00:00
// Refix archive link that will be wrong
$thread_file_content = str_replace ( sprintf ( 'href="/' . $config [ 'board_path' ] . $config [ 'dir' ][ 'archive' ] . $config [ 'dir' ][ 'archive' ], $board [ 'uri' ]), sprintf ( 'href="/' . $config [ 'board_path' ] . $config [ 'dir' ][ 'archive' ], $board [ 'uri' ]), $thread_file_content );
2017-06-05 22:29:52 +00:00
// Remove Form from HTML
$thread_file_content = preg_replace ( " /<form(.*?)>/i " , " " , $thread_file_content );
$thread_file_content = preg_replace ( " /< \ /form>/i " , " " , $thread_file_content );
$thread_file_content = preg_replace ( " /<input (.*?)>/i " , " " , $thread_file_content );
// Remove Redundant code from HTML
$thread_file_content = preg_replace ( " /<div id= \" report \ -fields \" (.*?)< \ /div>/i " , " " , $thread_file_content );
$thread_file_content = preg_replace ( " /<div id= \" thread \ -interactions \" (.*?)< \ /div>/i " , " " , $thread_file_content );
// Write altered thread HTML to archive location
@ file_put_contents ( $board [ 'dir' ] . $config [ 'dir' ][ 'archive' ] . $config [ 'dir' ][ 'res' ] . sprintf ( $config [ 'file_page' ], $thread_id ), $thread_file_content , LOCK_EX );
}
2018-03-22 21:35:15 +00:00
// Copy json file to Archive
// Read Content of Json file
$json_file_content = @ file_get_contents ( $board [ 'dir' ] . $config [ 'dir' ][ 'res' ] . $thread_id . " .json " );
// Replace links and posting mode to Archived
$json_file_content = str_replace ( substr ( $board [ 'dir' ], 0 , - 1 ) . '\/' . substr ( $config [ 'dir' ][ 'res' ], 0 , - 1 ), substr ( $board [ 'dir' ], 0 , - 1 ) . '\/' . substr ( $config [ 'dir' ][ 'archive' ], 0 , - 1 ) . '\/' . substr ( $config [ 'dir' ][ 'res' ], 0 , - 1 ), $json_file_content );
// Write altered thread json to archive location
@ file_put_contents ( $board [ 'dir' ] . $config [ 'dir' ][ 'archive' ] . $config [ 'dir' ][ 'res' ] . $thread_id . " .json " , $json_file_content , LOCK_EX );
2017-06-05 22:29:52 +00:00
// Copy Images and Files Associated with Thread
if ( $post [ 'files' ]) {
foreach ( json_decode ( $post [ 'files' ]) as $i => $f ) {
if ( $f -> file !== 'deleted' ) {
@ copy ( $board [ 'dir' ] . $config [ 'dir' ][ 'img' ] . $f -> file , $board [ 'dir' ] . $config [ 'dir' ][ 'archive' ] . $config [ 'dir' ][ 'img' ] . $f -> file );
@ copy ( $board [ 'dir' ] . $config [ 'dir' ][ 'thumb' ] . $f -> thumb , $board [ 'dir' ] . $config [ 'dir' ][ 'archive' ] . $config [ 'dir' ][ 'thumb' ] . $f -> thumb );
$file_list [] = $f ;
// $file_list[$i]['file'] = $f->file;
// $file_list[$i]['thumb'] = $f->thumb;
}
}
}
}
// Insert Archive Data in Database
2017-06-24 18:19:15 +00:00
$query = prepare ( sprintf ( " INSERT INTO ``archive_%s`` VALUES (:thread_id, :snippet, :lifetime, :files, 0, 0, 0) " , $board [ 'uri' ]));
2017-06-05 22:29:52 +00:00
$query -> bindValue ( ':thread_id' , $thread_id , PDO :: PARAM_INT );
$query -> bindValue ( ':snippet' , $thread_data [ 'snippet' ], PDO :: PARAM_STR );
2017-06-07 13:02:20 +00:00
$query -> bindValue ( ':lifetime' , time (), PDO :: PARAM_INT );
2017-06-05 22:29:52 +00:00
$query -> bindValue ( ':files' , json_encode ( $file_list ));
$query -> execute () or error ( db_error ( $query ));
2017-07-17 01:30:31 +00:00
// Check if Thread should be Auto Featured based on OP Trip
if ( in_array ( $thread_data [ 'trip' ], $config [ 'archive' ][ 'auto_feature_trips' ]))
self :: featureThread ( $thread_id );
2017-06-05 22:29:52 +00:00
// Purge Threads that have timed out
2017-06-07 13:02:20 +00:00
if ( ! $config [ 'archive' ][ 'cron_job' ][ 'purge' ])
2017-06-06 01:16:57 +00:00
self :: purgeArchive ();
2017-06-05 22:29:52 +00:00
// Rebuild Archive Index
self :: buildArchiveIndex ();
return true ;
}
// Removes Archived Threads that has outlived their lifetime
static public function purgeArchive () {
global $config , $board ;
2017-06-07 13:02:20 +00:00
// If archive is set to live forever return
if ( ! $config [ 'archive' ][ 'lifetime' ])
return ;
2017-06-05 22:29:52 +00:00
// Delete all static pages and files for archived threads that has timed out
2017-06-13 23:25:14 +00:00
$query = prepare ( sprintf ( " SELECT `id`, `files` FROM ``archive_%s`` WHERE `lifetime` < :lifetime AND `featured` = 0 AND `mod_archived` = 0 " , $board [ 'uri' ]));
2017-06-07 17:40:12 +00:00
$query -> bindValue ( ':lifetime' , strtotime ( " - " . $config [ 'archive' ][ 'lifetime' ]), PDO :: PARAM_INT );
2017-06-07 13:02:20 +00:00
$query -> execute () or error ( db_error ( $query ));
2017-06-05 22:29:52 +00:00
while ( $thread = $query -> fetch ( PDO :: FETCH_ASSOC )) {
// Delete Files
foreach ( json_decode ( $thread [ 'files' ]) as $f ) {
@ unlink ( $board [ 'dir' ] . $config [ 'dir' ][ 'archive' ] . $config [ 'dir' ][ 'img' ] . $f -> file );
@ unlink ( $board [ 'dir' ] . $config [ 'dir' ][ 'archive' ] . $config [ 'dir' ][ 'img' ] . $f -> thumb );
}
// Delete Thread
@ unlink ( $board [ 'dir' ] . $config [ 'dir' ][ 'archive' ] . $config [ 'dir' ][ 'res' ] . sprintf ( $config [ 'file_page' ], $thread [ 'id' ]));
2017-06-24 18:19:15 +00:00
// Delete Vote Data
$del_query = prepare ( " DELETE FROM ``votes_archive`` WHERE `board` = :board AND `thread_id` = :thread_id " );
$del_query -> bindValue ( ':board' , $board [ 'uri' ]);
$del_query -> bindValue ( ':thread_id' , $thread [ 'id' ], PDO :: PARAM_INT );
$del_query -> execute () or error ( db_error ( $del_query ));
2017-06-05 22:29:52 +00:00
}
// Delete Archive Entries
2017-06-07 17:40:12 +00:00
if ( $query -> rowCount () != 0 ) {
2017-06-13 23:25:14 +00:00
$query = prepare ( sprintf ( " DELETE FROM ``archive_%s`` WHERE `lifetime` < :lifetime AND `featured` = 0 AND `mod_archived` = 0 " , $board [ 'uri' ])) or error ( db_error ());
2017-06-07 17:40:12 +00:00
$query -> bindValue ( ':lifetime' , strtotime ( " - " . $config [ 'archive' ][ 'lifetime' ]), PDO :: PARAM_INT );
$query -> execute () or error ( db_error ( $query ));
2017-06-11 12:24:11 +00:00
2017-06-13 23:25:14 +00:00
modLog ( sprintf ( " Purged %d archived threads due to expiration date " , $query -> rowCount ()));
2017-06-07 17:40:12 +00:00
}
2017-06-05 22:29:52 +00:00
return $query -> rowCount ();
}
// Feature thread and replies
2017-06-13 23:25:14 +00:00
static public function featureThread ( $thread_id , $mod_archive = false ) {
global $config , $board , $mod ;
2017-06-05 22:29:52 +00:00
// If featuring of threads is turned off return
2017-06-13 23:25:14 +00:00
if ( ! $mod_archive && ! $config [ 'feature' ][ 'threads' ])
return ;
// If mod archive of threads is turned off return
if ( $mod_archive && ! $config [ 'mod_archive' ][ 'threads' ])
2017-06-05 22:29:52 +00:00
return ;
2017-06-13 23:25:14 +00:00
$query = query ( sprintf ( " SELECT `files` FROM ``archive_%s`` WHERE `id` = %d AND " . ( $mod_archive ? " `mod_archived` " : " `featured` " ) . " = 0 " , $board [ 'uri' ], ( int ) $thread_id )) or error ( db_error ());
2017-06-05 22:29:52 +00:00
if ( ! $thread = $query -> fetch ( PDO :: FETCH_ASSOC ))
error ( $config [ 'error' ][ 'invalidpost' ]);
// Read Content of HTML
$thread_file_content = @ file_get_contents ( $board [ 'dir' ] . $config [ 'dir' ][ 'archive' ] . $config [ 'dir' ][ 'res' ] . sprintf ( $config [ 'file_page' ], $thread_id ));
// Replace links and posting mode to Archived
2017-06-13 23:25:14 +00:00
$thread_file_content = str_replace ( sprintf ( 'src="/' . $config [ 'board_path' ] . $config [ 'dir' ][ 'archive' ], $board [ 'uri' ]), sprintf ( 'src="/' . $config [ 'board_path' ] . ( $mod_archive ? $config [ 'dir' ][ 'mod_archive' ] : $config [ 'dir' ][ 'featured' ]), $board [ 'uri' ]), $thread_file_content );
$thread_file_content = str_replace ( sprintf ( 'href="/' . $config [ 'board_path' ] . $config [ 'dir' ][ 'archive' ], $board [ 'uri' ]), sprintf ( 'href="/' . $config [ 'board_path' ] . ( $mod_archive ? $config [ 'dir' ][ 'mod_archive' ] : $config [ 'dir' ][ 'featured' ]), $board [ 'uri' ]), $thread_file_content );
2017-06-05 22:29:52 +00:00
$thread_file_content = str_replace ( 'Archived thread' , 'Featured thread' , $thread_file_content );
// Write altered thread HTML to archive location
2017-06-13 23:25:14 +00:00
@ file_put_contents ( $board [ 'dir' ] . ( $mod_archive ? $config [ 'dir' ][ 'mod_archive' ] : $config [ 'dir' ][ 'featured' ]) . $config [ 'dir' ][ 'res' ] . sprintf ( $config [ 'file_page' ], $thread_id ), $thread_file_content , LOCK_EX );
2017-06-05 22:29:52 +00:00
foreach ( json_decode ( $thread [ 'files' ]) as $f ) {
2017-06-13 23:25:14 +00:00
@ copy ( $board [ 'dir' ] . $config [ 'dir' ][ 'archive' ] . $config [ 'dir' ][ 'img' ] . $f -> file , $board [ 'dir' ] . ( $mod_archive ? $config [ 'dir' ][ 'mod_archive' ] : $config [ 'dir' ][ 'featured' ]) . $config [ 'dir' ][ 'img' ] . $f -> file );
@ copy ( $board [ 'dir' ] . $config [ 'dir' ][ 'archive' ] . $config [ 'dir' ][ 'thumb' ] . $f -> thumb , $board [ 'dir' ] . ( $mod_archive ? $config [ 'dir' ][ 'mod_archive' ] : $config [ 'dir' ][ 'featured' ]) . $config [ 'dir' ][ 'thumb' ] . $f -> thumb );
2017-06-05 22:29:52 +00:00
}
// Update DB entry
2017-06-13 23:25:14 +00:00
query ( sprintf ( " UPDATE ``archive_%s`` SET " . ( $mod_archive ? " `mod_archived` " : " `featured` " ) . " = 1 WHERE `id` = %d " , $board [ 'uri' ], ( int ) $thread_id )) or error ( db_error ());
// Add mod log entry
modLog ( sprintf ( " Added thread #%d to " . ( $mod_archive ? " mod archive " : " featured threads " ), $thread_id ));
2017-06-05 22:29:52 +00:00
// Rebuild Featured Index
self :: buildFeaturedIndex ();
2017-06-24 18:19:15 +00:00
// Rebuild Archive Index
self :: buildArchiveIndex ();
2017-06-05 22:29:52 +00:00
return true ;
}
2017-06-13 23:25:14 +00:00
static public function deleteFeatured ( $thread_id , $mod_archive = false ) {
global $config , $board , $mod ;
2017-06-05 22:29:52 +00:00
2018-09-29 03:29:36 +00:00
$query = query ( sprintf ( " SELECT `id`, `files`, `lifetime` FROM ``archive_%s`` WHERE `featured` = 1 OR `mod_archived` = 1 " , $board [ 'uri' ])) or error ( db_error ());
2017-06-05 22:29:52 +00:00
if ( ! $thread = $query -> fetch ( PDO :: FETCH_ASSOC ))
error ( $config [ 'error' ][ 'invalidpost' ]);
// Delete Files
foreach ( json_decode ( $thread [ 'files' ]) as $f ) {
2017-06-13 23:25:14 +00:00
@ unlink ( $board [ 'dir' ] . ( $mod_archive ? $config [ 'dir' ][ 'mod_archive' ] : $config [ 'dir' ][ 'featured' ]) . $config [ 'dir' ][ 'img' ] . $f -> file );
@ unlink ( $board [ 'dir' ] . ( $mod_archive ? $config [ 'dir' ][ 'mod_archive' ] : $config [ 'dir' ][ 'featured' ]) . $config [ 'dir' ][ 'img' ] . $f -> thumb );
2017-06-05 22:29:52 +00:00
}
// Delete Thread
2017-06-13 23:25:14 +00:00
@ unlink ( $board [ 'dir' ] . ( $mod_archive ? $config [ 'dir' ][ 'mod_archive' ] : $config [ 'dir' ][ 'featured' ]) . $config [ 'dir' ][ 'res' ] . sprintf ( $config [ 'file_page' ], $thread_id ));
2017-06-05 22:29:52 +00:00
// Delete Entry in DB if it has timed out
2017-06-11 12:24:11 +00:00
if ( $thread [ 'lifetime' ] != 0 && $thread [ 'lifetime' ] < strtotime ( " - " . $config [ 'archive' ][ 'lifetime' ]))
2017-06-13 23:25:14 +00:00
query ( sprintf ( " DELETE FROM ``archive_%s`` WHERE `id` = %d AND " . ( $mod_archive ? " `featured` " : " `mod_archived` " ) . " = 0 " , $board [ 'uri' ], ( int ) $thread_id )) or error ( db_error ());
2017-06-05 22:29:52 +00:00
else
2017-06-13 23:25:14 +00:00
query ( sprintf ( " UPDATE ``archive_%s`` SET " . ( $mod_archive ? " `mod_archived` " : " `featured` " ) . " = 0 WHERE `id` = %d " , $board [ 'uri' ], ( int ) $thread_id )) or error ( db_error ());
2017-06-05 22:29:52 +00:00
2017-06-13 23:25:14 +00:00
// Add mod log entry
modLog ( sprintf ( " Deleted thread #%d from " . ( $mod_archive ? " mod archive " : " featured threads " ), $thread_id ));
2017-06-05 22:29:52 +00:00
// Rebuild Featured Index
self :: buildFeaturedIndex ();
2017-06-24 18:19:15 +00:00
// Rebuild Archive Index
self :: buildArchiveIndex ();
2017-06-05 22:29:52 +00:00
}
static public function RebuildArchiveIndexes () {
global $config ;
// If archiving is turned off return
if ( ! $config [ 'archive' ][ 'threads' ])
return ;
// Purge Archive
2017-06-06 01:16:57 +00:00
if ( ! $config [ 'archive' ][ 'cron_job' ][ 'purge' ])
self :: purgeArchive ();
2017-06-05 22:29:52 +00:00
// Rebuild Archive Index
self :: buildArchiveIndex ();
// Rebuild Featured Index
self :: buildFeaturedIndex ();
}
static public function buildArchiveIndex () {
global $config , $board ;
// If archiving is turned off return
if ( ! $config [ 'archive' ][ 'threads' ])
return ;
2017-06-11 12:24:11 +00:00
// Get archive List
$archive = self :: getArchiveList ();
2017-06-05 22:29:52 +00:00
foreach ( $archive as & $thread )
$thread [ 'archived_url' ] = $config [ 'dir' ][ 'res' ] . sprintf ( $config [ 'file_page' ], $thread [ 'id' ]);
$title = sprintf ( _ ( 'Archived' ) . ' %s: ' . $config [ 'board_abbreviation' ], _ ( 'threads' ), $board [ 'uri' ]);
$archive_page = Element ( 'page.html' , array (
'config' => $config ,
'mod' => false ,
'hide_dashboard_link' => true ,
'boardlist' => createBoardList ( false ),
'title' => $title ,
'subtitle' => " " ,
'body' => Element ( " mod/archive_list.html " , array (
'config' => $config ,
2017-06-11 12:24:11 +00:00
'thread_count' => count ( $archive ),
2017-06-06 15:39:29 +00:00
'board' => $board ,
2017-06-05 22:29:52 +00:00
'archive' => $archive
))
));
file_write ( $config [ 'dir' ][ 'home' ] . $board [ 'dir' ] . $config [ 'dir' ][ 'archive' ] . $config [ 'file_index' ], $archive_page );
}
2017-06-11 12:24:11 +00:00
2017-08-22 13:03:06 +00:00
static public function getArchiveList ( $featured = false , $mod_archive = false , $order_by_lifetime = false ) {
2017-06-11 12:24:11 +00:00
global $config , $board ;
$archive = false ;
if ( $featured ) {
2017-08-22 13:03:06 +00:00
$query = query ( sprintf ( " SELECT `id`, `snippet`, `featured`, `mod_archived` FROM ``archive_%s`` WHERE `featured` = 1 " , $board [ 'uri' ]) . ( $order_by_lifetime ? " ORDER BY `lifetime` DESC " : " ORDER BY `id` DESC " )) or error ( db_error ());
2017-06-13 23:25:14 +00:00
$archive = $query -> fetchAll ( PDO :: FETCH_ASSOC );
} else if ( $mod_archive ) {
2017-08-22 13:03:06 +00:00
$query = query ( sprintf ( " SELECT `id`, `snippet`, `featured`, `mod_archived` FROM ``archive_%s`` WHERE `mod_archived` = 1 " , $board [ 'uri' ]) . ( $order_by_lifetime ? " ORDER BY `lifetime` DESC " : " ORDER BY `id` DESC " )) or error ( db_error ());
2017-06-11 12:24:11 +00:00
$archive = $query -> fetchAll ( PDO :: FETCH_ASSOC );
} else {
2017-08-22 13:03:06 +00:00
$query = prepare ( sprintf ( " SELECT `id`, `snippet`, `featured`, `mod_archived`, `votes` FROM ``archive_%s`` WHERE `lifetime` > :lifetime " , $board [ 'uri' ]) . ( $order_by_lifetime ? " ORDER BY `lifetime` DESC " : " ORDER BY `id` DESC " ));
2017-06-11 12:24:11 +00:00
$query -> bindValue ( ':lifetime' , strtotime ( " - " . $config [ 'archive' ][ 'lifetime' ]), PDO :: PARAM_INT );
$query -> execute () or error ( db_error ());
$archive = $query -> fetchAll ( PDO :: FETCH_ASSOC );
}
return $archive ;
}
2017-06-05 22:29:52 +00:00
static public function buildFeaturedIndex () {
global $config , $board ;
// If featuring of threads is turned off return
if ( ! $config [ 'feature' ][ 'threads' ])
return ;
2017-06-24 18:59:50 +00:00
2017-06-11 12:24:11 +00:00
// Get featured archived threads
$archive = self :: getArchiveList ( true );
2017-06-05 22:29:52 +00:00
foreach ( $archive as & $thread )
$thread [ 'featured_url' ] = $config [ 'dir' ][ 'res' ] . sprintf ( $config [ 'file_page' ], $thread [ 'id' ]);
$title = sprintf ( _ ( 'Featured' ) . ' %s: ' . $config [ 'board_abbreviation' ], _ ( 'threads' ), $board [ 'uri' ]);
$archive_page = Element ( 'page.html' , array (
'config' => $config ,
'mod' => false ,
'hide_dashboard_link' => true ,
'boardlist' => createBoardList ( false ),
'title' => $title ,
'subtitle' => " " ,
'body' => Element ( " mod/archive_featured_list.html " , array (
'config' => $config ,
2017-06-24 18:59:50 +00:00
'board' => $board ,
2017-06-05 22:29:52 +00:00
'archive' => $archive
))
));
file_write ( $config [ 'dir' ][ 'home' ] . $board [ 'dir' ] . $config [ 'dir' ][ 'featured' ] . $config [ 'file_index' ], $archive_page );
}
2017-06-24 18:19:15 +00:00
static public function addVote ( $board , $thread_id ) {
global $config ;
// Check if thread exist in archive
$query = prepare ( sprintf ( " SELECT COUNT(*) FROM ``archive_%s`` WHERE `id` = %d " , $board , $thread_id ));
$query -> execute () or error ( db_error ( $query ));
if ( $query -> fetchColumn ( 0 ) == 0 )
error ( $config [ 'error' ][ 'nonexistant' ]);
// Check if ip has voted
$query = prepare ( " SELECT COUNT(*) FROM ``votes_archive`` WHERE `board` = :board AND `thread_id` = :thread_id AND `ip` = :ip " );
$query -> bindValue ( ':board' , $board , PDO :: PARAM_STR );
$query -> bindValue ( ':thread_id' , $thread_id , PDO :: PARAM_INT );
$query -> bindValue ( ':ip' , ( $config [ 'bcrypt_ip_addresses' ] ? get_ip_hash ( $_SERVER [ 'REMOTE_ADDR' ]) : $_SERVER [ 'REMOTE_ADDR' ]), PDO :: PARAM_STR );
// Error if already voted
$query -> execute () or error ( db_error ( $query ));
if ( $query -> fetchColumn ( 0 ) != 0 )
error ( $config [ 'error' ][ 'already_voted' ]);
// Increase vote count for thread
query ( sprintf ( " UPDATE ``archive_%s`` SET `votes` = `votes`+1 WHERE `id` = %d " , $board , ( int ) $thread_id )) or error ( db_error ());
// Add ip to voted db
$query = prepare ( " INSERT INTO ``votes_archive`` VALUES (NULL, :board, :thread_id, :ip) " );
$query -> bindValue ( ':board' , $board , PDO :: PARAM_STR );
$query -> bindValue ( ':thread_id' , $thread_id , PDO :: PARAM_INT );
$query -> bindValue ( ':ip' , ( $config [ 'bcrypt_ip_addresses' ] ? get_ip_hash ( $_SERVER [ 'REMOTE_ADDR' ]) : $_SERVER [ 'REMOTE_ADDR' ]), PDO :: PARAM_STR );
$query -> execute () or error ( db_error ( $query ));
// Rebuild Archive Index
self :: buildArchiveIndex ();
}
2017-06-05 22:29:52 +00:00
}
2018-09-29 03:29:36 +00:00
?>