I am trying to integrate ck editor in my admin section.i putted the ck editor folder into my assets folder.here is the code
<script type="text/javascript" src="<?php echo base_url(); ?>assets/admin/ckeditor/ckeditor.js"></script>
after that i make a code for helper.here is the code
<?php
if(!defined('BASEPATH')) exit('No direct script access allowed');
/*
* CKEditor helper for CodeIgniter
*
* #author Samuel Sanchez <samuel.sanchez.work#gmail.com> - http://kromack.com/
* #package CodeIgniter
* #license http://creativecommons.org/licenses/by-nc-sa/3.0/us/
* #tutorial http://kromack.com/developpement-php/codeigniter/ckeditor-helper-for-codeigniter/
* #see http://codeigniter.com/forums/viewthread/127374/
* #version 2010-08-28
*
*/
/**
* This function adds once the CKEditor's config vars
* #author Samuel Sanchez
* #access private
* #param array $data (default: array())
* #return string
*/
function cke_initialize($data = array()) {
$return = '';
if(!defined('CI_CKEDITOR_HELPER_LOADED')) {
define('CI_CKEDITOR_HELPER_LOADED', TRUE);
$return = '<script type="text/javascript" src="'.base_url(). $data['path'] . '/ckeditor.js"></script>';
$return .= "<script type=\"text/javascript\">CKEDITOR_BASEPATH = '" . base_url() . $data['path'] . "/';</script>";
}
return $return;
}
/**
* This function create JavaScript instances of CKEditor
* #author Samuel Sanchez
* #access private
* #param array $data (default: array())
* #return string
*/
function cke_create_instance($data = array()) {
$return = "<script type=\"text/javascript\">
CKEDITOR.replace('" . $data['id'] . "', {";
//Adding config values
if(isset($data['config'])) {
foreach($data['config'] as $k=>$v) {
// Support for extra config parameters
if (is_array($v)) {
$return .= $k . " : [";
$return .= config_data($v);
$return .= "]";
}
else {
$return .= $k . " : '" . $v . "'";
}
if($k !== end(array_keys($data['config']))) {
$return .= ",";
}
}
}
$return .= '});</script>';
return $return;
}
/**
* This function displays an instance of CKEditor inside a view
* #author Samuel Sanchez
* #access public
* #param array $data (default: array())
* #return string
*/
function display_ckeditor($data = array())
{
// Initialization
$return = cke_initialize($data);
// Creating a Ckeditor instance
$return .= cke_create_instance($data);
// Adding styles values
if(isset($data['styles'])) {
$return .= "<script type=\"text/javascript\">CKEDITOR.addStylesSet( 'my_styles_" . $data['id'] . "', [";
foreach($data['styles'] as $k=>$v) {
$return .= "{ name : '" . $k . "', element : '" . $v['element'] . "', styles : { ";
if(isset($v['styles'])) {
foreach($v['styles'] as $k2=>$v2) {
$return .= "'" . $k2 . "' : '" . $v2 . "'";
if($k2 !== end(array_keys($v['styles']))) {
$return .= ",";
}
}
}
$return .= '} }';
if($k !== end(array_keys($data['styles']))) {
$return .= ',';
}
}
$return .= ']);';
$return .= "CKEDITOR.instances['" . $data['id'] . "'].config.stylesCombo_stylesSet = 'my_styles_" . $data['id'] . "';
</script>";
}
return $return;
}
/**
* config_data function.
* This function look for extra config data
*
* #author ronan
* #link http://kromack.com/developpement-php/codeigniter/ckeditor-helper-for-codeigniter/comment-page-5/#comment-545
* #access public
* #param array $data. (default: array())
* #return String
*/
function config_data($data = array())
{
$return = '';
foreach ($data as $key)
{
if (is_array($key)) {
$return .= "[";
foreach ($key as $string) {
$return .= "'" . $string . "'";
if ($string != end(array_values($key))) $return .= ",";
}
$return .= "]";
}
else {
$return .= "'".$key."'";
}
if ($key != end(array_values($data))) $return .= ",";
}
return $return;
}
now here is my controller code:
public $data = array();
public function __construct() {
//parent::Controller();
parent::__construct();
$this->load->helper('url'); //You should autoload this one ;)
$this->load->helper('ckeditor');
//Ckeditor's configuration
$this->data['ckeditor'] = array(
//ID of the textarea that will be replaced
'id' => 'content',
'path' => base_url().'assets/admin/js/ckeditor',
//Optionnal values
'config' => array(
'toolbar' => "Full", //Using the Full toolbar
'width' => "550px", //Setting a custom width
'height' => '100px', //Setting a custom height
),
//Replacing styles from the "Styles tool"
'styles' => array(
//Creating a new style named "style 1"
'style 1' => array (
'name' => 'Blue Title',
'element' => 'h2',
'styles' => array(
'color' => 'Blue',
'font-weight' => 'bold'
)
),
//Creating a new style named "style 2"
'style 2' => array (
'name' => 'Red Title',
'element' => 'h2',
'styles' => array(
'color' => 'Red',
'font-weight' => 'bold',
'text-decoration' => 'underline'
)
)
)
);
$this->data['ckeditor_2'] = array(
//ID of the textarea that will be replaced
'id' => 'content_2',
'path' => 'js/ckeditor',
//Optionnal values
'config' => array(
'width' => "550px", //Setting a custom width
'height' => '100px', //Setting a custom height
'toolbar' => array( //Setting a custom toolbar
array('Bold', 'Italic'),
array('Underline', 'Strike', 'FontSize'),
array('Smiley'),
'/'
)
),
//Replacing styles from the "Styles tool"
'styles' => array(
//Creating a new style named "style 1"
'style 3' => array (
'name' => 'Green Title',
'element' => 'h3',
'styles' => array(
'color' => 'Green',
'font-weight' => 'bold'
)
)
)
);
}
and here is my view code:
<textarea name="content" id="content" ><p>Example data</p></textarea>
<?php echo display_ckeditor($ckeditor); ?>
but my ckeditor.js is failed to load please help me or give me the suitable steps for integrating the ck editor in codeigniter.
i got the answer of my own question.
to install the ck editor in codeignitor you just have to follow the below steps:-
1.put the ck editor folder in assets(or in which you want).and give the proper path to js file.
2.now in your view section just include the js file like that:
<script type="text/javascript" src="<?php echo base_url(); ?>assets/admin/ckeditor/ckeditor.js"></script>
3.now on same file put this code:-
<textarea class="ckeditor" name="editor1"></textarea>
4.now you can see the editor on your browser.
Related
I am using a php module in my joomla site called: Ari Sexy Lightbox Lite. I was running on php 5.3 and had to go to 5.6.
However... Since this php upgrade i am getting two errors in my page.
Deprecated: Non-static method AriJSONHelper::encode() should not be called statically, assuming $this from incompatible context in /home/deb25878n3/domains/hang-on-run.nl/public_html/plugins/content/arisexylightboxlite/arisexylightboxlite.php on line 93
Deprecated: Non-static method AriJSONHelper::_getJSONHandler() should not be called statically, assuming $this from incompatible context in /home/deb25878n3/domains/hang-on-run.nl/public_html/plugins/content/arisexylightboxlite/arisexylightboxlite/kernel/Web/JSON/class.JSONHelper.php on line 21
I tried to fix this myself but my php knowledge is way to rusty...
I really hope that someone can help solve this.
This is the code itself:
<?php
/*
* ARI Sexy Lightbox Lite Joomla! 1.5 plugin
*
* #package ARI Sexy Lightbox Lite
* #version 1.0.0
* #author ARI Soft
* #copyright Copyright (c) 2009 www.ari-soft.com. All rights reserved
* #license GNU/GPL (http://www.gnu.org/copyleft/gpl.html)
*
*/
defined('_JEXEC') or die('Restricted access');
jimport('joomla.plugin.plugin');
jimport('joomla.filter.filterinput');
require_once dirname(__FILE__) . '/arisexylightboxlite/kernel/class.AriKernel.php';
AriKernel::import('Web.JSON.JSONHelper');
class plgContentArisexylightboxlite extends JPlugin
{
/*
* Constructor
*/
function __construct(&$subject, $config)
{
parent::__construct($subject, $config);
}
function onContentPrepare($context, &$article, &$params)
{
$this->prepareContent($article, 'arisexylightboxlite');
}
function onPrepareContent(&$article, &$params, $limitstart)
{
$this->prepareContent($article);
}
function prepareContent($article, $folder = '')
{
static $loaded;
if ($loaded)
return ;
$mainframe = JFactory::getApplication();
$plgParams = $this->params;
$rel = $plgParams->get('opt_find', 'sexylightbox');
$loadAssets = $plgParams->get('loadAssets', 'auto');
if ($loadAssets == 'auto' && (empty($article->text) || !preg_match('/<[^>]*rel=("|\')?' . $rel . '(\[|"|\'| |\/)/i', $article->text)))
return ;
$document = JFactory::getDocument();
$baseUri = JURI::root(true) . '/plugins/content/' . ($folder ? $folder . '/' : '') . 'arisexylightboxlite/js/';
$loadJQuery = (bool)$plgParams->get('includeJQuery', false);
$noConflict = (bool)$plgParams->get('noConflict', true);
if ($loadJQuery)
{
$loadJQueryMethod = $plgParams->get('loadJQueryMethod', 'google_cdn');
if ($loadJQueryMethod == 'local')
{
if (J3_0)
JHtml::_('jquery.framework', $noConflict);
else
$document->addScript($baseUri . 'jquery.min.js');
}
else
{
$document->addScript('//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js');
}
if ($noConflict)
{
if (!J3_0 || $loadJQueryMethod != 'local')
$document->addScript($baseUri . 'jquery.noconflict.js');
}
}
$document->addScript($baseUri . 'jquery.easing.js');
$document->addScript($baseUri . 'jquery.sexylightbox.min.js');
$document->addStyleSheet($baseUri . 'sexylightbox.css');
$jsOptions = $this->getOptions($folder);
$document->addScriptDeclaration(
sprintf('jQuery(document).ready(function(){ SexyLightbox.initialize(%s); });',
$jsOptions ? AriJSONHelper::encode($jsOptions) : ''));
$loaded = true;
}
function getOptions($folder = '')
{
$defOptions = array(
'find' => 'sexylightbox',
'zIndex' => 32000,
'color' => 'black',
'emergefrom' => 'top',
'showDuration' => 200,
'closeDuration' => 400,
'moveDuration' => 1000,
'moveEffect' => 'easeInOutBack',
'resizeDuration' => 1000,
'resizeEffect' => 'easeInOutBack',
'shake' => array(
'distance' => 10,
'duration' => 100,
'loops' => 2,
'transition' => 'easeInOutBack'
)
);
$options = $this->getParamOptions($defOptions);
$options['dir'] = str_replace(' ', '%20', JURI::root(true) . '/plugins/content/' . ($folder ? $folder . '/' : '') . 'arisexylightboxlite/js/sexyimages');
return $options;
}
function getParamOptions($defOptions, $prefix = 'opt_')
{
$plgParams = $this->params;
$options = array();
$filter = JFilterInput::getInstance();
foreach ($defOptions as $key => $value)
{
if (is_array($value))
{
$subOptions = $this->getParamOptions($value, $prefix . $key . '_');
if (count($subOptions) > 0)
$options[$key] = $subOptions;
}
else
{
$paramValue = $plgParams->get($prefix . $key, $value);
if ($paramValue !== $value)
{
$paramValue = $filter->clean($paramValue, gettype($value));
if ($paramValue !== $value)
$options[$key] = $paramValue;
}
}
}
return $options;
}
}
I have a custom extension that uses the Joomla profile plugin and extends it to provide additional fields to the user profile in the administrator panel and in the registered area on the front end of the website. The fields are set to display to admins-only, be disabled, be optional or be required. When they are set to admin-only, they do not show on the front end of the website in the "edit your profile" form. The plugin handles the UPDATE command for all fields with no issues in the administrator panel, but when the UPDATE command is triggered by a user updating their profile on the front end, all of the admin-only fields are overwritten with empty values. All of the other fields, whether they are optional or required are successfully saved or maintained in the form. I have included the custom profile plugin's PHP code below.
<?php
/**
* #package Joomla.Plugin
* #subpackage User.profile
*
* #copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
* #license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('JPATH_BASE') or die;
/**
* An example custom profile plugin.
*
* #since 1.6
*/
class PlgUserKiduka extends JPlugin
{
/**
* Load the language file on instantiation.
*
* #var boolean
* #since 3.1
*/
protected $autoloadLanguage = true;
/**
* Constructor
*
* #param object &$subject The object to observe
* #param array $config An array that holds the plugin configuration
*
* #since 1.5
*/
public function __construct(& $subject, $config)
{
parent::__construct($subject, $config);
JFormHelper::addFieldPath(__DIR__ . '/fields');
}
/**
* Runs on content preparation
*
* #param string $context The context for the data
* #param object $data An object containing the data for the form.
*
* #return boolean
*
* #since 1.6
*/
public function onContentPrepareData($context, $data)
{
// No need to display the context variable as a heading on the registration page
// echo '<h1>'.$context.'</h1>';
// Check we are manipulating a valid form.
if (!in_array($context, array('com_users.profile', 'com_users.user', 'com_users.registration', 'com_admin.profile')))
{
return true;
}
if (is_object($data))
{
$userId = isset($data->id) ? $data->id : 0;
if ($userId > 0)
{
// Load the profile data from the database.
$db = JFactory::getDbo();
$db->setQuery(
'SELECT * FROM #__kiduka_accounts WHERE user_id = ' . $userId
);
$data->kiduka = $db->loadObject();
}
}
return true;
}
/**
* adds additional fields to the user editing form
*
* #param JForm $form The form to be altered.
* #param mixed $data The associated data for the form.
*
* #return boolean
*
* #since 1.6
*/
public function onContentPrepareForm($form, $data)
{
if (!($form instanceof JForm))
{
$this->_subject->setError('JERROR_NOT_A_FORM');
return false;
}
// Check we are manipulating a valid form.
$name = $form->getName();
if (!in_array($name, array('com_admin.profile', 'com_users.user', 'com_users.profile', 'com_users.registration')))
{
return true;
}
foreach(JFactory::getUser()->get('groups') as $group){
if(in_array($group, $this->params->get('usergroup'))){
return true;
}
}
// Add the registration fields to the form.
JForm::addFormPath(__DIR__ . '/profiles');
$form->loadFile('profile', false);
$fields = array(
'firechief',
'title',
'membership_no',
'organization',
'organizationtype',
'membertype',
'afcaregion',
'municipalcode',
'membershipyear',
'address1',
'address2',
'city',
'province',
'postalcode',
'country',
'businessphone',
'homephone',
'cellphone',
'fax',
'notes',
'gstexempt',
'billorganization',
'billaddress1',
'billaddress2',
'billcity',
'billprovince',
'billpostalcode',
'billcountry'
);
// Change fields description when displayed in front-end or back-end profile editing
$app = JFactory::getApplication();
foreach ($fields as $field)
{
// Case using the users manager in admin
if ($name == 'com_users.user')
{
// Toggle whether the field is required.
if ($this->params->get('profile-require_' . $field, 1) > 0 || $this->params->get('profile-require_' . $field, 1) == -1)
{
$form->setFieldAttribute($field, 'required', ($this->params->get('profile-require_' . $field) == 2) ? 'required' : '', 'kiduka');
}
else
{
$form->removeField($field, 'kiduka');
}
}
// Case registration
elseif ($name == 'com_users.registration')
{
// Toggle whether the field is required.
if ($this->params->get('register-require_' . $field, 1) > 0)
{
$form->setFieldAttribute($field, 'required', ($this->params->get('register-require_' . $field) == 2) ? 'required' : '', 'kiduka');
}
else
{
$form->removeField($field, 'kiduka');
}
}
// Case profile in site or admin
elseif ($name == 'com_users.profile' || $name == 'com_admin.profile')
{
// Toggle whether the field is required.
if ($this->params->get('profile-require_' . $field, 1) > 0)
{
$form->setFieldAttribute($field, 'required', ($this->params->get('profile-require_' . $field) == 2) ? 'required' : '', 'kiduka');
}
else
{
$form->removeField($field, 'kiduka');
}
}
}
return true;
}
/**
* saves user profile data
*
* #param array $data entered user data
* #param boolean $isNew true if this is a new user
* #param boolean $result true if saving the user worked
* #param string $error error message
*
* #return bool
*/
public function onUserAfterSave($data, $isNew, $result, $error)
{
$user = JFactory::getUser();
$modified_by = $user->get('id');
$userId = JArrayHelper::getValue($data, 'id', 0, 'int');
$datenow = JFactory::getDate();
$modified = $datenow->toSql();
$fields = array(
// 'membership_no',
'title',
'firechief',
'organization',
'address1',
'address2',
'city',
'province',
'postalcode',
'country',
'businessphone',
'homephone',
'cellphone',
'fax',
'organizationtype',
'membertype',
'billorganization',
'billaddress1',
'billaddress2',
'billcity',
'billprovince',
'billpostalcode',
'billcountry',
'afcaregion',
'gstexempt',
'notes',
'municipalcode',
'membershipyear'
);
if($isNew){
$query = 'INSERT INTO #__kiduka_accounts VALUES(NULL, '.$userId.', "", '.$userId.', '.$userId;
foreach($fields as $field){
$query .= ', "'.$data['kiduka'][$field].'"';
}
$query .= ')';
}else{
$query = 'UPDATE #__kiduka_accounts SET ';
$query .= 'modified = "'.$modified.'", ';
$query .= 'modified_by = "'.$modified_by.'", ';
$query .= 'membership_no = "'.$userId.'", ';
for($i = 0; $i < count($fields); $i++){
$query .= $fields[$i] . ' = "'.$data['kiduka'][$fields[$i]].'"';
if($i < count($fields) - 1){
$query .= ', ';
}
}
$query .= ' WHERE user_id = "'.$userId.'"';
}
// var_dump($data);
// die();
$db = JFactory::getDbo();
$db->setQuery($query);
$db->query();
// var_dump($query);
// die();
return true;
}
public function onUserAfterDelete($user, $success, $msg)
{
if (!$success)
{
return false;
}
$userId = JArrayHelper::getValue($user, 'id', 0, 'int');
if ($userId)
{
try
{
$db = JFactory::getDbo();
$db->setQuery(
'DELETE FROM #__kiduka_accounts WHERE user_id = ' . $userId);
$db->execute();
}
catch (Exception $e)
{
$this->_subject->setError($e->getMessage());
return false;
}
}
return true;
}
}
#Elin I have figured it out. It was suggested on the Joomla forum to use two $fields arrays, one for the front-end profile form and another with all of the fields for the administrator user manager profile form. I have included the PHP code for the onUserAfterSave function below. The if($app->isSite()) if/else shows the limited fields on the front-end profile form and the full list of fields on the administrator profile form.
public function onUserAfterSave($data, $isNew, $result, $error)
{
$app = JFactory::getApplication();
$user = JFactory::getUser();
$modified_by = $user->get('id');
$userId = JArrayHelper::getValue($data, 'id', 0, 'int');
$datenow = JFactory::getDate();
$modified = $datenow->toSql();
if($app->isSite())
{
$fields = array(
'address1',
'address2',
'city',
'province',
'postalcode',
'country',
'businessphone',
'homephone',
'cellphone',
'fax'
);
}
else
{
$fields = array(
'firechief',
'title',
'organization',
'organizationtype',
'membertype',
'afcaregion',
'municipalcode',
'membershipyear',
'address1',
'address2',
'city',
'province',
'postalcode',
'country',
'businessphone',
'homephone',
'cellphone',
'fax',
'notes',
'gstexempt',
'billorganization',
'billaddress1',
'billaddress2',
'billcity',
'billprovince',
'billpostalcode',
'billcountry'
);
}
if($isNew)
{
$db = JFactory::getDbo();
$query = 'INSERT INTO #__kiduka_accounts VALUES(NULL, '.$userId.', "", '.$userId.', '.$userId;
foreach($fields as $field)
{
$query .= ', "'.$data['kiduka'][$field].'"';
}
$query .= ')';
}
else
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query .= 'UPDATE #__kiduka_accounts SET ';
$query .= 'modified = "'.$modified.'", ';
$query .= 'modified_by = "'.$modified_by.'", ';
$query .= 'membership_no = "'.$userId.'", ';
for($i = 0; $i < count($fields); $i++)
{
$query .= $fields[$i] . ' = "'.$data['kiduka'][$fields[$i]].'"';
if($i < count($fields) - 1)
{
$query .= ', ';
}
}
$query .= ' WHERE user_id = "'.$userId.'"';
}
$db->setQuery($query);
$db->execute();
return true;
}
i am finally fed up of this problem, tried almost every solution but no solution.
I am using captcha-reCaptcha in my joomla website with BT login module, i can see the label captcha in the form but the captcha field is not showing, i am attaching the screenshot and recaptcha.php file as well where have changed the API SERVER URLs.
recaptcha.php
<?php
/**
* #package Joomla.Plugin
* #subpackage Captcha
*
* #copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* #license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
jimport('joomla.environment.browser');
/**
* Recaptcha Plugin.
* Based on the oficial recaptcha library( http://recaptcha.net/plugins/php/ )
*
* #package Joomla.Plugin
* #subpackage Captcha
* #since 2.5
*/
class plgCaptchaRecaptcha extends JPlugin
{
const RECAPTCHA_API_SERVER = "http://www.google.com/recaptcha/api";
const RECAPTCHA_API_SECURE_SERVER = "https://www.google.com/recaptcha/api";
const RECAPTCHA_VERIFY_SERVER = "www.google.com";
public function __construct($subject, $config)
{
parent::__construct($subject, $config);
$this->loadLanguage();
}
/**
* Initialise the captcha
*
* #param string $id The id of the field.
*
* #return Boolean True on success, false otherwise
*
* #since 2.5
*/
public function onInit($id)
{
// Initialise variables
$lang = $this->_getLanguage();
$pubkey = $this->params->get('public_key', '');
$theme = $this->params->get('theme', 'clean');
if ($pubkey == null || $pubkey == '')
{
throw new Exception(JText::_('PLG_RECAPTCHA_ERROR_NO_PUBLIC_KEY'));
}
$server = self::RECAPTCHA_API_SERVER;
if (JBrowser::getInstance()->isSSLConnection())
{
$server = self::RECAPTCHA_API_SECURE_SERVER;
}
JHtml::_('script', $server.'/js/recaptcha_ajax.js');
$document = JFactory::getDocument();
$document->addScriptDeclaration('window.addEvent(\'domready\', function() {
Recaptcha.create("'.$pubkey.'", "dynamic_recaptcha_1", {theme: "'.$theme.'",'.$lang.'tabindex: 0});});'
);
return true;
}
/**
* Gets the challenge HTML
*
* #return string The HTML to be embedded in the form.
*
* #since 2.5
*/
public function onDisplay($name, $id, $class)
{
return '<div id="dynamic_recaptcha_1"></div>';
}
/**
* Calls an HTTP POST function to verify if the user's guess was correct
*
* #return True if the answer is correct, false otherwise
*
* #since 2.5
*/
public function onCheckAnswer($code)
{
// Initialise variables
$privatekey = $this->params->get('private_key');
$remoteip = JRequest::getVar('REMOTE_ADDR', '', 'SERVER');
$challenge = JRequest::getString('recaptcha_challenge_field', '');
$response = JRequest::getString('recaptcha_response_field', '');;
// Check for Private Key
if (empty($privatekey))
{
$this->_subject->setError(JText::_('PLG_RECAPTCHA_ERROR_NO_PRIVATE_KEY'));
return false;
}
// Check for IP
if (empty($remoteip))
{
$this->_subject->setError(JText::_('PLG_RECAPTCHA_ERROR_NO_IP'));
return false;
}
// Discard spam submissions
if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0)
{
$this->_subject->setError(JText::_('PLG_RECAPTCHA_ERROR_EMPTY_SOLUTION'));
return false;
}
$response = $this->_recaptcha_http_post(self::RECAPTCHA_VERIFY_SERVER, "/verify",
array(
'privatekey' => $privatekey,
'remoteip' => $remoteip,
'challenge' => $challenge,
'response' => $response
)
);
$answers = explode("\n", $response[1]);
if (trim($answers[0]) == 'true') {
return true;
}
else
{
//#todo use exceptions here
$this->_subject->setError(JText::_('PLG_RECAPTCHA_ERROR_'.strtoupper(str_replace('-', '_', $answers[1]))));
return false;
}
}
/**
* Encodes the given data into a query string format.
*
* #param string $data Array of string elements to be encoded
*
* #return string Encoded request
*
* #since 2.5
*/
private function _recaptcha_qsencode($data)
{
$req = "";
foreach ($data as $key => $value)
{
$req .= $key . '=' . urlencode(stripslashes($value)) . '&';
}
// Cut the last '&'
$req = rtrim($req, '&');
return $req;
}
/**
* Submits an HTTP POST to a reCAPTCHA server.
*
* #param string $host
* #param string $path
* #param array $data
* #param int $port
*
* #return array Response
*
* #since 2.5
*/
private function _recaptcha_http_post($host, $path, $data, $port = 80)
{
$req = $this->_recaptcha_qsencode($data);
$http_request = "POST $path HTTP/1.0\r\n";
$http_request .= "Host: $host\r\n";
$http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
$http_request .= "Content-Length: " . strlen($req) . "\r\n";
$http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
$http_request .= "\r\n";
$http_request .= $req;
$response = '';
if (($fs = #fsockopen($host, $port, $errno, $errstr, 10)) == false )
{
die('Could not open socket');
}
fwrite($fs, $http_request);
while (!feof($fs))
{
// One TCP-IP packet
$response .= fgets($fs, 1160);
}
fclose($fs);
$response = explode("\r\n\r\n", $response, 2);
return $response;
}
/**
* Get the language tag or a custom translation
*
* #return string
*
* #since 2.5
*/
private function _getLanguage()
{
// Initialise variables
$language = JFactory::getLanguage();
$tag = explode('-', $language->getTag());
$tag = $tag[0];
$available = array('en', 'pt', 'fr', 'de', 'nl', 'ru', 'es', 'tr');
if (in_array($tag, $available))
{
return "lang : '" . $tag . "',";
}
// If the default language is not available, let's search for a custom translation
if ($language->hasKey('PLG_RECAPTCHA_CUSTOM_LANG'))
{
$custom[] ='custom_translations : {';
$custom[] ="\t".'instructions_visual : "' . JText::_('PLG_RECAPTCHA_INSTRUCTIONS_VISUAL') . '",';
$custom[] ="\t".'instructions_audio : "' . JText::_('PLG_RECAPTCHA_INSTRUCTIONS_AUDIO') . '",';
$custom[] ="\t".'play_again : "' . JText::_('PLG_RECAPTCHA_PLAY_AGAIN') . '",';
$custom[] ="\t".'cant_hear_this : "' . JText::_('PLG_RECAPTCHA_CANT_HEAR_THIS') . '",';
$custom[] ="\t".'visual_challenge : "' . JText::_('PLG_RECAPTCHA_VISUAL_CHALLENGE') . '",';
$custom[] ="\t".'audio_challenge : "' . JText::_('PLG_RECAPTCHA_AUDIO_CHALLENGE') . '",';
$custom[] ="\t".'refresh_btn : "' . JText::_('PLG_RECAPTCHA_REFRESH_BTN') . '",';
$custom[] ="\t".'help_btn : "' . JText::_('PLG_RECAPTCHA_HELP_BTN') . '",';
$custom[] ="\t".'incorrect_try_again : "' . JText::_('PLG_RECAPTCHA_INCORRECT_TRY_AGAIN') . '",';
$custom[] ='},';
$custom[] ="lang : '" . $tag . "',";
return implode("\n", $custom);
}
// If nothing helps fall back to english
return '';
}
}
secondly there is no other login module enabled, no other captcha module is enabled.
Please tell me the solution.
I am using a custom form decorator found at: http://code.google.com/p/digitalus-cms/source/browse/trunk/library/Digitalus/Form/Decorator/Composite.php?r=767
At the bottom of the file (line 70) is:
$output = '<div class="form_element">'
. $label
. $input
. $errors
. $desc
. '</div>';
I would like to make the DIV class dynamic and passed when I create the elements in my controller. Any built-in ZEND functions I use only modifies the LABEL or INPUT. Here's an example of my element creation:
$decorator = new Composite();
$this->addElement('text', 'start', array(
'label' => 'Start Number',
'required' => true,
'filters' => array('StringTrim'),
'validators' => array(
'alnum',
),
'decorators' => array($decorator)
));
Any ideas would be very much appreciated. Thanks for taking the time to look!
Now sure why all CSS classes are hardcoded, if you are allowed to change this current decorator just fix the render() method:
class Digitalus_Form_Decorator_Composite
{
/* ... */
public function render($content)
{
$element = $this->getElement();
if (!$element instanceof Zend_Form_Element) {
return $content;
}
if (null === $element->getView()) {
return $content;
}
$separator = $this->getSeparator();
$placement = $this->getPlacement();
$label = $this->buildLabel();
$input = $this->buildInput();
$errors = $this->buildErrors();
$desc = $this->buildDescription();
$output = '<div class="'.$this->getOption('class').'">'
. $label
. $input
. $errors
. $desc
. '</div>';
switch ($placement) {
case (self::PREPEND):
return $output . $separator . $content;
case (self::APPEND):
default:
return $content . $separator . $output;
}
}
/* ... */
}
And during element creation:
$element->setDecorators(array(
/* ... */
array(array('div'=>'Composite'), array('class' => 'my_class_name'))
/* ... */
)));
If you don't want to edit existing decorator, just extend it and override render() method...
I am trying to configure CKEditor but I get the following in my source, it seems that the helper is not being sent any of the $data from my index function, My helper is located application/helpers
This is my code:
Helper:
<?php
if(!defined('BASEPATH')) exit('No direct script access allowed');
/*
* CKEditor helper for CodeIgniter
*
* #author Samuel Sanchez <samuel.sanchez.work#gmail.com> - http://kromack.com/
* #package CodeIgniter
* #license http://creativecommons.org/licenses/by-nc-sa/3.0/us/
* #tutorial http://kromack.com/developpement-php/codeigniter/ckeditor-helper-for-codeigniter/
* #see http://codeigniter.com/forums/viewthread/127374/
* #version 2010-08-28
*
*/
/**
* This function adds once the CKEditor's config vars
* #author Samuel Sanchez
* #access private
* #param array $data (default: array())
* #return string
*/
function cke_initialize($data = array()) {
$return = '';
if(!defined('CI_CKEDITOR_HELPER_LOADED')) {
define('CI_CKEDITOR_HELPER_LOADED', TRUE);
$return = '<script type="text/javascript" src="'.base_url(). $data['path'] . '/ckeditor.js"></script>';
$return .= "<script type=\"text/javascript\">CKEDITOR_BASEPATH = '" . base_url() . $data['path'] . "/';</script>";
}
return $return;
}
/**
* This function create JavaScript instances of CKEditor
* #author Samuel Sanchez
* #access private
* #param array $data (default: array())
* #return string
*/
function cke_create_instance($data = array()) {
$return = "<script type=\"text/javascript\">
CKEDITOR.replace('" . $data['id'] . "', {";
//Adding config values
if(isset($data['config'])) {
foreach($data['config'] as $k=>$v) {
// Support for extra config parameters
if (is_array($v)) {
$return .= $k . " : [";
$return .= config_data($v);
$return .= "]";
}
else {
$return .= $k . " : '" . $v . "'";
}
if($k !== end(array_keys($data['config']))) {
$return .= ",";
}
}
}
$return .= '});</script>';
return $return;
}
/**
* This function displays an instance of CKEditor inside a view
* #author Samuel Sanchez
* #access public
* #param array $data (default: array())
* #return string
*/
function display_ckeditor($data = array())
{
// Initialization
$return = cke_initialize($data);
// Creating a Ckeditor instance
$return .= cke_create_instance($data);
// Adding styles values
if(isset($data['styles'])) {
$return .= "<script type=\"text/javascript\">CKEDITOR.addStylesSet( 'my_styles_" . $data['id'] . "', [";
foreach($data['styles'] as $k=>$v) {
$return .= "{ name : '" . $k . "', element : '" . $v['element'] . "', styles : { ";
if(isset($v['styles'])) {
foreach($v['styles'] as $k2=>$v2) {
$return .= "'" . $k2 . "' : '" . $v2 . "'";
if($k2 !== end(array_keys($v['styles']))) {
$return .= ",";
}
}
}
$return .= '} }';
if($k !== end(array_keys($data['styles']))) {
$return .= ',';
}
}
$return .= ']);';
$return .= "CKEDITOR.instances['" . $data['id'] . "'].config.stylesCombo_stylesSet = 'my_styles_" . $data['id'] . "';
</script>";
}
return $return;
}
/**
* config_data function.
* This function look for extra config data
*
* #author ronan
* #link http://kromack.com/developpement-php/codeigniter/ckeditor-helper-for-codeigniter/comment-page-5/#comment-545
* #access public
* #param array $data. (default: array())
* #return String
*/
function config_data($data = array())
{
$return = '';
foreach ($data as $key)
{
if (is_array($key)) {
$return .= "[";
foreach ($key as $string) {
$return .= "'" . $string . "'";
if ($string != end(array_values($key))) $return .= ",";
}
$return .= "]";
}
else {
$return .= "'".$key."'";
}
if ($key != end(array_values($data))) $return .= ",";
}
return $return;
}
**.htaccess:**
# Customized error messages.
ErrorDocument 404 /index.php
# Set the default handler.
DirectoryIndex index.php
# Various rewrite rules.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|css|js|images|files|scripts|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
Source
<script type="text/javascript" src="http://house.dev.local//ckeditor.js"></script><script type="text/javascript">CKEDITOR_BASEPATH = 'http://house.dev.local//';</script><script type="text/javascript">
View
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Editpage extends CI_Controller {
function __construct(){
parent::__construct();
}
function index($id){
if(!$this->session->userdata('logged_in'))redirect('admin/home');
$this->load->helper('ckeditor');
//Ckeditor's configuration
$this->data['ckeditor'] = array(
//ID of the textarea that will be replaced
'id' => 'content',
'path' => 'includes/js/ckedit',
//Optionnal values
'config' => array(
'toolbar' => "Full", //Using the Full toolbar
'width' => "550px", //Setting a custom width
'height' => '100px', //Setting a custom height
),
//Replacing styles from the "Styles tool"
'styles' => array(
//Creating a new style named "style 1"
'style 1' => array (
'name' => 'Blue Title',
'element' => 'h2',
'styles' => array(
'color' => 'Blue',
'font-weight' => 'bold'
)
),
//Creating a new style named "style 2"
'style 2' => array (
'name' => 'Red Title',
'element' => 'h2',
'styles' => array(
'color' => 'Red',
'font-weight' => 'bold',
'text-decoration' => 'underline'
)
)
)
);
if ($this->input->post('submit')){
#The User has submitted updates, lets begin!
#Set The validation Rules
$this->form_validation->set_rules('content', 'Content', 'trim|required|xss_clean');
#if the form_validation rules fail then load the login page with the errors. Otherwise continue validating the user/pass
if ($this->form_validation->run() == FALSE){
$data['cms_pages'] = $this->navigation_model->getCMSPages($id);
#connect to getCMSCotent and set the page info equal to the $data['page'] where the row is equal to the passed $id from the URL.
$data['page'] = $this->page_model->getCMSContent($id);
$data['content'] = $this->load->view('admin/editpage', $data, TRUE);
$this->load->view('admintemplate', $data);
}
#Form Validation passed, so lets continue updating.
#lets set some variables.
$content = $this->input->post('content', TRUE);
#Now if updatePage fails to update hte database then show "there was a problem", you could echo the db error itself
if($this->page_model->updatePage($id, $content)) {
$data['cms_pages'] = $this->navigation_model->getCMSPages($id);
#connect to getCMSContent and set the page info equal to the $data['page'] where the row is equal to the passed $id from the URL.
$data['page'] = $this->page_model->getCMSContent($id);
$data['success'] = TRUE;
$data['content'] = $this->load->view('admin/editpage', $data, TRUE);
$this->load->view('admintemplate', $data);
}//END if updatePage
}else{
$data['cms_pages'] = $this->navigation_model->getCMSPages($id);
#connect to getCMSCotent and set the page info equal to the $data['page'] where the row is equal to the passed $id from the URL.
$data['page'] = $this->page_model->getCMSContent($id);
$data['content'] = $this->load->view('admin/editpage', $data, TRUE);
$this->load->view('admintemplate', $data);
}//END if post submitted
} //END function index()
}
You do know that you can jst embed CK Editor with JS to a textarea, and not much around with all this.
http://ckeditor.com/demo
Hows you exactly how.. 3 second job.
One issue may be the double slash in your JS paths;
CKEDITOR_BASEPATH = 'http://house.dev.local//';
Also, is .htaccess blocking access to your CKEditor files ?
Where is your helper functions? what does it do ?
If that is the issue, please post it.
Also, your own helpers should NOT going in to 'system/helpers', they go in to your 'application/helpers', system helpers are for core helpers only.