Hello

July 30, 2010, 05:17:45 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?
Login with username, password and session length
What sNews Is: - sNews is a simple, basic, customizable CMS tool suitable for developers with beginner-to-advanced PHP skills. It is also useful to have a good working knowledge of how to work with, set up and manage MySQL databases. sNews is not - geared towards the end-user who knows little or nothing about building and developing PHP-MySQL based websites.
News: Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.
 
   Home   Help Search Login Register  
Pages: [1] 2 3 ... 6
  Print  
Author Topic: [MOD] Long articles splitted in subpages  (Read 17463 times)
skidoo
Newbie
*

Karma: 4
Posts: 41


« on: May 28, 2007, 02:00:28 PM »

UPDATES AT BOTTOM OF POST
ALL OF UPDATES ARE INCLUDED IN ZIPED FILE, YOU DO NOT HAVE TO CHANGE FILES FROM UPDATE SECTION AT BOTTOM, IF YOU DOWNLOADED ZIP FILE AFTER 16 JUNE 2007 Smiley

Hello Smiley,

Some time ago I asked on forum for modifacation of sNews, which I found on Mika's page. He did not answer in that thread, so I decided to do some 'hack' (big word for my work;) ) and do it my self.  I did this by saturday night and sunday morning, I am not php programist, so be understing for my 'hacked' version Smiley. I was tried to make it easy to use and maintain (in philosophy of sNews) and not interfere to much ( I'm not writing here about code :cool: )in main functionality of this great CMS.

I take snews.php 1.6 with  philmoz modifacation Articles sorted by categories. I choose modificated  version by philmoz, because this admin feature in my opinion is very importent and usuful, especialy in big sites and in my mod helps keep easy maintaining articles and subpages.

Here is zip with three files:diff, orig snews.php (with philmoz mod), and modified snews-split.php (this is what You probably need most).

My mod need one new table in databese, and one new column added to table articles:
Code:
CREATE TABLE subarticles (
        id int(11) primary key auto_increment,
        article_id int(11),
        page_number int(11),
        title varchar(100) default NULL,
        seftitle varchar(100) default NULL,
        `text` longtext
);

ALTER TABLE articles ADD COLUMN subarticle bool;
and  styles to style.css:
Code:
.current-sub-number {
        color: green;
}
.current-sub-menu {
        color: blue;
}
.sub-menu {
float: right; margin-right: 10px; padding: 10px;
}
.sub-number {
        color: black;
        float: right;
        margin-right: 50px;
        margin-left: 40px;
}
In .htaccess add 2 lines:
Code:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z_]+)/([^/]+)/([^/]+)/ index.php?category=$1&title=$2&subtitle=$3 [L]
Copy the file snews-split.php to the directory, where You have snews and change first line in index.php:
Quote
<?php session_start(); include('snews-split.php'); ?>
In editon of article (or when adding new one) in customize You will see new option:

Display subpages of article.

When You turn it checked, in articles listing appear link to adding new subpages, and if there are any added subpages You also will see link to editing subpages with its number.

Order of displayed subpages in menu is by page number, which You provide adding new subpage.

Always first subpage of article is main article Smiley, that is next subpage should have page number = 2 and up.

Menu in top left in article, and numbers of subpages  (at the bottom of the article) shows when "Display subpages of articles" is checked and You click "continue reading" or article title.

I tested it on standard snews template, If You found any bugs, problems write at once Smiley.

UPDATE #1

