Something like a sidebar...

Something like a sidebar...

Postby Pryrates on Tue Jul 08, 2008 4:50 pm

hi!

First of all: I did not know where to post this, because I don't know whether it is Plugin related or template related and it is not a real problem, more a question... If I'm wrong in this forum I'm sorry.


The first time I heard something about lifetype was on a website, that had on the left side something like a sidebar, in that all blogs were listed, whereas in the rest of the space the space the blog was located. With a click on the Bar one could easily get to another blog. I found this interesting thats why I realized the lifetype Symbol at the bottom of the page and I went for a look at the lifetype site.

Now I'm running lifetype on my own and I really want to integrate such a sidebar, but I haven't found information about it in the wiki or in the forums so far. So: how do I do that?

I hope you can help me.
peace Pryrates
Pryrates
 
Posts: 8
Joined: Mon Jul 07, 2008 12:25 pm
LifeType Version: 1.2.8

Re: Something like a sidebar...

Postby jondaley on Wed Jul 09, 2008 12:01 am

That sounds like a plugin of sorts - I vaguely recall someone(s) asking for something like that - I don't think there is an officially released plugin that does that. You might search around on the forums, and see if the user posted any code.

Do you simply want a link to all blogs on the server?

That probably wouldn't be too hard to write.
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: Something like a sidebar...

Postby Pryrates on Wed Jul 09, 2008 3:12 am

Yep, I want a column besinde my blog where there are links to all other blogs.
Pryrates
 
Posts: 8
Joined: Mon Jul 07, 2008 12:25 pm
LifeType Version: 1.2.8

Re: Something like a sidebar...

Postby Pryrates on Thu Jul 10, 2008 4:21 am

Still found nothing on this board...

Has noone an idea? Or if nothin else helps at least some tips concerning how to code it or so since I'm new to php coding...
Pryrates
 
Posts: 8
Joined: Mon Jul 07, 2008 12:25 pm
LifeType Version: 1.2.8

Re: Something like a sidebar...

Postby jondaley on Thu Jul 10, 2008 7:07 am

You'll probably want to start with a plugin like recentcomments, and modify it a ton. I wouldn't worry about the admin side of things, and comment out all of the menu creation and stuff like that for now. You'll want a function like the getArticle() that is in that plugin, and instead make a getBlogs() that looks something like this:

Code: Select all
function getBlogs(){
   lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );                           
   $blogs = new Blogs();
   return $blogs->getAllBlogs();
}


And then in your template code, you'll call various function (found in class/dao/bloginfo.class.php) like:
Code: Select all
{if $allblogs && $allblogs->isEnabled}
{assign var=blogs value=$allblogs->getBlogs()}
<ul>
{foreach from=$blogs item=panel_blog}
  {assign var=generator value=$panel_blog->getResourceGenerator()}
  <li><a href="{$generator->blogLink()}">{$panel_blog->getBlog()}</a></li>
{/foreach}
</ul>
{/if}


Or a little simpler:
Code: Select all
{assign var=blogs value=$allblogs->getBlogs()}
<ul>
{foreach from=$blogs item=panel_blog}
  <li><a href="{$url->blogLink($panel_blog)}">{$panel_blog->getBlog()}</a></li>
{/foreach}
</ul>


You'll want the {if} statements in your final code, but you can leave them out for testing. And I think the second bit of code will work without getting a resourceGenerator for each blog.
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: Something like a sidebar...

Postby Pryrates on Thu Jul 10, 2008 8:59 am

This might be annoying but since I'm a real noob concerning php and .template (.template is just html code...?) I have more questions.

For start I just inserted the first code snippet you gave me in the pluginrecentcomments.class.php as a new function and let the rest as it was since I was not sure about what is still needed.

But then... there are some other files and since I'm trying to change the code I would really like to know what those do first, so that I could see what has to be changed and what I don't need...
The language files are unimportant.

