setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Start building the XML string $xml = ''; $xml .= ''; // Check if the 'private' column exists in the YOURLS database table $table_name = YOURLS_DB_TABLE_URL; $stmt = $pdo->query("DESCRIBE `$table_name`"); $private_column_exists = false; while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { if ($row['Field'] === 'private') { $private_column_exists = true; break; } } if ($private_column_exists) { // Retrieve all public short URLs $stmt = $pdo->prepare("SELECT `keyword`, `url`, `timestamp` FROM `$table_name` WHERE `private` = '0'"); $stmt->execute(); } else { // Retrieve all short URLs (assuming all are public) $stmt = $pdo->prepare("SELECT `keyword`, `url`, `timestamp` FROM `$table_name`"); $stmt->execute(); } // Loop through each link and add it to the sitemap while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $shorturl = yourls_link($row['keyword']); $timestamp = date('c', strtotime($row['timestamp'])); $xml .= ''; $xml .= '' . htmlspecialchars($shorturl) . ''; $xml .= '' . $timestamp . ''; $xml .= 'weekly'; $xml .= '0.8'; $xml .= ''; } // Close the XML $xml .= ''; // Save the XML to sitemap.xml file file_put_contents(YOURLS_ABSPATH . '/sitemap.xml', $xml); } catch (PDOException $e) { // Handle PDO exceptions yourls_die('Error: ' . $e->getMessage()); } }