Modifying the homepage

Modifying the homepage, a forum discussion on Jojo CMS. Join us for more discussions on Modifying the homepage on our Administration (backend and configuration) forum.

Back to Forum Index : Back to Administration (backend and configuration)   RSS
glouk glouk

13 Jan 2009
Posts: 46

Hi,

I'm back to jojo after some time. my projects has stalled for a few months...

Now i'm almost done, except i want to build a custom home page, that will include a blog.

How do i do this ?

I've tried copying the index.php into my plugin, and adding the corresponding declarative lines in the api.php, but that does not work : i get a 404.

So how should i proceed ?

Thanks
glouk glouk

13 Jan 2009
Posts: 46

ooops, forgot to rename the file...

i'm done with the 404, but is there a simple way to fetch, say, the last 5 articles ?
tom

Developer

tom

13 Jan 2009
Posts: 379

if you're using a reasonably recent version of Jojo, the articles plugin should have something like this in global.php:

$_CATEGORIES = (Jojo::getOption('article_enable_categories', 'no') == 'yes') ? true : false ;
$categories = ($_CATEGORIES) ? Jojo::selectQuery("SELECT * FROM {articlecategory}") : array();

/* Create latest Articles array for sidebar: getArticles(x, start, categoryid) = list x# of articles */
if ($_CATEGORIES && count($categories) && Jojo::getOption('article_sidebar_categories', 'no')=='yes') {
$smarty->assign('allarticles', JOJO_Plugin_Jojo_article::getArticles(Jojo::getOption('article_num_sidebar_articles', 3), 0, 'all') );
foreach ($categories as $c) {
$category = $c['ac_url'];
$categoryid = $c['articlecategoryid'];
$smarty->assign('articles_' . str_replace('-', '_', $category), JOJO_Plugin_Jojo_article::getArticles(Jojo::getOption('article_num_sidebar_articles', 3), 0, $categoryid) );
}
} else {
$smarty->assign('articles', JOJO_Plugin_Jojo_article::getArticles(Jojo::getOption('article_num_sidebar_articles', 3)) );
}

if you're not using categories it generates a smarty array called 'articles', of the latest articles - it assumes 3 unless you tell it otherwise in
options > articles > number of articles to show in the sidebar

...then, in your theme template add something like this :

<div id='news'>
<h2>News</h2>
{foreach from=$articles key=key item=article}
{if $article.ar_image}<img src="images/v7000/articles/{$article.ar_image}" alt = "{$article.title}" class="right-image" style="clear: right"/>{/if}
<h3>{$article.title}</h3>
<p class='news-content'>
{$article.bodyplain|truncate:150:"..."}
<a class='links' href='{$article.url}'>&gt; Read more</a>
</p>
{/foreach}
<p class="links">&gt; <a href='{$SITEURL}/{$articleshome}/'>See all news articles</a></p>

</div>


glouk glouk

13 Jan 2009
Posts: 46

Thanks Tom for your answer : seems perfectly clear to me.

I use jojo RC1. I believe it's the most recent version ? even if it's not that recent ;)

tom

Developer

tom

13 Jan 2009
Posts: 379

if you want to get fancy...
in global.php in the theme folder (anything in the theme will override anything anywhere else):

/* Create recent Articles array for sidebar: getArticles(x, start, categoryid) = list x# of articles */
$articles = Jojo_Plugin_Jojo_article::getArticles(30, 0);
shuffle($articles);
$articles = array_slice($articles, 0, 5);

$smarty->assign('articles', $articles);

this gets the 30 latest articles, randomly shuffles the order and picks the first 5 to assign to smarty
which will mean that you get a different selection of stories displayed every time you visit the page

you can also use :
$articles = Jojo_Plugin_Jojo_article::getArticles();
to get all articles, but it adds a bit of overhead if you've got a lot of articles


