SearchWp.php 9.82 KB
<?php
/*
* Template Name: Search Wp Results
PDF Icons made by Flat Icons www.flaticon.com"
*/

global $user_ID;
get_currentuserinfo();
if (!$user_ID) {
    auth_redirect();
}

?>
    <style>
        .searchwp-highlight {
            background-color : #ccff00;
        }

        .screen-reader-text {
            clip        : rect(1px, 1px, 1px, 1px);
            clip-path   : polygon(0px 0px, 0px 0px, 0px 0px, 0px 0px);
            position    : absolute !important;
            white-space : nowrap;
            height      : 1px;
            width       : 1px;
            overflow    : hidden;
        }

        #brokercontent {
            height : auto !important;
        }

        .noButton #cboxLoadedContent {
            margin : 0
        }

        .noButton #cboxClose {
            display : none;
        }

        div#cboxOverlay {
            z-index : 999999999 !important;
        }

        #search_paginate_links {
            margin-top : 30px;
        }

    </style>
<?php get_header("brokerlanding");
global $wpdb;

?>
    <div id="brokercontent">
        <div class="row">
            <?php //include_once('broker_sidebar.php'); ?>
        </div>
        <div class="row">
            <?php //include_once('broker_sidebar_tab.php'); ?>
        </div>
        <div id="page-content">
            <?php
            if (function_exists(clean_custom_menus())) {
                clean_custom_menus();
            }
            ?>
            <h5 style="text-transform:uppercase;"><?php the_title(); ?></h5>
            <?php $query = isset($_REQUEST['searchvar']) ? sanitize_text_field($_REQUEST['searchvar']) : '';
            $swppg       = isset($_REQUEST['swppg']) ? absint($_REQUEST['swppg']) : 1;

            $highlighter = false;
            if (class_exists('SearchWP_Term_Highlight')) {
                $highlighter = new SearchWP_Term_Highlight();
            }
            $swp_query = new SWP_Query(
                array(
                    's'              => $_REQUEST['searchvar'],    // search query
                    'engine'         => 'default', // search engine
                    'posts_per_page' => 5,
                    'page'           => $swppg,
                )
            );

            $pagination = paginate_links(
                array(
                    'format'   => '?swppg=%#%',
                    'current'  => $swppg,
                    'total'    => $swp_query->max_num_pages,
                    'show_all' => false,
                )
            );

            $i = 0;
            if (!empty($swp_query->posts)) {
                foreach ($swp_query->posts as $post) {
                    setup_postdata($post);
                    if ('application/pdf' == get_post_mime_type($post->ID)) {
                        $icon      = '<img src="' . get_template_directory_uri(
                            ) . '/images/pdf-2.svg" width="20px" style="margin-right:10px;" />';
                        $url       = wp_get_attachment_url($post->ID);
                        $data      = 'hidemepdf' . $i . '';
                        $class     = 'pdfLink';
                        $permalink = "#";
                        ?>
                        <div style="display:none" class="hidemepdf" id="hidemepdf<?php echo $i; ?>" class="hidemepdf">
                            <?php echo do_shortcode(
                                '[pdfjs-viewer url=' . $url . ' search=' . $_REQUEST['searchvar'] . '  viewer_width=800px viewer_height=700px  fullscreen=true download=true print=true]'
                            ); ?>
                        </div>

                        <?php
                        $i++;
                    } else {
                        if($post->post_type == 'campaign') {
                            $icon      = '<img src="' . get_template_directory_uri(
                                ) . '/images/new_letter.svg" width="20px" style="margin-right:10px; margin-bottom:5px;" />';

                            $url    = WP_PLUGIN_URL . '/tenzing-campaign-monitor/';
                            $permalink = $url . 'campaignRetriever.php?campaignURL=' . get_post_meta(get_the_ID(), 'item_url', true);
                        } else {
                            $permalink = get_option('home') . '/search-result?id=' . get_the_ID();
                            $icon      = '';
                        }

                        $data      = '';
                        $class     = '';
                    }

                    ?>
                    <div class="post">
                        <h3>
                            <a href="<?php echo $permalink; ?>" class="<?php echo $class; ?>"
                               data="<?php echo $data; ?>" target="_blank">
                                <?php
                                echo $icon;
                                // highlight the title
                                $title = get_the_title();
                                if ($highlighter) {
                                    $title = $highlighter->apply_highlight($title, $_REQUEST['searchvar']);
                                }
                                echo $title;

                                ?>
                            </a>
                        </h3>
                        <?php
                        // output an excerpt
                        if ('application/pdf' == get_post_mime_type($post->ID)) {
                            $excerpt = htmlentities(get_post_meta($post->ID, 'searchwp_content', true));
                            $excerpt = trim(
                                preg_replace(
                                    '/ +/',
                                    ' ',
                                    preg_replace(
                                        '/[^A-Za-z0-9 ]/',
                                        ' ',
                                        urldecode(html_entity_decode(strip_tags($excerpt)))
                                    )
                                )
                            );


                        } else {
                            $excerpt = get_the_excerpt();
                        }
                        if ($highlighter) {
                            //  $excerpt = $highlighter->apply_highlight($excerpt, $query);
                            $strpos = strpos($excerpt, $query);
                        }

                        echo substr($excerpt, $strpos - 150, 350);
                        ?>
                        <div class="custom-field-content">
                            <?php
                            // output highlighted content from a Custom Field
                            $custom_field = get_post_meta(get_the_ID(), 'my_custom_field_key', true);
                            if ($highlighter) {
                                $custom_field = $highlighter->apply_highlight($custom_field, $query);
                            }
                            echo $custom_field;
                            ?>
                        </div>
                    </div>
                <?php }
                wp_reset_postdata();

                if ($swp_query->max_num_pages > 1) { ?>
                    <div id="search_paginate_links">
                        <nav class='custom-pagination'>
                            <?php echo wp_kses_post($pagination); ?>
                        </nav>
                    </div>
                <?php }
            } else {
                ?>
                <p>No results found.</p>
                <?php
            } ?>
        </div>
    </div>
