MyAnimeList.net

Forums

Recent Posts | My Watched Topics | My Ignored Topics | Search

saka's minimal signature script (with merged anime/manga feeds)

Must be a Club Member to Reply
Pages (9) [1] 2 3 » ... Last »
#1
05-10-09, 11:13 AM

Offline
Joined: May 2008
Posts: 4614
After marveling at all the spaghetti code floating around, I decided to make a refined minimal script to complement shiteiru/erhgeiz's script.

This script should work as a drop-in replacement for that script, except without all the obscure token nonsense that plagues it. The file is designed mostly as a learning excercise for people new to php, and because of that I have commented it heavily. I have tried to mark important areas with UPPERCASE comments, so look for those for configuration purposes.

For now I'm just giving you the files , but I plan to post a full tutorial soon. At minimum, you will need a background image ("background.png" default) and a font *.ttf file in the same directory as this script and upload them all to your webserver. You can find great custom fonts at http://dafont.com/

Here's the code:

Download saka's minimal script (with anime/manga merged and example files)
(last updated March 17, 2015 - v1.57)


Important Notes on image caching:
  • This script contains support for simple image caching. Your script will get accessed every time someone looks at a forum thread you posted in.... and that can mean thousands of hits in a short time period. Caching basically just makes it so the script doesn't have to build the signature from scratch every single time. Instead it just outputs a reasonably new copy of what it's created previously.

    In order to store that temporary image of your sig, the script will need a writable location to save it. I recommend making an empty directory named 'cache' and making sure it's writable on the server (chmod 777 or change file properties using an FTP client like FileZilla). I've put an empty directory in the zip for you, but you'll need to set the permissions on it after you upload.

    The caching greatly reduces stress on MAL and your server, and makes it much faster. Please use it! (see comments in the script to see how it works, or ask here if you're unsure how to set it up for your server)

  • Image displaying but not updating? By default, the image only updates at most every ten minutes, but for testing/building your sig you may want to set the cache time to 0 minutes so you can see your changes immediately. The script checks its own modification time so re-uploading the php file or deleting the cache image will force it to refresh... but if you are trying different fonts or background images it wouldn't be aware of that. Once your sig is working how you'd like, remember to put the cache time back to something reasonable! I recommend 10-15 minutes.


Where do I point my signature?
You can set your forum signature to use something like
[img]http://yourdomain/signature/sig.php[/img]

...and the file will output your signature image directly (make sure cache is enabled).

Alternatively, you can link to the saved image, for example...
[img]http://yourdomain/signature/cache/sig.png[/img]

...and have a cronjob visit the sig.php location every few minutes to keep the image current. Loading the cache image directly is faster, and is more resistent from 000webhost audits and other such errors, so I recommend this indirect method when possible. If you use MAL Updater, you can use the PHP Signature plugin instead of a cronjob (and your sig will update whenever you watch anime).
Modified by saka, 03-17-15, 1:35 PM
 
#2
05-10-09, 1:35 PM

Offline
Joined: Feb 2008
Posts: 4533
Looks good. Are you going to post this in the creative corner or allow shiteiru/'whatever his name is now' to update his post?
 
#3
05-10-09, 1:37 PM

Offline
Joined: May 2008
Posts: 4614
kuroshiroi said:
Looks good. Are you going to post this in the creative corner or allow shiteiru/'whatever his name is now' to update his post?

he knows about it... i don't really mind either way.
 
#4
05-10-09, 2:59 PM

Offline
Joined: May 2007
Posts: 4739
lol@people who change nicks frequently.
 
#5
05-10-09, 6:04 PM

Offline
Joined: Feb 2009
Posts: 174
I dont feel like learning more stuff so i'll keep my bombarding sig :)
 
#6
05-11-09, 12:40 AM

Offline
Joined: Sep 2007
Posts: 2285
Tried it out, really nice. Only things it is missing are transparency and title cutter I think :)

edit: just typo fix, I'm still half-asleep...
Modified by SunyiNyufi, 05-11-09, 12:50 AM
 
#7
05-11-09, 5:59 AM

Offline
Joined: Apr 2008
Posts: 94
lol@people who change nicks frequently.


Tell me...what's bad or funny about changing ones nick ? ^^ I don't get it.

