コード例 #1
0
 protected function renderStack($stack)
 {
     if (empty($stack)) {
         return '';
     }
     $html = '<ul>';
     $firstLevel = $prevLevel = $stack[0]['level'];
     $stackLength = count($stack);
     foreach ($stack as $key => $header) {
         $level = $header['level'];
         $nextLevel = $key < $stackLength - 1 ? $stack[$key + 1]['level'] : $firstLevel;
         $link = '<a href="#' . $header['id'] . '">' . $header['text'] . '</a>';
         if ($level === $prevLevel) {
             $html .= '<li>' . $link;
             $html .= $level < $nextLevel ? '' : '</li>';
         } elseif ($level < $prevLevel) {
             $html .= str_repeat('</ul></li>', $prevLevel - $level) . '<li>' . $link;
             $html .= $level < $nextLevel ? '' : '</li>';
         } elseif ($level > $prevLevel) {
             $html .= '<ul><li>' . $link;
             $html .= $level < $nextLevel ? '' : '</li>';
         }
         $prevLevel = $level;
     }
     $html .= str_repeat('</ul></li>', $level - $firstLevel);
     $html .= '</ul>';
     return $html;
     $html = str_replace('>', ">\n", $html);
     dmDebug::kill($html);
 }
コード例 #2
0
ファイル: dmThread.php プロジェクト: theolymp/diem
 protected function perf($kill = false)
 {
     if ($kill) {
         dmDebug::killForce(dmOs::getPerformanceInfos());
     }
     dmDebug::showForce(dmOs::getPerformanceInfos());
 }
コード例 #3
0
ファイル: dmAssetCompressor.php プロジェクト: jdart/diem
 public function process(array $assets)
 {
     if (empty($assets)) {
         return array();
     }
     $timer = dmDebug::timerOrNull('dmAssetCompressor::process(' . $this->type . ')');
     $this->assets = $assets;
     $this->cachedAssets = array();
     $this->cdnAssets = array();
     $this->preservedAssets = array();
     $this->processedAssets = array();
     $this->cacheKey = '';
     $this->webDir = sfConfig::get('sf_web_dir');
     $this->preProcess();
     foreach ($this->assets as $webPath => $options) {
         if ($this->isOnFilesystem($webPath)) {
             if (!file_exists($this->webDir . $webPath)) {
                 $this->log('Missing ' . $this->type . ' : ' . $this->webDir . $webPath);
                 $this->cacheKey .= $webPath;
             } elseif ($this->isCachable($webPath, $options)) {
                 $this->cachedAssets[$webPath] = $options;
                 $this->cacheKey .= $webPath . filemtime($this->webDir . $webPath);
             } else {
                 $this->preservedAssets[$webPath] = $options;
             }
         } else {
             $this->cdnAssets[$webPath] = $options;
         }
     }
     if (!empty($this->cachedAssets)) {
         $this->cacheKey = md5($this->processCacheKey($this->cacheKey));
         $cacheWebPath = '/cache/' . $this->type;
         $cacheDirPath = $this->webDir . $cacheWebPath;
         $cacheFilePath = $cacheDirPath . '/' . $this->cacheKey . '.' . $this->type;
         $this->filesystem->mkdir($cacheDirPath);
         if (!file_exists($cacheFilePath)) {
             $cacheContent = '';
             foreach ($this->cachedAssets as $webPath => $options) {
                 $cacheContent .= $this->processAssetContent(file_get_contents($this->webDir . $webPath), $webPath);
             }
             $cacheContent = $this->processCacheContent($cacheContent);
             file_put_contents($cacheFilePath, $cacheContent);
             chmod($cacheFilePath, 0666);
             if ($this->options['gz_compression']) {
                 file_put_contents($cacheFilePath . '.gz', gzencode($cacheContent));
                 chmod($cacheFilePath . '.gz', 0666);
             }
             $message = sprintf('%s : compressed %d assets ( %s )', get_class($this), count($this->cachedAssets), dmOs::humanizeSize($cacheFilePath));
             $this->dispatcher->notify(new sfEvent($this, 'application.log', array($message, 'priority' => sfLogger::INFO)));
         }
         $this->processedAssets = array_merge($this->cdnAssets, array($cacheWebPath . '/' . $this->cacheKey . '.' . $this->type => array()), $this->preservedAssets);
     } else {
         $this->processedAssets = array_merge($this->cdnAssets, $this->preservedAssets);
     }
     $this->postProcess();
     $timer && $timer->addTime();
     return $this->processedAssets;
 }
