PageRenderTime 49ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/fusionpbx/mod/xml_edit/config.php

https://github.com/bfritz/fusionpbx
PHP | 178 lines | 91 code | 19 blank | 68 comment | 15 complexity | b491129ebd40a9b98b1a24cf03b46c76 MD5 | raw file
  1. <?php
  2. /*
  3. FusionPBX
  4. Version: MPL 1.1
  5. The contents of this file are subject to the Mozilla Public License Version
  6. 1.1 (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.mozilla.org/MPL/
  9. Software distributed under the License is distributed on an "AS IS" basis,
  10. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. for the specific language governing rights and limitations under the
  12. License.
  13. The Original Code is FusionPBX
  14. The Initial Developer of the Original Code is
  15. Mark J Crane <markjcrane@fusionpbx.com>
  16. Portions created by the Initial Developer are Copyright (C) 2008-2010
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <markjcrane@fusionpbx.com>
  20. */
  21. error_reporting (E_ALL ^ E_NOTICE);
  22. ob_start("ob_gzhandler");
  23. $applicationname = 'Edit';
  24. $bodyoptions = "";
  25. $dbfilename = "clip.db";
  26. $dbfilepath = PROJECT_PATH."/xml_edit/";
  27. //$temp = $_ENV["TEMP"]."\\";
  28. if (is_writable($dbfilepath.$dbfilename)) { //is writable
  29. //use database in current location
  30. echo "yes";
  31. }
  32. else { //not writable
  33. /*
  34. //running from a non writable location so copy to temp directory
  35. if (file_exists($temp.$dbfilename)) {
  36. $dbfilepath = $temp; //file already exists use existing file
  37. }
  38. else { //file doese not exist
  39. //copy the file to the temp dir
  40. if (copy($dbfilepath.$dbfilename, $temp.$dbfilename)) {
  41. //echo "copy succeeded.\n";
  42. $dbfilepath = $temp;
  43. }
  44. else {
  45. echo "Copy Failed ";
  46. exit;
  47. }
  48. }
  49. */
  50. }
  51. function get_string_between($string, $start, $end){
  52. $string = " ".$string;
  53. $ini = strpos($string,$start);
  54. if ($ini == 0) return "";
  55. $ini += strlen($start);
  56. $len = strpos($string,$end,$ini) - $ini;
  57. return substr($string,$ini,$len);
  58. }
  59. //$fullstring = "this is my [tag]dog[/tag]";
  60. //$parsed = get_string_between($fullstring, "[tag]", "[/tag]");
  61. //database connection
  62. try {
  63. //$db = new PDO('sqlite2:example.db'); //sqlite 2
  64. //$db = new PDO('sqlite::memory:'); //sqlite 3
  65. if (!function_exists('phpmd5')) {
  66. function phpmd5($string) {
  67. return md5($string);
  68. }
  69. }
  70. if (!function_exists('phpmd5')) {
  71. function phpunix_timestamp($string) {
  72. return strtotime($string);
  73. }
  74. }
  75. if (!function_exists('phpnow')) {
  76. function phpnow() {
  77. return date('r');
  78. }
  79. }
  80. if (!function_exists('phpleft')) {
  81. function phpleft($string, $num) {
  82. return substr($string, 0, $num);
  83. }
  84. }
  85. if (!function_exists('phpright')) {
  86. function phpright($string, $num) {
  87. return substr($string, (strlen($string)-$num), strlen($string));
  88. }
  89. }
  90. if (!function_exists('phpsqlitedatatype')) {
  91. function phpsqlitedatatype($string, $field) {
  92. //--- Begin: Get String Between start and end characters -----
  93. $start = '(';
  94. $end = ')';
  95. $ini = stripos($string,$start);
  96. if ($ini == 0) return "";
  97. $ini += strlen($start);
  98. $len = stripos($string,$end,$ini) - $ini;
  99. $string = substr($string,$ini,$len);
  100. //--- End: Get String Between start and end characters -----
  101. $strdatatype = '';
  102. $stringarray = split (',', $string);
  103. foreach($stringarray as $lnvalue) {
  104. //$strdatatype .= "-- ".$lnvalue ." ".strlen($lnvalue)." delim ".strrchr($lnvalue, " ")."---<br>";
  105. //$delimpos = stripos($lnvalue, " ");
  106. //$strdatatype .= substr($value,$delimpos,strlen($value))." --<br>";
  107. $fieldlistarray = split (" ", $value);
  108. //$strdatatype .= $value ."<br>";
  109. //$strdatatype .= $fieldlistarray[0] ."<br>";
  110. //echo $fieldarray[0]."<br>\n";
  111. if ($fieldarray[0] == $field) {
  112. //$strdatatype = $fieldarray[1]." ".$fieldarray[2]." ".$fieldarray[3]." ".$fieldarray[4]; //strdatatype
  113. }
  114. unset($fieldarray, $string, $field);
  115. }
  116. //$strdatatype = $string;
  117. return $strdatatype;
  118. }
  119. } //end function
  120. /*
  121. $db = new PDO('sqlite:'.$dbfilepath.$dbfilename); //sqlite 3
  122. //bool PDO::sqliteCreateFunction ( string function_name, callback callback [, int num_args] )
  123. $db->sqliteCreateFunction('md5', 'phpmd5', 1);
  124. //$db->sqliteCreateFunction('unix_timestamp', 'phpunix_timestamp', 1);
  125. $db->sqliteCreateFunction('now', 'phpnow', 0);
  126. $db->sqliteCreateFunction('sqlitedatatype', 'phpsqlitedatatype', 2);
  127. $db->sqliteCreateFunction('strleft', 'phpleft', 2);
  128. $db->sqliteCreateFunction('strright', 'phpright', 2);
  129. */
  130. }
  131. catch (PDOException $error) {
  132. print "error: " . $error->getMessage() . "<br/>";
  133. die();
  134. }
  135. if(!function_exists('escapejs')){
  136. function escapejs($strtemp) {
  137. $strtemp = str_replace ("\"", "\\\"", $strtemp); //escape the single quote
  138. //$strtemp = str_replace ("'", "''", $strtemp); //escape the single quote
  139. return $strtemp;
  140. }
  141. }
  142. if(!function_exists('check_str')){
  143. function check_str($strtemp) {
  144. //$strtemp = str_replace ("\$", "\\\$", $strtemp); //escape the single quote
  145. //$strtemp = str_replace ("\'", "''", $strtemp); //escape the single quote
  146. $strtemp = str_replace ("'", "''", $strtemp); //escape the single quote
  147. //echo "strtemp $strtemp";
  148. return $strtemp;
  149. }
  150. }
  151. ?>