The Serendipity Handbook

You can now read the (german) handbook here: PDF - https://github.com/s9y/Book (LaTeX source).

Forum-Information

Before posting about errors, make sure that the answer cannot already be found in our FAQ or by searching this forum!
Posting is restricted to registered users (registering is free and simple!) due to recent spam attacks. When having trouble with this board, contact garvin(-at)s9y(-dot)org.

Board index Development Last post by author to embed externally

Discussion corner for Developers of Serendipity.
User avatar
aschlemmer
Regular
 
Posts: 55
Joined: Fri Feb 23, 2007 7:13 pm
Location: Freiburg/Germany

Postby aschlemmer » Wed Apr 25, 2012 1:58 pm

Hi!

I'm looking for a smart way to display the last post by author from a s9y installation (domain a) on my personal homepage (domain b), same DB server for both.

It would also be nice to have a way to show the last comment by author in the same configuration.
Is there a solution with RSS or similar?

Thanks for any hints or code snippets :)
Achim
www.ms-reporter.de
Pharma-unabhängige Infos für Multiple Sklerose-Betroffene
schnellze.it
Einzigartiges Zusammenspiel aus Popfetcher und s9y

User avatar
garvinhicking
Core Developer
 
Posts: 28950
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany

Postby garvinhicking » Wed Apr 25, 2012 6:29 pm

Hi!

Two ways, the API way:

Code: Select all
<?php
chdir('/path/to/serendipity');
include 'serendipity_config.inc.php';
$serendipity['GET']['viewAuthor'] = 7; // Enter author id!
$entries = serendipity_fetchEntries(null, null, true); // Pass the parameter for limit=1, I'm too lazy to look it up - it's documented in include/functions_entries.inc.php in the function header
serendipity_printEntries($entries);