Anyway, nearly every nick used online is self given and holds absolutely no meaning, so whats the point in "not changing it" ?

I don't really mind if people know me or not.
Who cares in the first place?

Btw. who cares which episodes have been watched by nick xyz in the last 4 or 5 hours (except you know him and want to know desperately what he was watching)...not me

The only purpose i made this sig thingie in the first place, was that custom sigs look a lot better than the mal generated ones. Besides that, there is absolutely no point (at least in my opinion) for creating self updating sigs.

Just my 2 cents.

Last not least: i don't want everyone to know what i'm doing where and why. So...in every community i'am i do indeed have a different nick.
Call it paranoia........who cares anyway ^^

Now go on and do something that matters like learning japanese or so :-D
Luck is the last dying wish of those who wanna believe that winning can happen by accident, sweat on the other hand is for those who know it's a choice, so decide now because destiny waits for no man.
 
#8
05-11-09, 6:52 AM

Offline
Joined: Dec 2008
Posts: 4503
Uh, it was screwing up on the transparencys for my sig, should add that
imagealphablending($sigimage,true);
imagesavealpha($sigimage,true);

thingy

Not that I know anything though, took me like 10 minutes to figure out where the heck to put it! lol
 
#9
05-11-09, 6:58 AM

Offline
Joined: May 2008
Posts: 4614
SunyiNyufi said:
Tried it out, really nice. Only things it is missing are transparency and title cutter I think :)


transparent overlays should work without imagealphablending() as long as only 24-bit png is used. I guess I could add an overlay by default or something, but I figured that had been covered enough already elsewhere. I might be wrong though.

I'll add in a title truncation line when I get back tonight.

ehrgeiz said:
The only purpose i made this sig thingie in the first place, was that custom sigs look a lot better than the mal generated ones. Besides that, there is absolutely no point (at least in my opinion) for creating self updating sigs.

Just my 2 cents.

yeah that's pretty much my opinion also... but there should be easier ways to make them look nice. It would be best if Xinil might get to expanding the existing sig system to have at least a few different fonts.

I just wanted to give people some options in the hosted php department.
 
05-11-09, 7:09 AM

Offline
Joined: Dec 2008
Posts: 4503
Cutting after however many characters would be nice to add too, cause I'm sure it'll come up

edit: love this code lol, theres barely anything with it so its easy for me to figure out how to add all the stuff like cutting on my own. Nice to have options, thanks for it.
Modified by Yuruku, 05-11-09, 7:15 AM
 
05-18-09, 12:51 AM

Offline
Joined: May 2008
Posts: 4614
Text 'cutting' and image overlays are now supported by default in the script. You can use the textlimit() and overlay_image() functions as defined in the script. You can use the new open_image() function to open any type of image that GD supports, although I recommend sticking with PNG.

Here's an example of limiting the string length to 25 characters:
$titles[0] = textlimit($titles[0], 25);

Here's an example of image overlay:
// open an image
$sigimage = open_image("background.png");

// put my png overlay on it
overlay_image("overlay.png");

...easy right? ^^

I've also added basic image caching by using a check_cache() function and tried to make it as simple as possible to understand. This still requires permission changes, but hopefully it's not too much for people.
 
05-18-09, 5:44 AM

Offline
Joined: Feb 2008
Posts: 4533
I recently added this way-too-long code to my script:
$replaceCharacters =     array('/ä/','/~/','/☆/','/†/');
$replaceWithCharacters = array('a','-','*','+');
$animeTitle = preg_replace($replaceCharacters,$replaceWithCharacters,$animeTitle);
It takes care of the characters (that I know of from MAL) that a lot of fonts don't include. Of course, * and + are no ☆ and † but you get the point.

I'm considering switching over to your script, I'd need to incorporate some minor changes but overall, it does what I need. I'm assuming it actually works with 000webhost's cron jobs?
 
05-18-09, 7:05 AM

Offline
Joined: May 2008
Posts: 4614
hmmm...It would be nice to compile a more comprehensive replacement method, or even better to have a fall-back font and let it switch to a unicode font only for writing those characters. I considered doing this in my own (non-minimal) script at one point... but since I no longer use the text I didn't bother. I don't really want to add anything more to this one, but it should be easy to add basic replacements using strtr(), near the other character replaces...

