From 8778e53b2970fa72172cc40e765311e73ee32f6d Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Fri, 28 Apr 2017 14:10:23 -0400 Subject: [PATCH 01/14] Update for Symphony 4.x Update release version. Update styles to fit Symphony 4.x layout. Add element in breadcrumb to go back to Documentation. Add data-titles to TD elements in index for mobile layout. --- assets/documenter.admin.css | 44 ++++++++------- content/content.index.php | 52 ++++++++--------- extension.driver.php | 18 +++--- extension.meta.xml | 5 +- lib/class.form.php | 108 +++++++++++++++++++++--------------- 5 files changed, 127 insertions(+), 100 deletions(-) diff --git a/assets/documenter.admin.css b/assets/documenter.admin.css index aa0aab2..1efef7a 100644 --- a/assets/documenter.admin.css +++ b/assets/documenter.admin.css @@ -1,6 +1,6 @@ /** - * A Symphony extension enabling addition of documentation - * to any page in the back end, including user-defined + * A Symphony extension enabling addition of documentation + * to any page in the back end, including user-defined * section indexes and entry editors. */ @@ -9,28 +9,30 @@ } #drawer-documenter { - background: #282828; + background: #fff; } #documenter-drawer .documenter-content { - color: rgba(255,255,255,.85); + color: #3B3D40; + padding: 0 3rem 3rem; } /* Headings */ #documenter-drawer h2 { - margin: 0 0 1em -0.39em; - padding: 0 0 0.39em 0.39em; - border-bottom: 1px solid #d1d1cc; - color: rgba(255,255,255,.85); + color: #2f77eb; + font-size: 2.4rem; + font-weight: 300; + padding: 3rem; } #documenter-drawer .documenter-content + h2 { - padding-top: 3em; + padding-top: 3rem; + border-top: 1px solid #d3dce2; } -#documenter-drawer .documenter-content h1, -#documenter-drawer .documenter-content h2, +#documenter-drawer .documenter-content h1, +#documenter-drawer .documenter-content h2, #documenter-drawer .documenter-content h3 { border-bottom: 1px solid #e7e7e7; margin: 0 0 0 -0.5em; @@ -42,8 +44,8 @@ color: rgba(255,255,255,.85); } -#documenter-drawer .documenter-content h1:after, -#documenter-drawer .documenter-content h2:after, +#documenter-drawer .documenter-content h1:after, +#documenter-drawer .documenter-content h2:after, #documenter-drawer .documenter-content h3:after { content: attr(data-show); position: absolute; @@ -52,20 +54,20 @@ color: rgba(255,255,255,.85); } -#documenter-drawer .documenter-content h1.open, -#documenter-drawer .documenter-content h2.open, +#documenter-drawer .documenter-content h1.open, +#documenter-drawer .documenter-content h2.open, #documenter-drawer .documenter-content h3.open { background: rgba(255, 255, 255, 0.6); } -#documenter-drawer .documenter-content h1.open:after, -#documenter-drawer .documenter-content h2.open:after, +#documenter-drawer .documenter-content h1.open:after, +#documenter-drawer .documenter-content h2.open:after, #documenter-drawer .documenter-content h3.open:after { content: attr(data-hide); } -#documenter-drawer .documenter-content .block.open + h1, -#documenter-drawer .documenter-content .block.open + h2, +#documenter-drawer .documenter-content .block.open + h1, +#documenter-drawer .documenter-content .block.open + h2, #documenter-drawer .documenter-content .block.open + h3 { border-top: 1px solid #e7e7e7; } @@ -110,13 +112,13 @@ content: counters(section, ".") ". "; } -#documenter-drawer ul, +#documenter-drawer ul, #documenter-drawer ol { margin: 0 0 1.5em 0; list-style-position: inside; } -#documenter-drawer ul li li, +#documenter-drawer ul li li, #documenter-drawer ol li li { margin-left: 1.5em; } diff --git a/content/content.index.php b/content/content.index.php index 7d3c634..48073e3 100644 --- a/content/content.index.php +++ b/content/content.index.php @@ -3,21 +3,21 @@ require_once(CONTENT . '/content.blueprintspages.php'); class contentExtensionDocumenterIndex extends contentBlueprintsPages { - + public function view() { - + // Start building the page $this->setPageType('table'); $this->setTitle(__('%1$s – %2$s', array(__('Symphony'), __('Documentation')))); - + $this->appendSubheading( __('Documentation'), Widget::Anchor( - __('Create New'), URL . '/symphony/extension/documenter/new/', + Widget::SVGIcon('add') . '' . __('Create New'), URL . '/symphony/extension/documenter/new/' . '', __('Create a new documentation item'), 'create button' ) ); - + // Grab all the documentation items $docs = Symphony::Database()->fetch(" SELECT @@ -27,13 +27,13 @@ public function view() { ORDER BY d.pages ASC "); - + // Build the table $thead = array( array(__('Title'), 'col'), array(__('Pages'), 'col') ); - + $tbody = array(); // If there are no records, display default message @@ -41,54 +41,56 @@ public function view() { $tbody = array(Widget::TableRow(array( Widget::TableData(__('None found.'), 'inactive', null, count($thead)) ), 'odd')); - + } - + // Otherwise, build table rows else{ $bOdd = true; - + foreach ($docs as $doc) { $doc_edit_url = URL . '/symphony/extension/documenter/edit/' . $doc['id'] . '/'; - + $col_title = Widget::TableData(Widget::Anchor( $doc['title'], $doc_edit_url )); $col_title->appendChild(Widget::Input("items[{$doc['id']}]", null, 'checkbox')); - + $col_title->setAttribute('data-title', __('Title')); + $pages = $doc['pages']; $pages = explode(',', $pages); $pages = join(', ', $pages); $col_pages = Widget::TableData($pages); - + $col_pages->setAttribute('data-title', __('Pages')); + $tbody[] = Widget::TableRow(array($col_title, $col_pages), ($bOdd ? 'odd' : NULL)); - + $bOdd = !$bOdd; } } - + $table = Widget::Table( Widget::TableHead($thead), null, Widget::TableBody($tbody), null ); $table->setAttribute('class','selectable'); - + $this->Form->appendChild($table); - + $actions = new XMLElement('div'); $actions->setAttribute('class', 'actions'); - + $options = array( array(null, false, __('With Selected...')), array('delete', false, __('Delete')), ); - + $actions->appendChild(Widget::Apply($options)); - + $this->Form->appendChild($actions); - + } - + function __actionIndex(){ $checked = @array_keys($_POST['items']); @@ -105,6 +107,6 @@ function __actionIndex(){ break; } } - } - - } + } + + } diff --git a/extension.driver.php b/extension.driver.php index b389808..c72cfe6 100644 --- a/extension.driver.php +++ b/extension.driver.php @@ -1,7 +1,7 @@ 'documenter-drawer')); foreach($items as $item) { - + // Add title if(isset($item['title'])) { $docs->appendChild( @@ -126,7 +126,7 @@ public function appendDocs($context) { ); } - + $button = General::sanitize(Symphony::Configuration()->get('button-text', 'Documentation')); $drawer = Widget::Drawer( 'documenter', @@ -134,8 +134,8 @@ public function appendDocs($context) { $docs, 'closed' ); - Administration::instance()->Page->insertDrawer($drawer, 'vertical-right'); - + + Administration::instance()->Page->insertDrawer($drawer, 'vertical-right', 'append', Widget::SVGIcon('help')); } } @@ -221,5 +221,5 @@ public function appendPreferences($context) { $group->appendChild($div); $context['wrapper']->appendChild($group); } - + } diff --git a/extension.meta.xml b/extension.meta.xml index 0d7d1f8..1d9b0ee 100644 --- a/extension.meta.xml +++ b/extension.meta.xml @@ -22,6 +22,9 @@ + + - Update for Symphony 4.x + - Sanitize configuration values before output @@ -64,4 +67,4 @@ - \ No newline at end of file + diff --git a/lib/class.form.php b/lib/class.form.php index 3847a9e..4c02ead 100644 --- a/lib/class.form.php +++ b/lib/class.form.php @@ -9,16 +9,24 @@ public function __construct($page) { $this->page = $page; } - - public function render() - { + + public function render() { $this->page->setPageType('form'); $fields = array(); - + + Administration::instance()->Page->insertBreadcrumbs( + array( + Widget::Anchor( + Widget::SVGIcon('arrow') . __('Documentation'), + SYMPHONY_URL . '/extension/documenter/' + ) + ) + ); + // If we're editing, make sure the item exists if ($this->page->_context[0]) { if (!$doc_id = $this->page->_context[0]) redirect(URL . '/symphony/extension/documenter/manage'); - + $existing = Symphony::Database()->fetchRow(0, " SELECT d.* @@ -28,7 +36,7 @@ public function render() d.id = '{$doc_id}' LIMIT 1 "); - + if (!$existing) { $this->page->_Parent->customError( E_USER_ERROR, __('Documentation Item not found'), @@ -39,15 +47,15 @@ public function render() ); } } - + // Build the status message if (isset($this->page->_context[1])) { if ($this->page->_context[1] == 'saved') { $this->page->pageAlert( __('Documentation Item updated at %1$s. Create another? View all Documentation', array(Widget::Time()->generate(__SYM_TIME_FORMAT__), - URL . '/symphony/extension/documenter/new/', - URL . '/symphony/extension/documenter/') + URL . '/symphony/extension/documenter/new/', + URL . '/symphony/extension/documenter/') ), Alert::SUCCESS ); @@ -55,8 +63,8 @@ public function render() $this->page->pageAlert( __('Documentation Item created at %1$s. Create another? View all Documentation', array(Widget::Time()->generate(__SYM_TIME_FORMAT__), - URL . '/symphony/extension/documenter/new/', - URL . '/symphony/extension/documenter/') + URL . '/symphony/extension/documenter/new/', + URL . '/symphony/extension/documenter/') ), Alert::SUCCESS ); @@ -66,15 +74,15 @@ public function render() // Find values if (isset($_POST['fields'])) { $fields = $_POST['fields']; - + } else if ($this->page->_context[0]) { $fields = $existing; $fields['content'] = General::sanitize($fields['content']); } - + $title = $fields['title']; if (trim($title) == '') $title = $existing['title']; - + // Start building the page $this->page->setTitle(__( ($title ? '%1$s – %2$s – %3$s' : '%1$s – %2$s'), @@ -85,10 +93,10 @@ public function render() ) )); $this->page->appendSubheading(($title ? $title : __('Untitled'))); - + // Start building the fieldsets $this->page->Form->setAttribute('class', 'two columns'); - + $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'primary column'); @@ -97,20 +105,19 @@ public function render() $label->appendChild(Widget::Input( 'fields[title]', General::sanitize($fields['title']) )); - + if (isset($this->page->_errors['title'])) { $label = Widget::Error($label, $this->page->_errors['title']); } $fieldset->appendChild($label); - + // Content textarea $label = Widget::Label(__('Content')); - + $content = Widget::Textarea('fields[content]', 30, 80, General::sanitize($fields['content'])); if (Symphony::Configuration()->get('text-formatter', 'documentation') != 'none') { $content->setAttribute('class', General::sanitize(Symphony::Configuration()->get('text-formatter', 'documentation'))); } - $label->appendChild($content); $fieldset->appendChild((isset($this->page->_errors['content']) ? Widget::Error($label, $this->page->_errors['content']) : $label)); @@ -123,12 +130,12 @@ public function render() } $this->page->Form->appendChild($fieldset); - + // Pages multi-select $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'secondary column'); $label = Widget::Label(__('Pages')); - + if (!is_array($fields['pages'])) { $pages_array = explode(',', $fields['pages']); } else { @@ -144,7 +151,7 @@ public function render() $items = array(); foreach ($menu['children'] as $item) { $items[] = array($item['link'], (in_array($item['link'], $pages_array)), General::sanitize($menu['name']) . " > " . General::sanitize($item['name'])); - + // If it's a section, add New and Edit pages // NOTE: This will likely break when extensions add custom nav groups if ($menu['name'] != 'Blueprints' and $menu['name'] != 'System') { @@ -171,37 +178,51 @@ public function render() array('type' => 'text/javascript'))); $label->appendChild(Widget::Select('fields[pages][]', $options, array('multiple' => 'multiple', 'id' => 'documenter-pagelist'))); - + if (isset($this->page->_errors['pages'])) { $label = Widget::Error($label, $this->page->_errors['pages']); } - + $fieldset->appendChild($label); $this->page->Form->appendChild($fieldset); - + // Form actions + Administration::instance()->Page->Header->setAttribute('class', 'spaced-bottom'); + Administration::instance()->Page->Context->setAttribute('class', 'spaced-right'); $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); - $div->appendChild(Widget::Input( - 'action[save]', ($this->page->_context[0] ? __('Save Changes') : __('Document It')), - 'submit', array('accesskey' => 's') - )); - - if ($this->page->_context[0]) { + + $div->appendChild( + Widget::SVGIconContainer( + 'save', + Widget::Input( + 'action[save]', + ($this->page->_context[0] ? __('Save Changes') : __('Document It')), + 'submit', + array('accesskey' => 's') + ) + ) + ); + + if($this->page->_context[0]){ $button = new XMLElement('button', __('Delete')); $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'confirm delete', 'title' => __('Delete this template'))); - $div->appendChild($button); + $div->appendChild( + Widget::SVGIconContainer( + 'delete', + $button + ) + ); } - + $this->page->Form->appendChild($div); } - - function applyFormatting($data, $validate = false, &$errors= null) - { + + function applyFormatting($data, $validate=false, &$errors=NULL){ include_once(TOOLKIT . '/class.textformattermanager.php'); - + $text_formatter = Symphony::Configuration()->get('text-formatter', 'documentation'); - + if ($text_formatter != 'none') { $formatter = TextformatterManager::create($text_formatter); $result = $formatter->run($data); @@ -210,9 +231,8 @@ function applyFormatting($data, $validate = false, &$errors= null) } if ($validate === true) { - include_once(TOOLKIT . '/class.xsltprocess.php'); - + if ($text_formatter == 'none') { $result = DocumentationForm::__replaceAmpersands($result); } else { @@ -222,6 +242,7 @@ function applyFormatting($data, $validate = false, &$errors= null) if (!General::validateXML($result, $errors, false, new XsltProcess)) { $result = $formatter->run(General::sanitize($data)); + if (!General::validateXML($result, $errors, false, new XsltProcess)) { return false; } @@ -232,9 +253,8 @@ function applyFormatting($data, $validate = false, &$errors= null) return $result; } - - private function __replaceAmpersands($value) - { + + private function __replaceAmpersands($value) { return preg_replace('/&(?!(#[0-9]+|#x[0-9a-f]+|amp|lt|gt);)/i', '&', trim($value)); } } From ddf7cc2d55dc2d5991d01fab7b021f4b2c98453b Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Mon, 1 May 2017 09:35:01 -0400 Subject: [PATCH 02/14] Add icon in actions list. --- lib/class.form.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/class.form.php b/lib/class.form.php index 4c02ead..a13274d 100644 --- a/lib/class.form.php +++ b/lib/class.form.php @@ -215,6 +215,8 @@ public function render() { ); } + $div->appendChild(Widget::SVGIcon('chevron')); + $this->page->Form->appendChild($div); } From 633901fb1a131e6745c0eb56e32d502936f093bd Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Thu, 4 May 2017 16:48:34 -0400 Subject: [PATCH 03/14] Make index table interactive. --- content/content.index.php | 1 + 1 file changed, 1 insertion(+) diff --git a/content/content.index.php b/content/content.index.php index 48073e3..dcb6314 100644 --- a/content/content.index.php +++ b/content/content.index.php @@ -74,6 +74,7 @@ public function view() { Widget::TableBody($tbody), null ); $table->setAttribute('class','selectable'); + $table->setAttribute('data-interactive', 'data-interactive'); $this->Form->appendChild($table); From d1f38c6e22b24d3f1f8f053d078f1a7d9e61de08 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Fri, 5 May 2017 15:05:46 -0400 Subject: [PATCH 04/14] Add extension custom icon to core Widget::SVGIcon. --- extension.driver.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/extension.driver.php b/extension.driver.php index c72cfe6..223e1c3 100644 --- a/extension.driver.php +++ b/extension.driver.php @@ -135,7 +135,16 @@ public function appendDocs($context) { 'closed' ); - Administration::instance()->Page->insertDrawer($drawer, 'vertical-right', 'append', Widget::SVGIcon('help')); + Widget::registerSVGIcon( + 'help', + '' + ); + Administration::instance()->Page->insertDrawer( + $drawer, + 'vertical-right', + 'append', + Widget::SVGIcon('help') + ); } } From f1b987a5c1a2e5115fc9ff177dbcf62bb99e21c8 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Wed, 10 May 2017 13:47:38 -0400 Subject: [PATCH 05/14] Fix CreateNew url --- content/content.index.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/content/content.index.php b/content/content.index.php index dcb6314..39e0006 100644 --- a/content/content.index.php +++ b/content/content.index.php @@ -13,8 +13,10 @@ public function view() { $this->appendSubheading( __('Documentation'), Widget::Anchor( - Widget::SVGIcon('add') . '' . __('Create New'), URL . '/symphony/extension/documenter/new/' . '', - __('Create a new documentation item'), 'create button' + Widget::SVGIcon('add') . '' . __('Create New') . '', + URL . '/symphony/extension/documenter/new/', + __('Create a new documentation item'), + 'create button' ) ); From 26723ea93724158e9f2a8d72c7ae8b4ebb7f8534 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Wed, 10 May 2017 15:01:18 -0400 Subject: [PATCH 06/14] Activated menu item fixed Add navigationPreRender to activate Documenter menu item when in extension. --- extension.driver.php | 47 +++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/extension.driver.php b/extension.driver.php index 223e1c3..8af69a3 100644 --- a/extension.driver.php +++ b/extension.driver.php @@ -1,17 +1,8 @@ Error