コード例 #4
0
ファイル: dmSeoValidator.php プロジェクト: theolymp/diem
 public function execute(array $attributes = array('slug'))
 {
     $timer = dmDebug::timerOrNull('dmSeoValidationService::execute');
     $this->attributes = $attributes;
     $this->checkAttributesExist();
     $duplicated = $this->validateAttributes();
     $timer && $timer->addTime();
     return $duplicated;
 }
コード例 #5
0
 protected function copyModel($model)
 {
     $table = dmDb::table($model);
     $tableName = $table->getTableName();
     $vars = array();
     $placeholders = array();
     foreach ($table->getColumns() as $columnName => $column) {
         $fields[] = $columnName;
         $placeholders[] = ':' . $columnName;
     }
     $conn = Doctrine_Manager::connection();
     $stmt = $conn->prepare(sprintf('INSERT INTO %s (%s) VALUES (%s)', $tableName, implode(',', $fields), implode(',', $placeholders)))->getStatement();
     $conn->beginTransaction();
     try {
         foreach ($this->oldDb->getData($tableName) as $array) {
             $values = array();
             foreach ($fields as $field) {
                 $values[':' . $field] = isset($array[$field]) ? $array[$field] : '';
             }
             $stmt->execute($values);
         }
     } catch (Exception $e) {
         dmDebug::show($model, $array);
         throw $e;
     }
     $conn->commit();
 }
コード例 #6
0
ファイル: dmBase.php プロジェクト: rafaelgou/diem
 /**
  * Diem code size
  * returns array(files, lines, characters)
  */
 public static function getDiemSize()
 {
     $timer = dmDebug::timerOrNull('dm::getDiemSize()');
     $pluginsDir = sfConfig::get('sf_plugins_dir') . '/';
     $files = sfFinder::type('file')->prune('om')->prune('map')->prune('base')->prune('vendor')->name('*\\.php', '*\\.css', '*\\.js', '*\\.yml')->in($pluginsDir . 'dmCorePlugin', $pluginsDir . 'dmAdminPlugin', $pluginsDir . 'dmFrontPlugin');
     foreach ($files as $key => $file) {
         if (strpos($file, '/web/lib/')) {
             unset($files[$key]);
         }
     }
     $lines = 0;
     $characters = 0;
     foreach ($files as $file) {
         $content = file($file);
         $lines += count($content);
         $characters += strlen(implode(' ', $content));
     }
     $response = array('nb_files' => count($files), 'lines' => $lines, 'characters' => $characters);
     $timer && $timer->addTime();
     return $response;
 }
