117 lines
3.5 KiB
PHP
117 lines
3.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
// File sources, images & scripts
|
|
$TRANSFEMRING_FILES = [
|
|
"nonbinary" => [
|
|
"arrow_path" => "../../../img/webrings/transfem_enby_arrow.png",
|
|
"banner_path" => "../../../img/webrings/transfem_enby_banner.png"
|
|
],
|
|
"transgender" => [
|
|
"arrow_path" => "../../../img/webrings/transfem_trans_arrow.png",
|
|
"banner_path" => "../../../img/webrings/transfem_trans_banner.png"
|
|
]
|
|
];
|
|
|
|
$TRANSFEMRING_SCRIPT_SOURCE = [
|
|
"selected_source" => 1,
|
|
"sources" =>
|
|
[["url" => "https://fem.nz/ring/transfemring.js",
|
|
"source" => "internet"],
|
|
["url" => "/transfemwebring.js",
|
|
"source" => "local"]]
|
|
];
|
|
|
|
// Specific variables for script
|
|
$TRANSFEMRING_ROOT = "https://fem.nz";
|
|
$TRANSFEMRING_VALID_WIDGET_TYPES = ["transgender", "nonbinary"];
|
|
|
|
// Personal identifiers/choices
|
|
$TRANSFEMRING_WIDGET_TYPE = $TRANSFEMRING_VALID_WIDGET_TYPES[1];
|
|
$TRANSFEMRING_ID = 8;
|
|
|
|
// Functions
|
|
function primarySplit(string $array) {
|
|
$i = 0;
|
|
while (strlen($array) !== 0) {
|
|
// Strip coma if found
|
|
if (str_starts_with($array,',')) {
|
|
$array = substr($array,1);
|
|
}
|
|
|
|
// Get substring position and length
|
|
$start_pos = 1;
|
|
$end_pos = strpos($array,"}",1);
|
|
$item_len = $end_pos - $start_pos;
|
|
|
|
// Save website into array, and strip array
|
|
$return_array[$i] = substr($array,$start_pos,$item_len);
|
|
$array = substr($array,$item_len+2); // +2 from { and }
|
|
|
|
$i++;
|
|
}
|
|
|
|
unset($array,$start_pos,$end_pos,$item_len,$array);
|
|
return $return_array;
|
|
}
|
|
|
|
function secondarySplit(string $sub_array) {
|
|
while (strlen($sub_array) !== 0){
|
|
if (str_starts_with($sub_array,',')) {
|
|
$sub_array = substr($sub_array,1);
|
|
}
|
|
|
|
$key_start_pos = 1;
|
|
$key_end_pos = strpos($sub_array,"\"",1);
|
|
$key_len = $key_end_pos - $key_start_pos;
|
|
$key = substr($sub_array,$key_start_pos,$key_len);
|
|
|
|
$value_start_pos = $key_len + 3; // +3 from " , " and :
|
|
// Check if key is quoted
|
|
if (strpos($sub_array,"\"",$value_start_pos) != $value_start_pos) {
|
|
$keyhasQuotes = FALSE;
|
|
$value_end_pos = strpos($sub_array,",");
|
|
} else {
|
|
$value_start_pos++; // +1 from "
|
|
$value_end_pos = strpos($sub_array,"\"",$value_start_pos);
|
|
$keyhasQuotes = TRUE;
|
|
}
|
|
$value_len = $value_end_pos - $value_start_pos;
|
|
$value = substr($sub_array,$value_start_pos,$value_len);
|
|
|
|
$return_sub_array[$key] = $value;
|
|
|
|
$sub_sub_array_len = $key_len + $value_len + 3; // +3 from " , " and :
|
|
if ($keyhasQuotes) {
|
|
$sub_sub_array_len = $sub_sub_array_len + 2; // +2 from " and "
|
|
}
|
|
|
|
$sub_array = substr($sub_array,$sub_sub_array_len);
|
|
}
|
|
|
|
unset($sub_array, $value, $value_len, $value_start_pos, $value_end_pos, $key, $key_len, $key_start_pos, $key_end_pos, $keyhasQuotes, $sub_sub_array_len);
|
|
return $return_sub_array;
|
|
}
|
|
|
|
$transfemring_sites = scrapeWebsiteSites($TRANSFEMRING_SCRIPT_SOURCE,'sites: [',']');
|
|
$transfemring_sites = primarySplit($transfemring_sites);
|
|
for ($i = 0; $i < sizeof($transfemring_sites); $i++) {
|
|
$depured_transfemring_sites[$i] = secondarySplit($transfemring_sites[$i]);
|
|
}
|
|
$transfemring_sites = $depured_transfemring_sites;
|
|
unset($depured_transfemring_sites);
|
|
|
|
for ($i = 1; $i < count($transfemring_sites); $i++){
|
|
if ($transfemring_sites[$i]['id'] == $TRANSFEMRING_ID) {
|
|
|
|
$transfem_prev = 'https://' . $transfemring_sites[($i-1)]["site_link"];
|
|
$transfem_current = 'https://' . $transfemring_sites[($i)]["site_link"];
|
|
$transfem_next = 'https://' . $transfemring_sites[($i+1)]["site_link"];
|
|
$found = TRUE;
|
|
}
|
|
}
|
|
|
|
if (!isset($found)) {
|
|
echo ("ERROR ID NOT FOUND");
|
|
} |