Changeset 2054167
- Timestamp:
- 03/20/2019 06:10:59 PM (7 years ago)
- Location:
- xo-for-angular/trunk
- Files:
-
- 2 added
- 1 deleted
- 5 edited
-
Includes/Api/Abstract/Objects/Term.class.php (modified) (4 diffs)
-
Includes/Api/Abstract/Responses/TermsFilterResponse.class.php (added)
-
Includes/Api/Abstract/Responses/TermsGetResponse.class.php (added)
-
Includes/Api/Abstract/Responses/TermsResponse.class.php (deleted)
-
Includes/Api/Api.class.php (modified) (1 diff)
-
Includes/Api/Controllers/TermsController.class.php (modified) (3 diffs)
-
Includes/Services/Classes/RouteGenerator.class.php (modified) (2 diffs)
-
xo-angular.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
xo-for-angular/trunk/Includes/Api/Abstract/Objects/Term.class.php
r2042983 r2054167 99 99 100 100 /** 101 * Optional collection of ACF fields set for the given term. 102 * 103 * @since 1.0.7 104 * 105 * @var array 106 */ 107 public $fields; 108 109 /** 101 110 * Generate a fully formed term object. 102 111 * … … 105 114 * @param WP_Term $term The base term object. 106 115 * @param bool $meta Optionally include meta in term object. 116 * @param bool $fields Optionally include ACF fields in post object. 107 117 */ 108 function __construct(WP_Term $term, $meta = false ) {118 function __construct(WP_Term $term, $meta = false, $fields = false) { 109 119 // Map base term object properties 110 120 $this->id = $term->term_id; … … 119 129 // Set the relative URL of the term using get_term_link and wp_make_link_relative 120 130 $this->url = wp_make_link_relative(get_term_link($term)); 131 132 // Optionally set the post fields 133 if ($fields) 134 $this->SetFields(); 121 135 122 136 // Optionally set the term meta … … 138 152 139 153 // Iterate over the retrieved meta options 140 foreach ($meta as $key => $value) 141 if ((is_array($value)) && (count($value) == 1) && (substr($key, 0, 1) != '_')) 154 foreach ($meta as $key => $value) { 155 // Skip the option if name not starts with an underscore indicating private or internal data 156 if (substr($key, 0, 1) == '_') 157 continue; 158 159 $addMeta = true; 160 161 // Check if meta option should be excluded 162 if (!empty($this->fields)) { 163 foreach ($this->fields as $exclude => $excludeValue) { 164 if (substr($key, 0, strlen($exclude)) == $exclude) { 165 $addMeta = false; 166 break; 167 } 168 } 169 } 170 171 if (!$addMeta) 172 continue; 173 174 if ((is_array($value)) && (count($value) == 1)) 142 175 $this->meta[$key] = $value[0]; 176 } 177 } 178 179 /** 180 * Set the ACF fields that are set for the given post. 181 * 182 * @since 1.0.7 183 * 184 * @return void 185 */ 186 public function SetFields() { 187 // Return empty array if ACF is unavailable 188 if (!function_exists('get_fields')) 189 return; 190 191 // Get collection of ACF fields for the post 192 $this->fields = get_fields($this->taxonomy . '_' . $this->id); 143 193 } 144 194 } -
xo-for-angular/trunk/Includes/Api/Api.class.php
r2051900 r2054167 68 68 $this->Xo->RequireOnce('Includes/Api/Abstract/Responses/PostsConfigResponse.class.php'); 69 69 $this->Xo->RequireOnce('Includes/Api/Abstract/Responses/MenusResponse.class.php'); 70 $this->Xo->RequireOnce('Includes/Api/Abstract/Responses/TermsResponse.class.php'); 70 $this->Xo->RequireOnce('Includes/Api/Abstract/Responses/TermsGetResponse.class.php'); 71 $this->Xo->RequireOnce('Includes/Api/Abstract/Responses/TermsFilterResponse.class.php'); 71 72 $this->Xo->RequireOnce('Includes/Api/Abstract/Responses/OptionsResponse.class.php'); 72 73 } -
xo-for-angular/trunk/Includes/Api/Controllers/TermsController.class.php
r2042983 r2054167 8 8 class XoApiControllerTerms extends XoApiAbstractIndexController 9 9 { 10 /** 11 * Get a taxonomy and term by url. 12 * 13 * @since 1.0.7 14 * 15 * @param mixed $params Request object 16 * @return XoApiAbstractTermsGetResponse 17 */ 18 public function Get($params) { 19 // Return an error if the url is missing 20 if (empty($params['url'])) 21 return new XoApiAbstractTermsGetResponse(false, __('Missing category url.', 'xo')); 22 23 // Get the taxonomy by parsing the requested url 24 $taxonomy = $this->GetTaxonomyByUrl($params['url']); 25 26 // Return an error if the taxonomy was not found 27 if (!$taxonomy) 28 return new XoApiAbstractTermsGetResponse(false, __('Unable to locate taxonomy.', 'xo')); 29 30 // Get the term within the found taxonomy by comparing the requested url 31 $term = $this->GetTermByTaxonomyAndUrl($taxonomy, $params['url']); 32 33 // Return an error if the term was not found 34 if (!$term) 35 return new XoApiAbstractTermsGetResponse(false, __('Unable to locate term.', 'xo')); 36 37 // Return success and the taxonomy and term objects 38 return new XoApiAbstractTermsGetResponse( 39 true, __('Successfully located term.', 'xo'), 40 new XoApiAbstractTerm($term, true, true) 41 ); 42 } 43 10 44 /** 11 45 * Filter, search, or list terms by various properties similar to get_terms(). … … 37 71 $terms = array(); 38 72 foreach ($taxonomyTerms as $term) 39 $terms[] = new XoApiAbstractTerm($term, true );73 $terms[] = new XoApiAbstractTerm($term, true, true); 40 74 41 75 // Sort the terms by the given term meta key … … 53 87 ); 54 88 } 89 90 /** 91 * Summary of GetTaxonomyByUrl 92 * 93 * @since 1.0.7 94 * 95 * @param mixed $url 96 * @return boolean|WP_Taxonomy 97 */ 98 private function GetTaxonomyByUrl($url) { 99 $taxonomies = get_taxonomies(array(), 'objects'); 100 101 foreach ($taxonomies as $taxonomy_config) { 102 if (!$taxonomy_config->public) 103 continue; 104 105 if (empty($taxonomy_config->rewrite['slug'])) 106 continue; 107 108 $taxonomyUrl = '/' . $taxonomy_config->rewrite['slug'] . '/'; 109 110 if (strpos($url, $taxonomyUrl) === 0) 111 return $taxonomy_config; 112 } 113 114 return false; 115 } 116 117 /** 118 * Summary of GetTermByTaxonomyAndUrl 119 * @param WP_Taxonomy $taxonomy 120 * @param mixed $url 121 * @return boolean|WP_Term 122 */ 123 private function GetTermByTaxonomyAndUrl(WP_Taxonomy $taxonomy, $url) { 124 $url = trailingslashit($url); 125 126 $taxonomyTerms = get_terms(array( 127 'taxonomy' => $taxonomy->name 128 )); 129 130 if ((is_wp_error($taxonomyTerms)) || (empty($taxonomyTerms))) 131 return false; 132 133 foreach ($taxonomyTerms as $term) { 134 $termUrl = trailingslashit(wp_make_link_relative(get_term_link($term))); 135 136 if (strpos($url, $termUrl) === 0) 137 return $term; 138 } 139 140 return false; 141 } 55 142 } -
xo-for-angular/trunk/Includes/Services/Classes/RouteGenerator.class.php
r2051900 r2054167 93 93 94 94 // Check if the post type has a rewrite base 95 if ( isset($post_type_config->rewrite['slug'])) {95 if (!empty($post_type_config->rewrite['slug'])) { 96 96 // Get the template of the rewrite base 97 97 if ((!$template = $this->Xo->Services->Options->GetOption('xo_' . $post_type . '_template', false)) … … 99 99 continue; 100 100 101 // Remove any tags from rewrite slug 102 $rewriteSlug = preg_replace('/(%)(.*?)(%)/', '', $post_type_config->rewrite['slug']); 103 $rewriteSlug = untrailingslashit($rewriteSlug); 104 101 105 // Generate route for a posts hub page which will handle individual post urls 102 $routes[] = new XoApiAbstractRoute($ post_type_config->rewrite['slug'], $attrs['loadChildren'], 'prefix', array(106 $routes[] = new XoApiAbstractRoute($rewriteSlug, $attrs['loadChildren'], 'prefix', array( 103 107 'postType' => $post_type 104 108 )); -
xo-for-angular/trunk/xo-angular.php
r2052267 r2054167 4 4 Plugin URI: https://angularxo.io 5 5 Description: Angular theme development in WordPress with templates and a powerful API. 6 Version: 1.0. 66 Version: 1.0.7 7 7 Author: Travis Brown 8 8 Author URI: http://www.xodustech.com
Note: See TracChangeset
for help on using the changeset viewer.