$buffer = strtr($buffer, array('ä' => 'a',...) );

kuroshiroi said:
I'm considering switching over to your script, I'd need to incorporate some minor changes but overall, it does what I need. I'm assuming it actually works with 000webhost's cron jobs?

there shouldn't be any problem. something like this should do it:
Modified by saka, 09-10-09, 6:54 PM
 
05-18-09, 7:35 AM

Offline
Joined: Feb 2008
Posts: 4533
saka said:
I don't really want to add anything more to this one
I hear you on that but it beats having boxes and shit in the sig.
 
06-02-09, 10:12 PM

Offline
Joined: May 2009
Posts: 56
Looks like i've learnt how to script, thanks alot.
Can you put JPEG pictures instead of png? or it doesnt work with JPEG?
 
06-02-09, 10:49 PM

Offline
Joined: May 2008
Posts: 4614
ryuK- said:
Looks like i've learnt how to script, thanks alot.
Can you put JPEG pictures instead of png? or it doesnt work with JPEG?


jpeg images should work just fine ...it should even work with GIF (not animated) and a host of other formats like BMP, XPM, and GD raw images.

By default, it still converts the output to PNG, though. If you don't want this, you can change the imagepng(...) lines at the end to imagejpeg() instead just to avoid extra conversion and/or reduce filesize if you don't need transparency. Remember to change the header(...) lines accordingly also.
 
06-02-09, 11:38 PM

Offline
Joined: May 2009
Posts: 56
Thanks, i got it working
 
06-19-09, 12:18 PM

Offline
Joined: Apr 2008
Posts: 262
saka said:
erm... it's filled with #'s possibly?

you're probably getting a parsing error.... just remove all the #'s in your code if they are actually there (global replace in your text editor should handle it).
btw... it's better to just ask in the thread for my script if you have questions.

Okay I done that, but still it isn't working. Maybe let's start from begging. That whole code must be put in one php file (ex. sig_creator), then I must have background, overlay (I'm using it), font file and cache folder, right? I got that all, cache folder chmod is set 777, server is 000webhost.com and the code is like in other topic (but without #'s), still it isn't working. What could be the problem?
 
06-19-09, 12:25 PM

Offline
Joined: Feb 2008
Posts: 4533
Post the code again with the error.
 
06-19-09, 12:59 PM

Offline
Joined: May 2008
Posts: 4614


Fixed the errors, Silmoren...

make sure you have the url set like i have done above, and that the $font is the path to an actual *.ttf font file.

not sure why you wanted to strip out all the comments... nor exactly exactly what is wrong... but I'll look later tonight if I have time.
 
06-19-09, 3:05 PM

Offline
Joined: Apr 2008
Posts: 262
Okay, everything seems to go better way now, great thanks for help, but still I would use some more ^^ Sig is loading now, but there's no text on it, whatever I do. Here's the text-regarding code:


Changing font, color, position, doesn't do anything, sig is still empty
 
06-19-09, 3:12 PM

Offline
Joined: Feb 2008
Posts: 4533
Well, what color is your background, are you sure that's the correct position of the text and since fonts are very CaSe-SeNsItIvE, check that, including the ttf.
 
06-19-09, 5:03 PM

Offline
Joined: May 2008
Posts: 4614
one more thing that might be the culprit: the mal forums will strip backslashes on edit... it's right on my post now, but I had to edit it once to put the backslashes back in. Without them the regular expressions break and none of your RSS data is loaded... which might cause no text to appear.

Make sure these three lines contain backslashes in your version:


You can check that your rss data is being matched by putting a line like this right before your text lines:
var_dump($titles); exit(0);

That will output what the titles array looks like and then stop the script.... so you should see some data when you try to run it.

You should see a list of all the titles in your feed... If nothing is there, something is probably going wrong with parsing. You can just remove the test code if it is working, or use it to test other variables if you'd like.

If that fails, just compare your code against my original since we know that works.... ;P
 
06-20-09, 5:16 AM

Offline
Joined: Apr 2008
Posts: 262
Checked the code, it's exacly the same as Your original code, also that var_dump line doesn't work, nothing changes (at first time I got "NULL error", but later nothing changed). Changing font position, angle, size, doesn't do anything.

