Skip to content

Instantly share code, notes, and snippets.

@Deraen
Last active January 4, 2016 08:19
Show Gist options
  • Select an option

  • Save Deraen/8594424 to your computer and use it in GitHub Desktop.

Select an option

Save Deraen/8594424 to your computer and use it in GitHub Desktop.
DO NOT LOOK HERE
<?php
/**
*
* Author: Juho Teperi <[email protected]>
* 2013
*
* Holy shit, PHP is horrible.
*
* Retrieve a post from PhpBB.
* Post is selected by 't' query params which is used to select id from $types array.
* Post is presumed to contain JSON.
*
* Intended use: Use a PhpBB post to manage some JSON data your JS script might use for something.
* eg. sidebar widget on frontage.
*
*/
define("IN_PHPBB", true);
$phpbb_root_path = (defined("PHPBB_ROOT_PATH")) ? PHPBB_ROOT_PATH : "./";
$phpEx = substr(strrchr(__FILE__, "."), 1);
include($phpbb_root_path . "common." . $phpEx);
$type = request_var("t", "foo");
$types = array("streams" => 23558, "recruiting" => 23559);
header('Content-type: application/json');
if (!array_key_exists($type, $types)) {
header('HTTP', true, 404);
die();
}
$post_id = $types[$type];
$sql_array = array(
'SELECT' => 'p.post_text',
'FROM' => array(POSTS_TABLE => 'p'),
'WHERE' => "p.post_id = $post_id"
);
$sql = $db->sql_build_query('SELECT', $sql_array);
$result = $db->sql_query($sql);
$post_data = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
echo(htmlspecialchars_decode($post_data['post_text']));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment