function val_0($id_artw, $id_prop, $lg) { global $link; $sql = "SELECT p" . $id_prop . ".qwd as prop_qwd from artw_prop,p" . $id_prop . " WHERE artw_prop.prop=" . $id_prop . " AND artw_prop.id_artw=" . $id_artw . " AND artw_prop.id_prop=p" . $id_prop . ".id AND p" . $id_prop . ".level=0"; $rep = mysqli_query($link, $sql); if (mysqli_num_rows($rep) == 0) { return ""; } else { $row = mysqli_fetch_assoc($rep); return "<a href=\"?p{$id_prop}=" . $row["prop_qwd"] . "\" class=\"interne\">" . label_item($row["prop_qwd"], $lg) . "</a>"; } }
function creators($id_artw, $l) { global $link, $q, $prop; $creators = ""; $vals = array(); $sql = "SELECT p170.qwd from artw_prop,p170 WHERE artw_prop.prop=170 AND artw_prop.id_artw={$id_artw} AND artw_prop.id_prop=p170.id"; $rep_prop = mysqli_query($link, $sql); while ($data_prop = mysqli_fetch_assoc($rep_prop)) { $vals[] = intval($data_prop['qwd']); } for ($i = 0; $i < count($vals); $i++) { global $fold_crotos; $dates = ""; $Q_creator = $vals[$i]; $year1 = ""; $year2 = ""; $qitem_path = $fold_crotos . "lab/artworks/creators/Q" . $Q_creator . ".txt"; if (!file_exists($qitem_path)) { $url_api = "https://www.wikidata.org/w/api.php?action=wbgetentities&ids=Q" . $Q_creator . "&format=json"; $dfic = file_get_contents($url_api, true); $data_item = json_decode($dfic, true); $claims = $data_item["entities"]["Q" . $Q_creator]["claims"]; $tab_date = array("P569", "P570"); for ($j = 0; $j < count($tab_date); $j++) { $b_date = 0; if ($claims[$tab_date[$j]]) { foreach ($claims[$tab_date[$j]] as $value) { $time = $value["mainsnak"]["datavalue"]["value"]["time"]; $precision = $value["mainsnak"]["datavalue"]["value"]["precision"]; if ($time) { $year = intval(substr($time, 1, strpos($time, "-") - 1)); if (intval($precision) < 9) { $year = "~" . $year; } } else { $year = ""; } if ($tab_date[$j] == "P569") { $year1 = $year; } else { $year2 = $year; } } } } if ($year1 != "" || $year2 != "") { $dates = " ("; if ($year1 != "") { $dates .= $year1; } else { $dates .= "?"; } $dates .= "–"; if ($year2 != "") { $dates .= $year2; } else { $dates .= "?"; } $dates .= ")"; } $fp2 = fopen("creators/Q" . $Q_creator . ".txt", "w"); fputs($fp2, $dates); fclose($fp2); } else { $fp2 = fopen("creators/Q" . $Q_creator . ".txt", "r"); $dates = fgets($fp2); fclose($fp2); } if ($creators != "") { $creators .= ", "; } $creators .= label_item($vals[$i], $l); if ($dates != "") { $creators .= " " . $dates; } $creators = "<a href=\"?q=Q" . $Q_creator . "&p=170\">" . $creators . "</a>"; } return $creators; }
?> <option value="" id="tout"><?php echo ucfirst(translate($l, "everything")); ?> </option> <?php $p31_list = array("3305213", "860861", "93184", "11060274", "125191", "133067", "212431", "5647631", "184296", "1473346"); if ($tab_idx["p31"] != "" && !in_array($tab_idx["p31"], $p31_list)) { echo " \t\t<option value=\"" . $tab_idx["p31"] . "\" selected>" . ucfirst(label_item($tab_idx["p31"], $l)) . "</option>\n"; } for ($i = 0; $i < count($p31_list); $i++) { $option = " \t\t<option value=\"" . $p31_list[$i] . "\""; if ($tab_idx["p31"] != "" && $tab_idx["p31"] == $p31_list[$i]) { $option .= " selected"; } echo $option . ">" . ucfirst(label_item($p31_list[$i], $l)) . "</option>\n"; } ?> </select> <?php $txt_crit = ""; foreach ($tab_idx as $key => $value) { if ($value != "" && $key != "p31") { $txt_crit .= "<label for=\"{$key}\"><span class=\"libelle_criteres\">" . translate($l, str_replace("p", "", $key)) . " :</span></label> "; $txt_crit .= txt_prop(0, $value, $l, "normal", 0, 0); $txt_crit .= "\t\t<input type=\"checkbox\" value=\"{$value}\" name=\"{$key}\" id=\"{$key}\" class=\"crit_sel\" checked=\"checked\" onChange=\"document.getElementById('form').submit()\"/>"; } } if ($q != "") { $txt_crit .= "<span class=\"libelle_criteres\">" . translate($l, "Wikidata") . " :</span> <a href=\"https://www.wikidata.org/wiki/Q" . $q . "\" class=\"externe\">Q" . $q . "</a>"; }
$rep2 = mysqli_query($link, $sql); $data2 = mysqli_fetch_assoc($rep2); $img = str_replace(" ", "_", $data2['P18']); $digest = md5($img); $folder = $digest[0] . '/' . $digest[0] . $digest[1] . '/' . urlencode($img); $w_thumb = floor(intval($data2['width']) / intval($data2['height']) * $h_thumb); $thumb = "http://upload.wikimedia.org/wikipedia/commons/thumb/" . $folder . "/" . $w_thumb . "px-" . urlencode($img); if (substr($img, -3) == "svg") { $thumb .= ".png"; } echo "\t<a href=\"https://commons.wikimedia.org/wiki/File:" . urlencode($img) . "\"><img src=\"" . $thumb . "\" /></a>"; } echo "\t</div>\n"; echo "<span>"; } echo label_item($data['qwd'], $l) . " <a href=\"https://www.wikidata.org/wiki/Q" . $data['qwd'] . "\"> (Q" . $data['qwd'] . ")</a>"; if ($thb == 1) { echo "</span>"; } echo "</td>\n"; echo "\t<td class=\"artworks\">{$nbartworks}</td>\n"; echo "\t<td class=\"images\">{$nbimg}</td>\n"; echo "\t<td><a href=\"/crotos/?p{$prop_query}=" . $data['qwd'] . "\">"; if ($l == "fr") { echo "voir les œuvres"; } else { echo "view artworks"; } echo "</a></td>\n"; echo "\t<td><a href=\"/crotos/lab/artworks/?p={$prop_query}&q=Q" . $data['qwd'] . "\">"; if ($l == "fr") {
function data_qwd($qwd, $row) { global $lg, $tab_check, $link, $h_thumb; $tab_lb = array("lb0" => $qwd, "lb18" => "", "lb373" => "", "lb1" => "", "lb2" => "", "lb170" => "", "lb571" => "", "lb31" => "", "lb186" => "", "lb195" => "", "lb217" => "", "lb276" => "", "lb179" => "", "lb3" => "", "lb973" => "", "lb727" => "", "lb347" => "", "lb1212" => "", "lb214" => "", "lb350" => "", "url_img" => "", "wp_links" => ""); if ($row == 0) { $tab_lb["lb1"] = label($qwd, $lg); if ($tab_lb["lb1"] == $qwd) { $tab_lb["lb1"] = ""; } } else { $id = $row['id']; if ($tab_check["c31"] == "1") { $tab_lb["lb31"] = txt_prop($id, 31, $lg, "normal", false, false); } $tab_lb["lb1"] = label_item($qwd, $lg); if ($tab_check["c2"] == "1") { $tab_lb["lb2"] = alias_item($qwd, $lg); } if ($tab_check["c170"] == "1") { $tab_lb["lb170"] = creators($id, $lg); } if ($tab_check["c571"] == "1") { $year1 = $row['year1']; $year2 = $row['year1']; if (!is_null($row['year1'])) { $tab_lb["lb571"] .= $row['year1']; if (!is_null($row['year2']) && $row['year1'] != $row['year2']) { $tab_lb["lb571"] .= " – " . $row['year2']; } if ($row['b_date'] == 1) { $tab_lb["lb571"] .= " (~)"; } } } if ($tab_check["c186"] == "1") { $tab_lb["lb186"] = txt_prop($id, 186, $lg, "normal", false, false); } if ($tab_check["c195"] == "1") { $tab_lb["lb195"] = txt_prop($id, 195, $lg, "listlink", false, false); } if ($tab_check["c217"] == "1") { $tab_lb["lb217"] = $row['P217']; } if ($tab_check["c276"] == "1") { $tab_lb["lb276"] = txt_prop($id, 276, $lg, "normal", false, false); } if ($tab_check["c179"] == "1") { $tab_lb["lb179"] = txt_prop($id, 179, $lg, "normal", false, false); } if ($tab_check["c973"] == "1") { $tab_lb["lb973"] = $row['link']; } if ($tab_check["c727"] == "1") { $tab_lb["lb727"] = $row['P727']; } if ($tab_check["c347"] == "1") { $tab_lb["lb347"] = $row['P347']; } if ($tab_check["c1212"] == "1") { $tab_lb["lb1212"] = $row['P1212']; } if ($tab_check["c214"] == "1") { $tab_lb["lb214"] = $row['P214']; } if ($tab_check["c350"] == "1") { $tab_lb["lb350"] = $row['P350']; } if ($tab_check["c18"] == "1") { if (intval($row['P18']) != 0) { $sql = "SELECT P18, width, height from commons_img WHERE id=" . $row['P18']; $rep2 = mysqli_query($link, $sql); $data2 = mysqli_fetch_assoc($rep2); $img = str_replace(" ", "_", $data2['P18']); $digest = md5($img); $folder = $digest[0] . '/' . $digest[0] . $digest[1] . '/' . urlencode($img); $w_thumb = floor(intval($data2['width']) / intval($data2['height']) * $h_thumb); $thumb = "http://upload.wikimedia.org/wikipedia/commons/thumb/" . $folder . "/" . $w_thumb . "px-" . urlencode($img); if (substr($img, -3) == "svg") { $thumb .= ".png"; } $tab_lb["url_img"] = "https://commons.wikimedia.org/wiki/File:" . urlencode($img); $tab_lb["lb18"] = "\t<a href=\"" . $tab_lb["url_img"] . "\" title=\"https://commons.wikimedia.org/wiki/File:" . urlencode($img) . "\"><img src=\"" . $thumb . "\" alt=\"" . str_replace("\"", "\\\"", $tab_lb["lb1"]) . "\" /></a>"; } } if ($tab_check["c373"] == "1") { $tab_lb["lb373"] = $row['P373']; } if ($tab_check["c3"] == "1") { $sql = "SELECT page,lg from label_page WHERE qwd=" . $qwd . " AND page!='' ORDER BY lg "; $rep2 = mysqli_query($link, $sql); $num_rows = mysqli_num_rows($rep2); if ($num_rows > 0) { $cpt2 = 0; $lg_of = ""; while ($data2 = mysqli_fetch_assoc($rep2)) { $cpt2++; if ($data2['lg'] != $lg_of) { if ($cpt2 != 1) { $tab_lb["lb3"] .= ", "; $tab_lb["wp_links"] .= ", "; } $tab_lb["lb3"] .= " <a href=\"https://" . $data2['lg'] . ".wikipedia.org/wiki/" . $data2['page'] . "\">[" . $data2['lg'] . "]</a>"; $tab_lb["wp_links"] .= "https://" . $data2['lg'] . ".wikipedia.org/wiki/" . $data2['page']; } $lg_of = $data2['lg']; } } } } return $tab_lb; }
<div id="contenu"> <?php while ($data = mysqli_fetch_assoc($rep)) { $id_prop = $data['id']; $nbartworks = $data['nb']; $nbimg = $data['nbimg']; $qwd = $data['qwd']; $lb = label_item($qwd, $l); $where = "(artw_prop.id_prop=" . $id_prop; $sql_sub = "SELECT id_sub FROM prop_sub WHERE prop=" . $prop . " AND id_prop=" . $id_prop; $rep_sub = mysqli_query($link, $sql_sub); while ($data_sub = mysqli_fetch_assoc($rep_sub)) { $where .= " OR artw_prop.id_prop=" . $data_sub['id_sub']; } $where .= ")"; $sql = "select artworks.qwd, commons_img.P18,commons_img.width,commons_img.height from artw_prop,artworks, commons_img WHERE " . $where . " AND artw_prop.prop=" . $prop . " AND artw_prop.id_artw=artworks.id AND artworks.P18=commons_img.id"; $rep_img = mysqli_query($link, $sql . " AND commons_img.height>239 AND commons_img.width>319 order by rand() limit 1"); $nb_img = mysqli_num_rows($rep_img); $img = "http://www.zone47.com/crotos/img/no_image2.png"; $qwd_img = ""; if ($nb_img != 0) { $data_img = mysqli_fetch_assoc($rep_img); } else { $rep_img = mysqli_query($link, $sql . " order by rand() limit 1"); $nb_img = mysqli_num_rows($rep_img); if ($nb_img != 0) { $data_img = mysqli_fetch_assoc($rep_img); } } if ($nb_img != 0) { $qwd_img = $data_img['qwd'];
if ($num_rows > 1) { echo "<div id=\"contenu\" class=\"yoxview\" >"; } else { echo "<div id=\"contenu\" class=\"yoxview contentsolo\" >"; } $cpt = 0; while ($data = mysqli_fetch_assoc($rep)) { $content = ""; $cpt++; $id_artw = $data['id']; $qwd_art = $data['qwd']; $inv = $data['P217']; $described_link = $data['link']; $titre = ""; $titre = label_item($qwd_art, $l); $trunc_title = truncate($titre); $trunk = false; if ($titre != $trunc_title) { $trunk = true; } $alias = alias_item($qwd_art, $l); $creator = txt_prop($id_artw, 170, $l, "creator", false); $pageWP = page_item($qwd_art, $l); $lgWP = ""; $pos = strpos($pageWP, "|"); if ($pos) { $lgWP = substr($pageWP, 0, $pos); $pageWP = substr($pageWP, $pos + 1, strlen($pageWP)); } $coll0 = val_0($id_artw, 195, $l);
$digest = md5($img); $folder = $digest[0] . '/' . $digest[0] . $digest[1] . '/' . urlencode($img); $w_thumb = floor(intval($data2['width']) / intval($data2['height']) * 30); if ($w_thumb > 70) { $w_thumb = 70; } $thumb = "http://upload.wikimedia.org/wikipedia/commons/thumb/" . $folder . "/" . $w_thumb . "px-" . urlencode($img); if (substr($img, -3) == "svg") { $thumb .= ".png"; } } $sql = "SELECT p170.qwd as prop_qwd, dates from artw_prop,p170 WHERE artw_prop.prop=170 AND artw_prop.id_artw=" . $rs['id_art_or_prop'] . " AND artw_prop.id_prop=p170.id"; $rep2 = mysqli_query($link, $sql); $crea = ""; while ($data2 = mysqli_fetch_assoc($rep2)) { $tl = label_item(intval($data2['prop_qwd']), $l); if ($tl != "") { $crea .= ", " . $tl; if ($data2['dates'] != "") { $crea .= " " . $data2['dates']; } } } if ($crea != "") { $crea = '<span class="lbs">' . $crea . '</span>'; } $txt .= 'q=' . $rs['qwd'] . '¤<span class="ims"><span class="is"><img src="' . $thumb . '"/></span><span class="lbs">' . $rs['label'] . '</span><span class="lbi">' . $crea . '</span></span>'; } elseif ($rs['prop'] == 170) { $sql = "SELECT dates from p170 WHERE id=" . $rs['id_art_or_prop']; $rep2 = mysqli_query($link, $sql); while ($data2 = mysqli_fetch_assoc($rep2)) {
function children_search($id_parent, $l) { global $link; $sql = "SELECT id, qwd,commonscategory from p276 WHERE id_parent=" . $id_parent; $rep = mysqli_query($link, $sql); $num_rows = mysqli_num_rows($rep); if ($num_rows != 0) { echo "\n<ul>"; } $data_rooms = array(); while ($data = mysqli_fetch_assoc($rep)) { $lbl = ucfirst(trim(label_item($data['qwd'], $l))); $sorttxt = ""; preg_match('#[0-9][0-9]*[a-z]*#i', $lbl, $matches); if ($matches) { $sorttxt = intval($matches[0]); } else { $sorttxt = $lbl; } $sorttxt2 = ""; preg_match('#.*,#i', $lbl, $matches); if ($matches) { $sorttxt2 = $matches[0]; } else { $sorttxt2 = $lbl; } $data_rooms[] = array("id_loc" => $data['id'], "qwd" => $data['qwd'], "commonscategory" => $data['commonscategory'], "label" => $lbl, "for_sort" => $sorttxt, "for_sort2" => $sorttxt2); } foreach ($data_rooms as $key => $row) { $id_loc[$key] = $row['id_loc']; $qwd[$key] = $row['qwd']; $commonscategory[$key] = $row['commonscategory']; $label[$key] = $row['label']; $for_sort[$key] = $row['for_sort']; $for_sort2[$key] = $row['for_sort2']; } array_multisort($for_sort2, SORT_ASC, $for_sort, SORT_ASC, $data_rooms); for ($i = 0; $i < count($data_rooms); $i++) { //$sql="SELECT count(id) as total from artw_prop WHERE prop=276 and id_prop=".$data_rooms[$i]["id_loc"]; $sql = "select count(distinct artworks.id) as total from p276, artw_prop, artworks WHERE p276.id=" . $data_rooms[$i]["id_loc"] . " AND artw_prop.id_prop=p276.id AND artw_prop.prop=276 AND artworks.id=artw_prop.id_artw"; $rep2 = mysqli_query($link, $sql); $data2 = mysqli_fetch_assoc($rep2); $nbartworks = $data2['total']; $sql = "select count(distinct artworks.id) as total from p276, artw_prop, artworks WHERE p276.id=" . $data_rooms[$i]["id_loc"] . " AND artw_prop.id_prop=p276.id AND artw_prop.prop=276 AND artworks.id=artw_prop.id_artw and artworks.P18=0"; $rep2 = mysqli_query($link, $sql); $data2 = mysqli_fetch_assoc($rep2); $nbmiss = $data2['total']; $txt = "\n<li>" . $data_rooms[$i]["label"] . " (<b>{$nbartworks} item"; if ($nbartworks > 1) { $txt .= "s"; } $txt .= "</b>"; if ($nbmiss > 0) { $txt .= " - " . $nbmiss; if ($nbmiss == 1) { if ($l == "fr") { $txt .= " image manquante"; } else { $txt .= " missing image"; } } else { if ($l == "fr") { $txt .= " images manquantes"; } else { $txt .= " missing images"; } } } $txt .= ")"; $txt .= " <a href=\"https://www.wikidata.org/wiki/Q" . $data_rooms[$i]["qwd"] . "\">Q" . $data_rooms[$i]["qwd"] . "</a>"; if ($data_rooms[$i]["commonscategory"] != "") { $txt .= " - <a href=\"https://commons.wikimedia.org/wiki/Category:" . $data_rooms[$i]["commonscategory"] . "\">WikiCommons</a>"; } $txt .= " - <a href=\"http://www.zone47.com/crotos/?p276=" . $data_rooms[$i]["qwd"] . "\">Crotos</a>"; $txt .= " - <a href=\"http://www.zone47.com/crotos/lab/artworks/?p=276&q=Q" . $data_rooms[$i]["qwd"] . "&c0=1&c1=1&c170=1&c571=1&c31=1&c217=1&c3=1&c347=1&c1212=1&c18=1\">"; if ($l == "fr") { $txt .= "Liste"; } else { $txt .= "List"; } $txt .= "</a></li>"; // - <a href=\"http://tools.wmflabs.org/autolist/index.php?language=fr&wdq=claim%5B276%3A%28tree%5B$qwd%5D%5B%5D%5B276%5D%29%5D&run=Run\">Autolist</a>"; echo $txt; $next = $data_rooms[$i]["id_loc"]; children_search($next, $l, $miss); } if ($num_rows != 0) { echo "\n</ul>"; } }