You cannot directly access this file

"); - public function fetchNavigation() { - return array( - array( - 'location' => __('System'), - 'name' => __('Documentation'), - 'link' => '/', - 'limit' => 'manager', - ) - ); - } + Class Extension_Documenter extends Extension { public function getSubscribedDelegates() { return array( @@ -34,6 +25,40 @@ public function getSubscribedDelegates() { 'page' => '/backend/', 'delegate' => 'InitaliseAdminPageHead', 'callback' => 'appendDocs' + ), + array( + 'page' => '/backend/', + 'delegate' => 'NavigationPreRender', + 'callback' => 'navigationPreRender' + ) + ); + } + + public function navigationPreRender($context) { + $c = Administration::instance()->getPageCallback(); + + if (strpos($c['classname'], 'contentExtensionDocumenter') !== false) { + foreach ($context['navigation'] as $key => $section) { + if ($section['name'] == __('System')) { + $context['navigation'][$key]['class'] = 'active opened'; + + foreach ($context['navigation'][$key]['children'] as $subkey => $subsection) { + if ($subsection['name'] == __('Documentation')) { + $context['navigation'][$key]['children'][$subkey]['class'] = 'active'; + } + } + } + } + } + } + + public function fetchNavigation() { + return array( + array( + 'location' => __('System'), + 'name' => __('Documentation'), + 'link' => '/', + 'limit' => 'manager', ) ); } From de70ac0b6e86a9488ac4eeca745821a8fd044f6d Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Fri, 12 May 2017 11:37:09 -0400 Subject: [PATCH 07/14] Take translatable string for drawer button. --- extension.driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension.driver.php b/extension.driver.php index 8af69a3..53cb65d 100644 --- a/extension.driver.php +++ b/extension.driver.php @@ -152,7 +152,7 @@ public function appendDocs($context) { } - $button = General::sanitize(Symphony::Configuration()->get('button-text', 'Documentation')); + $button = General::sanitize(Symphony::Configuration()->get('button-text', __('Documentation'))); $drawer = Widget::Drawer( 'documenter', ($button != '' ? $button : __('Documentation')), From 27b974850ee94dda41802e3f35941f49cd17757a Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Wed, 17 May 2017 10:56:33 -0400 Subject: [PATCH 08/14] Update php-min/php-max info --- extension.meta.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension.meta.xml b/extension.meta.xml index 1d9b0ee..671bf02 100644 --- a/extension.meta.xml +++ b/extension.meta.xml @@ -22,7 +22,7 @@ - + - Update for Symphony 4.x From 0809a73e3bdc57a9c0625c4534a1fab106720846 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Fri, 26 May 2017 15:06:34 -0400 Subject: [PATCH 09/14] Style fixes --- assets/documenter.admin.css | 1 - 1 file changed, 1 deletion(-) diff --git a/assets/documenter.admin.css b/assets/documenter.admin.css index 1efef7a..39b290a 100644 --- a/assets/documenter.admin.css +++ b/assets/documenter.admin.css @@ -22,7 +22,6 @@ #documenter-drawer h2 { color: #2f77eb; font-size: 2.4rem; - font-weight: 300; padding: 3rem; } From 677f6248f3bcc3bbbd2d9acb56b2b4f53290aab8 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Thu, 24 Aug 2017 15:34:39 -0400 Subject: [PATCH 10/14] SQL and PHP cases PHP true,false,null in lowercase SQL keywords uppercase --- content/content.index.php | 2 +- extension.driver.php | 12 ++++++------ lib/class.form.php | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/content/content.index.php b/content/content.index.php index 39e0006..a3a8e91 100644 --- a/content/content.index.php +++ b/content/content.index.php @@ -65,7 +65,7 @@ public function view() { $col_pages = Widget::TableData($pages); $col_pages->setAttribute('data-title', __('Pages')); - $tbody[] = Widget::TableRow(array($col_title, $col_pages), ($bOdd ? 'odd' : NULL)); + $tbody[] = Widget::TableRow(array($col_title, $col_pages), ($bOdd ? 'odd' : null)); $bOdd = !$bOdd; } diff --git a/extension.driver.php b/extension.driver.php index 53cb65d..064abf7 100644 --- a/extension.driver.php +++ b/extension.driver.php @@ -135,7 +135,7 @@ public function appendDocs($context) { if(!empty($items)) { // Generate documentation panel - $docs = new XMLElement('div', NULL, array('id' => 'documenter-drawer')); + $docs = new XMLElement('div', null, array('id' => 'documenter-drawer')); foreach($items as $item) { // Add title @@ -183,11 +183,11 @@ public function uninstall() { public function install() { Symphony::Database()->query( "CREATE TABLE `tbl_documentation` ( - `id` int(11) unsigned NOT NULL auto_increment, - `title` varchar(255), - `pages` text, - `content` text, - `content_formatted` text, + `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `title` VARCHAR(255), + `pages` TEXT, + `content` TEXT, + `content_formatted` TEXT, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;" ); diff --git a/lib/class.form.php b/lib/class.form.php index a13274d..acabcfb 100644 --- a/lib/class.form.php +++ b/lib/class.form.php @@ -220,7 +220,7 @@ public function render() { $this->page->Form->appendChild($div); } - function applyFormatting($data, $validate=false, &$errors=NULL){ + function applyFormatting($data, $validate = false, &$errors = null){ include_once(TOOLKIT . '/class.textformattermanager.php'); $text_formatter = Symphony::Configuration()->get('text-formatter', 'documentation'); @@ -256,7 +256,7 @@ function applyFormatting($data, $validate=false, &$errors=NULL){ return $result; } - private function __replaceAmpersands($value) { + private function __replaceAmpersands($value){ return preg_replace('/&(?!(#[0-9]+|#x[0-9a-f]+|amp|lt|gt);)/i', '&', trim($value)); } } From eab82aff9dfe8ed503ea5059aaa024496e993f03 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Fri, 15 Jun 2018 10:41:55 -0400 Subject: [PATCH 11/14] Code refactoring for Database --- content/content.edit.php | 56 +++++++++++++++++--------- content/content.index.php | 21 +++++----- content/content.new.php | 39 ++++++++++-------- extension.driver.php | 83 +++++++++++++++++++++++++-------------- extension.meta.xml | 1 + lib/class.form.php | 16 ++++---- 6 files changed, 133 insertions(+), 83 deletions(-) diff --git a/content/content.edit.php b/content/content.edit.php index b9ef02c..79039d3 100644 --- a/content/content.edit.php +++ b/content/content.edit.php @@ -2,9 +2,9 @@ require_once(TOOLKIT . '/class.administrationpage.php'); require_once(EXTENSIONS . '/documenter/lib/class.form.php'); - + class contentExtensionDocumenterEdit extends AdministrationPage { - + private $form; public function __construct() { @@ -15,49 +15,67 @@ public function __construct() { public function view() { $this->form->render(); } - + public function action() { $doc_id = $this->_context[0]; - + // Delete action if (@array_key_exists('delete', $_POST['action'])) { - $page = Symphony::Database()->fetchRow(0, "SELECT * FROM tbl_documentation WHERE `id` = '$doc_id'"); - Symphony::Database()->delete('tbl_documentation', " `id` = '$doc_id'"); + $page = Symphony::Database() + ->select(['*']) + ->from('tbl_documentation') + ->where(['id' => $doc_id]) + ->execute() + ->rows()[0]; + + Symphony::Database() + ->delete('tbl_documentation') + ->where(['id' => $doc_id]) + ->execute() + ->success(); + redirect(URL . '/symphony/extension/documenter/'); } - + // Save action if(@array_key_exists('save', $_POST['action'])){ - + $this->_errors = array(); // Polish up some field content $fields = $_POST['fields']; - + if(isset($fields['pages'])) { $fields['pages'] = implode(',',$fields['pages']); } $fields['content_formatted'] = $this->form->applyFormatting($fields['content'], true, $this->_errors); - + if($fields['content_formatted'] === false){ - $fields['content_formatted'] = General::sanitize($this->form->applyFormatting($fields['content'])); + $fields['content_formatted'] = General::sanitize($this->form->applyFormatting($fields['content'])); } if(!isset($fields['content']) || trim($fields['content']) == '') $this->_errors['content'] = __('Content is a required field'); - - if(!isset($fields['pages']) || trim($fields['pages']) == '') $this->_errors['pages'] = __('Pages is a required field'); - if(empty($this->_errors)){ - if(!Symphony::Database()->update($fields, 'tbl_documentation', "`id` = '$doc_id'")) $this->pageAlert(__('Unknown errors occurred while attempting to save. Please check your activity log.', array(URL.'/symphony/system/log/')), Alert::ERROR); + if(!isset($fields['pages']) || trim($fields['pages']) == '') $this->_errors['pages'] = __('Pages is a required field'); - else{ + if(empty($this->_errors)){ + if (!Symphony::Database() + ->update('tbl_documentation') + ->set($fields) + ->where(['id' => $doc_id]) + ->execute() + ->success() + ) { + $this->pageAlert(__('Unknown errors occurred while attempting to save. Please check your activity log.', array(URL.'/symphony/system/log/')), Alert::ERROR); + } + else { redirect(URL . "/symphony/extension/documenter/edit/$doc_id/saved/"); } } } - - if(is_array($this->_errors) && !empty($this->_errors)) $this->pageAlert(__('An error occurred while processing this form. See below for details.'), Alert::ERROR); + + if(is_array($this->_errors) && !empty($this->_errors)) $this->pageAlert(__('An error occurred while processing this form. See below for details.'), Alert::ERROR); } - + } diff --git a/content/content.index.php b/content/content.index.php index a3a8e91..058b7c0 100644 --- a/content/content.index.php +++ b/content/content.index.php @@ -21,14 +21,12 @@ public function view() { ); // Grab all the documentation items - $docs = Symphony::Database()->fetch(" - SELECT - d.* - FROM - `tbl_documentation` AS d - ORDER BY - d.pages ASC - "); + $docs = Symphony::Database() + ->select(['d.*']) + ->from('tbl_documentation', 'd') + ->orderBy('d.pages') + ->execute() + ->rows(); // Build the table $thead = array( @@ -105,7 +103,12 @@ function __actionIndex(){ $doc_items = $checked; - Symphony::Database()->delete('tbl_documentation', " `id` IN('".implode("','",$checked)."')"); + Symphony::Database() + ->delete('tbl_documentation') + ->where(['id' => ['in' => $checked]]) + ->execute() + ->success(); + redirect(Administration::instance()->getCurrentPageURL()); break; } diff --git a/content/content.new.php b/content/content.new.php index 9092108..71cce92 100644 --- a/content/content.new.php +++ b/content/content.new.php @@ -2,9 +2,9 @@ require_once(TOOLKIT . '/class.administrationpage.php'); require_once(EXTENSIONS . '/documenter/lib/class.form.php'); - + class contentExtensionDocumenterNew extends AdministrationPage { - + private $form; public function __construct() { @@ -18,40 +18,45 @@ public function view() { public function action() { if(@array_key_exists('save', $_POST['action'])){ - + $this->_errors = array(); // Polish up some field content $fields = $_POST['fields']; - + if(isset($fields['pages'])) { $fields['pages'] = implode(',',$fields['pages']); } - + $fields['content_formatted'] = $this->form->applyFormatting($fields['content'], true, $this->_errors); - + if($fields['content_formatted'] === false){ - $fields['content_formatted'] = General::sanitize($this->form->applyFormatting($fields['content'])); + $fields['content_formatted'] = General::sanitize($this->form->applyFormatting($fields['content'])); } - if(!isset($fields['title']) || trim($fields['title']) == '') $this->_errors['title'] = __('Title is a required field'); - + if(!isset($fields['title']) || trim($fields['title']) == '') $this->_errors['title'] = __('Title is a required field'); + if(!isset($fields['pages']) || trim($fields['pages']) == '') $this->_errors['pages'] = __('Page is a required field'); - + if(!isset($fields['content']) || trim($fields['content']) == '') $this->_errors['content'] = __('Content is a required field'); if(empty($this->_errors)){ - - if(!Symphony::Database()->insert($fields, 'tbl_documentation')) $this->pageAlert(__('Unknown errors occurred while attempting to save. Please check your activity log.', array(URL.'/symphony/system/log/')), Alert::ERROR); - - else{ + if (!Symphony::Database() + ->insert('tbl_documentation') + ->values($fields) + ->execute() + ->success() + ) { + $this->pageAlert(__('Unknown errors occurred while attempting to save. Please check your activity log.', array(URL.'/symphony/system/log/')), Alert::ERROR); + } + else { $doc_id = Symphony::Database()->getInsertID(); redirect(URL . "/symphony/extension/documenter/edit/$doc_id/created/"); - } + } } } - + if(is_array($this->_errors) && !empty($this->_errors)) $this->pageAlert(__('An error occurred while processing this form. See below for details.'), Alert::ERROR); } - + } diff --git a/extension.driver.php b/extension.driver.php index 064abf7..7dcd3a5 100644 --- a/extension.driver.php +++ b/extension.driver.php @@ -75,14 +75,13 @@ public function appendDocs($context) { $pos = strripos($current_page_url, '/edit/'); $current_page_url = substr($current_page_url, 0, $pos + 6); } - $pages = Symphony::Database()->fetch(" - SELECT - d.pages, d.id - FROM - `tbl_documentation` AS d - ORDER BY - d.pages ASC - "); + + $pages = Symphony::Database() + ->select(['d.pages', 'd.id']) + ->from('tbl_documentation', 'd') + ->orderBy('d.pages') + ->execute() + ->rows(); foreach($pages as $key => $value) { if(strstr($value['pages'],',')) { @@ -108,15 +107,13 @@ public function appendDocs($context) { foreach($pages as $page) { if(in_array($current_page_url, $page)) { if(isset($page['id'])) { - $items[] = Symphony::Database()->fetchRow(0, " - SELECT - d.title, d.content_formatted - FROM - `tbl_documentation` AS d - WHERE - d.id = '{$page['id']}' - LIMIT 1 - "); + $items[] = Symphony::Database() + ->select(['d.title', 'd.content_formatted']) + ->from('tbl_documentation', 'd') + ->where(['d.id' => $page['id']]) + ->limit(1) + ->execute() + ->rows()[0]; } else { ### @@ -174,27 +171,55 @@ public function appendDocs($context) { } public function uninstall() { - Symphony::Database()->query("DROP TABLE `tbl_documentation`;"); + // Symphony::Database()->query("DROP TABLE `tbl_documentation`;"); Symphony::Configuration()->remove('text-formatter', 'documentation'); Symphony::Configuration()->remove('button-text', 'documentation'); Symphony::Configuration()->write(); + + return Symphony::Database() + ->drop('tbl_documentation') + ->ifExists() + ->execute() + ->success(); } public function install() { - Symphony::Database()->query( - "CREATE TABLE `tbl_documentation` ( - `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, - `title` VARCHAR(255), - `pages` TEXT, - `content` TEXT, - `content_formatted` TEXT, - PRIMARY KEY (`id`) - ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;" - ); Symphony::Configuration()->set('text-formatter', 'none', 'documentation'); Symphony::Configuration()->set('button-text', __('Documentation'), 'documentation'); Symphony::Configuration()->write(); - return; + + return Symphony::Database() + ->create('tbl_documentation') + ->ifNotExists() + ->charset('utf8') + ->collate('utf8_unicode_ci') + ->fields([ + 'id' => [ + 'type' => 'int(11)', + 'auto' => true, + ], + 'title' => [ + 'type' => 'varchar(255)', + 'null' => true, + ], + 'pages' => [ + 'type' => 'text', + 'null' => true, + ], + 'content' => [ + 'type' => 'text', + 'null' => true, + ], + 'content_formatted' => [ + 'type' => 'text', + 'null' => true, + ], + ]) + ->keys([ + 'id' => 'primary', + ]) + ->execute() + ->success(); } public function savePreferences($context) { diff --git a/extension.meta.xml b/extension.meta.xml index 671bf02..15bf715 100644 --- a/extension.meta.xml +++ b/extension.meta.xml @@ -24,6 +24,7 @@ - Update for Symphony 4.x + - Code refactoring for Database and EQFA - Sanitize configuration values before output diff --git a/lib/class.form.php b/lib/class.form.php index acabcfb..3086ba7 100644 --- a/lib/class.form.php +++ b/lib/class.form.php @@ -27,15 +27,13 @@ public function render() { if ($this->page->_context[0]) { if (!$doc_id = $this->page->_context[0]) redirect(URL . '/symphony/extension/documenter/manage'); - $existing = Symphony::Database()->fetchRow(0, " - SELECT - d.* - FROM - `tbl_documentation` AS d - WHERE - d.id = '{$doc_id}' - LIMIT 1 - "); + $existing = Symphony::Database() + ->select(['d.*']) + ->from('tbl_documentation', 'd') + ->where(['d.id' => $doc_id]) + ->limit(1) + ->execute() + ->rows()[0]; if (!$existing) { $this->page->_Parent->customError( From 3b4d26c0ab121861c8661217064bcf1ca271c265 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Tue, 19 Jun 2018 11:11:10 -0400 Subject: [PATCH 12/14] Replace deprecated method fetch() by select() --- extension.meta.xml | 1 + lib/class.form.php | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/extension.meta.xml b/extension.meta.xml index 15bf715..14a372e 100644 --- a/extension.meta.xml +++ b/extension.meta.xml @@ -25,6 +25,7 @@ - Update for Symphony 4.x - Code refactoring for Database and EQFA + - Replace deprecated method fetch() by select() - Sanitize configuration values before output diff --git a/lib/class.form.php b/lib/class.form.php index 3086ba7..71e6849 100644 --- a/lib/class.form.php +++ b/lib/class.form.php @@ -160,7 +160,11 @@ public function render() { // Generate a list of sectionField-data for auto-generation of documentation: if ($item['type'] == 'section') { $arr2 = array('name' => $item['name'], 'link' => $item['link'], 'items' => array()); - $fields = FieldManager::fetch(null, $item['section']['id']); + $fields = (new FieldManager) + ->select() + ->section($item['section']['id']) + ->execute() + ->rows(); foreach($fields as $field) { /* @var $field Field */ From 46c410fae63aec94054c58cfe80559c06a913e49 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Tue, 19 Jun 2018 14:07:39 -0400 Subject: [PATCH 13/14] Replace rows()[0] with proper next() --- content/content.edit.php | 2 +- extension.driver.php | 2 +- lib/class.form.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/content/content.edit.php b/content/content.edit.php index 79039d3..e26f70a 100644 --- a/content/content.edit.php +++ b/content/content.edit.php @@ -26,7 +26,7 @@ public function action() { ->from('tbl_documentation') ->where(['id' => $doc_id]) ->execute() - ->rows()[0]; + ->next(); Symphony::Database() ->delete('tbl_documentation') diff --git a/extension.driver.php b/extension.driver.php index 7dcd3a5..e258f11 100644 --- a/extension.driver.php +++ b/extension.driver.php @@ -113,7 +113,7 @@ public function appendDocs($context) { ->where(['d.id' => $page['id']]) ->limit(1) ->execute() - ->rows()[0]; + ->next(); } else { ### diff --git a/lib/class.form.php b/lib/class.form.php index 71e6849..7928322 100644 --- a/lib/class.form.php +++ b/lib/class.form.php @@ -33,7 +33,7 @@ public function render() { ->where(['d.id' => $doc_id]) ->limit(1) ->execute() - ->rows()[0]; + ->next(); if (!$existing) { $this->page->_Parent->customError( From 67e08a84f82dc0444fbcccc32e14e7e41768a040 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Tue, 18 Dec 2018 09:43:14 -0500 Subject: [PATCH 14/14] Remote SQL collate and charset definitions. --- extension.driver.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/extension.driver.php b/extension.driver.php index e258f11..8c3c0bf 100644 --- a/extension.driver.php +++ b/extension.driver.php @@ -191,8 +191,6 @@ public function install() { return Symphony::Database() ->create('tbl_documentation') ->ifNotExists() - ->charset('utf8') - ->collate('utf8_unicode_ci') ->fields([ 'id' => [ 'type' => 'int(11)',