Source of file BoltHtmlEditorField_Toolbar.php
Size: 3,001 Bytes - Last Modified: 2021-12-24T06:39:34+00:00
/var/www/docs.ssmods.com/process/src/code/anchors/BoltHtmlEditorField_Toolbar.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 | <?php class BoltHtmlEditorField_Toolbar extends HtmlEditorField_Toolbar { private static $allowed_actions = array( 'LinkForm', 'MediaForm', 'viewfile', 'getanchors' ); public function getanchors() { $id = (int)$this->getRequest()->getVar('PageID'); $anchors = array(); if (($page = Page::get()->byID($id)) && !empty($page)) { if (!$page->canView()) { throw new SS_HTTPResponse_Exception( _t( 'HtmlEditorField.ANCHORSCANNOTACCESSPAGE', 'You are not permitted to access the content of the target page.' ), 403 ); } // Chris Bolt $anchors = self::getPageAnchors($page); // End Chris Bolt } else { throw new SS_HTTPResponse_Exception( _t('HtmlEditorField.ANCHORSPAGENOTFOUND', 'Target page not found.'), 404 ); } return json_encode($anchors); } // Chris Bolt public static function getPageAnchors($page) { $anchors = array(); $db = $page->config()->get('db'); if ($db && is_array($db)) { foreach($db as $k => $v) { if ($v == 'HTMLText') { // Similar to the regex found in HtmlEditorField.js / getAnchors method. if (preg_match_all("/\s(name|id)=\"([^\"]+?)\"|\s(name|id)='([^']+?)'/im", $page->$k, $matches)) { $anchors = array_merge($anchors, array_filter(array_merge($matches[2], $matches[4]))); } } } } $has_one = $page->config()->get('has_one'); if ($has_one && is_array($has_one)) { foreach($has_one as $k => $v) { if (($obj = $page->obj($k)) && $obj->exists()) { $anchors = array_merge($anchors, self::getObjectAnchors($obj)); if (is_a($obj, 'ContentModuleArea')) { if (($modules = $obj->Modules()) && $modules && $modules->count()) { foreach ($modules as $module) { $anchors = array_merge($anchors, self::getObjectAnchors($module)); } } } } } } $has_many = $page->config()->get('has_many'); if ($has_many && is_array($has_many)) { foreach($has_many as $k => $v) { if (($list = $page->$k()) && $list && $list->count()) { foreach ($list as $obj) { $anchors = array_merge($anchors, self::getObjectAnchors($obj)); } } } } return $anchors; } public static function getObjectAnchors($obj) { $anchors = array(); if ($obj->hasMethod('Anchor') && ($anchor = $obj->Anchor()) && is_string($anchor)) { $anchors[] = $anchor; } if ($obj->hasMethod('Anchors') && ($anchor = $obj->Anchors()) && is_array($anchor)) { $anchors = array_merge($anchors, $anchor); } $db = $obj->config()->get('db'); if ($db && is_array($db)) { foreach($db as $k => $v) { if ($v == 'HTMLText') { // Similar to the regex found in HtmlEditorField.js / getAnchors method. if (preg_match_all("/\s(name|id)=\"([^\"]+?)\"|\s(name|id)='([^']+?)'/im", $obj->$k, $matches)) { $anchors = array_merge($anchors, array_filter(array_merge($matches[2], $matches[4]))); } } } } return $anchors; } // End Chris Bolt } |