/** * Registers a taxonomy * @param Taxonomy $taxonomy The taxonomy model * @return object What is being returned by register_taxonomy */ private function registerTaxonomy(Taxonomy $taxonomy) { $labelParser = new LabelParser($taxonomy); $labelParser->parse(); $singular = $labelParser->singular(); $plural = $labelParser->plural(); $key = $this->model->getWordpressKey() . "_" . $taxonomy->getWordpressKey(); $customizedOptions = $taxonomy->getConfiguration() + array('hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_admin_column' => true, 'update_count_callback' => '_update_post_term_count', 'query_var' => $key, 'show_in_nav_menus' => false, 'show_tagcloud' => false, 'rewrite' => array(), 'capabilities' => array(), 'labels' => array()); $customizedOptions['capabilities'] += array('manage_terms' => 'read', 'edit_terms' => 'read', 'delete_terms' => 'read', 'assign_terms' => 'read'); $customizedOptions['rewrite'] += array('with_front' => true, 'slug' => $key); $customizedOptions['labels'] += array('name' => _x($plural, 'Post Type General Name', 'strata'), 'singular_name' => _x($singular, 'Post Type Singular Name', 'strata'), 'menu_name' => __($plural, 'strata'), 'parent_item_colon' => __($singular . ' Item:', 'strata'), 'all_items' => __('All ' . $plural, 'strata'), 'view_item' => __('View ' . $singular . ' Item', 'strata'), 'add_new_item' => __('Add New', 'strata'), 'add_new' => __('Add New', 'strata'), 'edit_item' => __('Edit ' . $singular, 'strata'), 'update_item' => __('Update ' . $singular, 'strata'), 'search_items' => __('Search ' . $plural, 'strata'), 'not_found' => __('Not found', 'strata'), 'not_found_in_trash' => __('Not found in Trash', 'strata')); $wordpressKey = $taxonomy->getWordpressKey(); Strata::app()->setConfig("runtime.taxonomy.query_vars.{$wordpressKey}", $customizedOptions['query_var']); return register_taxonomy($wordpressKey, array($this->model->getWordpressKey()), $customizedOptions); }
protected function getModelEntityByString($taxonomy) { try { return Taxonomy::factoryFromKey($taxonomy); } catch (Exception $e) { // don't care, not a strata model. } }
private function rewriteStrataTaxonomy($taxonomyKey, $config) { try { $taxonomy = Taxonomy::factory(substr($taxonomyKey, 4)); $localizedSlugs = array_merge(array($taxonomy->hasConfig("rewrite.slug") ? $taxonomy->getConfig("rewrite.slug") : $taxonomyKey), $taxonomy->extractConfig("i18n.{s}.rewrite.slug")); $this->addTaxonomyRewrites(implode("|", $localizedSlugs), $config->query_var); } catch (Exception $e) { Strata::app()->log("Tried to translate {$taxonomyKey}, but could not find the associated model.", "<magenta>Polyglot:UrlRewriter</magenta>"); } }
public static function factoryFromKey($wordpressKey) { if (preg_match('/_?cpt_(\\w+)/', $wordpressKey, $matches)) { return self::factory($matches[1]); } elseif (preg_match('/_?tax_(\\w+)/', $wordpressKey, $matches)) { return Taxonomy::factory($matches[1]); } elseif (preg_match('/_?(post|page)/', $wordpressKey, $matches)) { return self::factory($matches[1]); } }
private function batchTaxonomyFileRegistrationAttempt($files = array()) { foreach ($files as $filename) { try { $potentialClassName = basename(substr($filename, 0, -4)); $model = Taxonomy::factory($potentialClassName); $this->attemptRuleExtraction($model); } catch (Exception $e) { // falure only means its not a Strata model. } } }
/** * Gets the associated taxonomy objects. * @return array */ public function getTaxonomies() { $tax = array(); foreach (Hash::normalize($this->belongs_to) as $taxonomyName => $taxonomyConfig) { if (class_exists($taxonomyName)) { $tax[] = new $taxonomyName(); } else { $tax[] = Taxonomy::factory($taxonomyName); } } return $tax; }
/** * {@inheritdoc} */ public function applyOptions(array $args) { $this->keyword = $args[0]; $this->classname = Taxonomy::generateClassName($this->keyword); }