Simple Pie "set_item_limit" doesn't - simplepie

I'm struggling to get set_item_limit to work. The feed comes in fine, but just renders every post. Here's the code I'm using:
// Make sure SimplePie is included. You may need to change this to match the location of autoloader.php
// For 1.0-1.2:
#require_once('../simplepie.inc');
// For 1.3+:
require_once('php/autoloader.php');
// process this feed with all of the default options.
$feed = new SimplePie();
// Set which feed to process. http://simplepie.org/blog/feed/
$feed->set_feed_url('https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=Tweet_Yourself');
// Run SimplePie.
$feed->set_item_limit(5);
$feed->init();
// This makes sure that the content is sent to the browser as text/html and the UTF-8 character set (since we didn't change it).
$feed->handle_content_type();
And here's the HTMLy bit:
<?php
//loop through all of the items in the feed, and $item represents the current item in the loop.
foreach ($feed->get_items() as $item): ?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100" align="left"><img src="sitewise/Tweet_Yourself_avatar.gif" alt="TweetYourself Twitter Feed" /></td>
<td>
<div class="item">
<h3><i><?php echo $item->get_title(); ?></i></h3>
<?php echo $item->get_description(); ?>
<p><small>Posted on <?php echo $item->get_date('j F Y | g:i a'); ?></small></p>
<hr />
</div>
</td>
</tr>
</table>
<?php endforeach; ?>
The table isn't the issue!
Any ideas?

The issue is
$feed->set_item_limit(5);
Is for merging feeds and not for a single feed.... you need to
change
foreach ($feed->get_items() as $item): ?>
to
foreach ($feed->get_items(0, 5) as $item): ?>
This would limit it to 5 items
SimplePIE Get_ITEMS

Related

Php 7 error for a simple form getting Object of class mysqli could not be converted to int

The code gets error saying Object of class mysqli could not be converted to int. When i try to load the page i get this error,i checked other questions but it was not helpful
<?php
$conn = mysqli_connect("localhost", "root", "", "coinlion");
if ($conn == 0) {
echo "could not connect";
} else {
mysqli_select_db("coinlion");
echo "connected";
}
?>
<form method="post">
<style>
#newlink {
width: 600px
}
</style>
<div id="newlink">
<div>
<table border=0>
<tr>
<td> Link URL:</td>
<td><input type="text" name="linkurl" value="" required></td>
</tr>
<tr>
<td> Link Description:</td>
<td><textarea name="linkdesc" cols="50" rows="5" required></textarea>
</td>
</tr>
</table>
</div>
</div>
<p>
<br>
<input type="submit" name="submit1">
<input type="reset" name="reset1">
</p>
php code
<?php
if (isset($_POST['submit1'])) {
$linkurl = $_POST['linkurl'];
$linkdesc = $_POST['linkdesc'];
mysqli_query($conn, "insert into
test(linkurl,linkdesc)values('$_POST[linkurl]','$_POST[linkdesc]')");
echo "data inserted";
}
?>
Well the issue was with the line if($conn==0) ,This value was taken as an integer so the error occured and an Connection variable to Mysqli_select_db was missing , after fixing it , the code ran successfully

PDO gather BLOB files

I'm trying to find a way to output whatever BLOB files are inserted into a silly database. In my code when I query the CV column I get all sorts of weird symbols. Can you guys please help me fix my code?
$crud->dataview($query);
}else{
$query = "SELECT id, from_unixtime(cheie_wp) as `datetime`, nume, prenume, email, telefon, oras, denumiri_job, cv FROM jobselection_data_old ORDER BY id DESC";
$records_per_page=10;
$newquery = $crud->paging($query,$records_per_page);
$crud->dataview($newquery);
public function dataview($query)
{
$stmt = $this->db->prepare($query);
$stmt->execute();
if($stmt->rowCount()>0)
{
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
$date_in = $row['datetime'];
$date_out = explode(' ', $date_in);
?>
<tr>
<td><?php echo $date_out[0]; ?></td>
<td><?php print($row['nume']); ?></td>
<td><?php print($row['prenume']); ?></td>
<td><?php print($row['email']); ?></td>
<td><?php print($row['telefon']); ?></td>
<td><?php print($row['oras']); ?></td>
<td><?php print($row['denumiri_job']); ?></td>
<td align="center"><?php
if($row['cv'] != NULL) { ?>
view
<?php }else{
echo '-';
}
?></td>
<td align="center">
<i class="glyphicon glyphicon-edit"></i>
</td>
<td align="center">
<i class="glyphicon glyphicon-remove-circle"></i>
</td>
</tr>
<?php
}
}else{ ... }
}
EDIT
I have modified my code and added view.php with this code:
if(isset($_GET['id']))
{
$stmt = $DB_con->prepare("SELECT cv FROM jobselection_data_old WHERE id=:id");
$stmt->execute(array(":id"=>$_GET['id']));
$stmt->bindColumn(1, $lob, PDO::PARAM_LOB);
$stmt->fetch(PDO::FETCH_BOUND);
header('content-type: image/jpeg');
echo $lob;
}
?>
The problem is that it does not generate the image file I have uploaded to the database.
You can check it at https://ns.jobselection.ro/db/
user/pass: test
I added a screen capture of my database as well: https://ns.jobselection.ro/db/screen.png . I only added one row for testing purposes!
Wow, this is really weird. I found what the issue was. I had my require configuration files in a separate php block of code in the same file. Until I placed them both in the same block of code it did not work!