Maybe something's with font file, it was .otf, I've changed it to ttf...
 
06-20-09, 6:32 AM

Offline
Joined: Feb 2008
Posts: 4533
Silmoren said:
Checked the code, it's exacly the same as Your original code, also that var_dump line doesn't work, nothing changes (at first time I got "NULL error", but later nothing changed). Changing font position, angle, size, doesn't do anything.

Maybe something's with font file, it was .otf, I've changed it to ttf...
You changed the name of the font or the code?
 
06-20-09, 9:11 AM

Offline
Joined: May 2008
Posts: 4614
Silmoren said:
Checked the code, it's exacly the same as Your original code, also that var_dump line doesn't work, nothing changes (at first time I got "NULL error", but later nothing changed). Changing font position, angle, size, doesn't do anything.

...which just further implies that something is wrong before the text stuff. There's probably nothing in the $titles array, so you're printing out a lot of nothing. An empty string prints just about the same when moved or rotated. ;)

Silmoren said:
Maybe something's with font file, it was .otf, I've changed it to ttf...

*.otf should work just as well, as long as it matches the filename in your code...

I still suspect something on one of the parsing lines is not correct, but I can't tell without looking at it. I've zipped up my test files and sent you a link via pm.

Just replace with your background.png and ol.png and it should work just fine.
 
06-20-09, 11:08 AM

Offline
Joined: Apr 2008
Posts: 262
Okay, as it can be seen the problem is out, it was the font file that generated errors, changed it and everything seems fine. Once more many thanks for all people, who helped me creating this sig ^^
 
06-20-09, 11:41 AM

Offline
Joined: May 2008
Posts: 4614
ooooo looks great, too.
 
06-22-09, 10:39 AM

Offline
Joined: May 2008
Posts: 1879
Hey, I'm making a signature for a friend using the anime/manga merged feeds. Anime updates works great, but when manga is updated, it looks like this:

It doesn't show the read chapter. It also showed the manga type before, but I managed to remove that. This problem is out of my skills though :P

This is what my code looks like:
 
06-22-09, 11:21 AM

Offline
Joined: Feb 2008
Posts: 4533
I'm guessing you'll need to edit
if ($status[$i] == "Watching" or $status[$i] == "Re-Watching")
to something like this:
if ($status[$i] == "Watching" or $status[$i] == "Re-Watching" or $status[$i] == "Reading")


Basically, tell the script how it should format the reading manga entries.
 
06-22-09, 11:28 AM

Offline
Joined: May 2008
Posts: 1879
Thank you, works great now :)
 
07-02-09, 5:44 PM

Offline
Joined: Sep 2007
Posts: 1013
Great script
 
07-03-09, 2:02 PM

Offline
Joined: Apr 2008
Posts: 262
Hmmm recently I wanted to change script from Anime to Anime/Manga. Everything works just fine but 2 problems.

Is it possible with this script to create signature that displays two titles with statuses, where one title is always for manga and other is always for anime? I've changed few things but that script always shows me my recent changes, so when I watch two animes, it displays changes about those two animes, when I read two mangas, it displayes changes about those two mangas.

Second thing is, that script displayes how many anime episodes I've watched, but it doesn't display how many manga chapters I've read.

Also made small change to the code, so that manga title won't be displayed with "- Manga" at the title end:

$titles[$i] = preg_replace('/ - (TV|Movie|ONA|OVA|OAD|Special|Manga)$/', '', $titles[$i]);
 
07-03-09, 2:57 PM

Offline
Joined: May 2008
Posts: 4614
Silmoren said:
Is it possible with this script to create signature that displays two titles with statuses, where one title is always for manga and other is always for anime? I've changed few things but that script always shows me my recent changes, so when I watch two animes, it displays changes about those two animes, when I read two mangas, it displayes changes about those two mangas.

I set it up like this intentionally, although since the status contains 'chapters' instead of 'episodes', you should be able to use this to determine whether an entry is anime or manga.

You could duplicate the preg_match_all lines and parse the anime and manga buffers separately instead of the combined one... You'd need to make some new array names, or make the titles[], status[] etc arrays two dimensional.

