Skip to content

Commit

Permalink
1. Get data from calender content type 2. Remove java script and use …
Browse files Browse the repository at this point in the history
…enque script 3. add metabox for event start date , end date and website URL 4.Code cleanup
  • Loading branch information
Satyanarayan Verma authored and Satyanarayan Verma committed Sep 17, 2015
1 parent 86f6221 commit 310520c
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 74 deletions.
Binary file modified .DS_Store
Binary file not shown.
98 changes: 92 additions & 6 deletions boilerplate.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@ class Boilerplate_Plugin
* Construct the plugin object
*/
public function __construct()
{
add_action('init', array(&$this, 'plugin_init'));
add_action('init', array(&$this, 'create_posttype_calander'));
add_action('admin_init', array(&$this, 'admin_init'));
add_action('admin_menu', array(&$this, 'add_menu'));
{
// add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ) );
// add_action( 'save_post', array( $this, 'save' ) );
add_action( 'init', array( &$this, 'plugin_init'));
add_action( 'init', array( &$this, 'create_posttype_calander' ) );
add_action( 'admin_init', array( &$this, 'admin_init' ) );
add_action( 'admin_menu', array( &$this, 'add_menu' ) );
add_action( 'add_meta_boxes', array( $this, 'add_custom_meta_box' ) );
add_action( "save_post", array( $this, "save_created_meta_box" ) );
add_filter( 'event_calender', array( $this, 'event_calender_callback' ) );
add_shortcode( 'eventcal', array( $this, 'event_calender_callback' ) );
add_action("wp_enqueue_scripts", array( $this, 'event_scripts' ) );

} // END public function __construct

Expand Down Expand Up @@ -119,7 +124,64 @@ public function event_calender_callback($atts)

} // END function


//Add meta fields

public function add_custom_meta_box( $post_type ){
$post_types = array( 'bp_calender' );
if ( in_array( $post_type, $post_types )) {
add_meta_box("event_start_date", "Create Event", array(&$this, "create_start_box"), $post_type );
}
}//END fundtion

//show meta fields
public function create_start_box( $post ){
wp_nonce_field(basename(__FILE__), "meta-box-nonce");
$meta_box_title = get_post_meta( $post->ID, '_bp_calender_title', true );
$meta_box_start_date = get_post_meta( $post->ID, '_bp_calender_start_date', true );
$meta_box_end_date = get_post_meta( $post->ID, '_bp_calender_end_date', true );
$meta_box_url = get_post_meta( $post->ID, '_bp_calender_url', true );
// wp_nonce_field( 'myplugin_inner_custom_box', 'myplugin_inner_custom_box_nonce' );

// Use get_post_meta to retrieve an existing value from the database.
?>
<div>
<label>Short Summery :&nbsp;</label><input type="text" size="14px" name="meta_box_title" id="meta_box_title" value="<?php if($meta_box_title){ echo $meta_box_title; } ?>" /><br>
<label>Start From :&nbsp;</label><input type="date" name="meta_box_start_date" id="meta_box_start_date" value="<?php if($meta_box_start_date){ echo $meta_box_start_date; } ?>" /><br>
<label>Open Till :&nbsp;</label><input type="date" name="meta_box_end_date" id="meta_box_end_date" value="<?php if($meta_box_end_date){ echo $meta_box_end_date; } ?>"/><br>
<label>URL :&nbsp;</label><input type="text" name="meta_box_url" id="meta_box_url" value="<?php if($meta_box_url){ echo $meta_box_url; } ?>" /><br>
</div>
<?php
}//END fundtion

//save mata fields
function save_created_meta_box( $post_id ){
if ( array_key_exists('meta_box_title', $_POST ) ) {
update_post_meta( $post_id,
'_bp_calender_title',
$_POST['meta_box_title']
);
}
if ( array_key_exists('meta_box_start_date', $_POST ) ) {
update_post_meta( $post_id,
'_bp_calender_start_date',
$_POST['meta_box_start_date']
);
}
if ( array_key_exists('meta_box_end_date', $_POST ) ) {
update_post_meta( $post_id,
'_bp_calender_end_date',
$_POST['meta_box_end_date']
);
}
if ( array_key_exists('meta_box_url', $_POST ) ) {
update_post_meta( $post_id,
'_bp_calender_url',
$_POST['meta_box_url']
);
}
}//END function


