codeigniter simplepie - codeigniter

I wanted to mention, i have simplepie working in my development environment but as soon as I uploaded the site I cannot get feeds into my homepage. Any ideas? here is the code that works on localhost:
function Homepage()
{
parent::Controller();
$this->base = $this->config->item('base_url');
$this->css = $this->config->item('css');
$this->images = $this->config->item('images');
$this->load->library('simplepie');
$this->simplepie->set_feed_url('http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/world/rss.xml');
$this->simplepie->set_cache_location(APPPATH.'cache/rss');
$this->simplepie->init();
$this->simplepie->handle_content_type();
}
function index()
{
$data['rssdata'] = array(
"title" => $this->simplepie->get_title(),
"description" => $this->simplepie->get_description(),
"items" => $this->simplepie->get_items(0,5)
);
$this->load->view($data)
}
this is the code that is in the view:
<h3 class="ui-widget-header"><?= $rssdata['title']?></h3>
<div id="accordion" >
<div>
<h5><?= $rssdata['description']?></h5>
<p><?php foreach($rssdata['items'] as $item) :?>
<ul>
<li><?php anchor($item->get_link(),$item->get_title());?></li>
<li class="rssfeed"><?php echo $item->get_description();?></li>
</ul>
<p><small>Posted on <?php echo $item->get_date('j F Y g:i a');?></small></p>
<?php endforeach;?>
</div>

Use the newest "bleeding edge" from their GitHub profile, it sorts out several problems with PHP 5.3 which were making Apache explode from too many errors.
At time of writing, the bleeding edge is marked as v1.2.1-dev.

I've had this problem once, when my hosting setup did not have cURL installed, and error_reporting was off....
try setting var $force_fsockopen = false; to var $force_fsockopen = true; in the SimplePie config file to see if it makes a difference

Related

Setting pagination

controllers/home.php
$this->page_model->counter($this->data['post_detail']->post_ID);
$this->data['post_list'] = $this->post_model->post($this->data['post_detail']->post_ID);
$this->data['gallery_list'] = $this->post_model->post($this->data['post_detail']->post_ID, true);
$isAjax = array('news-post');
if (in_array($this->data['post_detail']->template_name, $isAjax))
{
if ( ! $this->input->is_ajax_request())
redirect($this->data['page_detail']->post_alias);
return $this->load->view($this->data['post_detail']->template_name, $this->data);
}
$this->load->view($this->data['post_detail']->template_name, $this->data);
views/news.php
<?php
$this->load->library('pagination');
$config['base_url'] = 'http://gsa-constructionspecialist.com/articles/article';
$config['total_rows'] = 14;
$config['per_page'] = 5;
$this->pagination->initialize($config);
?>
<div class="w626 content right">
<?php
if ($post_list){
foreach ($post_list as $pl){
?>
<div>
<p><br><br><strong><?php echo $pl->post_title; ?></strong></p>
<p><?php echo date('F jS, Y',strtotime($pl->post_date)); ?></p>
<br/>
<div style="text-align:justify"><?php echo word_limiter(strip_tags($pl->post_content),25); ?><span style="color:#fff"> Read More ></span></div>
</div>
<?php } } ?>
<?php echo $this->pagination->create_links(); ?>
I am trying to set the pagination but it only appears on the bottom and it does not hide the articles that suppose to be on the next page.
Please help fix the codes? Thanks in advance.
The pagination class will generate pages numbers based on the information you provide to it, however its up to you to generate the actual results for a particular page. You might tell the pagination class it's 5 results per page, but in reality it doesn't know whether you're outputting 5 results per page or 500.
It seems to me as though:
$this->data['post_list'] = $this->post_model->post($this->data['post_detail']->post_ID);
needs the current page number passing in, i.e.
$this->data['post_list'] = $this->post_model->post($this->data['post_detail']->post_ID, $current_page);
You then need to modify your database query within the model using LIMIT to limit the number of results (and the offset) for that page.
Does this help?

Retrieve product custom media image label in magento

