public static function getTerms($websiteid, $prefix = '', $what = 'site', $gen_type = 'post') { $output = new stdClass(); $output->errors = array(); $output->cats = array(); $dbwebsites = array(); if ($what == 'group') { $input_name = 'groups_selected_cats_' . $prefix . '[]'; } else { $input_name = 'sites_selected_cats_' . $prefix . '[]'; } if (!empty($websiteid)) { if (MainWP_Utility::ctype_digit($websiteid)) { $website = MainWP_DB::Instance()->getWebsiteById($websiteid); $dbwebsites[$website->id] = MainWP_Utility::mapSite($website, array('id', 'url', 'name', 'adminname', 'nossl', 'privkey', 'nosslkey')); } } if ($gen_type == 'post') { $bkc_option_path = 'default_keywords_post'; $keyword_option = 'keywords_page'; } else { if ($gen_type == 'page') { $bkc_option_path = 'default_keywords_page'; $keyword_option = 'keywords_page'; } } if ($prefix == 'bulk') { $opt = apply_filters('mainwp-get-options', $value = '', 'mainwp_content_extension', 'bulk_keyword_cats', $bkc_option_path); $selected_cats = unserialize(base64_decode($opt)); } else { $opt = apply_filters('mainwp-get-options', $value = '', 'mainwp_content_extension', $keyword_option); if (is_array($opt) && is_array($opt[$prefix])) { $selected_cats = unserialize(base64_decode($opt[$prefix]['selected_cats'])); } } $selected_cats = is_array($selected_cats) ? $selected_cats : array(); $ret = ''; if (count($dbwebsites) > 0) { $opt = apply_filters('mainwp-get-options', $value = '', 'mainwp_content_extension', 'taxonomy'); $post_data = array('taxonomy' => base64_encode($opt)); MainWP_Utility::fetchUrlsAuthed($dbwebsites, 'get_terms', $post_data, array(MainWP_Post::getClassName(), 'PostsGetTerms_handler'), $output); foreach ($dbwebsites as $siteid => $website) { $cats = array(); if (is_array($selected_cats[$siteid])) { foreach ($selected_cats[$siteid] as $val) { $cats[] = $val['term_id']; } } if (!empty($output->errors[$siteid])) { $ret .= '<p> ' . __('Error - ', 'mainwp') . $output->errors[$siteid] . '</p>'; } else { if (count($output->cats[$siteid]) > 0) { foreach ($output->cats[$siteid] as $cat) { if ($cat->term_id) { if (in_array($cat->term_id, $cats)) { $checked = ' checked="checked" '; } else { $checked = ''; } $ret .= '<div class="mainwp_selected_sites_item ' . (!empty($checked) ? 'selected_sites_item_checked' : '') . '"><input type="checkbox" name="' . $input_name . '" value="' . $siteid . ',' . $cat->term_id . ',' . stripslashes($cat->name) . '" ' . $checked . '/><label>' . $cat->name . '</label></div>'; } } } else { $ret .= '<p>No categories have been found</p>'; } } } } else { $ret .= '<p>' . __('Error - ', 'mainwp') . ' no site</p>'; } echo $ret; }