public static function to_xml($data = null, $xml = null, $basenode = 'xml') { // turn off compatibility mode as simple xml throws a wobbly if you don't. if (@ini_get('zend.ze1_compatibility_mode') == 1) { @ini_set('zend.ze1_compatibility_mode', 0); } if ($xml === null) { $xml = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><{$basenode} />"); } // Force it to be something useful if (!is_array($data) && !is_object($data)) { $data = (array) $data; } foreach ($data as $key => $value) { // no numeric keys in our xml please! if (is_numeric($key)) { // make string key... $key = mgm_singular($basenode) != $basenode ? mgm_singular($basenode) : 'item'; } // replace anything not alpha numeric $key = preg_replace('/[^a-z_\\-0-9]/i', '', $key); $key = preg_replace('/^[0-9]{1,}/i', '', $key); // lower $key = strtolower($key); // if there is another array found recrusively call this function if (is_array($value) || is_object($value)) { $node = $xml->addChild($key); // recrusive call. mgm_format::to_xml($value, $node, $key); } else { // add single node. $value = htmlspecialchars(html_entity_decode($value, ENT_QUOTES, 'UTF-8'), ENT_QUOTES, "UTF-8"); $xml->addChild($key, $value); } } // as xml return $xml->asXML(); }
/** * get gifted contents * * @verb GET * @action all * @url <site>/mgmapi/contents/gifted.<format> -- list all post types * @url <site>/mgmapi/contents/gifted/:(posts|pages|custom_post_type).<format> -- list only specified post type * @url <site>/mgmapi/contents/gifted/:(posts|pages|custom_post_type)/:id.<format> -- list specified post type by post id * * @param string $post_type * @param int $id * @since 1.0 */ public function gifted_get($post_type = '', $id = NULL) { global $wpdb; // get vars $get_vars = $this->request->data['get']; // start $start = isset($get_vars['start']) ? (int) $get_vars['start'] : 0; // rows $rows = isset($get_vars['rows']) ? (int) $get_vars['rows'] : 100; // status $status = 'success'; $message = ''; // registered post types $post_types = mgm_get_post_types(false); // all post types if (empty($post_type)) { // get $contents = $this->_get_purchased_contents($post_types, $id, $start, $rows, true); // content type $content_type = 'all post types'; } else { // post/page if (in_array($post_type, array('posts', 'pages'))) { $post_type = mgm_singular($post_type); } // validate if (!in_array($post_type, $post_types)) { // error $status = 'error'; $message = sprintf(__('Specified post type - %s is invalid, try with a valid post type only', 'mgm'), $post_type); } else { // get $contents = $this->_get_purchased_contents($post_type, $id, $start, $rows, true); // content type $content_type = $post_type; } } // name $content_type_name = 'contents'; // data when contents found if (isset($contents)) { // total rows $total_rows = count($contents); // base $data = array('total_rows' => $total_rows); // by id if (isset($id) && (int) $id > 0) { // message $message = sprintf(__('Get gifted - %s dy id#%d response', 'mgm'), $content_type, $id); // data if ($total_rows > 0) { $data = $data + array(mgm_singular($content_type_name) => array_shift($contents)); } } else { // all // message $message = sprintf(__('Get gifted - %s response - %d %s found', 'mgm'), $content_type, $total_rows, $content_type); // data if ($total_rows > 0) { $data = $data + array($content_type_name => $contents); } } } // response $response = array('status' => $status, 'message' => $message); // data if (isset($data)) { $response = $response + array('data' => $data); } // return return array($response, 200); }
/** * edit/add term/taxonomy form to assign access by membership types * * @param taxonomy * @return none */ function mgm_taxonomy_form($taxonomy) { // except tags if (is_object($taxonomy)) { $term = $taxonomy->taxonomy; } else { $term = $taxonomy; } // exit if tags if ($term == 'post_tag') { return; } // member types $access_membership_types = mgm_get_class('post_taxonomy')->get_access_membership_types(); // init $membership_types = array(); // check edit if (isset($taxonomy->term_id) && $taxonomy->term_id > 0) { // check if (isset($access_membership_types[$taxonomy->term_id])) { $membership_types = $access_membership_types[$taxonomy->term_id]; } } // label if ($tax = get_taxonomy($term)) { $label = isset($tax->singular_label) ? $tax->singular_label : (isset($tax->labels->singular_name) ? $tax->labels->singular_name : mgm_singular($term)); $name = isset($tax->name) ? $tax->name : $term; } else { $label = mgm_singular($term); $name = $term; } // access $mgm_taxonomy_access = mgm_make_checkbox_group('mgm_taxonomy_access[]', mgm_get_class('membership_types')->membership_types, $membership_types, MGM_KEY_VALUE); ?> <script language="javascript"> <!-- jQuery(document).ready(function(){ <?php if (isset($taxonomy->term_id) && intval($taxonomy->term_id) > 0) { ?> var html='<tr class="form-field form-required">' + ' <th scope="row" valign="top"><label for="cat_name"><?php printf(__('%s Protection', 'mgm'), $label); ?> </label></th>' + ' <td><div>'+"<?php echo $mgm_taxonomy_access; ?> "+'</div>'+ ' <p><?php printf(__('Only selected membership types can access the <b>%s</b> taxonomy (Leave all unchecked to allow public access)', 'mgm'), $label); ?> </p></td>' + '</tr>'; jQuery("#edittag .form-table:last").append(html); <?php } else { ?> var html='<div class="form-field">'+ '<label for="mgm_taxonomy_access"><?php printf(__('%s Protection', 'mgm'), $label); ?> </label>'+ "<?php echo $mgm_taxonomy_access; ?> "+ '<p><?php printf(__('Only selected membership types can access the <b>%s</b> taxonomy (Leave all unchecked to allow public access)', 'mgm'), $label); ?> .</p>'+ '</div>'; jQuery("#addtag p.submit").before(html); <?php } ?> }); //--> </script> <?php }