コード例 #1
0
ファイル: StrataTest.php プロジェクト: francoisfaubert/strata
 public function testStrataConfigurableTrait()
 {
     $strata = new Strata();
     $strata->setConfig("first_level", array("second_level" => true));
     $value = $strata->getConfig("first_level.second_level");
     $this->assertTrue($value);
 }
コード例 #2
0
 public function __construct()
 {
     $i18n = Strata::i18n();
     $this->currentLocale = $i18n->getCurrentLocale();
     $this->defaultLocale = $i18n->getDefaultLocale();
     $this->textdomain = $i18n->getTextdomain();
 }
コード例 #3
0
 private function logMessage($message = "")
 {
     $logger = Strata::app()->getLogger();
     if (!is_null($logger)) {
         $logger->error($message, "Strata:Error");
     }
 }
コード例 #4
0
 /**
  * Assigns all the declared project commands.
  */
 public function assign()
 {
     $cmdPath = Strata::getCommandPath();
     if (is_dir($cmdPath)) {
         $this->parseDirectoryForCommandFiles($cmdPath);
     }
 }
コード例 #5
0
ファイル: UrlRoute.php プロジェクト: francoisfaubert/strata
 /**
  * Adds a resourced based route possibility based on a custom
  * post type or taxonomy.
  * @param WordpressEntity $model
  */
 public function addResourcePossibility(WordpressEntity $model)
 {
     $slug = null;
     if (property_exists($model, "routed") && is_array($model->routed) && array_key_exists("controller", $model->routed)) {
         $controllerName = $model->routed['controller'];
         $controllerObject = new $controllerName();
         $controller = $controllerObject->getShortName();
     } else {
         $controller = Controller::generateClassName($model->getShortName());
     }
     $i18n = Strata::i18n();
     if ($i18n->isLocalized()) {
         $currentLocale = $i18n->getCurrentLocale();
         if ($currentLocale && !$currentLocale->isDefault()) {
             $slugInfo = $model->extractConfig("i18n." . $currentLocale->getCode() . ".rewrite.slug");
             $slug = array_pop($slugInfo);
             if (!is_null($slug)) {
                 $this->automatedRoutes[] = array('*', "/{$slug}/page/[i:pageNumber]/?", "{$controller}#index");
                 $this->automatedRoutes[] = array('*', "/{$slug}/[:slug]/?", "{$controller}#show");
                 $this->automatedRoutes[] = array('*', "/{$slug}/?", "{$controller}#index");
             }
         }
     }
     $slugInfo = $model->extractConfig("rewrite.slug");
     $slug = array_pop($slugInfo);
     if (is_null($slug)) {
         $slug = $model->getWordpressKey();
     }
     $this->automatedRoutes[] = array('*', "/{$slug}/page/[i:pageNumber]/?", "{$controller}#index");
     $this->automatedRoutes[] = array('*', "/{$slug}/[:slug]/?", "{$controller}#show");
     $this->automatedRoutes[] = array('*', "/{$slug}/?", "{$controller}#index");
 }
コード例 #6
0
 public function filter_onInit()
 {
     $strataRewriter = Strata::rewriter();
     $i18n = Strata::i18n();
     $configuration = $i18n->getConfiguration();
     // Taxonomies
     $rewriter = new TaxonomyRewriter($i18n, $strataRewriter);
     $rewriter->setConfiguration($configuration);
     $rewriter->rewrite();
     // Custom Post Types
     $rewriter = new CustomPostTypeRewriter($i18n, $strataRewriter);
     $rewriter->setConfiguration($configuration);
     $rewriter->rewrite();
     // Translate homepages
     $rewriter = new HomepageRewriter($i18n, $strataRewriter);
     $rewriter->setDefaultHomepageId($i18n->query()->getDefaultHomepageId());
     $rewriter->rewrite();
     // Translate the default slugs
     $rewriter = new DefaultWordpressRewriter($i18n, $strataRewriter);
     $rewriter->setConfiguration($configuration);
     $rewriter->rewrite();
     $postPermalink = new PostPermalinkManager();
     add_filter('post_link', array($postPermalink, "filter_onCptLink"), 5, 2);
     add_filter('post_type_link', array($postPermalink, "filter_onCptLink"), 5, 2);
     add_filter('page_link', array($postPermalink, "filter_onPostLink"), 5, 2);
     $termPermalink = new TermPermalinkManager();
     add_filter('term_link', array($termPermalink, 'filter_onTermLink'), 5, 3);
     $metaManager = new PostMetaManager();
     add_action('save_post', array($metaManager, 'filter_onSavePost'), 100);
     $metaManager = new TermMetaManager();
     add_action('create_term', array($metaManager, 'filter_onCreateTerm'), 100);
     add_action('edit_term', array($metaManager, 'filter_onEditTerm'), 100);
 }
