Skip to content

Commit

Permalink
Allow captcha when submit a webllink (#223)
Browse files Browse the repository at this point in the history
* allow captcha  on submit web link

allow captcha  on submit web link (1/5)

* allow captcha  on submit web link

allow captcha  on submit web link (2/5)

* allow captcha  on submit web link

allow captcha  on submit web link (3/5)

* allow captcha  on submit web link

allow captcha  on submit web link (4/5)

* allow captcha  on submit web link

allow captcha  on submit web link (5/5)

* CS fix

CS fix

* XML CS for #223

Simple XML CS #223

* update captcha message

update captcha message like com_user, com_contatct #10931

* handle session data

handle session data 1(/2)

* handle session data

handle session data (2/2)

* move buttons down

move buttons down

* fix conflicts with #231

fix conflicts with #231

* fix conflicts with #231 

fix conflicts with #231
  • Loading branch information
alikon authored and chrisdavenport committed Jul 4, 2016
1 parent 77d2b1f commit 1680ec7
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 17 deletions.
13 changes: 13 additions & 0 deletions src/administrator/components/com_weblinks/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@
description="COM_WEBLINKS_COMPONENT_DESC"
>

<field
name="captcha"
type="plugins"
label="COM_WEBLINKS_FIELD_CAPTCHA_LABEL"
description="COM_WEBLINKS_FIELD_CAPTCHA_DESC"
default=""
folder="captcha"
filter="cmd"
>
<option value="">JOPTION_USE_DEFAULT</option>
<option value="0">JOPTION_DO_NOT_USE</option>
</field>

<field name="target" type="list"
default="0"
description="COM_WEBLINKS_FIELD_TARGET_DESC"
Expand Down
2 changes: 2 additions & 0 deletions src/administrator/language/en-GB/en-GB.com_weblinks.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ COM_WEBLINKS_ERROR_UNIQUE_ALIAS="Another web link from this category has the sam
COM_WEBLINKS_FIELD_ALIAS_DESC="The alias is for internal use only. Leave this blank and Joomla will fill in a default value from the title. It has to be unique for each web link in the same category."
COM_WEBLINKS_FIELD_CATEGORY_DESC="Choose a category for this Web link."
COM_WEBLINKS_FIELD_CATEGORYCHOOSE_DESC="Please choose a Web Links category to display."
COM_WEBLINKS_FIELD_CAPTCHA_DESC="Select the captcha plugin that will be used in the web link submit form. You may need to enter required information for your captcha plugin in the Plugin Manager.<br />If 'Use Default' is selected, make sure a captcha plugin is selected in Global Configuration."
COM_WEBLINKS_FIELD_CAPTCHA_LABEL="Allow Captcha on Web Link"
COM_WEBLINKS_FIELD_CONFIG_CAT_SHOWNUMBERS_DESC="Show/Hide the number of Web Links in each Category."
COM_WEBLINKS_FIELD_CONFIG_CAT_SHOWNUMBERS_LABEL="# Web Links"
COM_WEBLINKS_FIELD_CONFIG_COUNTCLICKS_DESC="If set to yes, the number of times the link has been clicked will be recorded."
Expand Down
10 changes: 10 additions & 0 deletions src/components/com_weblinks/controllers/weblink.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,21 @@ protected function getReturnPage()
*/
public function save($key = null, $urlVar = 'w_id')
{
// Get the application
$app = JFactory::getApplication();

// Get the data from POST
$data = $this->input->post->get('jform', array(), 'array');

// Save the data in the session.
$app->setUserState('com_weblinks.edit.weblink.data', $data);
$result = parent::save($key, $urlVar);

// If ok, redirect to the return page.
if ($result)
{
// Flush the data from the session
$app->setUserState('com_weblinks.edit.weblink.data', null);
$this->setRedirect($this->getReturnPage());
}

Expand Down
9 changes: 9 additions & 0 deletions src/components/com_weblinks/models/forms/weblink.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@
size="45"
labelclass="control-label" />

<field
name="captcha"
type="captcha"
label="COM_WEBLINKS_CAPTCHA_LABEL"
description="COM_WEBLINKS_CAPTCHA_DESC"
validate="captcha"
namespace="weblink"
/>

</fieldset>
<fields name="metadata">
<fieldset name="jmetadata"
Expand Down
54 changes: 37 additions & 17 deletions src/components/com_weblinks/views/form/tmpl/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@
JHtml::_('formbehavior.chosen', 'select');
JHtml::_('behavior.modal', 'a.modal_jform_contenthistory');

$captchaEnabled = false;
$captchaSet = $this->params->get('captcha', JFactory::getApplication()->get('captcha', '0'));

foreach (JPluginHelper::getPlugin('captcha') as $plugin)
{
if ($captchaSet === $plugin->name)
{
$captchaEnabled = true;
break;
}
}

// Create shortcut to parameters.
$params = $this->state->get('params');
?>
Expand All @@ -35,6 +47,31 @@
</h1>
<?php endif; ?>
<form action="<?php echo JRoute::_('index.php?option=com_weblinks&view=form&w_id=' . (int) $this->item->id); ?>" method="post" name="adminForm" id="adminForm" class="form-validate form-vertical">

<?php echo $this->form->renderField('title'); ?>
<?php echo $this->form->renderField('alias'); ?>
<?php echo $this->form->renderField('catid'); ?>
<?php echo $this->form->renderField('url'); ?>
<?php echo $this->form->renderField('tags'); ?>

<?php if ($params->get('save_history', 0)) : ?>
<?php echo $this->form->renderField('version_note'); ?>
<?php endif; ?>

<?php if ($this->user->authorise('core.edit.state', 'com_weblinks.weblink')) : ?>
<?php echo $this->form->renderField('state'); ?>
<?php endif; ?>
<?php echo $this->form->renderField('language'); ?>
<?php echo $this->form->renderField('description'); ?>

<hr class="hr-condensed" />

<?php if ($captchaEnabled) : ?>
<div class="btn-group">
<?php echo $this->form->renderField('captcha'); ?>
</div>
<?php endif; ?>

<div class="btn-toolbar">
<div class="btn-group">
<button type="button" class="btn btn-primary" onclick="Joomla.submitbutton('weblink.save')">
Expand All @@ -53,23 +90,6 @@
<?php endif; ?>
</div>

<hr class="hr-condensed" />
<?php echo $this->form->renderField('title'); ?>
<?php echo $this->form->renderField('alias'); ?>
<?php echo $this->form->renderField('catid'); ?>
<?php echo $this->form->renderField('url'); ?>
<?php echo $this->form->renderField('tags'); ?>

<?php if ($params->get('save_history', 0)) : ?>
<?php echo $this->form->renderField('version_note'); ?>
<?php endif; ?>

<?php if ($this->user->authorise('core.edit.state', 'com_weblinks.weblink')) : ?>
<?php echo $this->form->renderField('state'); ?>
<?php endif; ?>
<?php echo $this->form->renderField('language'); ?>
<?php echo $this->form->renderField('description'); ?>

<input type="hidden" name="return" value="<?php echo $this->return_page;?>" />
<input type="hidden" name="task" value="" />
<?php echo JHtml::_('form.token'); ?>
Expand Down
8 changes: 8 additions & 0 deletions src/components/com_weblinks/views/form/view.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class WeblinksViewForm extends JViewLegacy
public function display($tpl = null)
{
$user = JFactory::getUser();
// Get the application
$app = JFactory::getApplication();

// Get model data.
$this->state = $this->get('State');
Expand All @@ -59,6 +61,12 @@ public function display($tpl = null)

if (!empty($this->item))
{
// Override the base weblink data with any data in the session.
$temp = (array) $app->getUserState('com_weblinks.edit.weblink.data', array());
foreach ($temp as $k => $v)
{
$this->item->$k = $v;
}
$this->form->bind($this->item);
}

Expand Down
2 changes: 2 additions & 0 deletions src/language/en-GB/en-GB.com_weblinks.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php
; Note : All ini files need to be saved as UTF-8 - No BOM

COM_WEBLINKS_CAPTCHA_LABEL="Captcha"
COM_WEBLINKS_CAPTCHA_DESC="Please complete the security check."
COM_WEBLINKS_CONTENT_TYPE_WEBLINK="Web Link"
COM_WEBLINKS_CONTENT_TYPE_CATEGORY="Web Links Category"
COM_WEBLINKS_DEFAULT_PAGE_TITLE="Web Links"
Expand Down

0 comments on commit 1680ec7

Please sign in to comment.