Using codeigniter to execute code from another file - codeigniter

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
}

Related

Keep the text in ckeditor text editor after getting error of form_validation in codeigniter

I want to keep the text which has been styled for sometime in Ckeditor even if there is an error in form_validation and the browser redirects to the previous page that you have been working on.
Of course, I've used set_value() in my input options, but the problem still remains.
this is the code in my view file:
<? $news_Body = array('name' => 'news_Body', 'value' => set_value('news_Body'), 'tabindex' => '16'); echo form_textarea($news_Body)?>
<?php echo display_ckeditor($ckeditor); ?>
All of the other inputs which set_value() has been used in them keep their value except the text_area with Ckeditor!
Have you added a validation for news_Body ? If not, set_value will not work.;

cakephp ajax remote function select input parameter

I try to do two inputs in cakePHP (category, subcategory).
And if i change category input i want ajax to load values to subcategories.
What i can do it?
Im using remote function like this:
$ajax->remoteFunction(
array(
'url' => array( 'controller' => 'categories', 'action' => 'loadSubcategories', AND NOW I WANT PUT HERE CATEGORY ID FROM MY INPUT ),
'update' => 'subcategories'
)
);
<select name="categories" id="categories" onhange="MY REMOTE FUNCTION">
CATEGORIES
</select>
<select name="subcategories" id="categories" onhange="MY REMOTE FUNCTION">
LOAD SUBCATEGORIES BY CATEGORY ID WITH AJAX
</select>
I hope you can understand me :)
All you need is:
a Cake action that outputs a list of items based on the data it receives (shouldn't be hard)
a bit of JS that figures out which categories are selected (which you already have)
another bit of JS that packages that data and sends it to the Cake action
another bit of JS that updates the site with the list of items you received back
I'd take a look at jQuery's AJAX functions to accomplish this task. If you POST the data in a format like this, it's very easily accessible in $this->data in Cake:
{
'data[ModelName][categories]' : $("#category").val()
}

The url from an image via custom field (wordpress)

Am not even sure if this can be done but...
Ive added a feed from my forums to wordpress it works great but I need it to auto add the url of the image in a custom field from the images in the post (feed) first image would be fine as its only ahve a slider
Is there any way to do this?
Details
Ok I think I did not explain this very well so made a few screen shots
This is my slider at the minute with my
This is an imported post one other feed I was using
On this image you can see the custom field (which I have to fill in after every import)
Adding the image url into the custom field
and finaly a view of the slider working
This is what am trying to do (auto) so my feed from my booru / forums / 2 other of my sites and (2 other peoples) sites make my home page on a new site
Hope this explain it alot more
This uses the external Simple Pie library built into WordPress to fetch the feed, get the image url and create a new post for each item and save the image url as a custom field.
To activate the process we have to hook into wp_cron. The code below does it daily but it would probably be better to do it weekly to prevent overlap. Some overlap will probably occur so this still needs a way to check if we have already imported the image
First we need a function to save the custom field after the post has been created. This section comes from another answer I found on WordPress Answers.
Edit:
This needs to be wrapped in a plugin to schedule the cron event and the cron event was missing the action to make it fire.
Edit:
Final version below tested and it works but the feed the OP is getting is using relative url's so the domain name needs to be added somewhere in the output code.
<?php
/*
Plugin Name: Fetch The Feed Image
Version: 0.1
Plugin URI: http://c3mdigital.com
Description: Sample plugin code to fetch feed image from rss and save it in a post
Author: Chris Olbekson
Author URI: http://c3mdigital.com
License: Unlicense For more information, please refer to <http://unlicense.org/>
*/
//Register the cron event on plugin activation and remove it on deactivation
register_activation_hook(__FILE__, 'c3m_activation_hook');
register_deactivation_hook(__FILE__, 'c3m_deactivation_hook');
add_action( 'c3m_scheduled_event', 'create_rss_feed_image_post');
function c3m_activation_hook() {
wp_schedule_event(time(), 'weekly', 'c3m_scheduled_event');
}
function c3m_deactivation_hook() {
wp_clear_scheduled_hook('c3m_scheduled_event');
}
function create_rss_feed_image_post() {
if(function_exists('fetch_feed')) {
include_once(ABSPATH . WPINC . '/feed.php'); // include the required file
$feed = fetch_feed('http://animelon.com/booru/rss/images'); // specify the source feed
}
foreach ($feed->get_items() as $item) :
// global $user_ID;
$new_post = array(
'post_title' => $item->get_title(),
'post_status' => 'published',
'post_date' => date('Y-m-d H:i:s'),
//'post_author' => $user_ID,
'post_type' => 'post',
'post_category' => array(0)
);
$post_id = wp_insert_post($new_post);
if ($enclosure = $item->get_enclosure() )
update_post_meta( $post_id, 'feed_image_url', $enclosure->get_link() );
endforeach;
}

Joomla TinyMCE editor do not save inserted image

We are building joomla component. And we use joomla editor in which we insert content.
But there is a problem, because when we add image to editor and save it, it do not add image to database and when we opening this element to edit it again, there is only text in editor, image disappears.
This is how we use it:
$editor =& JFactory::getEditor();
echo $editor->display('text', $this->hello->text, '800', '300', '20', '20');
Maybe there is need to supply aditional parameters to display method?
Problem solved.
The standard way of getting the form data $post = JRequest::get('post'); is not enough in the case of using a editor. This will filter the content, hence losing line breaks and paragraps. So we need to add an extra line to get the editor contents in a raw unfiltered way. This data will be passed to the model to save into the database.
To get HTML form post data you need to get this data in following way
$data = JRequest::getVar( 'editorName', 'defaultValue', 'post', 'string', JREQUEST_ALLOWRAW );
And need to add a javascript for the view(tmpl file)
function submitbutton(action) {
var form = document.adminForm;
switch(action)
{
case 'save':case 'apply':
<?php
$editor =& JFactory::getEditor();
echo $editor->save( 'editorName' );
?>
case 'publish':
case 'unpublish':
case 'cancel':
default:
submitform( action );
}
}

Rewriting URL's in codeigniter with url_title()?

I am rewriting my website with codeigniter and have something I want to do but not sure it is possible.
I have a gallery on my site powered by the Flickr API. Here is an example of the code I use to display the Landscape pictures:
<?php foreach ($landscapes->photoset->photo as $l->photoset->photo) : ?>
<a href="<?=$l->photoset->photo->farm?>/<?=$l->photoset->photo->server?>/<?=$l->photoset->photo->id?>/<?=$l->photoset->photo->secret?>/<?=$l->photoset->photo->title?>">
<img class="f_thumb" src="<?=$l->photoset->photo->farm?>.static.flickr.com/<?=$l->photoset->photo->server?>/<?=$l->photoset->photo->id ?>_<?=$l->photoset->photo->secret ?>_s.jpg" title="<?=$l->photoset->photo->title?>" alt="<?=$l->photoset->photo->title?>" />
</a>
<?php endforeach; ?>
As you can see when a user clicks on a picture I pass over the Farm, Server, ID, Secret and Title elements using URI segments and build the page in the controller using
$data['farm'] = $this->uri->segment(3);
$data['server'] = $this->uri->segment(4);
$data['id'] = $this->uri->segment(5);
$data['secret'] = $this->uri->segment(6);
$data['title'] = $this->uri->segment(7);
Everything works and is fine, but the URL’s are a tad long. Example:
http://localhost:8888/wip/index.php/gallery/focus/3/2682/4368875046/e8f97f61d9/Old_Mill_House_in_Donegal
Is there a way to rewrite the URL so its more like:
http://localhost:8888/wip/index.php/gallery/focus/Old_Mill_House_in_Donegal
I was looking at using:
$url_title = $this->uri->segment(7);
$url_title = url_title($url_title, 'underscore', TRUE);
But I can’t seem to be able to get it to work. Any ideas?
Are the links linking internally? Or are they linking to flickr? If it's internally, I'd suppose you could pass all the requisite information via POST. If it's to flickr, I don't think there is a way you can control how they want requests to come in for a specific item.
What's the endgame/purpose of all that extra info (secret, server, etc)?

Resources