CKEditor v.4 in CodeIgniter 2 project [closed] - codeigniter

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
Is there someone who use CKEditor 4.0 in Codeigniter 2 project? I could find just inbtegrating with CKeditor 3. Very good tutorial, but project structure of forth version is differ from third. Pls, help to integrate ckeditor 4 with codeigniter 2 or pls share some link to tutorial with good explanation.
UPD
I tried this way. I added the following to my view
<script type="text/javascript">
CKEDITOR.replace( 'anons_area' );
</script>
<?php $anons_data = array(
'name' => 'anons',
'id' => 'anons_area',
'value' => 'Введите анонс',
'rows' => '10',
'cols' => '50',
'style' => 'width:50%',
);
echo form_textarea($anons_data); ?>
but it doesn't work.
UPD2
I found out why editor can't be loaded to browser. Firebug says that access forbiden to ckeditor.js script, You don't have permission to access the requested object.
It is either read-protected or not readable by the server.

Okay this really isn't hard at all...
Put this in the head of the page you want the ckEditor in, obviously pointing to the correct path for your application:
<script src="'.base_url().'assets/lib/ckeditor/ckeditor.js"></script>
Then in the body where you want the editor:
<textarea cols="80" id="editorName" name="editorName" rows="60">
</textarea>
At the bottom of the page:
<script type="text/javascript">
CKEDITOR.replace( 'editorName' );
</script>
It's honestly that easy.

using codeigniter & Ckeditor 4.02 based on code from the ck example page
<script src="<?php echo base_url();?>ckeditor/ckeditor.js"></script>
<?php
// static example to populate form with text
$formvalue = "Here is some text to appear in the form box. " ;
?>
<textarea class="ckeditor" name="editor1"><?php echo $formvalue ?></textarea>
You can also use the CI form helper
<?php
$formvalue = "Here is some text to appear in the form box." ;
$formdata = array(
'class' => 'ckeditor',
'name' => 'editor1',
'id' => 'SomeID',
'value' => $formvalue
);
echo form_textarea($formdata) ;
?>
Next step would be replacing $formvalue with a database result to populate the form (like editing a blog post, etc).
And if you use the CI Form helper it needs to be loaded first, the easiest is to autoload it in config/autoload.php
Now -- If some brilliant person has some tips on creating a custom tool bar...?

Related

Enable html in joomla editor

In one of my joomla custom form, I am rendering an editor as follows
<?php
$qu=$question ? $question : '';
$editor = JFactory::getEditor();
echo $editor->display('question', $qu, '100%', '400', '80', '15');
?>
The editor was working fine But when I am trying to submit after formatting, its html part won't get sumitted. If the editor was loading from xml filter="safehtml" or filter="raw" will work. But how to enable html in this case ?
Please help
Thanks in advance
The problem lies in JRequest::GET which by default strips all html.
You have to ask specifically the input you want html from.
JRequest::getVar( 'yourfieldname', '', 'post', 'string', JREQUEST_ALLOWHTML );
Joomla Docs

Using codeigniter to execute code from another file

I am new to CodeIgniter and I am used to the old school php scripting so I'll need some help with this:
I want to include a Captcha system in one of my forms.
According to its documentation, to generate an image, you need to do it like this:
<img id="captcha" src="/securimage/securimage_show" alt="CAPTCHA Image" />
I downloaded the files, but where do I put them? And how do I use Codeigniter to call the securimage_show.php file? And output its contents into the src attribute of the image?
When adding Captcha in Fuel (a codeigniter based cms), I've put the php file that generates the Captcha image in the folder where you put images, then link to it the same way you link to an image:
<?php echo img(array('src'=>'image_show.php', 'alt'=> 'CAPTCHA Image')); ?>
Perhaps not the nicest solution, but it works.
Alternatively, just use a Captcha plugin written specifically for codeigniter, such as the NuCaptcha CodeIgniter plugin, http://docs.nucaptcha.com/plugins/codeigniter.
Codeigiter have a captcha helper.
First, you want to create a folder where you will be able to store your captcha images and give this folder permissions to perform read/write operations. In this case, I've created captcha folder in root of my codeigniter instance.
Then, we want to load captcha helper:
$this->load->helper('captcha');
Let's initiate instance of captcha with our settings (you can do it either in Controller or View with your form):
$rand_string = strtoupper(random_string('nozero', 4));
$settings = array(
'word' => $rand_string,
'img_path' => './captcha/',
'img_url' => base_url() .'captcha/',
'img_width' => '250',
'img_height' => 35,
'expiration' => 7200
);
$cap = create_captcha($settings);
$this->session->set_userdata('captchaWord',$cap['word']);
Please note, that I'm keeping generated captcha word in my session whenever I create it (for instance on page refresh). This way I can compare original captcha word with input from my form. Then, I will display generated captcha image with input field somewhere in my form (View):
<form id="my_form">
<input type="text" name="captcha" value=""/>
<?= $cap['image']; ?>
</form>
Now, all I have to do, is to compare input received from my_form with actual captcha value (in my controller, where I handle form submission):
$userCaptcha = $this->input->post('captcha');
$actual_word = $this->session->userdata('captchaWord');
if( strcmp(strtoupper($userCaptcha),strtoupper($actual_word)) == 0 ) {
// input and captcha are the same
}

Cakephp with Ajax, this.element.setAttribute is not a function

