getLatestActiveThreads from myBB
This commit is contained in:
commit
9635d914c5
40
activethreads.php
Normal file
40
activethreads.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
/**
|
||||
* Return the latest threads of one forum, where a post has been posted
|
||||
*
|
||||
* @param integer $forum_id Forum ID to fetch threads from
|
||||
* @param integer $limit Amount of threads to get
|
||||
* @param boolean $excluse_invisible Shall we also get invisible threads?
|
||||
* @return array
|
||||
*/
|
||||
function getLatestActiveThreads($forum_id = 0, $limit = 7, $exclude_invisible = true)
|
||||
{
|
||||
global $pdo, $prefix;
|
||||
// This will be the array, where we can save the threads
|
||||
$threads = array();
|
||||
|
||||
/**
|
||||
* If defined forum id is 0, we do not fetch threads from only one forum,
|
||||
* but we fetch the latest threads of all forums
|
||||
* Therefore we add the forum_id in the where condition
|
||||
* We only fetch visible threads, if there is anything we want to hide ;)
|
||||
* However we can also define that we want the invisible threads as well
|
||||
*/
|
||||
$fetch_invisible_threads = ($exclude_invisible == true) ? '1' : '0';
|
||||
$condition = [];
|
||||
$condition['visible'] = $fetch_invisible_threads;
|
||||
if ($forum_id != 0){
|
||||
$condition['fid'] = intval($forum_id);
|
||||
}
|
||||
|
||||
// Run the Query
|
||||
$query = $pdo->select()
|
||||
->from(MYBB_PREFIX.'threads')
|
||||
->whereMany($condition, '=')
|
||||
->orderBy('lastpost', 'DESC')
|
||||
->limit(intval($limit), 0)
|
||||
->execute();
|
||||
|
||||
return $query->fetchAll();
|
||||
}
|
||||
|
6
composer.json
Normal file
6
composer.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"minimum-stability": "dev",
|
||||
"require": {
|
||||
"slim/pdo": "^1.10"
|
||||
}
|
||||
}
|
65
composer.lock
generated
Normal file
65
composer.lock
generated
Normal file
|
@ -0,0 +1,65 @@
|
|||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"hash": "d1c6c4a84dd7d10aa418cd379c810ed7",
|
||||
"content-hash": "1be1f0d88c406a5544cb07add016bdd4",
|
||||
"packages": [
|
||||
{
|
||||
"name": "slim/pdo",
|
||||
"version": "1.10.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/FaaPz/Slim-PDO.git",
|
||||
"reference": "9424e6d5f3737a71722ab1f868c1d3090b63287d"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/FaaPz/Slim-PDO/zipball/9424e6d5f3737a71722ab1f868c1d3090b63287d",
|
||||
"reference": "9424e6d5f3737a71722ab1f868c1d3090b63287d",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-pdo": "*",
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Slim\\PDO\\": "src/PDO/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Fabian de Laender",
|
||||
"email": "fabian@faapz.nl",
|
||||
"homepage": "http://faapz.nl",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "PDO database library for Slim Framework",
|
||||
"homepage": "https://github.com/FaaPz/Slim-PDO",
|
||||
"keywords": [
|
||||
"database",
|
||||
"framework",
|
||||
"pdo",
|
||||
"slim"
|
||||
],
|
||||
"time": "2016-08-14 11:42:49"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "dev",
|
||||
"stability-flags": [],
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": [],
|
||||
"platform-dev": []
|
||||
}
|
39
digest.html
Normal file
39
digest.html
Normal file
|
@ -0,0 +1,39 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<head></head>
|
||||
<body>
|
||||
<p>{{Username}},</p>
|
||||
|
||||
<p>Here’s a daily update of activity on the Olympic Business forum.</p>
|
||||
|
||||
<p><table style="padding: 1em">
|
||||
<thead>
|
||||
<th style="padding: 0.5em">Forum</th>
|
||||
<th>Thread</th>
|
||||
<th>Started by</th>
|
||||
<th>Post count</th>
|
||||
<th>Last update</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td style="padding: 0.5em">
|
||||
Sales
|
||||
</td>
|
||||
<td style="padding: 0.5em">
|
||||
Sales thread [hyperlink]<br>
|
||||
How do I increase sales?
|
||||
</td>
|
||||
<td>User.Name, 20/04/2017</td>
|
||||
<td>3</td>
|
||||
<td>User.Name, 24/04/2017</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></p>
|
||||
|
||||
<p>Thank you,<br>
|
||||
Olympic Business Forum Staff</p>
|
||||
|
||||
<p>To unsubscribe from these daily digests, click here: {{link}}</p>
|
||||
</body>
|
||||
</html>
|
12
digest.php
Normal file
12
digest.php
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
require_once "vendor/autoload.php";
|
||||
require_once "activethreads.php";
|
||||
define("MYBB_ROOT", "../");
|
||||
define("MYBB_PREFIX", "mybb_");
|
||||
define("FORUM_ID", 0);// 0 means all forums
|
||||
$dsn = 'mysql:host=localhost;dbname=mybb;charset=utf8';
|
||||
$usr = 'root';
|
||||
$pwd = '123456';
|
||||
|
||||
$pdo = new \Slim\PDO\Database($dsn, $usr, $pwd);
|
||||
$threads = getLatestActiveThreads(FORUM_ID, 100, true);
|
Reference in a new issue