/** * Get a page storable content * * @return string the page text content */ protected function getPageContentForStore() { $content = $this->getPageContent(); return dmMarkdown::brutalToText(trim(preg_replace('|\\s{2,}|', ' ', strip_tags(str_replace(array("\n", '<'), array(' ', ' <'), $content))))); }
public function getReplacementsForPatterns(dmProjectModule $module, array $patterns, dmDoctrineRecord $record) { $moduleKey = $module->getKey(); $replacements = array(); foreach ($this->getPatternsPlaceholders($patterns) as $placeholder) { if ('culture' === $placeholder || 'user.culture' === $placeholder) { $replacements[$this->wrap($placeholder)] = $this->culture; continue; } /* * Extract model and field from 'model.field' or 'model' */ if (strpos($placeholder, '.')) { list($usedModuleKey, $field) = explode('.', $placeholder); } else { $usedModuleKey = $placeholder; $field = '__toString'; } $usedModuleKey = dmString::modulize($usedModuleKey); $usedRecord = null; /* * Retrieve used record */ if ($usedModuleKey === $moduleKey) { $usedRecord = $record; } elseif ($module->hasAncestor($usedModuleKey)) { $usedRecord = $record->getAncestorRecord($module->getAncestor($usedModuleKey)->getModel()); } else { $usedRecord = $record->getRelatedRecord($this->moduleManager->getModule($usedModuleKey)->getModel()); } if ($usedRecord instanceof dmDoctrineRecord) { /* * get record value for field */ if ($field === '__toString') { $usedValue = $usedRecord->__toString(); $processMarkdown = true; } else { try { $usedValue = $usedRecord->get($field); } catch (Doctrine_Record_UnknownPropertyException $e) { $usedValue = $usedRecord->{'get' . dmString::camelize($field)}(); } $processMarkdown = $this->shouldProcessMarkdown($usedRecord->getTable(), $field); } unset($usedRecord); } else { $usedValue = $moduleKey . '-' . $usedModuleKey . ' not found'; $processMarkdown = false; } $usedValue = trim($usedValue); if ($processMarkdown) { $usedValue = dmMarkdown::brutalToText($usedValue); } $replacements[$this->wrap($placeholder)] = $usedValue; } return $replacements; }
foreach (dmDb::table('dmTestPost')->findAll() as $post) { if (!($page = $post->getDmPage())) { $t->skip('Post ' . $post . ' has no page', 6); continue; } $page->refresh(true); $categ = $page->getNode()->getParent()->getRecord(); $domain = $page->getNode()->getParent()->getNode()->getParent()->getRecord(); $t->is($post->isActive, $page->isActive, 'is_active field synchronized to ' . ($post->isActive ? 'TRUE' : 'FALSE')); $slug = 'dm-test-domains/' . $domain->id . '-' . dmString::slugify($domain->title) . '/' . $categ->id . '-' . dmString::slugify($categ->name) . '/' . dmString::slugify($post->title) . '-' . $post->id; $slug = dmSeoSynchronizer::truncateValueForField($slug, 'slug'); $t->is($page->slug, $slug, 'slug : ' . $slug); $name = 'Post : ' . trim($post->title); $name = dmSeoSynchronizer::truncateValueForField($name, 'name'); $t->is($page->name, $name, 'name : ' . $name); $title = ucfirst(trim($post->title) . ' | ' . trim($categ->name)); $title = dmSeoSynchronizer::truncateValueForField($title, 'title'); $t->is($page->title, $title, 'title : ' . $title); $h1 = trim($post->title); $h1 = dmSeoSynchronizer::truncateValueForField($h1, 'h1'); $t->is($page->h1, $h1, 'h1 : ' . $h1); $description = dmSeoSynchronizer::truncateValueForField(dmMarkdown::brutalToText($post->body), 'description'); $t->is($page->description, $description ? $description : null, 'description : ' . $description); } $t->comment('Add inactive domain'); $domain = dmDb::table('DmTestDomain')->create(array('title' => 'a domain', 'is_active' => false))->saveGet(); $domain->refresh(); $t->comment('created domain ' . $domain->id); $helper->updatePageTreeWatcher($t); $t->isa_ok($page = $domain->dmPage, 'DmPage', 'domain has a page'); $t->ok(!$page->isActive, 'domain page is not active');