Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Programming Q&A
PHP help
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="habz0n" data-source="post: 214371" data-attributes="member: 35329"><p>My site/server uses JASONAPI and AuthME</p><p> </p><p>but here it is:</p><p> </p><p>[PHP]<?php</p><p> </p><p> /*</p><p> * CraftControl Core Class</p><p> */</p><p> if( !defined('IN_CT') ){ die(); }</p><p> </p><p> class CC_Site {</p><p> </p><p> /*</p><p> * Setting the default.</p><p> */</p><p> public function __construct() {</p><p> global $CT;</p><p> $CT->template->addParam('slideshow', $this->slideshow());</p><p> $CT->template->addParam('navigation', $this->assembleNavigation());</p><p> }</p><p> </p><p> /*</p><p> * Assembling the slideshow</p><p> */</p><p> public function slideshow() {</p><p> global $CT, $my, $cc;</p><p> $template = $cc->tpl->entity('slideshow');</p><p> //Whitelist Button</p><p> $whitelist = ($cc->data['0']['whitelist'] == "1")? str_replace('%whitelist_url%', WEBSITE_URL . '/index.php/whitelist', $cc->tpl->entity('whitelist_button')) : '';</p><p> //Slideshow images.</p><p> $ss = $my->query("SELECT * FROM</p><p> {prefix}slideshow</p><p> ORDER BY</p><p> place</p><p> ASC");</p><p> $ss_total = '';</p><p> foreach( $ss as $img ) {</p><p> if( $img['place'] == "1" ) {</p><p> $ss_total .= str_replace(</p><p> '%image_url%',</p><p> WEBSITE_URL . '/bin/slideshows/' . $img['image'],</p><p> $cc->tpl->entity('slideshow_slide_first')</p><p> );</p><p> } else {</p><p> $ss_total .= str_replace(</p><p> '%image_url%',</p><p> WEBSITE_URL . '/bin/slideshows/' . $img['image'],</p><p> $cc->tpl->entity('slideshow_slide_consecutive')</p><p> );</p><p> }</p><p> }</p><p> //Assembling the slideshow.</p><p> $result = str_replace(</p><p> array(</p><p> '%ss_header%',</p><p> '%ss_description%',</p><p> '%whitelist_button%',</p><p> '%slideshow_slides%'</p><p> ),</p><p> array(</p><p> $cc->data['0']['ss_header'],</p><p> $cc->data['0']['ss_description'],</p><p> $whitelist,</p><p> $ss_total</p><p> ),</p><p> $template</p><p> );</p><p> return $result;</p><p> }</p><p> </p><p> /*</p><p> * Assembling the navigation.</p><p> */</p><p> public function assembleNavigation() {</p><p> global $cc, $my;</p><p> $result = $my->query("SELECT * FROM</p><p> {prefix}navigation</p><p> ORDER BY</p><p> place</p><p> ASC");</p><p> $return = '';</p><p> $template = $cc->tpl->entity('navigation_link');</p><p> foreach( $result as $nav ) {</p><p> $return .= str_replace(array(</p><p> '%link_uri%',</p><p> '%link_name%'</p><p> ),</p><p> array(</p><p> $nav['link'],</p><p> $nav['name']</p><p> ),</p><p> $template);</p><p> }</p><p> $return = str_replace('%site_url%', WEBSITE_URL, $return);</p><p> return $return;</p><p> }</p><p> </p><p> /*</p><p> * Form processing messages.</p><p> */</p><p> public function formMessage($mode, $message) {</p><p> global $cc, $my;</p><p> switch($mode) {</p><p> case "0":</p><p> $template = $cc->tpl->entity('form_process_failure');</p><p> break;</p><p> case "1":</p><p> $template = $cc->tpl->entity('form_process_success');</p><p> break;</p><p> }</p><p> $resut = str_replace(</p><p> '%message%',</p><p> $message,</p><p> $template</p><p> );</p><p> return $result;</p><p> }</p><p> </p><p> /*</p><p> * Pages</p><p> */</p><p> public function default_page() {</p><p> global $cc, $my;</p><p> $page = $my->query("SELECT * FROM</p><p> `{prefix}pages`</p><p> WHERE</p><p> `def` =1</p><p> ");</p><p> return $page['0']['content'];</p><p> }</p><p> public function play_page() {</p><p> global $cc, $my;</p><p> $template = $cc->tpl->addTpl('play');</p><p> if( $cc->json->call('getServer') == NULL ) {</p><p> $result = str_replace(</p><p> '%message%',</p><p> LANGUAGE_SERVER_OFFLINE,</p><p> $cc->tpl->entity('form_process_failure')</p><p> );</p><p> } else {</p><p> $images = '';</p><p> $names = implode(',', $cc->json->call('getPlayerNames')['success']);</p><p> foreach( $cc->json->call('getPlayerNames')['success'] as $player ) {</p><p> $images .= '<img src="https://minotar.net/helm/' . $player . '/50.png" title="' . $player . '" />';</p><p> }</p><p> $result = str_replace(</p><p> array(</p><p> '%player_count%',</p><p> '%server_ip%',</p><p> '%player_images%',</p><p> '%player_names%'</p><p> ),</p><p> array(</p><p> $cc->json->call('getPlayerCount')['success'],</p><p> JSONAPI_HOST . ':' . SERVER_PORT,</p><p> $images,</p><p> $names</p><p> ),</p><p> $template</p><p> );</p><p> }</p><p> return $result;</p><p> }</p><p> public function events_page() {</p><p> global $cc, $my;</p><p> $template = $cc->tpl->addTpl('events');</p><p> $e_tpl = $cc->tpl->entity('event_item');</p><p> $events = $my->query("SELECT * FROM</p><p> {prefix}events</p><p> ORDER BY</p><p> id</p><p> DESC");</p><p> $items = '';</p><p> //die(var_dump($events));</p><p> foreach( $events as $event ) {</p><p> $items .= str_replace(</p><p> array(</p><p> '%event_image%',</p><p> '%event_title%',</p><p> '%event_description%',</p><p> '%event_start%',</p><p> '%event_end%'</p><p> ),</p><p> array(</p><p> WEBSITE_URL . '/bin/events/' . $event['image'],</p><p> $event['title'],</p><p> $event['description'],</p><p> $event['from'],</p><p> $event['to']</p><p> ),</p><p> $e_tpl</p><p> );</p><p> }</p><p> $result = str_replace(</p><p> '%events_page%',</p><p> $items,</p><p> $template</p><p> );</p><p> return $result;</p><p> }</p><p> public function whitelist_page() {</p><p> global $cc, $my;</p><p> if( $cc->data['0']['whitelist'] == "1" ) {</p><p> $result = '';</p><p> $process = '';</p><p> if( isset($_POST['request']) ) {</p><p> try {</p><p> $username = $cc->clean($_POST['username']);</p><p> $email = $cc->clean($_POST['email']);</p><p> </p><p> $list = $my->get('{prefix}whitelist');</p><p> </p><p> if( !$username or !$email ) {</p><p> throw new Exception (LANGUAGE_FORM_INPUT_FIELDS);</p><p> } elseif( in_array($username, $list) ) {</p><p> throw new Exception (LANGUAGE_FORM_WHITELIST_USERNAME_USED);</p><p> } else {</p><p> $insert = array(</p><p> 'username' => $username,</p><p> 'email' => $email</p><p> );</p><p> if( $my->insert('{prefix}whitelist', $insert) ) {</p><p> $process = str_replace(</p><p> '%message%',</p><p> LANGUAGE_FORM_WHITELIST_SUCCESS,</p><p> $cc->tpl->entity('form_process_success')</p><p> );</p><p> } else {</p><p> throw new Exception (LANGUAGE_MYSQL_ERROR_INSERT);</p><p> }</p><p> }</p><p> } catch( Exception $e ) {</p><p> $process = str_replace(</p><p> '%message%',</p><p> $e->getMessage(),</p><p> $cc->tpl->entity('form_process_failure')</p><p> );</p><p> }</p><p> }</p><p> $form = str_replace(</p><p> array(</p><p> '%whitelist_form_process%',</p><p> '%whitelist_form_username_name%',</p><p> '%whitelist_form_email_name%',</p><p> '%whitelist_form_submit_name%'</p><p> ),</p><p> array(</p><p> WEBSITE_URL . '/index.php/whitelist',</p><p> 'username',</p><p> 'email',</p><p> 'request'</p><p> ),</p><p> $cc->tpl->entity('whitelist_form')</p><p> );</p><p> $result = str_replace(</p><p> array(</p><p> '%form_process%',</p><p> '%whitelist_form%'</p><p> ),</p><p> array(</p><p> $process,</p><p> $form</p><p> ),</p><p> $cc->tpl->addTpl('whitelist')</p><p> );</p><p> } else {</p><p> $result = str_replace(</p><p> '%message%',</p><p> 'You don\'t have to be whitelisted to play!',</p><p> $cc->tpl->entity('form_process_success')</p><p> );</p><p> }</p><p> return $result;</p><p> }</p><p> </p><p> }</p><p> </p><p>?>[/PHP]</p></blockquote><p></p>
[QUOTE="habz0n, post: 214371, member: 35329"] My site/server uses JASONAPI and AuthME but here it is: [PHP]<?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; } } ?>[/PHP] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Programming Q&A
PHP help
Top