com.lokorin.lokorin.lib
[ class tree: com.lokorin.lokorin.lib ] [ index: com.lokorin.lokorin.lib ] [ all elements ]

Source for file lib_dkpbank.php

Documentation is available at lib_dkpbank.php

  1. <?php
  2. /*
  3. * Lokorin.com
  4. * Copyright 2004-2006
  5. * Licensed under the GNU LGPL. See COPYING for full terms.
  6. */
  7. /**
  8. * A library that contains resources related to the DKP Bank balance
  9. * recordings.
  10. * @author Andreas Launila
  11. * @version $Revision: 1.11 $
  12. * @package com.lokorin.lokorin.lib
  13. * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
  14. */
  15.  
  16. /**
  17. * For access to common constants and functions.
  18. */
  19. require_once('common.php');
  20.  
  21. /**
  22. * The names of all the members that should be ignored while taking snapshots.
  23. * The names are comma delimited.
  24. * @var string
  25. * @access private
  26. */
  27. define('IGNORED_MEMBERS', 'Rott');
  28.  
  29. /**
  30. * Performs a snapshot of the Europa EQDKP standings. It records all members'
  31. * current points and the total balance in the database.
  32. * @throws IOException If something went wrong when performing the snapshot.
  33. * @access public
  34. */
  35. function performDkpSnapshot() {
  36. global $db;
  37. $errno = $errstr = '';
  38. $fp = fsockopen("www.europaguild.net", 80, $errno, $errstr, 5);
  39. if(!$fp) {
  40. //An error occured while connecting
  41. throw new IOException($errstr.' ('.$errno.')');
  42. } else {
  43. //Set header
  44. $out = "GET /eqdkp/listmembers.php?s= HTTP/1.1\r\n";
  45. $out .= "Host: www.europaguild.net\r\n";
  46. $out .= "Cookie: eqdkp_data=a%3A2%3A%7Bs%3A13%3A%22auto_login_id%22%3Bs%3A32%3A%22332db7088291c743cfad6a828c3604c8%22%3Bs%3A7%3A%22user_id%22%3Bs%3A3%3A%22348%22%3B%7D\r\n";
  47. $out .=" Connection: Close\r\n\r\n";
  48. $lines = array();
  49. fwrite($fp, $out);
  50. while(!feof($fp)) {
  51. $lines[] = trim(fgets($fp, 256));
  52. }
  53. fclose($fp);
  54. }
  55. //Remove the html functionality, translate it to plain text
  56. //$document = preg_replace('/&lt;.+?&gt;/s', '', htmlspecialchars(implode("\n", $lines)));
  57. $matches = array();
  58. preg_match_all('/\n\d+\n(\w+)\n[ \w]+\n\d+\n.+?\n.+?\n.+?\n.+?\n([\d\.\-]+)/',
  59. strip_tags(implode("\n", $lines)), $matches);
  60. $names = $matches[1];
  61. $points = $matches[2];
  62. //Remove all members that should be ignored from the snapshot.
  63. $ignoredNames = explode(',', IGNORED_MEMBERS);
  64. foreach($ignoredNames as $memberName) {
  65. $id = array_search($memberName, $names);
  66. if($id !== false) {
  67. unset($names[$id]);
  68. unset($points[$id]);
  69. }
  70. }
  71.  
  72. $totalPoints = array_sum($points);
  73. if($totalPoints == 0) {
  74. //No points were recorded, there was probably a connection problem.
  75. return false;
  76. }
  77.  
  78. $vars = array(
  79. 'timestamp' => time(),
  80. 'points' => array_sum($points)
  81. );
  82.  
  83. //Insert the global snapshot.
  84. $db->queryInsert(TABLE_DKPBANK, $vars);
  85. $snapshotId = $db->getLastInsertId(TABLE_DKPBANK, 'id');
  86. //Insert the individual recordings.
  87. foreach($names as $id => $name) {
  88. $vars = array(
  89. 'snapshot_id' => $snapshotId,
  90. 'name' => $name,
  91. 'points' => $points[$id]
  92. );
  93. $db->queryInsert(TABLE_DKPBANK_MEMBERS, $vars);
  94. }
  95. }
  96. ?>

Documentation generated on Sun, 16 Apr 2006 21:03:19 +0200 by phpDocumentor 1.3.0RC4