...and
if you want to have one as a 'highlighted article' that gets displayed differently from the other 4 (like with a larger picture or more of a text snippet:

$articles = Jojo_Plugin_Jojo_article::getArticles(30, 0);
shuffle($articles);
$articles = array_slice($articles, 0, 5);
$featured = array_pop($articles);

$smarty->assign('articles', $articles);
$smarty->assign('featured', $featured);

and add handling for {$featured} into the template along with the other article stuff


glouk glouk

13 Jan 2009
Posts: 46

thanks again Tom !
glouk glouk

14 Jan 2009
Posts: 46

Integrating the blog items in my homepage works fine !

Now i have two more questions :

1. how do i change the favicon ? i've tried to put the vavicon.ico in several places, to no luck.

2. the syntax "images/v7000/" is not documented. what is its meaning ?

thank you.
tom

Developer

tom

14 Jan 2009
Posts: 379

favicon.ico goes into the root of the theme folder (ie at the same level of the other folders in there like images etc) - you may also need to do a full browser refresh, and on some browsers, the favicon is aggressively cached, so getting the new one to show is not always immediate.

try doing a force refresh on the icon url (eg http://[yoursite]/favicon.ico

using the images/[#modifier] syntax will take the image and resize it (meaning all your base images can be full res, and it will generate thumbnails and so on automatically)

it can be used both on images in any of images folders (in the theme or in a plugin), or on images in the downloads folder, by following the modifier with the folder name in downloads - eg downloads/articles/[image] -> images/v6000/articles/[image]

h# is for height, w# is for width with the other dimension scaled accordingly
v# is for volume (meaning wide images and tall images will both be scaled to the same relative size although their widths and heights may be different)
#x# is for width by height - the larger dimension will be reduced to one and then the image auto cropped on the other to fit

the full size image will be available from images/default/[imagefile]
glouk glouk

14 Jan 2009
Posts: 46

thank you Tom
glouk glouk

15 Jan 2009
Posts: 46

And here I am back again... I have a problem with special chars in the body of the article. At first ithought the editor was the culprit, but then i took a look at jojo_articles.php, and found this in the getArticles function :

$articles[$i]['title'] = Jojo::html2text($articles[$i]['ar_title']);
$articles[$i]['bodyplain'] = Jojo::html2text($articles[$i]['ar_body']);

What happens is : when i type in standard text, the body is stored in clean html, but gets converted back to text when the data is retrieved, and the reverse conversion of entities goes wrong. It works however with the title, that is not html encoded.
I'd say i don't know why it works, since the title's special chars, not being html encoded, should act weird in the browser. But i couldn't find the source code of jojo::textfilter(), so...

however, i'm tempted to modify those lines to my liking, but then how should i proceed ? tap directly in the source file or redefine the function in global.php in my own plugin or in the template ?

thanks

[edit] after trying some of this, it behaves weird : if I use htmlentities() on the title, special chars get double-encoded... is there some sort of top-level textfilter in jojo ? The strange thing is : it does not happen with the body, which is also html-encoded since i removed the html2text function...
tom

Developer

tom

16 Jan 2009
Posts: 379

htmlentities and html2text are both frought with issues when dealing with anything outside of unmarked english text (Russian is the one i've had the most headaches dealing with)

the trunk copy of articles (which will appear in the next release) abandons html2text wherever possible (partly because the overhead is so high) and uses strip_tags instead.

the three functions work in quite different ways

strip_tags just removes tags

html2text does a conversion of <p> tags to <br />, uppercases headings etc to get rid of all tags that might cause problems and then does an htmlentities

htmlentities converts everything into htmlentites (including tag characters like <>) so is no good for converting html markup on its own. there is a less aggresive variant - htmlspecialchars - which just deals with ampersands, quotes and <>, but is still pretty hopeless with unicoded text

the idea behind performing this operation in general is that the $articles array is primarily for use in displaying snippets of the text, which are truncated. If you don't get rid of the tags (by one means or another) you are likely to end up with a snippet with no closing tag on it, which will make your page fail validation.

If you want the raw html, in the template, instead of:
<p>{$article.plainbody}</p>
use:
{$article.ar_body}

the title and the body are treated differently, because the title is a plain text field, which users tend to fill with things like & which ought to be htmlentitied, particularly as the title gets used in the url. I can't remember if rc1 does this on save (and stores it in the database in htmlentites) or processes it after the fact.. checking the database entries should clear that up though.
The body should have been pre htmlentied already, before it gets to the database, by the editor, so as far as articles is concerned should only need the tags removed.

clear as mud? :)
glouk glouk

17 Jan 2009
Posts: 46

not that much ;)

as far as i see in phpMyAdmin, the title, is not html encoded in the db, but the body is.

however the title is clean on the page, and if i html encode it, i get odd characters.

mystery to me, but then, if it works...

thanks tom
tom

Developer

tom

5 Feb 2009
Posts: 379

but wait! there's more...

I've been fooling around with a multi-language site in an attempt to come up with one method that works for producing valid html from plain text fields (like page titles, article titles etc)
the problem is, you can't guarantee what will be in them - could contain &, or &amp;, or foreign character text.
I've used (using article titles as an example):

$article['title'] = htmlspecialchars($article['ar_title'], ENT_COMPAT, UTF-8, false);

and it seems to work pretty consistently.
I tried doing the check later at the template level but Smarty just isn't smart enough, so I've ended up using this at the plugin php level, to clean the variable just before it goes to smarty


glouk glouk

6 Feb 2009
Posts: 46

thanx Tom, i'll use this in my plugin !!!
tom

Developer

tom

6 Feb 2009
Posts: 379

whoops - should at least get the syntax right... left the quotes off the UTF-8 :p
$article['title'] = htmlspecialchars($article['ar_title'], ENT_COMPAT, 'UTF-8', false);
Back to Forum Index : Back to Administration (backend and configuration)   RSS
You must be logged in to post a reply



You need to Register or Log In before posting on these forums.