fix for deleting subarticles:
find in line 1554 in snews-split.php
Quote
echo html_input('submit', 'delete_article', delete_article', l('delete'), '', 'button', 'onclick="javascript: return pop()"', '', '', '', '', '', '', '', '');
and change it to
Quote
echo html_input('submit', 'sub_delete_article', 'sub_sub_delete_article', l('delete'), '', 'button', 'onclick="javascript: return pop()"', '', '', '', '', '', '', '', '');
UPDATE #2 - I think not last...
Fixed deleting subpages together with main article:

After line 1866 in snews-split.php:
Quote
mysql_query("DELETE FROM ".db('prefix')."articles WHERE id = $id LIMIT 1;");
add line:
Quote
mysql_query("DELETE FROM ".db('prefix')."subarticles WHERE article_id = $id;");
UPDATE #3
In few places in sql statemants I forget to add . "  db('prefix') " .. I don't write all of this lines here, instead I updated ziped file

UPDATE #4

I added "new subpage" link in editing main article (with info about number already added articles).

This what You have to modify (all changes are made in snews-split.php):

Add two lines in function l:
Quote

        $l['number_of_subpages'] = "Number of already added subpages: ";
        $l['no_subpages'] = "No subpages added yet";

Find line 1397 in snews-split.php:
Quote
echo html_input('button', 'include', '', 'Include', '', 'button', 'onclick="tag(\'include\')"', '', '', '', '', '', '', '', '');
and after this line add:
Quote

        if ($frm_display_subpages == 'ok' && !empty($id)) {
        echo "
<a href=\" ". db('website')."index.php?action=sub_article_new&id=$id\">" . l('new_subpage') ." </a>  ";
        number_of_subpages($id);
        }

Under the function form_subarticles add one new function:

Quote
function number_of_subpages($id) {
        $r = mysql_fetch_array(mysql_query("SELECT count(*) FROM ".db('prefix')."subarticles where article_id='$id';"));
        if ( $r[0] > 0 ) { echo l('number_of_subpages'). "<b>$r[0]</b>"; }
        else { echo l('no_subpages'); }
        return 0;
}
UPDATE #5
I  made changes in form_subarticles - fixed return to editing *NEW* article (and not to editing existing) form when where errors (existing title, page number, seftitle).

UPDATE #6
I modified functions sitemap() and breadcrumbs() to display subpages, and function search() to search strings in subpages.

UPDATE #7

Unique title (and seftitle) only in article, not in all subarticles table.

UPDATE #8

Function delocalize() is in Polish.

 Ziped file from top of post contains all all of above updates and most actuall diff file.


Regards
skidoo :cool:
« Last Edit: September 21, 2007, 08:37:07 AM by skidoo » Logged
bramsyuur
sNews Dude
Hero Member
*****

Karma: 23
Posts: 899



WWW
« Reply #1 on: May 28, 2007, 02:30:43 PM »

Really useful mod skidoo!
Thanks for your contribution!

Demo to test it here: http://snews.vietbee.net/demos/sub-pages/
Login with : test/test

Bug found: You need to remove the sub-pages when the primary article was deleted. Now, the related sub-pages of an article still remain into the DB.
Logged

La comunidad sNews en tu idioma!
Comunidad sNews en Español
skidoo
Newbie
*

Karma: 4
Posts: 41


« Reply #2 on: May 28, 2007, 03:14:40 PM »

Yes, I forget about deleting :/. I will try to fix it today night.

Regards
skidoo
Logged
Patric Ahlqvist
Nobodys perfect, but Im pretty effing close
Administrator
ULTIMATE member
******

Karma: 64
Posts: 4903


“I'm a self-made man and worships my creator.”


WWW
« Reply #3 on: May 28, 2007, 03:48:01 PM »

Mhm, I'm a tad stupid today...aswell, hehe... tried to add an article a long fecker at Frederic's test site, but I don't seem to be able to add sub's... Could you explain one more time in laymen terms ?
Logged

My sNews site
"It's only dead fish that goes with the flow... "
Updated, online again - Free designs
Keyrocks
Administrator
ULTIMATE member
******

Karma: 411
Posts: 5452


Semantically Challenged


WWW
« Reply #4 on: May 28, 2007, 03:50:34 PM »

Yes... I'd also like to have a clearer picture of what this MOD is for and how it is used. Smiley
Logged

Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU
bramsyuur
sNews Dude
Hero Member
*****

Karma: 23
Posts: 899



WWW
« Reply #5 on: May 28, 2007, 03:53:34 PM »

@Patrick and Key:
Patric, I've fixed your post.
Check again my demo site to see in action.
See in the articles view command to look the subpages item.
Logged

La comunidad sNews en tu idioma!
Comunidad sNews en Español
philmoz
High flyer
Administrator
ULTIMATE member
******

Karma: 150
Posts: 1836



WWW
« Reply #6 on: May 28, 2007, 04:04:12 PM »

ok, create new or edit old article...
-- select customise.
--- place check in Display subpages of article box
---save(edit)
then, view the article list... and there is another option.
select it to create a 'sub-page', and put number 2 in the box.
fill out the  new article as you would normally and save.

then view the original.
------------
Logged

Take offs are optional, landings are mandatory, unless you get into space, then you have other issues.
Patric Ahlqvist
Nobodys perfect, but Im pretty effing close
Administrator
ULTIMATE member
******

Karma: 64
Posts: 4903


“I'm a self-made man and worships my creator.”


WWW
« Reply #7 on: May 28, 2007, 04:08:21 PM »

Got it Wink (http://snews.vietbee.net/demos/sub-pages/blably/patric/) A note there for either you or skidoo... Great modification, Ski... going to use that when totally done and finished...

Would however be cool to compare the two ways of achieving this. Knowing Mika-man his version is not entirly like this one :lol:
Logged

My sNews site
"It's only dead fish that goes with the flow... "
Updated, online again - Free designs
skidoo
Newbie
*

Karma: 4
Posts: 41


« Reply #8 on: May 28, 2007, 04:12:43 PM »

thanks philmoz for simpler explanation Smiley

fix for deleting subarticles:
find in line 1554 in snews-split.php
Quote
echo html_input('submit', 'delete_article', delete_article', l('delete'), '', 'button', 'onclick="javascript: return pop()"', '', '', '', '', '', '', '', '');
and change it to
Quote
echo html_input('submit', 'sub_delete_article', 'sub_sub_delete_article', l('delete'), '', 'button', 'onclick="javascript: return pop()"', '', '', '', '', '', '', '', '');
At evening I will fix deleting all subpages together with deleting an article.

Regards
skidoo
Logged
skidoo
Newbie
*

Karma: 4
Posts: 41


« Reply #9 on: May 28, 2007, 04:20:34 PM »

Quote from: Patric
Got it Wink (http://snews.vietbee.net/demos/sub-pages/blably/patric/) A note there for either you or skidoo... Great modification, Ski... going to use that when totally done and finished...

Would however be cool to compare the two ways of achieving this. Knowing Mika-man his version is not entirly like this one :lol:
Patric, I have read what You wrote in test page. You can add subpages in edit article (which You alredy had in cms), simply check the "Display subpages of article" and then option for adding new subpage will show under the article in article view.

regards
skidoo
Logged
Patric Ahlqvist
Nobodys perfect, but Im pretty effing close
Administrator
ULTIMATE member
******

Karma: 64
Posts: 4903


“I'm a self-made man and worships my creator.”


WWW
« Reply #10 on: May 28, 2007, 04:35:16 PM »

Yes, I know that, skid... I only felt that that option for adding new subpage that now is placed under article view, perhaps could be placed inside the edit article instead...

Like this:
I add the article, and I check the checkbox hinting I would like to add a new subpage.
I press submit, and I go back to edit article and then the "add new subpage" is located inside the edit article rather than in article view...

Might not be doable, might not even be better, and might not even be logical to any other than me, but that's how I see it Wink... Again... great MOD, skid.
Logged

My sNews site
"It's only dead fish that goes with the flow... "
Updated, online again - Free designs
skidoo
Newbie
*

Karma: 4
Posts: 41


« Reply #11 on: May 28, 2007, 07:22:35 PM »

I have fiixed deleting subpages together with main article:

After line 1866:
Quote
mysql_query("DELETE FROM ".db('prefix')."articles WHERE id = $id LIMIT 1;");
add line:
Quote
mysql_query("DELETE FROM ".db('prefix')."subarticles WHERE article_id = $id;");
Patric, I think it could be doable... I'will figure it out in a few days.

regards
skidoo
Logged
piXelatedEmpire
MIA
Thread Moderator
ULTIMATE member
*****

Karma: 37
Posts: 1456


currently MIA


« Reply #12 on: May 29, 2007, 02:27:24 AM »

This looks like a terrific MOD... I'll be watching this thread to see how it develops.

Cheers  :cool:
Logged

my apologies to the sNews crew, but I will be MIA for the forseeable future
Patric Ahlqvist
Nobodys perfect, but Im pretty effing close
Administrator
ULTIMATE member
******

Karma: 64
Posts: 4903


“I'm a self-made man and worships my creator.”


WWW
« Reply #13 on: May 29, 2007, 10:08:08 AM »

Quote from: SKID-MAN
Patric, I think it could be doable... I'will figure it out in a few days.
Awsome Wink
Logged

My sNews site
"It's only dead fish that goes with the flow... "
Updated, online again - Free designs
Zucye
Sr. Member
****

Karma: 5
Posts: 354



WWW
« Reply #14 on: May 29, 2007, 05:29:10 PM »

Quote from: Patric
Would however be cool to compare the two ways of achieving this. Knowing Mika-man his version is not entirly like this one :lol:
I would like to see this as well.

Observation: The Article pagination gets trap inside the 1st comment. (http://snews.vietbee.net/demos/sub-pages/home/linear-equations/#Comment1)

Skidoo this is a really nice MOD!
Logged

We can always learn from our failures, not so much from obvious success - C. Robinson (W. Disney). Smiley
Pages: [1] 2 3 ... 6
  Print  
 
Jump to:  

English Steel 1.6 © Saxon North Technologies
Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!