// Create Custom post type for calender
function create_posttype_calander() {
register_post_type( 'bp_calender',
Expand All @@ -135,6 +197,30 @@ function create_posttype_calander() {
);
}

/**
*Add scripts and CSS to the plugin
*/

//Add Scripts and Css
public function event_scripts(){
wp_enqueue_style( 'moment_js', plugins_url('/css/fullcalendar.css', __FILE__) );
wp_enqueue_style( 'moment_js', plugins_url('/css/fullcalendar.print.css', __FILE__) );
wp_enqueue_script( 'moment_js', plugins_url('/js/moment.min.js', __FILE__), '', '', true );
wp_enqueue_script( 'common_js', plugins_url('/js/jquery.min.js', __FILE__), '', '', true );
wp_enqueue_script( 'fullcalendar_js', plugins_url('/js/fullcalendar.js', __FILE__), '', '', true );
}//End Function













} // END class Boilerplate_Plugin
} // END if(!class_exists('Boilerplate_Plugin'))
Expand Down
Binary file modified templates/.DS_Store
Binary file not shown.
69 changes: 4 additions & 65 deletions templates/frontend.php
Original file line number Diff line number Diff line change
@@ -1,75 +1,14 @@

<?php $plugins_url = plugins_url(); ?>
<meta charset='utf-8' />
<link href='<?php echo $plugins_url ?>/boilerplate/css/fullcalendar.css' rel='stylesheet' />
<link href='<?php echo $plugins_url ?>/boilerplate/css/fullcalendar.print.css' rel='stylesheet' media='print' />
<script src='<?php echo $plugins_url ?>/boilerplate/js/moment.min.js'></script>
<script src='<?php echo $plugins_url ?>/boilerplate/js/jquery.min.js'></script>
<script src='<?php echo $plugins_url ?>/boilerplate/js/fullcalendar.js'></script>
<script>

jQuery(document).ready(function() {

jQuery('#calendar').fullCalendar({
defaultDate: '2015-02-12',
defaultDate: Date(),
editable: true,
eventLimit: true, // allow "more" link when too many events
events: [
{
title: 'All Day Event',
start: '2015-02-01'
},
{
title: 'Long Event',
start: '2015-02-07',
end: '2015-02-10'
},
{
id: 999,
title: 'Repeating Event',
start: '2015-02-09T16:00:00'
},
{
id: 999,
title: 'Repeating Event',
start: '2015-02-16T16:00:00'
},
{
title: 'Conference',
start: '2015-02-11',
end: '2015-02-13'
},
{
title: 'Meeting',
start: '2015-02-12T10:30:00',
end: '2015-02-12T12:30:00'
},
{
title: 'Lunch',
start: '2015-02-12T12:00:00'
},
{
title: 'Meeting',
start: '2015-02-12T14:30:00'
},
{
title: 'Happy Hour',
start: '2015-02-12T17:30:00'
},
{
title: 'Dinner',
start: '2015-02-12T20:00:00'
},
{
title: 'Birthday Party',
start: '2015-02-13T07:00:00'
},
{
title: 'Click for Google',
url: 'http://google.com/',
start: '2015-02-28'
}
]
events: <?php
include(sprintf("%s/get-events.php", dirname(__FILE__)));
?>
});

});
Expand Down
18 changes: 15 additions & 3 deletions templates/get-events.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,28 @@

// sprintf("%s/templates/json/events.json", dirname(__FILE__));
// Read and parse our events JSON file into an array of event data arrays.
$json = file_get_contents(dirname(__FILE__) . '/json/events.json');
$input_arrays = json_decode($json, true);

// $json = file_get_contents(dirname(__FILE__) . '/json/events.json');
// $input_arrays = json_decode($json, true);
// Accumulate an output array of event data arrays.


$args = array( 'post_type' => 'bp_calender');
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$id = get_the_ID();
$title = get_post_meta( $id , '_bp_calender_title', true );
$start = get_post_meta( $id , '_bp_calender_start_date', true );
$end = get_post_meta( $id , '_bp_calender_end_date', true );
$url = get_post_meta( $id , '_bp_calender_url', true );
$input_arrays[] = array("title"=>$title, "start"=>$start, "end"=>$end, "url"=>$url);
endwhile;

$output_arrays = array();
foreach ($input_arrays as $array) {

// Convert the input array into a useful Event object
$event = new Event($array, $timezone);

// If the event is in-bounds, add it to the output
if ($event->isWithinDayRange($range_start, $range_end)) {
$output_arrays[] = $event->toArray();
Expand Down

0 comments on commit 310520c

Please sign in to comment.