<?php wp_nav_menu(
    array(
        'theme_location' => 'broker-footer',
        'container'      => 'nav',
        'container_id'   => 'broker-footer',
    )
);
?>
    <script>
        jQuery(document).ready(
            function ($) {
                $(".pdfLink").colorbox(
                    {
                        className: 'noButton', top: 150, width: 800, html: function () {
                        var pdfloc = $(this).attr('data');
                        var pdf = $('#' + pdfloc).html();
                        return pdf;
                    }
                    }
                );

                $(document).bind(
                    'cbox_complete', function () {

                        if ($(window).width() < 799) {
                            document.getElementById("fullscreen").click();
                        }

                        $('#colorbox,#cboxOverlay,#cboxWrapper').css('z-index', '99999999');
                    }
                );

                $("#findInput").val("<?php echo $_REQUEST['searchvar'];?>");

                $('<a id="cboxCloseBox" style="float:right;right:0px;position:absolute;" href="javascript:void(0)">close</a>').appendTo("#cboxTopRight");

                $("#cboxCloseBox").click(
                    function () {
                        document.getElementById("cboxClose").click();
                    }
                );

                var smallMenu = jQuery('.col-sm-smallMenu');
                // Change zIndex when a user hovers the side menu
                smallMenu.on('mouseenter',function() {
                    jQuery(this).css('zIndex', 999999);
                });

                smallMenu.on('mouseleave',function() {
                    setTimeout(function() {
                        smallMenu.css('zIndex', 0);
                    }, 500);
                });
            }
        );
    </script>
    <style>
        #cboxOverlay {
            position : fixed;
            width    : 100%;
            height   : 100%;
            z-index  : 9998;
        }

        html {
            margin-top : 32px !important;
        }
        .menu-broker_footer-container {
            float: right;
        }
       .menu-broker_footer-container #menu-broker_footer li {
            list-style-type: none;
            float: left;
            padding-right: 10px;
        }
    </style>
<?php get_footer(); ?>