コード例 #7
0
ファイル: dmProjectRecordTest.php プロジェクト: theolymp/diem
    $cat2 = $po->getRelatedRecord('DmTestCateg');
    $t->is((string) $cat1, (string) $cat2, sprintf('post %d related categ : %s / %s', $po->id, $cat1 ? $cat1->id : 'NULL', $cat2 ? $cat2->id : 'NULL'));
}
$t->diag('Related record test : verifying that we get the first related record in reversed local relation');
foreach (dmDb::table('DmTestCateg')->findAll() as $cat) {
    $post1 = $cat->Posts[0]->orNull();
    $post2 = $cat->getRelatedRecord('DmTestPost');
    $t->is((string) $post1, (string) $post2, sprintf('categ %d related post : %s / %s', $cat->id, $post1 ? $post1->id : 'NULL', $post2 ? $post2->id : 'NULL'));
}
$t->diag('Related record test : verifying that we get the first related record in association relation');
foreach (dmDb::table('DmTestCateg')->findAll() as $cat) {
    $dom1 = $cat->Domains[0]->orNull();
    $dom2 = $cat->getRelatedRecord('DmTestDomain');
    $t->is((string) $dom1, (string) $dom2, sprintf('categ %d related domain : %s / %s', $cat->id, $dom1 ? $dom1->id : 'NULL', $dom2 ? $dom2->id : 'NULL'));
    if ($dom1 != $dom2) {
        dmDebug::kill($cat->Domains, $cat->getRelatedRecord('DmTestDomain'));
    }
}
$t->diag('Related record test : verifying that we get the first related record in reverse association relation');
foreach (dmDb::table('DmTestDomain')->findAll() as $dom) {
    $cat1 = $dom->Categs[0]->orNull();
    $cat2 = $dom->getRelatedRecord('DmTestCateg');
    $t->is((string) $cat1, (string) $cat2, sprintf('domain %d related categ : %s / %s', $dom->id, $cat1 ? $cat1->id : 'NULL', $cat2 ? $cat2->id : 'NULL'));
}
$t->diag('Related record test : verifying that we get the first related record in another association relation');
foreach (dmDb::table('DmTestTag')->findAll() as $_tag) {
    $post1 = $_tag->Posts[0]->orNull();
    $post2 = $_tag->getRelatedRecord('DmTestPost');
    $t->is((string) $post1, (string) $post2, sprintf('tag %d related post : %s / %s', $_tag->id, $post1 ? $post1->id : 'NULL', $post2 ? $post2->id : 'NULL'));
}
//$t->diag('Related record id tests');
コード例 #8
0
ファイル: dmSeoSyncTest.php プロジェクト: vjousse/diem
<?php

require_once realpath(dirname(__FILE__) . '/../../..') . '/unit/helper/dmUnitTestHelper.php';
$helper = new dmUnitTestHelper();
$helper->boot();
$nbLoremizeRecords = 10;
$helper->get('page_tree_watcher')->connect();
$markdown = $helper->get('markdown');
$nbTests = 5 + $nbLoremizeRecords * 12;
$t = new lime_test($nbTests);
$helper->loremizeDatabase($nbLoremizeRecords, $t);
dmDb::table('DmAutoSeo')->findOneByModuleAndAction('dmTestDomain', 'show')->merge(array('slug' => '%dmTestDomain.id%-%dmTestDomain%'))->save();
dmDb::table('DmAutoSeo')->findOneByModuleAndAction('dmTestCateg', 'show')->merge(array('slug' => '%dmTestCateg.id%-%dmTestCateg%'))->save();
dmDb::table('DmAutoSeo')->findOneByModuleAndAction('dmTestPost', 'show')->merge(array('slug' => '%dmTestPost%-%dmTestPost.id%', 'name' => 'Post : %dmTestPost.title%', 'title' => '%dmTestPost% | %dmTestCateg.name%', 'h1' => '%dmTestPost%', 'description' => '%dmTestPost.body%'))->save();
$t->diag('seo construction');
$timer = dmDebug::timer('update seo');
try {
    $helper->updatePageTreeWatcher($t);
} catch (Exception $e) {
    $t->skip('Not supported on this server: ' . $e->getMessage(), $nbTests);
    return;
}
$t->ok(true, sprintf('Seo updated in %01.2f s', $timer->getElapsedTime()));
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();
コード例 #9
0
 protected function checkEachRecordChildrenHavePage($module, $t)
 {
     $errors = array();
     /*
      * Test only leaf modules
      */
     if ($module->hasChildren()) {
         return $errors;
     }
     if ($ancestorModule = $module->getFarthestAncestorWithPage()) {
         $ancestorModel = $ancestorModule->getModel();
     } else {
         return $errors;
     }
     /*
      * Verify that each record wich has an ancestor has a page
      */
     $records = new myDoctrineCollection($module->getTable());
     foreach ($ancestorModule->getTable()->findAll() as $ancestorRecord) {
         $records = $records->merge($module->getTable()->createQuery('r')->whereAncestor($ancestorRecord, $module->getModel())->fetchRecords());
     }
     foreach ($records as $record) {
         if (!$record->getDmPage()) {
             $error = sprintf('%s %d %s has no page', $module, $record->id, $record);
             $t->diag($error);
             $errors[] = $error;
         }
     }
     if (count($errors)) {
         $t->diag('Error !');
         dmDebug::kill($errors);
     }
     return $errors;
 }