コード例 #7
0
 /**
  * Assigns all the declared shell commands of the middlewares.
  */
 public function assign()
 {
     $app = Strata::app();
     foreach ($app->getMiddlewares() as $middleware) {
         $this->attemptMultipleRegistrations($middleware->shellCommands);
     }
 }
コード例 #8
0
 public function __construct()
 {
     $i18n = Strata::i18n();
     $this->currentLocale = $i18n->getCurrentLocale();
     $this->defaultLocale = $i18n->getDefaultLocale();
     $this->shouldLocalizeByFallback = !$i18n->currentLocaleIsDefault() && $i18n->shouldFallbackToDefaultLocale();
 }
コード例 #9
0
 /**
  * Should one of the conditions be missing, the validator
  * will return a successful test.
  */
 public function test($value, $context)
 {
     if ($this->hasConfig("if") && !is_null($this->getConfig("if"))) {
         $request = Strata::router()->getCurrentController()->request;
         foreach ($this->getConfig("if") as $key => $expectedValue) {
             $comparedValue = $request->isPost() ? $request->post($key) : $request->get($key);
             if ($comparedValue !== $expectedValue) {
                 // ignore the rest of the validations, $expectedValue is not met
                 // therefore it's not a case when we need to validate the actual value.
                 return true;
             }
         }
     }
     if (is_string($value)) {
         $trimmed = trim($value);
         return !empty($trimmed);
     }
     // Array are expected to be lists on which we are
     // validating integer values, not string values.
     if (is_array($value)) {
         foreach ($value as $key => $currentValue) {
             if ((int) $currentValue > 0) {
                 return true;
             }
         }
         return false;
     }
 }
コード例 #10
0
ファイル: Debugger.php プロジェクト: francoisfaubert/strata
 public static function trace($backtrace = null, $options = array())
 {
     if (is_null($backtrace)) {
         $backtrace = debug_backtrace();
     }
     $backtrace = array_reverse($backtrace);
     $count = count($backtrace);
     $options += array('depth' => 50, 'start' => 0, 'output' => static::HTML);
     switch ($options['output']) {
         case static::RAW:
             $tpl = "%s(%s) from of %s#%d\n";
             break;
         case static::CONSOLE:
             $tpl = "<info>%s(%s)</info> in %s @ <yellow>%d</yellow>\n";
             break;
         default:
             $tpl = "<div style=\"" . static::HTML_STYLES . "\"><strong>%s<em>(%s)</em></strong><br/>in %s @ %d<br/><br/></div>";
     }
     $trace = "";
     $i = $options['start'];
     while ($i < $count && $i < $options['depth']) {
         $details = $backtrace[$i];
         $file = isset($details['file']) ? str_replace(Strata::getRootPath(), '~', $details['file']) : 'unknown';
         $line = isset($details['line']) ? $details['line'] : 'unknown';
         $args = $details['args'];
         $arguments = array();
         foreach ($args as $arg) {
             $arguments[] = static::getType($arg);
         }
         $trace .= sprintf($tpl, $details['function'], implode(", ", $arguments), $file, $line);
         $i++;
     }
     return $trace;
 }
コード例 #11
0
ファイル: FormHelper.php プロジェクト: francoisfaubert/strata
 /**
  * Opens up a form tag
  * @param  mixed   ModelEntity or null
  * @param  array  $options
  * @return string
  */
 public function create($mixed = null, $options = array())
 {
     $this->request = Strata::router()->getCurrentController()->request;
     if (!is_null($mixed) && !in_array('Strata\\Model\\CustomPostType\\ModelEntity', class_parents($mixed))) {
         throw new Exception("A form can only be linked to either an object inheriting ModelEntity or nothing at all.");
     }
     if (is_object($mixed)) {
         $this->associatedEntity = $mixed;
     }
     $this->configuration = $this->parseFormConfiguration($options);
     $formAttributes = $this->configuration;
     unset($formAttributes['hasSteps']);
     unset($formAttributes['type']);
     unset($formAttributes['nonce']);
     if (!is_null($this->associatedEntity) && $this->associatedEntity->hasValidationErrors()) {
         if (array_key_exists('class', $formAttributes)) {
             $formAttributes['class'] .= " has-errors ";
         } else {
             $formAttributes['class'] = "has-errors";
         }
     }
     $htmlAttributes = $this->arrayToHtmlAttributes($formAttributes);
     $salt = $this->getNonceSalt();
     $nonceTag = $this->generateNonceTag($salt);
     $nonceHidden = $this->generateHidden(array("name" => "auth_id"), wp_create_nonce($salt));
     return sprintf("<form %s>\n%s\n%s\n", $htmlAttributes, $nonceHidden, $nonceTag);
 }
