google analytics api
http://www.masnun.me/2010/05/01/working-with-the-google-chart-visualization-javascript-apis.html
Display CDATA with XSL
I've been playing around with it and there's something I can't figure out.
The XML is based of an RSS Feed. Here's a example of XML I am trying to play with.
<item>
<title>Dinner at Chilis</title>
<link></link>
<description>
[!CDATA[<div><b>Location:</b> Chilis </div>
<div><b>Start Time:</b> 4/21/2010</div>
<div><b>Description:</b> Dinner at Chilis </div>]]>
</description>
</item>
Here's a part of the XSL I've been playing around.
<xsl:template match="item">
<xsl:value-of select="title"/>
<xsl:value-of disable-output-escaping="yes" select="substring-before(substring-after(description, ']]'), '[CDATA[') "/>
</xsl:template>
I'm not sure why it's not displaying the string.
My previous code was like this:
<xsl:template match="item">
<xsl:value-of select="title"/>
<xsl:value-of disable-output-escaping="yes" select="description"/>
</xsl:template>
It displays, but I won't have control on how to select the specific text in the description tag.
It's something I want to learn how to do it. I'm still a beginner in XSL so my apologies for being a newbie.
EDIT*
Ok. I got it.
It displays only the first line though. lol. Here's the code I have right now.
<xsl:template match="item">
<xsl:value-of select="title"/>
<xsl:value-of disable-output-escaping="yes" select="substring-before(substring-after(description, '<div>'), '</div>') "/>
</xsl:template>
So far so good. I'll play around a bit more.
libxml writer - XML writer
<?php
// THIS IS ABSOLUTELY ESSENTIAL - DO NOT FORGET TO SET THIS
@date_default_timezone_set("GMT");
$writer = new XMLWriter();
// Output directly to the user
$writer->openURI('php://output');
$writer->startDocument('1.0');
$writer->setIndent(4);
// declare it as an rss document
$writer->startElement('rss');
$writer->writeAttribute('version', '2.0');
$writer->writeAttribute('xmlns:atom', 'http://www.w3.org/2005/Atom');
$writer->startElement("channel");
//----------------------------------------------------
//$writer->writeElement('ttl', '0');
$writer->writeElement('title', 'Latest Products');
$writer->writeElement('description', 'This is the latest products from our website.');
$writer->writeElement('link', 'http://www.domain.com/link.htm');
$writer->writeElement('pubDate', date("D, d M Y H:i:s e"));
$writer->startElement('image');
$writer->writeElement('title', 'Latest Products');
$writer->writeElement('link', 'http://www.domain.com/link.htm');
$writer->writeElement('url', 'http://www.iab.net/media/image/120x60.gif');
$writer->writeElement('width', '120');
$writer->writeElement('height', '60');
$writer->endElement();
//----------------------------------------------------
//----------------------------------------------------
$writer->startElement("item");
$writer->writeElement('title', 'New Product 8');
$writer->writeElement('link', 'http://www.domain.com/link.htm');
$writer->writeElement('description', 'Description 8 Yeah!');
$writer->writeElement('guid', 'http://www.domain.com/link.htm?tiem=1234');
$writer->writeElement('pubDate', date("D, d M Y H:i:s e"));
$writer->startElement('category');
$writer->writeAttribute('domain', 'http://www.domain.com/link.htm');
$writer->text('May 2008');
$writer->endElement(); // Category
// End Item
$writer->endElement();
//----------------------------------------------------
// End channel
$writer->endElement();
// End rss
$writer->endElement();
$writer->endDocument();
$writer->flush();
?>
<?xml version="1.0"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Latest Products</title>
<description>This is the latest products from our website.</description>
<link>http://www.domain.com/link.htm</link>
<pubDate>Thu, 10 Jul 2008 11:47:14 GMT</pubDate>
<image>
<title>Latest Products</title>
<link>http://www.domain.com/link.htm</link>
<url>http://www.iab.net/media/image/120x60.gif</url>
<width>120</width>
<height>60</height>
</image>
<item>
<title>New Product 8</title>
<link>http://www.domain.com/link.htm</link>
<description>Description 8 Yeah!</description>
<guid>http://www.domain.com/link.htm?tiem=1234</guid>
<pubDate>Thu, 10 Jul 2008 11:47:14 GMT</pubDate>
<category domain="http://www.domain.com/link.htm">May 2008</category>
</item>
</channel>
</rss>
generating xml using XmlWrite class
class XmlWriter {
var $xml;
var $indent;
var $stack = array();
function XmlWriter($indent = ' ') {
$this->indent = $indent;
$this->xml = '<?xml version="1.0" encoding="utf-8"?>'."\n";
}
function _indent() {
for ($i = 0, $j = count($this->stack); $i < $j; $i++) {
$this->xml .= $this->indent;
}
}
function push($element, $attributes = array()) {
$this->_indent();
$this->xml .= '<'.$element;
foreach ($attributes as $key => $value) {
$this->xml .= ' '.$key.'="'.htmlentities($value).'"';
}
$this->xml .= ">\n";
$this->stack[] = $element;
}
function element($element, $content, $attributes = array()) {
$this->_indent();
$this->xml .= '<'.$element;
foreach ($attributes as $key => $value) {
$this->xml .= ' '.$key.'="'.htmlentities($value).'"';
}
$this->xml .= '>'.htmlentities($content).'</'.$element.'>'."\n";
}
function emptyelement($element, $attributes = array()) {
$this->_indent();
$this->xml .= '<'.$element;
foreach ($attributes as $key => $value) {
$this->xml .= ' '.$key.'="'.htmlentities($value).'"';
}
$this->xml .= " />\n";
}
function pop() {
$element = array_pop($this->stack);
$this->_indent();
$this->xml .= "</$element>\n";
}
function getXml() {
return $this->xml;
}
}
/* Test
$xml = new XmlWriter();
$array = array(
array('monkey', 'banana', 'Jim'),
array('hamster', 'apples', 'Kola'),
array('turtle', 'beans', 'Berty'),
);
$xml->push('zoo');
foreach ($array as $animal) {
$xml->push('animal', array('species' => $animal[0]));
$xml->element('name', $animal[2]);
$xml->element('food', $animal[1]);
$xml->pop();
}
$xml->pop();
print $xml->getXml();
*/
?>
Perlmod is a program that will help you manage Perl Modules.
A Perl module is a discrete component of software for the Perl
programming language. Technically, it is a particular set of
conventions for using Perl's package mechanism that has become
universally adopted.[discuss] A module defines its source code to be
in a package (much like a Java package), the Perl mechanism for
defining namespaces, e.g. CGI or Net::FTP or XML::Parser; the file
structure mirrors the namespace structure (e.g. the source code for
Net::FTP is in Net/FTP.pm). Furthermore, a module is the Perl
equivalent of the class when object-oriented programming is employed
Now we'll see an easy way to manage them, install, list, delete
(uninstall) from the command line.
Perlmod is a program that will help you manage Perl Modules.
use PHP:: session
set by php ..
http://search.cpan.org/~miyagawa/PHP-Session-0.26/lib/PHP/Session.pm
script to delete dovecot users
#
# deldovecotuser - for deleting virtual dovecot users
#
if [ ! $# = 1 ]
then
echo -e "Usage: $0 username@domain"
exit 1
else
user=`echo "$1" | cut -f1 -d "@"`
domain=`echo "$1" | cut -s -f2 -d "@"`
if [ -x $domain ]
then
echo -e "No domain given\nUsage: $0 username@domain: "
exit 2
fi
fi
read -n 1 -p "Delete user $user@$domain from dovecot? [Y/N]? " REPLY
echo
case $REPLY in
y | Y)
new_users=`grep -v $user@$domain /etc/dovecot-users`
new_passwd=`grep -v $user@$domain /etc/dovecot-passwd`
new_vmaps=`grep -v $user@$domain /etc/postfix/vmaps`
new_vhosts=`grep -v $domain /etc/postfix/vhosts`
echo "Deleting $user@$domain from /etc/dovecot/users"
echo "$new_users" > /etc/dovecot-users
echo "Deleting $user@$domain from /etc/dovecot-passwd"
echo "$new_passwd" > /etc/dovecot-passwd
echo "Deleting $user@$domain from /etc/postfix/vmaps"
echo "$new_vmaps" > /etc/postfix/vmaps
echo "Deleting $domain from /etc/postfix/vhosts"
echo "$new_vhosts" > /etc/postfix/vhosts
postmap /etc/postfix/vmaps
postfix reload
read -n1 -p "Delete all files in /home/vmail/$domain/$user? [Y/N]? " DELETE
echo
case $DELETE in
y | Y)
echo "Deleting files in /home/vmail/$domain/$user"
rm -fr /home/vmail/$domain/$user
rm -fr /home/vmail/$domain
;;
* )
echo "Not deleting files in /home/vmail/$domain/$user"
;;
esac
;;
* )
echo "Aborting..."
;;
esac