class/pluginrecentcommentsconfigaction.php an heir of AdminAction from Joomla, but what it is supposed to do?
Same for class/pluginrecentcommentsrssaction.class.php and class/pluginrecentcommentsupdateconfigaction.class.php... :-(

view/... seems to be unimportant for now for what I want. I guess this is just for the adminsection.


The next code snipped you gave me is supposed to be placed in "my" template. The plugin comes with two templates: recentcomments.template and rss20.template and which one is to be edited? recentcomments.template to me looks to me again not like the file that displays the plugin, but: I don't know :-(

Sorry to ask such basic questions.
Pryrates
 
Posts: 8
Joined: Mon Jul 07, 2008 12:25 pm
LifeType Version: 1.2.8

Re: Something like a sidebar...

Postby jondaley on Fri Jul 11, 2008 3:57 am

Correct, for the initial go at the plugin, you don't need any of the files in the plugin except the main pluginrecentcomments.class.php (which you should name whatever you want to call your plugin) You need the constructor of the plugin (where the author and date, etc. are set). And then I think just the one function I gave above.

Once it is working, then you can put in some other code so it can be enabled from the admin, etc.

Yes, the template code goes in your template, in the plugin/templates directory - those are for the admin side as well.

I have no idea why you mentioned Joomla - that doesn't seem to be related to what you are talking about.
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: Something like a sidebar...

Postby Pryrates on Fri Jul 11, 2008 4:13 am

Yes this was an error, I meant lifetype.

Ok I'll try what you said, prepare for the next questions in about an hour :-)
Pryrates
 
Posts: 8
Joined: Mon Jul 07, 2008 12:25 pm
LifeType Version: 1.2.8

Re: Something like a sidebar...

Postby Pryrates on Fri Jul 11, 2008 5:10 am

So...
Code: Select all
//BlogList.class.php
<?php

    include_once( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
    include_once( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );

    class BlogList extends PluginBase
    {
        var $pluginEnabled;
        var $maxComments;

        function BlogList()
        {
            $this->PluginBase();
            $this->id = "BlogList";
            $this->author = "NN";
            $this->desc = "This plugin should display a List of all published weblogs.";
            $this->locales = Array( "en_UK" );
            $this->init();
        }

   function isEnabled()
   {
       return $this->pluginEnabled;
        }

   function getBlogs(){
            lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
            $blogs = new Blogs();
            return $blogs->getAllBlogs();
        }
    }
?>


and the template:
Code: Select all
<?xml version="1.0" encoding="{$locale->getCharset()}"?>
<?xml-stylesheet href="{$url->getUrl("/styles/rss.css")}" type="text/css"?>
<rss version="2.0"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
>
 <channel>
  <title>List of Weblogs</title>
  {assign var=blogs value=$allblogs->getBlogs()}
  <ul>
  {foreach from=$blogs item=panel_blog}
    <li><a href="{$url->blogLink($panel_blog)}">{$panel_blog->getBlog()}</a></li>
  {/foreach}
  </ul>
 </channel>
</rss>


Now I just made a dir
BlogList/
BlogList.class.php
template/
rss20.template
locale/
locale_en_UK.php
class/

and uploaded it in the plugin directory from lifetype. Does mot show in the plugin center and does nothing visible when visiting a blog. Same is true if I upload the the normal recent comments plugin with a different name and the changed files.
Hardly unexpected, yet I got stuck...

the post above should appear some minutes after yours, dunno why it's been sent just now..
Pryrates
 
Posts: 8
Joined: Mon Jul 07, 2008 12:25 pm
LifeType Version: 1.2.8

Re: Something like a sidebar...

Postby chromos on Fri Jul 11, 2008 2:37 pm

hmmm I see several errors.
Which template file have have you modified?

I did not try whether your plugin is functional, but i put all the stuff together you'll need for your plugin.

Here is the dir structure.
bloglist/
pluginbloglist.class.php
class/
action/
pluginbloglistconfigaction.class.php
pluginbloglistupdateconfigaction.class.php
view/
pluginbloglisconfigview.class.php
locale/
locale_en_UK.php
template/
bloglist.template

files go here:
pluginbloglist.class.php
Code: Select all
<?php
   
   lt_include( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
   
   /**
    * Plugin that offers features to return a recent article comments from the current blog
    */
   class PluginBlogList extends PluginBase
   {
      var $pluginEnabled;
       
      function PluginBlogList($source = "")
      {
         $this->PluginBase($source);
         $this->id = "bloglist";
         $this->version = "20081107";
         $this->author = "NN";
         $this->desc = "This plugin should display a List of all published weblogs.";
         
         $this->locales = Array( "en_UK");

         if( $source == "admin" ) {
            $this->registerAdminAction( "bloglist", "PluginBlogListConfigAction" );
            $this->registerAdminAction( "updateBlogListConfig", "PluginBlogListUpdateConfigAction" );
            $menu =& Menu::getMenu();
            if( !$menu->entryExists( "/menu/controlCenter/manageAppearancePlugins" ))
               $this->addMenuEntry( "/menu/controlCenter", "manageAppearancePlugins", "", "", true, false );         

            $this->addMenuEntry( "/menu/controlCenter/manageAppearancePlugins", "BlogList", "?op=bloglist", "" );
         }

      }

      function register()
      {
         $blogSettings = $this->blogInfo->getSettings();
         $this->pluginEnabled = $blogSettings->getValue( "plugin_bloglist_enabled" );
      }

      function isEnabled()
      {
         return $this->pluginEnabled;
      }
       
      function getBlogs()
      {
         lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
         $blogs = new Blogs();
         return $blogs->getAllBlogs();
      }

      function getPluginConfigurationKeys()
      {
         lt_include(PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php");
         return (Array(Array("name" => "plugin_bloglist_enabled", "type" => "boolean")));
      }
   }
?>


pluginbloglistconfigaction.class.php
Code: Select all
<?php

   lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
   lt_include( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );
   lt_include( PLOG_CLASS_PATH."plugins/bloglist/class/view/pluginbloglistconfigview.class.php" );   

   /**
    * shows a form with the current configuration
    */
   class PluginBlogListConfigAction extends AdminAction
   {
      
      function PluginBlogListConfigAction( $actionInfo, $request )
      {
         $this->AdminAction( $actionInfo, $request );
      }
      
      function perform()
      {
                  $this->_view = new PluginBlogListConfigView( $this->_blogInfo );
         $this->setCommonData();
         return true;
      }
   }
?>


pluginbloglistupdateconfigaction.class.php
Code: Select all
<?php

   lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
   lt_include( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );
   lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
   lt_include( PLOG_CLASS_PATH."plugins/bloglist/class/view/pluginbloglistconfigview.class.php" );   
      
   /**
    * updates the plugin configuration
    */
   class PluginBlogListUpdateConfigAction extends AdminAction
   {
      var $_pluginEnabled;
      
      function PluginBlogListUpdateConfigAction( $actionInfo, $request )
      {
         $this->AdminAction( $actionInfo, $request );
      }
      
      function validate()
      {
         $this->_pluginEnabled = $this->_request->getValue( "pluginEnabled" );
         $this->_pluginEnabled = ($this->_pluginEnabled != "" );         
         return true;
      }
             
      function perform()
      {
                  //update the plugin configurations to blog setting
         $blogSettings = $this->_blogInfo->getSettings();
         $blogSettings->setValue( "plugin_bloglist_enabled", $this->_pluginEnabled );
         $this->_blogInfo->setSettings( $blogSettings );
         //save the blogs settings
         $blogs = new Blogs();
         if( !$blogs->updateBlog( $this->_blogInfo )) {
            $this->_view = new PluginBlogListConfigView( $this->_blogInfo );
            $this->_view->setErrorMessage( $this->_locale->tr("error_updating_settings"));
            $this->setCommonData();
            return false;
         }
         
         // if everything went ok...
         $this->_blogInfo->setSettings( $blogSettings );
         $this->_session->setValue( "blogInfo", $this->_blogInfo );
         $this->saveSession();
         $this->_view = new PluginBlogListConfigView( $this->_blogInfo );
         $this->_view->setSuccessMessage( $this->_locale->tr("bloglist_settings_saved_ok"));
         $this->setCommonData();
         
         // clear the cache
         CacheControl::resetBlogCache( $this->_blogInfo->getId());            
           
                  return true;      
      }
   }
?>


pluginbloglistconfigview.class.php
Code: Select all
<?php
   lt_include( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );

   /**
    * implements the main view of the feed reader plugin
    */
   class PluginBlogListConfigView extends AdminPluginTemplatedView
   {

      function PluginBlogListConfigView( $blogInfo )
      {
         $this->AdminPluginTemplatedView( $blogInfo, "bloglist", "bloglist" );
      }

      function render()
      {
         // load some configuration settings
         $blogSettings = $this->_blogInfo->getSettings();
         $pluginEnabled = $blogSettings->getValue( "plugin_bloglist_enabled" );
         
         // create a view and export the settings to the template
         $this->setValue( "pluginEnabled", $pluginEnabled );
            
         parent::render();
      }
   }
?>


locale_en_UK.php
Code: Select all
<?php
$messages["managebloglist"] = "Blog List Management";
$messages["bloglist"] = "Blog List";

$messages["bloglist_plugin_enabled"] = "Enable this plugin";
$messages["bloglist_plugin"] = "Blog List Plugin";

$messages["bloglist_settings_saved_ok"] = "Blog List settings saved successfully!";
$messages["bloglist_error_maxcomments"] = "Maximum Showed Comments Should > 0!";

$messages["label_configuration"] = "Configuration";
$messages["label_enable"] = "Enable";
?>


bloglist.template
Code: Select all
{include file="$admintemplatepath/header.template"}
{include file="$admintemplatepath/navigation.template" showOpt=bloglist title=$locale->tr("bloglist_plugin")}
<form name="BlogListPluginConfig" method="post">
 <fieldset class="inputField">
 <legend>{$locale->tr("label_configuration")}</legend>
  {include file="$admintemplatepath/successmessage.template"}
  {include file="$admintemplatepath/errormessage.template"} 
  <div class="field">
   <label for="pluginEnabled">{$locale->tr("label_enable")}</label>
   <span class="required"></span>
   <div class="formHelp">
    <input class="checkbox" type="checkbox" name="pluginEnabled"
           id="pluginEnabled" {if $pluginEnabled} checked="checked" {/if}
           {user_cannot_override
             key=plugin_bloglist_enabled}disabled="disabled"
           {/user_cannot_override}
           value="1" 
     />{$locale->tr("bloglist_plugin_enabled")}
   </div>

  </div>
</form>
{include file="$admintemplatepath/footernavigation.template"}
{include file="$admintemplatepath/footer.template"}


Have a look at the plugins from the wiki. Hope there are no typos ;)
Last edited by chromos on Sat Jul 12, 2008 11:32 am, edited 1 time in total.
chromos
 
Posts: 274
Joined: Wed Mar 09, 2005 2:22 pm
LifeType Version: 1.2.9-devel

Re: Something like a sidebar...

Postby Pryrates on Fri Jul 11, 2008 3:24 pm

Hey, thanks!!

Looks like you programmed the whole plug now? Something could be wring as the plugin does not work when I uploaded it, but maybe I'll find something. Thanks again!

Ehm your note that I should look at the plugins of the wiki I didn't get I think...? To compare? To finish? To learn? To use?
Sorry...


To the errors in the code the post two above: Maybe some errors derivate from the original plugins since the original just did not want to work with my lifetype (Fatal error...) but much more likely it was me. I edited the rss20.template since in the other there was no for loop and I thought this what later should be displayed should have a loop for the recent comments (since they re more than one comment).
Pryrates
 
Posts: 8
Joined: Mon Jul 07, 2008 12:25 pm
LifeType Version: 1.2.8

Re: Something like a sidebar...

Postby chromos on Sat Jul 12, 2008 7:18 am

Np.

Yes I did. The plugin is working here.

Yes exactly. To compare and learn :)

About the errors:
Your template file made no sense. Because this file is used for showing your plugin in the Administation/PluginCentre panel. Just compare my template file and yours.
If your still getting errors I have to check if I made a mistake somewhere.

You should read about templates in the wiki. How to install them, write them etc. The template file in the plugins' directories has nothing to do with the templates that style your blog.
chromos
 
Posts: 274
Joined: Wed Mar 09, 2005 2:22 pm
LifeType Version: 1.2.9-devel

Re: Something like a sidebar...

Postby chromos on Sat Jul 12, 2008 11:31 am

sorry, made a copy'n paste mistake ... please have a look at the updated pluginbloglistconfigaction.class.php
chromos
 
Posts: 274
Joined: Wed Mar 09, 2005 2:22 pm
LifeType Version: 1.2.9-devel


Return to Everything Else Goes Here!

cron