Name: Saving additional data with comments.
Author: Rokker93
CuteNews Compatibility: 1.3.6 - * (no incompatibility reported yet)
Description: This topic will explain how to add new fields to comments, so your users can add more information, It is alittle long and rather complex for what It Is, but It will work on newer and older versions of CN.

Instructions:
Now before we start, do understand that this is a TUTORIAL. So don't just go copy and past everything. Please do try and understand what you're doing.

1) shows.inc.php find

        $name = trim($name);

Add under it

        $NAME = trim($NAME);

Replacing NAME, with a word related to the information you're storing, no spaces or special characters please.
$NAME will be used later on awell. So the samse change should be made to those aswell.

2) Find

             <input type=\"hidden\" name=\"ucat\" value=\"$ucat\" />

Underneath add:

             <input type=\"hidden\" name=\"NAME\" value=\"$NAME\" />

Replacing NAME, with a word chosen In step 1.

3) [This stops the field being blank. If you don't want this, then skip to step 4]
Find

    if($name == " " or $name == ""){
            echo("<div style=\"text-align: center;\">You must enter name.
[url=]go back[/url]</div>");
                $CN_HALT = TRUE;
                break 1;
        }

and add underneath

    if($NAME == " " or $NAME == ""){
            echo("<div style=\"text-align: center;\">You must fill In all the fields!.
[url=]go back[/url]</div>");
                $CN_HALT = TRUE;
                break 1;
        }

Again, replacing NAME with the word used in step 1! You may also change the message.

4) Next find

    if($mail == " " or $mail == ""){ $mail = "none"; }

Underneath add:

    if($NAME == " " or $NAME == ""){ $NAME = "none"; }

5) Find:

        fwrite($new_comments, "$old_comments_arr[0]|>|$old_comments_arr[1]$time|$name|$mail|$ip|$comments||\n");


And add |$NAME after $comments, so It would look like

        fwrite($new_comments, "$old_comments_arr[0]|>|$old_comments_arr[1]$time|$name|$mail|$ip|$comments|$NAME||\n");

Again, replacing NAME with the word used in step 1!
And make sure that at the end of the string there are 2 | as you see demonstrated in the 2 above codes and the code below. Else CN will have trouble splitting the information in seperate comments and will consider it as 1 comment.

If you're adding more then one field to comments, then just keep adding the variable name, as you did with $NAME, eg.

fwrite($new_comments, "$old_comments_arr[0]|>|$old_comments_arr[1]$time|$name|$mail|$ip|$comments|$new_var1|$new_var2|$etc||\n");

6) We have validated and saved the information, now we just need to add a input field for the people !
In your comments template (so please do use the template editor in your CN panel, and don't edit the tpl files), add

<input type="text" name="NAME" value="Enter Text.." />

Replacing NAME again.
Ofcourse you're not obligate to use this. You can just aswell make a dropdownbox, or use checkboxes. As long as you won't forget to add the 'name' attribute.

7) Now lets show the people what we have stored!
In shows.inc.php still, find

$output = str_replace("{comment}", "<a name=\"".$comment_arr[0]."\"></a>$comment_arr[4]",$output);


And add underneath:

if($comment_arr[5] != "none"){ $output = str_replace("{NAME}",  $comment_arr[5], $output); }
else { $output = str_replace("{NAME}", '', $output); }


If you are adding two fields, have one line with $comment_arr[5] and one with $comment_arr[6] etc.
So each time you add a new data to your comments, a new slot for that data will be added to comments.txt
The number will tell CN for which slot you want to get the data and replace the tag with that data.
Replacing NAME again.

// HOW TO EDIT COMMENTS.

Open inc/editcomments.mdu
Find:

    <tr>
    <td height=20 valign=middle valign=\"top\" width=\"102\" bgcolor=\"#F9F8F7\">
    IP
    <td height=20 valign=middle width=\"1002\" bgcolor=\"#F9F8F7\">
    [url=]$single_arr[3][/url]   
    [url=][ban this ip][/url]
    </tr>


Add underneath:

    <tr>
    <td height=20 valign=middle valign=\"top\" width=\"102\">
    NAME
    <td height=20 valign=middle width=\"1002\" bgcolor=\"#F9F8F7\">
    <input type="text" name="NAME" value=$single_arr[5]" /></a>
    </tr>


Replacing NAME again and use the correct slot number.

Now find:

fwrite($new_com,"$comment_arr[0]|$poster|$mail|$comment_arr[3]|$comment||");

