bootstrap.php 6.2 KB

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