SigServer DEV

From AniDB
Jump to navigation Jump to search

General

this is the place to contribute ideas on a possible future addition of a special signature picture feature to anidb.

Related forum thread: AniDB Development Forum - SigServer

For other areas of active development on AniDB, check: Development

Vision

AniDB users can create highly personalized signature images which can be used in forum singatures and which acurately reflect user specific or general anidb data. Some examples are:

  • Mylist statistics of the user (Mylist size, latest added, latest watched, total watched, ...)
  • Vote statistics general or user based (Top3 animes, my Top3, worst anime ever, ...)
  • General anidb statistics
  • Group statistics (Latest releases by group X, ...)
  • Anime statistics (percent aired, percent subbed, latest file added, total users, total groups, total files, total eps, ...)
  • ...

The user would not need any webspace to host such images and would not need to update/regenerate them. All signature images would be directly loaded from an AniDB webserver.

The idea is for the sig server to be the middle entity between AniDB and the user, which allows almost any kind of singature pic to be created, according to the personal preferences of the user. As such a lot of attention should go towards the configuration/customization interface of such a feature. We are aware that this is a hell lot of work, but it's the long term goal. The image generation itself is fairly easy.

Basically AniDB will offer all kinds of stats data and more via xml, much more than is currently on offer. The sig server would transparently get it's data from AniDB and the user will be able to pick all kinds of information bits from the available data and position and format it freely on a background pic which he can upload himself. Of course many users wouldn't need this degree of flexibility, so there would need to be some common premade default selections for style/info combinations which are most commonly requested. Furthermore background images could be shared between users.

... if a users feels like having a total mess of a sig pic where every single character is done in a different font type, color and size... why not let him do it? ...

Some examples:

Data

Implementation

General

here a short outline of the way it is supposed to work: (Let's call the new server "sig server" for now)

  • The sig server has it's own user database
  • Users can configure the signature pics via a webinterface of the sig server
  • The sig server provides an url which returns the sig pic
  • When the url is requested the sig server will look for a locally cached pic or cached anidb status information for the user and will either return the cached pic, a new pic created with the cached information or will issue an http request to retrieve the needed stats via as XML and then create the pic.

It is important to underline at this point that the sig server does never directly interact with the anidb database. It does not have SQL access, it does not store the users anidb password (only their anidb username) and it never modifies any information on anidb.

On suggestion for how things could look like (feel free to suggest other ways):

  • AniDB will link to the sig server
  • A first time user will visit the sig server and register a new account (username and password can be different from anidb)
  • Once registered the user gets to a configuration page where he has to enter his anidb username (without the anidb password!) and there will be a help text explaining the required profile settings on anidb for this to work (the anidb XML interface will only provide the information if the user selected certain permissions for the guest user)
  • the user can then either select an image from a selection of publicly available pictures stored on the server or can upload is own picture (for each own picture the user can specify whether it should be made public or not (needs mod review)).
  • once a picture is selected the user can select the type of data shown and the formatting from predefined profiles or can define his own profile (profile can be made public)
  • a profile should be very configurable, allowing selections like:
    • information to display
    • font/size/color/location/... for each part
    • maybe some kind of basic scripting
  • one user should be able to specify upto N signature picture+profile combinations which can all be active at the same time (maybe 5 ?)
  • some nice statistics and a modding interface would be good

Hosting

We have a dedicated server ready for hosting this feature. Restrictions:

  • Database related code should be able to work with PostgreSQL AND MySQL
    • Just to be clear - You will NOT have access to the AniDB database via SQL. As such you're free to come up with your own database schema for the information you need to store. All AniDB data you need will be available as XML via HTTP GET requests.
    • The SigServer will require a separate signup and will not make use of the AniDB user account data.
  • Currently the server only runs PHP4 Php Info, but PHP5 could be installed.

Data Retrieval

The SigServer will receive the required data by making HTTP GET requests to the main anidb server and by getting XML replies. Here are some examples.

CAUTION! - Don't access these urls more than one or twice a day or you will get yourself an automatic 24h ban!

The mylist export documentation may be helpful in understanding the meaning of the different fields in the XML replies: Mylist_export_template_guidelines

Feature Requests

  • add requests for additional data here
  • Latest watched files. - antennen
  • Feed for resolving UserID etc. - antennen
  • Latest votes - for each anime, tmp, episodes, groups, reviews --Suppy 18:13, 28 April 2007 (UTC)
  • Top votes - for each anime, tmp, episodes, groups, reviews --Suppy 18:13, 28 April 2007 (UTC)

XML Parsing

To use the XML replies from the server, they have to be parsed and probably cached.

To parse the XML, standard php-commands can be used.

A working example for xml.xml with the output array stack():

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Load and parse XML
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

$file = "xml.xml";
$stack = array();

// start_element_handler ( resource parser, string name, array attribs )
function startElement($parser, $name, $attribs)
{
   global $stack;
   $tag=array("name"=>$name,"attribs"=>$attribs);
   array_push($stack,$tag);
}

// end_element_handler ( resource parser, string name )
function endElement($parser, $name)
{
   global $stack;
   $stack[count($stack)-2]['children'][] = $stack[count($stack)-1];
   array_pop($stack);
}

// handler ( resource parser, string data )
function characterData($parser, $data)
{
   global $stack,$i;
  
  
   if(trim($data))
   { 
             $stack[count($stack)-1]['data'] .= $data; 
   }
}
// handler ( resource parser, string target, string data )

function defaultHandler($parser, $data)
{
  
}

function externalEntityRefHandler($parser, $openEntityNames, $base, $systemId,
                                 $publicId) {
   if ($systemId) {
       if (!list($parser, $fp) = new_xml_parser($systemId)) {
           printf("Could not open entity %s at %s\n", $openEntityNames,
                   $systemId);
           return false;
       }
       while ($data = fread($fp, 4096)) {
           if (!xml_parse($parser, $data, feof($fp))) {
               printf("XML error: %s at line %d while parsing entity %s\n",
                       xml_error_string(xml_get_error_code($parser)),
                       xml_get_current_line_number($parser), $openEntityNames);
               xml_parser_free($parser);
               return false;
           }
       }
       xml_parser_free($parser);
       return true;
   }
   return false;
}

function new_xml_parser($file)
{
   global $parser_file;
   $xml_parser = xml_parser_create();
  
   xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0);
  
   xml_set_processing_instruction_handler($xml_parser, "PIHandler");
  
   xml_set_element_handler($xml_parser, "startElement", "endElement");
  
   xml_set_character_data_handler($xml_parser, "characterData");
  
   xml_set_default_handler($xml_parser, "defaultHandler");
  
   xml_set_external_entity_ref_handler($xml_parser, "externalEntityRefHandler");
 
   if (!($fp = @fopen($file, "r"))) {
       return false;
   }
   if (!is_array($parser_file)) {
       settype($parser_file, "array");
   }
   $parser_file[$xml_parser] = $file;
   return array($xml_parser, $fp);
}

if (!(list($xml_parser, $fp) = new_xml_parser($file))) {
   die("could not open XML input");
}

//ERROR
while ($data = fread($fp, 4096)) {
   if (!xml_parse($xml_parser, $data, feof($fp))) {
       die(sprintf("XML error: %s at line %d\n",
                   xml_error_string(xml_get_error_code($xml_parser)),
                   xml_get_current_line_number($xml_parser)));
   }
}
//END
xml_parser_free($xml_parser);