function TextToHTML($string, $stringLanguage = false) { global $_JAM; // Look for Markdown preference if ($_JAM->projectConfig['useMarkdown']) { require_once 'engine/libraries/smartypants.php'; require_once 'engine/libraries/markdown.php'; return SmartyPants(Markdown($string)); } // First find backticked portions and store them for later use $backtickmatch = '{`([^`]*)`}u'; preg_match_all($backtickmatch, $string, $metaFillOutArray, PREG_PATTERN_ORDER); // Only index 1 is suitable for use $fillOutArray = $metaFillOutArray[1]; // Replace matches with placeholders $string = preg_replace($backtickmatch, '%PLACEHOLDER', $string); $match = array('{\\r}u', '{^([^\\n]+)$}mu', '{<p>-(=)+-</p>}u', '{<p>([^\\n]+)</p>[\\n\\s]*<p>-*</p>}u', '{<p>[-·•]\\s?([^\\n]+)</p>(\\n{1}|$)}u', '{</ul>\\n<ul>}u', '{<p>(\\d)\\. ([^\\n]+)</p>(\\n{1}|$)}u', '{</ol>\\n<ol type="1" start="\\d">}u', '{</p>\\n<p>([^\\t])}u', "{(/?)>\\[([^\\s=>\\]]*)=([^\\s>\\]]*)\\]}u", '{<p>%PLACEHOLDER</p>}u'); $replace = array('', e('p', '$1'), e('hr'), e('h2', '$1'), e('ul', e('li', '$1')) . "\n", "\n", e('ol', array('type' => 1, 'start' => '$1'), e('li', '$2')) . "\n", "\n", e('br') . "\n\$1", ' $2="$3"$1>', '%PLACEHOLDER'); $smartizedString = TextRenderer::SmartizeText($string, $language); $HTMLString = preg_replace($match, $replace, $smartizedString); // Reinsert backticked portions while ($fillout = array_shift($fillOutArray)) { $HTMLString = preg_replace('{%PLACEHOLDER}u', $fillout, $HTMLString, 1); } return $HTMLString; }
<ul class="perspectives-formulaire"> <? if ($this->items): ?> <? foreach($this->items as $id => $item): ?> <li id="perspective-<?php echo $id; ?> "> <div class="numero"><?php echo $item['numero']; ?> </div> <div class="texte"><?php echo TextRenderer::FormatText($item['texte']); ?> </div> </li> <? endforeach; ?> <? endif; ?> </ul>
$typeString = 's’inscrit immédiatement avant'; break; case 3: $typeString = 's’inscrit immédiatement après'; break; endswitch; ?> <p>Cette contribution <?php echo $typeString; ?> la perspective <strong><?php echo $perspective_numero; ?> </strong>:</p> <div class="perspective"> <div class="texte"><?php echo TextRenderer::FormatText($perspective_texte); ?> </div> </div> <? else: ?> <p>Cette contribution est un commentaire général sur l’ensemble des perspectives.</p> <? endif; ?> <? endif; ?> <?php echo $contribution; ?> </div> <div id="autresContributions"> <h3>Contributions reliées</h3> <? if ($autresContributions): ?> <dl>
function FetchItems($queryParams = '') { global $_JAM; $query = new Query(); $query->AddFrom($this->name); if ($this->config['keepVersions']) { // This is a multiversions table; fetch 'master' field $query->AddFields(array('master' => 'IF(' . $this->name . '.master IS NULL, ' . $this->name . '.id, ' . $this->name . '.master)')); $query->AddWhere($this->name . '.current = TRUE'); } else { // This is a standard table; fetch 'id' field $query->AddFields(array('id' => $this->name . '.id')); } /* // Order by master if we're keeping versions if ($this->config['keepVersions']) { $query->AddOrderBy('master DESC'); }*/ // Add localized data if ($this->isLocalizable) { $localizedTable = $this->name . '_localized'; $query->AddFields(array('language' => $localizedTable . '.language')); $query->AddFrom($localizedTable); $where = array($localizedTable . '.item = ' . $this->name . '.id', $localizedTable . ".language = '" . $_JAM->language . "'"); $query->AddWhere($where); } // Load all fields if none were specified if (!$queryParams['fields']) { foreach ($this->schema as $name => $info) { $queryParams['fields'][] = $name; } } foreach ($this->schema as $name => $info) { // Manually remove multi fields from query; they will be processed anyway (possibly kludgy) if ($info['type'] == 'multi') { if ($multiFieldKey = array_search($name, $queryParams['fields'])) { unset($queryParams['fields'][$multiFieldKey]); } } // Process custom parameters if ($info['localizable']) { $replaceString = $this->name . '_localized.' . $name; } else { $replaceString = $this->name . '.' . $name; } // Fetch data for related modules if (@in_array($name, $queryParams['fields'])) { if ($info['type'] == 'int' && ($relatedModule = $info['relatedModule']) && $relatedModule != 'users' && $relatedModule != $this->name) { // Add fields from foreign module $relatedModuleSchema = Module::ParseConfigFile($relatedModule, 'config/schema.ini', true); foreach ($relatedModuleSchema as $foreignName => $foreignInfo) { $fields[$name . '_' . $foreignName] = $relatedModule . '.' . $foreignName; } $query->AddFields($fields); // Determine whether we should look for 'master' or 'id' field $relatedModuleConfig = Module::ParseConfigFile($relatedModule, 'config/config.ini', true); $joinCondition = $this->name . '.' . $name . ' = '; if ($relatedModuleConfig['keepVersions']) { $joinCondition .= $relatedModule . '.master AND ' . $relatedModule . '.current = TRUE'; } else { $joinCondition .= $relatedModule . '.id'; } // Build query $joinTable = $relatedModule; $query->AddJoin($this->name, $joinTable, $joinCondition); } } $queryParams = Module::InsertTableNames($queryParams, $name, $replaceString); } // Load custom parameters $query->LoadParameters($queryParams); // Load paths if appropriate if ($this->config['autoPaths'] || get_parent_class($this) && method_exists($this, 'GetPath')) { $query->AddFields(array('path' => '_paths.path')); $joinTable = '_paths'; $joinConditions[] = '_paths.module = ' . $this->moduleID; $joinConditions[] = '_paths.current = 1'; if ($this->config['keepVersions']) { $joinConditions[] = '((_paths.item = ' . $this->name . '.id AND ' . $this->name . '.master IS NULL) OR ' . '_paths.item = ' . $this->name . '.master)'; } else { $joinConditions[] = '_paths.item = ' . $this->name . '.id'; } $query->AddJoin($this->name, $joinTable, $joinConditions); if ($this->isLocalizable) { $query->AddWhere($this->name . '_localized.language = _paths.language'); } } // Debug query: //dp($query->GetQueryString()); // Fetch actual module data if ($this->rawData = $query->GetArray()) { // Load data for 'multi' fields if ($this->hasMulti) { $where = 'frommodule = ' . $this->moduleID; if ($multiArray = Query::FullResults('_relationships', $where)) { foreach ($this->rawData as $id => $item) { foreach ($multiArray as $multiData) { if ($multiData['fromid'] == $id) { $this->rawData[$id][$this->multiRelatedModules[$multiData['tomodule']]][] = $multiData['toid']; } } } } } // Make a copy of the data for processing so we can keep the raw data available $this->processedData = $this->rawData; // Post-process data foreach ($this->schema as $name => $info) { foreach ($this->processedData as $id => $data) { if ($this->processedData[$id][$name]) { switch ($info['type']) { case 'string': $this->processedData[$id][$name] = TextRenderer::SmartizeText($data[$name]); break; case 'text': case 'shorttext': if (!$info['wysiwyg']) { // Render text using TextRenderer if it's not a WYSIWYG field if (strstr($data[$name], "\n") !== false) { // String contains newline characters; format as multiline text $this->processedData[$id][$name] = TextRenderer::TextToHTML($data[$name]); } else { // String is a single line; format as single line $this->processedData[$id][$name] = TextRenderer::SmartizeText($data[$name]); } } break; case 'datetime': case 'timestamp': case 'date': case 'time': $this->processedData[$id][$name] = new Date($data[$name]); break; case 'file': $this->processedData[$id][$name] = $this->NestModule('files', $data[$name]); break; } } } } // Subclasses can provide a method to further format data if (method_exists($this, 'FormatData')) { $this->FormatData(); } if ($this->items) { // If $this->items is already set, don't overwrite it return $this->processedData; } else { return $this->items = $this->processedData; } } else { return false; } }