Skip to content

Commit

Permalink
Merge pull request #3 from twiro/integration
Browse files Browse the repository at this point in the history
Fix PHP 5.4 Support
  • Loading branch information
twiro committed Apr 5, 2017
2 parents 6da8a0f + f77374a commit 14f580f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
36 changes: 18 additions & 18 deletions content/content.questions.php
Expand Up @@ -31,14 +31,14 @@ function __switchboard($type='view')
$function = ($type == 'action' ? '__action' : '__view') . (isset($this->_page) ? ucfirst($this->_page) : 'Index');

if(!method_exists($this, $function)) {

// If there is no action function, just return without doing anything
if($type == 'action') return;

$this->_Parent->errorPageNotFound();

}

$this->$function();

}
Expand All @@ -47,7 +47,7 @@ function __viewIndex()
{
$this->setTitle(anti_spam_question::EXT_NAME . ' – ' . __('Symphony'));
$this->setPageType('index');
$this->appendSubheading(anti_spam_question::EXT_NAME, Widget::Anchor('Create New', anti_spam_question::EXT_BASE_URL . '/new/', __('Create a new entry'), 'create button'));
$this->appendSubheading(anti_spam_question::EXT_NAME, Widget::Anchor('Create New', SYMPHONY_URL . anti_spam_question::EXT_CONTENT_PATH . '/new/', __('Create a new entry'), 'create button'));

$aTableHead = array(
array(__('Question'), 'col'),
Expand All @@ -70,7 +70,7 @@ function __viewIndex()

foreach($entries as $entry) {

$tableData[] = Widget::TableData(Widget::Anchor(General::limitWords($entry['question'], '100'), anti_spam_question::EXT_BASE_URL . '/edit/' . $entry['id'] . '/', $entry['id'], 'content'));
$tableData[] = Widget::TableData(Widget::Anchor(General::limitWords($entry['question'], '100'), SYMPHONY_URL . anti_spam_question::EXT_CONTENT_PATH . '/edit/' . $entry['id'] . '/', $entry['id'], 'content'));
$tableData[] = Widget::TableData(General::limitWords($entry['answer'], '100'));
$tableData[count($tableData) - 1]->appendChild(Widget::Input('items['.$entry['id'].']', NULL, 'checkbox'));

Expand All @@ -81,7 +81,7 @@ function __viewIndex()
unset($tableData);
}
}

$table = Widget::Table(Widget::TableHead($aTableHead), NULL, Widget::TableBody($aTableBody));
$table->setAttribute('class', 'selectable');
$table->setAttribute('data-interactive', 'data-interactive');
Expand Down Expand Up @@ -125,7 +125,7 @@ function __viewNew()
// page context
$this->appendSubheading(__('New Question'));
$breadcrumbs = array(
Widget::Anchor(anti_spam_question::EXT_NAME, anti_spam_question::EXT_BASE_URL . '/' )
Widget::Anchor(anti_spam_question::EXT_NAME, SYMPHONY_URL . anti_spam_question::EXT_CONTENT_PATH . '/' )
);
$this->insertBreadcrumbs($breadcrumbs);

Expand All @@ -150,16 +150,16 @@ function __viewNew()
$div->appendChild(Widget::Input('action[save]', 'Create Entry', 'submit', array('accesskey' => 's')));

$this->Form->appendChild($div);

}

function __actionNew() {

if(!Symphony::Database()->insert($_POST['fields'], anti_spam_question::EXT_TBL_NAME)) {
define_safe('__SYM_DB_INSERT_FAILED__', true);
$this->pageAlert(NULL, AdministrationPage::PAGE_ALERT_ERROR);
} else {
redirect(anti_spam_question::EXT_BASE_URL . '/edit/' . Symphony::Database()->getInsertID() . '/created/');
redirect(SYMPHONY_URL . anti_spam_question::EXT_CONTENT_PATH . '/edit/' . Symphony::Database()->getInsertID() . '/created/');
}
}

Expand All @@ -175,7 +175,7 @@ function __viewEdit()

