Warning: chmod(): Operation not permitted in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [0] in function chmod in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [1] in function include_once in /var/www/hopeinstoughton_www/wp-settings.php on line 560 [2] in function require_once in /var/www/hopeinstoughton_www/wp-config.php on line 85 [3] in function require_once in /var/www/hopeinstoughton_www/wp-load.php on line 50 [4] in function require_once in /var/www/hopeinstoughton_www/wp-blog-header.php on line 13 [5] in function require in /var/www/hopeinstoughton_www/index.php on line 17
| Server IP : 94.177.8.99 / Your IP : 216.73.217.165 Web Server : Apache/2.4.58 (Ubuntu) System : Linux aries 6.8.0-134-generic #134-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 26 18:43:11 UTC 2026 x86_64 User : www-data ( 33) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/hopeinstoughton_www/wp-content/plugins/adult-class/ |
Upload File : |
<?php
/*
Plugin Name: Adult Class
Plugin URI: http://hostz.org/
Description: Group Classes by Series
Author: Phil Young
Author URI: http://hostz.org/
Version: 1.0.0
*/
/*
page:
<style type="text/css">
ul.classlist {
list-style: none;
margin-top: 20px !important;
}
ul.classlist li {
list-style: none !important;
margin-left: 0 !important;
font-size: 1.1rem;
padding: 4px !important;
}
ul.classlist li:nth-child(even) {
background-color: #AED2CE;
}
ul.classlist li:nth-child(odd) {
background-color: #E4F0F0;
}
</style>
[adult-class]
*/
class adult_class {
//const SPECIAL_PAGE = 2073; // demo
const SPECIAL_PAGE = 2267; // live
const EXHORT = 364;
private $header;
private $slug;
private $pagenum;
public function __construct() {
$this->isPost = $_SERVER['REQUEST_METHOD'] == 'POST';
$this->DIR = plugins_url('', __FILE__);
//add_action( 'template_redirect', [$this, '__404'] );
//add_filter( 'catalyst_site_layout', [$this, '__setlayout'], 1 );
//add_filter( '_get_page_link', [$this, '__canonical'], 80, 2 );
add_filter( 'catalyst_byline_meta', [$this, '__author'], 90 );
add_filter( 'catalyst_post_categories_shortcode', [$this, '__categories'], 90 );
add_action('wp_enqueue_scripts', array($this, 'add_css' ));
add_action('admin_enqueue_scripts', array($this, 'add_css' ));
// create list of talks - date / speaker / title
add_shortcode('adult-class', [$this, '_shortcode_handler'] );
}
function add_css() {
wp_enqueue_style('adult_class', plugins_url('jquery.dataTables.min.css', __FILE__), [], '1.10.21');
// wp_enqueue_script('adult_class_1', plugins_url('jquery.dataTables.min.js', __FILE__), [], '1.10.21' );
wp_enqueue_script('adult_class_1', plugins_url('jquery.dataTables.js', __FILE__), [], '1.10.21' );
// wp_enqueue_script('adult_class_2', plugins_url('classes.js', __FILE__), [], '' );
}
// List of Classes
function _shortcode_handler($atts) {
global $wpdb;
$ex = static::EXHORT;
$sql = <<<BLOCK
SELECT e.me_slug, e.me_topic, e.me_id,
count(x.mixe_item) as qty, max(mi_date) as dt,
max(mi_type) as tp,
ms_firstname, ms_lastname, ms_suffix
FROM `mm_item_x_event` as x
inner join `mm_event` as e on x.mixe_event=e.me_id
left join `mm_item` as i on i.mi_id = x.mixe_item
left join `mm_speaker` as s on i.mi_speaker=s.ms_id
where (mi_type <> "mt") and (mi_type <> "cbt")
and x.mixe_event <> $ex
and (present_mp3 <> 0 or present_mp4 <> 0)
group by mixe_event
BLOCK;
$newstuff = $wpdb->get_results($sql);
$output = $this->_asDataTable($newstuff);
return $output;
}
private function AsSpeaker($item) {
$value = trim($item->ms_firstname . ' ' . $item->ms_lastname);
if (!empty($item->ms_suffix)) $value .= ' ' . $item->ms_suffix;
return $value;
}
private function _asDataTable($res) {
global $MEDIASEARCH;
$data = [
'pageLength' => 25,
'dom' => 'lfrtip',
'order' => [[ 0, 'desc' ]],
'columns' => [
[ 'data' => ['_' => 'rawdate', 'display' => 'date'], 'title' => 'Date' ],
[ 'data' => 'title', 'title' => 'Title' ],
[ 'data' => 'spk', 'title' => 'Presenter', 'width' => 140 ],
[ 'data' => 'qty', 'title' => 'Classes' ],
[ 'data' => 'type', 'title' => 'Type', 'width' => 130 ],
],
'data' => [],
];
foreach($res as $row) {
$x = strtotime($row->dt . ' 12:00Z');
$the_date = gmdate('m/Y', $x);
$title = htmlspecialchars($row->me_topic);
switch($row->tp) {
case 'ac':
$type = 'Adult Class';
break;
case 'bc':
$type = 'Bible Class';
break;
case 'ex': // exhort - assuming part of a study weekend
case 'study':
$type = 'Study Weekend';
break;
case 'se': // special event
case 'sp': // special
case 'other':
$type = 'Other';
break;
case 'cbt':
$type = 'cbt.com';
break;
case 'cyc':
$type = 'CYC';
break;
default:
$type = '-';
break;
}
$link = $row->me_slug;
if ($link == '') {
if (is_object($MEDIASEARCH)) {
$link = $MEDIASEARCH->generateAuth($row->me_id, '', TRUE);
} else {
$link = '#';
}
} else {
$link = '/' . $link;
}
$safelink = htmlspecialchars($link);
$data['data'][] = [
'date' => $the_date,
'rawdate'=> $row->dt,
'title' => "<a href=\"{$safelink}\" target=\"_blank\">{$title}</a>",
'spk' => $this->asSpeaker($row),
'qty' => $row->qty,
'type' => $type,
];
}
$jsontext = json_encode($data);
$output = <<<BLOCK
<style type="text/css">
table.dataTable thead th, table.dataTable thead td {
text-align: left;
padding: 8px 10px;
}
</style>
<table class="datatable-adult">
<thead>
</thead>
<tbody>
</tbody>
</table>
<script type="text/javascript">
var $ = jQuery.noConflict();
var \$table = $('table.datatable-adult');
if (\$table.length) {
\$table.DataTable($jsontext);
}
</script>
BLOCK;
return $output;
}
// remove Author section at top
public function __author($meta) {
if ($this->header) {
return '';
}
return $meta;
}
// remove Categories: at bottom
public function __categories($value) {
if ($this->header) {
return '';
}
return $value;
}
// Not Used
public function __404() {
global $wp_query;
if( is_404() && $this->header ){
$uri = ltrim($_SERVER['REQUEST_URI'], '/');
list($basic, $pagenum) = explode('/', $uri, 2);
$pagenum = intval($pagenum, 10);
if ($pagenum < 1) $pagenum = 1;
$this->_loadThePage($pagenum);
$this->pagenum = $pagenum;
$wp_query->is_404 = FALSE;
$protocol = $_SERVER['SERVER_PROTOCOL'];
header("{$protocol} 200 OK");
}
}
// change the canonical link to something more suitable
// Not Used
public function __canonical($link, $post_id) {
if ($this->header && $post_id == static::SPECIAL_PAGE) {
$elements = parse_url($link);
return $elements['scheme'] . '://' . $elements['host'] . '/' . $this->slug . '/' . $this->pagenum;
}
return $link;
}
// set wide theme in Catalyst, but only if we are on our special page
// Not Used
public function __setlayout( $layout ) {
$uri = ltrim($_SERVER['REQUEST_URI'], '/');
list($basic, $pagenum) = explode('/', $uri, 2);
$ok = $this->_checkIfvalid($basic);
if ($ok) {
$this->slug = $basic;
return 'no-sidebar wide';
}
return $layout;
}
private function _checkIfvalid($basic) {
global $wpdb;
$xbasic = '"' . esc_sql($basic) . '"';
$sql = "select * from `cd_seriesh` where csh_slug={$xbasic}";
$this->header = $wpdb->get_row($sql);
return !is_null($this->header);
}
private function _loadThePage($pagenum) {
global $wpdb, $wp_query;
$args = [
'p' => static::SPECIAL_PAGE, // ID of a page, post, or custom type
'post_type' => 'any'
];
$wp_query = new WP_Query($args);
$wp_query->post->post_title = $this->header->csh_title;
$wp_query->post->post_name = "{$this->slug}/$pagenum";
$series_id = $this->header->csh_id;
$videoplayer = '(we\'re missing a video for this page)';
// load all classes
$xid = '"' . esc_sql($series_id) . '"';
$sql = <<<BLOCK
select * from `cd_seriest` as t
left join `cd_seriesh` as h on h.csh_id = t.cst_series
where cst_series={$xid}
order by cst_date, cst_id
BLOCK;
$res = $wpdb->get_results($sql);
$pages = count($res);
$output = '';
$author = $this->header->csh_author;
$audio = '';
foreach($res as $index => $item) {
$classnum = $index + 1;
if ($index) $output .= ' | ';
$safe_text = htmlspecialchars($item->cst_topic);
if ($classnum == $pagenum) {
$type = $item->csh_type;
$date = str_replace('-', '.', $item->cst_date);
$output .= "<span title=\"{$safe_text}\">Class {$classnum}</span>";
switch($type) {
case 'ac':
$file = "current/{$date} ac";
$mp3 = "current/{$date} ac.mp3";
if (!empty($item->cst_filename)) {
$file = $item->cst_filename;
$mp3 = $file . '.mp3';
}
break;
case 'bc':
case 'sp':
case 'sd':
case 'cyc':
$file = $item->cst_filename;
$mp3 = $file . '.mp3';
break;
default:
$file = '';
$mp3 = '';
}
if (empty($item->cst_topic)) {
$title = '';
} else {
$title = " title=\"Class {$classnum} - {$safe_text} ({$author})\"";
}
$videoplayer = "[videoplayer file=\"{$file}\"{$title}]";
$filename = "/av/{$mp3}";
$sourcefile = realpath(__DIR__ . '/../../..' . $filename);
if (file_exists($sourcefile)) {
$audio = "<a href=\"$filename\" title=\"right click, and choose 'save as' to save.\">play audio</a>";
} else {
$audio = "<!-- $sourcefile -->";
}
} else {
$output .= "<a href=\"/{$this->slug}/{$classnum}\" title=\"{$safe_text}\">Class {$classnum}</a>";
}
}
if ($pages == 1) {
$output = '';
}
$wp_query->post->post_content = str_replace(
['[links]', '[videoplayer]', '<!-- audio -->'],
["<div>$output</div>", $videoplayer, $audio ],
$wp_query->post->post_content);
// remove author info, remove categories
}
}
global $ADULTCLASS;
$ADULTCLASS = new adult_class();