<?php
/*
* CraftControl Core Class
*/
if( !defined('IN_CT') ){ die(); }
class CC_Site {
/*
* Setting the default.
*/
public function __construct() {
global $CT;
$CT->template->addParam('slideshow', $this->slideshow());
$CT->template->addParam('navigation', $this->assembleNavigation());
}
/*
* Assembling the slideshow
*/
public function slideshow() {
global $CT, $my, $cc;
$template = $cc->tpl->entity('slideshow');
//Whitelist Button
$whitelist = ($cc->data['0']['whitelist'] == "1")? str_replace('%whitelist_url%', WEBSITE_URL . '/index.php/whitelist', $cc->tpl->entity('whitelist_button')) : '';
//Slideshow images.
$ss = $my->query("SELECT * FROM
{prefix}slideshow
ORDER BY
place
ASC");
$ss_total = '';
foreach( $ss as $img ) {
if( $img['place'] == "1" ) {
$ss_total .= str_replace(
'%image_url%',
WEBSITE_URL . '/bin/slideshows/' . $img['image'],
$cc->tpl->entity('slideshow_slide_first')
);
} else {
$ss_total .= str_replace(
'%image_url%',
WEBSITE_URL . '/bin/slideshows/' . $img['image'],
$cc->tpl->entity('slideshow_slide_consecutive')
);
}
}
//Assembling the slideshow.
$result = str_replace(
array(
'%ss_header%',
'%ss_description%',
'%whitelist_button%',
'%slideshow_slides%'
),
array(
$cc->data['0']['ss_header'],
$cc->data['0']['ss_description'],
$whitelist,
$ss_total
),
$template
);
return $result;
}
/*
* Assembling the navigation.
*/
public function assembleNavigation() {
global $cc, $my;
$result = $my->query("SELECT * FROM
{prefix}navigation
ORDER BY
place
ASC");
$return = '';
$template = $cc->tpl->entity('navigation_link');
foreach( $result as $nav ) {
$return .= str_replace(array(
'%link_uri%',
'%link_name%'
),
array(
$nav['link'],
$nav['name']
),
$template);
}
$return = str_replace('%site_url%', WEBSITE_URL, $return);
return $return;
}
/*
* Form processing messages.
*/
public function formMessage($mode, $message) {
global $cc, $my;
switch($mode) {
case "0":
$template = $cc->tpl->entity('form_process_failure');
break;
case "1":
$template = $cc->tpl->entity('form_process_success');
break;
}
$resut = str_replace(
'%message%',
$message,
$template
);
return $result;
}
/*
* Pages
*/
public function default_page() {
global $cc, $my;
$page = $my->query("SELECT * FROM
`{prefix}pages`
WHERE
`def` =1
");
return $page['0']['content'];
}
public function play_page() {
global $cc, $my;
$template = $cc->tpl->addTpl('play');
if( $cc->json->call('getServer') == NULL ) {
$result = str_replace(
'%message%',
LANGUAGE_SERVER_OFFLINE,
$cc->tpl->entity('form_process_failure')
);
} else {
$images = '';
$names = implode(',', $cc->json->call('getPlayerNames')['success']);
foreach( $cc->json->call('getPlayerNames')['success'] as $player ) {
$images .= '<img src="https://minotar.net/helm/' . $player . '/50.png" title="' . $player . '" />';
}
$result = str_replace(
array(
'%player_count%',
'%server_ip%',
'%player_images%',
'%player_names%'
),
array(
$cc->json->call('getPlayerCount')['success'],
JSONAPI_HOST . ':' . SERVER_PORT,
$images,
$names
),
$template
);
}
return $result;
}
public function events_page() {
global $cc, $my;
$template = $cc->tpl->addTpl('events');
$e_tpl = $cc->tpl->entity('event_item');
$events = $my->query("SELECT * FROM
{prefix}events
ORDER BY
id
DESC");
$items = '';
//die(var_dump($events));
foreach( $events as $event ) {
$items .= str_replace(
array(
'%event_image%',
'%event_title%',
'%event_description%',
'%event_start%',
'%event_end%'
),
array(
WEBSITE_URL . '/bin/events/' . $event['image'],
$event['title'],
$event['description'],
$event['from'],
$event['to']
),
$e_tpl
);
}
$result = str_replace(
'%events_page%',
$items,
$template
);
return $result;
}
public function whitelist_page() {
global $cc, $my;
if( $cc->data['0']['whitelist'] == "1" ) {
$result = '';
$process = '';
if( isset($_POST['request']) ) {
try {
$username = $cc->clean($_POST['username']);
$email = $cc->clean($_POST['email']);
$list = $my->get('{prefix}whitelist');
if( !$username or !$email ) {
throw new Exception (LANGUAGE_FORM_INPUT_FIELDS);
} elseif( in_array($username, $list) ) {
throw new Exception (LANGUAGE_FORM_WHITELIST_USERNAME_USED);
} else {
$insert = array(
'username' => $username,
'email' => $email
);
if( $my->insert('{prefix}whitelist', $insert) ) {
$process = str_replace(
'%message%',
LANGUAGE_FORM_WHITELIST_SUCCESS,
$cc->tpl->entity('form_process_success')
);
} else {
throw new Exception (LANGUAGE_MYSQL_ERROR_INSERT);
}
}
} catch( Exception $e ) {
$process = str_replace(
'%message%',
$e->getMessage(),
$cc->tpl->entity('form_process_failure')
);
}
}
$form = str_replace(
array(
'%whitelist_form_process%',
'%whitelist_form_username_name%',
'%whitelist_form_email_name%',
'%whitelist_form_submit_name%'
),
array(
WEBSITE_URL . '/index.php/whitelist',
'username',
'email',
'request'
),
$cc->tpl->entity('whitelist_form')
);
$result = str_replace(
array(
'%form_process%',
'%whitelist_form%'
),
array(
$process,
$form
),
$cc->tpl->addTpl('whitelist')
);
} else {
$result = str_replace(
'%message%',
'You don\'t have to be whitelisted to play!',
$cc->tpl->entity('form_process_success')
);
}
return $result;
}
}
?>
You can't use array dereferencing in PHP 5.3Hello devbest,
I can not find anything that can help me
I am getting this error with CraftControl
Parse error: syntax error, unexpected '[' in /home/verac124/public_html/app/cc/site.class.php on line 139
the creator said the php versionis out dated I have 5.3
Function array dereferencing has been added, e.g. foo()[0]