PageRenderTime 38ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/exchange/code/trunk/administrator/components/com_exchange/helper.php

https://bitbucket.org/eddieajau/the-art-of-joomla-archive
PHP | 114 lines | 55 code | 8 blank | 51 comment | 4 complexity | 6f30e3a7e182006259e6314c2fbc8134 MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: helper.php 280 2010-09-18 02:14:15Z eddieajau $
  4. * @package NewLifeInIT
  5. * @subpackage com_exchange
  6. * @copyright Copyright 2005 - 2010 New Life in IT Pty Ltd. All rights reserved.
  7. * @license GNU General Public License version 2 or later.
  8. * @link http://www.theartofjoomla.com
  9. */
  10. // no direct access
  11. defined('_JEXEC') or die;
  12. /**
  13. * @package NewLifeInIT
  14. * @subpackage com_exchange
  15. * @since 1.0
  16. */
  17. class ExchangeLog extends JObject
  18. {
  19. /**
  20. * The internal counter for the number of log messages
  21. * @var int
  22. */
  23. private $count;
  24. /**
  25. * An array of messages
  26. * @var array
  27. */
  28. private $logs;
  29. /**
  30. * Constructor
  31. */
  32. function __construct()
  33. {
  34. $this->logs = array();
  35. $this->count = 0;
  36. }
  37. /**
  38. * Singleton method
  39. *
  40. * @return ExchangeLog
  41. */
  42. function &getInstance()
  43. {
  44. static $instance = null;
  45. if ($instance == null) {
  46. $instance = new ExchangeLog;
  47. }
  48. return $instance;
  49. }
  50. /**
  51. * Adds a log message
  52. *
  53. * @param int A code
  54. * @param string A message
  55. * @param boolean True if you are appending to the last message added
  56. */
  57. function add($code, $text, $append = false)
  58. {
  59. $log = &ExchangeLog::getInstance();
  60. if ($append && $log->count > 0) {
  61. $i = $log->count - 1;
  62. $log->logs[$i]['code'] = $code;
  63. $log->logs[$i]['text'] .= $text;
  64. }
  65. else
  66. {
  67. $log->logs[] = array('code' => (int) $code, 'text' => $text);
  68. $log->count++;
  69. }
  70. }
  71. /**
  72. * Output the log as an HTML list
  73. *
  74. * @return string
  75. */
  76. function toHtml()
  77. {
  78. $log = &ExchangeLog::getInstance();
  79. $result = '<ol class="log">';
  80. foreach ($log->logs as $item)
  81. {
  82. $result .= '<li class="c'.$item['code'].'">'.nl2br($item['text']).'</li>';
  83. }
  84. $result .= '</ol>';
  85. return $result;
  86. }
  87. }
  88. /**
  89. * @package jXExchange
  90. */
  91. class XMLHelper
  92. {
  93. /**
  94. * Checks if a string value is boolean true
  95. *
  96. * @param mixed A string or integer value
  97. * @return boolean True is the value is a text or int representation of a boolean
  98. */
  99. function isBool($value)
  100. {
  101. static $bools = array('yes', '1', 'true', 'y');
  102. $needle = strtolower(trim($value));
  103. $result = in_array($needle, $bools);
  104. return $result;
  105. }
  106. }