Skip to content

Commit

Permalink
add options page and shortcode parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
crossan007 committed Sep 9, 2017
1 parent fcc7511 commit f592b2f
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 14 deletions.
13 changes: 5 additions & 8 deletions churchcrm-calendar/admin/class-churchcrm-calendar-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,11 @@ public function enqueue_scripts() {
public function register_menu() {

// Order page
add_submenu_page(
'edit.php?post_type=churchcrm-calendar',
__( 'ChurchCRM Calendar Options', $this->plugin_name ),
__( 'Options', $this->plugin_name ),
'edit_pages',
'churchcrm-calendar-options',
array( $this, 'display_options_page' )
);
add_options_page('ChurchCRM Calendar Plugin Page','ChurchCRM Calendar', 'manage_options','churchcrm-calendar',array($this,'my_plugin_options'));
}

function my_plugin_options() {
include_once( 'partials/churchcrm-calendar-admin-display.php' );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,66 @@
*
* This file is used to markup the admin-facing aspects of the plugin.
*
* @link http://example.com
* @since 1.0.0
* @link
* @since 1.00
*
* @package ChurchCRM_Calendar
* @subpackage ChurchCRM_Calendar/admin/partials
*/
?>

<!-- This file should primarily consist of HTML with a little bit of PHP. -->

// Check Nonce and then update options
if ( !empty($_POST) && check_admin_referer( 'churchcrm-calendar-options', 'churchcrm-calendar-options' ) ) {
update_option( '_curchcrm_server_url', $_POST[ "curchcrm_server_url"] );
update_option( '_events_count_max', $_POST[ "events_count_max"]);

$churchcrm_server_url = stripslashes_deep( get_option('_curchcrm_server_url') );
$events_count_max = stripslashes_deep( get_option('_events_count_max') );
// We've updated the options, send off an AJAX request to flush the rewrite rules
#TODO# Should move these options to use the Settings API instead of our own custom thing - or maybe just make it all AJAX - no need for a page refresh
?>
<script type="text/javascript">
jQuery(document).ready(function($) {
var data = {
'action': 'sslp_flush_rewrite_rules',
}

$.post( "<?php echo admin_url( 'admin-ajax.php' ); ?>", data, function(response){});
});
</script>
<?php

} else {
$churchcrm_server_url = stripslashes_deep( get_option('_curchcrm_server_url') );
$events_count_max = stripslashes_deep( get_option('_events_count_max') );
}


$output = '<div class="wrap sslp-options">';
$output .= '<div id="icon-edit" class="icon32 icon32-posts-staff-member"><br></div>';
$output .= '<h2>' . __( 'ChurchCRM Calendar' , 'churchcrm-calendar' ) . '</h2>';
$output .= '<h2>' . __( 'Options', 'churchcrm-calendar' ) . '</h2>';

$output .= '<div class="sslp-content sslp-column">';
$output .= '<form method="post" action="">';
$output .= '<fieldset id="curchcrm_server_url" class="sslp-fieldset">';
$output .= '<legend class="sslp-field-label">' . __( 'ChurchCRM Server URL' , 'churchcrm-calendar' ) . '</legend>';
$output .= '<input type="text" name="curchcrm_server_url" value="' . $churchcrm_server_url . '"></fieldset>';

$output .= '<fieldset id="events_count_max" class="sslp-fieldset">';
$output .= '<legend class="sslp-field-label">' . __( 'Max Events to display (Default)' , 'churchcrm-calendar' ) . '</legend>';
$output .= '<input type="text" name="events_count_max" value="' . $events_count_max . '"></fieldset>';
$output .= '<p><input type="submit" value="' . __( 'Save ALL Changes' , 'churchcrm-calendar' ) . '" class="button button-primary button-large"></p>';

$output .= wp_nonce_field('churchcrm-calendar-options', 'churchcrm-calendar-options');
$output .= '</form>';
$output .= '</div>';
$output .= '<div class="sslp-sidebar sslp-column last">';
// Get the sidebar
ob_start();
include_once( 'churchcrm-calendar-admin-sidebar.php' );
$output .= ob_get_clean();
$output .= '</div>';
$output .= '</div>';

echo $output;
2 changes: 2 additions & 0 deletions churchcrm-calendar/public/class-churchcrm-calendar-public.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function __construct( $plugin_name, $version ) {

$this->churchcrm_calendar_list_shortcode_atts = array();
$this->churchcrm_calendar_list_shortcode_atts_defaults = array(
"max"=>stripslashes_deep( get_option('_events_count_max') )
);
$this->churchcrm_calendar_register_shortcodes();

Expand Down Expand Up @@ -136,6 +137,7 @@ public function churchcrm_calendar_list_shortcode_callback( $atts = array() ) {
global $crmc_sc_output;

$this->churchcrm_calendar_list_shortcode_atts = shortcode_atts( $this->churchcrm_calendar_list_shortcode_atts_defaults, $atts, 'churchcrm-calendar-list' );
//print_r($atts);
include( 'partials/churchcrm-calendar-list-shortcode-display.php' );
return $crmc_sc_output;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,23 @@

$atts = $this->churchcrm_calendar_list_shortcode_atts;

$events = json_decode(file_get_contents("http://192.168.33.10/external/calendar/events"));
$events = json_decode(file_get_contents(get_option('_curchcrm_server_url')."/external/calendar/events"));
$events_count_max = $this->churchcrm_calendar_list_shortcode_atts['max'];

/*
TODO: Render the events on the page.
*/
$crmc_sc_output = "<div class=\"events-list\">";

$events_count_current = 0;
foreach ($events as $Event)
{
if ($events_count_current >= $events_count_max) { break; }
$crmc_sc_output .= "<div class=\"event-div\">";
$crmc_sc_output .= "<div class=\"event-div-header\"><h1>$Event->Title</h1><h2>".date("M/j/y g:i A",strtotime($Event->Start))."</h2></div>";
$crmc_sc_output .= "<div class=\"event-div-body\"><p>$Event->Desc</p></div>";
$crmc_sc_output .= "</div>";
$events_count_current ++;
}

$crmc_sc_output .= "</div>";
Expand Down

0 comments on commit f592b2f

Please sign in to comment.