bootstrap.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. error_reporting( E_ALL | E_STRICT );
  3. // change this, if your php files and data is outside of your webservers document root
  4. if (!defined('PATH')) define('PATH', '..' . DIRECTORY_SEPARATOR);
  5. if (!defined('PUBLIC_PATH')) define('PUBLIC_PATH', '..');
  6. require PATH . 'lib/auto.php';
  7. class helper
  8. {
  9. /**
  10. * example ID of a paste
  11. *
  12. * @var string
  13. */
  14. private static $pasteid = '5e9bc25c89fb3bf9';
  15. /**
  16. * example paste
  17. *
  18. * @var array
  19. */
  20. private static $paste = array(
  21. 'data' => '{"iv":"EN39/wd5Nk8HAiSG2K5AsQ","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"QKN1DBXe5PI","ct":"8hA83xDdXjD7K2qfmw5NdA"}',
  22. 'meta' => array(
  23. 'postdate' => 1344803344,
  24. 'opendiscussion' => true,
  25. 'formatter' => 'plaintext',
  26. 'attachment' => '{"iv":"Pd4pOKWkmDTT9uPwVwd5Ag","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"ZIUhFTliVz4","ct":"6nOCU3peNDclDDpFtJEBKA"}',
  27. 'attachmentname' => '{"iv":"76MkAtOGC4oFogX/aSMxRA","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"ZIUhFTliVz4","ct":"b6Ae/U1xJdsX/+lATud4sQ"}',
  28. ),
  29. );
  30. /**
  31. * example ID of a comment
  32. *
  33. * @var string
  34. */
  35. private static $commentid = '5a52eebf11c4c94b';
  36. /**
  37. * example comment
  38. *
  39. * @var array
  40. */
  41. private static $comment = array(
  42. 'data' => '{"iv":"Pd4pOKWkmDTT9uPwVwd5Ag","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"ZIUhFTliVz4","ct":"6nOCU3peNDclDDpFtJEBKA"}',
  43. 'meta' => array(
  44. 'nickname' => '{"iv":"76MkAtOGC4oFogX/aSMxRA","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"ZIUhFTliVz4","ct":"b6Ae/U1xJdsX/+lATud4sQ"}',
  45. 'vizhash' => 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABGUlEQVQokWOsl5/94983CNKQMjnxaOePf98MeKwPfNjkLZ3AgARab6b9+PeNEVnDj3/ff/z7ZiHnzsDA8Pv7H2TVPJw8EAYLAwb48OaVgIgYKycLsrYv378wMDB8//qdCVMDRA9EKSsnCwRBxNsepaLboMFlyMDAICAi9uHNK24GITQ/MDAwoNhgIGMLtwGrzegaLjw5jMz9+vUdnN17uwDCQDhJgk0O07yvX9+teDX1x79v6DYIsIjgcgMaYGFgYOBg4kJx2JejkAiBxAw+PzAwMNz4dp6wDXDw4MdNNOl0rWYsNkD89OLXI/xmo9sgzatJjAYmBgYGDiauD3/ePP18nVgb4MF89+M5ZX6js293wUMpnr8KTQMAxsCJnJ30apMAAAAASUVORK5CYII=',
  46. 'postdate' => 1344803528,
  47. ),
  48. );
  49. /**
  50. * get example paste ID
  51. *
  52. * @return string
  53. */
  54. public static function getPasteId()
  55. {
  56. return self::$pasteid;
  57. }
  58. /**
  59. * get example paste
  60. *
  61. * @return array
  62. */
  63. public static function getPaste($meta = array())
  64. {
  65. $example = self::$paste;
  66. $example['meta'] = array_merge($example['meta'], $meta);
  67. return $example;
  68. }
  69. /**
  70. * get example paste ID
  71. *
  72. * @return string
  73. */
  74. public static function getCommentId()
  75. {
  76. return self::$commentid;
  77. }
  78. /**
  79. * get example comment
  80. *
  81. * @return array
  82. */
  83. public static function getComment($meta = array())
  84. {
  85. $example = self::$comment;
  86. $example['meta'] = array_merge($example['meta'], $meta);
  87. return $example;
  88. }
  89. /**
  90. * delete directory and all its contents recursively
  91. *
  92. * @param string $path
  93. * @throws Exception
  94. */
  95. public static function rmdir($path)
  96. {
  97. $path .= DIRECTORY_SEPARATOR;
  98. $dir = dir($path);
  99. while(false !== ($file = $dir->read())) {
  100. if($file != '.' && $file != '..') {
  101. if(is_dir($path . $file)) {
  102. self::rmdir($path . $file);
  103. } elseif(is_file($path . $file)) {
  104. if(!@unlink($path . $file)) {
  105. throw new Exception('Error deleting file "' . $path . $file . '".');
  106. }
  107. }
  108. }
  109. }
  110. $dir->close();
  111. if(!@rmdir($path)) {
  112. throw new Exception('Error deleting directory "' . $path . '".');
  113. }
  114. }
  115. /**
  116. * create ini file
  117. *
  118. * @param string $pathToFile
  119. * @param array $values
  120. */
  121. public static function createIniFile($pathToFile, $values)
  122. {
  123. if (count($values)) {
  124. @unlink($pathToFile);
  125. $ini = fopen($pathToFile, 'a');
  126. foreach ($values as $section => $options) {
  127. fwrite($ini, "[$section]" . PHP_EOL);
  128. foreach($options as $option => $setting) {
  129. if (is_null($setting)) {
  130. continue;
  131. } elseif (is_string($setting)) {
  132. $setting = '"' . $setting . '"';
  133. } else {
  134. $setting = var_export($setting, true);
  135. }
  136. fwrite($ini, "$option = $setting" . PHP_EOL);
  137. }
  138. fwrite($ini, PHP_EOL);
  139. }
  140. fclose($ini);
  141. }
  142. }
  143. /**
  144. * a var_export that returns arrays without line breaks
  145. * by linus@flowingcreativity.net via php.net
  146. *
  147. * @param mixed $var
  148. * @param bool $return
  149. * @return void|string
  150. */
  151. public static function var_export_min($var, $return = false)
  152. {
  153. if (is_array($var)) {
  154. $toImplode = array();
  155. foreach ($var as $key => $value) {
  156. $toImplode[] = var_export($key, true) . ' => ' . self::var_export_min($value, true);
  157. }
  158. $code = 'array(' . implode(', ', $toImplode) . ')';
  159. if ($return) {
  160. return $code;
  161. } else {
  162. echo $code;
  163. }
  164. } else {
  165. return var_export($var, $return);
  166. }
  167. }
  168. }