streams/Code/Module/Update.php

84 lines
2.7 KiB
PHP
Raw Normal View History

<?php
2022-02-16 04:08:28 +00:00
namespace Code\Module;
2019-04-15 05:31:07 +00:00
/*
* Update
2021-10-16 21:56:36 +00:00
* Called by main.js to load or fetch updates of content for various conversation streams/timelines.
* It invokes the appropriate module's get() function to return an array of HTML rendered conversations/posts.
* Some state is passed to the module controller prior to calling module->get() to indicate that
* the existing content should either be replaced or appended to.
* The current modules that support this manner of update are
* channel, hq, stream, display, search, and pubstream.
* The state we are passing is the profile_uid (passed to us as $_GET['p']), and argv(2) === 'load'
* to indicate that we're replacing original content.
*
* module->profile_uid - tell the module who owns this data
* module->loading - tell the module to replace existing content
* module->updating - always true to tell the module that this is a js initiated request
*
* Inside main.js we also append all of the relevant content query params which were initially used on that
* page via buildCmd so those are passed to this instance of update and are therefore available from the module.
2019-04-15 05:31:07 +00:00
*/
use App;
2022-02-16 04:08:28 +00:00
use Code\Web\Controller;
2022-08-13 10:57:14 +00:00
use Exception;
2019-04-15 05:31:07 +00:00
2021-12-02 23:02:31 +00:00
class Update extends Controller
{
2021-12-02 23:02:31 +00:00
public function get()
{
2021-12-02 23:02:31 +00:00
$profile_uid = intval($_GET['p']);
2021-12-02 23:02:31 +00:00
// Change a profile_uid of 0 (not logged in) to (-1) for selected controllers
// as they only respond to liveUpdate with non-zero values
2021-12-02 23:02:31 +00:00
if ((!$profile_uid) && in_array(argv(1), ['display', 'search', 'pubstream', 'home'])) {
$profile_uid = (-1);
}
2021-12-02 23:02:31 +00:00
if (argc() < 2) {
killme();
}
2022-02-16 04:08:28 +00:00
$module = "\\Code\\Module\\" . ucfirst(argv(1));
2021-12-02 23:02:31 +00:00
$load = (((argc() > 2) && (argv(2) == 'load')) ? 1 : 0);
try {
$mod = new $module();
2022-08-13 10:57:14 +00:00
} catch (Exception $e) {
logger('Invalid module: ' . $module);
killme();
}
2021-12-02 23:02:31 +00:00
// Set the state flags of the relevant module (only conversational
// modules support state flags
2021-12-02 23:02:31 +00:00
if (isset($mod->profile_uid)) {
$mod->profile_uid = $profile_uid;
}
if (isset($mod->updating)) {
$mod->updating = 1;
}
if (isset($mod->loading) && $load) {
$mod->loading = 1;
}
2019-04-15 05:31:07 +00:00
2021-12-02 23:02:31 +00:00
header("Content-type: text/html");
2021-12-02 23:02:31 +00:00
// Modify the argument parameters to match what the new controller
// expects. They are currently set to what this controller expects.
2021-12-02 23:02:31 +00:00
App::$argv = [argv(1)];
App::$argc = 1;
echo "<!DOCTYPE html><html><body><section>\r\n";
echo $mod->get();
echo "</section></body></html>\r\n";
killme();
}
}