I have a custom block loading products on my front page that loads the four newest products that have a custom product picture attribute set via:
$_helper = $this->helper('catalog/output');
$_productCollection = Mage::getModel("catalog/product")->getCollection();
$_productCollection->addAttributeToSelect('*');
$_productCollection->addAttributeToFilter("image_feature_front_right", array("notnull" => 1));
$_productCollection->addAttributeToFilter("image_feature_front_right", array("neq" => 'no_selection'));
$_productCollection->addAttributeToSort('updated_at', 'DESC');
$_productCollection->setPageSize(4);
What I am trying to do is grab the image_feature_front_right label as set in the back-end, but have been unable to do so. Here is my code for displaying the products on the front end:
<?php foreach($_productCollection as $_product) : ?>
<div class="fll frontSale">
<div class="productImageWrap">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'image_feature_front_right')->directResize(230,315,4) ?>" />
</div>
<div class="salesItemInfo">
<p class="caps"><?php echo $this->htmlEscape($_product->getName());?></p>
<p class="nocaps"><?php echo $this->getImageLabel($_product, 'image_feature_front_right') ?></p>
</div>
</div>
I read that $this->getImageLabel($_product, 'image_feature_front_right') was the way to do it, but produces nothing. What am I doing wrong?
Thanks!
Tre
It seems you asked this same question in another thread, so to help others who might be searching for an answer, I'll anser it here as well:
I imagine this is some sort of magento bug. The issue seems to be that the Magento core is not setting the custom_image_label attribute. Whereas for the default built-in images [image, small_image, thumbnail_image] it does set these attributes - so you could do something like:
$_product->getData('small_image_label');
If you look at Mage_Catalog_Block_Product_Abstract::getImageLabel() it just appends '_label' to the $mediaAttributeCode that you pass in as the 2nd param and calls $_product->getData().
If you call $_product->getData('media_gallery'); you'll see the custom image label is available. It's just nested in an array. So use this function:
function getImageLabel($_product, $key) {
$gallery = $_product->getData('media_gallery');
$file = $_product->getData($key);
if ($file && $gallery && array_key_exists('images', $gallery)) {
foreach ($gallery['images'] as $image) {
if ($image['file'] == $file)
return $image['label'];
}
}
return '';
}
It'd be prudent to extend the Magento core code (Ideally Mage_Catalog_Block_Product_Abstract, but I don't think Magento lets you override Abstract classes), but if you need a quick hack - just stick this function in your phtml file then call:
<?php echo getImageLabel($_product, 'image_feature_front_right')?>
Your custom block would need to inherit from Mage_Catalog_Block_Product_Abstract to give access to that method.
You could also use the code directly from the method in the template:
$label = $_product->getData('image_feature_front_right');
if (empty($label)) {
$label = $_product->getName();
}

codeigniter session issue - some session info not sticking

