Beispiel #1
0
 function parse($data, $query)
 {
     $this->Query = array();
     $this->SUBVERSION = sprintf('%s-%s', $query['handler'], $this->HANDLER_VERSION);
     $this->result = generic_parser_b($data['rawdata'], $this->REG_FIELDS, 'dmy');
     unset($this->result['registered']);
     if (isset($this->result['nodomain'])) {
         unset($this->result['nodomain']);
         $this->result['regrinfo']['registered'] = 'no';
         return $this->result;
     }
     $this->result['regrinfo']['registered'] = 'yes';
     if (!$this->deep_whois) {
         return $this->result;
     }
     unset($this->Query['handler']);
     if (isset($this->result['regyinfo']['whois'])) {
         $this->Query['server'] = $this->result['regyinfo']['whois'];
     }
     $subresult = $this->GetData($query);
     if (isset($subresult['rawdata'])) {
         $this->result['rawdata'] = $subresult['rawdata'];
         @($this->Query['handler'] = $this->REGISTRARS[$this->result['regyinfo']['registrar']]);
         if (!empty($this->Query['handler'])) {
             $this->Query['file'] = sprintf('whois.gtld.%s.php', $this->Query['handler']);
             $regrinfo = $this->Process($this->result['rawdata']);
             $this->result['regrinfo'] = merge_results($this->result['regrinfo'], $regrinfo);
         }
     }
     return $this->result;
 }
