public function onSaving(): bool
{
+
$this->saveDataInWebflow();
$change = false;
$hasChanged = false;
$imagesChanged = false;
+
foreach ($seo[$mainLocale] as $page) {
if ($page['og_title_copied']) {
{
start_measure("Webflow refresh data from api");
$lock = $this->getLock();
- //dd(Webflow::getAllData($this->webflow)['cms']);
try {
Webflow::clearCache();
$this->api = $this->getEditableData();
$urlmaps = $this->getURLMaps();
$urlmap = $urlmaps[$locale];
$origRelative = $relative;
- $strippedSlashRelative=ltrim($relative,'/');
+ $strippedSlashRelative = ltrim($relative, '/');
$html = file_get_contents($f->getPathname());
$regex = '/("https:\/\/' . $this->webflow . '.webflow.io\/\\\\")(.*)(\\\\"")/';
return parent::onRetrieved();
}
- public function getEditableData()
+ public function getEditableData($force = false)
{
Webflow::setToken($this->webflow_api_token);
- return Webflow::getEditableData($this->webflow, $this->getMirrorPath());
+ return Webflow::getEditableData($this->webflow, $this->getMirrorPath(), $force);
}
public function getAvailableLocales()
return self::request('assets/' . $id, ['altText' => $alt], 'post', 0, true);
}
- public static function getEditableData($shortname, $mirrorPath)
+ public static function getEditableData($shortname, $mirrorPath, $force = false)
{
start_measure('Webflow : get editable data');
$key = self::getToken() . '_' . $shortname;
- if (!isset(self::$_editableData[$key])) {
+
+ if ($force || !isset(self::$_editableData[$key])) {
+
$data = self::getAllData($shortname);
+
+
$res = ['texts' => [], 'images' => [], 'seo' => []];
foreach ($data['pages'] as $pageID => $page) {
$details = $page['details'];
- $url = trim($details['slug']??'');
+ $url = trim($details['slug'] ?? '');
$c = $page;
while (true) {
if (null === $c['details']['parentId']) {
}
}
+
$url = '/' . $url;
$res['seo'][$pageID] = $seo;
+
foreach ($page['contents'] as $node) {
if ($node['type'] === 'text') {
if (!$node['text']['text'] || !$node['text']['html']) {
$html = str_replace('<br />', "\n", $node['text']['html']);
$html = str_replace('<br>', "\n", $html);
$texts = Html::getTextNodes($html);
- foreach ($texts as $t) {
- if (!isset($res['texts'][$t])) {
- $res['texts'][$t] = ['key' => base64_encode($t), 'occurences' => 0];
- }
- $res['texts'][$t]['occurences']++;
- }
+ self::addTexts($texts, $res['texts']);
} else if ($node['type'] === 'image') {
$res['images'][$assetId] = ['page' => $pageID, 'id' => $assetId, 'alt' => $node['image']['alt'], 'url' => $data['assets'][$assetId]['hostedUrl']];
}
}
+
+ if (is_file($mirrorPath . $url)) {
+ $texts = Html::getTextNodes(file_get_contents($mirrorPath . $url));
+ self::addTexts($texts, $res['texts']);
+ }
}
$ignoreNames = ['slug', 'json'];
} else if ($type === 'RichText') {
$texts = Html::getTextNodes($t);
}
- foreach ($texts as $t) {
- if (!isset($res['texts'][$t])) {
- $res['texts'][$t] = ['key' => base64_encode($t), 'occurences' => 0];
- }
- $res['texts'][$t]['occurences']++;
- }
+ self::addTexts($texts, $res['texts']);
}
}
}
- $res['seo'] = static::getPagesFromHTMLFiles($res['seo'], $mirrorPath);
-
-
-
+ $res['seo'] = static::getPagesFromHTMLFiles($res['seo'], $mirrorPath);
self::$_editableData[$key] = $res;
}
return self::$_editableData[$key];
}
+ protected static function addTexts($texts, &$array)
+ {
+ foreach ($texts as $t) {
+ $t = trim($t);
+ if (!$t) {
+ continue;
+ }
+ $paragraphs = preg_split('/\v{2,}/', $t);
+ foreach ($paragraphs as $p) {
+ if (!isset($array[$p])) {
+ $array[$p] = ['key' => base64_encode($p), 'occurences' => 0];
+ }
+ $array[$p]['occurences']++;
+ }
+ }
+ }
+
public static function getPagesFromHTMLFiles($seo, $mirrorPath)
{
foreach (Files::getRecursiveDirectoryIterator($mirrorPath) as $f) {