Please login or register.

Login with username, password and session length
Advanced search  

News:

You need/want an older version of sNews ? Download an older/unsupported version here.

Author Topic: Add Author's name to Articles & Pages  (Read 721 times)

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Add Author's name to Articles & Pages
« on: March 28, 2012, 03:05:04 PM »

Applies to: Single user versions of sNews 1.6

In answer to a request:

This mod allows you to enter the name of the author for an article or page when creating a new, or editing an existing, article or page. A new text field is added to the New & Edit Article and Page panels, above the content Editor textarea. The author's name is saved to the articles table in the database.

NOTE: These same steps would generally apply in order to add any other editable data to the articles table and retrieve it for display purposes within an article or page.

Step One:
To add the author value to your articles table, run the following SQL query on your existing database from phpMyAdmin:
Code: [Select]
ALTER TABLE `articles`
ADD (`author` varchar(100) default NULL );


Step Two: Changes to snews.php

In // ARTICLES FORM  function:

1)  Search for:
Code: [Select]
$frm_sef_title = $_SESSION['temp']['seftitle'] ? cleanSEF($_SESSION['temp']['seftitle']) : $r['seftitle'];

... and below it, paste in:
Code: [Select]
$frm_author = $_SESSION['temp']['author'] ? $_SESSION['temp']['author'] : $r['author']; // author mod

2)  Search for: $frm_submit = l('submit'); and insert under it:
Code: [Select]
$frm_author = $_SESSION['temp']['author']; // author mod

3)  Search for: echo html_input('textarea', 'text', 'txt', and insert above it to make the Author text field in the New & Edit Article and Page panels:
Code: [Select]
echo html_input('text', 'author', 'auth', $frm_author, 'Author', '', '', '', '', '', '', '', '', '', '');

In function processing()

1) Search for $seftitle = $_POST['seftitle']; and paste under it:
Code: [Select]
$author = $_POST['author']; // author mod

2) Search for case(isset($_POST['add_article'])): and replace the query string with this one to save the author value when creating a new article or page:
Code: [Select]
mysql_query("INSERT INTO ".db('prefix')."articles(title, seftitle, text, date, category, position, displaytitle, displayinfo, commentable, published, description_meta, keywords_meta, author) VALUES('$title', '$seftitle', '$text', '$date', '$category', '$position', '$display_title', '$display_info', '$commentable', '$publish_article', '$description_meta', '$keywords_meta', '$author')");

3) And four lines below that, replace the query string with this one to save the author value when editing and article or page:
Code: [Select]
mysql_query("UPDATE ".db('prefix')."articles SET title='$title', seftitle = '$seftitle', text = '$text',".$future." category = '$category', position = '$position', displaytitle = '$display_title', displayinfo = '$display_info', commentable = '$commentable', published = '$publish_article', description_meta = '$description_meta', keywords_meta = '$keywords_meta', author = '$author' WHERE id = '$id' LIMIT 1;");


In function center():

1) Search for $title = $r['title']; and under it paste in the following to get the author value for display:
Code: [Select]
$author = $r['author']; // author mod

2) And, three lines below it, under the line that starts with echo '<h2>'.(strlen($text) > paste in (before the closing bracket) to display the author name just under the article or page title:
Code: [Select]
        if (!empty($author) && $author != 'null') { echo 'By: '.$author.''; }
« Last Edit: April 16, 2012, 06:21:36 AM by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

adminphp

  • Full Member
  • ***
  • Karma: 4
  • Posts: 150
  • you must be a great snewser .
Re: Add Author's name to Articles & Pages
« Reply #1 on: March 28, 2012, 06:48:46 PM »

thanks all appreciate your help keyrock really , thanks again. and + karma for you.
the mod works great.
Logged
“Fifty years of programming language research, and we end up with C++?”

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: Add Author's name to Articles & Pages
« Reply #2 on: March 28, 2012, 07:42:26 PM »

Good to see that it was useful. Thanks for the K+.  8)
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

adminphp

  • Full Member
  • ***
  • Karma: 4
  • Posts: 150
  • you must be a great snewser .
Re: Add Author's name to Articles & Pages
« Reply #3 on: April 03, 2012, 07:49:15 AM »

 ??? ???
« Last Edit: April 15, 2012, 10:26:29 PM by adminphp »
Logged
“Fifty years of programming language research, and we end up with C++?”

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: Add Author's name to Articles & Pages
« Reply #4 on: April 03, 2012, 09:29:40 PM »

I really want to display author's name inside of article's text at the first line of it.

That would be nice, eh? Unfortunately, you cannot do this.  ;D

As you will notice in your snews.php file, the string is now located just below the string that generates the article title, and before the closing } curly-bracket for the IF string (above it) that checks if the title should be displayed.

The string below the closing } curly-bracket is:
   file_include(str_replace('[break]', '', $text), $shorten);
... This is the function-tag for the //FILE INCLUSION function (much further down in snews.php) which decides how the text of the article will be generated... in full-text or shortened with a "read more" link.

When you write an article and save it to the articles table, the text of the first sentence is always started with an opening <p> tag. It is included in the text in the articles table. So, that starts the first sentence as a new paragraph AFTER the author's name.

To get the author's name in-line at the start of the first paragraph, we would need to manually type the author's name within the first sentence in the article textarea itself. There is no other way to get it after the opening <p> tag.

So... you would start typing your article's first sentence with: By phpadmin - followed by the first sentence, so that both are in the first paragraph of the article.

Of course, if you did that, then you would not need this modification at all.  If you want to keep using this modification, then you will have to live with where the author's name is now displayed. 8)
« Last Edit: April 03, 2012, 09:34:37 PM by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

adminphp

  • Full Member
  • ***
  • Karma: 4
  • Posts: 150
  • you must be a great snewser .