Beispiel #2
0
function run_the_queries($gcmaz_wpdb, $wpdb, $sql_search_terms, $rows_to_return, $pages_to_ignore_gcmaz, $pages_to_ignore_local)
{
    /*******************************************************
     * 2 Queries (gcmaz domain & local site)
     * 
     *   I.  unfinished - pages to ignore
     *   II. Prep vars for the statement
     *   III.  To filter or not
     *   IV.  The Queries
     *   V.   Functions (merge, object to array, sort)
     * 
     *  Notes about the prepare statement:
     *  a.    escape the wildcards %=escape and %=wildcard
     *  b.    the C, D, E  ... denote placeholders in the wpdb->prepare statement in order where 
     *  c.     the sql statement has %s, %d denoting "string" or "integer"
     *  d.    blueprint of the prepared statement
     *         $rows = $gcmaz_wpdb->get_results($gcmaz_wpdb->prepare( "the sql query", C, D, E, F, G, H, I, J, K, L, M, N, O, P)
     *  e.    variables used in "local" end with _local to avoid collision
     ********************************************************/
    // I.  array of pages on gcmaz we don't want to return
    // need to set this up as options in custom gcmaz plugin instead of hardcoded (select pages to ignore in search results)
    $pages_to_ignore_gcmaz = $pages_to_ignore_gcmaz;
    $pages_to_ignore_local = $pages_to_ignore_local;
    // II.  INIT VARS FOR THE SQL PREPARE STATEMENT
    $var_for_publish = "publish";
    $var_for_page = "page";
    $var_for_post = "post";
    $var_for_whats = "whats-happening";
    $var_for_concert = "concert";
    $var_for_community = "community-info";
    $var_for_splash = "splash-post";
    $var_for_publish_local = "publish";
    $var_for_page_local = "page";
    $var_for_post_local = "post";
    $var_for_splash_local = "splash-post";
    // III.  FILTER OR NOT
    // the default search isn't filtered, but it can be refined in which case the following vars will be populated
    //check for search filter vars - to filter by domain, posts, pages
    if (isset($_POST['filter_the_search'])) {
        // not default search, filters in play
        //domain
        if (isset($_POST['showDomain'])) {
            $showDomain = sanitize_text_field($_POST['showDomain']);
        } else {
            $showDomain = 'gcmaz';
        }
        //pages
        if (isset($_POST['showPages'])) {
            $showPages = true;
        } else {
            $showPages = false;
        }
        //posts
        if (isset($_POST['showPosts'])) {
            $showPosts = true;
        } else {
            $showPosts = false;
        }
        //news
        if (isset($_POST['showNews'])) {
            $showNews = true;
        } else {
            $showNews = false;
        }
    } else {
        // default search
        $showDomain = 'gcmaz';
        $showPosts = true;
        $showPages = true;
        $showNews = true;
    }
    // IV.  THE QUERIES
    //-----------------------------------------------------
    //     FILTERED SEARCH TO SHOW KAFF NEWS
    //-----------------------------------------------------
    // don't bother with local search
    // search gcmaz.com for KAFF News "posts" only
    if ($showDomain == 'news' || $showDomain == 'gcmaz' && $showNews == true && $showPosts == false && $showPages == false) {
        $sql = "\n                    SELECT ID, post_date, post_title, guid, post_name, post_type\n                    FROM {$gcmaz_wpdb->posts}\n                    WHERE (" . implode(' OR ', $sql_search_terms) . ")\n                        AND post_status = '%s'\n                        AND (post_type = '%s')\n                        AND ID NOT IN (" . implode($pages_to_ignore_gcmaz, ", ") . ")\n                    ORDER BY post_date DESC\n                    LIMIT {$rows_to_return}\n                     ";
        //for debugging
        //echo "<div style='background:yellow;color:red'>NEWS</div>";
        //$prepared_statement = $gcmaz_wpdb->prepare($sql, $var_for_publish, $var_for_post);
        //print_r($prepared_statement);
        $rows_gcmaz = $gcmaz_wpdb->get_results($gcmaz_wpdb->prepare($sql, $var_for_publish, $var_for_post));
        // convert to array
        $results = convert_results_to_array($rows_gcmaz);
        // dont need to merge, just sort
        $results = sort_results($results);
        return $results;
    }
    //--------------------------------------------------------------------------------
    //     DEFAULT SEARCH  & FILTERED SEARCH THAT SHOWS POSTS & PAGES
    //--------------------------------------------------------------------------------
    if ($showPosts == true && $showPages == true || $showPosts == false && $showPages == false) {
        if ($showDomain == 'local') {
            //LOCAL ONLY
            //SKIPS NEWS
            $sql_local = "\n                            SELECT ID, post_date, post_title, guid, post_name, post_type\n                            FROM {$wpdb->posts}\n                            WHERE (" . implode(' OR ', $sql_search_terms) . ")\n                                AND post_status = '%s'\n                                AND (post_type = '%s' OR post_type = '%s' OR post_type = '%s')\n                                AND ID NOT IN (" . implode($pages_to_ignore_local, ", ") . ")\n                            ORDER BY post_date DESC\n                            LIMIT {$rows_to_return}\n                             ";
            //for debugging
            //echo "<div style='background:yellow;color:red'>LOCAL PAGES AND POSTS, SKIPS NEWS</div>";
            //$prepared_statement_local = $wpdb->prepare($sql_local, $var_for_publish_local, $var_for_page_local, $var_for_post_local, $var_for_splash_local);
            //print_r($prepared_statement_local);
            $rows_local = $wpdb->get_results($wpdb->prepare($sql_local, $var_for_publish_local, $var_for_page_local, $var_for_post_local, $var_for_splash_local));
            // convert to array
            $rows_local = convert_results_to_array($rows_local);
            //sort results
            $results = sort_results($rows_local);
            return $results;
        } else {
            // ENTIRE DOMAIN
            // WITH NEWS
            if ($showNews == true) {
                // QUERY1) GCMAZ.com
                $sql = "\n                            SELECT ID, post_date, post_title, guid, post_name, post_type\n                            FROM {$gcmaz_wpdb->posts}\n                            WHERE (" . implode(' OR ', $sql_search_terms) . ")\n                                AND post_status = '%s'\n                                AND (post_type = '%s' OR post_type = '%s' OR post_type = '%s' OR post_type = '%s' OR post_type = '%s' OR post_type = '%s')\n                                AND ID NOT IN (" . implode($pages_to_ignore_gcmaz, ", ") . ")\n                            ORDER BY post_date DESC\n                            LIMIT {$rows_to_return}\n                             ";
                //for debugging
                //$prepared_statement = $gcmaz_wpdb->prepare($sql, $var_for_publish, $var_for_page, $var_for_post, $var_for_whats, $var_for_concert, $var_for_community, $var_for_splash);
                //print_r($prepared_statement);
                $rows_gcmaz = $gcmaz_wpdb->get_results($gcmaz_wpdb->prepare($sql, $var_for_publish, $var_for_page, $var_for_post, $var_for_whats, $var_for_concert, $var_for_community, $var_for_splash));
                // QUERY 2) LOCAL Search
                $sql_local = "\n                                SELECT ID, post_date, post_title, guid, post_name, post_type\n                                FROM {$wpdb->posts}\n                                WHERE (" . implode(' OR ', $sql_search_terms) . ")\n                                    AND post_status = '%s'\n                                    AND (post_type = '%s' OR post_type = '%s' OR post_type = '%s')\n                                    AND ID NOT IN (" . implode($pages_to_ignore_local, ", ") . ")\n                                ORDER BY post_date DESC\n                                LIMIT {$rows_to_return}\n                                 ";
                //for debugging
                //echo "<div style='background:yellow;color:red'>ALL PAGES AND POSTS WITH NEWS</div>";
                //$prepared_statement_local = $wpdb->prepare($sql_local, $var_for_publish_local, $var_for_page_local, $var_for_post_local, $var_for_splash_local);
                //print_r($prepared_statement_local);
                $rows_local = $wpdb->get_results($wpdb->prepare($sql_local, $var_for_publish_local, $var_for_page_local, $var_for_post_local, $var_for_splash_local));
                // convert to array
                $rows_gcmaz = convert_results_to_array($rows_gcmaz);
                $rows_local = convert_results_to_array($rows_local);
                // merge results
                $results = merge_results($rows_gcmaz, $rows_local);
                //sort results
                $results = sort_results($results);
                return $results;
            } else {
                // ENTIRE DOMAIN
                // WITHOUT NEWS
                // QUERY1) GCMAZ.com
                $sql = "\n                            SELECT ID, post_date, post_title, guid, post_name, post_type\n                            FROM {$gcmaz_wpdb->posts}\n                            WHERE (" . implode(' OR ', $sql_search_terms) . ")\n                                AND post_status = '%s'\n                                AND (post_type = '%s' OR post_type = '%s' OR post_type = '%s' OR post_type = '%s' OR post_type = '%s')\n                                AND ID NOT IN (" . implode($pages_to_ignore_gcmaz, ", ") . ")\n                            ORDER BY post_date DESC\n                            LIMIT {$rows_to_return}\n                             ";
                //for debugging
                //$prepared_statement = $gcmaz_wpdb->prepare($sql, $var_for_publish, $var_for_page, $var_for_whats, $var_for_concert, $var_for_community, $var_for_splash);
                //print_r($prepared_statement);
                $rows_gcmaz = $gcmaz_wpdb->get_results($gcmaz_wpdb->prepare($sql, $var_for_publish, $var_for_page, $var_for_whats, $var_for_concert, $var_for_community, $var_for_splash));
                // QUERY 2) LOCAL Search
                $sql_local = "\n                                SELECT ID, post_date, post_title, guid, post_name, post_type\n                                FROM {$wpdb->posts}\n                                WHERE (" . implode(' OR ', $sql_search_terms) . ")\n                                    AND post_status = '%s'\n                                    AND (post_type = '%s' OR post_type = '%s' OR post_type = '%s')\n                                    AND ID NOT IN (" . implode($pages_to_ignore_local, ", ") . ")\n                                ORDER BY post_date DESC\n                                LIMIT {$rows_to_return}\n                                 ";
                //for debugging
                //echo "<div style='background:yellow;color:red'>ALL PAGES AND POSTS WITHOUT NEWS</div>";
                //$prepared_statement_local = $wpdb->prepare($sql_local, $var_for_publish_local, $var_for_page_local, $var_for_post_local, $var_for_splash_local);
                //print_r($prepared_statement_local);
                $rows_local = $wpdb->get_results($wpdb->prepare($sql_local, $var_for_publish_local, $var_for_page_local, $var_for_post_local, $var_for_splash_local));
                // convert to array
                $rows_gcmaz = convert_results_to_array($rows_gcmaz);
                $rows_local = convert_results_to_array($rows_local);
                // merge results
                $results = merge_results($rows_gcmaz, $rows_local);
                //sort results
                $results = sort_results($results);
                return $results;
            }
        }
    }
    //-----------------------------------------------------
    //     FILTERED SEARCH TO SHOW POSTS NOT PAGES
    //-----------------------------------------------------
    if ($showPosts == true && $showPages == false) {
        if ($showDomain == 'local') {
            // LOCAL ONLY
            // SKIPS NEWS
            $sql_local = "\n                                SELECT ID, post_date, post_title, guid, post_name, post_type\n                                FROM {$wpdb->posts}\n                                WHERE (" . implode(' OR ', $sql_search_terms) . ")\n                                    AND post_status = '%s'\n                                    AND (post_type = '%s' OR post_type = '%s')\n                                    AND ID NOT IN (" . implode($pages_to_ignore_local, ", ") . ")\n                                ORDER BY post_date DESC\n                                LIMIT {$rows_to_return}\n                                 ";
            //for debugging
            //echo "<div style='background:yellow;color:red'>LOCAL POSTS, SKIPS NEWS</div>";
            $rows_local = $wpdb->get_results($wpdb->prepare($sql_local, $var_for_publish_local, $var_for_post_local, $var_for_splash_local));
            // convert to array
            $rows_local = convert_results_to_array($rows_local);
            //sort results
            $results = sort_results($rows_local);
            return $results;
        } else {
            //  ENTIRE DOMAIN
            // WITH NEWS
            if ($showNews == true) {
                // QUERY 1) gcmaz.com
                $sql = "\n                            SELECT ID, post_date, post_title, guid, post_name, post_type\n                            FROM {$gcmaz_wpdb->posts}\n                            WHERE (" . implode(' OR ', $sql_search_terms) . ")\n                                AND post_status = '%s'\n                                AND (post_type = '%s' OR post_type = '%s' OR post_type = '%s' OR post_type = '%s' OR post_type = '%s')\n                                AND ID NOT IN (" . implode($pages_to_ignore_gcmaz, ", ") . ")\n                            ORDER BY post_date DESC\n                            LIMIT {$rows_to_return}\n                             ";
                //for debugging
                //$prepared_statement = $gcmaz_wpdb->prepare($sql, $var_for_publish, $var_for_post, $var_for_whats, $var_for_concert, $var_for_community, $var_for_splash);
                //print_r($prepared_statement);
                // GET RESULTS  see notes (blueprint) for details
                $rows_gcmaz = $gcmaz_wpdb->get_results($gcmaz_wpdb->prepare($sql, $var_for_publish, $var_for_post, $var_for_whats, $var_for_concert, $var_for_community, $var_for_splash));
                // QUERY 2) LOCAL Search
                $sql_local = "\n                                    SELECT ID, post_date, post_title, guid, post_name, post_type\n                                    FROM {$wpdb->posts}\n                                    WHERE (" . implode(' OR ', $sql_search_terms) . ")\n                                        AND post_status = '%s'\n                                        AND (post_type = '%s' OR post_type = '%s')\n                                        AND ID NOT IN (" . implode($pages_to_ignore_local, ", ") . ")\n                                    ORDER BY post_date DESC\n                                    LIMIT {$rows_to_return}\n                                     ";
                //for debugging
                //echo "<div style='background:yellow;color:red'>ALL POSTS WITH NEWS</div>";
                //$prepared_statement_local = $wpdb->prepare($sql_local, $var_for_publish_local, $var_for_post_local, $var_for_splash_local);
                //print_r($prepared_statement_local);
                $rows_local = $wpdb->get_results($wpdb->prepare($sql_local, $var_for_publish_local, $var_for_post_local, $var_for_splash_local));
                // convert to array
                $rows_gcmaz = convert_results_to_array($rows_gcmaz);
                $rows_local = convert_results_to_array($rows_local);
                // merge results
                $results = merge_results($rows_gcmaz, $rows_local);
                //sort results
                $results = sort_results($results);
                return $results;
            } else {
                // ENTIRE DOMAIN
                // WITHOUT NEWS
                // QUERY 1) gcmaz.com
                $sql = "\n                            SELECT ID, post_date, post_title, guid, post_name, post_type\n                            FROM {$gcmaz_wpdb->posts}\n                            WHERE (" . implode(' OR ', $sql_search_terms) . ")\n                                AND post_status = '%s'\n                                AND (post_type = '%s' OR post_type = '%s' OR post_type = '%s' OR post_type = '%s')\n                                AND ID NOT IN (" . implode($pages_to_ignore_gcmaz, ", ") . ")\n                            ORDER BY post_date DESC\n                            LIMIT {$rows_to_return}\n                             ";
                //for debugging
                //$prepared_statement = $gcmaz_wpdb->prepare($sql, $var_for_publish, $var_for_whats, $var_for_concert, $var_for_community, $var_for_splash);
                //print_r($prepared_statement);
                // GET RESULTS  see notes (blueprint) for details
                $rows_gcmaz = $gcmaz_wpdb->get_results($gcmaz_wpdb->prepare($sql, $var_for_publish, $var_for_whats, $var_for_concert, $var_for_community, $var_for_splash));
                // QUERY 2) LOCAL Search
                $sql_local = "\n                                    SELECT ID, post_date, post_title, guid, post_name, post_type\n                                    FROM {$wpdb->posts}\n                                    WHERE (" . implode(' OR ', $sql_search_terms) . ")\n                                        AND post_status = '%s'\n                                        AND (post_type = '%s' OR post_type = '%s')\n                                        AND ID NOT IN (" . implode($pages_to_ignore_local, ", ") . ")\n                                    ORDER BY post_date DESC\n                                    LIMIT {$rows_to_return}\n                                     ";
                //for debugging
                //echo "<div style='background:yellow;color:red'>ALL POSTS WITHOUT NEWS</div>";
                //$prepared_statement_local = $wpdb->prepare($sql_local, $var_for_publish_local, $var_for_post_local, $var_for_splash_local);
                //print_r($prepared_statement_local);
                $rows_local = $wpdb->get_results($wpdb->prepare($sql_local, $var_for_publish_local, $var_for_post_local, $var_for_splash_local));
                // convert to array
                $rows_gcmaz = convert_results_to_array($rows_gcmaz);
                $rows_local = convert_results_to_array($rows_local);
                // merge results
                $results = merge_results($rows_gcmaz, $rows_local);
                //sort results
                $results = sort_results($results);
                return $results;
            }
        }
    }
    //-----------------------------------------------------
    //     FILTERED SEARCH TO SHOW PAGES NOT POSTS
    //-----------------------------------------------------
    if ($showPosts == false && $showPages == true) {
        if ($showDomain == 'local') {
            // LOCAL ONLY
            // SKIPS NEWS
            $sql_local = "\n                            SELECT ID, post_date, post_title, guid, post_name, post_type\n                            FROM {$wpdb->posts}\n                            WHERE (" . implode(' OR ', $sql_search_terms) . ")\n                                AND post_status = '%s'\n                                AND (post_type = '%s')\n                                AND ID NOT IN (" . implode($pages_to_ignore_local, ", ") . ")\n                            ORDER BY post_date DESC\n                            LIMIT {$rows_to_return}\n                             ";
            //for debugging
            //echo "<div style='background:yellow;color:red'>LOCAL PAGES, SKIPS NEWS</div>";
            //$prepared_statement_local = $wpdb->prepare($sql_local, $var_for_publish_local, $var_for_post_local, $var_for_splash_local);
            //print_r($prepared_statement_local);
            $rows_local = $wpdb->get_results($wpdb->prepare($sql_local, $var_for_publish_local, $var_for_page_local));
            // convert to array
            $rows_local = convert_results_to_array($rows_local);
            //sort results
            $results = sort_results($rows_local);
            return $results;
        } else {
            // ENTIRE DOMAIN
            // WITH NEWS
            if ($showNews == true) {
                // QUERY 1) gcmaz.com
                $sql = "\n                            SELECT ID, post_date, post_title, guid, post_name, post_type\n                            FROM {$gcmaz_wpdb->posts}\n                            WHERE (" . implode(' OR ', $sql_search_terms) . ")\n                                AND post_status = '%s'\n                                AND (post_type = '%s' OR post_type = '%s')\n                                AND ID NOT IN (" . implode($pages_to_ignore_gcmaz, ", ") . ")\n                            ORDER BY post_date DESC\n                            LIMIT {$rows_to_return}\n                             ";
                //for debugging
                //$prepared_statement = $gcmaz_wpdb->prepare($sql, $var_for_publish, $var_for_page);
                //print_r($prepared_statement);
                $rows_gcmaz = $gcmaz_wpdb->get_results($gcmaz_wpdb->prepare($sql, $var_for_publish, $var_for_post, $var_for_page));
                // QUERY 2) local
                // --------------------------
                // PREPARE THE STATEMENT
                $sql_local = "\n                                SELECT ID, post_date, post_title, guid, post_name, post_type\n                                FROM {$wpdb->posts}\n                                WHERE (" . implode(' OR ', $sql_search_terms) . ")\n                                    AND post_status = '%s'\n                                    AND (post_type = '%s')\n                                    AND ID NOT IN (" . implode($pages_to_ignore_local, ", ") . ")\n                                ORDER BY post_date DESC\n                                LIMIT {$rows_to_return}\n                                 ";
                //for debugging
                //echo "<div style='background:yellow;color:red'>ALL PAGES WITH NEWS</div>";
                //$prepared_statement_local = $wpdb->prepare($sql_local, $var_for_publish_local, $var_for_post_local, $var_for_splash_local);
                //print_r($prepared_statement_local);
                //GET RESULTS  see notes (blueprint) for details
                $rows_local = $wpdb->get_results($wpdb->prepare($sql_local, $var_for_publish_local, $var_for_page_local));
                // convert to array
                $rows_gcmaz = convert_results_to_array($rows_gcmaz);
                $rows_local = convert_results_to_array($rows_local);
                // merge results
                $results = merge_results($rows_gcmaz, $rows_local);
                //sort results
                $results = sort_results($results);
                return $results;
            } else {
                // ENTIRE DOMAIN
                // WITHOUT NEWS
                // QUERY 1) gcmaz.com
                $sql = "\n                            SELECT ID, post_date, post_title, guid, post_name, post_type\n                            FROM {$gcmaz_wpdb->posts}\n                            WHERE (" . implode(' OR ', $sql_search_terms) . ")\n                                AND post_status = '%s'\n                                AND (post_type = '%s')\n                                AND ID NOT IN (" . implode($pages_to_ignore_gcmaz, ", ") . ")\n                            ORDER BY post_date DESC\n                            LIMIT {$rows_to_return}\n                             ";
                //for debugging
                //$prepared_statement = $gcmaz_wpdb->prepare($sql, $var_for_publish, $var_for_page);
                //print_r($prepared_statement);
                $rows_gcmaz = $gcmaz_wpdb->get_results($gcmaz_wpdb->prepare($sql, $var_for_publish, $var_for_page));
                // QUERY 2) local
                // --------------------------
                // PREPARE THE STATEMENT
                $sql_local = "\n                                SELECT ID, post_date, post_title, guid, post_name, post_type\n                                FROM {$wpdb->posts}\n                                WHERE (" . implode(' OR ', $sql_search_terms) . ")\n                                    AND post_status = '%s'\n                                    AND (post_type = '%s')\n                                    AND ID NOT IN (" . implode($pages_to_ignore_local, ", ") . ")\n                                ORDER BY post_date DESC\n                                LIMIT {$rows_to_return}\n                                 ";
                //for debugging
                //echo "<div style='background:yellow;color:red'>ALL PAGES WITHOUT NEWS</div>";
                //$prepared_statement_local = $wpdb->prepare($sql_local, $var_for_publish_local, $var_for_post_local, $var_for_splash_local);
                //print_r($prepared_statement_local);
                //GET RESULTS  see notes (blueprint) for details
                $rows_local = $wpdb->get_results($wpdb->prepare($sql_local, $var_for_publish_local, $var_for_page_local));
                // convert to array
                $rows_gcmaz = convert_results_to_array($rows_gcmaz);
                $rows_local = convert_results_to_array($rows_local);
                // merge results
                $results = merge_results($rows_gcmaz, $rows_local);
                //sort results
                $results = sort_results($results);
                return $results;
            }
        }
    }
}