<?php
/*
Plugin - PlogStaticRotator
Copyright (C) 2005 Matthew Wood
                                                                                
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
*/


include_once(PLOG_CLASS_PATH."class/plugin/pluginbase.class.php");
include_once(PLOG_CLASS_PATH.
    "plugins/plogstaticrotator/class/dao/plogstaticrotatorcontents.class.php");

class PluginPlogStaticRotator extends PluginBase
{
  function PluginPlogStaticRotator()
  {
    $this->PluginBase();

    $this->id = "PlogStaticRotator";
    $this->desc = "Allows administrators to place a static block in their templates while also being able to rotate the content displayed in it";
    $this->author = "woodzy";
    $this->locale = Array();

    $this->addMenuEntry("/menu/Manage","PlogStaticRotator","");
    $this->addMenuEntry("/menu/Manage/PlogStaticRotator","ViewStaticContent",
        "?op=plogViewRotatorContent");
    $this->addMenuEntry("/menu/Manage/PlogStaticRotator","NewRotatorContent",
        "?op=plogNewViewRotatorContent");
    $this->addMenuEntry("/menu/Manage/PlogStaticRotator","EditContent",
        "?op=plogEditViewRotatorContent");

    $this->registerAdminAction("plogViewRotatorContent",
        "AdminPlogStaticRotatorViewAction");
    $this->registerAdminAction("plogNewRotatorContent",
        "AdminPlogStaticRotatorNewAction");
    $this->registerAdminAction("plogNewViewRotatorContent",
        "AdminPlogStaticRotatorNewViewAction");
    $this->registerAdminAction('plogEditViewRotatorContent',
        "AdminPlogStaticRotatorEditViewAction");
    $this->registerAdminAction('plogEditRotatorContent',
        "AdminPlogStaticRotatorEditAction");
    $this->registerAdminAction('plogDeleteRotatorContent',
        "AdminPlogStaticRotatorDeleteAction");

    $this->install;
  }

  function install()
  {
    $fields = "
      id I4 NOTNULL PRIMARY AUTOINCREMENT,
      blogid I4 NOTNULL KEY,
      title C(50) NOTNULL,
      content TEXT";

    $db =& Db::getDb();
    $dbPrefix = Db::getPrefix();

    $tableName = $dbPrefix."plogstaticrotator_content";

    $dict = NewDataDictionary($db);

    $sqlAry = $dict->ChangeTableSQL($tableName,$fields);
    $result = $dict->ExecuteSQLArray($sqlAry);
    if (!$result)
      die("There was an error creating plogbirthday plugin tables!");
    
    return true;
  }
  function getContent($blogid)
  {
    /* database stores month & day in mmdd format */
    $psrc = new PlogStaticRotatorContents();
    $content = $psrc->getRandomContent($blogid);
    return $content;
  }
}

/* vim:ai:sw=2:expandtab:cin:
*/
?>
