Supermind Search Consulting Blog 
Solr - Elasticsearch - Big Data

Posts about programming

Fixing private posts in WordPress 1.2

Posted by Kelvin on 24 Dec 2004 | Tagged as: programming

Private posts in WP 1.2 aren't displayed even to the user who created them. This may already have been patched in versions of WordPress > 1.2, but I haven't upgraded yet.

Only one file needs to be changed: wp-blog.header.php

  1. Do a search for "// Category stuff" without the quotes
  2. Copy and paste the following ABOVE "// Category stuff":
    // Check if the user is logged-in - KT 24122004
      if((!empty($_COOKIE['wordpressuser_'.$cookiehash])) && 
    (!empty($_COOKIE['wordpresspass_'.$cookiehash]))) {
        $user_login = $_COOKIE['wordpressuser_'.$cookiehash];
        $user_pass_md5 = $_COOKIE['wordpresspass_'.$cookiehash];
      }
      function checklogin() {
        global $user_login, $user_pass_md5, $user_ID;
        $userdata = get_userdatabylogin($user_login);
        if ($user_pass_md5 != md5($userdata->user_pass)) {
          return false;
        } else {
         $user_ID = $userdata->ID;
          return true;
        }
      } 
      checklogin();
    
  3. That's it! Private posts will now be displayed. If you'd like some kind of indication that the post is a private one, edit index.php and insert something like

    < ?php if ('private' == $post->post_status) _e(' - Private'); ?>

    into the region where the post is displayed.

  4. What's basically happening is a check is done if the login cookie exists, and if so, ensure the username and password is valid, before setting $user_ID which is used later on to retrieve private posts. I could have also modified the login code to include the user_id in the cookie, but didn't think that was as secure as this approach, though this incurs an additional database hit to perform the login check.

Open-source project evaluation

Posted by Kelvin on 23 Dec 2004 | Tagged as: programming

Evaluating open-source projects is always tricky. Here's what I've been doing:

  1. Check online documentation. User guide? Architecture? Javadocs? Tutorials?
  2. Download binary and source.
  3. Run demo.
  4. Click through demo.
  5. Scan the source code. Check the package layout.

At this stage, I usually have a pretty good idea of how healthy the project is.

ofBiz: Take 2

Posted by Kelvin on 09 Dec 2004 | Tagged as: work, programming

I'm quite disillusioned by the ofBiz community, here's why:

1. Low emphasis on documentation. Or should I say, freely available documentation. The code is poorly documented, tutorials and Javadocs hardly exist, and when newbie questions are asked, the most frequently heard answers on the mailing list are: purchase the training videos, and purchase a subscription to the upcoming documentation site.

2. Little emphasis on coherent releases, no clear roadmap.

3. There is abit of an elitist attitude in the community, that goes along the lines of: ofBiz will make your life x times easier, and its incredibly powerful, and because its way of doing things is so different, it'll take you about 6 months to get productive in it. Excuse me, 6 months?

Having said that, however, I'm very impressed with the flexibility of the data model, and there are some very good ideas to be found in it. So, I had the idea of doing something like an ofBiz-for-sane-people project. 🙂 No, I'm just kidding.

What I'll probably do is revert to my old plan of building a Hibernate/Spring/Webwork2/Freemarker framework for developing web apps. Yes, you heard me right, Freemarker, not Velocity. I'm a recent convert to the power of taglibs, and would be pretty sweet to have access to them from the template. I will also use a portal framework for handling the integration between different web apps.

The to-do list, in chronological order:
1. Party manager, as per ofBiz
2. Classification manager, for managing topic maps
3. Document manager, the doc management system

Documenting ofBiz: 02.12.2004

Posted by Kelvin on 02 Dec 2004 | Tagged as: programming

  • widget-form.dtd is found at ofBizHome/components/content/dtd/widget-form.dtd. This file is very helpful when learning to code forms using the form widget.
  • To substitute values into XXXForms.xml fields, in the appropriate .bsh file, use something like formWrapper.putInContext("name", "value") instead of adding the value into the context. Even better, check out the wiki page for form widgets.
  • Individual <field> declarations override defaults for the <auto-fields-entity>. For example, this is how to make a hidden field with a value:
    <field name="fieldName"><hidden value="defaultValue"/></field>
  • There is a (implicit?) case-sensitive naming convention for form actions. This is IMPORTANT!
    1. Actions displaying forms to create an entity: AddXXX
    2. Actions executing the entity creation: createXXX
    3. Actions displaying forms to update an entity: EditXXX
    4. Actions executing the entity update: updateXXX
    5. Actions executing entity deletion: removeXXX

    The rule of thumb is all actions which display a view should be start with an upper-case character, and all database-related actions should start with a lower-case character.

Documenting ofBiz: 01.12.2004

Posted by Kelvin on 01 Dec 2004 | Tagged as: programming

