/** * Get taxonomy terms * * @param array $params * * @return array|WP_Error */ public static function getAllTerms($params = array()) { $taxonomy = meAnjanWqg_Utils::arrayValueAsString($params, 'taxonomy', '', 'trim'); $field = meAnjanWqg_Utils::arrayValueAsString($params, 'field', '', 'trim'); if ($field == '') { $field = 'term_id'; } switch ($field) { case 'name': case 'term_id': case 'slug': break; default: $field = 'term_id'; break; } $args = array('orderby' => 'name', 'order' => 'ASC', 'hide_empty' => false); $res = get_terms($taxonomy, $args); $data = array(); if (is_array($res) && count($res) > 0) { foreach ($res as $r) { $data[] = array('label' => $r->name, 'value' => $r->{$field}); } } return $data; }
/** * Get users * * @param array $params * * @return array|null|object */ public static function getUsers($params = array()) { /** * @var wpdb $wpdb */ global $wpdb; /* params */ $users_table_name = trim(meAnjanWqg_Utils::arrayValue($params, 'users_table_name', $wpdb->users)); if ($users_table_name == '') { $users_table_name = $wpdb->users; } $users_table_alias = trim(meAnjanWqg_Utils::arrayValue($params, 'users_table_alias', 'u')); if ($users_table_alias == '') { $users_table_alias = 'u'; } $fields = meAnjanWqg_Utils::arrayValue($params, 'fields', $users_table_alias . '.*'); if (empty($fields)) { $fields = $users_table_alias . '.*'; } /* Fields */ if (is_array($fields) && count($fields) > 0) { $fields = join(',', $fields); } else { if (is_string($fields)) { $fields = trim(trim($fields), ','); } else { $fields = $users_table_alias . '.*'; } } $where_clause = " 1 "; $sql = "select {$fields} from {$users_table_name} {$users_table_alias} where {$where_clause} order by {$users_table_alias}.user_nicename asc"; $users = $wpdb->get_results($sql, 'ARRAY_A'); return $users; }
/** * Generates <option> html tag for a tag * * @param array $params * * @return bool|string */ public static function generateTagOption($params = array()) { $tag = meAnjanWqg_Utils::arrayValue($params, 'tag', false); if (!is_object($tag)) { return false; } $label_field = meAnjanWqg_Utils::arrayValue($params, 'label_field', 'name'); $label_field_extra = meAnjanWqg_Utils::arrayValue($params, 'label_field_extra', ''); $value_field = meAnjanWqg_Utils::arrayValue($params, 'value_field', 'term_id'); $indent = (int) meAnjanWqg_Utils::arrayValue($params, 'indent', 0); $label = isset($tag->{$label_field}) ? $tag->{$label_field} : ''; $value = isset($tag->{$value_field}) ? $tag->{$value_field} : ''; $label = str_repeat('-', $indent) . $label; if ($label_field_extra != '') { $extraLabelValue = isset($tag->{$label_field_extra}) ? trim($tag->{$label_field_extra}) : ''; if ($extraLabelValue != '') { $label .= " [{$extraLabelValue}]"; } } /* Selected attr */ $selected_attr = ''; $selected = meAnjanWqg_Utils::arrayValue($params, 'selected', ''); if (is_array($selected) && in_array($value, $selected)) { $selected_attr = ' selected'; } else { if ($selected == $value) { $selected_attr = ' selected'; } } $html = "<option value='{$value}'{$selected_attr}>{$label}</option>"; return $html; }
/** * Get config * * @param string $key * @param null $default * * @return mixed */ public function getConfig($key = '', $default = null) { $key = trim($key); if ($key == '') { return $this->_config; } return meAnjanWqg_Utils::arrayValue($this->_config, $key, $default); }
/** * Generates <option> tag for a category * * @param array $params * * @return bool|string */ public static function generateCategoryOption($params = array()) { $category = meAnjanWqg_Utils::arrayValue($params, 'category', false); if (!is_object($category)) { return false; } $label_field = meAnjanWqg_Utils::arrayValue($params, 'label_field', 'name'); $label_field_extra = meAnjanWqg_Utils::arrayValue($params, 'label_field_extra', ''); $value_field = meAnjanWqg_Utils::arrayValue($params, 'value_field', 'term_id'); $indent = (int) meAnjanWqg_Utils::arrayValue($params, 'indent', 0); $label = isset($category->{$label_field}) ? $category->{$label_field} : ''; if ($label_field_extra != '') { $extraLabelValue = isset($category->{$label_field_extra}) ? trim($category->{$label_field_extra}) : ''; if ($extraLabelValue != '') { $label .= " [{$extraLabelValue}]"; } } $value = isset($category->{$value_field}) ? $category->{$value_field} : ''; $label = str_repeat('-', $indent) . $label; /* Selected attr */ $selected_attr = ''; $selected = meAnjanWqg_Utils::arrayValue($params, 'selected', ''); if (is_array($selected) && in_array($value, $selected)) { $selected_attr = ' selected'; } else { if ($selected == $value) { $selected_attr = ' selected'; } } $html = "<option value='{$value}'{$selected_attr}>{$label}</option>"; $categories = self::getCategories($category->term_id); /* Child categories */ if (is_array($categories) && count($categories) > 0) { foreach ($categories as $c) { $newParam = $params; $newParam['indent'] = $indent + 1; $newParam['category'] = $c; $html .= self::generateCategoryOption($newParam); } } return $html; }
/** * Prepares the data to be passed to javascript * * @return array * */ private function prepareJsData() { $main = meAnjanWqg_Main::getInstance(); $jsData = array('idPrefix' => $main->getConfig('idPrefix'), 'ajax_url' => array('form_generate' => meAnjanWqg_Utils::wpAjaxUrl(self::AJAX_ACTION_GENERATE_CODE), 'author_id_autocomplete' => meAnjanWqg_Utils::wpAjaxUrl(self::AJAX_ACTION_AUTHOR_ID_AUTOCOMLETE), 'author_name_autocomplete' => meAnjanWqg_Utils::wpAjaxUrl(self::AJAX_ACTION_AUTHOR_NAME_AUTOCOMLETE), 'taxonomy_terms' => meAnjanWqg_Utils::wpAjaxUrl(self::AJAX_ACTION_TAXONOMY_TERMS), 'data_preview' => meAnjanWqg_Utils::wpAjaxUrl(self::AJAX_ACTION_DATA_PREVIEW), 'post_list' => meAnjanWqg_Utils::wpAjaxUrl(self::AJAX_ACTION_POST_LIST)), 'codeMirrorTheme' => self::CODEMIRROR_THEME, 'html_ids' => $main->getConfig('html/ids'), 'taxonomies' => meAnjanWqg_Taxonomies::getTaxonomies(), 'taxonomy_fields' => array(array('label' => 'ID', 'value' => 'term_id', 'default' => 1), array('label' => 'Name', 'value' => 'name', 'default' => 0), array('label' => 'Slug', 'value' => 'slug', 'default' => 0)), 'taxonomy_operators' => array(array('value' => 'IN', 'default' => 1, 'label' => 'Match Any'), array('value' => 'NOT IN', 'default' => 0, 'label' => 'Match None'), array('value' => 'AND', 'default' => 0, 'label' => 'Match All'), array('value' => 'EXISTS', 'default' => 0, 'label' => 'Exists'), array('value' => 'NOT EXISTS', 'default' => 0, 'label' => 'Not Exists'))); return $jsData; }
<table class="form-table"> <tr> <td> <label> <strong>Search By Keyword (#s)</strong>Search entries by a keyword<br /> <input type="text" name="search[keyword]" value="<?php echo stripslashes(meAnjanWqg_Utils::arrayValueAsString($wqgData, 'search/keyword', '')); ?> " > </label> </td> </tr> </table>
<tr> <td> <label> <strong>Exclude Author ID List (#author__not_in)</strong>Exclude posts from selected authors<br /> <select data-placeholder="Select one or more author" name="author[not_in][]" id="author_not_in" title="Excluded Author ID List" size="10" multiple> <?php if (is_array($wqg_users) && count($wqg_users) > 0) { ?> <?php foreach ($wqg_users as $u) { ?> <option <?php echo meAnjanWqg_Utils::selectedAttr($wqgData, 'author/not_in', $u['id'], true); ?> value="<?php echo $u['id']; ?> "><?php echo $u['name']; ?> [<?php echo $u['id']; ?> ]</option> <?php } ?>
?> </option> <?php } ?> </select> </label> </td> </tr> <tr> <td> <div class="me-anjan-wqg-meta-query-block" id="me-anjan-wqg-meta-query-block"> </div> <div style="clear: both;"></div> <input type="button" id="me-anjan-wqg-add-meta-query" value="Add Meta Query" class="button"/> </td> </tr> </table> <script type="text/javascript"> var meAnjanWqgMetaQueryCriterias = <?php echo json_encode(array_values(meAnjanWqg_Utils::arrayValue($wqgData, 'meta_query/queries'))); ?> ; </script>
/** * Generates code and args for meta key search * * @param $start_indent * * @return string */ public function generateMetaArgCode($start_indent) { /** @var wpdb $wpdb */ global $wpdb; $metaCompareTypes = array('=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN', 'NOT EXISTS', 'REGEXP', 'NOT REGEXP', 'RLIKE'); $start_indent = (int) $start_indent; if ($start_indent < 0) { $start_indent = 0; } $data = meAnjanWqg_Utils::arrayValue($this->_data, 'meta'); $code = array(); if (is_array($data) && count($data) > 0) { $key = meAnjanWqg_Utils::arrayValueAsString($data, 'key', '', 'trim'); $value = meAnjanWqg_Utils::arrayValueAsString($data, 'value', '', 'trim'); $value_num = meAnjanWqg_Utils::arrayValueAsString($data, 'value_num', '', 'trim'); $compare = meAnjanWqg_Utils::arrayValueAsString($data, 'compare', '', 'trim'); if ($key != '') { if (!in_array($compare, $metaCompareTypes)) { $compare = '='; } if ($value != '' || $value_num != '') { # key $code[] = meAnjanWqg_Utils::_l($start_indent, "'meta_key' => '{$key}',", 1); $this->_args['meta_key'] = $key; # compare $code[] = meAnjanWqg_Utils::_l($start_indent, "'meta_compare' => '{$compare}',", 1); $this->_args['meta_compare'] = $compare; # value if ($value != '') { $code[] = meAnjanWqg_Utils::_l($start_indent, "'meta_value' => '{$value}',", 1); $this->_args['meta_value'] = $value; } # value_num if ($value_num != '') { $code[] = meAnjanWqg_Utils::_l($start_indent, "'meta_value_num' => '{$value_num}',", 1); $this->_args['meta_value_num'] = $value_num; } } } } if (!empty($code)) { $content = PHP_EOL; $content .= meAnjanWqg_Utils::_l($start_indent, "/* Meta key params */", 2); $content .= join('', $code); return $content; } return join('', $code); }
</label> </td> </tr> <tr> <td> <label> <strong>Minute (#minute)</strong>Posted in the minute<br /> <input type="text" name="date[minute]" value="<?php echo stripslashes(meAnjanWqg_Utils::arrayValueAsString($wqgData, 'date/minute', '')); ?> " > </label> </td> </tr> <tr> <td> <label> <strong>Second (#second)</strong>Posted in the second<br /> <input type="text" name="date[second]" value="<?php echo stripslashes(meAnjanWqg_Utils::arrayValueAsString($wqgData, 'date/second', '')); ?> " > </label> </td> </tr> </table>
<tr> <td> <label> <strong>Meta Value as number (#meta_value_num)</strong>Meta value as number<br/> <select size="1" name="meta[compare]"> <?php foreach ($metaComparisonTypes as $v) { ?> <option value="<?php echo $v; ?> " <?php if ($v == meAnjanWqg_Utils::arrayValue($wqgData, 'meta/compare', '=')) { ?> selected="selected"<?php } ?> ><?php echo $v; ?> </option> <?php } ?> </select> </label> </td>
<label> <strong>Posts Per Archive Page (#posts_per_archive_page)</strong>Number of posts per archive/search page<br/> <input type="text" name="pagination[posts_per_archive_page]" value="<?php echo meAnjanWqg_Utils::arrayValue($wqgData, 'pagination/posts_per_archive_page'); ?> " /> </label> </td> </tr> <tr> <td> <label> <?php $ignore_sticky_posts = meAnjanWqg_Utils::arrayValueAsInt($wqgData, 'pagination/ignore_sticky_posts', 0) > 0; ?> <input type="hidden" name="pagination[ignore_sticky_posts]" value="0" /> <input type="checkbox" name="pagination[ignore_sticky_posts]" value="1" <?php if ($ignore_sticky_posts) { ?> checked<?php } ?> /> Ignore Sticky Posts </label> </td> </tr> </tbody>
echo meAnjanWqg_Posts::postsDropdown(array('post_type' => $selectedPostTypes, 'nopaging' => TRUE, 'empty_value' => array('label' => '', 'value' => ''), 'label_field' => 'post_name', 'value_field' => 'post_name', 'attributes' => array('name' => 'post[post_slug]', 'id' => $idPrefix . 'post-slug', 'class' => 'chosen', 'data-placeholder' => ' '), 'selected' => meAnjanWqg_Utils::arrayValue($wqgData, 'post/post_slug'))); ?> </label> </td> </tr> <!-- post_slug --> <tr> <td> <label> <strong>Parent Post (#post_parent)</strong>Get child posts<br/> <?php echo meAnjanWqg_Posts::postsDropdown(array('post_type' => $selectedPostTypes, 'nopaging' => TRUE, 'label_field' => 'post_title', 'label_field_extra' => 'ID', 'value_field' => 'ID', 'attributes' => array('name' => 'post[post_parent][]', 'id' => $idPrefix . 'post-parent', 'class' => 'chosen', 'data-placeholder' => 'Select one or more posts', 'multiple' => 'multiple'), 'selected' => meAnjanWqg_Utils::arrayValue($wqgData, 'post/post_parent'))); ?> </label> </td> </tr> <!-- post_parent --> <tr> <td> <label> <strong>Exclude Parent Posts (#post_parent__not_in)</strong>Exclude posts with these parent posts<br/> <?php echo meAnjanWqg_Posts::postsDropdown(array('post_type' => $selectedPostTypes, 'nopaging' => TRUE, 'label_field' => 'post_title', 'label_field_extra' => 'ID', 'value_field' => 'ID', 'attributes' => array('name' => 'post[post_parent_not_in][]', 'id' => $idPrefix . 'post-parent-not-in', 'class' => 'chosen', 'data-placeholder' => 'Select one or more posts', 'multiple' => 'multiple'), 'selected' => meAnjanWqg_Utils::arrayValue($wqgData, 'post/post_parent_not_in'))); ?> </label> </td> </tr> <!-- post_parent__not_in --> </table>
*/ $criteriaData = meAnjanWqg_Utils::arrayValueAsArray($wqgData, 'date_query/criteria', array()); $criteriaData = array_values($criteriaData); // to force json array $dateCompareOperators = array('=', '!=', '>', '>=', '<', '<=', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'); ?> <table class="form-table"> <tr> <td> <label> <strong>Relation (#date_query/relation)</strong>Match all or match any?<br /> <?php $dateQueryRelations = array('and', 'or'); $selectedRelation = meAnjanWqg_Utils::arrayValueAsString($wqgData, 'date_query/relation', 'and', 'trim'); ?> <select id="<?php echo $idPrefix; ?> date-query-relation" name="date_query[relation]" class="chosen" data-placeholder="Select relation"> <?php foreach ($dateQueryRelations as $key) { ?> <option value="<?php echo $key; ?> " <?php if ($key == $selectedRelation) {
} ?> <div style="clear: both;"></div> <div class="me-anjan-wqg-buttons-container"> <input type="hidden" name="wqg-action" id="<?php echo $idPrefix; ?> action" value="generate-code"> <input type="hidden" class="wqgCurrentTab" name="currentTab" value="<?php echo meAnjanWqg_Utils::arrayValue($wqgData, 'currentTab'); ?> "/> <button type="submit" class="button-primary">Save & Generate</button> <button type="button" id="<?php echo $idPrefix . $main->getConfig('html/ids/reset_button'); ?> " class="button-primary red" name="reset_wqg_data">Reset </button> </div> </div> <div style="clear: both;"></div>
</select> </label> </td> </tr> <tr> <td> <div class="me-anjan-wqg-tax-query-block"></div> <div style="clear: both;"></div> <input type="button" id="me-anjan-wqg-add-taxonomy" value="Add Taxonomy" class="button" /> </td> </tr> <tr> <td> <?php $res = meAnjanWqg_Taxonomies::getTaxonomies(); ?> </td> </tr> </table> <script type="text/javascript"> var meAnjanPluginsWqgTaxRules = <?php echo json_encode(meAnjanWqg_Utils::arrayValue($wqgData, 'tax/rules')); ?> ; </script>
<?php echo meAnjanWqg_Posts::postsDropdown(array('post_type' => 'post', 'nopaging' => TRUE, 'empty_value' => array('label' => '~ Select ~', 'value' => ''), 'label_field' => 'post_name', 'value_field' => 'post_name', 'attributes' => array('name' => 'post[post_slug]', 'id' => 'post_slug', 'class' => 'chosen'), 'selected' => meAnjanWqg_Utils::arrayValue($wqgData, 'post/post_slug'))); ?> </label> </td> </tr> <!-- post_slug --> <tr> <td> <label> <strong>Page ID (#p)</strong>Get entries by selected post id<br/> <?php echo meAnjanWqg_Posts::postsDropdown(array('post_type' => 'page', 'nopaging' => TRUE, 'empty_value' => array('label' => '~ Select ~', 'value' => ''), 'label_field' => 'post_title', 'value_field' => 'ID', 'attributes' => array('name' => 'post[page_id]', 'id' => 'page_id', 'class' => 'chosen'), 'selected' => meAnjanWqg_Utils::arrayValue($wqgData, 'post/page_id'))); ?> </label> </td> </tr> <!-- page_id --> <tr> <td> <label> <strong>Post Slug (#name)</strong>Get entries by selected post slug<br/> <?php echo meAnjanWqg_Posts::postsDropdown(array('post_type' => 'page', 'nopaging' => TRUE, 'empty_value' => array('label' => '~ Select ~', 'value' => ''), 'label_field' => 'post_name', 'value_field' => 'post_name', 'attributes' => array('name' => 'post[page_slug]', 'id' => 'page_slug', 'class' => 'chosen'), 'selected' => meAnjanWqg_Utils::arrayValue($wqgData, 'post/page_slug'))); ?> </label> </td> </tr> <!-- page_slug --> </table>
echo meAnjanWqg_Tags::tagsDropdown(array('label_field' => 'name', 'label_field_extra' => 'term_id', 'value_field' => 'term_id', 'attributes' => array('name' => 'tag[and][]', 'id' => 'tag_and', 'multiple' => 'multiple', 'data-placeholder' => 'Select one or more tag id'), 'selected' => meAnjanWqg_Utils::arrayValue($wqgData, 'tag/and'))); ?> </label> </td> </tr> <!-- and --> <tr> <td> <label> <strong>Any Tag ID (#tag__in)</strong>Get entries having any of the selected tag ids<br /> <?php echo meAnjanWqg_Tags::tagsDropdown(array('label_field' => 'name', 'label_field_extra' => 'term_id', 'value_field' => 'term_id', 'attributes' => array('name' => 'tag[in][]', 'id' => 'tag_in', 'multiple' => 'multiple', 'data-placeholder' => 'Select one or more tag id'), 'selected' => meAnjanWqg_Utils::arrayValue($wqgData, 'tag/in'))); ?> </label> </td> </tr> <!-- in --> <tr> <td> <label> <strong>Exclude Tag IDs (#tag__not_in)</strong>Get entries not having any of the selected tag ids<br /> <?php echo meAnjanWqg_Tags::tagsDropdown(array('label_field' => 'name', 'label_field_extra' => 'term_id', 'value_field' => 'term_id', 'attributes' => array('name' => 'tag[not_in][]', 'id' => 'tag_not_in', 'multiple' => 'multiple', 'data-placeholder' => 'Select one or more tag id'), 'selected' => meAnjanWqg_Utils::arrayValue($wqgData, 'tag/not_in'))); ?> </label> </td> </tr> <!-- not in --> </table>
/** * Gets post order by field values * * @return array */ public static function getPostOrderByFields() { $keys = array('ID', 'author', 'title', 'name', 'date', 'modified', 'parent', 'rand', 'menu_order', 'meta_value'); if (meAnjanWqg_Utils::isMinWpVersion('2.8')) { $keys[] = 'none'; $keys[] = 'meta_value_num'; } if (meAnjanWqg_Utils::isMinWpVersion('2.9')) { $keys[] = 'comment_count'; } if (meAnjanWqg_Utils::isMinWpVersion('3.5')) { $keys[] = 'post__in'; } if (meAnjanWqg_Utils::isMinWpVersion('4.0')) { $keys[] = 'type'; } asort($keys); return $keys; }
<?php } ?> </select> </label> </td> </tr> <tr> <td> <label> <strong>Sort Dir (#order)</strong>Sorting direction<br/> <?php $sortDirs = array('asc', 'desc'); $selectedSortDir = meAnjanWqg_Utils::arrayValueAsString($wqgData, 'sorting/order', 'desc', 'trim'); ?> <select id="<?php echo $idPrefix; ?> sorting-order" name="sorting[order]" class="chosen" data-placeholder="Select order"> <?php foreach ($sortDirs as $key) { ?> <option value="<?php echo $key; ?> " <?php if ($key == $selectedSortDir) {
</tr> <tr> <td> <label> <strong>Category Ids in (#category__in)</strong>Get entries associated with <b>ANY</b> of the selected category ids<br /> <?php echo meAnjanWqg_Categories::categoriesDropdown(array('label_field' => 'name', 'label_field_extra' => 'term_id', 'value_field' => 'term_id', 'attributes' => array('name' => 'category[in][]', 'id' => 'category_in', 'multiple' => 'multiple', 'size' => 10, 'data-placeholder' => 'Select one or more categories'), 'selected' => meAnjanWqg_Utils::arrayValue($wqgData, 'category/in'))); ?> </label> </td> </tr> <tr> <td> <label> <strong>Exclude Categories (#category__not_in)</strong>Get entries <b>NOT</b> associated with any of the selected category ids<br /> <?php echo meAnjanWqg_Categories::categoriesDropdown(array('label_field' => 'name', 'label_field_extra' => 'term_id', 'value_field' => 'term_id', 'attributes' => array('name' => 'category[not_in][]', 'id' => 'category_not_in', 'multiple' => 'multiple', 'size' => 10, 'data-placeholder' => 'Select one or more categories'), 'selected' => meAnjanWqg_Utils::arrayValue($wqgData, 'category/not_in'))); ?> </label> </td> </tr> </table>