} } // Twitter Query Handling if (isset($params['twquery'])) { $twQueryParamsSet = array(); $twQueryParamsSet = explodeQuery($params['twquery']); $index = 0; foreach ($twQueryParamsSet as $twQueryParams) { $index++; makeTwitterQuery($socialWall, $twQueryParams); } } // Instagram Query Handling if (isset($params['inquery'])) { $inQueryParamsSet = array(); $inQueryParamsSet = explodeQuery($params['inquery']); $index = 0; foreach ($inQueryParamsSet as $inQueryParams) { $index++; makeInstagramQuery($socialWall, $inQueryParams); } } //$jsonResult = json_encode($result); //echo $jsonResult; /* ========================================= */ function explodeQuery($query) { $queryArray = array(); $queryArray = explode(";", $query); $index = 0; foreach ($queryArray as $singleQuery) {
function manageQuery($input) { $input = str_replace('\\"', '"', $input); $querycount = 1; $querylist = 0; $querytab = array(); while (preg_match('#(?:.*"){' . $querycount . '}([^"]+)".*$#isU', $input)) { $querytab[$querylist] = preg_replace('#(?:.*"){' . $querycount . '}([^"]+)".*$#isU', '$1', $input); $querycount = $querycount + 2; $querylist++; } foreach ($querytab as $key => $val) { if ($querytab[$key] == $input) { unset($querytab[$key]); } else { $querytab[$key] = explodeQuery($querytab[$key]); $querytab[$key] = '%' . $querytab[$key] . '%'; } } if ($querytab == array()) { $querytab = ''; } $inputwthquote = preg_replace('#"[^"]+"#isU', '', $input); $inputwthquote = explodeQuery($inputwthquote); $inputs = explode(' ', $inputwthquote); foreach ($inputs as $key => $val) { if ($val == '') { unset($inputs[$key]); } else { $inputs[$key] = preg_replace('#(^ | $)#', '', $val); $inputs[$key] = '%' . $inputs[$key] . '%'; } } $finputs = implode(' ', $inputs); $fqueryt = ''; if ($querytab) { $fqueryt = implode(' ', $querytab); } $checksum = $finputs . ' ' . $fqueryt; $checksum = explode('% %', $checksum); foreach ($checksum as $key => $val) { $checksum[$key] = str_replace('%', '', $val); $checksum[$key] = preg_replace('#(^ | $)#', '', $checksum[$key]); $checksum[$key] = '%' . $checksum[$key] . '%'; } foreach ($checksum as $key => $val) { if ($key == 0) { $logicword = 'WHERE'; } else { $terms = isset($_POST['terms']) ? $_POST['terms'] : 'any'; switch ($terms) { case 'all': $logicword = 'AND'; break; case 'any': $logicword = 'OR'; break; default: $logicword = 'OR'; } } $contitl = isset($_POST['contitl']) ? $_POST['contitl'] : 'title'; switch ($contitl) { case 'or': $contitl = 'or'; break; case 'and': $contitl = 'and'; break; case 'content': $contitl = 'content'; break; case 'title': $contitl = 'title'; break; default: $contitl = 'title'; } if ($contitl == 'or') { $querypart[$key] = $logicword . ' (`title` LIKE \'' . $val . '\' OR `content` LIKE \'' . $val . '\')'; } elseif ($contitl == 'and') { $querypart[$key] = $logicword . ' (`title` LIKE \'' . $val . '\' AND `content` LIKE \'' . $val . '\')'; } elseif ($contitl == 'content') { $querypart[$key] = $logicword . ' (`content` LIKE \'' . $val . '\')'; } elseif ($contitl == 'title') { $querypart[$key] = $logicword . ' (`title` LIKE \'' . $val . '\')'; } else { $querypart[$key] = $logicword . ' (`title` LIKE \'' . $val . '\')'; } } // end foreach checksum $finalquery = implode(' ', $querypart); return $finalquery; }
<?php /* Router, all requests sent to api directory forwarded here. URLs of type api/data/args converted to array. Determine method then data. Call functions in dbLib* to process commands */ include_once "setUp.php"; include_once "utils.php"; include_once "databaseFunctions.php"; if (!isset($db)) { $db = createConnection(); } $urlParameters = explodeQuery($_SERVER['QUERY_STRING']); switch ($_SERVER['REQUEST_METHOD']) { case "POST": // Creation /* echo "<strong><code>Post</code></strong>: <br>"; */ post($db, $urlParameters); break; case "GET": //Retrieval /* echo "<p><strong><code>Get</code></strong>:</p>"; */ get($db, $urlParameters); break; case "DELETE": /* echo "<strong><code>Delete</code></strong>: <br>"; */ break; default: echo "<strong>Error: unexpected method. Can handle <code>POST</code>, <code>GET</code>, <code>DELETE</code></strong>"; http_response_code(405);