Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: [SMALL MOD] Credit line for articles  (Read 1603 times)

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
[SMALL MOD] Credit line for articles
« on: March 23, 2010, 03:05:22 PM »

It begun here: http://snewscms.com/forum/index.php?topic=9011.0
Background: I needed to add a credit line for articles in a site I'm working on. In my case, it's for photos mostly but I suspect it could be used for any "credit line" needs you may have. The way it works is that by adding a "credits" tag to the infoline we can have an output that looks like this:


The mod itself is fairly simple, although to use it we must first change the database, then add a lang variable, then change snews.php - so there are a few steps to go through. The mod comes with no guarantees whatsoever, is published "as-is", and if you don't know what to do with it then you probably don't need it.

First, as always, make sure you have a backup of your db and snews files!

THE MOD
========

0. Change the database. You can do that in various ways, the simplest of which is to use phpMyAdmin to add a field in the articles table, for example after "keywords_meta", with the following values (field, type, collation, null):
Code: [Select]
credits, varchar(255), utf8_unicode_ci, null
1. Next we open the EN.php lang file located in the "lang" folder, find the #customize article block and add the following line at the end of that block:
Code: [Select]
$l['credits'] = 'Credit';
This is the line that goes with the input field in the admin panel, it's not public so you can put whatever term feels comfortable to you there.

From this point, all changes are in snews.php.
2. Info line tags (line 55): add "credits", like so:

Quote
// INFO LINE TAGS (readmore, comments, date)
$tags = array(
   'infoline' => '<p class="date">,readmore,comments,date,credits,edit,</p>',
   'comments' => '<p class="meta">,name, '.l('on').' ,date,edit,</p>,<p class="comment">,comment,</p>'
);

3. articles(), on line 613 in an unmodified version, add "a.credits" - like so:
Quote
$query_articles = 'SELECT
               a.id AS aid,title,a.seftitle AS asef,text,a.date,
               a.displaytitle,a.displayinfo,a.commentable,a.visible,a.credits
            FROM  '._PRE.'articles'.' AS a
            WHERE id ='.$_ID.$visible;

4. Do the same on lines 667 and 677, like so:
Quote
$query_articles = 'SELECT
                  a.id AS aid,title,a.seftitle AS asef,text,a.date,
                  a.displaytitle,a.displayinfo,a.commentable,a.visible,a.credits
and
Quote
$query_articles = 'SELECT
                  a.id AS aid,title,a.seftitle AS asef,text,a.date,
                     displaytitle,displayinfo,commentable,a.visible,a.credits,
                  c.name AS name,c.seftitle AS csef,