Prestashop 1.5.6 - Add a custom field in Admin Product Page

I have been trying to introduce a new custom field in Admin Product page but got a weird error. Actually this field has the same text area type as the existing ones. If I enter a plain text, it works fine but if I enter anything starts with an opening angle bracket (<) it gives me a 403 forbidden error. I already checked permission of folders and files.
This is what I have done.
New db field
ProductCore class. Made changes wherever 'description' is referenced because they are pretty much the same thing.
Information.tpl modified to display this new field.
This is how Admin Product page looks like after the change. As you can see, a plain text can be saved without any issue.
If I type in any html tag, which starts with an angle bracket, then save, I get a 403 error, whereas an existing textarea such as Description in the screen is totally fine.
I have checked permission of files and folders and error logs but couldn't find any clue. Anyone got an idea? Please help!
information.tpl
<tr>
<td class="col-left">
{include file="controllers/products/multishop/checkbox.tpl" field="description" type="tinymce" multilang="true"}
<label>{l s='Description:'}<br /></label>
<p class="product_description">({l s='Appears in the body of the product page'})</p>
</td>
<td style="padding-bottom:5px;">
{include file="controllers/products/textarea_lang.tpl" languages=$languages
input_name='description'
input_value=$product->description
}
<p class="clear"></p>
</td>
</tr>
<tr>
<td class="col-left">
{include file="controllers/products/multishop/checkbox.tpl" field="alternate_item" type="tinymce" multilang="true"}
<label>{l s='Alternate Item:'}<br /></label>
</td>
<td style="padding-bottom:5px;">
{include file="controllers/products/textarea_lang.tpl"
languages=$languages
input_name='alternate_item'
input_value=$product->alternate_item}
<p class="clear"></p>
</td>
</tr>
textarea_lang.tpl
<div class="translatable">
{foreach from=$languages item=language}
<div class="lang_{$language.id_lang}" style="{if !$language.is_default}display:none;{/if}float: left;">
<textarea cols="100" rows="10" id="{$input_name}_{$language.id_lang}"
name="{$input_name}_{$language.id_lang}"
class="autoload_rte" >{if isset($input_value[$language.id_lang])}{$input_value[$language.id_lang]|htmlentitiesUTF8}{/if}</textarea>
<span class="counter" max="{if isset($max)}{$max}{else}none{/if}"></span>
<span class="hint">{$hint|default:''}<span class="hint-pointer"> </span></span>
</div>
{/foreach}
</div>
<script type="text/javascript">
var iso = '{$iso_tiny_mce}';
var pathCSS = '{$smarty.const._THEME_CSS_DIR_}';
var ad = '{$ad}';
</script>
You must override the ProductCore class NOT modify ProductCore class
class Product extends ProductCore
{
public $alternate_item;
public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
{
self::$definition['fields']['alternate_item'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml');
parent::__construct($id_product, $full, $id_lang, $id_shop, $context);
}
}
The override class must be placed in override/classes folder or yourmodule/override/classes
When you override a class you must delete cache/class_index.php

how to get name based on id from DB table in yii framework

i am developing web application by using yii framework, i have one table called "userprofile" in my database. i have tried to export userprofile data to excel file, everything is working fine this is my userprofile table fields
user profile table
id username password studentname classid parentname email
1. xxxxx asdf yyyyy 2 pqrs xy#gmail.com
classname table
classid classname
1. xxxxx
2. yyyyy
3. zzzzz
In my controller i have one function called actionExcelexport() and it has
$content = $this->renderPartial("excel",array("model"=>Puserprofile::model()->findAll()),true);
In above line i am calling one excel file called excel and this is my excel.php
<table>
<tr>
<td style="background-color: #555;color:#fff">User Name</td>
<td style="background-color: #555;color:#fff">Student Name</td>
<td style="background-color: #555;color:#fff">ClassID</td>
<td style="background-color: #555;color:#fff">Parent Name</td>
<td style="background-color: #555;color:#fff">Email</td>
</tr>
<?php foreach($model as $data):?>
<tr>
<td> <?php echo $data->username ?> </td>
<td> <?php echo $data->studentname ?> </td>
<td> <?php echo $data->classid ?> </td>
<td> <?php echo $data->parentname ?> </td>
<td> <?php echo $data->email ?> </td>
</tr>
<?php endforeach; ?>
</table>
my reqirement:-
In my excel file i want to get classname instead of classid for example if my classs id is '2', classname 'yyyy' should get in excel file how to retrive classname based on classid could you please help me
i got solution for my problem
In my excel.php, instead of this line
classid ?>
i changed
class->classname?>
class->classname = my userprofile model has relation function and it has some relation because i am using foreign key for my table so i am taking this 'class' from my model and this is ('classname') my database field name

Form validation with Struts 2 + Dojo framework

I'm new on Dojo, and I'm trying to validate a form (like the last one of this example : http://dojotoolkit.org/documentation/tutorials/1.6/validation/), using Struts2 tags, but I can't.
With a "classic" HTML form (tags , ....) everything is fine, but with Struts 2 tags (), the "required" validation don't work ...
Here is my code :
<script type="text/javascript">
dojo.require('dojox.validate');
dojo.require('dojox.validate.us');
dojo.require('dojox.validate.web');
/* basic dijit classes */
dojo.require('dijit.form.CheckBox');
dojo.require('dijit.form.Textarea');
dojo.require('dijit.form.FilteringSelect');
dojo.require('dijit.form.TextBox');
dojo.require('dijit.form.ValidationTextBox');
dojo.require('dijit.form.DateTextBox');
dojo.require('dijit.form.TimeTextBox');
dojo.require('dijit.form.Button');
dojo.require('dijit.form.RadioButton');
dojo.require('dijit.form.Form');
dojo.require('dijit.form.DateTextBox');
/* basic dojox classes */
dojo.require('dojox.form.BusyButton');
dojo.require('dojox.form.CheckedMultiSelect');
</script>
<s:form dojoType="dijit.form.Form" method="post" id="toto"
theme="simple">
<script type="dojo/method" event="onSubmit">
if(this.validate()) {
return confirm('Form is valid, press OK to submit');
} else {
alert('Formulaire invalide');
return false;
}
return true;
</script>
<table cellpadding="0" cellspacing="2">
<tr>
<td valign="top"><strong>First Name*: </strong></td>
<td>
<s:textfield
name="email"
id="email"
placeholder="Your email"
dojoType="dijit.form.ValidationTextBox"
required="true"
missingMessage="Obligatoire !" />
</td>
</tr>
</table>
<s:submit
value="Submit Form"
label="Submit Form"
id="submitButton"
dojoType="dijit.form.Button"/>
</s:form>
How can I check that my fields are not empty with struts tags please ?
Thank you all
You need to check to make sure that what you're rendering is what Dojo expects. I don't know how the current Dojo validation works, but:
The "required" attribute is an attribute of <s:textfield>, it's likely not being rendered, thus not available to Dojo--if that's what Dojo uses to determine if a field is required.