ManiaLib 1.0b1 API Reference

Source for file standardManiacode.php

Documentation is available at standardManiacode.php

  1. <?php
  2. /**
  3.  * @author Philippe Melot
  4.  * @copyright 2009-2010 NADEO
  5.  * @package ManiaLib
  6.  */
  7.  
  8. /**
  9.  * Maniacode Toolkit base component
  10.  * @package ManiaLib
  11.  * @subpackage ManiacodeToolkit
  12.  */
  13. abstract class ManiacodeComponent
  14. {
  15.     /**#@+
  16.      * @ignore
  17.      */
  18.     protected $xmlTagName;
  19.     protected $xml;
  20.     protected $name;
  21.     /**#@-*/
  22.     
  23.     /**
  24.      * This method sets the Name of the file once download
  25.      *
  26.      * @param string $name The name of the file once download
  27.      * @return void 
  28.      *
  29.      */
  30.     function setName($name)
  31.     {
  32.         $this->name $name;
  33.     }
  34.     
  35.     /**
  36.      * This method gets the Name of the element
  37.      *
  38.      * @return string This return the name of the file once download
  39.      *
  40.      */
  41.     function getName()
  42.     {
  43.         return $this->name;
  44.     }
  45.     
  46.     protected function preFilter({}
  47.     protected function postFilter({}
  48.     
  49.     final function save()
  50.     {    
  51.         $this->preFilter();
  52.         
  53.         $this->xml Maniacode::$domDocument->createElement($this->xmlTagName);
  54.         end(Maniacode::$parentNodes)->appendChild($this->xml);
  55.         
  56.         if (isset($this->name))
  57.         {
  58.             $elem  Maniacode::$domDocument->createElement('name');
  59.             $value Maniacode::$domDocument->createTextNode($this->name);
  60.             $elem->appendChild($value);
  61.             $this->xml->appendChild($elem);
  62.         }
  63.         
  64.         $this->postFilter();
  65.     }
  66. }
  67.  
  68. /**
  69.  * File download
  70.  * @package ManiaLib
  71.  * @subpackage ManiacodeToolkit
  72.  */
  73. abstract class FileDownload extends ManiacodeComponent
  74. {
  75.     /**#@+
  76.      * @ignore
  77.      */
  78.     protected $url;
  79.     /**#@-*/
  80.     
  81.     function __construct($name ''$url  '')
  82.     {
  83.         $this->name $name;
  84.         $this->url $url;
  85.     }
  86.     
  87.     /**
  88.      * This method sets the url to download the file
  89.      *
  90.      * @param string $url The url to download the file
  91.      * @return void 
  92.      *
  93.      */
  94.     function setUrl($url)
  95.     {
  96.         $this->url $url;
  97.     }
  98.     
  99.     /**
  100.      * This method gets the Url of the element
  101.      *
  102.      * @return void 
  103.      *
  104.      */
  105.     function getUrl()
  106.     {
  107.         return $this->url;
  108.     }
  109.     
  110.     protected function postFilter()
  111.     {
  112.         if (isset($this->url))
  113.         {
  114.             $elem  Maniacode::$domDocument->createElement('url');
  115.             $value Maniacode::$domDocument->createTextNode($this->url);
  116.             $elem->appendChild($value);
  117.             $this->xml->appendChild($elem);
  118.         }
  119.     }
  120. }
  121.  
  122. /**
  123.  * Install track
  124.  * @package ManiaLib
  125.  * @subpackage ManiacodeToolkit
  126.  */
  127. class InstallTrack extends FileDownload
  128. {
  129.     /**
  130.      * @ignore
  131.      */
  132.     protected $xmlTagName 'install_track';
  133.     
  134.     function __construct($name=''$url='')
  135.     {
  136.         parent::__construct($name$url);
  137.     }
  138. }
  139.  
  140. /**
  141.  * Play track
  142.  * @package ManiaLib
  143.  * @subpackage ManiacodeToolkit
  144.  */
  145. class PlayTrack extends FileDownload
  146. {
  147.     /**
  148.      * @ignore
  149.      */
  150.     protected $xmlTagName 'play_track';
  151.     
  152.     function __construct($name=''$url='')
  153.     {
  154.         parent::__construct($name$url);
  155.     }
  156. }
  157.  
  158. /**
  159.  * Package track
  160.  * Use it only with InstallTrackPack
  161.  * @package ManiaLib
  162.  * @subpackage ManiacodeToolkit
  163.  */
  164. class PackageTrack extends FileDownload
  165. {
  166.     /**
  167.      * @ignore
  168.      */
  169.     protected $xmlTagName 'track';
  170.     
  171.     function __construct($name=''$url='')
  172.     {
  173.         parent::__construct($name$url);
  174.     }
  175. }
  176.  
  177. /**
  178.  * Install track pack
  179.  * @package ManiaLib
  180.  * @subpackage ManiacodeToolkit
  181.  */
  182. {
  183.     /**#@+
  184.      * @ignore
  185.      */
  186.     protected $xmlTagName 'install_track_pack';
  187.     protected $tracks array();
  188.     /**#@-*/
  189.     
  190.     function __construct($name='')
  191.     {
  192.         $this->name $name;
  193.     }
  194.  
  195.     function addTrack($name '',  $url '')
  196.     {
  197.         $this->tracks[new PackageTrack($name$url);
  198.     }
  199.     
  200.     function getLastInsert()
  201.     {
  202.         return end($this->tracks);
  203.     }
  204.     
  205.     protected function postFilter()
  206.     {
  207.         if (isset($this->tracks&& is_array($this->tracks&& count($this->tracks))
  208.         {
  209.             foreach ($this->tracks as $track)
  210.             {
  211.                 $track->save();
  212.             }
  213.         }
  214.     }
  215. }
  216.  
  217. /**
  218.  * Install replay
  219.  * @package ManiaLib
  220.  * @subpackage ManiacodeToolkit
  221.  */
  222. class InstallReplay extends FileDownload
  223. {
  224.     /**
  225.      * @ignore
  226.      */
  227.     protected $xmlTagName 'install_replay';
  228.     
  229.     function __construct($name=''$url='')
  230.     {
  231.         parent::__construct($name$url);
  232.     }
  233. }
  234.  
  235. /**
  236.  * View replay
  237.  * @package ManiaLib
  238.  * @subpackage ManiacodeToolkit
  239.  */
  240. class ViewReplay extends FileDownload
  241. {
  242.     /**
  243.      * @ignore
  244.      */
  245.     protected $xmlTagName 'view_replay';
  246.     
  247.     function __construct($name=''$url='')
  248.     {
  249.         parent::__construct($name$url);
  250.     }
  251. }
  252.  
  253. /**
  254.  * Play replay
  255.  * @package ManiaLib
  256.  * @subpackage ManiacodeToolkit
  257.  */
  258. class PlayReplay extends FileDownload
  259. {
  260.     /**
  261.      * @ignore
  262.      */
  263.     protected $xmlTagName 'play_replay';
  264.     
  265.     function __construct($name=''$url='')
  266.     {
  267.         parent::__construct($name$url);
  268.     }
  269. }
  270.  
  271. /**
  272.  * Install skin
  273.  * @package ManiaLib
  274.  * @subpackage ManiacodeToolkit
  275.  */
  276. class InstallSkin extends FileDownload
  277. {
  278.     /**#@+
  279.      * @ignore
  280.      */
  281.     protected $xmlTagName 'install_skin';
  282.     protected $file;
  283.     /**#@-*/
  284.     
  285.     function __construct($name=''$file=''$url='')
  286.     {
  287.         parent::__construct($name$url);
  288.         $this->setFile($file);
  289.     }
  290.     
  291.     /**
  292.      * This method sets the path to install the skin
  293.      *
  294.      * @param string $file The path to the skin
  295.      * @return void 
  296.      *
  297.      */
  298.     public function setFile($file)
  299.     {
  300.         $this->file $file;
  301.     }
  302.     
  303.     /**
  304.      * This method gets the path to install the skin
  305.      *
  306.      * @return string The path to the skin
  307.      *
  308.      */
  309.     public function getFile()
  310.     {
  311.         return $this->file;
  312.     }
  313.     
  314.     protected  function postFilter()
  315.     {
  316.         if (isset($this->file))
  317.         {
  318.             $elem  Maniacode::$domDocument->createElement('file');
  319.             $value Maniacode::$domDocument->createTextNode($this->file);
  320.             $elem->appendChild($value);
  321.             $this->xml->appendChild($elem);
  322.         }
  323.     }
  324. }
  325.  
  326. /**
  327.  * Get skin
  328.  * @package ManiaLib
  329.  * @subpackage ManiacodeToolkit
  330.  */
  331. class GetSkin extends InstallSkin
  332. {
  333.     /**
  334.      * @ignore
  335.      */
  336.     protected $xmlTagName 'get_skin';
  337.     
  338.     function __construct($name=''$file=''$url='')
  339.     {
  340.         parent::__construct($name$file$url);
  341.     }
  342. }
  343.  
  344. /**
  345.  * Show message
  346.  * @package ManiaLib
  347.  * @subpackage ManiacodeToolkit
  348.  */
  349. {
  350.     /**#@+
  351.      * @ignore
  352.      */
  353.     protected $xmlTagName 'show_message';
  354.     protected $message;
  355.     /**#@-*/
  356.     
  357.     function __construct($message 'This is a default message provided by Manialib')
  358.     {
  359.         $this->setMessage($message);
  360.     }
  361.     
  362.     function setMessage($message)
  363.     {
  364.         $this->message $message;
  365.     }
  366.     
  367.     function getMessage()
  368.     {
  369.         return $this->message;
  370.     }
  371.     
  372.     function postFilter()
  373.     {
  374.         if ($this->message)
  375.         {
  376.             $elem  Maniacode::$domDocument->createElement('message');
  377.             $value Maniacode::$domDocument->createTextNode($this->message);
  378.             $elem->appendChild($value);
  379.             $this->xml->appendChild($elem);
  380.         }
  381.     }
  382. }
  383.  
  384. /**
  385.  * Goto link
  386.  * @package ManiaLib
  387.  * @subpackage ManiacodeToolkit
  388.  */
  389. class GotoLink extends ManiacodeComponent
  390. {
  391.     /**#@+
  392.      * @ignore
  393.      */
  394.     protected $xmlTagName 'goto';
  395.     protected $link;
  396.     /**#@-*/
  397.     
  398.     function __construct($link 'manialib')
  399.     {
  400.         $this->setLink($link);
  401.     }
  402.     
  403.     function setLink($link)
  404.     {
  405.         $this->link $link;
  406.     }
  407.     
  408.     function getLink()
  409.     {
  410.         return $this->link;
  411.     }
  412.     
  413.     protected function postFilter()
  414.     {
  415.         if (isset($this->link))
  416.         {
  417.             $elem  Maniacode::$domDocument->createElement('link');
  418.             $value Maniacode::$domDocument->createTextNode($this->link);
  419.             $elem->appendChild($value);
  420.             $this->xml->appendChild($elem);
  421.         }
  422.     }
  423. }
  424.  
  425. /**
  426.  * Join server
  427.  * @package ManiaLib
  428.  * @subpackage ManiacodeToolkit
  429.  */
  430. {
  431.     /**#@+
  432.      * Connection type
  433.      */
  434.     const PLAY = 1;
  435.     const SPEC = 2;
  436.     const REFEREE = 3;
  437.     /**#@-*/
  438.     
  439.     /**#@+
  440.      * @ignore
  441.      */
  442.     protected $xmlTagName 'join_server';
  443.     protected $ip;
  444.     protected $password;
  445.     protected $connectionType;
  446.     /**#@-*/
  447.     
  448.     function __construct($connectionType self::PLAY)
  449.     {
  450.         $this->connectionType $connectionType;
  451.     }
  452.     
  453.     function setIp($ip)
  454.     {
  455.         $this->ip $ip;
  456.     }
  457.     
  458.     function getIp()
  459.     {
  460.         return $this->ip;
  461.     }
  462.     
  463.     function setPassword($password)
  464.     {
  465.         $this->password $password;
  466.     }
  467.     
  468.     function getPassword()
  469.     {
  470.         return $this->password;
  471.     }
  472.     
  473.     function setConnectionType($connection)
  474.     {
  475.         $this->connectionType $connection;
  476.     }
  477.     
  478.     function getConnectionType()
  479.     {
  480.         return $this->connectionType;
  481.     }
  482.     
  483.     protected function postFilter()
  484.     {
  485.         if (isset($this->ip))
  486.         {
  487.             $elem  Maniacode::$domDocument->createElement('ip');
  488.             $value Maniacode::$domDocument->createTextNode($this->ip);
  489.             $elem->appendChild($value);
  490.             $this->xml->appendChild($elem);
  491.         }
  492.         
  493.         if (isset($this->password))
  494.         {
  495.             $elem  Maniacode::$domDocument->createElement('password');
  496.             $value Maniacode::$domDocument->createTextNode($this->password);
  497.             $elem->appendChild($value);
  498.             $this->xml->appendChild($elem);
  499.         }
  500.         
  501.         if (isset($this->connectionType))
  502.         {
  503.             $elem  Maniacode::$domDocument->createElement('connection_type');
  504.             $value Maniacode::$domDocument->createTextNode($this->connectionType);
  505.             $elem->appendChild($value);
  506.             $this->xml->appendChild($elem);
  507.         }
  508.     }
  509. }
  510.  
  511. /**
  512.  * Add buddy
  513.  * @package ManiaLib
  514.  * @subpackage ManiacodeToolkit
  515.  */
  516. class AddBuddy extends ManiacodeComponent
  517. {
  518.     /**#@+
  519.      * @ignore
  520.      */
  521.     protected $xmlTagName 'add_buddy';
  522.     protected $login;
  523.     /**#@-*/
  524.     
  525.     function __construct($login)
  526.     {
  527.         $this->login $login;
  528.     }
  529.     
  530.     function setLogin($login)
  531.     {
  532.         $this->login $login;
  533.     }
  534.     
  535.     function getLogin()
  536.     {
  537.         return $this->login;
  538.     }
  539.     
  540.     protected function postFilter()
  541.     {
  542.         if (isset($this->login))
  543.         {
  544.             $elem  Maniacode::$domDocument->createElement('login');
  545.             $value Maniacode::$domDocument->createTextNode($this->login);
  546.             $elem->appendChild($value);
  547.             $this->xml->appendChild($elem);
  548.         }
  549.     }
  550. }
  551.  
  552. /**
  553.  * Invite buddy
  554.  * @package ManiaLib
  555.  * @subpackage ManiacodeToolkit
  556.  */
  557. {
  558.     /**#@+
  559.      * @ignore
  560.      */
  561.     protected $xmlTagName 'invite_buddy';
  562.     protected $email;
  563.     /**#@-*/
  564.     
  565.     function __construct($email '')
  566.     {
  567.         $this->email $email;
  568.     }
  569.     
  570.     function setEmail($email)
  571.     {
  572.         $this->email $email;
  573.     }
  574.     
  575.     function getEmail()
  576.     {
  577.         return $this->email;
  578.     }
  579.     
  580.     protected function postFilter()
  581.     {
  582.         if (isset($this->email))
  583.         {
  584.             $elem  Maniacode::$domDocument->createElement('email');
  585.             $value Maniacode::$domDocument->createTextNode($this->email);
  586.             $elem->appendChild($value);
  587.             $this->xml->appendChild($elem);
  588.         }
  589.     }
  590. }
  591.  
  592. /**
  593.  * Add favorite
  594.  * @package ManiaLib
  595.  * @subpackage ManiacodeToolkit
  596.  */
  597. class AddFavourite extends AddBuddy
  598. {
  599.     /**
  600.      * @ignore
  601.      */
  602.     protected $xmlTagName 'add_favourite';
  603.     
  604.     function __construct($login)
  605.     {
  606.         parent::__construct($login);
  607.     }
  608. }
  609.  
  610. ?>