&& isset($query)
&& is_object($query)
&& isset($query->query['post_type'])) {
- $postType = $query->query['post_type'];
- if ($postType == GLM_BLOCK_POST_TYPE) {
- $query->set('orderby', 'menu_order');
- $query->set('order', 'asc');
+ $postType = $query->query['post_type'];
+ if ($postType == GLM_BLOCK_POST_TYPE) {
+ $query->set('orderby', 'menu_order');
+ $query->set('order', 'asc');
+ }
}
- }
}
/**
'label' => __('Blocks'),
'labels' => $labels,
'description' => 'Stores Blocks and Block data',
- 'public' => true,
+ 'public' => false,
'publicly_queriable' => false,
'rewrite' => false,
'show_ui' => true,
$glm_block_post = ($post)
? get_post_meta($post->ID, 'glm_block_post', true)
: '';
+ $glm_block_event = ($post)
+ ? get_post_meta($post->ID, 'glm_block_event', true)
+ : '';
include $this->pluginDirName . 'views/admin/metaBoxes.php';
}
global $post;
// verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times
- if (isset($post) && !wp_verify_nonce($_POST['glm_block_noncename'],
- 'glm_block_noncename')) {
+ if (isset($post) && !wp_verify_nonce($_POST['glm_block_noncename'], 'glm_block_noncename')) {
return $post->ID;
}
// OK, we're authenticated: we need to find and save the data
// We'll put it into an array to make it easier to loop though.
update_post_meta($post->ID, 'glm_block_url', $_POST['glm_block_url']);
- update_post_meta($post->ID, 'glm_block_ext_url',
- $_POST['glm_block_ext_url']);
+ update_post_meta($post->ID, 'glm_block_ext_url', $_POST['glm_block_ext_url']);
update_post_meta($post->ID, 'glm_block_page', $_POST['glm_block_page']);
update_post_meta($post->ID, 'glm_block_post', $_POST['glm_block_post']);
+ update_post_meta($post->ID, 'glm_block_event', $_POST['glm_block_event']);
}
/**
global $wpdb, $wp;
$catId = filter_var($catId, FILTER_VALIDATE_INT);
$args = array(
- 'posts_per_page' => -1,
+ 'posts_per_page' => -1,
'post_type' => GLM_BLOCK_POST_TYPE,
'orderby' => 'menu_order post_title',
'order' => 'asc'
$block->externalUrl = false;
$custom = get_post_custom($block->ID);
switch ($custom['glm_block_url'][0]) {
+ case 'event':
+ $block->url = get_permalink($custom['glm_block_event'][0]);
+ break;
case 'page':
$block->url = get_permalink($custom['glm_block_page'][0]);
break;
$messages['glm_blocks'] = array(
0 => '', // Unused. Messages start at index 1.
- 1 => sprintf(__('Block updated. <a href="%s">View item</a>'),
- esc_url(get_permalink($post_ID))),
+ 1 => __('Block updated.'),
2 => __('Custom field updated.'),
3 => __('Custom field deleted.'),
4 => __('Block updated.'),
/* translators: %s: date and time of the revision */
5 => isset($_GET['revision'])
- ? sprintf(__('Block restored to revision from %s'),
- wp_post_revision_title((int) $_GET['revision'],
- false))
+ ? sprintf(__('Block restored to revision from %s'),
+ wp_post_revision_title((int) $_GET['revision'],
+ false))
: false,
- 6 => sprintf(__('Block published. <a href="%s">View event</a>'),
- esc_url(get_permalink($post_ID))),
- 7 => __('Block saved.'),
- 8 => sprintf(__('Block submitted. <a target="_blank" href="%s">Preview event</a>'),
- esc_url(add_query_arg('preview', 'true',
- get_permalink($post_ID)))),
- 9 => sprintf(__('Block scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview job</a>'),
+ 6 => __('Block published.'),
+ 7 => __('Block saved.'),
+ 8 => __('Block submitted.'),
+ 9 => sprintf(__('Block scheduled for: <strong>%1$s</strong>.'),
// translators: Publish box date format, see http://php.net/date
- date_i18n(__('M j, Y @ G:i'),
- strtotime($post->post_date)),
- esc_url(get_permalink($post_ID))),
- 10 => sprintf(__('Block draft updated. <a target="_blank" href="%s">Preview event</a>'),
- esc_url(add_query_arg('preview', 'true',
- get_permalink($post_ID)))),
- );
+ date_i18n(__('M j, Y @ G:i'),
+ strtotime($post->post_date))),
+ 10 => __('Block draft updated.'),
+ );
return $messages;
}
/**
*/
function addOrderColumn($header_text_columns)
{
- $header_text_columns['menu_order'] = "Order";
- return $header_text_columns;
+ $header_text_columns['menu_order'] = "Order";
+ return $header_text_columns;
}
/**
{
global $post;
switch ($name) {
- case 'menu_order':
+ case 'menu_order':
$order = $post->menu_order;
echo $order;
break;
- default:
+ default:
break;
- }
+ }
}
/**
*/
function orderSortable($columns)
{
- $columns['menu_order'] = 'menu_order';
- return $columns;
+ $columns['menu_order'] = 'menu_order';
+ return $columns;
+ }
+
+ /**
+ * glm_blocks_get_posts
+ *
+ * @access public
+ * @return void
+ */
+ function get_posts()
+ {
+ $query = array(
+ 'post_type' => 'post',
+ 'suppress_filters' => true,
+ 'update_post_term_cache' => false,
+ 'update_post_meta_cache' => false,
+ 'post_status' => 'publish',
+ 'order' => 'DESC',
+ 'orderby' => 'date',
+ 'posts_per_page' => -1,
+ );
+ $get_posts = new WP_Query;
+ $posts = $get_posts->query( $query );
+ $results = array();
+ if ( ! $get_posts->post_count ) {
+ return $results;
+ }
+ foreach ( $posts as $post ) {
+ if ( 'post' == $post->post_type ) {
+ $info = mysql2date( __( 'Y/m/d' ), $post->post_date );
+ } else {
+ continue;
+ }
+ $results[] = array(
+ 'ID' => $post->ID,
+ 'title' => trim( esc_html( strip_tags( get_the_title( $post ) ) ) ),
+ 'permalink' => get_permalink( $post->ID ),
+ 'info' => $info,
+ );
+ }
+ return $results;
}
+ /**
+ * get_events
+ *
+ * @access public
+ * @return void
+ */
+ public function get_events()
+ {
+ global $wpdb;
+ $results = array();
+ if ( !defined( 'AI1EC_PATH' ) ) {
+ return $results;
+ }
+
+ $sql = "
+ SELECT p.ID,p.post_title,
+ DATE_FORMAT(FROM_UNIXTIME(e.start), '%m/%d/%Y') as 'starting',
+ DATE_FORMAT(FROM_UNIXTIME(e.end), '%m/%d/%Y') AS ending
+ FROM {$wpdb->prefix}posts p LEFT OUTER JOIN {$wpdb->prefix}ai1ec_events e
+ ON (e.post_id = p.ID)
+ WHERE p.post_type = 'ai1ec_event'
+ ORDER BY p.post_title,e.start";
+
+ return $wpdb->get_results( $sql, ARRAY_A );
+ }
}
<select id="glm_block_post" name="glm_block_post">
<option value="">None</option>
<?php
-$glmPosts = glm_blocks_get_posts();
+$glmPosts = $this->get_posts();
foreach ($glmPosts as $post) {
echo '<option value="' . $post['ID'] . '"';
if ($post['ID'] == $glm_block_post) {
?>
</select>
<?php
-function glm_blocks_get_posts() {
- $query = array(
- 'post_type' => 'post',
- 'suppress_filters' => true,
- 'update_post_term_cache' => false,
- 'update_post_meta_cache' => false,
- 'post_status' => 'publish',
- 'order' => 'DESC',
- 'orderby' => 'date',
- 'posts_per_page' => -1,
- );
- $get_posts = new WP_Query;
- $posts = $get_posts->query( $query );
- $results = array();
- if ( ! $get_posts->post_count ) {
- return $results;
- }
- foreach ( $posts as $post ) {
- if ( 'post' == $post->post_type ) {
- $info = mysql2date( __( 'Y/m/d' ), $post->post_date );
- } else {
- continue;
+$events = $this->get_events();
+//echo '<pre>' . print_r( $events, true ) . '</pre>';
+if ( isset( $events ) && is_array( $events ) && !empty( $events ) ) {
+ ?><br>
+ <input type="radio" name="glm_block_url" value="event"
+ <?php if ($glm_block_url == 'event') { echo 'checked'; }; ?>>
+ <?php
+ echo '<label for="my_meta_box_post_type">Internal Event: </label>';
+ echo '<select id="glm_block_event" name="glm_block_event">';
+ echo '<option value="">None</option>';
+ foreach ( $events as $event ) {
+ echo '<option value="' . $event['ID'] . '"';
+ if ($event['ID'] == $glm_block_event) {
+ echo ' selected';
}
- $results[] = array(
- 'ID' => $post->ID,
- 'title' => trim( esc_html( strip_tags( get_the_title( $post ) ) ) ),
- 'permalink' => get_permalink( $post->ID ),
- 'info' => $info,
- );
+ echo '>' . $event['post_title'] . ' (' . $event['starting'] . ')</option>';
}
- return $results;
+ echo '</select>';
}
?>