/** * Deletes all plugin terms. * * @return void */ private function delete_terms() { $query = "\nSELECT term_id\nFROM {$this->wpdb->term_taxonomy}\nWHERE taxonomy = %s\nLIMIT 500"; $query = $this->wpdb->prepare($query, $this->taxonomy); while ($term_ids = $this->wpdb->get_col($query)) { foreach ($term_ids as $term_id) { wp_delete_term($term_id, $this->taxonomy); } } }
/** * Fetch related sites. * * @param int $site_id * @return array */ public function get_related_sites($site_id = 0) { $site_id = $this->empty_site_id_fallback($site_id); if (isset($this->related_sites[$site_id])) { return $this->related_sites[$site_id]; } $sql = $this->get_related_sites_sql($site_id); $this->related_sites[$site_id] = $this->wpdb->get_col($sql); return $this->related_sites[$site_id]; }
/** * Uninstalls all plugin data. * * @return void */ public function uninstall() { if (is_multisite()) { foreach ($this->wpdb->get_col("SELECT blog_id FROM {$this->wpdb->blogs}") as $blog_id) { switch_to_blog($blog_id); $this->delete_options(); restore_current_blog(); } } else { $this->delete_options(); } }
/** * Performs an SQL query assigning all terms to their correct language equivalent if it exists. * This should only be run after the previous functionality in here has finished. * Afterwards the term counts are recalculated globally, since term assignments bypassing the WordPress Core, * will not trigger any sort of update on those. */ private function reassign_terms() { $update_query = $this->wpdb->prepare("UPDATE {$this->wpdb->term_relationships} AS o,\n\t\t\t\t\t{$this->wpdb->prefix}icl_translations AS ic,\n\t\t\t\t\t{$this->wpdb->prefix}icl_translations AS iw,\n\t\t\t\t\t{$this->wpdb->prefix}icl_translations AS ip,\n\t\t\t\t\t{$this->wpdb->posts} AS p\n\t\t\t\t\t\tSET o.term_taxonomy_id = ic.element_id\n\t\t\t\t\t\tWHERE ic.trid = iw.trid\n\t\t\t\t\t\t\tAND ic.element_type = iw.element_type\n\t\t\t\t\t\t\tAND iw.element_id = o.term_taxonomy_id\n\t\t\t\t\t\t\tAND ic.language_code = ip.language_code\n\t\t\t\t\t\t\tAND ip.element_type = CONCAT('post_', p.post_type)\n\t\t\t\t\t\t\tAND ip.element_id = p.ID\n\t\t\t\t\t\t\tAND o.object_id = p.ID\n\t\t\t\t\t\t\tAND o.term_taxonomy_id != ic.element_id\n\t\t\t\t\t\t\tAND iw.element_type = %s", 'tax_' . $this->taxonomy); $rows_affected = $this->wpdb->query($update_query); if ($rows_affected) { $term_ids = $this->wpdb->get_col($this->wpdb->prepare("SELECT term_taxonomy_id FROM {$this->wpdb->term_taxonomy} WHERE taxonomy = %s", $this->taxonomy)); // Do not run the count update on taxonomies that are not actually registered as proper taxonomy objects, e.g. WooCommerce Product Attributes. $taxonomy_object = $this->sitepress->get_wp_api()->get_taxonomy($this->taxonomy); if ($taxonomy_object && isset($taxonomy_object->object_type)) { $this->sitepress->get_wp_api()->wp_update_term_count($term_ids, $this->taxonomy); } } }
/** * Deletes all remote MultilingualPress nav menu items linking to the (to-be-deleted) site with the given ID. * * @param int $deleted_site_id The ID of the to-be-deleted site. * * @return void */ public function delete_items_for_deleted_site($deleted_site_id) { $query = "\nSELECT blog_id\nFROM {$this->wpdb->blogs}\nWHERE blog_id != %d"; $query = $this->wpdb->prepare($query, $deleted_site_id); foreach ($this->wpdb->get_col($query) as $site_id) { switch_to_blog($site_id); $query = "\nSELECT p.ID\nFROM {$this->wpdb->posts} p\nINNER JOIN {$this->wpdb->postmeta} pm\nON p.ID = pm.post_id\nWHERE pm.meta_key = %s\n\tAND pm.meta_value = %s"; $query = $this->wpdb->prepare($query, $this->meta_key, $deleted_site_id); foreach ($this->wpdb->get_col($query) as $post_id) { wp_delete_post($post_id, true); } restore_current_blog(); } }
/** * Returns an array of tables in the database. * * if multisite && mainsite: all tables of the site * if multisite && subsite: all tables of current blog * if single site : all tabkes of the site * * @access public * @return array */ public function get_tables() { if (function_exists('is_multisite') && is_multisite()) { if (is_main_site()) { $tables = $this->wpdb->get_col("SHOW TABLES LIKE'" . $this->wpdb->base_prefix . "%'"); } else { $blog_id = get_current_blog_id(); $tables = $this->wpdb->get_col("SHOW TABLES LIKE '" . $this->wpdb->base_prefix . absint($blog_id) . "\\_%'"); } } else { $tables = $this->wpdb->get_col("SHOW TABLES LIKE'" . $this->wpdb->base_prefix . "%'"); } return $tables; }
/** * Uninstalls all plugin data. * * @return void */ public function uninstall() { $option_name = $this->option->get_name(); if (is_multisite()) { foreach ($this->wpdb->get_col("SELECT blog_id FROM {$this->wpdb->blogs}") as $blog_id) { switch_to_blog($blog_id); delete_option($this->version_option_name); delete_option($option_name); } restore_current_blog(); } else { delete_option($this->version_option_name); delete_option($option_name); } }
/** * Execute the query, with the current variables. * * @since 3.1.0 */ public function query() { $qv =& $this->query_vars; $this->request = "SELECT {$this->query_fields} {$this->query_from} {$this->query_where} {$this->query_orderby} {$this->query_limit}"; if (is_array($qv['fields']) || 'all' == $qv['fields']) { $this->results = $this->db->get_results($this->request); } else { $this->results = $this->db->get_col($this->request); } /** * Filters SELECT FOUND_ROWS() query for the current WP_User_Query instance. * * @since 3.2.0 * * @param string $sql The SELECT FOUND_ROWS() query for the current WP_User_Query. */ if (isset($qv['count_total']) && $qv['count_total']) { $this->total_users = $this->db->get_var(apply_filters('found_users_query', 'SELECT FOUND_ROWS()')); } if (!$this->results) { return; } if ('all_with_meta' == $qv['fields']) { cache_users($this->results); $r = array(); foreach ($this->results as $userid) { $r[$userid] = new WP_User($userid, '', $qv['blog_id']); } $this->results = $r; } elseif ('all' == $qv['fields']) { foreach ($this->results as $key => $user) { $this->results[$key] = new WP_User($user, '', $qv['blog_id']); } } }
/** * Fetch related sites. * * @param int $site_id * @param bool $public TRUE if you want just public sites. * @return array */ public function get_related_sites($site_id = 0, $public = TRUE) { $site_id = $this->empty_site_id_fallback($site_id); $key = "{$site_id}-" . (int) $public; if (isset($this->related_sites[$key])) { return $this->related_sites[$key]; } // There are no public sites. No need to run a query in this case. if ($public && array() === $this->public_site_ids) { $this->related_sites[$key] = array(); return array(); } $sql = $this->get_related_sites_sql($site_id, $public); $this->related_sites[$key] = $this->wpdb->get_col($sql); return $this->related_sites[$key]; }
public function on_sub($sub_id) { if ($this->ID == 0) { return false; } $result = $this->_wpdb->get_col(sprintf('SELECT rel_id FROM %s WHERE user_id = %d AND sub_id = %d', MEMBERSHIP_TABLE_RELATIONS, $this->ID, $sub_id)); return apply_filters('membership_on_sub', !empty($result), $sub_id, $this->ID); }
/** * Returns all ids from DB suitable for given restriction. * E.g. all comment_id values where comment_post_id = 1 * @param string $entityName * @param array $where * @return array */ private function getIdsForRestriction($entityName, $where) { $idColumnName = $this->dbSchemaInfo->getEntityInfo($entityName)->idColumnName; $table = $this->dbSchemaInfo->getPrefixedTableName($entityName); $sql = "SELECT {$idColumnName} FROM {$table} WHERE "; $sql .= join(" AND ", array_map(function ($column) { return "`{$column}` = %s"; }, array_keys($where))); $ids = $this->database->get_col($this->database->prepare($sql, $where)); return $ids; }
function global_site_search_output($content) { global $wp_query; if (!isset($wp_query->query_vars['namespace']) || $wp_query->query_vars['namespace'] != 'gss' || $wp_query->query_vars['type'] != 'search') { return $content; } // We are on a search results page $global_site_search_per_page = get_site_option('global_site_search_per_page', '10'); $global_site_search_post_type = get_site_option('global_site_search_post_type', 'post'); //=====================================// // $phrase = isset($wp_query->query_vars['search']) ? urldecode($wp_query->query_vars['search']) : ''; if (empty($phrase) && isset($_REQUEST['phrase'])) { $phrase = trim($_REQUEST['phrase']); } if (empty($phrase)) { ob_start(); global_site_search_form(); $content .= ob_get_clean(); return $content; } $theauthor = get_user_by('login', $phrase); if (is_object($theauthor)) { $author_id = $theauthor->ID; } $parameters = array(); if (isset($author_id) && is_numeric($author_id) && $author_id != 0) { $parameters['author'] = $author_id; } else { $parameters['s'] = $phrase; } $parameters['post_type'] = $global_site_search_post_type != 'all' ? $global_site_search_post_type : $this->db->get_col("SELECT post_type FROM {$this->db->base_prefix}network_posts GROUP BY post_type"); // Add in the start and end numbers $parameters['posts_per_page'] = absint($global_site_search_per_page); // Set the page number if (!isset($wp_query->query_vars['paged']) || $wp_query->query_vars['paged'] <= 1) { $parameters['paged'] = 1; $start = 0; } else { $parameters['paged'] = absint($wp_query->query_vars['paged']); $start = $global_site_search_per_page * ($wp_query->query_vars['paged'] - 1); } //=====================================// ob_start(); $network_query_posts = network_query_posts($parameters); include global_site_search_locate_template('global-site-search.php'); $content .= ob_get_clean(); return $content; }
function get_tables_saved($con_type, $username, $password, $database, $host) { global $wpdb; if ($con_type == 'local') { $query = "SHOW TABLES"; $tables = $wpdb->get_col($query); } else { if ($con_type == 'remote') { $wpdb_temp = new wpdb($username, $password, $database, $host); $query = "SHOW TABLES"; $tables = $wpdb_temp->get_col($query); } } //$wpdb= new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST); return $tables; }
/** * Return a record as an array based on a given SQL select statement keys and params list. * * Executes wpdb get_row using the specified SQL statement. * If more than one row is returned by the query, only the specified row is returned by the function, but all rows are cached for later use. * Returns NULL if no result is found * * @link https://codex.wordpress.org/Class_Reference/wpdb WordPress WPDB Class * * @param string[] $commandList * @param mixed[] $params * @param int $offset * @param mixed $type the type of object/array/etc. to return see wpdb get_row. * @param string $mode = get_row or get_col to fetch a single row or multiple rows of a single column * @return mixed the database array_a or object. */ function get_Record($commandList, $params = array(), $offset = 0, $type = ARRAY_A, $mode = 'get_row') { $this->is_Extended(); $query = $this->get_SQL($commandList); // No placeholders, just call direct with no prepare // if (strpos($query, '%') !== false) { $query = $this->db->prepare($query, $params); } // get_row (default) or get_col based on the mode if ($mode === 'get_col') { $results = $this->db->get_col($query, $offset); } else { $results = $this->db->get_row($query, $type, $offset); } return $results; }
function allowed_redirect_hosts($allowed_hosts) { if (!empty($_REQUEST['redirect_to'])) { $redirect_url = parse_url($_REQUEST['redirect_to']); if (isset($redirect_url['host'])) { $network_home_url = parse_url(network_home_url()); if ($redirect_url['host'] != $network_home_url['host']) { $pos = strpos($redirect_url['host'], '.'); if ($pos !== false && substr($redirect_url['host'], $pos + 1) === $network_home_url['host']) { $allowed_hosts[] = $redirect_url['host']; } $bid = $this->db->get_var("SELECT blog_id FROM {$this->dmtable} WHERE domain = '{$redirect_url['host']}' ORDER BY id LIMIT 1"); if ($bid) { $allowed_hosts[] = $redirect_url['host']; } } } } else { $domains = (array) $this->db->get_col(sprintf("SELECT domain FROM %s WHERE blog_id = %d ORDER BY id ASC", DOMAINMAP_TABLE_MAP, $this->db->blogid)); $original = $this->db->get_var("SELECT domain FROM {$this->db->blogs} WHERE blog_id = " . intval($this->db->blogid)); $allowed_hosts = array_unique(array_merge($allowed_hosts, $domains, array($original))); } return $allowed_hosts; }
/** * Checks if some tables with the given prefix exist in the database * * @param string $dbUser * @param string $dbPassword * @param string $dbName * @param string $dbHost * @param string $dbPrefix * @return bool */ private function someWpTablesExist($dbUser, $dbPassword, $dbName, $dbHost, $dbPrefix) { $wpdb = new \wpdb($dbUser, $dbPassword, $dbName, $dbHost); $wpdb->set_prefix($dbPrefix); $tables = $wpdb->get_col("SHOW TABLES LIKE '{$dbPrefix}_%'"); $wpTables = array_intersect($tables, $wpdb->tables()); return count($wpTables) > 0; }
/** * Transforms a single query, from one field to another. * * @since 3.2.0 * * @param array $query The single query. Passed by reference. * @param string $resulting_field The resulting field. Accepts 'slug', 'name', 'term_taxonomy_id', * or 'term_id'. Default 'term_id'. */ public function transform_query(&$query, $resulting_field) { if (empty($query['terms'])) { return; } if ($query['field'] == $resulting_field) { return; } $resulting_field = sanitize_key($resulting_field); switch ($query['field']) { case 'slug': case 'name': foreach ($query['terms'] as &$term) { /* * 0 is the $term_id parameter. We don't have a term ID yet, but it doesn't * matter because `sanitize_term_field()` ignores the $term_id param when the * context is 'db'. */ $term = "'" . esc_sql(sanitize_term_field($query['field'], $term, 0, $query['taxonomy'], 'db')) . "'"; } $terms = implode(",", $query['terms']); $terms = $this->db->get_col("\n\t\t\t\t\tSELECT {$this->db->term_taxonomy}.{$resulting_field}\n\t\t\t\t\tFROM {$this->db->term_taxonomy}\n\t\t\t\t\tINNER JOIN {$this->db->terms} USING (term_id)\n\t\t\t\t\tWHERE taxonomy = '{$query['taxonomy']}'\n\t\t\t\t\tAND {$this->db->terms}.{$query['field']} IN ({$terms})\n\t\t\t\t"); break; case 'term_taxonomy_id': $terms = implode(',', array_map('intval', $query['terms'])); $terms = $this->db->get_col("\n\t\t\t\t\tSELECT {$resulting_field}\n\t\t\t\t\tFROM {$this->db->term_taxonomy}\n\t\t\t\t\tWHERE term_taxonomy_id IN ({$terms})\n\t\t\t\t"); break; default: $terms = implode(',', array_map('intval', $query['terms'])); $terms = $this->db->get_col("\n\t\t\t\t\tSELECT {$resulting_field}\n\t\t\t\t\tFROM {$this->db->term_taxonomy}\n\t\t\t\t\tWHERE taxonomy = '{$query['taxonomy']}'\n\t\t\t\t\tAND term_id IN ({$terms})\n\t\t\t\t"); } if ('AND' == $query['operator'] && count($terms) < count($query['terms'])) { $query = new WP_Error('inexistent_terms', __('Inexistent terms.')); return; } $query['terms'] = $terms; $query['field'] = $resulting_field; }
/** * Used internally to get a list of site IDs matching the query vars. * * @since 4.6.0 * @access protected * * @return int|array A single count of site IDs if a count query. An array of site IDs if a full query. */ protected function get_site_ids() { $order = $this->parse_order($this->query_vars['order']); // Disable ORDER BY with 'none', an empty array, or boolean false. if (in_array($this->query_vars['orderby'], array('none', array(), false), true)) { $orderby = ''; } elseif (!empty($this->query_vars['orderby'])) { $ordersby = is_array($this->query_vars['orderby']) ? $this->query_vars['orderby'] : preg_split('/[,\\s]/', $this->query_vars['orderby']); $orderby_array = array(); foreach ($ordersby as $_key => $_value) { if (!$_value) { continue; } if (is_int($_key)) { $_orderby = $_value; $_order = $order; } else { $_orderby = $_key; $_order = $_value; } $parsed = $this->parse_orderby($_orderby); if (!$parsed) { continue; } if ('site__in' === $_orderby || 'network__in' === $_orderby) { $orderby_array[] = $parsed; continue; } $orderby_array[] = $parsed . ' ' . $this->parse_order($_order); } $orderby = implode(', ', $orderby_array); } else { $orderby = "blog_id {$order}"; } $number = absint($this->query_vars['number']); $offset = absint($this->query_vars['offset']); if (!empty($number)) { if ($offset) { $limits = 'LIMIT ' . $offset . ',' . $number; } else { $limits = 'LIMIT ' . $number; } } if ($this->query_vars['count']) { $fields = 'COUNT(*)'; } else { $fields = 'blog_id'; } // Parse site IDs for an IN clause. $site_id = absint($this->query_vars['ID']); if (!empty($site_id)) { $this->sql_clauses['where']['ID'] = $this->db->prepare('blog_id = %d', $site_id); } // Parse site IDs for an IN clause. if (!empty($this->query_vars['site__in'])) { $this->sql_clauses['where']['site__in'] = "blog_id IN ( " . implode(',', wp_parse_id_list($this->query_vars['site__in'])) . ' )'; } // Parse site IDs for a NOT IN clause. if (!empty($this->query_vars['site__not_in'])) { $this->sql_clauses['where']['site__not_in'] = "blog_id NOT IN ( " . implode(',', wp_parse_id_list($this->query_vars['site__not_in'])) . ' )'; } $network_id = absint($this->query_vars['network_id']); if (!empty($network_id)) { $this->sql_clauses['where']['network_id'] = $this->db->prepare('site_id = %d', $network_id); } // Parse site network IDs for an IN clause. if (!empty($this->query_vars['network__in'])) { $this->sql_clauses['where']['network__in'] = 'site_id IN ( ' . implode(',', wp_parse_id_list($this->query_vars['network__in'])) . ' )'; } // Parse site network IDs for a NOT IN clause. if (!empty($this->query_vars['network__not_in'])) { $this->sql_clauses['where']['network__not_in'] = 'site_id NOT IN ( ' . implode(',', wp_parse_id_list($this->query_vars['network__not_in'])) . ' )'; } if (!empty($this->query_vars['domain'])) { $this->sql_clauses['where']['domain'] = $this->db->prepare('domain = %s', $this->query_vars['domain']); } // Parse site domain for an IN clause. if (is_array($this->query_vars['domain__in'])) { $this->sql_clauses['where']['domain__in'] = "domain IN ( '" . implode("', '", $this->db->_escape($this->query_vars['domain__in'])) . "' )"; } // Parse site domain for a NOT IN clause. if (is_array($this->query_vars['domain__not_in'])) { $this->sql_clauses['where']['domain__not_in'] = "domain NOT IN ( '" . implode("', '", $this->db->_escape($this->query_vars['domain__not_in'])) . "' )"; } if (!empty($this->query_vars['path'])) { $this->sql_clauses['where']['path'] = $this->db->prepare('path = %s', $this->query_vars['path']); } // Parse site path for an IN clause. if (is_array($this->query_vars['path__in'])) { $this->sql_clauses['where']['path__in'] = "path IN ( '" . implode("', '", $this->db->_escape($this->query_vars['path__in'])) . "' )"; } // Parse site path for a NOT IN clause. if (is_array($this->query_vars['path__not_in'])) { $this->sql_clauses['where']['path__not_in'] = "path NOT IN ( '" . implode("', '", $this->db->_escape($this->query_vars['path__not_in'])) . "' )"; } if (is_numeric($this->query_vars['archived'])) { $archived = absint($this->query_vars['archived']); $this->sql_clauses['where']['archived'] = $this->db->prepare("archived = %d ", $archived); } if (is_numeric($this->query_vars['mature'])) { $mature = absint($this->query_vars['mature']); $this->sql_clauses['where']['mature'] = $this->db->prepare("mature = %d ", $mature); } if (is_numeric($this->query_vars['spam'])) { $spam = absint($this->query_vars['spam']); $this->sql_clauses['where']['spam'] = $this->db->prepare("spam = %d ", $spam); } if (is_numeric($this->query_vars['deleted'])) { $deleted = absint($this->query_vars['deleted']); $this->sql_clauses['where']['deleted'] = $this->db->prepare("deleted = %d ", $deleted); } if (is_numeric($this->query_vars['public'])) { $public = absint($this->query_vars['public']); $this->sql_clauses['where']['public'] = $this->db->prepare("public = %d ", $public); } // Falsey search strings are ignored. if (strlen($this->query_vars['search'])) { $search_columns = array(); if ($this->query_vars['search_columns']) { $search_columns = array_intersect($this->query_vars['search_columns'], array('domain', 'path')); } if (!$search_columns) { $search_columns = array('domain', 'path'); } /** * Filters the columns to search in a WP_Site_Query search. * * The default columns include 'domain' and 'path. * * @since 4.6.0 * * @param array $search_columns Array of column names to be searched. * @param string $search Text being searched. * @param WP_Site_Query $this The current WP_Site_Query instance. */ $search_columns = apply_filters('site_search_columns', $search_columns, $this->query_vars['search'], $this); $this->sql_clauses['where']['search'] = $this->get_search_sql($this->query_vars['search'], $search_columns); } $date_query = $this->query_vars['date_query']; if (!empty($date_query) && is_array($date_query)) { $this->date_query = new WP_Date_Query($date_query, 'registered'); $this->sql_clauses['where']['date_query'] = preg_replace('/^\\s*AND\\s*/', '', $this->date_query->get_sql()); } $join = ''; $where = implode(' AND ', $this->sql_clauses['where']); $pieces = array('fields', 'join', 'where', 'orderby', 'limits', 'groupby'); /** * Filters the site query clauses. * * @since 4.6.0 * * @param array $pieces A compacted array of site query clauses. * @param WP_Site_Query &$this Current instance of WP_Site_Query, passed by reference. */ $clauses = apply_filters_ref_array('sites_clauses', array(compact($pieces), &$this)); $fields = isset($clauses['fields']) ? $clauses['fields'] : ''; $join = isset($clauses['join']) ? $clauses['join'] : ''; $where = isset($clauses['where']) ? $clauses['where'] : ''; $orderby = isset($clauses['orderby']) ? $clauses['orderby'] : ''; $limits = isset($clauses['limits']) ? $clauses['limits'] : ''; $groupby = isset($clauses['groupby']) ? $clauses['groupby'] : ''; if ($where) { $where = 'WHERE ' . $where; } if ($groupby) { $groupby = 'GROUP BY ' . $groupby; } if ($orderby) { $orderby = "ORDER BY {$orderby}"; } $found_rows = ''; if (!$this->query_vars['no_found_rows']) { $found_rows = 'SQL_CALC_FOUND_ROWS'; } $this->sql_clauses['select'] = "SELECT {$found_rows} {$fields}"; $this->sql_clauses['from'] = "FROM {$this->db->blogs} {$join}"; $this->sql_clauses['groupby'] = $groupby; $this->sql_clauses['orderby'] = $orderby; $this->sql_clauses['limits'] = $limits; $this->request = "{$this->sql_clauses['select']} {$this->sql_clauses['from']} {$where} {$this->sql_clauses['groupby']} {$this->sql_clauses['orderby']} {$this->sql_clauses['limits']}"; if ($this->query_vars['count']) { return intval($this->db->get_var($this->request)); } $site_ids = $this->db->get_col($this->request); return array_map('intval', $site_ids); }
$quizID = 9; $courseID = 3; $unitID = 680; */ /* check: WPCW_quizzes_getAllQuizzesForCourse($courseID); WPCW_quizzes_getQuizResultsForUser($userID, $quizIDListForSQL); WPCW_quizzes_updateQuizResults($quizResultsSoFar) WPCW_quizzes_getUserResultsForQuiz($userID, $unitID, $quizID) */ // $bla = WPCW_quizzes_getAllQuizzesForCourse($courseID); // geht $str .= "<p>1.) Welche Courses gibt es?</p>"; $courses = $wpdb->get_col("\n\t \tSELECT * \n\t \tFROM {$wpcwdb->courses}\n\t \tORDER BY course_id;\n\t "); foreach ($courses as $course_key => $course_value) { $str .= "Course " . $course_value . "<br>"; } //var_dump($courses); $strk = ""; $str .= "<p>2.) Alle Courses durchgehe und seine Quizze holen</p>"; foreach ($courses as $course_key => $course_value) { $str .= "<h3>Course " . $course_value . "</h3>"; $str .= "<table class = \"quiz\">"; $str .= "<tr class=\"quiz\"><td class=\"separator_course\" class=\"quiz\">Start Course " . $course_value . "</td></tr>"; $quizzes = WPCW_quizzes_getAllQuizzesForCourse($course_value); $fez1 = 0; foreach ($quizzes as $quiz_key => $quiz_value) { $fez1++; $str .= "<tr><td class=\"separator_quiz\">Start Quiz ID " . $quiz_value->quiz_id . "</td></tr>";
/** * Used internally to get a list of comment IDs matching the query vars. * * @since 4.4.0 * @access protected */ protected function get_comment_ids() { // Assemble clauses related to 'comment_approved'. $approved_clauses = array(); // 'status' accepts an array or a comma-separated string. $status_clauses = array(); $statuses = $this->query_vars['status']; if (!is_array($statuses)) { $statuses = preg_split('/[\\s,]+/', $statuses); } // 'any' overrides other statuses. if (!in_array('any', $statuses)) { foreach ($statuses as $status) { switch ($status) { case 'hold': $status_clauses[] = "comment_approved = '0'"; break; case 'approve': $status_clauses[] = "comment_approved = '1'"; break; case 'all': case '': $status_clauses[] = "( comment_approved = '0' OR comment_approved = '1' )"; break; default: $status_clauses[] = $this->db->prepare("comment_approved = %s", $status); break; } } if (!empty($status_clauses)) { $approved_clauses[] = '( ' . implode(' OR ', $status_clauses) . ' )'; } } // User IDs or emails whose unapproved comments are included, regardless of $status. if (!empty($this->query_vars['include_unapproved'])) { $include_unapproved = $this->query_vars['include_unapproved']; // Accepts arrays or comma-separated strings. if (!is_array($include_unapproved)) { $include_unapproved = preg_split('/[\\s,]+/', $include_unapproved); } $unapproved_ids = $unapproved_emails = array(); foreach ($include_unapproved as $unapproved_identifier) { // Numeric values are assumed to be user ids. if (is_numeric($unapproved_identifier)) { $approved_clauses[] = $this->db->prepare("( user_id = %d AND comment_approved = '0' )", $unapproved_identifier); // Otherwise we match against email addresses. } else { $approved_clauses[] = $this->db->prepare("( comment_author_email = %s AND comment_approved = '0' )", $unapproved_identifier); } } } // Collapse comment_approved clauses into a single OR-separated clause. if (!empty($approved_clauses)) { if (1 === count($approved_clauses)) { $this->sql_clauses['where']['approved'] = $approved_clauses[0]; } else { $this->sql_clauses['where']['approved'] = '( ' . implode(' OR ', $approved_clauses) . ' )'; } } $order = 'ASC' == strtoupper($this->query_vars['order']) ? 'ASC' : 'DESC'; // Disable ORDER BY with 'none', an empty array, or boolean false. if (in_array($this->query_vars['orderby'], array('none', array(), false), true)) { $orderby = ''; } elseif (!empty($this->query_vars['orderby'])) { $ordersby = is_array($this->query_vars['orderby']) ? $this->query_vars['orderby'] : preg_split('/[,\\s]/', $this->query_vars['orderby']); $orderby_array = array(); $found_orderby_comment_ID = false; foreach ($ordersby as $_key => $_value) { if (!$_value) { continue; } if (is_int($_key)) { $_orderby = $_value; $_order = $order; } else { $_orderby = $_key; $_order = $_value; } if (!$found_orderby_comment_ID && in_array($_orderby, array('comment_ID', 'comment__in'))) { $found_orderby_comment_ID = true; } $parsed = $this->parse_orderby($_orderby); if (!$parsed) { continue; } if ('comment__in' === $_orderby) { $orderby_array[] = $parsed; continue; } $orderby_array[] = $parsed . ' ' . $this->parse_order($_order); } // If no valid clauses were found, order by comment_date_gmt. if (empty($orderby_array)) { $orderby_array[] = "{$this->db->comments}.comment_date_gmt {$order}"; } // To ensure determinate sorting, always include a comment_ID clause. if (!$found_orderby_comment_ID) { $comment_ID_order = ''; // Inherit order from comment_date or comment_date_gmt, if available. foreach ($orderby_array as $orderby_clause) { if (preg_match('/comment_date(?:_gmt)*\\ (ASC|DESC)/', $orderby_clause, $match)) { $comment_ID_order = $match[1]; break; } } // If no date-related order is available, use the date from the first available clause. if (!$comment_ID_order) { foreach ($orderby_array as $orderby_clause) { if (false !== strpos('ASC', $orderby_clause)) { $comment_ID_order = 'ASC'; } else { $comment_ID_order = 'DESC'; } break; } } // Default to DESC. if (!$comment_ID_order) { $comment_ID_order = 'DESC'; } $orderby_array[] = "{$this->db->comments}.comment_ID {$comment_ID_order}"; } $orderby = implode(', ', $orderby_array); } else { $orderby = "{$this->db->comments}.comment_date_gmt {$order}"; } $number = absint($this->query_vars['number']); $offset = absint($this->query_vars['offset']); if (!empty($number)) { if ($offset) { $limits = 'LIMIT ' . $offset . ',' . $number; } else { $limits = 'LIMIT ' . $number; } } if ($this->query_vars['count']) { $fields = 'COUNT(*)'; } else { $fields = "{$this->db->comments}.comment_ID"; } $post_id = absint($this->query_vars['post_id']); if (!empty($post_id)) { $this->sql_clauses['where']['post_id'] = $this->db->prepare('comment_post_ID = %d', $post_id); } // Parse comment IDs for an IN clause. if (!empty($this->query_vars['comment__in'])) { $this->sql_clauses['where']['comment__in'] = "{$this->db->comments}.comment_ID IN ( " . implode(',', wp_parse_id_list($this->query_vars['comment__in'])) . ' )'; } // Parse comment IDs for a NOT IN clause. if (!empty($this->query_vars['comment__not_in'])) { $this->sql_clauses['where']['comment__not_in'] = "{$this->db->comments}.comment_ID NOT IN ( " . implode(',', wp_parse_id_list($this->query_vars['comment__not_in'])) . ' )'; } // Parse comment parent IDs for an IN clause. if (!empty($this->query_vars['parent__in'])) { $this->sql_clauses['where']['parent__in'] = 'comment_parent IN ( ' . implode(',', wp_parse_id_list($this->query_vars['parent__in'])) . ' )'; } // Parse comment parent IDs for a NOT IN clause. if (!empty($this->query_vars['parent__not_in'])) { $this->sql_clauses['where']['parent__not_in'] = 'comment_parent NOT IN ( ' . implode(',', wp_parse_id_list($this->query_vars['parent__not_in'])) . ' )'; } // Parse comment post IDs for an IN clause. if (!empty($this->query_vars['post__in'])) { $this->sql_clauses['where']['post__in'] = 'comment_post_ID IN ( ' . implode(',', wp_parse_id_list($this->query_vars['post__in'])) . ' )'; } // Parse comment post IDs for a NOT IN clause. if (!empty($this->query_vars['post__not_in'])) { $this->sql_clauses['where']['post__not_in'] = 'comment_post_ID NOT IN ( ' . implode(',', wp_parse_id_list($this->query_vars['post__not_in'])) . ' )'; } if ('' !== $this->query_vars['author_email']) { $this->sql_clauses['where']['author_email'] = $this->db->prepare('comment_author_email = %s', $this->query_vars['author_email']); } if ('' !== $this->query_vars['author_url']) { $this->sql_clauses['where']['author_url'] = $this->db->prepare('comment_author_url = %s', $this->query_vars['author_url']); } if ('' !== $this->query_vars['karma']) { $this->sql_clauses['where']['karma'] = $this->db->prepare('comment_karma = %d', $this->query_vars['karma']); } // Filtering by comment_type: 'type', 'type__in', 'type__not_in'. $raw_types = array('IN' => array_merge((array) $this->query_vars['type'], (array) $this->query_vars['type__in']), 'NOT IN' => (array) $this->query_vars['type__not_in']); $comment_types = array(); foreach ($raw_types as $operator => $_raw_types) { $_raw_types = array_unique($_raw_types); foreach ($_raw_types as $type) { switch ($type) { // An empty translates to 'all', for backward compatibility case '': case 'all': break; case 'comment': case 'comments': $comment_types[$operator][] = "''"; break; case 'pings': $comment_types[$operator][] = "'pingback'"; $comment_types[$operator][] = "'trackback'"; break; default: $comment_types[$operator][] = $this->db->prepare('%s', $type); break; } } if (!empty($comment_types[$operator])) { $types_sql = implode(', ', $comment_types[$operator]); $this->sql_clauses['where']['comment_type__' . strtolower(str_replace(' ', '_', $operator))] = "comment_type {$operator} ({$types_sql})"; } } $parent = $this->query_vars['parent']; if ($this->query_vars['hierarchical'] && !$parent) { $parent = 0; } if ('' !== $parent) { $this->sql_clauses['where']['parent'] = $this->db->prepare('comment_parent = %d', $parent); } if (is_array($this->query_vars['user_id'])) { $this->sql_clauses['where']['user_id'] = 'user_id IN (' . implode(',', array_map('absint', $this->query_vars['user_id'])) . ')'; } elseif ('' !== $this->query_vars['user_id']) { $this->sql_clauses['where']['user_id'] = $this->db->prepare('user_id = %d', $this->query_vars['user_id']); } // Falsy search strings are ignored. if (strlen($this->query_vars['search'])) { $search_sql = $this->get_search_sql($this->query_vars['search'], array('comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content')); // Strip leading 'AND'. $this->sql_clauses['where']['search'] = preg_replace('/^\\s*AND\\s*/', '', $search_sql); } // If any post-related query vars are passed, join the posts table. $join_posts_table = false; $plucked = wp_array_slice_assoc($this->query_vars, array('post_author', 'post_name', 'post_parent')); $post_fields = array_filter($plucked); if (!empty($post_fields)) { $join_posts_table = true; foreach ($post_fields as $field_name => $field_value) { // $field_value may be an array. $esses = array_fill(0, count((array) $field_value), '%s'); $this->sql_clauses['where'][$field_name] = $this->db->prepare(" {$this->db->posts}.{$field_name} IN (" . implode(',', $esses) . ')', $field_value); } } // 'post_status' and 'post_type' are handled separately, due to the specialized behavior of 'any'. foreach (array('post_status', 'post_type') as $field_name) { $q_values = array(); if (!empty($this->query_vars[$field_name])) { $q_values = $this->query_vars[$field_name]; if (!is_array($q_values)) { $q_values = explode(',', $q_values); } // 'any' will cause the query var to be ignored. if (in_array('any', $q_values, true) || empty($q_values)) { continue; } $join_posts_table = true; $esses = array_fill(0, count($q_values), '%s'); $this->sql_clauses['where'][$field_name] = $this->db->prepare(" {$this->db->posts}.{$field_name} IN (" . implode(',', $esses) . ")", $q_values); } } // Comment author IDs for an IN clause. if (!empty($this->query_vars['author__in'])) { $this->sql_clauses['where']['author__in'] = 'user_id IN ( ' . implode(',', wp_parse_id_list($this->query_vars['author__in'])) . ' )'; } // Comment author IDs for a NOT IN clause. if (!empty($this->query_vars['author__not_in'])) { $this->sql_clauses['where']['author__not_in'] = 'user_id NOT IN ( ' . implode(',', wp_parse_id_list($this->query_vars['author__not_in'])) . ' )'; } // Post author IDs for an IN clause. if (!empty($this->query_vars['post_author__in'])) { $join_posts_table = true; $this->sql_clauses['where']['post_author__in'] = 'post_author IN ( ' . implode(',', wp_parse_id_list($this->query_vars['post_author__in'])) . ' )'; } // Post author IDs for a NOT IN clause. if (!empty($this->query_vars['post_author__not_in'])) { $join_posts_table = true; $this->sql_clauses['where']['post_author__not_in'] = 'post_author NOT IN ( ' . implode(',', wp_parse_id_list($this->query_vars['post_author__not_in'])) . ' )'; } $join = ''; if ($join_posts_table) { $join .= "JOIN {$this->db->posts} ON {$this->db->posts}.ID = {$this->db->comments}.comment_post_ID"; } if (!empty($this->meta_query_clauses)) { $join .= $this->meta_query_clauses['join']; // Strip leading 'AND'. $this->sql_clauses['where']['meta_query'] = preg_replace('/^\\s*AND\\s*/', '', $this->meta_query_clauses['where']); if (!$this->query_vars['count']) { $groupby = "{$this->db->comments}.comment_ID"; } } if (!empty($this->query_vars['date_query']) && is_array($this->query_vars['date_query'])) { $this->date_query = new WP_Date_Query($this->query_vars['date_query'], 'comment_date'); $this->sql_clauses['where']['date_query'] = preg_replace('/^\\s*AND\\s*/', '', $this->date_query->get_sql()); } $where = implode(' AND ', $this->sql_clauses['where']); $pieces = array('fields', 'join', 'where', 'orderby', 'limits', 'groupby'); /** * Filters the comment query clauses. * * @since 3.1.0 * * @param array $pieces A compacted array of comment query clauses. * @param WP_Comment_Query &$this Current instance of WP_Comment_Query, passed by reference. */ $clauses = apply_filters_ref_array('comments_clauses', array(compact($pieces), &$this)); $fields = isset($clauses['fields']) ? $clauses['fields'] : ''; $join = isset($clauses['join']) ? $clauses['join'] : ''; $where = isset($clauses['where']) ? $clauses['where'] : ''; $orderby = isset($clauses['orderby']) ? $clauses['orderby'] : ''; $limits = isset($clauses['limits']) ? $clauses['limits'] : ''; $groupby = isset($clauses['groupby']) ? $clauses['groupby'] : ''; $this->filtered_where_clause = $where; if ($where) { $where = 'WHERE ' . $where; } if ($groupby) { $groupby = 'GROUP BY ' . $groupby; } if ($orderby) { $orderby = "ORDER BY {$orderby}"; } $found_rows = ''; if (!$this->query_vars['no_found_rows']) { $found_rows = 'SQL_CALC_FOUND_ROWS'; } $this->sql_clauses['select'] = "SELECT {$found_rows} {$fields}"; $this->sql_clauses['from'] = "FROM {$this->db->comments} {$join}"; $this->sql_clauses['groupby'] = $groupby; $this->sql_clauses['orderby'] = $orderby; $this->sql_clauses['limits'] = $limits; $this->request = "{$this->sql_clauses['select']} {$this->sql_clauses['from']} {$where} {$this->sql_clauses['groupby']} {$this->sql_clauses['orderby']} {$this->sql_clauses['limits']}"; if ($this->query_vars['count']) { return intval($this->db->get_var($this->request)); } else { $comment_ids = $this->db->get_col($this->request); return array_map('intval', $comment_ids); } }
/** * Fetch a single column of the results from the supplied SQL statement. * * @param string|\Dewdrop\Db\Select $sql * @param array $bind * @return array */ public function fetchCol($sql, $bind = array()) { return $this->execWpdb($this->wpdb->get_col($this->adapter->prepare($sql, $bind))); }
/** * Get the IDs of all forms in our table. * * @author Jeremy Pry * @return array Form IDs. */ public function get_form_ids() { return $this->wpdb->get_col("SELECT `id` FROM {$this->prefixed_table_name}"); }
/** * Retrieve one column from the database. * * @see wpdb::get_col() */ public function getCol($query = null, $x = 0) { return $this->db->get_col($query, $x); }
/** * @see wpdb::get_col() */ function get_col($query = null, $x = 0) { if ($this->ignore_query($query)) { return parent::get_col($query, $x); } $this->init_cache(); $key = md5('get_col(' . $query . ',' . $x . ')'); $result = null; $cache = $this->get_cache_item($key); if ($cache) { $result = $cache['result']; $this->last_result = $cache['last_result']; $this->num_rows = $cache['num_rows']; } else { $result = parent::get_col($query, $x); $cache = array('result' => $result, 'last_result' => $this->last_result, 'num_rows' => $this->num_rows); $this->set_cache_item($key, $cache); } return $result; }
/** * Diese Funktion holt alle Quiz-Ergebnisse aller User. * Danach werden alle, die bestanden haben, aber nicht 100% erreicht haben, auf 100% gesetzt, inkl. der richtigen Antworten * (die on-thy-fly aus der DB geholt werden) * @author GW * Die Fremdfunktion WPCW_quizzes_getAllQuizzesForCourse($course_value) wird benutzt, sie gehört zu Courseware */ function erase_progress() { $strk = ""; $strk = "<h2>Alle bestandenen Quiz-Ergebnisse auf 100% ändern</h2>"; require_once '../wp-config.php'; include_once '../wp-content/plugins/wp-courseware/lib/common.inc.php'; include_once '../wp-content/plugins/wp-courseware/lib/constants.inc.php'; include_once '../wp-content/plugins/wp-courseware/lib/email_defaults.inc.php'; if (!defined('ABSPATH')) { define('ABSPATH', dirname(__FILE__) . '/'); } $wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST); // "Richtige" Tabelle mit der Backup-Tabelle überschreiben, wenn Haken gesetzt if ($_REQUEST['restore_backup'] == 1) { require_once '../wp-admin/includes/upgrade.php'; $sql = "DROP TABLE wp13_wpcw_user_progress_quizzes"; $wpdb->query($sql); $sql = "CREATE TABLE wp13_wpcw_user_progress_quizzes LIKE wp13_wpcw_user_progress_quizzes_backup"; $wpdb->query($sql); $sql = "INSERT INTO wp13_wpcw_user_progress_quizzes SELECT * FROM wp13_wpcw_user_progress_quizzes_backup"; $wpdb->query($sql); echo "wp13_wpcw_user_progress_quizzes_backup aus Backup wiederhergestellt"; } $strk .= "<form name=\"form1\" method=\"post\" action=\"" . $_SERVER['REQUEST_URI'] . "\">"; $str .= "<p>1.) Welche Courses gibt es?</p>"; //$strk .= "<p>1.) Welche Courses gibt es?</p>"; $courses = $wpdb->get_col("\n\t SELECT * \n\t FROM wp13_wpcw_courses\n\t ORDER BY course_id;\n\t "); foreach ($courses as $course_key => $course_value) { $str .= "Course " . $course_value . "<br>"; } $str .= "<p>2.) Alle Courses durchgehe und seine Quizze holen</p>"; //$strk .= "<p>2.) Alle Courses durchgehe und seine Quizze holen</p>"; foreach ($courses as $course_key => $course_value) { $str .= "<h3>Course " . $course_value . "</h3>"; $str .= "<table class = \"quiz\">"; $str .= "<tr class=\"quiz\"><td class=\"separator_course\" class=\"quiz\">Start Course " . $course_value . "</td></tr>"; $quizzes = WPCW_quizzes_getAllQuizzesForCourse($course_value); $fez1 = 0; foreach ($quizzes as $quiz_key => $quiz_value) { $fez1++; $str .= "<tr><td class=\"separator_quiz\">Start Quiz ID " . $quiz_value->quiz_id . "</td></tr>"; $str .= "<tr><td class=\"separator_quiz\" colspan=2 style=\"font-weight: bold;\">" . $fez1 . ".) Quiz ID: " . $quiz_value->quiz_id . " - " . $quiz_value->quiz_title . "</td></tr>"; $str .= "<tr><td class=\"separator_quiz\" colspan=2>QuizPassMark: " . $quiz_value->quiz_pass_mark . "</td></tr>"; $str .= "<tr><td> </td></tr>"; $quizIDListForSQL = "(" . $quiz_value->quiz_id . ")"; $sql = "SELECT * \n\t FROM wp13_wpcw_user_progress_quizzes\n\t WHERE user_id = " . $userID . " \n\t AND quiz_id = " . $quiz_value->quiz_id . " \n\t ORDER BY quiz_completed_date;\n\t "; $sql = "SELECT * \n\t FROM wp13_wpcw_user_progress_quizzes\n\t WHERE quiz_id = " . $quiz_value->quiz_id . " \n\t ORDER BY quiz_completed_date;\n\t "; //$str .= $sql; $results = $wpdb->get_results($sql); //echo "<pre>";var_dump($results);echo "</pre>"; $str .= "<tr><td><table><tr><td>Results for: "; if ($results == NULL) { $str .= "keine</td></tr></table></td></tr>"; } else { $str .= "<tr><td><table><tr><td>"; $fez2 = 0; foreach ($results as $result_key => $result_value) { $update = ""; $fez2++; $strk .= "Kurs " . $course_value . " - Quiz " . $quiz_value->quiz_id . " - User " . $result_value->user_id; //var_dump($result_value); $str .= "<tr><td><br></td></tr>"; $str .= "<tr><td class=\"separator_attempt\">Start User " . $result_value->user_id . " Attempt " . $result_value->quiz_attempt_id . "</td></tr>"; $strk .= " - Attempt " . $result_value->quiz_attempt_id; $str .= "<tr><td class=\"separator_attempt\" colspan=2 style=\"font-weight: bold;\">" . $fez2 . ".) Attempt on : " . $result_value->quiz_completed_date . " - " . $quiz_value->quiz_title . "</td></tr>"; $str .= "<tr><td class=\"separator_attempt\" colspan=2>Grade: " . $result_value->quiz_grade . "</td></tr>"; $str .= "<tr><td> </td></tr>"; //$str .= "Data: ".$result_value->quiz_data."<br>"; $data_seri = $result_value->quiz_data; $data_unseri = unserialize($data_seri); $strk .= " - Braucht " . $quiz_value->quiz_pass_mark . " % - Hat: " . $result_value->quiz_grade . "% "; if ($result_value->quiz_grade == 100) { $str .= "<tr><td style=\"background: #aca;\">Bestanden mit 100% - keine Änderung nötig-> Braucht " . $quiz_value->quiz_pass_mark . " % - Hat erreicht: " . $result_value->quiz_grade . "%</td></tr>"; $strk .= "<span style=\"background: #aca;\">Bestanden mit 100% - keine Änderung nötig</span>"; } elseif ($result_value->quiz_grade >= $quiz_value->quiz_pass_mark) { $str .= "<tr><td style=\"background: #caa;\">Bestanden, aber nicht mit 100% - Änderung nötig -> Braucht " . $quiz_value->quiz_pass_mark . " % - Hat erreicht: " . $result_value->quiz_grade . "%</td></tr>"; $strk .= "<span style=\"background: #caa;\">Bestanden, aber nicht mit 100% - Änderung nötig</span>"; // Jetzt Änderung foreach ($data_unseri as $data_unseri_key => $data_unseri_value) { //$str .= "data_unseri_value ". $data_unseri_key . " - " . $data_unseri_value . "<br>"; //$str .= "<pre>";var_dump($data_unseri_key); $str .= "</pre>"; $str .= "<tr><td style=\"background: #eee;\">their_answer: " . $data_unseri[$data_unseri_key]["their_answer"] . " - correct: " . $data_unseri[$data_unseri_key]["correct"]; if ($data_unseri[$data_unseri_key]["their_answer"] != $data_unseri[$data_unseri_key]["correct"]) { $str .= " <span style=\"background:red; color:white;\">FALSCH. Also kopieren</span> "; $data_unseri[$data_unseri_key]["their_answer"] = $data_unseri[$data_unseri_key]["correct"]; $str .= "their_answer: " . $data_unseri[$data_unseri_key]["their_answer"] . " - correct: " . $data_unseri[$data_unseri_key]["correct"]; $str .= "<br>"; /* $sql = "SELECT question_data_answers FROM wp13_wpcw_quizzes_questions WHERE question_id = ".$data_unseri_key; $str .= $sql; $tar_result = $wpdb->get_results($sql); $tar_result = $tar_result[0]; //$tar_result = unserialize($tar_result[0]); $tar_result = $tar_result->question_data_answers; $tar_result = unserialize($tar_result); foreach ($tar_result AS $tar_result_key => $tar_result_value) { $tar_result_value = $tar_result_value["answer"]; $tar_result_value = md5($tar_result_value); echo "<pre>";var_dump ($tar_result_value);echo "</pre>"; } */ $sql = "SELECT question_correct_answer\n\t FROM wp13_wpcw_quizzes_questions\n\t WHERE question_id = " . $data_unseri_key; $qca_result = $wpdb->get_row($sql); //$qca_result = $qca_result[0]; //$qca_result = unserialize($qca_result[0]); //$qca_result = $qca_result->question_data_answers; //$qca_result = unserialize($qca_result); //echo "<pre>";var_dump ($qca_result);echo "</pre>"; /* foreach ($tar_result AS $qca_result_key => $qca_result_value) { $qca_result_value = $qca_result_value["answer"]; $qca_result_value = md5($qca_result_value); echo "<pre>";var_dump ($qca_result_value);echo "</pre>"; } */ //$str .= $sql; $data_unseri[$data_unseri_key]["question_correct_answer"] = $qca_result->question_correct_answer; $str .= "question_correct_answer: " . $data_unseri[$data_unseri_key]["question_correct_answer"] . " - correct: " . $qca_result->question_correct_answer; $str .= "<br>"; $data_unseri[$data_unseri_key]["got_right"] = "yes"; $str .= "got_right: " . $data_unseri[$data_unseri_key]["got_right"]; $echo_reseri = 1; $data_reseri = serialize($data_unseri); // Hier jetzt Schreibvorgang in DB // Herkömmliches UPDATE: $update = "UPDATE wp13_wpcw_user_progress_quizzes SET \n\t quiz_data = '" . $data_reseri . "',\n\t quiz_correct_questions = " . $result_value->quiz_question_total . ", \n\t quiz_grade = 100.00 \n\t WHERE quiz_id = " . $quiz_value->quiz_id . " \n\t AND user_id = " . $result_value->user_id . " \n\t AND quiz_attempt_id = " . $result_value->quiz_attempt_id; $update_action = 0; if ($_POST['cleanup_now'] == "yes" && $_REQUEST['restore_backup'] != 1) { //$strk .= "<br><tr><td>".$update."</td></tr>"; $wpdb->update('wp13_wpcw_user_progress_quizzes', array('quiz_data' => $data_reseri, 'quiz_correct_questions' => $result_value->quiz_question_total, 'quiz_grade' => '100.00'), array('quiz_id' => $quiz_value->quiz_id, 'user_id' => $result_value->user_id, 'quiz_attempt_id' => $result_value->quiz_attempt_id)); // quiz_completion_time_seconds = 0 ??? notwendig? $update_action = 1; } // Ende Schreibvorgang } else { $str .= " <span style=\"background:green; color:white;\">RICHTIG</span>."; $echo_reseri = 0; $data_reseri = serialize($data_unseri); } $str .= "</td></tr>"; } // Ende Änderung if ($update_action == 1) { $strk .= " <span style=\"background: #f5c34c;\">OK, geändert</span>"; } } else { $str .= "<tr><td style=\"background: #aca;\">Nicht bestanden - keine Änderung nötig. Braucht " . $quiz_value->quiz_pass_mark . " % - Hat erreicht: " . $result_value->quiz_grade . "%</td></tr>"; $strk .= "<span style=\"background: #aca;\">Nicht bestanden - keine Änderung nötig</span>"; } $str .= "<tr><td> </td></tr>"; //if ($echo_reseri==1) $str .= "<tr><td>".$data_reseri."</td></tr>"; $strk .= "<br>"; $str .= "<tr><td class=\"separator_attempt\">Ende User " . $result_value->user_id . " Attempt " . $fez2 . "</td></tr>"; } $str .= "</td></tr></table></td></tr>"; } $str .= "<tr><td class=\"separator_quiz\">Ende Quiz ID " . $course_value . "</td></tr><tr><td><br></td></tr>"; } $str .= "<tr><td class=\"separator_course\">Ende Course " . $course_value . "</td></tr>"; // Ende Course $str .= "</table><br>"; } $strk .= "<input type=\"hidden\" id=\"cleanup_now\" name=\"cleanup_now\" value=\"yes\" />"; $strk .= "<input type=\"checkbox\" id=\"restore_backup\" name=\"restore_backup\" value=\"1\" />Backup wiederherstellen (zum Testen)"; $strk .= "<input type=\"submit\" value=\"Jetzt bereinigen\" />"; $strk .= "<input name=\"action\" value=\"insert\" type=\"hidden\" />"; $strk .= "</form>"; echo $strk . "<br><br>"; //echo $str; }
/** * Retrieve the posts based on query variables. * * There are a few filters and actions that can be used to modify the post * database query. * * @since 1.5.0 * @access public * * @return array List of posts. */ public function get_posts() { $this->parse_query(); /** * Fires after the query variable object is created, but before the actual query is run. * * Note: If using conditional tags, use the method versions within the passed instance * (e.g. $this->is_main_query() instead of is_main_query()). This is because the functions * like is_main_query() test against the global $wp_query instance, not the passed one. * * @since 2.0.0 * * @param WP_Query &$this The WP_Query instance (passed by reference). */ do_action_ref_array('pre_get_posts', array(&$this)); // Shorthand. $q =& $this->query_vars; // Fill again in case pre_get_posts unset some vars. $q = $this->fill_query_vars($q); // Parse meta query $this->meta_query = new WP_Meta_Query(); $this->meta_query->parse_query_vars($q); // Set a flag if a pre_get_posts hook changed the query vars. $hash = md5(serialize($this->query_vars)); if ($hash != $this->query_vars_hash) { $this->query_vars_changed = true; $this->query_vars_hash = $hash; } unset($hash); // First let's clear some variables $distinct = ''; $whichauthor = ''; $whichmimetype = ''; $where = ''; $limits = ''; $join = ''; $search = ''; $groupby = ''; $post_status_join = false; $page = 1; if (isset($q['caller_get_posts'])) { _deprecated_argument('WP_Query', '3.1.0', __('"caller_get_posts" is deprecated. Use "ignore_sticky_posts" instead.')); if (!isset($q['ignore_sticky_posts'])) { $q['ignore_sticky_posts'] = $q['caller_get_posts']; } } if (!isset($q['ignore_sticky_posts'])) { $q['ignore_sticky_posts'] = false; } if (!isset($q['suppress_filters'])) { $q['suppress_filters'] = false; } if (!isset($q['cache_results'])) { if (wp_using_ext_object_cache()) { $q['cache_results'] = false; } else { $q['cache_results'] = true; } } if (!isset($q['update_post_term_cache'])) { $q['update_post_term_cache'] = true; } if (!isset($q['lazy_load_term_meta'])) { $q['lazy_load_term_meta'] = $q['update_post_term_cache']; } if (!isset($q['update_post_meta_cache'])) { $q['update_post_meta_cache'] = true; } if (!isset($q['post_type'])) { if ($this->is_search) { $q['post_type'] = 'any'; } else { $q['post_type'] = ''; } } $post_type = $q['post_type']; if (empty($q['posts_per_page'])) { $q['posts_per_page'] = get_option('posts_per_page'); } if (isset($q['showposts']) && $q['showposts']) { $q['showposts'] = (int) $q['showposts']; $q['posts_per_page'] = $q['showposts']; } if (isset($q['posts_per_archive_page']) && $q['posts_per_archive_page'] != 0 && ($this->is_archive || $this->is_search)) { $q['posts_per_page'] = $q['posts_per_archive_page']; } if (!isset($q['nopaging'])) { if ($q['posts_per_page'] == -1) { $q['nopaging'] = true; } else { $q['nopaging'] = false; } } if ($this->is_feed) { // This overrides posts_per_page. if (!empty($q['posts_per_rss'])) { $q['posts_per_page'] = $q['posts_per_rss']; } else { $q['posts_per_page'] = get_option('posts_per_rss'); } $q['nopaging'] = false; } $q['posts_per_page'] = (int) $q['posts_per_page']; if ($q['posts_per_page'] < -1) { $q['posts_per_page'] = abs($q['posts_per_page']); } elseif ($q['posts_per_page'] == 0) { $q['posts_per_page'] = 1; } if (!isset($q['comments_per_page']) || $q['comments_per_page'] == 0) { $q['comments_per_page'] = get_option('comments_per_page'); } if ($this->is_home && (empty($this->query) || $q['preview'] == 'true') && 'page' == get_option('show_on_front') && get_option('page_on_front')) { $this->is_page = true; $this->is_home = false; $q['page_id'] = get_option('page_on_front'); } if (isset($q['page'])) { $q['page'] = trim($q['page'], '/'); $q['page'] = absint($q['page']); } // If true, forcibly turns off SQL_CALC_FOUND_ROWS even when limits are present. if (isset($q['no_found_rows'])) { $q['no_found_rows'] = (bool) $q['no_found_rows']; } else { $q['no_found_rows'] = false; } switch ($q['fields']) { case 'ids': $fields = "{$this->db->posts}.ID"; break; case 'id=>parent': $fields = "{$this->db->posts}.ID, {$this->db->posts}.post_parent"; break; default: $fields = "{$this->db->posts}.*"; } if ('' !== $q['menu_order']) { $where .= " AND {$this->db->posts}.menu_order = " . $q['menu_order']; } // The "m" parameter is meant for months but accepts datetimes of varying specificity if ($q['m']) { $where .= " AND YEAR({$this->db->posts}.post_date)=" . substr($q['m'], 0, 4); if (strlen($q['m']) > 5) { $where .= " AND MONTH({$this->db->posts}.post_date)=" . substr($q['m'], 4, 2); } if (strlen($q['m']) > 7) { $where .= " AND DAYOFMONTH({$this->db->posts}.post_date)=" . substr($q['m'], 6, 2); } if (strlen($q['m']) > 9) { $where .= " AND HOUR({$this->db->posts}.post_date)=" . substr($q['m'], 8, 2); } if (strlen($q['m']) > 11) { $where .= " AND MINUTE({$this->db->posts}.post_date)=" . substr($q['m'], 10, 2); } if (strlen($q['m']) > 13) { $where .= " AND SECOND({$this->db->posts}.post_date)=" . substr($q['m'], 12, 2); } } // Handle the other individual date parameters $date_parameters = array(); if ('' !== $q['hour']) { $date_parameters['hour'] = $q['hour']; } if ('' !== $q['minute']) { $date_parameters['minute'] = $q['minute']; } if ('' !== $q['second']) { $date_parameters['second'] = $q['second']; } if ($q['year']) { $date_parameters['year'] = $q['year']; } if ($q['monthnum']) { $date_parameters['monthnum'] = $q['monthnum']; } if ($q['w']) { $date_parameters['week'] = $q['w']; } if ($q['day']) { $date_parameters['day'] = $q['day']; } if ($date_parameters) { $date_query = new WP_Date_Query(array($date_parameters)); $where .= $date_query->get_sql(); } unset($date_parameters, $date_query); // Handle complex date queries if (!empty($q['date_query'])) { $this->date_query = new WP_Date_Query($q['date_query']); $where .= $this->date_query->get_sql(); } // If we've got a post_type AND it's not "any" post_type. if (!empty($q['post_type']) && 'any' != $q['post_type']) { foreach ((array) $q['post_type'] as $_post_type) { $ptype_obj = get_post_type_object($_post_type); if (!$ptype_obj || !$ptype_obj->query_var || empty($q[$ptype_obj->query_var])) { continue; } if (!$ptype_obj->hierarchical) { // Non-hierarchical post types can directly use 'name'. $q['name'] = $q[$ptype_obj->query_var]; } else { // Hierarchical post types will operate through 'pagename'. $q['pagename'] = $q[$ptype_obj->query_var]; $q['name'] = ''; } // Only one request for a slug is possible, this is why name & pagename are overwritten above. break; } //end foreach unset($ptype_obj); } if ('' !== $q['title']) { $where .= $this->db->prepare(" AND {$this->db->posts}.post_title = %s", stripslashes($q['title'])); } // Parameters related to 'post_name'. if ('' != $q['name']) { $q['name'] = sanitize_title_for_query($q['name']); $where .= " AND {$this->db->posts}.post_name = '" . $q['name'] . "'"; } elseif ('' != $q['pagename']) { if (isset($this->queried_object_id)) { $reqpage = $this->queried_object_id; } else { if ('page' != $q['post_type']) { foreach ((array) $q['post_type'] as $_post_type) { $ptype_obj = get_post_type_object($_post_type); if (!$ptype_obj || !$ptype_obj->hierarchical) { continue; } $reqpage = get_page_by_path($q['pagename'], OBJECT, $_post_type); if ($reqpage) { break; } } unset($ptype_obj); } else { $reqpage = get_page_by_path($q['pagename']); } if (!empty($reqpage)) { $reqpage = $reqpage->ID; } else { $reqpage = 0; } } $page_for_posts = get_option('page_for_posts'); if ('page' != get_option('show_on_front') || empty($page_for_posts) || $reqpage != $page_for_posts) { $q['pagename'] = sanitize_title_for_query(wp_basename($q['pagename'])); $q['name'] = $q['pagename']; $where .= " AND ({$this->db->posts}.ID = '{$reqpage}')"; $reqpage_obj = get_post($reqpage); if (is_object($reqpage_obj) && 'attachment' == $reqpage_obj->post_type) { $this->is_attachment = true; $post_type = $q['post_type'] = 'attachment'; $this->is_page = true; $q['attachment_id'] = $reqpage; } } } elseif ('' != $q['attachment']) { $q['attachment'] = sanitize_title_for_query(wp_basename($q['attachment'])); $q['name'] = $q['attachment']; $where .= " AND {$this->db->posts}.post_name = '" . $q['attachment'] . "'"; } elseif (is_array($q['post_name__in']) && !empty($q['post_name__in'])) { $q['post_name__in'] = array_map('sanitize_title_for_query', $q['post_name__in']); $post_name__in = "'" . implode("','", $q['post_name__in']) . "'"; $where .= " AND {$this->db->posts}.post_name IN ({$post_name__in})"; } // If an attachment is requested by number, let it supersede any post number. if ($q['attachment_id']) { $q['p'] = absint($q['attachment_id']); } // If a post number is specified, load that post if ($q['p']) { $where .= " AND {$this->db->posts}.ID = " . $q['p']; } elseif ($q['post__in']) { $post__in = implode(',', array_map('absint', $q['post__in'])); $where .= " AND {$this->db->posts}.ID IN ({$post__in})"; } elseif ($q['post__not_in']) { $post__not_in = implode(',', array_map('absint', $q['post__not_in'])); $where .= " AND {$this->db->posts}.ID NOT IN ({$post__not_in})"; } if (is_numeric($q['post_parent'])) { $where .= $this->db->prepare(" AND {$this->db->posts}.post_parent = %d ", $q['post_parent']); } elseif ($q['post_parent__in']) { $post_parent__in = implode(',', array_map('absint', $q['post_parent__in'])); $where .= " AND {$this->db->posts}.post_parent IN ({$post_parent__in})"; } elseif ($q['post_parent__not_in']) { $post_parent__not_in = implode(',', array_map('absint', $q['post_parent__not_in'])); $where .= " AND {$this->db->posts}.post_parent NOT IN ({$post_parent__not_in})"; } if ($q['page_id']) { if ('page' != get_option('show_on_front') || $q['page_id'] != get_option('page_for_posts')) { $q['p'] = $q['page_id']; $where = " AND {$this->db->posts}.ID = " . $q['page_id']; } } // If a search pattern is specified, load the posts that match. if (strlen($q['s'])) { $search = $this->parse_search($q); } if (!$q['suppress_filters']) { /** * Filters the search SQL that is used in the WHERE clause of WP_Query. * * @since 3.0.0 * * @param string $search Search SQL for WHERE clause. * @param WP_Query $this The current WP_Query object. */ $search = apply_filters_ref_array('posts_search', array($search, &$this)); } // Taxonomies if (!$this->is_singular) { $this->parse_tax_query($q); $clauses = $this->tax_query->get_sql($this->db->posts, 'ID'); $join .= $clauses['join']; $where .= $clauses['where']; } if ($this->is_tax) { if (empty($post_type)) { // Do a fully inclusive search for currently registered post types of queried taxonomies $post_type = array(); $taxonomies = array_keys($this->tax_query->queried_terms); foreach (get_post_types(array('exclude_from_search' => false)) as $pt) { $object_taxonomies = $pt === 'attachment' ? get_taxonomies_for_attachments() : get_object_taxonomies($pt); if (array_intersect($taxonomies, $object_taxonomies)) { $post_type[] = $pt; } } if (!$post_type) { $post_type = 'any'; } elseif (count($post_type) == 1) { $post_type = $post_type[0]; } $post_status_join = true; } elseif (in_array('attachment', (array) $post_type)) { $post_status_join = true; } } /* * Ensure that 'taxonomy', 'term', 'term_id', 'cat', and * 'category_name' vars are set for backward compatibility. */ if (!empty($this->tax_query->queried_terms)) { /* * Set 'taxonomy', 'term', and 'term_id' to the * first taxonomy other than 'post_tag' or 'category'. */ if (!isset($q['taxonomy'])) { foreach ($this->tax_query->queried_terms as $queried_taxonomy => $queried_items) { if (empty($queried_items['terms'][0])) { continue; } if (!in_array($queried_taxonomy, array('category', 'post_tag'))) { $q['taxonomy'] = $queried_taxonomy; if ('slug' === $queried_items['field']) { $q['term'] = $queried_items['terms'][0]; } else { $q['term_id'] = $queried_items['terms'][0]; } // Take the first one we find. break; } } } // 'cat', 'category_name', 'tag_id' foreach ($this->tax_query->queried_terms as $queried_taxonomy => $queried_items) { if (empty($queried_items['terms'][0])) { continue; } if ('category' === $queried_taxonomy) { $the_cat = get_term_by($queried_items['field'], $queried_items['terms'][0], 'category'); if ($the_cat) { $this->set('cat', $the_cat->term_id); $this->set('category_name', $the_cat->slug); } unset($the_cat); } if ('post_tag' === $queried_taxonomy) { $the_tag = get_term_by($queried_items['field'], $queried_items['terms'][0], 'post_tag'); if ($the_tag) { $this->set('tag_id', $the_tag->term_id); } unset($the_tag); } } } if (!empty($this->tax_query->queries) || !empty($this->meta_query->queries)) { $groupby = "{$this->db->posts}.ID"; } // Author/user stuff if (!empty($q['author']) && $q['author'] != '0') { $q['author'] = addslashes_gpc('' . urldecode($q['author'])); $authors = array_unique(array_map('intval', preg_split('/[,\\s]+/', $q['author']))); foreach ($authors as $author) { $key = $author > 0 ? 'author__in' : 'author__not_in'; $q[$key][] = abs($author); } $q['author'] = implode(',', $authors); } if (!empty($q['author__not_in'])) { $author__not_in = implode(',', array_map('absint', array_unique((array) $q['author__not_in']))); $where .= " AND {$this->db->posts}.post_author NOT IN ({$author__not_in}) "; } elseif (!empty($q['author__in'])) { $author__in = implode(',', array_map('absint', array_unique((array) $q['author__in']))); $where .= " AND {$this->db->posts}.post_author IN ({$author__in}) "; } // Author stuff for nice URLs if ('' != $q['author_name']) { if (strpos($q['author_name'], '/') !== false) { $q['author_name'] = explode('/', $q['author_name']); if ($q['author_name'][count($q['author_name']) - 1]) { $q['author_name'] = $q['author_name'][count($q['author_name']) - 1]; // no trailing slash } else { $q['author_name'] = $q['author_name'][count($q['author_name']) - 2]; // there was a trailing slash } } $q['author_name'] = sanitize_title_for_query($q['author_name']); $q['author'] = get_user_by('slug', $q['author_name']); if ($q['author']) { $q['author'] = $q['author']->ID; } $whichauthor .= " AND ({$this->db->posts}.post_author = " . absint($q['author']) . ')'; } // MIME-Type stuff for attachment browsing if (isset($q['post_mime_type']) && '' != $q['post_mime_type']) { $whichmimetype = wp_post_mime_type_where($q['post_mime_type'], $this->db->posts); } $where .= $search . $whichauthor . $whichmimetype; if (!empty($this->meta_query->queries)) { $clauses = $this->meta_query->get_sql('post', $this->db->posts, 'ID', $this); $join .= $clauses['join']; $where .= $clauses['where']; } $rand = isset($q['orderby']) && 'rand' === $q['orderby']; if (!isset($q['order'])) { $q['order'] = $rand ? '' : 'DESC'; } else { $q['order'] = $rand ? '' : $this->parse_order($q['order']); } // Order by. if (empty($q['orderby'])) { /* * Boolean false or empty array blanks out ORDER BY, * while leaving the value unset or otherwise empty sets the default. */ if (isset($q['orderby']) && (is_array($q['orderby']) || false === $q['orderby'])) { $orderby = ''; } else { $orderby = "{$this->db->posts}.post_date " . $q['order']; } } elseif ('none' == $q['orderby']) { $orderby = ''; } elseif ($q['orderby'] == 'post__in' && !empty($post__in)) { $orderby = "FIELD( {$this->db->posts}.ID, {$post__in} )"; } elseif ($q['orderby'] == 'post_parent__in' && !empty($post_parent__in)) { $orderby = "FIELD( {$this->db->posts}.post_parent, {$post_parent__in} )"; } elseif ($q['orderby'] == 'post_name__in' && !empty($post_name__in)) { $orderby = "FIELD( {$this->db->posts}.post_name, {$post_name__in} )"; } else { $orderby_array = array(); if (is_array($q['orderby'])) { foreach ($q['orderby'] as $_orderby => $order) { $orderby = addslashes_gpc(urldecode($_orderby)); $parsed = $this->parse_orderby($orderby); if (!$parsed) { continue; } $orderby_array[] = $parsed . ' ' . $this->parse_order($order); } $orderby = implode(', ', $orderby_array); } else { $q['orderby'] = urldecode($q['orderby']); $q['orderby'] = addslashes_gpc($q['orderby']); foreach (explode(' ', $q['orderby']) as $i => $orderby) { $parsed = $this->parse_orderby($orderby); // Only allow certain values for safety. if (!$parsed) { continue; } $orderby_array[] = $parsed; } $orderby = implode(' ' . $q['order'] . ', ', $orderby_array); if (empty($orderby)) { $orderby = "{$this->db->posts}.post_date " . $q['order']; } elseif (!empty($q['order'])) { $orderby .= " {$q['order']}"; } } } // Order search results by relevance only when another "orderby" is not specified in the query. if (!empty($q['s'])) { $search_orderby = ''; if (!empty($q['search_orderby_title']) && (empty($q['orderby']) && !$this->is_feed) || isset($q['orderby']) && 'relevance' === $q['orderby']) { $search_orderby = $this->parse_search_order($q); } if (!$q['suppress_filters']) { /** * Filters the ORDER BY used when ordering search results. * * @since 3.7.0 * * @param string $search_orderby The ORDER BY clause. * @param WP_Query $this The current WP_Query instance. */ $search_orderby = apply_filters('posts_search_orderby', $search_orderby, $this); } if ($search_orderby) { $orderby = $orderby ? $search_orderby . ', ' . $orderby : $search_orderby; } } if (is_array($post_type) && count($post_type) > 1) { $post_type_cap = 'multiple_post_type'; } else { if (is_array($post_type)) { $post_type = reset($post_type); } $post_type_object = get_post_type_object($post_type); if (empty($post_type_object)) { $post_type_cap = $post_type; } } if (isset($q['post_password'])) { $where .= $this->db->prepare(" AND {$this->db->posts}.post_password = %s", $q['post_password']); if (empty($q['perm'])) { $q['perm'] = 'readable'; } } elseif (isset($q['has_password'])) { $where .= sprintf(" AND {$this->db->posts}.post_password %s ''", $q['has_password'] ? '!=' : '='); } if (!empty($q['comment_status'])) { $where .= $this->db->prepare(" AND {$this->db->posts}.comment_status = %s ", $q['comment_status']); } if (!empty($q['ping_status'])) { $where .= $this->db->prepare(" AND {$this->db->posts}.ping_status = %s ", $q['ping_status']); } if ('any' == $post_type) { $in_search_post_types = get_post_types(array('exclude_from_search' => false)); if (empty($in_search_post_types)) { $where .= ' AND 1=0 '; } else { $where .= " AND {$this->db->posts}.post_type IN ('" . join("', '", $in_search_post_types) . "')"; } } elseif (!empty($post_type) && is_array($post_type)) { $where .= " AND {$this->db->posts}.post_type IN ('" . join("', '", $post_type) . "')"; } elseif (!empty($post_type)) { $where .= " AND {$this->db->posts}.post_type = '{$post_type}'"; $post_type_object = get_post_type_object($post_type); } elseif ($this->is_attachment) { $where .= " AND {$this->db->posts}.post_type = 'attachment'"; $post_type_object = get_post_type_object('attachment'); } elseif ($this->is_page) { $where .= " AND {$this->db->posts}.post_type = 'page'"; $post_type_object = get_post_type_object('page'); } else { $where .= " AND {$this->db->posts}.post_type = 'post'"; $post_type_object = get_post_type_object('post'); } $edit_cap = 'edit_post'; $read_cap = 'read_post'; if (!empty($post_type_object)) { $edit_others_cap = $post_type_object->cap->edit_others_posts; $read_private_cap = $post_type_object->cap->read_private_posts; } else { $edit_others_cap = 'edit_others_' . $post_type_cap . 's'; $read_private_cap = 'read_private_' . $post_type_cap . 's'; } $user_id = get_current_user_id(); $q_status = array(); if (!empty($q['post_status'])) { $statuswheres = array(); $q_status = $q['post_status']; if (!is_array($q_status)) { $q_status = explode(',', $q_status); } $r_status = array(); $p_status = array(); $e_status = array(); if (in_array('any', $q_status)) { foreach (get_post_stati(array('exclude_from_search' => true)) as $status) { if (!in_array($status, $q_status)) { $e_status[] = "{$this->db->posts}.post_status <> '{$status}'"; } } } else { foreach (get_post_stati() as $status) { if (in_array($status, $q_status)) { if ('private' == $status) { $p_status[] = "{$this->db->posts}.post_status = '{$status}'"; } else { $r_status[] = "{$this->db->posts}.post_status = '{$status}'"; } } } } if (empty($q['perm']) || 'readable' != $q['perm']) { $r_status = array_merge($r_status, $p_status); unset($p_status); } if (!empty($e_status)) { $statuswheres[] = "(" . join(' AND ', $e_status) . ")"; } if (!empty($r_status)) { if (!empty($q['perm']) && 'editable' == $q['perm'] && !current_user_can($edit_others_cap)) { $statuswheres[] = "({$this->db->posts}.post_author = {$user_id} " . "AND (" . join(' OR ', $r_status) . "))"; } else { $statuswheres[] = "(" . join(' OR ', $r_status) . ")"; } } if (!empty($p_status)) { if (!empty($q['perm']) && 'readable' == $q['perm'] && !current_user_can($read_private_cap)) { $statuswheres[] = "({$this->db->posts}.post_author = {$user_id} " . "AND (" . join(' OR ', $p_status) . "))"; } else { $statuswheres[] = "(" . join(' OR ', $p_status) . ")"; } } if ($post_status_join) { $join .= " LEFT JOIN {$this->db->posts} AS p2 ON ({$this->db->posts}.post_parent = p2.ID) "; foreach ($statuswheres as $index => $statuswhere) { $statuswheres[$index] = "({$statuswhere} OR ({$this->db->posts}.post_status = 'inherit' AND " . str_replace($this->db->posts, 'p2', $statuswhere) . "))"; } } $where_status = implode(' OR ', $statuswheres); if (!empty($where_status)) { $where .= " AND ({$where_status})"; } } elseif (!$this->is_singular) { $where .= " AND ({$this->db->posts}.post_status = 'publish'"; // Add public states. $public_states = get_post_stati(array('public' => true)); foreach ((array) $public_states as $state) { if ('publish' == $state) { // Publish is hard-coded above. continue; } $where .= " OR {$this->db->posts}.post_status = '{$state}'"; } if ($this->is_admin) { // Add protected states that should show in the admin all list. $admin_all_states = get_post_stati(array('protected' => true, 'show_in_admin_all_list' => true)); foreach ((array) $admin_all_states as $state) { $where .= " OR {$this->db->posts}.post_status = '{$state}'"; } } if (is_user_logged_in()) { // Add private states that are limited to viewing by the author of a post or someone who has caps to read private states. $private_states = get_post_stati(array('private' => true)); foreach ((array) $private_states as $state) { $where .= current_user_can($read_private_cap) ? " OR {$this->db->posts}.post_status = '{$state}'" : " OR {$this->db->posts}.post_author = {$user_id} AND {$this->db->posts}.post_status = '{$state}'"; } } $where .= ')'; } /* * Apply filters on where and join prior to paging so that any * manipulations to them are reflected in the paging by day queries. */ if (!$q['suppress_filters']) { /** * Filters the WHERE clause of the query. * * @since 1.5.0 * * @param string $where The WHERE clause of the query. * @param WP_Query &$this The WP_Query instance (passed by reference). */ $where = apply_filters_ref_array('posts_where', array($where, &$this)); /** * Filters the JOIN clause of the query. * * @since 1.5.0 * * @param string $where The JOIN clause of the query. * @param WP_Query &$this The WP_Query instance (passed by reference). */ $join = apply_filters_ref_array('posts_join', array($join, &$this)); } // Paging if (empty($q['nopaging']) && !$this->is_singular) { $page = absint($q['paged']); if (!$page) { $page = 1; } // If 'offset' is provided, it takes precedence over 'paged'. if (isset($q['offset']) && is_numeric($q['offset'])) { $q['offset'] = absint($q['offset']); $pgstrt = $q['offset'] . ', '; } else { $pgstrt = absint(($page - 1) * $q['posts_per_page']) . ', '; } $limits = 'LIMIT ' . $pgstrt . $q['posts_per_page']; } // Comments feeds if ($this->is_comment_feed && !$this->is_singular) { if ($this->is_archive || $this->is_search) { $cjoin = "JOIN {$this->db->posts} ON ({$this->db->comments}.comment_post_ID = {$this->db->posts}.ID) {$join} "; $cwhere = "WHERE comment_approved = '1' {$where}"; $cgroupby = "{$this->db->comments}.comment_id"; } else { // Other non singular e.g. front $cjoin = "JOIN {$this->db->posts} ON ( {$this->db->comments}.comment_post_ID = {$this->db->posts}.ID )"; $cwhere = "WHERE ( post_status = 'publish' OR ( post_status = 'inherit' && post_type = 'attachment' ) ) AND comment_approved = '1'"; $cgroupby = ''; } if (!$q['suppress_filters']) { /** * Filters the JOIN clause of the comments feed query before sending. * * @since 2.2.0 * * @param string $cjoin The JOIN clause of the query. * @param WP_Query &$this The WP_Query instance (passed by reference). */ $cjoin = apply_filters_ref_array('comment_feed_join', array($cjoin, &$this)); /** * Filters the WHERE clause of the comments feed query before sending. * * @since 2.2.0 * * @param string $cwhere The WHERE clause of the query. * @param WP_Query &$this The WP_Query instance (passed by reference). */ $cwhere = apply_filters_ref_array('comment_feed_where', array($cwhere, &$this)); /** * Filters the GROUP BY clause of the comments feed query before sending. * * @since 2.2.0 * * @param string $cgroupby The GROUP BY clause of the query. * @param WP_Query &$this The WP_Query instance (passed by reference). */ $cgroupby = apply_filters_ref_array('comment_feed_groupby', array($cgroupby, &$this)); /** * Filters the ORDER BY clause of the comments feed query before sending. * * @since 2.8.0 * * @param string $corderby The ORDER BY clause of the query. * @param WP_Query &$this The WP_Query instance (passed by reference). */ $corderby = apply_filters_ref_array('comment_feed_orderby', array('comment_date_gmt DESC', &$this)); /** * Filters the LIMIT clause of the comments feed query before sending. * * @since 2.8.0 * * @param string $climits The JOIN clause of the query. * @param WP_Query &$this The WP_Query instance (passed by reference). */ $climits = apply_filters_ref_array('comment_feed_limits', array('LIMIT ' . get_option('posts_per_rss'), &$this)); } $cgroupby = !empty($cgroupby) ? 'GROUP BY ' . $cgroupby : ''; $corderby = !empty($corderby) ? 'ORDER BY ' . $corderby : ''; $comments = (array) $this->db->get_results("SELECT {$distinct} {$this->db->comments}.* FROM {$this->db->comments} {$cjoin} {$cwhere} {$cgroupby} {$corderby} {$climits}"); // Convert to WP_Comment $this->comments = array_map('get_comment', $comments); $this->comment_count = count($this->comments); $post_ids = array(); foreach ($this->comments as $comment) { $post_ids[] = (int) $comment->comment_post_ID; } $post_ids = join(',', $post_ids); $join = ''; if ($post_ids) { $where = "AND {$this->db->posts}.ID IN ({$post_ids}) "; } else { $where = "AND 0"; } } $pieces = array('where', 'groupby', 'join', 'orderby', 'distinct', 'fields', 'limits'); /* * Apply post-paging filters on where and join. Only plugins that * manipulate paging queries should use these hooks. */ if (!$q['suppress_filters']) { /** * Filters the WHERE clause of the query. * * Specifically for manipulating paging queries. * * @since 1.5.0 * * @param string $where The WHERE clause of the query. * @param WP_Query &$this The WP_Query instance (passed by reference). */ $where = apply_filters_ref_array('posts_where_paged', array($where, &$this)); /** * Filters the GROUP BY clause of the query. * * @since 2.0.0 * * @param string $groupby The GROUP BY clause of the query. * @param WP_Query &$this The WP_Query instance (passed by reference). */ $groupby = apply_filters_ref_array('posts_groupby', array($groupby, &$this)); /** * Filters the JOIN clause of the query. * * Specifically for manipulating paging queries. * * @since 1.5.0 * * @param string $join The JOIN clause of the query. * @param WP_Query &$this The WP_Query instance (passed by reference). */ $join = apply_filters_ref_array('posts_join_paged', array($join, &$this)); /** * Filters the ORDER BY clause of the query. * * @since 1.5.1 * * @param string $orderby The ORDER BY clause of the query. * @param WP_Query &$this The WP_Query instance (passed by reference). */ $orderby = apply_filters_ref_array('posts_orderby', array($orderby, &$this)); /** * Filters the DISTINCT clause of the query. * * @since 2.1.0 * * @param string $distinct The DISTINCT clause of the query. * @param WP_Query &$this The WP_Query instance (passed by reference). */ $distinct = apply_filters_ref_array('posts_distinct', array($distinct, &$this)); /** * Filters the LIMIT clause of the query. * * @since 2.1.0 * * @param string $limits The LIMIT clause of the query. * @param WP_Query &$this The WP_Query instance (passed by reference). */ $limits = apply_filters_ref_array('post_limits', array($limits, &$this)); /** * Filters the SELECT clause of the query. * * @since 2.1.0 * * @param string $fields The SELECT clause of the query. * @param WP_Query &$this The WP_Query instance (passed by reference). */ $fields = apply_filters_ref_array('posts_fields', array($fields, &$this)); /** * Filters all query clauses at once, for convenience. * * Covers the WHERE, GROUP BY, JOIN, ORDER BY, DISTINCT, * fields (SELECT), and LIMITS clauses. * * @since 3.1.0 * * @param array $clauses The list of clauses for the query. * @param WP_Query &$this The WP_Query instance (passed by reference). */ $clauses = (array) apply_filters_ref_array('posts_clauses', array(compact($pieces), &$this)); $where = isset($clauses['where']) ? $clauses['where'] : ''; $groupby = isset($clauses['groupby']) ? $clauses['groupby'] : ''; $join = isset($clauses['join']) ? $clauses['join'] : ''; $orderby = isset($clauses['orderby']) ? $clauses['orderby'] : ''; $distinct = isset($clauses['distinct']) ? $clauses['distinct'] : ''; $fields = isset($clauses['fields']) ? $clauses['fields'] : ''; $limits = isset($clauses['limits']) ? $clauses['limits'] : ''; } /** * Fires to announce the query's current selection parameters. * * For use by caching plugins. * * @since 2.3.0 * * @param string $selection The assembled selection query. */ do_action('posts_selection', $where . $groupby . $orderby . $limits . $join); /* * Filters again for the benefit of caching plugins. * Regular plugins should use the hooks above. */ if (!$q['suppress_filters']) { /** * Filters the WHERE clause of the query. * * For use by caching plugins. * * @since 2.5.0 * * @param string $where The WHERE clause of the query. * @param WP_Query &$this The WP_Query instance (passed by reference). */ $where = apply_filters_ref_array('posts_where_request', array($where, &$this)); /** * Filters the GROUP BY clause of the query. * * For use by caching plugins. * * @since 2.5.0 * * @param string $groupby The GROUP BY clause of the query. * @param WP_Query &$this The WP_Query instance (passed by reference). */ $groupby = apply_filters_ref_array('posts_groupby_request', array($groupby, &$this)); /** * Filters the JOIN clause of the query. * * For use by caching plugins. * * @since 2.5.0 * * @param string $join The JOIN clause of the query. * @param WP_Query &$this The WP_Query instance (passed by reference). */ $join = apply_filters_ref_array('posts_join_request', array($join, &$this)); /** * Filters the ORDER BY clause of the query. * * For use by caching plugins. * * @since 2.5.0 * * @param string $orderby The ORDER BY clause of the query. * @param WP_Query &$this The WP_Query instance (passed by reference). */ $orderby = apply_filters_ref_array('posts_orderby_request', array($orderby, &$this)); /** * Filters the DISTINCT clause of the query. * * For use by caching plugins. * * @since 2.5.0 * * @param string $distinct The DISTINCT clause of the query. * @param WP_Query &$this The WP_Query instance (passed by reference). */ $distinct = apply_filters_ref_array('posts_distinct_request', array($distinct, &$this)); /** * Filters the SELECT clause of the query. * * For use by caching plugins. * * @since 2.5.0 * * @param string $fields The SELECT clause of the query. * @param WP_Query &$this The WP_Query instance (passed by reference). */ $fields = apply_filters_ref_array('posts_fields_request', array($fields, &$this)); /** * Filters the LIMIT clause of the query. * * For use by caching plugins. * * @since 2.5.0 * * @param string $limits The LIMIT clause of the query. * @param WP_Query &$this The WP_Query instance (passed by reference). */ $limits = apply_filters_ref_array('post_limits_request', array($limits, &$this)); /** * Filters all query clauses at once, for convenience. * * For use by caching plugins. * * Covers the WHERE, GROUP BY, JOIN, ORDER BY, DISTINCT, * fields (SELECT), and LIMITS clauses. * * @since 3.1.0 * * @param array $pieces The pieces of the query. * @param WP_Query &$this The WP_Query instance (passed by reference). */ $clauses = (array) apply_filters_ref_array('posts_clauses_request', array(compact($pieces), &$this)); $where = isset($clauses['where']) ? $clauses['where'] : ''; $groupby = isset($clauses['groupby']) ? $clauses['groupby'] : ''; $join = isset($clauses['join']) ? $clauses['join'] : ''; $orderby = isset($clauses['orderby']) ? $clauses['orderby'] : ''; $distinct = isset($clauses['distinct']) ? $clauses['distinct'] : ''; $fields = isset($clauses['fields']) ? $clauses['fields'] : ''; $limits = isset($clauses['limits']) ? $clauses['limits'] : ''; } if (!empty($groupby)) { $groupby = 'GROUP BY ' . $groupby; } if (!empty($orderby)) { $orderby = 'ORDER BY ' . $orderby; } $found_rows = ''; if (!$q['no_found_rows'] && !empty($limits)) { $found_rows = 'SQL_CALC_FOUND_ROWS'; } $this->request = $old_request = "SELECT {$found_rows} {$distinct} {$fields} FROM {$this->db->posts} {$join} WHERE 1=1 {$where} {$groupby} {$orderby} {$limits}"; if (!$q['suppress_filters']) { /** * Filters the completed SQL query before sending. * * @since 2.0.0 * * @param string $request The complete SQL query. * @param WP_Query &$this The WP_Query instance (passed by reference). */ $this->request = apply_filters_ref_array('posts_request', array($this->request, &$this)); } /** * Filters the posts array before the query takes place. * * Return a non-null value to bypass WordPress's default post queries. * * Filtering functions that require pagination information are encouraged to set * the `found_posts` and `max_num_pages` properties of the WP_Query object, * passed to the filter by reference. If WP_Query does not perform a database * query, it will not have enough information to generate these values itself. * * @since 4.6.0 * * @param array|null $posts Return an array of post data to short-circuit WP's query, * or null to allow WP to run its normal queries. * @param WP_Query $this The WP_Query instance, passed by reference. */ $this->posts = apply_filters_ref_array('posts_pre_query', array(null, &$this)); if ('ids' == $q['fields']) { if (null === $this->posts) { $this->posts = $this->db->get_col($this->request); } $this->posts = array_map('intval', $this->posts); $this->post_count = count($this->posts); $this->set_found_posts($q, $limits); return $this->posts; } if ('id=>parent' == $q['fields']) { if (null === $this->posts) { $this->posts = $this->db->get_results($this->request); } $this->post_count = count($this->posts); $this->set_found_posts($q, $limits); $r = array(); foreach ($this->posts as $key => $post) { $this->posts[$key]->ID = (int) $post->ID; $this->posts[$key]->post_parent = (int) $post->post_parent; $r[(int) $post->ID] = (int) $post->post_parent; } return $r; } if (null === $this->posts) { $split_the_query = $old_request == $this->request && "{$this->db->posts}.*" == $fields && !empty($limits) && $q['posts_per_page'] < 500; /** * Filters whether to split the query. * * Splitting the query will cause it to fetch just the IDs of the found posts * (and then individually fetch each post by ID), rather than fetching every * complete row at once. One massive result vs. many small results. * * @since 3.4.0 * * @param bool $split_the_query Whether or not to split the query. * @param WP_Query $this The WP_Query instance. */ $split_the_query = apply_filters('split_the_query', $split_the_query, $this); if ($split_the_query) { // First get the IDs and then fill in the objects $this->request = "SELECT {$found_rows} {$distinct} {$this->db->posts}.ID FROM {$this->db->posts} {$join} WHERE 1=1 {$where} {$groupby} {$orderby} {$limits}"; /** * Filters the Post IDs SQL request before sending. * * @since 3.4.0 * * @param string $request The post ID request. * @param WP_Query $this The WP_Query instance. */ $this->request = apply_filters('posts_request_ids', $this->request, $this); $ids = $this->db->get_col($this->request); if ($ids) { $this->posts = $ids; $this->set_found_posts($q, $limits); _prime_post_caches($ids, $q['update_post_term_cache'], $q['update_post_meta_cache']); } else { $this->posts = array(); } } else { $this->posts = $this->db->get_results($this->request); $this->set_found_posts($q, $limits); } } // Convert to WP_Post objects. if ($this->posts) { $this->posts = array_map('get_post', $this->posts); } if (!$q['suppress_filters']) { /** * Filters the raw post results array, prior to status checks. * * @since 2.3.0 * * @param array $posts The post results array. * @param WP_Query &$this The WP_Query instance (passed by reference). */ $this->posts = apply_filters_ref_array('posts_results', array($this->posts, &$this)); } if (!empty($this->posts) && $this->is_comment_feed && $this->is_singular) { /** This filter is documented in wp-includes/query.php */ $cjoin = apply_filters_ref_array('comment_feed_join', array('', &$this)); /** This filter is documented in wp-includes/query.php */ $cwhere = apply_filters_ref_array('comment_feed_where', array("WHERE comment_post_ID = '{$this->posts[0]->ID}' AND comment_approved = '1'", &$this)); /** This filter is documented in wp-includes/query.php */ $cgroupby = apply_filters_ref_array('comment_feed_groupby', array('', &$this)); $cgroupby = !empty($cgroupby) ? 'GROUP BY ' . $cgroupby : ''; /** This filter is documented in wp-includes/query.php */ $corderby = apply_filters_ref_array('comment_feed_orderby', array('comment_date_gmt DESC', &$this)); $corderby = !empty($corderby) ? 'ORDER BY ' . $corderby : ''; /** This filter is documented in wp-includes/query.php */ $climits = apply_filters_ref_array('comment_feed_limits', array('LIMIT ' . get_option('posts_per_rss'), &$this)); $comments_request = "SELECT {$this->db->comments}.* FROM {$this->db->comments} {$cjoin} {$cwhere} {$cgroupby} {$corderby} {$climits}"; $comments = $this->db->get_results($comments_request); // Convert to WP_Comment $this->comments = array_map('get_comment', $comments); $this->comment_count = count($this->comments); } // Check post status to determine if post should be displayed. if (!empty($this->posts) && ($this->is_single || $this->is_page)) { $status = get_post_status($this->posts[0]); if ('attachment' === $this->posts[0]->post_type && 0 === (int) $this->posts[0]->post_parent) { $this->is_page = false; $this->is_single = true; $this->is_attachment = true; } $post_status_obj = get_post_status_object($status); // If the post_status was specifically requested, let it pass through. if (!$post_status_obj->public && !in_array($status, $q_status)) { if (!is_user_logged_in()) { // User must be logged in to view unpublished posts. $this->posts = array(); } else { if ($post_status_obj->protected) { // User must have edit permissions on the draft to preview. if (!current_user_can($edit_cap, $this->posts[0]->ID)) { $this->posts = array(); } else { $this->is_preview = true; if ('future' != $status) { $this->posts[0]->post_date = current_time('mysql'); } } } elseif ($post_status_obj->private) { if (!current_user_can($read_cap, $this->posts[0]->ID)) { $this->posts = array(); } } else { $this->posts = array(); } } } if ($this->is_preview && $this->posts && current_user_can($edit_cap, $this->posts[0]->ID)) { /** * Filters the single post for preview mode. * * @since 2.7.0 * * @param WP_Post $post_preview The Post object. * @param WP_Query &$this The WP_Query instance (passed by reference). */ $this->posts[0] = get_post(apply_filters_ref_array('the_preview', array($this->posts[0], &$this))); } } // Put sticky posts at the top of the posts array $sticky_posts = get_option('sticky_posts'); if ($this->is_home && $page <= 1 && is_array($sticky_posts) && !empty($sticky_posts) && !$q['ignore_sticky_posts']) { $num_posts = count($this->posts); $sticky_offset = 0; // Loop over posts and relocate stickies to the front. for ($i = 0; $i < $num_posts; $i++) { if (in_array($this->posts[$i]->ID, $sticky_posts)) { $sticky_post = $this->posts[$i]; // Remove sticky from current position array_splice($this->posts, $i, 1); // Move to front, after other stickies array_splice($this->posts, $sticky_offset, 0, array($sticky_post)); // Increment the sticky offset. The next sticky will be placed at this offset. $sticky_offset++; // Remove post from sticky posts array $offset = array_search($sticky_post->ID, $sticky_posts); unset($sticky_posts[$offset]); } } // If any posts have been excluded specifically, Ignore those that are sticky. if (!empty($sticky_posts) && !empty($q['post__not_in'])) { $sticky_posts = array_diff($sticky_posts, $q['post__not_in']); } // Fetch sticky posts that weren't in the query results if (!empty($sticky_posts)) { $stickies = get_posts(array('post__in' => $sticky_posts, 'post_type' => $post_type, 'post_status' => 'publish', 'nopaging' => true)); foreach ($stickies as $sticky_post) { array_splice($this->posts, $sticky_offset, 0, array($sticky_post)); $sticky_offset++; } } } // If comments have been fetched as part of the query, make sure comment meta lazy-loading is set up. if (!empty($this->comments)) { wp_queue_comments_for_comment_meta_lazyload($this->comments); } if (!$q['suppress_filters']) { /** * Filters the array of retrieved posts after they've been fetched and * internally processed. * * @since 1.5.0 * * @param array $posts The array of retrieved posts. * @param WP_Query &$this The WP_Query instance (passed by reference). */ $this->posts = apply_filters_ref_array('the_posts', array($this->posts, &$this)); } // Ensure that any posts added/modified via one of the filters above are // of the type WP_Post and are filtered. if ($this->posts) { $this->post_count = count($this->posts); $this->posts = array_map('get_post', $this->posts); if ($q['cache_results']) { update_post_caches($this->posts, $post_type, $q['update_post_term_cache'], $q['update_post_meta_cache']); } $this->post = reset($this->posts); } else { $this->post_count = 0; $this->posts = array(); } if ($q['lazy_load_term_meta']) { wp_queue_posts_for_term_meta_lazyload($this->posts); } return $this->posts; }
/** * @param array $exclude * @return array */ private function query_information_schema(array $exclude = array()) { $sql = $this->get_information_schema_sql($exclude); return $this->wpdb->get_col($sql); }
public function select_data_from_db_for_values($db_info, $value_column, $table, $where, $order_by) { global $wpdb; $query = "SELECT `" . $value_column . "` FROM " . $table . $where . " ORDER BY " . $order_by; if ($db_info) { $temp = explode('@@@wdfhostwdf@@@', $db_info); $host = $temp[0]; $temp = explode('@@@wdfportwdf@@@', $temp[1]); $port = $temp[0]; $temp = explode('@@@wdfusernamewdf@@@', $temp[1]); $username = $temp[0]; $temp = explode('@@@wdfpasswordwdf@@@', $temp[1]); $password = $temp[0]; $temp = explode('@@@wdfdatabasewdf@@@', $temp[1]); $database = $temp[0]; $wpdb_temp = new wpdb($username, $password, $database, $host); $choices_values = $wpdb_temp->get_col($query); } else { $choices_values = $wpdb->get_col($query); } return $choices_values; }
/** * Used internally to get a list of network IDs matching the query vars. * * @since 4.6.0 * @access protected * * @return int|array A single count of network IDs if a count query. An array of network IDs if a full query. */ protected function get_network_ids() { $order = $this->parse_order($this->query_vars['order']); // Disable ORDER BY with 'none', an empty array, or boolean false. if (in_array($this->query_vars['orderby'], array('none', array(), false), true)) { $orderby = ''; } elseif (!empty($this->query_vars['orderby'])) { $ordersby = is_array($this->query_vars['orderby']) ? $this->query_vars['orderby'] : preg_split('/[,\\s]/', $this->query_vars['orderby']); $orderby_array = array(); foreach ($ordersby as $_key => $_value) { if (!$_value) { continue; } if (is_int($_key)) { $_orderby = $_value; $_order = $order; } else { $_orderby = $_key; $_order = $_value; } $parsed = $this->parse_orderby($_orderby); if (!$parsed) { continue; } if ('network__in' === $_orderby) { $orderby_array[] = $parsed; continue; } $orderby_array[] = $parsed . ' ' . $this->parse_order($_order); } $orderby = implode(', ', $orderby_array); } else { $orderby = "{$this->db->site}.id {$order}"; } $number = absint($this->query_vars['number']); $offset = absint($this->query_vars['offset']); if (!empty($number)) { if ($offset) { $limits = 'LIMIT ' . $offset . ',' . $number; } else { $limits = 'LIMIT ' . $number; } } if ($this->query_vars['count']) { $fields = 'COUNT(*)'; } else { $fields = "{$this->db->site}.id"; } // Parse network IDs for an IN clause. if (!empty($this->query_vars['network__in'])) { $this->sql_clauses['where']['network__in'] = "{$this->db->site}.id IN ( " . implode(',', wp_parse_id_list($this->query_vars['network__in'])) . ' )'; } // Parse network IDs for a NOT IN clause. if (!empty($this->query_vars['network__not_in'])) { $this->sql_clauses['where']['network__not_in'] = "{$this->db->site}.id NOT IN ( " . implode(',', wp_parse_id_list($this->query_vars['network__not_in'])) . ' )'; } if (!empty($this->query_vars['domain'])) { $this->sql_clauses['where']['domain'] = $this->db->prepare("{$this->db->site}.domain = %s", $this->query_vars['domain']); } // Parse network domain for an IN clause. if (is_array($this->query_vars['domain__in'])) { $this->sql_clauses['where']['domain__in'] = "{$this->db->site}.domain IN ( '" . implode("', '", $this->db->_escape($this->query_vars['domain__in'])) . "' )"; } // Parse network domain for a NOT IN clause. if (is_array($this->query_vars['domain__not_in'])) { $this->sql_clauses['where']['domain__not_in'] = "{$this->db->site}.domain NOT IN ( '" . implode("', '", $this->db->_escape($this->query_vars['domain__not_in'])) . "' )"; } if (!empty($this->query_vars['path'])) { $this->sql_clauses['where']['path'] = $this->db->prepare("{$this->db->site}.path = %s", $this->query_vars['path']); } // Parse network path for an IN clause. if (is_array($this->query_vars['path__in'])) { $this->sql_clauses['where']['path__in'] = "{$this->db->site}.path IN ( '" . implode("', '", $this->db->_escape($this->query_vars['path__in'])) . "' )"; } // Parse network path for a NOT IN clause. if (is_array($this->query_vars['path__not_in'])) { $this->sql_clauses['where']['path__not_in'] = "{$this->db->site}.path NOT IN ( '" . implode("', '", $this->db->_escape($this->query_vars['path__not_in'])) . "' )"; } // Falsey search strings are ignored. if (strlen($this->query_vars['search'])) { $this->sql_clauses['where']['search'] = $this->get_search_sql($this->query_vars['search'], array("{$this->db->site}.domain", "{$this->db->site}.path")); } $join = ''; $where = implode(' AND ', $this->sql_clauses['where']); $pieces = array('fields', 'join', 'where', 'orderby', 'limits', 'groupby'); /** * Filters the network query clauses. * * @since 4.6.0 * * @param array $pieces A compacted array of network query clauses. * @param WP_Network_Query &$this Current instance of WP_Network_Query, passed by reference. */ $clauses = apply_filters_ref_array('networks_clauses', array(compact($pieces), &$this)); $fields = isset($clauses['fields']) ? $clauses['fields'] : ''; $join = isset($clauses['join']) ? $clauses['join'] : ''; $where = isset($clauses['where']) ? $clauses['where'] : ''; $orderby = isset($clauses['orderby']) ? $clauses['orderby'] : ''; $limits = isset($clauses['limits']) ? $clauses['limits'] : ''; $groupby = isset($clauses['groupby']) ? $clauses['groupby'] : ''; if ($where) { $where = 'WHERE ' . $where; } if ($groupby) { $groupby = 'GROUP BY ' . $groupby; } if ($orderby) { $orderby = "ORDER BY {$orderby}"; } $found_rows = ''; if (!$this->query_vars['no_found_rows']) { $found_rows = 'SQL_CALC_FOUND_ROWS'; } $this->sql_clauses['select'] = "SELECT {$found_rows} {$fields}"; $this->sql_clauses['from'] = "FROM {$this->db->site} {$join}"; $this->sql_clauses['groupby'] = $groupby; $this->sql_clauses['orderby'] = $orderby; $this->sql_clauses['limits'] = $limits; $this->request = "{$this->sql_clauses['select']} {$this->sql_clauses['from']} {$where} {$this->sql_clauses['groupby']} {$this->sql_clauses['orderby']} {$this->sql_clauses['limits']}"; if ($this->query_vars['count']) { return intval($this->db->get_var($this->request)); } $network_ids = $this->db->get_col($this->request); return array_map('intval', $network_ids); }
/** * Get a list of tables that the current user can read. * @return string[] The table names. */ public function get_table_names() { if (!$this->table_names) { $this->table_names = array(); foreach ($this->wpdb->get_col('SHOW TABLES') as $table_name) { if (Grants::current_user_can(Grants::READ, $table_name)) { $this->table_names[] = $table_name; } } } return $this->table_names; }