And same as before, add |$NAME after $comment

fwrite($new_com,"$comment_arr[0]|$poster|$mail|$comment_arr[3]|$comment|$NAME||");

This is basics on how to add fields to comments, you can do this as many times as you want, just follow the same idea.

You can install a captcha yourself rather then deleteing the spam o.O
Look in the Problem Solving / Help & Support

Unfortunatly cutenews will never have those. And never be perfect, as no on works on it anymore.

Shame.

I've edited my first post to use a popup https://cutephp.com/forum/style_emoticons/default/smile.gif and added some other features.
Hope you like.

Name: Edit/delete news link
Author: rokker93
CuteNews Compatibility: 1.3.6 - * (no incompatibility reported yet)
Description: Add's a button/link on your site which allows you to go to the editnews page if you're logged in CuteNews from your site.
Instructions:
before we start keep in mind that the forum sometimes splits the word java script. This must be 1 word!!

Open index.php and look for

                else{
                   setcookie("username", $username);
                   setcookie("md5_password", $cmd5_password);
                }
        }

And add under

if($member_db[1] == "1"){ setcookie("userlevel", "loggedin", time()+3600, "/", ".yoursite.com"); }
else { }

Please replace yoursite.com with your site's url. No www or http. Eg .cutephp.com

Now search for

$config_check_referer = TRUE; // Set to TRUE for more seciruty


Change TRUE to FALSE ( Dont worry, its not that major security issue )

Now open shows.inc.php and search for

else{ $output = str_replace("{category-icon}", "", $output); }

Below that add

if($_COOKIE["userlevel"] == "loggedin"){ 
$output = str_replace("[a-edit]", "[url= onclick=\]", $output); 
$output = str_replace("[/a-edit]", "[/url]", $output); 
$output = str_replace("[a-delete]", "<a onClick=\"java script:confirmdeletenews('$news_arr[0]'); return(false)\" href=\"#\">", $output); 
$output = str_replace("[/a-delete]", "</a>", $output); 
} else { 
$output = str_replace("[a-edit]", "<!- ", $output); 
$output = str_replace("[/a-edit]", " ->", $output); 
$output = str_replace("[a-delete]", "<!- ", $output); 
$output = str_replace("[/a-delete]", " ->", $output); 
}

Now find the same line again, but further down below that add

if($_COOKIE["userlevel"] == "loggedin"){ 
$output = str_replace("[a-edit]", "[url= onclick=\]", $output); 
$output = str_replace("[/a-edit]", "[/url]", $output); 
$output = str_replace("[a-delete]", "<a onClick=\"java script:confirmdeletenews('$news_arr[0]'); return(false)\" href=\"#\">", $output); 
$output = str_replace("[/a-delete]", "</a>", $output); 
} else { 
$output = str_replace("[a-edit]", "<!- ", $output); 
$output = str_replace("[/a-edit]", " ->", $output); 
$output = str_replace("[a-delete]", "<! - ", $output); 
$output = str_replace("[/a-delete]", " ->", $output); 
}

Now open show_news.php and after the first <?PHP add

echo"<script language=\"javascript\"> 
        function confirmdeletenews(id){
        var agree=confirm(\"Are you sure you want to delete this news?\");
        if (agree)
        location.href=('index.php?mod=editnews&action=doeditnews&goto=back&source=&ifdelete=yes&id='+id);return false;
        }
</script>";

Now open editnews.mdu and search for

if($okdeleted and $okdelcom){ msg("info","News Deleted","The news item successfully was deleted.
If there were comments for this article they are also deleted."); }

Replace with

if($okdeleted and $okdelcom and $_GET[goto] == "back"){ echo"<script Language=\"JavaScript\">location.href=('$_SERVER[HTTP_REFERER]');</script>"; }
elseif($okdeleted and $okdelcom){ msg("info","News Deleted","The news item successfully was deleted.
If there were comments for this article they are also deleted."); }

// Extra's. Not needed but go with the mod
Open options.inc.mdu and search for

{category}

    {category-icon}

Replace with

{category}

    {category-icon}

[a-edit] & [/a-edit]

[a-delete] & [/a-delete]


Find

   - Shows the category icon (if any)

Replace with

    - Shows the category icon (if any)

    - Shows an edit link on news when logged in as admin

    - Shows an delete link on news when logged in as admin

Credits:
Jaybuz - For being a pain and asking for this.

Posts found: 5

Pages 1

CutePHP Forums → Posts by rokker93