$this->appendSubheading($entry['question']);
$breadcrumbs = array(
Widget::Anchor(anti_spam_question::EXT_NAME, anti_spam_question::EXT_BASE_URL . '/' )
Widget::Anchor(anti_spam_question::EXT_NAME, SYMPHONY_URL . anti_spam_question::EXT_CONTENT_PATH . '/' )
);
$this->insertBreadcrumbs($breadcrumbs);

Expand All @@ -202,17 +202,17 @@ function __viewEdit()
$this->Form->appendChild($div);

if(isset($this->_flag)) {

switch($this->_flag) {

case 'saved':
$this->pageAlert(__('Question updated successfully. <a href="%s">Create another?</a>', array(anti_spam_question::EXT_BASE_URL . '/new/')), Alert::SUCCESS);
$this->pageAlert(__('Question updated successfully. <a href="%s">Create another?</a>', array(SYMPHONY_URL . anti_spam_question::EXT_CONTENT_PATH . '/new/')), Alert::SUCCESS);
break;

case 'created':
$this->pageAlert(__('Question created successfully. <a href="%s">Create another?</a>', array(anti_spam_question::EXT_BASE_URL . '/new/')), Alert::SUCCESS);
$this->pageAlert(__('Question created successfully. <a href="%s">Create another?</a>', array(SYMPHONY_URL . anti_spam_question::EXT_CONTENT_PATH . '/new/')), Alert::SUCCESS);
break;

}
}
}
Expand All @@ -223,7 +223,7 @@ function __actionEdit()
define_safe('__SYM_DB_INSERT_FAILED__', true);
$this->pageAlert(NULL, Alert::ERROR);
} else {
redirect(anti_spam_question::EXT_BASE_URL . '/edit/' . $this->_id . '/saved/');
redirect(SYMPHONY_URL . anti_spam_question::EXT_CONTENT_PATH . '/edit/' . $this->_id . '/saved/');
}
}
}
3 changes: 3 additions & 0 deletions extension.meta.xml
Expand Up @@ -16,6 +16,9 @@
</author>
</authors>
<releases>
<release version="2.1.2" date="2017-04-05" min="2.4.0" max="2.x.x">
- Fix PHP 5.4 Support ([#2](https://github.com/twiro/anti_spam_question/issues/2))
</release>
<release version="2.1.1" date="2017-03-21" min="2.4.0" max="2.x.x">
- Fix code example in documentation ([#1](https://github.com/twiro/anti_spam_question/issues/1))
</release>
Expand Down
20 changes: 10 additions & 10 deletions lib/class.anti_spam_question.php
@@ -1,7 +1,7 @@
<?php

class anti_spam_question {

/**
* Name of the extension table
* @var string
Expand All @@ -13,26 +13,26 @@ class anti_spam_question {
* @var string
*/
const EXT_TBL_NAME = 'tbl_anti_spam_question';

/**
* Define datasource root node name
* @var string
*/
const EXT_DS_ROOT = 'anti-spam-question';

/**
* Name of the extension content base url
* The extension's content path
* @var string
*/
const EXT_BASE_URL = URL . '/symphony/extension/anti_spam_question/questions';
const EXT_CONTENT_PATH = '/extension/anti_spam_question/questions';

/**
* Creates the table needed for the extensions entries
*/
public static function createTable()
{
$tbl = self::EXT_TBL_NAME;

return Symphony::Database()->query("
CREATE TABLE IF NOT EXISTS `$tbl` (
`id` int(11) unsigned NOT NULL auto_increment,
Expand All @@ -54,14 +54,14 @@ public static function deleteTable()
DROP TABLE IF EXISTS `$tbl`
");
}

/**
* event filter
*/
public function eventFilter($context)
{
if (in_array('anti-spam-question', $context['event']->eParamFILTERS)) {

$tbl = self::EXT_TBL_NAME;
$sql = "SELECT * FROM `$tbl` WHERE `id` = '" . $_POST['anti-spam-question']['id'] . "' LIMIT 1";
$entry = Symphony::Database()->fetchRow('0', $sql);
Expand All @@ -70,7 +70,7 @@ public function eventFilter($context)
$context['messages'][] = array('anti-spam-question', true, NULL);
} else {
$context['messages'][] = array('anti-spam-question', false, __('The answer to the anti spam question was incorrect.'));
}
}
}
}
}

0 comments on commit 14f580f

Please sign in to comment.