Text.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * @file
  4. * TeamSpeak 3 PHP Framework
  5. *
  6. * $Id: Text.php 06/06/2016 22:27:13 scp@Svens-iMac $
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. * @package TeamSpeak3
  22. * @version 1.1.24
  23. * @author Sven 'ScP' Paulsen
  24. * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
  25. */
  26. /**
  27. * @class TeamSpeak3_Viewer_Text
  28. * @brief Renders nodes used in ASCII-based TeamSpeak 3 viewers.
  29. */
  30. class TeamSpeak3_Viewer_Text implements TeamSpeak3_Viewer_Interface
  31. {
  32. /**
  33. * A pre-defined pattern used to display a node in a TeamSpeak 3 viewer.
  34. *
  35. * @var string
  36. */
  37. protected $pattern = "%0%1 %2\n";
  38. /**
  39. * Returns the code needed to display a node in a TeamSpeak 3 viewer.
  40. *
  41. * @param TeamSpeak3_Node_Abstract $node
  42. * @param array $siblings
  43. * @return string
  44. */
  45. public function fetchObject(TeamSpeak3_Node_Abstract $node, array $siblings = array())
  46. {
  47. $this->currObj = $node;
  48. $this->currSib = $siblings;
  49. $args = array(
  50. $this->getPrefix(),
  51. $this->getCorpusIcon(),
  52. $this->getCorpusName(),
  53. );
  54. return TeamSpeak3_Helper_String::factory($this->pattern)->arg($args);
  55. }
  56. /**
  57. * Returns the ASCII string to display the prefix of the current node.
  58. *
  59. * @return string
  60. */
  61. protected function getPrefix()
  62. {
  63. $prefix = "";
  64. if(count($this->currSib))
  65. {
  66. $last = array_pop($this->currSib);
  67. foreach($this->currSib as $sibling)
  68. {
  69. $prefix .= ($sibling) ? "| " : " ";
  70. }
  71. $prefix .= ($last) ? "\\-" : "|-";
  72. }
  73. return $prefix;
  74. }
  75. /**
  76. * Returns an ASCII string which can be used to display the status icon for a
  77. * TeamSpeak_Node_Abstract object.
  78. *
  79. * @return string
  80. */
  81. protected function getCorpusIcon()
  82. {
  83. return $this->currObj->getSymbol();
  84. }
  85. /**
  86. * Returns a string for the current corpus element which contains the display name
  87. * for the current TeamSpeak_Node_Abstract object.
  88. *
  89. * @return string
  90. */
  91. protected function getCorpusName()
  92. {
  93. return $this->currObj;
  94. }
  95. }