Seeing that ofBiz's developer docs are so atrocious, I'm gonna start documenting my learnings here. Maybe they'll find their way to ofBiz's Wiki, which is also in a terrifying state of disrepair.

  • ofBizHome/base/config/component-load.xml: contains information on which components are loaded. Comment out a couple when developing to lower startup time.
  • ${component}/data/${component}TypeData.xml contains data that can be loaded into the database. Use WebTools to load the data into DB.
  • Every new component needs ofbiz-component.xml in the component's home directory.
  • The base-permission attribute in webapp in ofbiz-component.xml refers to the role that must exist for a user to log-in to this webapp. So, when creating a new component, its important to also load data into security_permission and security_group_permission so users can log-in.
  • The recommended way of developing forms is using the FormWidget. This basically involves creating a ${component}Forms.xml and placing in the same folder as your .ftl files. Check out examples in the Content webapp.

That's all for tonight.. just wanted to jot them down before I forget.

Spring, Hibernate and Velocity

Posted by Kelvin on 21 Nov 2004 | Tagged as: work, programming

I've been busy getting Spring, Hibernate and Velocity working, so some rants about it..

When I started using Torque as an OR tool, I really liked the its query-by-criteria system, but disliked the fact that code generation had to be done, and that every domain object effectively became five objects (Person, PersonPeer, BasePerson and BasePersonPeer and PersonMap). Also irritating was the compulsory inheritance from a persistence-based superclass, which seemed to be an abuse of inheritance, and takes away your only chance of inheritance in Java. I also didn't like the fact that all domain objects were placed into an om package. After a while, it just gets really unmanageable.

So, I was really thrilled when I discovered Hibernate. No more code generation, no more persistence-class inheritance and my objects could live anywhere they wanted.

Spring recommends a differentiation between POJOs, DAO classes (like Torque Peers), service objects (where business logic and transactions resides) and the web layer. As you'll see from the jPetstore demo, the objects are also placed into these packages accordingly.

One huge difficulty I ran with Spring and Hibernate was lazy instantiation of collections. Hibernate's sessionfactory is managed by Spring, so unless an object is created by Spring, there's no easy way of getting hold of a Hibernate session. Technically, POJOs aren't supposed to even know about sessions. HOWEVER, with a lazily instantiated collection, the same session that opened the proxy must be still open when getCollection() is called on the collection, and that's a big problem. when the poor POJO has no reference or knowledge about the session.

This is well documented at these links, with some workarounds suggested
http://thread.gmane.org/gmane.comp.java.springframework.user/3513
http://thread.gmane.org/gmane.comp.java.springframework.user/3402
http://forum.springframework.org/viewtopic.php?t=1640&highlight=hibernate+dao&sid=828d4100ba2f6f8dffc7f06bc7054857
http://forum.springframework.org/viewtopic.php?t=1805&highlight=hibernate+dao&sid=828d4100ba2f6f8dffc7f06bc7054857
http://forum.springframework.org/viewtopic.php?t=301&postdays=0&postorder=asc&highlight=hibernate+dao&start=0

So, I've had to compromise and remove the lazy instantiation and perform it via the DAO instead. Yucky, but lazy instantiation's really important for that object, and I really like Spring's wrapper around Hibernate.

Something else I worked on was porting Velocity Tool's VelocityLayoutServlet to Spring, so template layouts are possible once again, plus use of tools in templates.

Open-source Java infrastructure

Posted by Kelvin on 19 Nov 2004 | Tagged as: work, programming

I'm gonna start a new project in Java soon. Seeing that I've left http://www.relevanz.com, pretty much whatever infrastructure I had built over the past years is gone, and I'll have to start from scratch, and that's probably a Good Thing.

So here's some items on my list (LGPL- or APL-compatible only):

Templating – Velocity, and Velocity tools
Scheduling – Quartz Scheduler
Cache – OSCache
User management – Oness
Security – http://acegisecurity.sourceforge.net/
Modules – ?
App Framework – Spring
Persistence – Hibernate
Search Engine – Lucene
Portlet – ?
Document Management – Daisy

Firefox Highlighting

Posted by Kelvin on 15 Nov 2004 | Tagged as: work, programming

I've started work on a highlighting extension in Firefox which allows one to save the highlighted text. Running into a wall with highlighting across elements. Highlighting within the same element is already functional, but it seems no one has actually gotten cross-element highlighting right. And the funny thing is, it all seems so trivial from the user's point of view…

Anyway, the links that have proved useful in learning about the DOM Range api and Mozilla's nsISelection:
http://www.xulplanet.com/references/xpcomref/
Everything can be a link…
http://www.mail-archive.com/mozilla-editor@mozilla.org/msg01437.html
http://www.webmasterworld.com/forum91/1170.htm
http://markpasc.org/weblog/2002/07/15/mozilla_editor_links_for_my_reference
and various extensions which perform highlighting from a cursor selection.

Python and Cheetah

Posted by Kelvin on 29 Oct 2004 | Tagged as: work, programming

Had my first stab at a python app: a web contact information db for the German intensive course I'm attending. Used Cheetah, a Velocity-like template engine for python. There are minor differences between Velocity and Cheetah, but these are minor – I was productive in about 30 minutes.

I really like Python. Things just work.

More on C++ regex

Posted by Kelvin on 05 Oct 2004 | Tagged as: programming

I got PCRE up and running with minimal hassle. There are binary versions available for most platforms.

Although its a C library, there are C++ wrappers available, most notably PCRE++. There seems to be a search-replace feature in PCRE++ as well.

More to update when I have abit more time. Today I travel to Münich. Hope to get some programming done on the train.

« Previous PageNext Page »