<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" ><channel><title>Kevin Deldycke &#187; Zenphoto</title> <atom:link href="http://kevin.deldycke.com/tag/zenphoto/feed/" rel="self" type="application/rss+xml" /><link>http://kevin.deldycke.com</link> <description>Free software engineer &#38; wannabe videomaker</description> <lastBuildDate>Fri, 03 Feb 2012 19:08:27 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>How-to: e107 autogallery to Zenphoto migration</title><link>http://kevin.deldycke.com/2008/08/how-to-e107-autogallery-to-zenphoto-migration/</link> <comments>http://kevin.deldycke.com/2008/08/how-to-e107-autogallery-to-zenphoto-migration/#comments</comments> <pubDate>Thu, 21 Aug 2008 22:42:05 +0000</pubDate> <dc:creator>Kev</dc:creator> <category><![CDATA[English]]></category> <category><![CDATA[autogallery]]></category> <category><![CDATA[e107]]></category> <category><![CDATA[Linux]]></category> <category><![CDATA[migration]]></category> <category><![CDATA[MySQL]]></category> <category><![CDATA[Python]]></category> <category><![CDATA[Script]]></category> <category><![CDATA[Snippet]]></category> <category><![CDATA[SQL]]></category> <category><![CDATA[Web]]></category> <category><![CDATA[Zenphoto]]></category><guid isPermaLink="false">http://kevin.deldycke.com/?p=310</guid> <description><![CDATA[These past few days I was working on the Cool Cavemen&#8217;s photo gallery to move it to a shiny new one, powered by Zenphoto. In this post I will roughly describe how I&#8217;ve done it, code and commands included. The &#8230; <a href="http://kevin.deldycke.com/2008/08/how-to-e107-autogallery-to-zenphoto-migration/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>These past few days I was working on the <a href="http://coolcavemen.com/photos">Cool Cavemen&#8217;s photo gallery</a> to move it to a shiny new one, powered by <a href="http://zenphoto.org">Zenphoto</a>. In this post I will roughly describe how I&#8217;ve done it, code and commands included.</p><p>The old gallery was based on <a href="http://sourceforge.net/projects/e107autogallery">autogallery</a>, a <a href="http://e107.org">e107</a> plugin. We assume here that both e107 and Zenphoto are well configured and installed at the root of you web hosting space (<code>/www</code> in this case).</p><p>The first step is to copy the autogallery album structure, with all its content, to Zenphoto:</p><pre class="brush: bash; title: ; notranslate">
cd /www
cp -ax ./e107_plugins/autogallery/Gallery/* ./zenphoto/albums/
</pre><p>Then we delete all previews, thumbnails and XML metadatas, to keep in Zenphoto original assets only:</p><pre class="brush: bash; title: ; notranslate">
find ./zenphoto/albums/ -iname &quot;*.xml&quot; | xargs rm -f
find ./zenphoto/albums/ -iname &quot;pv_*&quot; | xargs rm -f
find ./zenphoto/albums/ -iname &quot;th_*&quot; | xargs rm -f
</pre><p>By now, you should be able to play with your medias using Zenphoto&#8217;s admin interface.</p><p>But if you&#8217;re unlucky as I was, you will find a strange bug which break down drag&#8217;n'drop album sorting. The fix I found was to remove, in photo filenames, the numerical prefix (and the following dot) set by autogallery to define the sort order. This operation should be performed, <em>before</em> the copy from autogallery to Zenphoto (= the first command in this post). By the way, if you know a one-liner to do this, please, please&#8230; share ! <img src='http://kevin.deldycke.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p>To migrate comments, I have no automatic solution. I choose to do this manually, editing the database by hand. In my case it was the quickest way as I only had a dozen of comments to migrate.</p><p>And last but not least, if you care about measuring the popularity of your photos, you should consider migrating the view counter associated with each of your media. Don&#8217;t worry, this time I wrote a script to take care of it automagically. It will generate a bunch of SQL statements you&#8217;ll have to execute on your Zenphoto MySQL database. Here is my <a href='http://kevin.deldycke.com/wp-content/uploads/2008/08/e107-autogallery-to-zenphoto-hit-counter-migration.py'>&#8220;e107 autogallery to Zenphoto hit counter migration script&#8221;</a> (nice name isn&#8217;t it ? <img src='http://kevin.deldycke.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ) that do the job:</p><pre class="brush: python; title: ; notranslate">
#!/usr/bin/python

##############################################################################
#
# Copyright (C) 2008 Kevin Deldycke &lt;kevin@deldycke.com&gt;
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
##############################################################################

&quot;&quot;&quot;
  Last update: 2008 aug 21
&quot;&quot;&quot;

########### User config ###########

AUTOGALLERY_ALBUM_PATH = &quot;/www/e107_plugins/autogallery/Gallery&quot;
ZENPHOTO_ALBUM_PATH    = &quot;/www/zenphoto/albums&quot;
ZENPHOTO_TABLE_PREFIX  = &quot;zenphoto_&quot;

######## End of user config #######

import os, hashlib
import xml.etree.ElementTree as ET

# Calculate hash of a given file
def getHash(path):
  # Calculate the hash from file raw data
  if not os.path.isfile(path):
    return None
  try:
    file_object = open(path, 'r')
    data = file_object.read()
  except:
    return None
  if not len(data):
    return None
  return hashlib.sha224(data).hexdigest()

# Associate each autogallery photo having a hitcounter greater than 0 with its MD5 hash
def populateHashTable(arg, dirname, names):
  global hash_table
  for name in names:
    file_path = os.path.join(dirname, name)
    # print &quot;Get hit count for %s&quot; % file_path
    # Check that the file as a positive hit counter associated with
    xml_file_path = &quot;%s.xml&quot; % file_path
    if not os.path.isfile(xml_file_path):
      continue
    try:
      tree = ET.parse(xml_file_path)
    except:
      continue
    node = tree.find(&quot;viewhits&quot;)
    if node is None:
      continue
    try:
      hits = int(node.text)
    except:
      continue
    if not hits &gt; 0:
      continue
    # Update hash table with data we care about
    file_hash = getHash(file_path)
    if file_hash is None:
      continue
    hash_table[file_hash] = hits + hash_table.get(file_hash, 0)

# Generate hitcount SQL request for each matching file
def generateSQL(arg, dirname, names):
  global sql
  for name in names:
    file_path = os.path.join(dirname, name)
    # print &quot;Search hitcounter matching file %s&quot; % file_path
    file_hash = getHash(file_path)
    if file_hash is None:
      continue
    if file_hash in hash_table:
      sql += &quot;UPDATE `%simages` SET `hitcounter`=`hitcounter`+%d WHERE `filename`=%r;\n&quot; % (ZENPHOTO_TABLE_PREFIX, hash_table[file_hash], name)

# Core of the script
hash_table = {}
sql        = &quot;&quot;
# Normalize path
source_path = os.path.abspath(AUTOGALLERY_ALBUM_PATH)
dest_path   = os.path.abspath(ZENPHOTO_ALBUM_PATH)

os.path.walk(source_path, populateHashTable, None)
# print repr(hash_table)
os.path.walk(dest_path, generateSQL, None)
print sql
</pre><p>I think code and comments are self-explainatory. And do not forget to update constants at the top of the script to match your installation paths and database&#8217;s tables prefix.</p><p>And finally, for your information, I tested all of this on following versions:</p><ul><li>e107 0.7.11</li><li>autogallery 2.61</li><li>Zenphoto 1.2</li><li>Python 2.5.2</li><li>Linux server</li></ul> ]]></content:encoded> <wfw:commentRss>http://kevin.deldycke.com/2008/08/how-to-e107-autogallery-to-zenphoto-migration/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>How-to add Google Analytics tracking to Zenphoto</title><link>http://kevin.deldycke.com/2008/08/how-to-add-google-analytics-tracking-to-zenphoto/</link> <comments>http://kevin.deldycke.com/2008/08/how-to-add-google-analytics-tracking-to-zenphoto/#comments</comments> <pubDate>Sat, 16 Aug 2008 20:49:55 +0000</pubDate> <dc:creator>Kev</dc:creator> <category><![CDATA[English]]></category> <category><![CDATA[analytics]]></category> <category><![CDATA[Google]]></category> <category><![CDATA[hack]]></category> <category><![CDATA[patch]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Snippet]]></category> <category><![CDATA[Web]]></category> <category><![CDATA[Zenphoto]]></category><guid isPermaLink="false">http://kevin.deldycke.com/?p=286</guid> <description><![CDATA[This is the patch I apply on each Zenphoto I install and upgrade. This little hack add Google Analytics tracking for all users except administrators. Why ? As you can see in ticket #441 in Zenphoto bugtracker, there is no &#8230; <a href="http://kevin.deldycke.com/2008/08/how-to-add-google-analytics-tracking-to-zenphoto/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p><img src="http://kevin.deldycke.com/wp-content/uploads/2008/08/zenphoto-12-150x23.png" alt="" title="zenphoto-12" width="150" height="23" class="alignleft size-thumbnail wp-image-299" /></p><p>This is the patch I apply on each <a href="http://www.zenphoto.org">Zenphoto</a> I install and upgrade. This little hack add <a href="http://www.google.com/analytics/">Google Analytics</a> tracking for all users except administrators.</p><p>Why ? As you can see in <a href="http://www.zenphoto.org/trac/ticket/441">ticket #441 in Zenphoto bugtracker</a>, there is no intention of adding support of GA in Zenphoto, even as an optional plugin. Hence my tiny hack. And for the non-admin stuff, I like having unbiased statistics: on low-audience websites, administrators can generate more traffic than legitimate users (if not all&#8230;).</p><p>Here is the <a href='http://kevin.deldycke.com/wp-content/uploads/2008/08/google-analytics-tracking-for-non-admin-users.patch'>downloadable patch file</a>, and its content:</p><pre class="brush: diff; title: ; notranslate">
diff -ru ./zenphoto-orig/zp-core/template-functions.php ./zenphoto/zp-core/template-functions.php
--- ./zenphoto-orig/zp-core/template-functions.php  2008-08-15 07:43:05.000000000 +0200
+++ ./zenphoto/zp-core/template-functions.php 2008-08-16 17:08:03.000000000 +0200
@@ -147,7 +147,16 @@

    echo &quot;&lt;li&gt;&lt;a href=\&quot;&quot;.$zf.&quot;/admin.php?logout$redirect\&quot;&gt;&quot;.gettext(&quot;Logout&quot;).&quot;&lt;/a&gt;&lt;/li&gt;\n&quot;;
    echo &quot;&lt;/ul&gt;&lt;/div&gt;\n&quot;;
- }
+ } else {
+    echo &quot;&lt;script type=\&quot;text/javascript\&quot;&gt;
+var gaJsHost = ((\&quot;https:\&quot; == document.location.protocol) ? \&quot;https://ssl.\&quot; : \&quot;http://www.\&quot;);
+document.write(unescape(\&quot;%3Cscript src='\&quot; + gaJsHost + \&quot;google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E\&quot;));
+&lt;/script&gt;
+&lt;script type=\&quot;text/javascript\&quot;&gt;
+var pageTracker = _gat._getTracker(\&quot;UA-XXXXXX-Y\&quot;);
+pageTracker._trackPageview();
+&lt;/script&gt;&quot;;
+  }
 }

 /**
</pre><p>This patch was generated from a <a href="http://www.zenphoto.org/2008/08/zenphoto-12-release-announcement/">Zenphoto v1.2</a> and will likely not work with any other version.</p><p>Do not forget to update the dummy Google Analytics account ID above (<code>UA-XXXXXX-Y</code>) by yours.</p><p>And finally, to apply the patch, invoke the classic <code>patch</code> command:</p><pre class="brush: bash; title: ; notranslate">
patch -p0 &lt; ./google-analytics-tracking-for-non-admin-users.patch
</pre>]]></content:encoded> <wfw:commentRss>http://kevin.deldycke.com/2008/08/how-to-add-google-analytics-tracking-to-zenphoto/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 2/16 queries in 0.007 seconds using apc
Object Caching 599/625 objects using apc

Served from: kevin.deldycke.com @ 2012-02-08 10:44:28 -->
