1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97:
<?php
require_once __DIR__."/../utils/Singleton.php";
use swag\Singleton;
class SettingsPageController extends Singleton {
public function init() {
add_action("wp_ajax_install_swagtoc",array($this,"installSwagToc"));
}
public function installSwagToc() {
global $wpdb;
$q=$wpdb->prepare(
"SELECT ID ".
"FROM {$wpdb->prefix}posts ".
"WHERE post_type=%s ".
"AND post_name=%s ",
"swag","toc");
$id=$wpdb->get_var($q);
if ($wpdb->last_error)
throw new Exception($wpdb->last_error);
if (!$id)
throw new Exception("No swag toc front page available");
update_option("show_on_front","page");
update_option("page_on_front",$id);
wp_redirect(admin_url('options-reading.php'));
}
private function xapi() {
$t=new Template(__DIR__."/../../tpl/settings_xapi.php");
if (is_plugin_active("wp-xapi-lrs/wp-xapi-lrs.php"))
$t->set("usingInternalLrs",TRUE);
else
$t->set("usingInternalLrs",FALSE);
return $t->render();
}
private function about() {
$t=new Template(__DIR__."/../../tpl/settings_about.php");
return $t->render();
}
public function process() {
$template=new Template(__DIR__."/../../tpl/settings.php");
$template->set("adminUrl",admin_url("options-general.php")."?page=ti_settings");
$tab="about";
if (isset($_REQUEST["tab"]))
$tab=$_REQUEST["tab"];
$template->set("tab",$tab);
$template->set("tabs",array(
"about"=>"About",
"xapi"=>"xAPI Settings",
));
switch ($tab) {
case "about":
$template->set("content",$this->about());
break;
case "xapi":
$template->set("content",$this->xapi());
break;
default:
$template->set("content","No such tab");
break;
}
$template->show();
}
}