/** * Edits a page * * @param {arr} $arr array containg page information * @param {site} $site object * @param {user} $user object * @return Response */ public static function edit($url, $changes, $site, $user) { // get a reference to the page object $page = Page::GetByUrl($url, $site->id); // get page $location = app()->basePath() . '/public/sites/' . $site->id . '/' . $url . '.html'; if ($page != NULL && file_exists($location)) { // get html $html = file_get_contents($location); // load the parser $dom = HtmlDomParser::str_get_html($html, $lowercase = true, $forceTagsClosed = false, $target_charset = DEFAULT_TARGET_CHARSET, $stripRN = false, $defaultBRText = DEFAULT_BR_TEXT, $defaultSpanText = DEFAULT_SPAN_TEXT); // content placeholder $main_content = ''; // get content foreach ($changes as $change) { $selector = $change['selector']; // set main content if ($selector == '[role="main"]') { $main_content = $change['html']; } // apply changes to the document $els = $dom->find($selector); if (isset($els[0])) { $els[0]->innertext = $change['html']; } } // remove data-ref attributes foreach ($dom->find('[data-ref]') as $el) { $el->removeAttr('data-ref'); } // update the page file_put_contents($location, $dom); // get text from content $text = strip_tags($main_content); $text = preg_replace("/\\s+/", " ", $text); $text = trim($text); $text = preg_replace('/[[:^print:]]/', '', $text); // set text to main_content $page->text = $text; // saves the page $page->save($site, $user); return TRUE; } else { return FALSE; } }