コード例 #12
0
 protected function updateCommonConfiguration()
 {
     $this->setConfig("view_source_path", Strata::getOurVendorPath() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'Error' . DIRECTORY_SEPARATOR);
     $this->setConfig("use_localized_views", false);
     $this->setConfig("allow_debug", false);
     $this->setConfig("layout", "layout");
 }
コード例 #13
0
ファイル: Validator.php プロジェクト: francoisfaubert/strata
 protected function getTextdomain($default = "strata")
 {
     $app = Strata::app();
     if ($app && $app->hasConfig("i18n.textdomain")) {
         return $app->getConfig("i18n.textdomain");
     }
     return $default;
 }
コード例 #14
0
 public function logQueryCompletion($sql)
 {
     $executionTime = microtime(true) - $this->executionStart;
     $timer = sprintf(" (Done in %s seconds)", round($executionTime, 4));
     $oneLine = preg_replace('/\\s+/', ' ', trim($sql));
     $label = "<magenta>Polyglot</magenta>";
     Strata::app()->log($oneLine . $timer, $label);
 }
コード例 #15
0
 public static function plant($mixedId, $mixedKind = "WP_Post", $dataset = array())
 {
     $tree = new self();
     $tree->setQuerier(Strata::I18n()->query());
     $tree->setContext($mixedId, $mixedKind);
     $tree->populate($dataset);
     return $tree;
 }
コード例 #16
0
 /**
  * Assigns all the declared project commands.
  */
 public function assign()
 {
     $path = array(Strata::getOurVendorPath(), "src", "Shell", "Command");
     $cmdPath = implode($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
     if (is_dir($cmdPath)) {
         $this->parseDirectoryForCommandFiles($cmdPath);
     }
 }
コード例 #17
0
ファイル: Taxonomy.php プロジェクト: francoisfaubert/strata
 /**
  * Returns the complete taxonomy query var variable
  */
 public function getQueryVar()
 {
     $wordpressKey = $this->getWordpressKey();
     $generatedQueryVar = Strata::config("runtime.taxonomy.query_vars.{$wordpressKey}");
     if (!is_null($generatedQueryVar)) {
         return $generatedQueryVar;
     }
     return $wordpressKey;
 }
コード例 #18
0
 private function shouldRewriteModelSlug($model)
 {
     if (!$this->currentLocale->isDefault() || Strata::i18n()->shouldFallbackToDefaultLocale()) {
         if (is_a($model, "Strata\\Model\\WordpressEntity")) {
             return $model->hasConfig("i18n." . $this->currentLocale->getCode() . ".rewrite.slug");
         }
     }
     return false;
 }
コード例 #19
0
ファイル: ModelTest.php プロジェクト: francoisfaubert/strata
 public function testCtpAdminMenuRegistered()
 {
     $this->wordpress->reset();
     $strata = Strata::app();
     $strata->setConfig("custom-post-types", array("TestCustomPostType"));
     $strata->run();
     $this->assertArrayHasKey('admin_menu', $this->wordpress->actions);
     $this->assertTrue($this->wordpress->actions['admin_menu'][0][0] instanceof Registrar);
 }
コード例 #20
0
 /**
  * Overrides the default i18n function in order to use
  * our custom Locale object and have our own set of functions.
  * @return array
  */
 protected function rebuildLocaleList()
 {
     $app = Strata::app();
     $original = Hash::normalize($app->getConfig("i18n.locales"));
     $newLocales = array();
     foreach ($original as $key => $config) {
         $newLocales[$key] = new Locale($key, $config);
     }
     return $newLocales;
 }
コード例 #21
0
 public function rewriteStrataPost($postTypekey, $config)
 {
     try {
         $cpt = CustomPostType::factory(substr($postTypekey, 4));
         $localizedSlugs = array_merge(array($cpt->hasConfig("rewrite.slug") ? $cpt->getConfig("rewrite.slug") : $postTypekey), $cpt->extractConfig("i18n.{s}.rewrite.slug"));
         $this->addCustomPostTypeRewrites(implode("|", $localizedSlugs), $postTypekey);
     } catch (Exception $e) {
         Strata::app()->log("Tried to translate {$slug}, but could not find the associated model.", "<magenta>Polyglot:UrlRewriter</magenta>");
     }
 }
コード例 #22
0
 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>");
     }
 }
