Change in APC for Magento stops SimplePie from working - magento

We have been using SimplePie on our Magento install to pull our blog posts into our home page without issue for several months now. Due to some other issues with Magento, we had our web host turn off opcode in APC. Once we did that, the next hourly update of SimplePie stopped the loading of the home page and returns the following error in Apache:
[Wed Jan 18 09:59:57 2012] [error] PHP Fatal error: Class 'Zend_Log' not found in {server root}/lib/SimplePie/simplepie.inc on line 738
I am at a bit of a loss on what is happening and what to do to fix it. SimplePie is delivered as a banner/widget so if I put it on a different category page I get the same results. (Page stops at SimplePie command) I was hoping it would be something simple like the change is forcing the old chached RSS to remain and can not be modified but I am not sure.
Any help would be very appreciated!
The code for SimplePie is unaltered and is version 1.2.1. I have a page /app/design/frontend/default/default/template/page/html/blog.phtml which has the following code.
<div class="col-narrow right sidebar-blog">
<h2>Our Gardening Blog</h2>
<?php
// Make sure SimplePie is included. You may need to change this to match the location of
require_once('lib/SimplePie/simplepie.inc');
// We'll process this feed with all of the default options.
$feed = new SimplePie();
// Set which feed to process.
$feed->set_feed_url('http://blog.americanmeadows.com/feed/');
// Run SimplePie.
$feed->init();
// This makes sure that the content is sent to the browser as text/html and the UTF-8
$feed->handle_content_type();
/*
Here, we'll loop through all of the items in the feed, and $item represents the
current item in the loop.
*/
foreach ($feed->get_items(0,2) as $rss_item):
?>
<div class="article-teaser">
<p><span><?php echo $rss_item->get_date('F j, Y'); ?></span></p>
<h2 class="article-title"><?php echo $rss_item->get_title(); ?></h2>
<?php if ($rss_item->get_item_tags('', 'thumbnail')) {$thumbnail = $rss_item->get_item_tags('', 'thumbnail'); echo "<img src='" . $thumbnail[0]['data'] . "'>"; } ?>
<p><?php echo $rss_item->get_description(); ?> <a class="more" href="<?php echo $rss_item->get_permalink(); ?>" target="_blank">Continue Reading</a></p>
</div>
<?php endforeach; ?>
</div>
I then have a banner which calls only the following
{{block type="page/html" template="page/html/blog.phtml"}}
I include that banner in the left column widget on our home page to have it display.
The lines in SimplePie is throwing the error is
function SimplePie($feed_url = null, $cache_location = null, $cache_duration = null)
{
// Other objects, instances created here so we can set options on them
$this->sanitize =& new SimplePie_Sanitize; /* Error is thrown here */
// Set options if they're passed to the constructor
if ($cache_location !== null)
{
$this->set_cache_location($cache_location);
}
I think that is what you need but am happy to post more.

My only thought here is that somewhere something is setting Zend_Log as an error logger. Check for set_error_handler() in your code and see if that's being registered anywhere. (You could double check that by causing an error yourself with trigger_error() and seeing what happens.)
As for why the error is occurring, I'd hazard a guess at that being because you're using 1.2.1 with PHP 4, which will give E_DEPRECATED errors when assigning new by reference (such as on that line).

Related

Showing notification with AJAX

I have a navbar on my users' panel. A part of the navbar indicates if the user has a new unread message. In this case a badge will appear next to an icon. I've simplified the codes here to make them easier to understand and read.
So this is the simplified HTML code:
<div class="btn-group msg-box">
<i class="fa fa-envelope"></i>
// this is the default state, no badge is shown
</div>
Here is the AJAX request which calls a custom function every 10 seconds:
<script type='text/javascript'>
$(document).ready(function(){
setInterval(checkMsg,10000);
});
function checkMsg(){
$.get('ajax.php',{user_id : <?php echo $user_id; ?>},function(data){
$('.msg-box').html(data);
});
}
</script>
And this is the ajax.php file content:
if(isset($_GET['user_id']){
// a few lines of code here to check if that particular user has any unread message.
// In such case a variable name $newMessage is set to 1. Now ... :
if($newMessage>0){
$data='
<i class="fa fa-envelope"></i>
<span class="badge"><i class="fa fa-info"></i></span>
';
}else{
$data='
<i class="fa fa-envelope"></i>
';
}
echo $data;
}
First of all, I know the way I've written this AJAX request is very rookie, but it works fine anyway, up to one point!
In case the user has a new message, and if they stay on a page, the code runs perfectly and shows the badge. But when the user refreshes the page or goes to another page, even-though they have a new message, that default state is shown again where there's no badge. And I know it's of course because I have specified a default state via HTML codes.
I need to know how I can keep the result of the AJAX request regardless of how many times the user refreshes the page or goes to another page.
UPDATE
I tried storing the query result in a SESSION in my ajax.php file. So instead of $data I wrote $_SESSION['data'].
Back on my HTML I made the following change:
<div class="btn-group msg-box">
<?php
if(!isset($_SESSION['data'])){
?>
<i class="fa fa-envelope"></i>
<?php
}else{
echo $_SESSION['data'];
}
?>
</div>
I made this change because I considered the fact that SESSIONS, by definition, are created and accessed globally within the domain. So once it's set, it can be checked and used on all other pages.
So that only if that SESSION isn't set, the default state should be displayed. But that as well doesn't seem to have my desired result. Still the same thing happens.
Ok, answering my own question now. :)
My UPDATE seemed to be a good idea which I tried.
The problem there was that I had written session_start(); on my main PHP file which was included in all other PHP files of the project.
So I basically thought that when the ajax.php file is called, there's no need to write session_start(); again. Because ajax.php was called inside a PHP file that had session_start(); in it already. So, I was wrong!
Adding session_start(); to the beginning of my code in ajax.php simply fixed the issue.

Magento 1.9 vertical menu issue

i've stumbled on a relatively known issue, but i cant find the solution.
I am using magento 1.9 CE
I have found some code to show a vertical menu of the current categorie with its children, and on the homepage the root category and everything works fine except 1 little detail. The subcategories don't load in the order of the backend. It's important that the same order as how it is setup in teh backend loads. I have tried allot of variations, like getCChildrenCategories but then it results in a blnak page. I also found menu's that do work, but then when i visit the homepage, i get an error and the page turns blank.
This is the code i am using at the moment.
<section class="block-layered-nav custom-left-menu" role="navigation">
<div class="block-content">
<?php
echo "<dl id='narrow-by-list2'>";
$_category = $this->getCurrentCategory();
$subcatid = $_category->getId();
$parentCategory = Mage::getBlockSingleton('catalog/navigation')->getCurrentCategory()->parent_id;
$name = $_category->getName();
$root_category = Mage::getModel('catalog/category')->load($subcatid);
$subcategories = $root_category->getChildren();
if($subcategories != "")
{
echo "<span class='h3'>Categorie</span><ol>";
foreach(explode(',',$subcategories) as $subcategory) {
$category = Mage::getModel('catalog/category')->load($subcategory);
echo '<li><a href="'.$category->getURL() .'" title="'.$category->getName().'" />'.$category->getName().'</a></li>';
}
}
else
{
echo "<span class='h3'>Categorie</span><ol>";
$root_category = Mage::getModel('catalog/category')->load($parentCategory);
$subcategories = $root_category->getChildren();
foreach(explode(',',$subcategories) as $subcategory) {
$category = Mage::getModel('catalog/category')->load($subcategory);
echo '<li><a href="'.$category->getURL() .'" title="'.$category->getName().'" />'.$category->getName().'</a>';
}
}
echo "</ol>";
?>
</div>
</section>
Any help would be much appreciated. All i know is that, somewhere in this code its not calling the categories the right way, i also tried:
$currentCat = Mage::registry('current_category');
but this results in a blank homepage.
Here is a link to the dev enviremont: http://dev.smoldersbv.nl/schroeven-en-bouten.html
If you hover over the main navigation you see a different order, the correct order, then on the left menu.
This is normal $this->getCurrentCategory() get the current category = the category you are currently browsing.
On the home page you are not in a category, like on any other cms pages or even on the contact us page, ... (and there are lots more). So you have nothing in the current category which is obvious.
Problem solved,
The way of the requests where wrong therefor this menu is unable to produce the order of the backend so i ended up using a whole different mockup.
thnx for looking anyway.

How to display error or success message in a template file?

I want to show message on some condition in a template file(custom module template file).I am having following code.
<?php
if(count($collection)): ?>
<?php foreach($collection as $coll): ?>
some calculations
<?php endforeach; ?>
<?php else: ?>
<?php $message = $this->__('There is no data available'); ?>
<?php echo Mage::getSingleton('core/session')->addNotice($message);?>
<?php endif;?>
But this is not working properly. The message is displayed on other pages not on the same page.
If you really need to implement that right in the template, you may use the code below:
<?php echo $this->getLayout()->createBlock('core/messages')->addNotice('My Message')->toHtml(); ?>
But the solution described by Amit Bera sounds like a better way to resolve it.
Muk,According to your code
Mage::getSingleton('core/session')->addNotice($message);
add an notice to magento.This is code set notice to session and which is reflecting on page refresh according php session ,a session variable set value is reflecting after page refresh.
If you already added this notice on other page before came to your file then ,you need to add core/session to custom module template file controllers file.
Code is $this->_initLayoutMessages('core/session');
In controller you need below code in controller.
/* load the layout from xml */
$this->loadLayout();
$this->_initLayoutMessages('core/session');
/* rendering layout */
$this->renderLayout();
Read more at inchoo blog
I found that $this->loadLayout() is what reads and clears messages from the session, therefore if you add messages before calling $this->loadLayout() then those messages should be displayed on the current page.
Example:
public function chooseFileAction() {
// a quick and dirty way to find the larger out of post_max_size and upload_max_filesize
$post_max_size = ini_get('post_max_size'); $post_max_size_int = str_replace('K', '000', str_replace('M', '000000', str_replace('G', '000000000', $post_max_size)));
$upload_max_filesize = ini_get('upload_max_filesize'); $upload_max_filesize_int = str_replace('K', '000', str_replace('M', '000000', str_replace('G', '000000000', $upload_max_filesize)));
$maxsize = $post_max_size_int < $upload_max_filesize_int ? $post_max_size : $upload_max_filesize;
// display max file size to user in a message box
$msg = 'Max file size: ' . $maxsize;
Mage::getSingleton('core/session')->addNotice($msg);
$this->loadLayout();
$this->_title($this->__('Catalog'))->_title($this->__('File Upload'));
$this->_setActiveMenu('catalog/customfileupload');
$block = $this->getLayout()->createBlock('customfileupload/adminhtml_customfileupload_choosefile');
$this->_addContent($block);
$this->renderLayout();
}
Caveat: this is tested in Magento 1.9, not 1.7.

Yii: Already add or edit record but view not update

I got a problem about browser cache when I already add/edit record in database. The data in database changed but in view not change. I must press F5 in browser for refresh that page and it'll show updated data.
Please guide to me how to solve this problem, Thanks.
Sorry I forgot to told you guys, In my application has two part.
Admin part (Backend) for add/edit data. (There's not any problem in
this part)
Front part for show data to viewer (Problem here! After
add/edit record in Admin part, this part not changed. I must refresh
page to see update)
This's my relevant code in Front part.
In Controller
class ProductController extends Controller
{
public function actionIndex()
{
$products = Product::model()->getProductList(); // use findAll() method
$this->render('index', array('products' => $products));
}
}
In Model
class Product extents CActiveRecord
{
/*
*
* The other code that generated by Gii
*
*/
public function getProductList()
{
return $this->findAll();
}
}
In View
<html>
<body>
<ul class="thumbnails thumbnails-product">
<?php foreach ($products as $product): ?>
<li class="span3" style="margin-left:0px;">
<div class="thumbnail">
<img class="img-thumb" src="../images/<?php echo $product->PDT_IMG" />
<?php echo CHtml::link($product->PDT_NAME, array('product/view/' . $product->PDT_ID)); ?>
<span class="price"><?php echo $product->PDT_PRICE; ?></span>
</div>
</li>
<?php endforeach; ?>
</ul>
</body>
</html>
If you want something to update on-the-fly, I think you're looking for in place editing.
You could take a look at this extension which does that for you.
Especially this part.
May be this can help you out:
Real-time display of server push data using Server-Sent Events (SSE)
this is server push technique by which we can fetch data in every changes made automatically and also after a certain time.
The problem has been solved.
I just add
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
Everytime that view load, it'll reread page and doesn't keep any cache.

Magento: Category Lock/Warning or T&C

I wonder if there is a way to add a Warning/Advisory or Terms & Conditions (preferably) to a category or a landing page to warn users about adult content. On the shop I'm working on there is an "Adult Section" Category for Erotic Toys, Lingerie, cosplay, etc. and I need to warn users about such content before they access the section in case they're less than 18.
I've searched the web and only found paid extensions which I cannot afford. Does anyone know how to do this?
I'm using Magento CE 1.7.
Thanks,
EDIT:
Ok, so I've been trying to figure out how to do this and I just figured that the best way to do it would be to just create a Category Landing Page and adding a java script for T&C redirect to the page I want it to.
This is the code I would use for the Category Landing Page with blank content would be this.
<?php $_categories = $this->getCurrentChildCategories() ?>
<?php $_collectionSize = $_categories->count() ?>
<div>
<?php $i=0; foreach ($_categories as $_category): ?>
<?php
$layer = Mage::getSingleton(‘catalog/layer’);
$layer->setCurrentCategory(Mage::getModel(‘catalog/category’)->load($_category->getId()));
$helper = Mage::helper(‘catalog/category’);
?>
Then I found a code snippet that would redirect the user to a page of my liking after clicking accept but I'm not sure how to implement it and/or if this is the best choice. Here's the code.
<form action="url-to-go-to" method="GET" onsubmit="return checkCheckBox(this)">
I accept: <input type="checkbox" value="0" name="agree">
<input type="submit" value="Continue">
<input type="button" value="Exit" onclick="document.location.href='BACKTOWHAT.html';">
</form>
<script type="text/javascript">
<!--
function checkCheckBox(f){
if (f.agree.checked == false )
{
alert("Please tick the box to continue");
return false;
} else
return true;
}
-->
</script>
Now I was thinking that it would be best to just create a simple CMS page and point the category on the top menu to that page and once they have agreed and clicked on continue, they could be taken to the actual category by simply pointing the 'onclick' to the URL of the actual category.
Not sure if this is the best way but it's the only way I could come up. The other way I thought of would've required me to take the "agreements" during checkout that already comes with magento and make an extension that would allow me to place it on any page and call the "Agreement ID" from the Sales/Terms and Conditions tab but I don't know how to actually do that, it was just a thought.
If anyone has a better solution, I'd be happy to hear it.
I would add some sort of JavaScript that shows a div over the top of the whole page, that will create a session cookie when you accept to watch the category. Otherwise, make a back() in the history navigation. This way you don't need another page, just JS.
On another note, could you please post the extensions you found that do this?

Resources