5. Still in articles() function, find the first if(infoline==true) part - around line 738 - and add the following directly below the opening curly brace:
Quote
if ($infoline == true) {
            $cred = $r['credits']; // Added march 23, 2010 (FredK)

5.1. In the switch, directly after the date case, add a new case like this:
Code: [Select]
/* New case, added march 23, 2010 (FredK) */
case ($tag == 'credits'):
echo ' | '.$cred;
break;
/* End new case */

5.2 Then repeat the last two steps in the second infoline part, first add $cred=$r['credits'];, then add the credits tag case, like this:
Code: [Select]
} else if (empty($currentPage)) {
if ($infoline == true) {
$cred = $r['credits']; // Added march 23, 2010 (FredK)
$tag = explode(',', tags('infoline'));
foreach ($tag as $tag ) {
switch ($tag) {
case 'date':
echo $a_date_format;
break;
/* New case, added march 23, 2010 (FredK) */
case ($tag == 'credits'):
echo ' | '.$cred;
break;
case 'readmore':
case 'comments': ;
break;
case 'edit':
if (_ADMIN) {
echo ' '.$edit_link;
}
break;
default:
echo $tag;
}
}
}

6. function form_articles($contents) - from around line 1914.
Find the $frm_meta_key line in the first block, copy it, paste it directly below the original and change it to this:
Code: [Select]
$frm_cred = $_SESSION[_SITE.'temp']['credits'] ? cleanSEF($_SESSION[_SITE.'temp']['credits']) : $r['credits']; //New line, added 3.23.10 (FredK)then find the next instance of $frm_meta_key, a bit further down in the same function, and do the same thing, e.g, copy the frm_meta_key field, paste, and change it like this:
Code: [Select]
$frm_cred = cleanSEF($_SESSION[_SITE.'temp']['credits']); //New line, added 3.23.10 (FredK)
7. Around line 2109, find this html_input block:
Code: [Select]
if ($contents != 'extra_new' && $edit_option != '2') {
echo html_input('text', 'description_meta', 'dm', $frm_meta_desc, l('description_meta'), '', '', '', '', '', '', '', '', '', '');
echo html_input('text', 'keywords_meta', 'km', $frm_meta_key, l('keywords_meta'), '', '', '', '', '', '', '', '', '', '');

Then add the following line directly below the keywords_meta line:
Code: [Select]
echo html_input('text', 'credits', 'crd', $frm_cred, l('credits'), '', '', '', '', '', '', '', '', '', ''); /*New line, added 3.23.10 (FredK)*/
8. Function processing(), first block, find the $keywords_meta line and add the following directly below it:
Code: [Select]
$cred = entity($_POST['credits']);
9. Around line 2896, find the add_article switch
Code: [Select]
switch (true) {
case (isset($_POST['add_article'])):
mysql_query("INSERT INTO "._PRE.'articles'."(

and add "credits" in the first block and '$cred' in the second part, like so:
Quote
mysql_query("INSERT INTO "._PRE.'articles'."(
                        title, seftitle, text, date, category,
                        position, extraid, page_extra, displaytitle,
                        displayinfo, commentable, published, description_meta,
                        keywords_meta, credits, show_on_home, show_in_subcats, artorder)
                     VALUES('$title', '$seftitle', '$text', '$date', '$category',
                        '$position', '$def_extra', '$page', '$display_title',
                        '$display_info', '$commentable', '$publish_article',
                        '$description_meta', '$keywords_meta', '$cred', '$show_on_home',
                        '$show_in_subcats', '$artorder')");
                     break;

10. Around line 2930, find
Code: [Select]
mysql_query("UPDATE "._PRE.'articles'." SET
and add the following (after the keywords_meta line):

Code: [Select]
credits = '$cred',and take care to include the trailing comma!

And that's all. With these changes and additions you get a new text field in the Customize panel when you create or edit an article. You can put any text in there, limited by default to 255 characters (if you need more then change the value in your db setting but a field like this shouldn't need more, generally), and it will be printed in the infoline as shown by the screengrab at the beginning of this post. Enjoy.

Hat tip to nukpana for crucial pointer and Sven-Philippe for testing.
Logged

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: [SMALL MOD] Credit line for articles
« Reply #1 on: March 30, 2010, 09:45:37 AM »

Merde ! >:(
I'm trying to insert a default author into the copyright and the syntax, this bloody syntax request doesn't work: ???
Quote
ALTER TABLE `articles` ADD `credits` VARCHAR(255) VALUES ('auteur')
what's the fuck??? :-[

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: [SMALL MOD] Credit line for articles
« Reply #2 on: March 30, 2010, 11:01:17 AM »

Merde ! >:( ... :-[

Doesn't work like that. I think the best way is to look at modifying step 5.1 or possibly step 7 to get the output you need.
(The value of `credits` is inserted in every article/page, that's why the default value NULL.)
Logged

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: [SMALL MOD] Credit line for articles
« Reply #3 on: March 30, 2010, 11:07:24 AM »

Doesn't work like that.
Ah! That's how I did it when we were testing, but with no value.
There I wanted to insert the same author'name into the existing field. No way?

mdj

  • Full Member
  • ***
  • Karma: 44
  • Posts: 226
    • mdj.us
Re: [SMALL MOD] Credit line for articles
« Reply #4 on: March 30, 2010, 01:24:48 PM »

Sven, are you trying to add a field with a default value?

Code: [Select]
ALTER TABLE `articles` ADD `credits` varchar(255) NOT NULL DEFAULT 'auteur';

To add the author to all empty credit fields, then try

Code: [Select]
UPDATE `articles` SET credits = 'auteur' WHERE credits = '';

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: [SMALL MOD] Credit line for articles
« Reply #5 on: March 30, 2010, 03:27:56 PM »

Howdee Matt?
Nice to see you there.
I think I'm gonna make it now...
hum... not now: we just had kinda storm with power breakings... :-\
later. I'll come back.

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: [SMALL MOD] Credit line for articles
« Reply #6 on: March 31, 2010, 07:40:54 AM »

Okey. Working fine.
Thanks Matt.

EDIT: oops...using ALTER TABLE and then entering a new author makes the field empty.
Gotta fix that.
And
Quote
UPDATE `articles` SET credits = 'auteur' WHERE credits = '';
did nothing. 0 records has been changed.  :'(

If in phpmyadmin I ask for a default value "auteur" all existing records have this value.
But then entering a new value makes the field empty.

Oh oh...
« Last Edit: March 31, 2010, 11:48:28 AM by Sven »
Logged

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: [SMALL MOD] Credit line for articles
« Reply #7 on: March 31, 2010, 12:37:00 PM »

Okey I had a bug (as usual) in my code (pre and final version being mixed) :-[

But I can't still update the credits field with the author's name.  ???

mihomes

  • Newbie
  • *
  • Karma: 2
  • Posts: 23
Re: [SMALL MOD] Credit line for articles
« Reply #8 on: November 01, 2012, 02:16:07 AM »

I know this is an old post, but...

I am trying to enter a hyperlink into my credit field... something like :

Code: [Select]
<a href="test.com">Author Name</a>
as I will be using this for listing an author name, possible link to page, and other stuff like rel="author" for Google.  Anyways, the characters are being saved/output as :

Code: [Select]
&lt;a href=&quot;test.com&quot;&gt;Author Name&lt;/a&gt;
What do I need to change for this?  Maybe I'm just tired from sitting here so long, but I can't seem to find/fix it.

EDIT: html_entity_decode will change it back to normal... wow I need some sleep lol
« Last Edit: November 01, 2012, 06:19:50 AM by mihomes »
Logged

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: [SMALL MOD] Credit line for articles
« Reply #9 on: November 01, 2012, 06:05:45 PM »

You'll need to add a text field in function form_articles($contents) for a url (with corresponding db field in the articles table, and processing bits). You can only enter html code such as <a href... in the article textarea, and for most html tags you'll need to edit function file_include() to get raw html code to work, like this:

Code: [Select]
# if(substr_count ($fulltext, '&')>0){$fulltext = str_replace('&', '&amp;', str_replace('&amp;', '&', $fulltext));}
(note the hashmark that comments the line out)

The issue isn't limited to this mod btw, it's the same for any field other than the article "text" textarea.

The simple solution to your problem is to add the author details within the article text itself.
Logged

mihomes

  • Newbie
  • *
  • Karma: 2
  • Posts: 23
Re: [SMALL MOD] Credit line for articles
« Reply #10 on: November 02, 2012, 10:42:13 PM »

Ended up doing this and it works fine :

Code: [Select]
$cred = !empty($r['credits']) ? 'by '.html_entity_decode($r['credits']).' on ' : NULL;
Logged