From 6cb37828e5f7e32d08e24234ee0d41de9312bc95 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Mon, 1 Feb 2016 15:18:54 -0500 Subject: [PATCH] Updating blocks Adding ability to add block that link to events from time.ly --- controllers/admin.php | 11 +++ js/glm-blocks.js | 8 ++- models/block.php | 137 ++++++++++++++++++++++++++++---------- views/admin/metaBoxes.php | 47 +++++-------- 4 files changed, 135 insertions(+), 68 deletions(-) diff --git a/controllers/admin.php b/controllers/admin.php index cf09a3c..9079930 100644 --- a/controllers/admin.php +++ b/controllers/admin.php @@ -30,3 +30,14 @@ class glm_blocks_admin } } + +/* + * + SELECT p.ID,p.post_title, + DATE_FORMAT(FROM_UNIXTIME(e.start), '%Y-%m-%d') as 'starting', + DATE_FORMAT(FROM_UNIXTIME(e.end), '%Y-%m-%d') AS ending + FROM glm_18_posts p LEFT OUTER JOIN glm_18_ai1ec_events e + ON (e.post_id = p.ID) + WHERE p.post_type = 'ai1ec_event'; + * + */ diff --git a/js/glm-blocks.js b/js/glm-blocks.js index 541bdf4..fc3ee41 100644 --- a/js/glm-blocks.js +++ b/js/glm-blocks.js @@ -1,5 +1,4 @@ jQuery(function($){ - $("#edit-slug-box").hide(); $("#set-ngg-post-thumbnail").hide(); $("#glm_block_page").change(function(){ @@ -23,4 +22,11 @@ jQuery(function($){ $("input[name=glm_block_url]").filter('input[value=url]').attr('checked', false); } }); + $("#glm_block_event").change(function(){ + if($("#glm_block_event").val()) { + $("input[name=glm_block_url]").filter('input[value=event]').attr('checked', true); + } else { + $("input[name=glm_block_url]").filter('input[value=event]').attr('checked', false); + } + }); }); diff --git a/models/block.php b/models/block.php index 0788cd4..5c018a1 100644 --- a/models/block.php +++ b/models/block.php @@ -70,12 +70,12 @@ class glm_models_block && 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'); + } } - } } /** @@ -102,7 +102,7 @@ class glm_models_block 'label' => __('Blocks'), 'labels' => $labels, 'description' => 'Stores Blocks and Block data', - 'public' => true, + 'public' => false, 'publicly_queriable' => false, 'rewrite' => false, 'show_ui' => true, @@ -156,6 +156,9 @@ class glm_models_block $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'; } @@ -171,8 +174,7 @@ class glm_models_block 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; } @@ -186,10 +188,10 @@ class glm_models_block // 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']); } /** @@ -203,7 +205,7 @@ class glm_models_block 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' @@ -216,6 +218,9 @@ class glm_models_block $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; @@ -271,32 +276,25 @@ class glm_models_block $messages['glm_blocks'] = array( 0 => '', // Unused. Messages start at index 1. - 1 => sprintf(__('Block updated. View item'), - 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. View event'), - esc_url(get_permalink($post_ID))), - 7 => __('Block saved.'), - 8 => sprintf(__('Block submitted. Preview event'), - esc_url(add_query_arg('preview', 'true', - get_permalink($post_ID)))), - 9 => sprintf(__('Block scheduled for: %1$s. Preview job'), + 6 => __('Block published.'), + 7 => __('Block saved.'), + 8 => __('Block submitted.'), + 9 => sprintf(__('Block scheduled for: %1$s.'), // 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. Preview event'), - 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; } /** @@ -308,8 +306,8 @@ class glm_models_block */ 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; } /** @@ -323,13 +321,13 @@ class glm_models_block { global $post; switch ($name) { - case 'menu_order': + case 'menu_order': $order = $post->menu_order; echo $order; break; - default: + default: break; - } + } } /** @@ -341,8 +339,73 @@ class glm_models_block */ 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 ); + } } diff --git a/views/admin/metaBoxes.php b/views/admin/metaBoxes.php index 8adef7b..e5f6bd1 100644 --- a/views/admin/metaBoxes.php +++ b/views/admin/metaBoxes.php @@ -45,7 +45,7 @@ wp_dropdown_pages( '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 '
' . print_r( $events, true ) . '
'; +if ( isset( $events ) && is_array( $events ) && !empty( $events ) ) { + ?>
+ > + Internal Event: '; + echo ''; } ?> -- 2.17.1