コード例 #23
0
 /**
  * Returns the internal custom post type slug
  * @return string
  */
 public static function wordpressKey()
 {
     $app = Strata::app();
     $classHash = md5(get_called_class());
     $cacheKey = "runtime.static.{$classHash}.wpkey";
     if (!$app->hasConfig($cacheKey)) {
         $obj = self::staticFactory();
         $app->setConfig($cacheKey, $obj->getWordpressKey());
     }
     return $app->getConfig($cacheKey);
 }
コード例 #24
0
 /**
  * {@inheritdoc}
  */
 public function register()
 {
     $message = "Timezone set to <info>%s</info>";
     $timezone = Strata::app()->getConfig("timezone");
     if (is_null($timezone)) {
         $timezone = self::DEFAULT_TIMEZONE;
         $message = "Timezone automatically set to <info>%s</info>";
     }
     date_default_timezone_set($timezone);
     Strata::app()->setConfig("runtime.timezone", sprintf($message, $timezone));
 }
コード例 #25
0
 private function translationExists()
 {
     $i18n = Strata::i18n();
     $translations = $i18n->query()->findTranlationsOfId($this->originalId, $this->originalKind);
     $targetLocale = $this->getTranslationLocale();
     foreach ($translations as $translation) {
         if ($targetLocale->getCode() === $translation->getTranslationLocaleCode()) {
             return true;
         }
     }
     return false;
 }
コード例 #26
0
 public static function localizeRouteByQuery($wp_query, $route = null)
 {
     if (is_null($route)) {
         $route = $_SERVER['REQUEST_URI'];
     }
     if ($wp_query->is_tax()) {
         $router = new TaxonomyRouter(Strata::i18n(), $wp_query);
     } else {
         $router = new PostRouter(Strata::i18n(), $wp_query);
     }
     return $router->localizeRoute($route);
 }
コード例 #27
0
 /**
  * Configures the class writer and makes it generate the
  * test classes required by the object type.
  */
 protected function generateTest()
 {
     $destination = implode(DIRECTORY_SEPARATOR, array("test", "Middleware", $this->classname . "Test.php"));
     $namespace = Strata::getNamespace() . "\\Test\\Middleware";
     $writer = $this->getWriter();
     $writer->setClassname($this->classname);
     $writer->setNamespace($namespace);
     $writer->setDestination($destination);
     $writer->setUses("\nuse Strata\\Test\\Test as StrataTest;\n");
     $writer->setExtends("StrataTest");
     $writer->create(true);
 }
コード例 #28
0
 private function saveRules()
 {
     if (count($this->collectedRewrites)) {
         $rewriter = Strata::rewriter();
         foreach ($this->collectedRewrites as $rewrite) {
             $rewriter->addRule($rewrite[0], $rewrite[1]);
         }
     }
     if (count($this->collectedRoutes)) {
         $router = Strata::router();
         $router->addModelRoutes($this->collectedRoutes);
     }
 }
コード例 #29
0
ファイル: Rewriter.php プロジェクト: francoisfaubert/strata
 /**
  * Applies the rules that have been defined at runtime. Note that
  * the rules are added in the same order as they have been defined
  * and this may cause racing condition in how rules are applied.
  * @return boolean Returns whether the process has written in the database
  */
 public function applyRules()
 {
     if (!$this->hasRules()) {
         return false;
     }
     $rules = $this->getRules();
     foreach ($rules as $rewrite) {
         add_rewrite_rule($rewrite[0], $rewrite[1], $rewrite[2]);
     }
     $wroteInDB = $this->flush();
     $message = $wroteInDB ? sprintf("Added <info>%d</info> and flushed the rewrite list.", count($rules)) : sprintf("Added <info>%d</info> while using the cached rewrites.", count($rules));
     Strata::app()->log($message, "<info>Rewriter</info>");
     return $wroteInDB;
 }
コード例 #30
0
 /**
  * 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);
 }