I'm trying to make a stackoverflow like tags system.
I followed this tutorial (in French): http://www.formation-cakephp.com/34/autocomplete-en-ajax which uses Prototype and Scriptaculous. Of course, I adapted it to my project
I get the following error:
this.element.setAttribute is not a function : controls.js Line 86
which corresponds to
this.element.setAttribute('autocomplete','off');
in the control.js file
I'm really new to Ajax, so I don't have a clue on what I'm doing (wrong)...
If you need some code from any file, let me know!
view.ctp:
<div class="input">
<label>Tags :</label>
<?php e($ajax->autoComplete(
'Tag.tag',
'/tags/autocomplete',
array(
'minChars' => 3,
'indicator' => 'ajaxloader'
)
)); ?>
<div id="ajaxloader" style="display:none;">
Chargement...
</div>
Controller:
function autocomplete()
{
$recherche = utf8_decode($this->data['Tag']['tag']);
$tags = $this->Tag->find(
'all',
array(
'fields' => 'DISTINCT tag',
'conditions' => "tag LIKE '$recherche%'",
'order' => 'tag',
'limit' => 10
)
);
$this->set(compact('tag', 'recherche'));
}
jQuery, scriptaculous, & prototype don't play well together but you can resolve this issue by putting jQuery in no-conflict mode.
var $j = jQuery.noConflict();
// $j is now an alias to the jQuery function; creating the new alias is optional.
Now instead of using the $ to for jQuery use $j so for example:
$j(document).ready(function() {
$j( "div" ).hide();
});
For more information on avoiding jQuery conflicts refer to the following: https://learn.jquery.com/using-jquery-core/avoid-conflicts-other-libraries/
It appears that scriptaculous doesn't play well with j-query. When I removed the j-query link I stopped getting an error. This definitely isn't an ideal solution, but I thought I'd share my discovery.

CodeIgniter dropdown (Javascript?)

Is there any way I can make a dropdown submit a form without clicking a button to to submit it. I want to be able to change languages on the fly in my site. I have the languages all set up. Here's my dropdown:
<?php echo form_open('languages');
$language = array(
'select' => 'Select Language',
'english' => 'English',
'spanish' => 'Español',
'german' => 'Deutsch',
'french' => 'Français'
);
echo form_dropdown('language', $language);
echo form_hidden('current_page', uri_string());
echo form_submit('submit', $this->lang->line('header6'));
echo form_close();
?>
How do I get the form to work without the submit button?
The easiest way would be to use jQuery. Your form and dropdown should have IDs to make referencing them easier.
$attributes = array('id' => 'form1');
echo form_open('languages', $attributes);
...
echo form_dropdown('language', $language, null, 'mydropdown');
Also include the following javascript (you'll need to load jQuery on the page for this to work). I've included Google's hosted version but you could install it locally if you prefer.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#mydropdown").live("change keyup", function () {
$("#form1").submit();
});
});
</script>
You don't strictly need to bind to keyup, you could just bind to the change event (in which case you could replace live("change") with simply change() but keyup covers keyboard changes to the dropdown.
I use onchange with any live select menu... makes it very very easy to fire off other methods.
<select id="myID" onchange="alert('Fired!')"><option value="gold">Beer</option>

Cakephp 1.3, Weird behavior on firefox when using $this->Html->link

Greetings,
I am getting a very weird and unpredictable result in firefox when using the following syntax:
$this->Html->link($this->Html->div('p-cpt',$project['Project']['name']) . $this->Html->div('p-img',$this->Html->image('/img/projects/'.$project['Project']['slug'].'/project.thumb.jpg', array('alt'=>$project['Project']['name'],'width'=>100,'height'=>380))),array('controller' => 'projects', 'action' => 'view', $project['Project']['slug']),array('title' => $project['Project']['name'], 'escape' => false),false);
OK I know it is big but bear with me.
The point is to get the following output:
<a href="x" title="x">
<div class="p-ctp">Name</div>
<div class="p-img"><img src="z width="y" height="a" alt="d" /></div>
</a>
I'm not sure if this validates correctly both on cakephp and html but it works everywhere else apart from firefox.
You can actually see the result here: http://www.gnomonconstructions.com/projects/browser
To reproduce the result use the form with different categories and press search. At some point it will happen!!
Although most of the time it renders the way it should, sometimes it produces an invalid output like that:
<div class="p-cpt">
name
</div>
<div class="p-img">
<img src="x" width="x" height="x" alt="x" />
</div>
Looks like it repeats the link inside each element.
To be honest the only reason I used this syntax was because cakephp encourages it.
Any help will be much appreciated :)
I am guessing that the name of some projects is null. According to the documentation, if you pass null as the second argument to the div() method, it will not generate the closing tag (and the resulting markup will be invalid).
The example of invalid markup that you pasted above appear to have come from Firebug rather than Page Source. Use Page Source to view the actual markup sent to the browser. The anchor tag is not repeated.
I rewrote your code to better see what happens. Copy it into one of your views, change 'My Project' to null, and notice how it will affect the $name_div variable:
<div class="p-cpt">My Project</div> will turn into <div class="p-cpt">.
<?php
$project['Project']['name'] = 'My Project';
$project['Project']['slug'] = 'my-project';
$image = $this->Html->image(
'/img/projects/' . $project['Project']['slug'] . '/project.thumb.jpg',
array(
'alt' => $project['Project']['name'],
'width' => 100,
'height' => 380
)
);
$name_div = $this->Html->div('p-cpt', $project['Project']['name']);
$image_div = $this->Html->div('p-img', $image);
$link = $this->Html->link(
$name_div . $image_div,
array(
'controller' => 'projects',
'action' => 'view',
$project['Project']['slug']
),
array(
'title' => $project['Project']['name'],
'escape' => false
)
);
var_dump($image);
echo 'Notice what happens below if project name is null.';
var_dump($name_div);
var_dump($image_div);
var_dump($link);
echo $link;

Resources