UtopiaSoftware Forums

Full Version: [1.3.0] News Illustrated
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
If you want to add a picture as an illustration of your article. Effect "ą la CNN" guaranteed. Big Grin

Database Tables edited:
- unp_news
- unp_settings

Files edited:
- news.php
- settings.php
- postnews.php
- editnews.php

Templates edited:
- news_newsbit

Access to unp_news table and add the SQL query:

Code:
ALTER TABLE `unp_news` ADD `picture` VARCHAR( 100 ) NOT NULL AFTER `subject` ;


Access to unp_setting table and add the SQL query:

Code:
INSERT INTO `unp_setting` VALUES (23, 21, 'URL to Image Directory', 'sitepics', '', 'The URL to the main folder containing the oploaded pictures for each article. <b>With</b> final slash (/). (Requires preceding http://)', 'text');
INSERT INTO `unp_setting` VALUES (24, 22, 'Image Alignment', 'alignpic', 'left', 'Whether the pictures will appear on the left or on the right of the text.', 'text');


Open news.php and find the while loop in "Process News - Standard" with the values:

PHP Code:
    while ($news $DB->fetch_array($getnews))
    {
        
$newsid $news['newsid'];
        
$subject $news['subject'];
        
$newstext $news['news'];
        
$poster $news['poster'];
        
$posterid $news['posterid'];
        
$date $news['date'];
        
$postdate unp_date($dateformat$date);
        
$posttime unp_date($timeformat$date);
        
$avatar unp_checkAvatar($posterid);
        ...
    } 

Add this value among them:

PHP Code:
$picture $news['picture']; 


Open settings.php and find the 22 values in "Process Settings Submission" and add this at the end of it:

PHP Code:
$value23 addslashes($_POST['23']);
$value24 addslashes($_POST['24']); 


then add this at the end of "UPDATE SETTINGS QUERIES":

PHP Code:
$DB->query("UPDATE `unp_setting` SET value='$value23' WHERE id='23'");
$DB->query("UPDATE `unp_setting` SET value='$value24' WHERE id='24'"); 


Open postnews.php and find in "Process News Submission":

PHP Code:
if ($action == '')
{
    if (isset(
$_POST['submitnews']))
    {
        
$subject addslashes(trim($_POST['subject']));
        
$news addslashes(trim($_POST['news']));
        
$posttime time();
        
$newsposter $USER['username'];
        
$newsposterid $USER['userid'];
...

Add this to those values:

PHP Code:
$picture addslashes(trim($_POST['picture'])); 


then find the following query:

PHP Code:
$submitnews $DB->query("INSERT INTO `unp_news` (`date`, `subject`, 
`news`, `posterid`, `poster`) VALUES ('$posttime','$subject','$news','$newsposterid','$newsposter')"
); 


change it into:

PHP Code:
$submitnews $DB->query("INSERT INTO `unp_news` (`date`, `subject`, 
`picture`, `news`, `posterid`,`poster`) VALUES ('$posttime','$subject','$picture','$news','$newsposterid','$newsposter')"
); 


then find the html table in "Process Post News Page Content" and add the row between the Subject and News fields:

Code:
    <tr>
        <td width="15%"><strong>Picture:</strong></td>
        <td width="85%"><input type="text" size="35" tabindex="2" maxlength="100" name="picture" /></td>
    </tr>


Open editnews.php and find in "Process News Edit Query":

PHP Code:
// make shorter vars
$subject $_POST['subject'];
$news $_POST['news']; 

add this value:

PHP Code:
$picture $_POST['picture']; 


then find in "Edit News":

PHP Code:
// make shorter vars
$newsid $newsarray['newsid'];
$subject $newsarray['subject'];
$date $newsarray['date'];
$news $newsarray['news']; 

add this value:

PHP Code:
$picture $newsarray['picture']; 


then in the html table following add this row between the Subject and News fields:

Code:
<tr>
    <td width="15%"><strong>Picture:</strong></td>
    <td width="15%"><input type="text" name="picture" maxlength="100" size="35" tabindex="'.newsid.'2" value="'.htmlspecialchars($picture).'" /></td>
</tr>


Now go to your UNP templates page and edit the template news_newsbit. Between {$useravatar} and {$newstext}, add this:

Code:
<img src="{$sitepics}{$picture}" align="{$alignpic}" style="margin: 0 5px 5px; border: 1px solid #000" />


Be sure now to:

  • create the default image directory,
  • upload the pictures needed,
  • have avatars NOT allowed, (what a mess it could make)
  • modify in your UNP settings the URL to the default image directory,
  • edit your old posts, writing the name of the picture in the Picture Field

Voilą! Doesn't that look nice?

* If you have any suggestions for a direct upload of the picture file... please, let me know.
This is really cool, thanks for the hack.
Possibly have a screenshot of the end result?
Hi

it was excellent , but I can not edit news picture in edit news part in admin panel .it does not change .what`s the problem ?
for example when i remove '.htmlspecialchars(fa.gif).' and type fa2.gif it doesn`t change .
or when i remove '.htmlspecialchars(fa.gif).' and type '.htmlspecialchars(fa2.gif).' and submit changes it does not change .
You need to modify editnews.php:

PHP Code:
$DB->query("UPDATE `unp_news` SET subject='$subject',news='$news' WHERE newsid=$newsid"); 

to

PHP Code:
$DB->query("UPDATE `unp_news` SET subject='$subject',picture='$picture',news='$news' WHERE newsid=$newsid"); 

Indeed, this is a cool hack but there is one little problem.... if you decide NOT to insert an image in a news, you get the MISSING IMAGE icon since it tries to look for an image that does not exist.. is there a workaround for this problem ??
After a year of silence, let me bring up again the subject and suggest some solutions to the question raised. First of all, thanks to batu for giving some answers.

Now, what if you decide NOT to add a picture and not have the MISSING IMAGE problem, here is the solution:

1. do you remember how we added the line to insert the picture?

Quote:
Open postnews.php and find in "Process News Submission":

PHP Code:

if ($action == '')
{
if (isset($_POST['submitnews']))
{
$subject = addslashes(trim($_POST['subject']));
$news = addslashes(trim($_POST['news']));
$posttime = time();
$newsposter = $USER['username'];
$newsposterid = $USER['userid'];
...
}


Instead of adding "$picture = ..." add:

PHP Code:
if ($picture == '')
{
     
$picture 'empty.gif';
}
else
{
     
$picture addslashes(trim($_POST['picture'])); 


* Of course, don't forget to create and upload your 1x1-sized "empty.gif" !

2. Then in news.php and the while loop in "Process News - Standard", add the lines:

PHP Code:
if ($picture == "empty.gif")
{
     
$alt "\" style=\"height: 1px; width: 1px; border: none; margin: 0;";
}
else
{
     
$alt $subject;


3. Finally, go back to your UNP templates page and edit the template news_newsbit. So far, you have this line:

Code:
<img src="{$sitepics}{$picture}" align="{$alignpic}" style="margin: 0 5px 5px; border: 1px solid #000" />


Erase all the "style" property and write instead this:

Code:
alt="{$alt}"


here is the result of those changes:
Article with a picture: http://praisedesign.com/article_with.jpg
Article without a picture: http://praisedesign.com/article_without.jpg


ok, now let me look at this interesting UNP 1.4.0.... he he he

Ciao!

Reference URL's