PageRenderTime 55ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/fusionpbx/mod/grammar_edit/config.php

https://github.com/bfritz/fusionpbx
PHP | 172 lines | 88 code | 23 blank | 61 comment | 13 complexity | be8178fb03a0c956dad6b03f75403b91 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. include "root.php";
  22. error_reporting (E_ALL ^ E_NOTICE);
  23. //ob_start("ob_gzhandler");
  24. $applicationname = 'Edit';
  25. $bodyoptions = "";
  26. $dbfilename = "clip.db";
  27. $dbfilepath = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/mod/php_edit/";
  28. //$temp = $_ENV["TEMP"]."\\";
  29. if (is_writable($dbfilepath.$dbfilename)) { //is writable
  30. //use database in current location
  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. //$fullstring = "this is my [tag]dog[/tag]";
  52. //$parsed = get_string_between($fullstring, "[tag]", "[/tag]");
  53. //database connection
  54. try {
  55. //$db = new PDO('sqlite2:example.db'); //sqlite 2
  56. //$db = new PDO('sqlite::memory:'); //sqlite 3
  57. if (!function_exists('phpmd5')) {
  58. function phpmd5($string) {
  59. return md5($string);
  60. }
  61. }
  62. if (!function_exists('phpmd5')) {
  63. function phpunix_timestamp($string) {
  64. return strtotime($string);
  65. }
  66. }
  67. if (!function_exists('phpnow')) {
  68. function phpnow() {
  69. return date('r');
  70. }
  71. }
  72. if (!function_exists('phpleft')) {
  73. function phpleft($string, $num) {
  74. return substr($string, 0, $num);
  75. }
  76. }
  77. if (!function_exists('phpright')) {
  78. function phpright($string, $num) {
  79. return substr($string, (strlen($string)-$num), strlen($string));
  80. }
  81. }
  82. if (!function_exists('phpsqlitedatatype')) {
  83. function phpsqlitedatatype($string, $field) {
  84. //--- Begin: Get String Between start and end characters -----
  85. $start = '(';
  86. $end = ')';
  87. $ini = stripos($string,$start);
  88. if ($ini == 0) return "";
  89. $ini += strlen($start);
  90. $len = stripos($string,$end,$ini) - $ini;
  91. $string = substr($string,$ini,$len);
  92. //--- End: Get String Between start and end characters -----
  93. $strdatatype = '';
  94. $stringarray = split (',', $string);
  95. foreach($stringarray as $lnvalue) {
  96. //$strdatatype .= "-- ".$lnvalue ." ".strlen($lnvalue)." delim ".strrchr($lnvalue, " ")."---<br>";
  97. //$delimpos = stripos($lnvalue, " ");
  98. //$strdatatype .= substr($value,$delimpos,strlen($value))." --<br>";
  99. $fieldlistarray = split (" ", $value);
  100. //$strdatatype .= $value ."<br>";
  101. //$strdatatype .= $fieldlistarray[0] ."<br>";
  102. //echo $fieldarray[0]."<br>\n";
  103. if ($fieldarray[0] == $field) {
  104. //$strdatatype = $fieldarray[1]." ".$fieldarray[2]." ".$fieldarray[3]." ".$fieldarray[4]; //strdatatype
  105. }
  106. unset($fieldarray, $string, $field);
  107. }
  108. //$strdatatype = $string;
  109. return $strdatatype;
  110. }
  111. } //end function
  112. $db = new PDO('sqlite:'.$dbfilepath.$dbfilename); //sqlite 3
  113. //bool PDO::sqliteCreateFunction ( string function_name, callback callback [, int num_args] )
  114. $db->sqliteCreateFunction('md5', 'phpmd5', 1);
  115. //$db->sqliteCreateFunction('unix_timestamp', 'phpunix_timestamp', 1);
  116. $db->sqliteCreateFunction('now', 'phpnow', 0);
  117. $db->sqliteCreateFunction('sqlitedatatype', 'phpsqlitedatatype', 2);
  118. $db->sqliteCreateFunction('strleft', 'phpleft', 2);
  119. $db->sqliteCreateFunction('strright', 'phpright', 2);
  120. }
  121. catch (PDOException $error) {
  122. print "error1: " . $error->getMessage() . "<br/>";
  123. die();
  124. }
  125. if(!function_exists('escapejs')){
  126. function escapejs($strtemp) {
  127. $strtemp = str_replace ("\"", "\\\"", $strtemp); //escape the single quote
  128. //$strtemp = str_replace ("'", "''", $strtemp); //escape the single quote
  129. return $strtemp;
  130. }
  131. }
  132. if(!function_exists('check_str')){
  133. function check_str($strtemp) {
  134. //$strtemp = str_replace ("\$", "\\\$", $strtemp); //escape the single quote
  135. //$strtemp = str_replace ("\'", "''", $strtemp); //escape the single quote
  136. $strtemp = str_replace ("'", "''", $strtemp); //escape the single quote
  137. //echo "strtemp $strtemp";
  138. return $strtemp;
  139. }
  140. }
  141. ?>