コード例 #10
0
ファイル: dmUnitTestHelper.php プロジェクト: theolymp/diem
 public function updatePageTreeWatcher(lime_test $t = null)
 {
     if ($t) {
         $t->diag('Launching update on pageTreeWatcher to restore page structure... this may take some time');
     }
     $timer = dmDebug::timer('pageTreeWatcher update ' . dmString::random(4));
     $this->get('page_tree_watcher')->update();
     if ($t) {
         $t->ok(true, sprintf('Pages synchronized in %01.2f s | %d pages', $timer->getElapsedTime(), dmDb::table('DmPage')->count()));
     }
 }
コード例 #11
0
 public function render()
 {
     $t = dmDebug::timerOrNull('dmAdminBreadCrumb::render');
     $links = $this->renderLinksArray($this->getLinks());
     if (empty($links)) {
         $html = '';
     } else {
         $html = $this->helper->open('div#breadCrumb.mt10.clearfix') . $this->helper->tag('ol', '<li>' . implode('</li><li class="sep">&gt;</li><li>', $links) . '</li>');
         if ($miniSearchForm = dmArray::get($this->context->getResponse()->getSlots(), 'dm.mini_search_form')) {
             $html .= $this->helper->tag('div.dm_mini_search_form', $miniSearchForm);
         }
         $html .= $this->helper->close('div');
     }
     $t && $t->addTime();
     return $html;
 }
コード例 #12
0
ファイル: dmSerializeTest.php プロジェクト: theolymp/diem
<?php

require_once dirname(__FILE__) . '/helper/dmUnitTestHelper.php';
$helper = new dmUnitTestHelper();
$helper->boot();
$nbTests = 20;
$t = new lime_test(3);
$array = array('text' => "\n\nInterroger l’homme au travers des croyances, des gestes et des récits dont il enveloppe le subtil du monde pour y entrevoir sa propre forme.\n\n\nEn tout lieu retrouver les empreintes laissées par l’imaginaire sur la pierre, sur l’eau, sur la terre, dans le temps du calendrier, dans le souffle des mots, et dans l’ombre des gestes.\n\n\nReconstruire, fragment par fragment, ce sens que la parole du mythe, aux mille et une légendes chuchotées depuis des millénaires, pourrait nous faire saisir.\n\n\nEt, inlassablement, reposer la question : qu’est-ce que l’homme ?", 'tag' => 'h1', 'css_class' => null, 'other_info' => 'tagada test');
$array = array('view' => 'big', 'css_class' => null, 'other_info' => 'tagada test');
$t->diag('json length : ' . strlen(json_encode($array)));
$t->diag('yaml length : ' . strlen(sfYaml::dump($array)));
$t->diag('serialize length : ' . strlen(serialize($array)));
$t->diag(serialize($array));
$t->is(json_decode(json_encode($array), true), $array, 'json_works');
$t->is(sfYaml::load(sfYaml::dump($array)), $array, 'yaml works');
$t->is(unserialize(serialize($array)), $array, 'serialize works');
$json = dmDebug::timer('json');
for ($it = 1; $it <= $nbTests; $it++) {
    json_decode(json_encode($array), true);
}
$t->diag('json time : ' . $json->getElapsedTime());
$yaml = dmDebug::timer('yaml');
for ($it = 1; $it <= $nbTests; $it++) {
    sfYaml::load(sfYaml::dump($array));
}
$t->diag('yaml time : ' . $yaml->getElapsedTime());
$serialize = dmDebug::timer('serialize');
for ($it = 1; $it <= $nbTests; $it++) {
    unserialize(serialize($array));
}
$t->diag('serialize time : ' . $serialize->getElapsedTime());