404
Oops! That page can't be found
- Home Page
- Services
- About
- Blog
- Contact Us
$doc = new DOMDocument('1.0', 'UTF-8'); $doc->preserveWhiteSpace = false; $doc->formatOutput = true; $previous = libxml_use_internal_errors(true); $loaded = $doc->load($xml_file, LIBXML_NONET); libxml_clear_errors(); libxml_use_internal_errors($previous); if (!$loaded) { error_log('Podcast XML: invalid XML for post ' . $post_id); return; } $items = $doc->getElementsByTagName('item'); $changed = false; foreach ($changed_fields as $desc_key) { if (!isset($description_to_audio[$desc_key])) { continue; } $saved_url = get_post_meta($post_id, $description_to_audio[$desc_key], true); if (!is_string($saved_url) || $saved_url === '') { continue; } $query = parse_url($saved_url, PHP_URL_QUERY); $params = array(); if (is_string($query)) { parse_str($query, $params); } $saved_path = isset($params['f']) && is_string($params['f']) ? $params['f'] : parse_url($saved_url, PHP_URL_PATH); $filename = basename(rawurldecode((string) $saved_path)); if (!preg_match('/\.mp3$/i', $filename)) { continue; } $matches = array(); foreach ($items as $xml_item) { $enclosures = $xml_item->getElementsByTagName('enclosure'); if ($enclosures->length < 1) { continue; } $xml_url = $enclosures->item(0)->getAttribute('url'); $xml_path = parse_url($xml_url, PHP_URL_PATH); $xml_filename = basename(rawurldecode((string) $xml_path)); if ($xml_filename === $filename) { $matches[] = $xml_item; } } if (count($matches) !== 1) { error_log('Podcast XML: expected one match for ' . $filename . ', found ' . count($matches)); continue; } $description = get_post_meta($post_id, $desc_key, true); $description = wp_strip_all_tags((string) $description); $description = html_entity_decode($description, ENT_QUOTES | ENT_HTML5, 'UTF-8'); $description = wp_check_invalid_utf8($description, true); $description = trim((string) preg_replace('/\s+/u', ' ', $description)); $description_html = '
' . htmlspecialchars($description, ENT_QUOTES | ENT_XML1, 'UTF-8') . '
'; $description_html = str_replace(']]>', ']]>', $description_html); $xml_item = $matches[0]; $nodes = $xml_item->getElementsByTagName('description'); if ($nodes->length) { $description_node = $nodes->item(0); while ($description_node->firstChild) { $description_node->removeChild($description_node->firstChild); } } else { $description_node = $doc->createElement('description'); $xml_item->appendChild($description_node); } $description_node->appendChild($doc->createCDATASection($description_html)); $changed = true; } if (!$changed) { return; } $backup = $xml_file . '.' . date('Ymd-His') . '-' . uniqid('', true) . '.bak'; if (!copy($xml_file, $backup)) { error_log('Podcast XML: backup failed for post ' . $post_id); return; } if ($doc->save($xml_file) === false) { error_log('Podcast XML: save failed for post ' . $post_id); } } public function phem_restrict_direct_access_to_xml() { if (isset($_GET['phem_action']) && $_GET['phem_action'] == 'phem_download_xml') { if (is_user_logged_in() && wcs_user_has_subscription(get_current_user_id(), '', 'active')) { /* wp_safe_redirect(PHIL_HENDRIEEPISODES_MANGER_URL . 'podcast/podcast.xml'); exit; */ $filename = PLUGINS_PATH . 'phs-s3-soundcloud/secure/podcast.xml'; header("Expires: 0"); header("Cache-Control: no-cache, no-store, must-revalidate"); header('Cache-Control: pre-check=0, post-check=0, max-age=0', false); header("Pragma: no-cache"); header("Content-type: text/html"); header("Content-Disposition:attachment; filename=\"" . basename($filename) . "\""); header("Content-Type: application/force-download"); readfile("{$filename}"); exit(); } else { /* $error = new WP_Error(); $error->add(404, _e('Not allowed', 'phsp')); die(); */ wp_die(__('Sorry, you are not allowed to download this file.', PHIL_HENDRIEEPISODES_MANGER_TEXT_DOMAIN)); } } } } new Episode_Post_Type(); }