[gnomeweb-wp: 1/13] Saving the pot file of the whole site in the po dir
- From: Vinicius Scopel Depizzol <vdepizzol src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnomeweb-wp: 1/13] Saving the pot file of the whole site in the po dir
- Date: Wed, 26 Jan 2011 23:00:34 +0000 (UTC)
commit 3ee2f9df03c993e37de19da59b93e5f067b9b46c
Author: Lincoln de Sousa <lincoln comum org>
Date: Sat Nov 6 20:55:28 2010 -0200
Saving the pot file of the whole site in the po dir
To do this, I had to add the database-export.php file previously in a
separated repo and then change it to encapsulate the xml generation
in a function.
wp-content/themes/gnome-grass/database-export.php | 82 +++++++++++++++++++++
wp-content/themes/gnome-grass/functions.php | 12 +++
2 files changed, 94 insertions(+), 0 deletions(-)
---
diff --git a/wp-content/themes/gnome-grass/database-export.php b/wp-content/themes/gnome-grass/database-export.php
new file mode 100644
index 0000000..0cc6a36
--- /dev/null
+++ b/wp-content/themes/gnome-grass/database-export.php
@@ -0,0 +1,82 @@
+<?php
+// Vinicius Depizzol
+// vdepizzol gmail com
+
+
+// This code by now only generates a XML with all the content from WordPress database.
+
+require_once(ABSPATH . "wp-config.php");
+
+function generate_po_xml () {
+ global $wpdb;
+
+ $myrows = $wpdb->get_results( "SELECT ID, post_content, post_title, post_excerpt, post_name FROM wp_posts WHERE post_type != 'revision' && post_type != 'nav_menu_item'" );
+
+
+ header("Content-type: text/xml");
+
+ $broken_dom_pages = array();
+
+ $dom = new DOMDocument('1.0', 'utf-8');
+ $dom->formatOutput = true;
+
+ $root = $dom->createElement("website");
+
+ foreach($myrows as $key => $value) {
+
+ $page = $dom->createElement("page");
+
+
+ // ID
+
+ $page_id = $dom->createAttribute('id');
+ $page_id_value = $dom->createTextNode($value->ID);
+ $page_id->appendChild($page_id_value);
+ $page->appendChild($page_id);
+
+
+ // page_title
+
+ $page_title = $dom->createElement("title");
+ $page_title_value = $dom->createTextNode($value->post_title);
+ $page_title->appendChild($page_title_value);
+ $page->appendChild($page_title);
+
+
+ // page_name
+
+ $page_name = $dom->createElement("name");
+ $page_name_value = $dom->createTextNode($value->post_name);
+ $page_name->appendChild($page_name_value);
+ $page->appendChild($page_name);
+
+
+ // page_content
+
+
+ $value->post_content = wpautop($value->post_content);
+
+
+ $content_xml = $dom->createDocumentFragment();
+ $content_xml->appendXML('<html>'.$value->post_content.'</html>');
+ if($content_xml == false) {
+ $broken_dom_pages[] = $value->ID;
+ }
+
+ $page_content = $dom->createElement("content");
+ $page_content->appendChild($content_xml);
+ $page->appendChild($page_content);
+
+ $root->appendChild($page);
+
+ }
+ $dom->appendChild($root);
+
+ $content = $dom->saveXML();
+ return $content;
+}
+
+if (isset($_REQUEST['print']))
+ print generate_po_xml ();
+
+?>
diff --git a/wp-content/themes/gnome-grass/functions.php b/wp-content/themes/gnome-grass/functions.php
index 27da0ac..0a866e1 100644
--- a/wp-content/themes/gnome-grass/functions.php
+++ b/wp-content/themes/gnome-grass/functions.php
@@ -4,6 +4,8 @@
* @subpackage Default_Theme
*/
+require_once ("database-export.php");
+
add_editor_style("editor_style.css");
add_theme_support('menus');
@@ -85,7 +87,17 @@ add_filter('gallery_style', create_function('$a', 'return preg_replace("%
%s", "", $a);'));
+function update_pot_file ($post) {
+ $podir = ABSPATH . "po/";
+ $xml_file = "{$podir}.tmp.xml";
+ file_put_contents ($xml_file, generate_po_xml ());
+
+ $cmd = "/usr/bin/xml2po -o {$podir}gnome.org.pot $xml_file";
+ exec ($cmd);
+ unlink ($xml_file);
+}
+add_action ('post_updated', 'update_pot_file');
?>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]