I'm using codeigniter session library to hold data that is used in a series of 3 pages and I'm experiencing strange behavior. My session variables remain in tact but the values disapear. Even stranger: I'm trying to store a serialized array in my session data and the first item of the array ends up being stored in a different variable?
I've attached a link that starts at the first page in the series where it is possible to click to the next page. I've printed the user_session data at the top of both pages (the third page isn't set up yet).
http://playmatics.com/nypl/site/index.php/member_area/quest/accept_quest/12
Sessions work everywhere else, for example I'm using a session to store login data and that works fine.
I've attached my controller and view below
//CONTROLLER:
function accept_quest() {
$assoc_quest_id = end($this->uri->segments);
if(!isset($quest_id)) {
redirect('member_area/quest');
//SEND A MESSAGE: NO QUEST STARTED
}
$quest_rows = $this->quest_model->get_quest_with_images($assoc_quest_id);
$quest = current($quest_rows);
$images = $this->pull_out_images($quest_rows);
//the data array is used both in the session,
//to pass values over to the next function in the quest chain
//and in the template
$data = array();
$data['quest_id'] = $assoc_quest_id;
$data['instruction_text'] = $quest->instructions;
$data['quest_title'] = $quest->name;
$data['quest_time_limit'] = $quest->time_limit;
$data['points_awarded'] = $quest->points_availible;
$data['quest_images'] = serialize($images);
//save data in a flash session to be used in the next function call in the quest chain: quest_action
$this->session->set_userdata($data);
print_r($this->session->all_userdata());
//the following data aren't needed in the session so they are added to the data array after the session has been set
$data['annotation_text'] = $quest->note;
$data['main_content'] = 'quests/quest_desc';
$this->load->view('includes/template', $data);
}
function quest_action() {
print_r($this->session->all_userdata());
$quest_id = $this->session->userdata('quest_id');
echo "the quest id is: $quest_id";
if(!isset($quest_id)) {
redirect('member_area/quest');
//SEND A MESSAGE: NO QUEST STARTED
}
$data['quest_id'] = $quest_id;
$data['quest_title'] = $this->session->userdata('quest_title');
$data['quest_images'] = $this->session->userdata('images');
$data['instruction_text'] = $this->session->userdata('instructions');
$data['quest_time_limit'] = $this->session->userdata('quest_time_limit');
$data['main_content'] = 'quests/quest_action';
$this->load->view('includes/template', $data);
}
//VIEW
//quest_desc:
<h1><?= $quest_title ?></h1>
<div id="quest_elements">
<figure>
<? foreach(unserialize($quest_images) as $image): ?>
<img class="media" src="<?= $image ?>" alt="<?= $quest_title ?> image"/>
<? endforeach; ?>
<figcaption>annotation: <?= $annotation_text ?></figcaption>
</figure>
<?= anchor("member_area/quest/quest_action", "Start Quest", array('title' => 'start quest')); ?>
</div><!-- end quest_elements -->
//quest_action:
<h1><?= $quest_title ?></h1>
<div id="quest_elements">
<figure>
<? foreach(unserialize($quest_images) as $image): ?>
<img class="media" src="<?= $image ?>" alt="<?= $quest_title ?> image"/>
<? endforeach; ?>
<figcaption>instructions: <?= $instruction_text ?></figcaption>
</figure>
<div id="timer">
<?= $quest_time_limit; ?>
</div>
<?= anchor("#start_timer", "Start Timer", array('title' => 'start quest timer')); ?>
</div>
If you are hitting the cookie size limit, I would suggest switching to CodeIgniter's native Database Sessions class. This enables you to store session information in a database, effectively removing the cookie size limitation, you are simply restricted to the size of the user_data field in the ci_sessions database.
Following the link above, the section on utilizing database sessions is near the bottom, providing you the proper DB schema and the config switch to database sessions.
As others have said, it is likely that you are hitting the 4k cookie limit of CI's session library. There are other alternative libraries available that use standard PHP sessions - http://codeigniter.com/wiki/PHPSession/ and http://codeigniter.com/wiki/Native_session/ for instance.

using ajax to post comments in cakephp results in 404 error, but no errors locally?

Using an ajax helper created for use with Jquery I've created a form that posts comments to "/comments/add", and this works as expected on my local wamp server but not on my production server. On my production server I get a '404 error, cannot find /comments/add'.
I've spent quite a bit of time searching for a resolution with no luck so far. I've focused on trying to identify a gap but nothing jumps out at me.
Here are some observations:
works as expected on local wamp server
requestHandler is listed as component
files on both local and production server are the same
controllers folder has write access
autoLayout and autoRender are both set to false
Here is the form in my view:
<div class="comments form">
<?php echo $ajax->form('/comments/add', 'tournament', array('url' => '/comments/add', 'update' => 'Comments', 'indicator' => 'commentSaved'));?>
<fieldset>
<legend><?php __('Add Comment');?></legend>
<div id="commentSaved" style="display: none; float: right;">
<h2>Loading...</h2>
</div>
<?php
echo $form->hidden('Comment.foreign_id', array('value' => $tournament['Tournament']['id']));
echo $form->hidden('Comment.belongs_to', array('value' => 'Tournament'));
echo $form->input('Comment.name');
echo $form->input('Comment.email');
echo $form->input('Comment.web', array('value' => 'http://'));
echo $form->input('Comment.content');
?>
</fieldset>
<?php echo $form->end('Submit');?>
</div>
And here is my 'comment's controller add action:
function add() {
if($this->RequestHandler->isAjax())
{
$this->autoLayout = false;
$this->autoRender=false;
$this->Comment->recursive =-1;
$commentInfos = $this->Comment->findAllByIp($_SERVER['REMOTE_ADDR']);
$spam = FALSE;
foreach($commentInfos as $commentInfo)
{
if ( time() - strtotime($commentInfo['Comment']['created']) < 180)
{
$spam = TRUE;
}
}
if ($spam === FALSE)
{
if (!empty($this->data)) {
$this->data['Comment']['ip'] = $_SERVER['REMOTE_ADDR'];
$this->Comment->create();
if ($this->Comment->save($this->data)) {
$this->Comment->recursive =-1;
$comments = $this->Comment->findAll(array('Comment.foreign_id' => $this->data['Comment']['foreign_id'], 'Comment.belongs_to' => $this->data['Comment']['belongs_to'], 'Comment.status' =>'approved'));
$this->set(compact('comments'));
$this->viewPath = 'elements'.DS.'posts';
$this->render('comments');
}
}
}
else
{
$this->Comment->recursive =-1;
$comments = $this->Comment->findAll(array('Comment.foreign_id' => $this->data['Comment']['foreign_id'], 'Comment.belongs_to' => $this->data['Comment']['belongs_to'], 'Comment.status' =>'approved'));
$this->set(compact('comments'));
$this->viewPath = 'elements'.DS.'posts';
$this->render('spam');
}
}
else
{
$this->Session->setFlash(__('Invalid Action. Please view a post to add a comment.', true));
$this->redirect(array('controller' => 'pages', 'action'=>'display', 'home'));
}
}
As you can see I've made sure that 'autoLayout' and 'autoRender' are set to false, but in Firebug I still get a 404 error stating /comments/add cannot be found on the production server.
I should also point out that I'm using jquery, jquery.form and jquery.editable as well as a ajax helper created to be used with jquery.
Any help or even suggestions about how to trouble shoot this is really appreciated.
Cheers,
Paul
Turns out that this was caused by the last few lines of code, calling a session that I don't use in comments.
else
{
$this->Session->setFlash(__('Invalid Action. Please view a post to add a comment.', true));
$this->redirect(array('controller' => 'pages', 'action'=>'display', 'home'));
}
Lesson learned, be careful with code you get from a tutorial. It might have something you don't use.
-Paul
Have you made sure your .htaccess files are present on the production server? If so, is mod_rewrite installed, and is .htaccess overriding allowed in the home directory? It seems like the problem must lie in some difference between your local environment and your production environment, and not in the code itself.

newbie problems with codeigniter

i'm trying to learn codeigniter (following a book) but don't understand why the web page comes out empty.
my controller is
class Welcome extends Controller {
function Welcome()
{
parent::Controller();
}
function index()
{
$data['title'] = "Welcome to Claudia's Kids";
$data['navlist'] = $this->MCats->getCategoriesNav();
$data['mainf'] = $this->MProducts->getMainFeature();
$skip = $data['mainf']['id'];
$data['sidef'] = $this->MProducts->getRandomProducts(3, $skip);
$data['main'] = "home";
$this->load->vars($data);
$this->load->view('template');
}
the view is:
<--doctype declaration etc etc.. -->
</head>
<body>
<div id="wrapper">
<div id="header">
<?php $this->load->view('header');?>
</div>
<div id='nav'>
<?php $this->load->view('navigation');?>
</div>
<div id="main">
<?php $this->load->view($main);?>
</div>
<div id="footer">
<?php $this->load->view('footer');?>
</div>
</div>
</body>
</html>
Now I know the model is passing back the right variables, but the page appears completely blank. I would expect at least to see an error, or the basic html structure, but the page is just empty. Moreover, the controller doesn't work even if I modify it as follows:
function index()
{
echo "hello.";
}
What am I doing wrong?
Everything was working until I made some changes to the model - but even if I delete all those new changes, the page is still blank.. i'm really confused!
thanks,
P.
I've isolated the function that gives me problems.
here it is:
function getMainFeature()
{
$data = array();
$this->db->select("id, name, shortdesc, image");
$this->db->where("featured", "true");
$this->db->where("status", "active");
$this->db->orderby("rand()");
$this->db->limit(1);
$Q = $this->db->get("products");
if ($Q->num_rows() > 0)
{
foreach($Q->result_arry() as $row)
{
$data = array(
"id" => $row['id'],
"name" => $row['name'],
"shortdesc" => $row['shortdesc'],
"image" => $row['image']
);
}
}
$Q->free_result();
return $data;
}
I'm quite convinced there must be a syntax error somewhere - but still don't understand why it doesn't show any error, even if I've set up error_reporting E_ALL in the index function..
First port of call is to run php -l on the command line against your controller and all the models you changed and then reverted.
% php -l somefile.php
It's likely that there is a parse error in one of the files, and you have Display Errors set to Off in your php.ini. You should set Display Errors on for development and off for production, in case you haven't already.
(Edit: in the example above you have missed off the closing } of the class. It might be that.)
Make sure error_reporting in index.php is set to E_ALL and post your code for the model in question.
After looking through your function I suspect it's caused by $this->db->orderby("rand()");
For active record this should be $this->db->order_by('id', 'random');
Note that orderby is deprecated, you can still use it for now but the new function name is order_by
Not sure, but it can be also caused by php's "display_errors" is set to false.
You can change it in your php.ini file.

Resources