PageRenderTime 39ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/plugins_repo/openXDeliveryLog/plugins/deliveryLog/oxLogConversion/logConversion.delivery.php

https://bitbucket.org/valmy/openx
PHP | 92 lines | 43 code | 10 blank | 39 comment | 3 complexity | 400030df1cfd967555b0018817618613 MD5 | raw file
  1. <?php
  2. /*
  3. +---------------------------------------------------------------------------+
  4. | OpenX v2.8 |
  5. | ========== |
  6. | |
  7. | Copyright (c) 2003-2009 OpenX Limited |
  8. | For contact details, see: http://www.openx.org/ |
  9. | |
  10. | This program is free software; you can redistribute it and/or modify |
  11. | it under the terms of the GNU General Public License as published by |
  12. | the Free Software Foundation; either version 2 of the License, or |
  13. | (at your option) any later version. |
  14. | |
  15. | This program is distributed in the hope that it will be useful, |
  16. | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  17. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
  18. | GNU General Public License for more details. |
  19. | |
  20. | You should have received a copy of the GNU General Public License |
  21. | along with this program; if not, write to the Free Software |
  22. | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
  23. +---------------------------------------------------------------------------+
  24. $Id$
  25. */
  26. /**
  27. * @package Plugin
  28. * @subpackage openxDeliveryLog
  29. */
  30. MAX_Dal_Delivery_Include();
  31. /**
  32. * A function to log conversions.
  33. *
  34. * @param integer $trackerId The ID of the tracker for which the conversion is to be logged.
  35. * @param array $serverRawIp The "raw IP address" value to use for the conversion.
  36. * @param array $aConversion An array of the conversion details, as returned from the
  37. * MAX_trackerCheckForValidAction() function.
  38. * @return array An array...
  39. */
  40. function Plugin_deliveryLog_oxLogConversion_logConversion_Delivery_logConversion($trackerId, $serverRawIp, $aConversion, $okToLog = true)
  41. {
  42. if (!$okToLog) { return false; }
  43. // Initiate the connection to the database (before using mysql_real_escape_string)
  44. OA_Dal_Delivery_connect('rawDatabase');
  45. $table = $GLOBALS['_MAX']['CONF']['table']['prefix'] . 'data_bkt_a';
  46. if (empty($GLOBALS['_MAX']['NOW'])) {
  47. $GLOBALS['_MAX']['NOW'] = time();
  48. }
  49. $time = $GLOBALS['_MAX']['NOW'];
  50. $aValues = array(
  51. 'server_ip' => $serverRawIp,
  52. 'tracker_id' => $trackerId,
  53. 'date_time' => gmdate('Y-m-d H:i:s', $time),
  54. 'action_date_time' => gmdate('Y-m-d H:i:s', $aConversion['dt']),
  55. 'creative_id' => $aConversion['cid'],
  56. 'zone_id' => $aConversion['zid'],
  57. 'ip_address' => $_SERVER['REMOTE_ADDR'],
  58. 'action' => $aConversion['action_type'],
  59. 'window' => $aConversion['window'],
  60. 'status' => $aConversion['status']
  61. );
  62. // Need to also escape identifier as "window" is reserved since PgSQL 8.4
  63. $aFields = array_map('OX_escapeIdentifier', array_keys($aValues));
  64. $aValues = array_map('OX_escapeString', $aValues);
  65. $query = "
  66. INSERT INTO
  67. {$table}
  68. (" . implode(', ', $aFields) . ")
  69. VALUES
  70. ('" . implode("', '", $aValues) . "')
  71. ";
  72. $result = OA_Dal_Delivery_query($query, 'rawDatabase');
  73. if (!$result) {
  74. return false;
  75. }
  76. $aResult = array(
  77. 'server_conv_id' => OA_Dal_Delivery_insertId('rawDatabase', $table, 'server_conv_id'),
  78. 'server_raw_ip' => $serverRawIp
  79. );
  80. return $aResult;
  81. }
  82. ?>