diff --git a/modules/faq/faq.php b/modules/faq/faq.php index 9fffda50..8f9af58b 100755 --- a/modules/faq/faq.php +++ b/modules/faq/faq.php @@ -34,116 +34,34 @@ function exec_ogp_module() echo '
Categories
'. '

'; - require 'modules/faq/rss_php.php'; - $url = 'https://opengamepanel.org/faq/rss.php'; - $local_copy = 'modules/faq/faq.rss'; ## Relative path - $save_as = realpath('modules' . DIRECTORY_SEPARATOR . 'faq') . DIRECTORY_SEPARATOR . 'faq.rss'; - ## Full path (adding the filename to realpath would fail if the file does not exists yet) - $online = false; - $local = true; - $updated = false; - $s = (isset($_SERVER['HTTPS'])) ? "s" : ""; - $p = (isset($_SERVER['SERVER_PORT']) and $_SERVER['SERVER_PORT'] != "80") ? ":".$_SERVER['SERVER_PORT'] : ""; - $localServerURL = $_SERVER['SERVER_NAME']; - if($localServerURL == "_"){ - $localServerURL = "localhost"; - } - $local_url = 'http'.$s.'://'.$localServerURL.$p.$_SERVER['SCRIPT_NAME']; - $local_url = str_replace('home.php', $local_copy, $local_url); - if(file_exists($save_as)) - { - $rss = new rss_php; - $rss->load($local_url); - $items = $rss->getItems(); #returns all rss items - $local = true; - } - /* - echo ""; - if( ($local AND ( strtotime("+1 day", filemtime($save_as)) <= strtotime("now") )) OR !$local) # Check the file is older than 1 day to avoid spamming the server - { - stream_context_set_default(array('ssl' => array( - 'verify_peer' => false, - 'verify_peer_name' => false - ) - )); - - $headers = get_headers( $url, 1 ); - touch( $save_as ); # Connection done, so we reset the file modification time even if the server is down (avoid server spamming) - echo ""; - if( $headers[0] == 'HTTP/1.1 200 OK') - { - $online = false; - $rss_online = new rss_php; - $rss_online->load($url); # SERVER USAGE WARNING : using 32kb of server bandwidth each time each person loads this function - $items_online = $rss_online->getItems(); - echo ""; - if(($local and $items_online != $items ) OR !$local) - { - $contents = file_get_contents($url); - if(preg_match('#^<\?xml version="1.0" encoding="utf-8" \?>#', $contents, $match)) - { - if( file_put_contents($save_as, $contents) === false ) - { - print_failure("Imposible write " . $save_as); - return; - } - touch( $save_as ); - echo ""; - $updated = true; - } - else - { - print_failure("Imposible fetch " . $url); - return; - } - } - else - { - echo ""; - } - } - } - + // Load FAQ data from new HTML structure + require_once 'modules/faq/faq_data.php'; + $entries = getFaqData(); - if($updated) - { - $rss = new rss_php; - $rss->load($local_url); - $items = $rss->getItems(); #returns all rss items - } - */ - - if(!file_exists($save_as)) - { - print_failure('Unable to load entries.'); - return; # Stop loading page - } - - - $entries = array(); - foreach($items as $index => $item) - { - $category = $item['category'][0]; - $entries[$category][$index]['title'] = $item['title'][0]; - $entries[$category][$index]['content'] = $item['content:encoded'][0]; - } $categories = ""; $accordion_entries = "
\n"; + foreach($entries as $category_name => $category_entries) { - $categories .= "
  • $category_name
  • "; - $accordion_entries .= "
    $category_name
    "; - foreach($category_entries as $index => $item) + // Create category navigation link with clean ID + $category_id = preg_replace('/[^a-z0-9_]/', '_', strtolower($category_name)); + $categories .= "
  • $category_name
  • "; + + // Create category section + $accordion_entries .= "
    $category_name
    "; + + // Add items for this category + foreach($category_entries as $item) { - $accordion_entries .= "\t
    ". - "$item[title]
    \n". - "\t
    \n\t\t
    $item[content]
    \n\t
    \n"; + $accordion_entries .= "\t
    ". + htmlspecialchars($item['title']) . "
    \n". + "\t
    \n\t\t
    " . $item['content'] . "
    \n\t
    \n"; } } $categories .= ""; $accordion_entries .= "
    "; - echo $categories.$accordion_entries; + echo $categories . $accordion_entries; echo "