Re: Add Author's name to Articles & Pages
« Reply #5 on: April 04, 2012, 12:04:54 AM »

uh !!  these little problems ; It gave me a headache, you understood me correctly what I Was needing for.

Quote
key says: There is no other way to get it after the opening <p> tag.
What about creating a function and put a button in administration form (new_article); and this function would include 'author's name'.
And whenever i want to display the author's name, I just have to click on the button, and include some thing for instance;  echo() function or  [func] [/func], which could make  call to db table of autho's name.

With this way, we could have the author's name within <p> tag, right key? hhh.
« Last Edit: April 04, 2012, 02:11:30 AM by adminphp »
Logged
“Fifty years of programming language research, and we end up with C++?”

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: Add Author's name to Articles & Pages
« Reply #6 on: April 04, 2012, 02:24:53 AM »

Well, I think this would just complicate things more than we need.
Preferably, we want to keep the mod script within the function we are already working in... so we don't have to make another query to the articles table.

I do not know what the best way to go would be to get it inside the first paragraph.
« Last Edit: April 04, 2012, 03:00:12 PM by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

adminphp

  • Full Member
  • ***
  • Karma: 4
  • Posts: 150
  • you must be a great snewser .
Re: Add Author's name to Articles & Pages
« Reply #7 on: April 04, 2012, 05:49:46 AM »

OK doug, your advices seems  helpful, i'll adapt with what I have in this time (author's name before <p> tag).
Logged
“Fifty years of programming language research, and we end up with C++?”

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: Add Author's name to Articles & Pages
« Reply #8 on: April 04, 2012, 03:54:01 PM »

OK - I have figured out a solution that will do what you want.

1)   In your style.css (or main stylesheet) file, add this to make the author name stay in-line. You can re-style this later, important part is display: inline;
      .author { float: left; display: inline; color: red; }

2)  In your snews.php file... go back to that string: if (!empty($author) && $author != 'null') { echo 'By: '.$author.''; } ... and comment it out or delete it.

3) Find this below the curly-bracket (that was under the string):
      file_include(str_replace('[break]', '', $text), $shorten);

... and replace it with this new section:
Code: [Select]
<?php // DO NOT COPY

// author mod starts here -----------------
if (!empty($author) && $author != 'null') {
    $add_author '<span class="author">By: '.$author.' -&nbsp;</span>';
}
file_include(str_replace('[break]'''$add_author.$text), $shorten);
// end of author mod ----------------------

// DO NOT COPY 
?>


Now... instead of just generating the author name with echo 'By: '.$author.''; as we did in the string we deleted, we are now defining the author name with $add_author = '<span class="author">By: '.$author.' -&nbsp;</span>';

This allows us to add some styling to it with the span-tags, and then add $add_author to the file_include string right beside $text ... so that the author's name comes just before the start of the text for the first paragraph.
« Last Edit: April 04, 2012, 04:00:13 PM by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

adminphp

  • Full Member
  • ***
  • Karma: 4
  • Posts: 150
  • you must be a great snewser .
Re: Add Author's name to Articles & Pages
« Reply #9 on: April 04, 2012, 10:58:10 PM »

OK doug, your advices seems  helpful, i'll adapt with what I have in this time (author's name before <p> tag).
cheer up; the mod  seem to work very smoothly, big salutation for you keyrocks. and I assist to give you more karmas. +one.
BUT;
some thing wrong in it; I wrote one author's name for a specific article and automatically that name shows in all articles.
where is the problem.
did you change anything that didn't got if empty show null.

Quote
doug said: Unfortunately, you cannot do this.
uh  ;D but you were abled to do that and you did.
and thanks to all memebers in this forum.
« Last Edit: April 04, 2012, 11:16:33 PM by adminphp »
Logged
“Fifty years of programming language research, and we end up with C++?”

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: Add Author's name to Articles & Pages
« Reply #10 on: April 05, 2012, 02:54:43 AM »

cheer up; the mod  seem to work very smoothly, big salutation for you keyrocks. and I assist to give you more karmas. +one.
BUT;
some thing wrong in it; I wrote one author's name for a specific article and automatically that name shows in all articles.
where is the problem. did you change anything that didn't got if empty show null.

No, I didn't change the 2 conditional checks. It is working OK on my test install of sNews 16 with no other mods. I have many articles, 3 each with a different author and the others with no author... and I have no problem... they display what the should and nothing if no author entered.

Quote
doug said: Unfortunately, you cannot do this.
uh  ;D but you were abled to do that and you did. and thanks to all memebers in this forum.

Well, I was thinking about a way of doing this when I went to sleep last night and the solution I used came to me when I woke up this morning... so I gave it a try and was happy to find that it worked. Sometimes sleeping on a problem comes up with a solution.  8)

Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

adminphp

  • Full Member
  • ***
  • Karma: 4
  • Posts: 150
  • you must be a great snewser .
Re: Add Author's name to Articles & Pages
« Reply #11 on: April 05, 2012, 03:40:48 AM »

hmm.
The problem which  i am facing it now, is not in all articles (sorry for what i wrote below)  ;D, but in all articles that come after the article which I had added the author's name to it.

for instance if i put author's name for some article which is in the middle of other articles, then it shows in all articles that come after it, but if i check page 2 or 3 of the category or index i find it normal.
So i thought there is a problem of ending this mod.
like what we get when we put this tag in articles;
Code: [Select]
<font face="arial">and we forget to put at the end, this :
Code: [Select]
</font>the article and the comments on it will have arial font.. the same problem I think we face with this mod.

I dont now how to keep this mod to work just in a specific article and not all articles that comes after.
what is your opinion doug about it?  sleep one more time and find us the solution.  ;D ;D
Logged
“Fifty years of programming language research, and we end up with C++?”