1 (edited by 2010-05-16 12:45:40)

Topic: [TUTORIAL][HACK] Saving additional data with my news.

Name: Saving additional data with my news.
Author: FUNimations
CuteNews Compatibility: 1.3.6 - * (no incompatibility reported yet)
Description: In this topic we'll discuss an alternative way to add new data other then the xfields which works great for adding stuff, but many people seem to have problems editing the stuff. This tutorial will mainly be about adding data to your news item.
Adding stuff to personal options or comments is a bit more difficult. This tutorial uses code from Cn 1.4.6. I'll explain how you do, not a copy and paste procedure. So for younger CN versions you will be able to use this tutorial.
Also be aware that this is for saving DATA and not (html) code or texts.
Instructions:

1) addnews.mdu
find

<td width=\"75\">
        Title
        <td width=\"575\" colspan=\"2\">
        <input type=text size=\"55\" name=\"title\" tabindex=1>
        </tr>


before the "; we'll add a new row for the new data. For example

<td width=\"75\">
        newdata
        <td width=\"575\" colspan=\"2\">
        <input type=text size=\"55\" name=\"newdata\">
        </tr>


of course you can use dropdowns here as well. But that's a hml related matter. There are many sites that give you html code for those web elements.
and next we'll have to save this new data.
so find

fwrite($news_file, "$added_time|$member_db[2]|$title|$short_story|$full_story|$manual_avatar|$nice_category||\n");


and add the new data like this

fwrite($news_file, "$added_time|$member_db[2]|$title|$short_story|$full_story|$manual_avatar|$nice_category|$newdata|\n");


notice how we add the NAME of the new input field with a $ in front of it.
And remember! $nice-category is slot #6 so your new data will start counting from there on forwards. $newdata being 7

To make the new data obligated find

$title       = replace_news("add", $title, TRUE, FALSE); // HTML in title is not allowed
if(trim($title) == "" or !$title){ msg("error","Error !!!","The title can not be blank.", "java script:history.go(-1)"); }


add under

$newdata       = replace_news("add",$newdata, TRUE, FALSE); // HTML in title is not allowed
if(trim($newdata) == "" or !$newdata){ msg("error","Error !!!","The newdata can not be blank.", "java script:history.go(-1)"); }


again ntice the $ in front of the name.

This is it. We have added a new data to news.tx

2) editnews.mdu
of course you'll also want to edit your new data so we'll need to add similar code to editnews.mdu
find

<tr>
        <td valign=middle width=\"75\" valign=\"top\">
        Title
        <td width=\"464\" colspan=\"3\">
        <input type=text name=title value=\"$item_db[2]\" size=55 tabindex=1>
    <td width=\"103\" valign=\"top\">
        </tr>

and we'll add a new row.

<tr>
        <td valign=middle width=\"75\" valign=\"top\">
        Title
        <td width=\"464\" colspan=\"3\">
        <input type=text name=newdata value=\"$item_db[7]\" size=55 tabindex=1>
    <td width=\"103\" valign=\"top\">
        </tr>

make sure you use the SAME name as addnews.mdu.
as value we give the 7th slot of $item_db. this number is the number i told you to remember earlier.
and next find

fwrite($new_db,"$old_db_arr[0]|$old_db_arr[1]|$title|$short_story|$full_story|$editavatar|$nice_category||\n");

and just like in addnews we'll add $newdata to this line.

3) open massactions.mdu and find

fwrite($new_db,"$old_db_arr[0]|$old_db_arr[1]|$old_db_arr[2]|$old_db_arr[3]|$old_db_arr[4]|$old_db_arr[5]|$nice_category|||\n");


foreach new data you added, ad a $old_db_arr[#] to the line just like you did for addnews and editnews. ($nice_category is slot 6!)

4) shows.inc.php
final step, let's create a tag for this new data so we may use this data in the templates.
find the following 2 lines

$output = str_replace("{title}", $news_arr[2], $template_full);
$output = str_replace("{title}", $news_arr[2], $output);

and add under

$output = str_replace("{newdata}", $news_arr[7], $output);


again notice how we use the 7 (that number you needed to remember)

5)
all that is left is to try your new field out http://cutephp.com/forum/style_emoticons/default/smile.gif