add_action('wp_enqueue_scripts', 'glm_site_scripts');
+function glm_admin_scripts($hook) {
+ if ('post.php' != $hook) {
+ return;
+ }
+ wp_enqueue_script(
+ 'jquery-quicksearch',
+ get_template_directory_uri() . '/js/quicksearch/jquery.quicksearch.js',
+ 'jquery'
+ );
+}
+add_action('admin_enqueue_scripts','glm_admin_scripts');
// Start of the Contextual/Highlight Search functions
function mytheme_init() {
//}
//add_filter('the_content', 'custom_content');
+//function save_postdata($postid)
+//{
+// if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return false;
+// if ( !current_user_can( 'edit_page', $postid ) ) return false;
+// if(empty($postid) || $_POST['post_type'] != 'article' ) return false;
+//
+// if($_POST['action'] == 'editpost'){
+// delete_post_meta($postid, 'publish_in_frontpage');
+// }
+//
+// add_post_meta($postid, 'publish_in_frontpage', $_POST['publish_in_frontpage']);
+//}
+//add_action( "save_post_page", "glm_save_post_page" );
+//function glm_save_post_page( $post_ID )
+//{
+// if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
+// return $post_ID ;
+//
+// if( isset( $_POST['input_name'] ))
+// {
+// update_post_meta( $post_ID, '_w4_template', $_POST['input_name'] );
+// }
+//}
+
+add_action( 'add_meta_boxes', 'glm_add_meta_box' );
+
+// Register Your Meta box
+function glm_add_meta_box( $post )
+{
+ $screens = array( 'post', 'page' );
+
+ foreach ( $screens as $screen ) {
+
+ add_meta_box(
+ 'glm_member_categories', // this is HTML id
+ 'GLM MemberDB Categories',
+ 'glm_member_categories_callback', // the callback function
+ 'page', // register on post type = page
+ 'side', //
+ 'core'
+ );
+ }
+}
+function glm_member_categories_callback( $post )
+{
+ global $wpdb;
+ global $config;
+ require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataCategories.php');
+ $glmcat = new GlmDataCategories($wpdb, $config);
+ $dispcat = $glmcat->getList();
+ $dispcatsorted = $glmcat->sortParentChild($dispcat);
+
+$term = null;
+$btn = __('Search');
+if ( is_category() ) { $term = get_queried_object(); }
+echo '<form method="get" id="search_form">';
+echo '<ul>';
+echo '<input type="text" value="" name="s" id="s" />';
+if ($term) {
+ $btn = sprintf( __('Search in %s'), $term->name);
+?>
+<input type="hidden" value="<?php echo $term->term_id; ?>" name="cat" />
+<input type="hidden" value="<?php echo $term->name; ?>" name="catname" />
+<?php } ?>
+<input type="submit" id="search_submit" name="Search" value="<?php echo $btn; ?>"/>
+</div>
+</form>
+<?php
+
+// echo '<form method="post" action="' . bloginfo('url') . '/listing-search-results/">';
+// foreach($dispcatsorted as $cat){
+// $x = '<select name="glm-member-cat-search">';
+// $x .= '<option value="">Select '. ucfirst($dispcat) . '</option>';
+// foreach ($dispcatsorted as $cat ) {
+// $x .= '<option value="' . $cat['name'] . '">' . $cat['name'] . '</option>';
+// }
+// $x .= '</select>';
+// echo $x;
+// }
+// echo '<input type="submit"/>';
+// echo '</form>';
+
+ echo "<ul style='margin-left: 2px;border: 1px solid lightgrey;height: 200px;margin-left: 2px;overflow-y: scroll;'>";
+ foreach ($dispcatsorted as $cat ) {
+ if ($cat['parent'] == 1) {
+ echo '<span class="glm-indent"></span>';
+ }
+ echo '<li class="misc-pub-section misc-pub-section-last">'
+ . '<label><input type="checkbox"' . (!empty($value) ? ' checked="unchecked" ' : null) . 'value="1" name="' . $cat['name'] .'" /> ' . $cat['name'] .'</label>'
+ .'</li>';
+ }
+ echo "</ul>";
+// echo '<pre style="margin-left: 200px;">dispcatsorted: ' . print_r($dispcatsorted, true) . "</pre>";
+// echo "<div id='cattest'>catname: " . $dispcatsorted[1]['name'] . "</div>";
+// echo "<div id='cattest'>has parent: " . $dispcatsorted[1]['value'] . "</div>";
+// echo "<div id='cattest'>catname2: " . $dispcatsorted[2]['name'] . "</div>";
+// echo "<div id='cattest'>has parent: " . $dispcatsorted[2]['value'] . "</div>";
+ ?>
+
+ <script>
+ jQuery('input#s').quicksearch('#search_form .misc-pub-section label');
+ var qs = jQuery('input#id_search_list').quicksearch('ul#list_example li');
+ jQuery('ul#list_example').append('<li>Loaded with Ajax</li>');
+ qs.cache();
+
+ </script>
+<?php
+}
+
+add_action( 'save_post', 'glm_save_meta_box_data' );
+
+/* Fire our meta box setup function on the post editor screen. */
+add_action( 'load-post.php', 'glm_post_meta_boxes_setup' );
+add_action( 'load-post-new.php', 'glm_post_meta_boxes_setup' );
+/* Meta box setup function. */
+function glm_post_meta_boxes_setup() {
+
+ /* Add meta boxes on the 'add_meta_boxes' hook. */
+ add_action( 'add_meta_boxes', 'glm_add_post_meta_boxes' );
+}
+/* Display the post meta box. */
+function glm_post_class_meta_box( $object, $box ) { ?>
+
+ <?php wp_nonce_field( basename( __FILE__ ), 'glm_post_class_nonce' ); ?>
+
+ <p>
+ <label for="glm-post-class"><?php _e( "Add a custom CSS class, which will be applied to WordPress' post class.", 'example' ); ?></label>
+ <br />
+ <input class="widefat" type="text" name="glm-post-class" id="smashing-post-class" value="<?php echo esc_attr( get_post_meta( $object->ID, 'glm_post_class', true ) ); ?>" size="30" />
+ </p>
+<?php }
+
+ /* Save post meta on the 'save_post' hook. */
+add_action( 'save_post', 'glm_save_post_class_meta', 10, 2 );
+
?>
--- /dev/null
+(function($, window, document, undefined) {
+ $.fn.quicksearch = function (target, opt) {
+
+ var timeout, cache, rowcache, jq_results, val = '', e = this, options = $.extend({
+ delay: 100,
+ selector: null,
+ stripeRows: null,
+ loader: null,
+ noResults: '',
+ matchedResultsCount: 0,
+ bind: 'keyup',
+ onBefore: function () {
+ return;
+ },
+ onAfter: function () {
+ return;
+ },
+ show: function () {
+ this.style.display = "";
+ },
+ hide: function () {
+ this.style.display = "none";
+ },
+ prepareQuery: function (val) {
+ return val.toLowerCase().split(' ');
+ },
+ testQuery: function (query, txt, _row) {
+ for (var i = 0; i < query.length; i += 1) {
+ if (txt.indexOf(query[i]) === -1) {
+ return false;
+ }
+ }
+ return true;
+ }
+ }, opt);
+
+ this.go = function () {
+
+ var i = 0,
+ numMatchedRows = 0,
+ noresults = true,
+ query = options.prepareQuery(val),
+ val_empty = (val.replace(' ', '').length === 0);
+
+ for (var i = 0, len = rowcache.length; i < len; i++) {
+ if (val_empty || options.testQuery(query, cache[i], rowcache[i])) {
+ options.show.apply(rowcache[i]);
+ noresults = false;
+ numMatchedRows++;
+ } else {
+ options.hide.apply(rowcache[i]);
+ }
+ }
+
+ if (noresults) {
+ this.results(false);
+ } else {
+ this.results(true);
+ this.stripe();
+ }
+
+ this.matchedResultsCount = numMatchedRows;
+ this.loader(false);
+ options.onAfter();
+
+ return this;
+ };
+
+ /*
+ * External API so that users can perform search programatically.
+ * */
+ this.search = function (submittedVal) {
+ val = submittedVal;
+ e.trigger();
+ };
+
+ /*
+ * External API to get the number of matched results as seen in
+ * https://github.com/ruiz107/quicksearch/commit/f78dc440b42d95ce9caed1d087174dd4359982d6
+ * */
+ this.currentMatchedResults = function() {
+ return this.matchedResultsCount;
+ };
+
+ this.stripe = function () {
+
+ if (typeof options.stripeRows === "object" && options.stripeRows !== null)
+ {
+ var joined = options.stripeRows.join(' ');
+ var stripeRows_length = options.stripeRows.length;
+
+ jq_results.not(':hidden').each(function (i) {
+ $(this).removeClass(joined).addClass(options.stripeRows[i % stripeRows_length]);
+ });
+ }
+
+ return this;
+ };
+
+ this.strip_html = function (input) {
+ var output = input.replace(new RegExp('<[^<]+\>', 'g'), "");
+ output = $.trim(output.toLowerCase());
+ return output;
+ };
+
+ this.results = function (bool) {
+ if (typeof options.noResults === "string" && options.noResults !== "") {
+ if (bool) {
+ $(options.noResults).hide();
+ } else {
+ $(options.noResults).show();
+ }
+ }
+ return this;
+ };
+
+ this.loader = function (bool) {
+ if (typeof options.loader === "string" && options.loader !== "") {
+ (bool) ? $(options.loader).show() : $(options.loader).hide();
+ }
+ return this;
+ };
+
+ this.cache = function () {
+
+ jq_results = $(target);
+
+ if (typeof options.noResults === "string" && options.noResults !== "") {
+ jq_results = jq_results.not(options.noResults);
+ }
+
+ var t = (typeof options.selector === "string") ? jq_results.find(options.selector) : $(target).not(options.noResults);
+ cache = t.map(function () {
+ return e.strip_html(this.innerHTML);
+ });
+
+ rowcache = jq_results.map(function () {
+ return this;
+ });
+
+ /*
+ * Modified fix for sync-ing "val".
+ * Original fix https://github.com/michaellwest/quicksearch/commit/4ace4008d079298a01f97f885ba8fa956a9703d1
+ * */
+ val = val || this.val() || "";
+
+ return this.go();
+ };
+
+ this.trigger = function () {
+ this.loader(true);
+ options.onBefore();
+
+ window.clearTimeout(timeout);
+ timeout = window.setTimeout(function () {
+ e.go();
+ }, options.delay);
+
+ return this;
+ };
+
+ this.cache();
+ this.results(true);
+ this.stripe();
+ this.loader(false);
+
+ return this.each(function () {
+
+ /*
+ * Changed from .bind to .on.
+ * */
+ $(this).on(options.bind, function () {
+
+ val = $(this).val();
+ e.trigger();
+ });
+ });
+
+ };
+
+}(jQuery, this, document));