(More info: http://www.s9y.org/78.html#A7)

And the DB way:

Code: Select all
$sql = mysql_query("SELECT * FROM serendipity_entries WHERE authorid = 7 ORDER BY timestamp DESC LIMIT 1");
$entry = mysql_fetch_array($sql, MYSQL_ASSOC);
print_r($entry);


Printing comments would work in a similar way, you would need to query serendipity_comments for that.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/

User avatar
aschlemmer
Regular
 
Posts: 55
Joined: Fri Feb 23, 2007 7:13 pm
Location: Freiburg/Germany

Postby aschlemmer » Thu Apr 26, 2012 9:39 am

Hi!

Thanks for your answer!
I tried this one:
garvinhicking wrote:the API way


with a blank test file containing;
Code: Select all
<?php
chdir('/path/to/s9y/');
include 'serendipity_config.inc.php';
$serendipity['GET']['viewAuthor'] = 3;
$entries = serendipity_fetchEntries(null, true,1);
serendipity_printEntries($entries);
chdir('/path/to/test-file/');
?>


and I get an error message:
Fatal error: Call to a member function assign() on a non-object in /path/to/s9y/include/functions_entries.inc.php on line 923

I'm lost with this message. What's going wrong here?

Regards,
Achim
www.ms-reporter.de
Pharma-unabhängige Infos für Multiple Sklerose-Betroffene
schnellze.it
Einzigartiges Zusammenspiel aus Popfetcher und s9y

User avatar
garvinhicking
Core Developer
 
Posts: 28950
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany

Postby garvinhicking » Thu Apr 26, 2012 10:51 am

Hi!

Sorry; after the viewAuthor variable, insert another line "serendipity_smarty_init();".

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/

User avatar
aschlemmer
Regular
 
Posts: 55
Joined: Fri Feb 23, 2007 7:13 pm
Location: Freiburg/Germany

Postby aschlemmer » Thu Apr 26, 2012 4:11 pm

OK, thanks: I modified my code to
Code: Select all
<?php
chdir('/path/to/s9y/');
include 'serendipity_config.inc.php';
$serendipity['GET']['viewAuthor'] = 3;
serendipity_smarty_init();
$entries = serendipity_fetchEntries(null, true,1);
serendipity_printEntries($entries);
chdir('/path/to/test-file/');
?>


The output is nothing -- a .php file containing only this results in an empty page.

Additionally, if I put it together with only one character (or other html), I get an error:
Warning: Cannot modify header information - headers already sent by (output started at /path/to/test-file/new.php:1) in /path/to/s9y/include/functions_config.inc.php on line 700

What's going on?

Lost in code,
Achim
www.ms-reporter.de
Pharma-unabhängige Infos für Multiple Sklerose-Betroffene
schnellze.it
Einzigartiges Zusammenspiel aus Popfetcher und s9y

User avatar
Timbalu
Regular
 
Posts: 2560
Joined: Sun May 02, 2004 3:04 pm

Postby Timbalu » Thu Apr 26, 2012 4:28 pm

Try with
Code: Select all
<html>
    <head>
        <title>test</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
   </head>
   <body>
<?php
chdir('./serendipity/');
include 'serendipity_config.inc.php';
$serendipity['GET']['viewAuthor'] = 1;
$entries = serendipity_fetchEntries(null, true,1);
$author_post = serendipity_printEntries($entries, 0,false,'','return',false,false,false);
echo '<pre>';print_r($author_post);echo '</pre>';
chdir('../');
?>
     </body>
</html>

If you really want to use Smarty you will need a template file like the docu said:
Code: Select all
<?php
// 1: Switch to the Serendipity path. We need to use chdir so that the s9y framework can use its relative calls.
chdir('/home/www/public_html/blog/');

// 2: Start the Serendipity API
include 'serendipity_config.inc.php';

// 3: Start Smarty templating
serendipity_smarty_init();

// 4: Get the latest entries
$entries = serendipity_fetchEntries(null, true,1);

// 5: Put all the variables into Smarty
serendipity_printEntries($entries);

// 6: Get the template file
$tpl = serendipity_getTemplateFile('entries.tpl', 'serendipityPath');

// 7: Format and output the entries
$serendipity['smarty']->display($tpl);

// 8: Go back to where you came from
chdir('/home/www/public_html/');

?>

.... but this is quite complicated to just display some title and a truncated body somewhere else, so I would go the second way via SELECT.
Regards,
Ian

User avatar
aschlemmer
Regular
 
Posts: 55
Joined: Fri Feb 23, 2007 7:13 pm
Location: Freiburg/Germany

Postby aschlemmer » Thu Apr 26, 2012 7:45 pm

Both ways are working now ... thank you very much for your support!
www.ms-reporter.de
Pharma-unabhängige Infos für Multiple Sklerose-Betroffene
schnellze.it
Einzigartiges Zusammenspiel aus Popfetcher und s9y

User avatar
aschlemmer
Regular
 
Posts: 55
Joined: Fri Feb 23, 2007 7:13 pm
Location: Freiburg/Germany

Postby aschlemmer » Mon May 07, 2012 4:39 pm

Hi!

that's me again ... with an additional question regarding character encodings. While I fetch the most recent entry with

Code: Select all
mysql_query("SELECT * FROM serendipity_entries WHERE authorid = 3 ORDER BY timestamp DESC LIMIT 1");
and print it with
Code: Select all
<?php echo( $entry["title"] ); ?>
the output doesn't show mutated vowels (ä, ö, ü, ß)

Example: Drei sch�ne Websites mit sinnvollem CSS3

That's not beautiful, I'm sure there's a switch to deal with that issue?
Thanks in advance and regards,
Achim
www.ms-reporter.de
Pharma-unabhängige Infos für Multiple Sklerose-Betroffene
schnellze.it
Einzigartiges Zusammenspiel aus Popfetcher und s9y

User avatar
Timbalu
Regular
 
Posts: 2560
Joined: Sun May 02, 2004 3:04 pm

Postby Timbalu » Tue May 08, 2012 8:20 am

Tell the browser to read the output file as UTF-8.
Look at my first examples <meta...> head part.

If this isn't possible, while the output page is using latin elsewhere, you should convert your database read with either
Code: Select all
mysql_query("SET NAMES utf8");
before the SELECT, or use PHP
Code: Select all
iconv("UTF-8", "CP1252", $data)
to convert from UTF-8 to ISO-8859-15 (which is better than utf8_decode($data))
Regards,
Ian

User avatar
aschlemmer
Regular
 
Posts: 55
Joined: Fri Feb 23, 2007 7:13 pm
Location: Freiburg/Germany

Postby aschlemmer » Tue May 08, 2012 9:05 am

Timbalu wrote:Tell the browser to read the output file as UTF-8.
Look at my first examples <meta...> head part.


This has been set.

Timbalu wrote:If this isn't possible, while the output page is using latin elsewhere, you should convert your database read with either
Code: Select all
mysql_query("SET NAMES utf8");
before the SELECT


To summarize:
Code: Select all
<?php
mysql_query("SET NAMES 'UTF8'");
$sql = mysql_query("SELECT * FROM serendipity_entries WHERE authorid = 3 ORDER BY timestamp DESC LIMIT 1");
$entry = mysql_fetch_array($sql, MYSQL_ASSOC); ?>
<p><?php echo( date( "d. M. Y", $entry["timestamp"] ) ); ?></p>
<a href="http://schnellze.it/?p=<?php echo( $entry["id"] ); ?>"><?php echo( $entry["title"] ); ?>


works perfectly. Thanks for the UTF-8 help!

I'm asking myself why I'm still getting exactly one result when setting the
Code: Select all
LIMIT 2
in the sql query? I'm afraid that it would be better for me to learn some php/mysql instead of asking such basics here :oops:

Regards,
Achim
www.ms-reporter.de
Pharma-unabhängige Infos für Multiple Sklerose-Betroffene
schnellze.it
Einzigartiges Zusammenspiel aus Popfetcher und s9y

User avatar
Timbalu
Regular
 
Posts: 2560
Joined: Sun May 02, 2004 3:04 pm

Postby Timbalu » Tue May 08, 2012 9:16 am

That looks like a mysql fetch issue, but possibly isn't, as further on you don't loop the array fetched by mysql. Try to write like this
Code: Select all
$entries = mysql_fetch_array($sql, MYSQL_ASSOC);
foreach ($entries AS $entry) { ?>
<p><?php echo( date( "d. M. Y", $entry["timestamp"] ) ); ?></p>
<a href="http://schnellze.it/?p=<?php echo( $entry["id"] ); ?>"><?php echo( $entry["title"] ); ?><hr />
<?php } ?>
Regards,
Ian



Return to Development

Who is online

Users browsing this forum: No registered users and 0 guests

cron