Results 1 to 4 of 4
  1. #1
    New Pligger tickle's Avatar
    Joined
    Sep 2006
    Posts
    22

    Don't know if this is too late to suggest

    I briefly look into some codes, and thought those "copy/paste" can be avoided. We didn't use the better part of php -- the inheritance.

    For each Pligg page, we need to load "header" and "footer", and may be sidebar too, we can avoid the copy/paste by creating a base class to handle the common loading and initialization. In this way, when we need to make any change in header, footer, or sidebar, there is only one place to go...

    <?php
    if ( !defined( 'LIBS_PliggPage' ) )
    define( 'LIBS_PliggPage', true );

    class PliggPage {

    public function PliggPage( ... ) { // whatever arguments are needed

    // php has no destructor, register_shutdown_function is to get around with the
    // missing function. "cleanup" will be called when the script exits, either normal,
    // or due to error
    register_shutdown_function( array( $this, "closure" ) );

    $this->init();
    $this->loadPageHeader();

    $this->draw(); // this must be implemented by derived class
    }

    private function init() { // all kinds of initialization go here
    $this->initDBConnection();
    ....

    }

    private function loadPageHeader() {
    // load the header
    }

    public function closure() {
    // load the footer, cleanup, etc.
    }

    protect function draw() {
    // no implementation in the base
    }

    }

    ?>


    Now you get easy with the real page, say the index page:

    <?php

    if !defined(....)
    define(...)

    class FrontPage extends PliggPage {

    public function FrontPage( ... ) {
    parent::PliggPage( ... ); // php doesn't call parent's ctor automatically
    }

    protected function draw() {
    // implement your real meat here for the front page
    }

    }

    ?>

    Now, write the index.php like this:

    <?php

    include( 'FrontPage.php' );

    new FrontPage( ... ); // that is it!!

    ?>


    The worst computer features to have when writing software is the "copy" and "paste" buttons. They should be completely disabled when writing codes!

    phpBB is out of control as I look at the codes some time ago. The code can be reduced by 90% if there is a design! I hope Pligg is not too late to have the inheritance in mind.

  2. #2
    Constant Pligger jitgos's Avatar
    Joined
    Apr 2006
    Posts
    315
    Tickle,

    First, thanks for helping. Second, nothing is too late ever with pligg. In fact there's FAR FAR FAR more going on with the pligg code to make it better, faster, cleaner, simpler, and easier to mod than you might believe. Nothing is out of the question when it comes to improving pligg.

    Jitgos

  3. #3
    Constant Pligger savant's Avatar
    Joined
    Apr 2006
    Posts
    1,181
    nice oop

    man i wish i knew more oop standards and patterns

    is your implementation compatible with php 4?

  4. #4
    New Pligger tickle's Avatar
    Joined
    Sep 2006
    Posts
    22
    Should work in both php4 and php5

Similar Threads

  1. Suggest me a template plz
    By Handsome in forum Questions & Comments
    Replies: 10
    Last Post: 04-28-2008, 04:06 AM
  2. New Mod -- Suggest a Category
    By chuckroast in forum Questions & Comments
    Replies: 2
    Last Post: 04-26-2007, 02:04 AM
  3. Suggest me...
    By dollars5 in forum Questions & Comments
    Replies: 4
    Last Post: 04-18-2007, 11:26 AM
  4. Suggest me what should I do?
    By dollars5 in forum Questions & Comments
    Replies: 4
    Last Post: 12-18-2006, 10:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Pligg Modules and Pligg Templates from Pligg Pro Donate to Pligg CMS Dreamhost Web Hosting Host Gator Web Hosting