function construct_query($query, $not, $level, $argn = "", $oper = "") { global $corresp, $search, $corresp_op; //La requête commence-t-elle par and, or ou and not ? $pos = strpos($query, "and not"); if ($pos !== false && $pos == 0) { $ope = "ex"; } else { $pos = strpos($query, "or"); if ($pos !== false && $pos == 0) { $ope = "or"; } else { $pos = strpos($query, "and"); if ($pos !== false && $pos == 0) { $ope = "and"; } else { $ope = ""; } } } if ($ope != "") { //Si opérateur, recherche des arguments $arqs = array(); preg_match("/^" . ($ope == "ex" ? "and not" : $ope) . " arg" . $level . "!1\\((.*)\\) arg" . $level . "!2\\((.*)\\)\$/", $query, $args); //print "/^".$ope." arg".$level."!1\((.*)\) arg".$level."!2\((.*)\)$/"; //print_r($args); $return1 = construct_query($args[1], 0, $level + 1, 1, $ope); if ($oper && $return1) { $inter = "inter_" . ($level - 2 + $argn) . "_f_" . $return1; global ${$inter}; if (!${$inter}) { ${$inter} = $oper; } //print $inter."=".$$inter."<br />"; } $return2 = construct_query($args[2], 0, $level + 1, 2, $ope); if ($return2) { //print $level." ".$argn; if ($argn == "") { $argn = 2; } $inter = "inter_" . ($level - 1 + $argn) . "_f_" . $return2; global ${$inter}; if (!${$inter}) { ${$inter} = $ope; } //print $inter."=".$$inter."<br />"; } return; } else { $use = explode("=", $query); $idf = $corresp[$use[0]]; if (!$idf) { make_error(3, "1=" . $use[0]); } else { $search[] = "f_" . $idf; $vals = array(); $vals[0] = traite_val($use[1], $idf); $field = "field_" . (!$level ? 0 : $level - 2 + $argn) . "_f_" . $idf; global ${$field}; ${$field} = $vals; $op = "op_" . (!$level ? 0 : $level - 2 + $argn) . "_f_" . $idf; global ${$op}; ${$op} = $corresp_op[$use[0]]; return $idf; } } return; }
function getDanmaku() { if (!isset($_REQUEST['cid'])) { make_error(400, "'cid' was required."); } $cid = $_REQUEST['cid']; header("Content-Type: text/xml;charset=UTF-8", true); header("Access-Control-Allow-Origin: *", true); header("Access-Control-Max-Age: 86400", true); header("Content-Encoding: deflate", true); $url = "http://comment.bilibili.com/" . $cid . ".xml"; echo get_data($url, array()); }
function construct_query($query, $not, $level, $argn = "") { //La requête commence-t-elle par and, or ou and not ? $pos = strpos($query, "and not"); if ($pos !== false && $pos == 0) { $ope = "and not"; } else { $pos = strpos($query, "or"); if ($pos !== false && $pos == 0) { $ope = "or"; } else { $pos = strpos($query, "and"); if ($pos !== false && $pos == 0) { $ope = "and"; } else { $ope = ""; } } } if ($ope != "") { //Si opérateur, recherche des arguments $arqs = array(); preg_match("/^" . $ope . " arg" . $level . "!1\\((.*)\\) arg" . $level . "!2\\((.*)\\)\$/", $query, $args); $return1 = construct_query($args[1], 0, $level + 1, 1); if ($ope == "and not") { $return2 = construct_query($args[2], 1, $level + 1, 2); } else { $return2 = construct_query($args[2], 0, $level + 1, 2); } if ($ope == "and not") { $ope = "and"; } $requete = "create temporary table r{$level} ENGINE=MyISAM "; if ($ope == "and") { $requete .= "select distinct {$return1}.notice_id from {$return1}, {$return2} where {$return1}.notice_id={$return2}.notice_id"; @pmb_mysql_query($requete); } else { $requete .= "select distinct notice_id from {$return1}"; @pmb_mysql_query($requete); $requete = "insert into r{$level} select distinct notice_id from {$return2} "; @pmb_mysql_query($requete); } $return = "r{$level}"; } else { $use = explode("=", $query); switch ($use[0]) { //Titre case 4: if ($not) { $requete = "select distinct notice_id from notices where (index_wew not like '%" . $use[1] . "%' )"; } else { $requete = "select distinct notice_id from notices where (index_wew like '%" . $use[1] . "%' )"; } break; //ISBN //ISBN case 7: if (isISBN($use[1])) { // si la saisie est un ISBN $code = formatISBN($use[1]); // si échec, ISBN erroné on le prend sous cette forme if (!$code) { $code = $use[1]; } } else { $code = $use[1]; } if ($not) { $requete = "select notice_id from notices where (code!='" . $code . "')"; } else { $requete = "select notice_id from notices where (code='" . $code . "')"; } break; // Auteur // Auteur case 1003: if ($not) { $requete = "create temporary table aut ENGINE=MyISAM select distinct responsability.responsability_notice as notice_id, index_author as auth from authors, responsability where responsability_author = author_id "; @pmb_mysql_query($requete); $requete = "select distinct notice_id from aut where auth not like '%" . $use[1] . "%'"; } else { $requete = "select distinct notice_id from responsability, authors, notices where index_author like '%" . $use[1] . "%' and author_id=responsability_author and notice_id=responsability_notice "; } break; default: make_error(3, "1=" . $use[0]); break; } $requete = "create temporary table r" . $level . "_" . $argn . " ENGINE=MyISAM " . $requete; @pmb_mysql_query($requete); $return = "r" . $level . "_" . $argn; } return $return; }
function construct_query($query, $not, $level, $argn = "") { //La requête commence-t-elle par and, or ou and not ? $pos = strpos($query, "and not"); if ($pos !== false && $pos == 0) { $ope = "and not"; } else { $pos = strpos($query, "or"); if ($pos !== false && $pos == 0) { $ope = "or"; } else { $pos = strpos($query, "and"); if ($pos !== false && $pos == 0) { $ope = "and"; } else { $ope = ""; } } } if ($ope != "") { $arqs = array(); preg_match("/^" . $ope . " arg" . $level . "!1\\((.*)\\) arg" . $level . "!2\\((.*)\\)\$/", $query, $args); $return1 = construct_query($args[1], 0, $level + 1, 1); if ($ope == "and not") { $return2 = construct_query($args[2], 1, $level + 1, 2); } else { $return2 = construct_query($args[2], 0, $level + 1, 2); } if ($ope == "and not") { $ope = "and"; } $requete = "create temporary table r{$level} "; if ($ope == "and") { $requete .= "select {$return1}.notice_id from {$return1}, {$return2} where {$return1}.notice_id={$return2}.notice_id"; @pmb_mysql_query($requete); } else { $requete .= "select notice_id from {$return1}"; @pmb_mysql_query($requete); $requete = "insert into r{$level} select {$return2}.notice_id from {$return2},{$return1} where {$return2}.notice_id!={$return1}.notice_id"; @pmb_mysql_query($requete); } $return = "r{$level}"; } else { $use = explode("=", $query); switch ($use[0]) { //Titre case 4: if ($not) { $requete = "select notice_id from notices where (tit1 not like '%" . $use[1] . "%' and tit2 not like '%" . $use[1] . "%' and tit3 not like '%" . $use[1] . "%' and tit4 not like '%" . $use[1] . "%')"; } else { $requete = "select notice_id from notices where (tit1 like '%" . $use[1] . "%' or tit2 like '%" . $use[1] . "%' or tit3 like '%" . $use[1] . "%' or tit4 like '%" . $use[1] . "%')"; } break; //ISBN //ISBN case 7: if (isISBN($use[1])) { // si la saisie est un ISBN $code = formatISBN($use[1]); // si échec, ISBN erroné on le prend sous cette forme if (!$code) { $code = $use[1]; } } else { $code = $use[1]; } if ($not) { $requete = "select notice_id from notices where (code!='" . $code . "')"; } else { $requete = "select notice_id from notices where (code='" . $code . "')"; } break; case 1003: if ($not) { $requete = "create temporary table aut1 select notice_id,concat(author_name,' ',author_rejete) as auth from notices left join authors on author_id=aut1_id"; @pmb_mysql_query($requete); $requete = "create temporary table aut2 select notice_id,concat(author_name,' ',author_rejete) as auth from notices left join authors on author_id=aut2_id"; @pmb_mysql_query($requete); $requete = "create temporary table aut3 select notice_id,concat(author_name,' ',author_rejete) as auth from notices left join authors on author_id=aut3_id"; @pmb_mysql_query($requete); $requete = "create temporary table aut4 select notice_id,concat(author_name,' ',author_rejete) as auth from notices left join authors on author_id=aut4_id"; @pmb_mysql_query($requete); $requete = "create temporary table aut select aut1.notice_id, concat(ifnull(aut1.auth,''),' ',ifnull(aut2.auth,''),' ',ifnull(aut3.auth,''),' ',ifnull(aut4.auth,'')) as auth from aut1, aut2, aut3, aut4 where aut2.notice_id=aut1.notice_id and aut3.notice_id=aut1.notice_id and aut4.notice_id=aut1.notice_id"; @pmb_mysql_query($requete); $requete = "select notice_id from aut where auth not like '%" . $use[1] . "%'"; } else { $requete = "select notice_id from notices,authors where (concat(author_name,' ',author_rejete) like '%" . $use[1] . "%' and (author_id=aut1_id or author_id=aut2_id or author_id=aut3_id or author_id=aut3_id))"; } break; // Sujet - Catégories // Sujet - Catégories case 21: if ($not) { $requete = "CREATE TEMPORARY TABLE cat SELECT DISTINCT notices_categories.notcateg_notice as notice_id, index_categorie as cat FROM categories, notices_categories WHERE notcateg_categorie = categ_id ORDER BY notices_categories.ordre_categorie"; @pmb_mysql_query($requete); $requete = "SELECT DISTINCT notice_id FROM cat WHERE cat not like '%" . $use[1] . "%'"; } else { $requete = "SELECT DISTINCT notice_id FROM notices_categories, categories, notices WHERE categ_id=notcateg_categorie AND notice_id=notcateg_notice AND index_categorie like '%" . $use[1] . "%'"; } break; default: make_error(3, "1=" . $use[0]); break; } $requete = "create temporary table r" . $level . "_" . $argn . " " . $requete; @pmb_mysql_query($requete); $return = "r" . $level . "_" . $argn; } return $return; }