If that sounds odd to you, you can do this easier workaround... If you've got more than 15 anime in your list (most people), you can just comment out the line that sorts the combined entries by date:
// array_multisort($timestamps,SORT_DESC,$titles,$status,$current,$totals,$units);

...and then the most recent manga entry should always be the 16th one (since the recent anime feeds list 15 entries). It's not as elegant, but it works.

Silmoren said:

Second thing is, that script displayes how many anime episodes I've watched, but it doesn't display how many manga chapters I've read.

Also made small change to the code, so that manga title won't be displayed with "- Manga" at the title end:

$titles[$i] = preg_replace('/ - (TV|Movie|ONA|OVA|OAD|Special|Manga)$/', '', $titles[$i]);

Strange, I thought I had fixed that already, but I guess i forgot to update the url. The full line to remove all types is this:
$titles[$i] = preg_replace('/ - (TV|Movie|ONA|OVA|OAD|Special|Manga|Manhwa|Manhua|Novel|One Shot|Doujin|OEL)$/', '', $titles[$i]);

I'll fix this on the first page shortly.
Modified by saka, 07-03-09, 3:00 PM
 
07-04-09, 5:44 AM

Offline
Joined: Sep 2007
Posts: 1013
Forgive me if I'm asking a lot, but is there a way to reposition text if the anime title has less then a certain amount of letters?
 
07-04-09, 6:15 AM

Offline
Joined: Feb 2008
Posts: 4533
Roxkis said:
Forgive me if I'm asking a lot, but is there a way to reposition text if the anime title has less then a certain amount of letters?
Should be rather easy, if you know a little programming. You'd have to use http://php.net/manual/en/function.strlen.php and some kind of conditional statement like a switch or an if.

There may be some errors there, but it should be something like this:

if (strlen($titles[0])>5)
{
imagettftext($sigimage,14,0,118,38,$colour,$font,$titles[0]);
imagettftext($sigimage,11,0,125,50,$colour,$font,$status[0]);
}
else
{
imagettftext($sigimage,14,0,200,38,$colour,$font,$titles[0]);
imagettftext($sigimage,11,0,150,50,$colour,$font,$status[0]);
}


In this case, the first 2 lines will execute if the length is over 5 and the last 2 will execute if the length is below 5.

Yes, I overuse white space, give me a break.
Modified by kuroshiroi, 07-04-09, 6:20 AM
 
07-04-09, 12:22 PM

Offline
Joined: Apr 2008
Posts: 262
saka said:
If that sounds odd to you, you can do this easier workaround... If you've got more than 15 anime in your list (most people), you can just comment out the line that sorts the combined entries by date:
// array_multisort($timestamps,SORT_DESC,$titles,$status,$current,$totals,$units);

...and then the most recent manga entry should always be the 16th one (since the recent anime feeds list 15 entries). It's not as elegant, but it works.

Nope, it doesn't work for me, when I use it, sig only displays anime entries.

saka said:
You could duplicate the preg_match_all lines and parse the anime and manga buffers separately instead of the combined one... You'd need to make some new array names, or make the titles[], status[] etc arrays two dimensional.

Hmm I understand what what you mean, but my low PHP skill doesn't allow me to use that.

Well I'll stick with what I've got now, still it's not so bad :P
 
07-04-09, 5:13 PM

Offline
Joined: May 2008
Posts: 4614
works for me... Try this code:
http://pastebin.com/m361654e1

the titles array comes out like this, where 0-14 are anime and 15+ are manga:


these are the lines i changed, which might be helpful:
http://pastebin.com/pastebin.php?diff=m361654e1
 
07-05-09, 7:41 AM

Offline
Joined: Apr 2008
Posts: 262
Hmm that seems to work nicely, thanks for help ^^
 
07-05-09, 8:31 AM

Offline
Joined: Feb 2008
Posts: 4533
saka 1 - php 0
 
07-10-09, 4:38 AM

Offline
Joined: Apr 2008
Posts: 262
Small change in code:

