/** * @param $html string */ public function fromHtml($html) { $this->paragraphs->exchangeArray(array()); if (trim($html)) { $dom = new \DOMDocument(); $dom->loadHTML(trim($html)); /** @var \DOMElement $node */ foreach ($dom->getElementsByTagName('p') as $node) { $this->inputSystem = $node->getAttribute('lang'); $paragraph = new LexParagraph(); foreach (explode(' ', $node->getAttribute('class')) as $classValue) { if (StringUtil::startsWith($classValue, 'guid_')) { $guid = substr($classValue, 5); if ($guid) { $paragraph->guid = $guid; } } if (StringUtil::startsWith($classValue, 'styleName_')) { $styleName = substr($classValue, 10); if ($styleName) { $paragraph->styleName = $styleName; } } } $content = LiftDecoder::sanitizeSpans($node, $this->inputSystem); if ($content) { $paragraph->content = $content; } $this->paragraphs->append($paragraph); } } }
/** * @param ObjectForEncoding $model * @param LexConfigFieldList $config * @param int $multiParagraphCount * @param boolean $modelModified */ private static function migrateMultiParagraphs($model, $config, &$multiParagraphCount, &$modelModified) { if (isset($model->customFields)) { foreach ($model->customFields as $fieldName => $customField) { if (is_a($customField, 'Api\\Model\\Languageforge\\Lexicon\\LexMultiText')) { $isMultiParagraph = false; $multiParagraph = new LexMultiParagraph(); foreach ($customField as $tag => $text) { if (StringUtil::startsWith($text->value, '<p>')) { $isMultiParagraph = true; $multiParagraphCount++; $multiParagraph->inputSystem = $tag; $value = substr($text->value, 3); if (StringUtil::endsWith($value, '</p>')) { $value = substr($value, 0, -4); } foreach (explode('</p><p>', $value) as $content) { $paragraph = new LexParagraph(); if ($content) { $paragraph->content = $content; } $multiParagraph->paragraphs->append($paragraph); } } } if ($isMultiParagraph) { $modelModified = true; $model->customFields[$fieldName] = $multiParagraph; if (!is_a($config->fields[$fieldName], 'Api\\Model\\Languageforge\\Lexicon\\Config\\LexConfigMultiParagraph')) { $multiParagraphConfig = new LexConfigMultiParagraph(); $multiParagraphConfig->label = $config->fields[$fieldName]->label; $multiParagraphConfig->hideIfEmpty = $config->fields[$fieldName]->hideIfEmpty; $config->fields[$fieldName] = $multiParagraphConfig; } } } } } }