if ($status[$i] == "Watching" or $status[$i] == "Re-Watching" or $status[$i] == "Reading" or $status[$i] == "Re-Reading") {


Without this, sig won't display amount of manga chapters
Modified by Silmoren, 07-16-09, 2:53 AM
 
07-11-09, 3:36 PM

Offline
Joined: May 2008
Posts: 4614
Thanks for mentioning that. This has been pointed out before so I've updated it in the code.

Since with dual feeds its more likely people will list lots of statuses, I've changed it to an in_array() call so that you don't need to keep writing " or $status[$i] == " every time. I encourage people to change the formatting bits any way they'd like.

Here's the diff:
 
07-15-09, 12:40 PM

Offline
Joined: Feb 2009
Posts: 6
saka said:

kuroshiroi said:
I'm considering switching over to your script, I'd need to incorporate some minor changes but overall, it does what I need. I'm assuming it actually works with 000webhost's cron jobs?

there shouldn't be any problem. something like this should do it:


is that how you did it? I tried to create a cron job exactly like that, but it doesn't update. I have to manually visit the php file to get my cache pic to update, so I know that is working.

mine looks like this and yes, I added it (just in case anyone asked)


any idea what I could be doing wrong?
Modified by yogknight, 07-15-09, 12:45 PM
 
07-15-09, 2:46 PM

Offline
Joined: May 2008
Posts: 4614
make sure the second field starts with public_html since the path should contain that. I'm not sure how it was left out of my screenie from earlier, but it should be there. So the second field for you would be:
public_html/myanimelist/sig_creator2.php
 
07-15-09, 9:22 PM

Offline
Joined: Feb 2009
Posts: 6
saka said:
make sure the second field starts with public_html since the path should contain that. I'm not sure how it was left out of my screenie from earlier, but it should be there. So the second field for you would be:
public_html/myanimelist/sig_creator2.php


it's still not updating, maybe that was just part of the problem
I've tried playing around with the check_cache function, to see if that was the problem, but no luck there
 
07-15-09, 11:26 PM

Offline
Joined: May 2008
Posts: 4614
check_cache() will just prevent the sig from updating more frequently than once every X minutes. If your cron job is set to visit it every ten minutes, then you should still see the updates after that 10 minutes (or the cache time, whichever is greater).

The script seems to be generating it properly, so it must be a problem with the cronjob and not the script. The settings you showed should work though... are you sure it isn't working? Try making an anime update, then wait 20 mins and check the cache image.

There are also alternatives to using cron, such as using MAL Updater's php signature plugin to visit the url.
 
07-16-09, 12:02 PM

Offline
Joined: Aug 2008
Posts: 182
I used the script posted on the first page (this), the anime and manga merged one. But I get this error: Parse error: parse error in C:\xampp\htdocs\sig\index4.php on line 62

Does anyone know what to do?
 
07-16-09, 12:05 PM

Offline
Joined: Feb 2009
Posts: 6
thanks for trying to help, but it's still not working

I made a strange discovery though. I tried 3 other cron job sites and tried to point them to my php file url, but the all failed when I tried to set the cron. I think there's something about my php file that cron jobs don't like.

Maybe I gotta make it not output an image, just save it to a the cache. Is there a way to do that?

EDIT: Nevermind, I fixed it, that was exactly the problem
I commented out the
header("Content-type: image/png");
line and BAM, now it works

EDIT2:
False alarm, it still doesn't work. Either it was a one time deal that it updated or someone was messing with me and manually ran my php
Modified by yogknight, 07-16-09, 9:18 PM
 
07-16-09, 12:07 PM

Offline
Joined: Jul 2008
Posts: 107
V3gas said:
I used the script posted on the first page (this), the anime and manga merged one. But I get this error: Parse error: parse error in C:xampphtdocssigindex4.php on line 62

Does anyone know what to do?


in fact there is missing a )

if ( in_array($status[$i], array("Watching", "Re-Watching", "Reading", "Re-Reading") ) {
should be changed to

if ( in_array($status[$i], array("Watching", "Re-Watching", "Reading", "Re-Reading") ) ) {
 
07-16-09, 12:23 PM

Offline
Joined: Aug 2008
Posts: 182
Niroko said:
]should be changed to

if ( in_array($status[$i], array("Watching", "Re-Watching", "Reading", "Re-Reading") ) ) {

Oh. Hahaha, such a small mistake. I guess I didn't look closely enough.

EDIT: Can anyone tell me how to not display Plan to Watch/- Read?
Modified by V3gas, 07-16-09, 1:16 PM
 
Top
Pages (9) [1] 2 3 » ... Last »