Recent Topics

1 Jul 09, 2011 02:07    

Hi, as always I am coding, it's so addictive and yet so rewarding (for me),
anyway I am stuck and hope I can get some advice, I was busy updating a plugin a created earlier, this plugin was developed from the summary.php code.

I made it into a useful plugin that displays a summary of all the blogs and it gets inserted through the widgets panel. It allows to pick any blog to use and then it displays the latest # posts.

It also displays which posts are featured or not. What I would like to update is for the user to be able to see which blog the plugin is assigned to in the Customize Widget panel to make it easier to find the relevant plugin to edit.

Similar to how the free html widget works, once content is changed its name displays in the Widget Panel as such.

I have managed to do that, well almost, the only problem I am having is getting the value from the widget settings.

Getting it from Globals are easy enough, but because it isn't set in globals I find myself stuck.

Here is what I got so far:

	var $name = NULL;

	function PluginInit( & $params)
	{	
		$this->name = $this->get_name(); 
		$this->short_desc = T_('Blog Summary for a All blogs overview');
		$this->long_desc = T_('Display a short list of Blog Summary for all blogs combined.');
	} 


	function get_widget_param_definitions( $params )
	{
		return array(
'available_blogs' => array(
				'label' => $this->T_( 'Available public blogs' ),
				'defaultvalue' => $this->get_public_blogs(),
				'type' => 'text',
				'size' => 40,
				'note' => $this->T_( 'Separate blogs with "," use as many as you like. ' )
				),
/* Some other variables.... */
	);

function get_name()	{ 	
				global $BlogCache, $Blog;			
						load_class( 'items/model/_itemlist.class.php', 'ItemList' );
						$BlogCache = & get_BlogCache();

/* THIS IS THE PROBLEM START*/
						$id = $this->disp_params[ 'available_blogs' ];
/* THIS IS THE PROBLEM END*/
						$blog = $BlogCache->get_by_ID( $id );
						$name = $blog->get( 'shortname', 'htmlattr' );
						return $name;
	}
	}

function some_func($params)
       {
/*CODE*/        

}

function SkinTag( $params )
	{
	       // Start display
		echo $params['block_start'];
		echo $this->some_func($params);
		echo $params['block_end'];
		return true;
	}
}

the part that i am struggling with is this:

$id = $this->disp_params[ 'available_blogs' ];

Which events/hooks should I use to get the $params?

2 Jul 09, 2011 04:32

function PluginInit( & $params)
{    
    $this->name = $this->get_name();


Never do processing at plugin init time. Move this to "some_func" method.

Try this, if it's not working for widget params see the next solution :)

$this->Settings->get('available_blogs');

function SkinTag( & $params )
{
    echo $this->some_func($params); 
}


function some_func( & $params )
{
   $id = $params['available_blogs'];
   $this->name = $this->get_name();
} 

3 Jul 09, 2011 04:37

load_class( 'items/model/_itemlist.class.php', 'ItemList' );


This is not needed since you don't work with items

4 Jul 09, 2011 04:53

as always, thanks. (:

5 Jul 09, 2011 06:17

None of it seems to work, the name is returned empty which defaults to the widget class name. Even if I say

$this->name = '123';

it is still returned empty. The closest I got to renaming it is in PluginInit


	function PluginInit( & $params)
	{	$this->name = '123';

:(

6 Jul 09, 2011 18:42

I don't exactly understand what you are doing. Can you post the whole file here?

7 Jul 12, 2011 06:23

<?php
/**
 * This file implements the Blog Summary plugin for b2evolution
 *
 * b2evolution - {@link http://b2evolution.net/}
 * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
 * @copyright (c)2003-2010 by Francois PLANQUE - {@link http://fplanque.net/}
 *
 * @package plugins
 */
 /**
 *Plugin Name: Blogsum! - Blog Posts list
 *
 *Plugin URI: http://www.midnightstudios.co.za/
 * 
 *Description: List recent posts from selected blogs
 * 
 *Author: Jacques Joubert
 * 
 *Author Group: Midnight Studios
 * 
 *Author URI: http://www.midnightstudios.co.za/
 * 
 *Version: 1.0.0        @version $Id: v 1.0.0 2011/07/12 00:20:55 achillis Exp $
 */


if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );


/**
 * Blog Summary Plugin
 *
 * This plugin displays a short list of newest posts from selected blogs.
 *
 * @package plugins
 */
class blogsum_plugin extends Plugin
{
	/**
	 * Variables below MUST be overriden by plugin implementations,
	 * either in the subclass declaration or in the subclass constructor.
	 */
	
	var $name = 'Blog Summary';
	var $code = 'blogsummary';
	var $priority = 80;
	var $version = '1.0.0';
	var $author = 'Jacques Joubert';
	var $help_url = '';
	var $group = 'Midnight Studios';

	/*
	 * These variables MAY be overriden.
	 */
	var $is_tool = false;
	var $apply_when = 'never';
	var $disp_params = array();
	
	var $allBlogs = array();
	var $BlogCache;
	var $number_of_installs = 1;


	function PluginInit( & $params)
	{	$this->short_desc = T_('Blog Summary for a All blogs overview');
		$this->long_desc = T_('Display a short list of Blog Summary for all blogs combined.');
	}

	/**
	 * We require b2evo 2.2
	 */
	function GetDependencies()
	{
		return array(
				'requires' => array(
					'api_min' => array( 99 ), // obsolete, but required for b2evo 1.8 before 1.8.3
					'app_min' => '2.2.0-beta',
				),
			);
	}
	
	function get_public_blogs()
	{ // Get a list of 'Public Blogs'
		$this->BlogCache = & get_Cache( 'BlogCache' );
		// pre_dump($this->BlogCache);		
		$pub_blogs = $this->BlogCache->load_public();
		$pub_blogs = implode( ', ', $pub_blogs );
		return $pub_blogs;
	}
	
	function get_member_blogs()
	{ // Get blogs the user is 'Owner' of
		$BlogCache = & get_Cache( 'BlogCache' );
		
		$member_blogs = $BlogCache->load_user_blogs();
		return $member_blogs;		
	}
	
		function get_owner_blogs()
	{ // Get blogs the user is 'Owner' of
		global $Blog;
		$BlogCache = & get_Cache( 'BlogCache' );
		
		$owner_blogs = $BlogCache->load_owner_blogs( $Blog->get( 'owner_user_ID' ) );
		$owner_blogs = implode( ', ', $owner_blogs );
		return $owner_blogs;		
	}
		

	
	function get_widget_param_definitions( $params )
	{
		return array(
			'title' => array(
				'label' => $this->T_('Title'),
				//'note' => $this->T_(''),
				'size' => 35,
				'type' => 'text',
				'defaultvalue' => T_('Recent / Updates')
			),
			'spes_title' => array(
				'label' => $this->T_('Title from blog name'),
				'note' => $this->T_('Link the title to a blog or leave empty for no link'),
				'size' => 1,
				'type' => 'text',
				'defaultvalue' => ''
			),
			'spes_blog_title' => array(
				'label' => $this->T_('Title for blog list'),
				'note' => $this->T_('Display a title for the blog listed'),
				'defaultvalue' => 0,
				'type' => 'checkbox',
			),
			'available_blogs' => array(
				'label' => $this->T_( 'Selected blogs' ),
				'defaultvalue' => $this->get_public_blogs(),
				'type' => 'text',
				'size' => 40,
				'note' => $this->T_( 'Seperate blogs with ",".<br><br>This is a list of all avalable public blogs: '.$this->get_public_blogs(). '<br><br>This is a list of all blogs for owner: '.$this->get_owner_blogs().'<br><br>' )
				),
			'blog_post_view' => array(
				'label' => T_( 'Post per blog' ),
				'note' => T_( 'Select how many post will be displayed per blog, there will be a more link' ),
				'size' => 4,
				'defaultvalue' => 3,
				),
		);
	}





 	/**
	 * Event handler: SkinTag
	 *
	 * @return boolean did we display?
	 */


	function sum_blog(& $params )
	{
	 	global $BlogCache,$Blog;
if(!isset($params['block_start'])) $params['block_start'] = '<ul>';
if(!isset($params['block_end'])) $params['block_end'] = "</ul>";


if(!isset($params['widget_start'])) $params['widget_start'] = '<ul class="summary">';
if(!isset($params['widget_end'])) $params['widget_end'] = "</ul>";

if(!isset($params['line_start'])) $params['line_start'] = '<li>';
if(!isset($params['line_end'])) $params['line_end'] = "</li>";
		
if(!isset($params['title'])) $params['title'] = T_('Recent / Updates');
if(!isset($params['block_title_start'])) $params['block_title_start'] = '<h3>';
if(!isset($params['block_title_end'])) $params['block_title_end'] = '</h3>';


if(!isset($params['specified_title_start'])) $params['specified_title_start'] = '<h6 class="sum">';
if(!isset($params['specified_title_end'])) $params['specified_title_end'] = '</h6>';

if(!isset($params['span_title_start']))$params['span_title_start'] = '<span class="sum_title">';
if(!isset($params['span_title_end']))$params['span_title_end'] = '</span>';

// Clear float
if(!isset($params ['clearfloat'])) $params ['clearfloat'] = '<div class="clearfloat"></div>';

/* Featured Item Hint*/ /* We can do this with css, but we can use icons instead of text */
if(!isset($params['f_font_start'])) $params['f_font_start'] = '<font color= green><b><i>';
if(!isset($params['f_font_end'])) $params['f_font_end'] = '</i></b></font>';
if(!isset($params['featured_post_hint'])) $params['featured_post_hint'] = '~Featured Post~';

/* Regular Item Hint*/ /* We can do this with css, but we can use icons instead of text */
if(!isset($params['r_font_start'])) $params['r_font_start'] = '<font color= blue><b><i>';
if(!isset($params['r_font_end'])) $params['r_font_end'] = '</i></b></font>';
if(!isset($params['regular_post_hint'])) $params['regular_post_hint'] = '~Regular Post~';

/* Regular Item Hint*/ /* We can do this with css, but we can use icons instead of text */
if(!isset($params['start_span'])) $params['start_span'] = '<span class="newline_item">';
if(!isset($params['end_span'])) $params['end_span'] = '</span>';
if(!isset($params ['empty_blog_msg'])) $params ['empty_blog_msg'] = 'Nothing Available Yet.';

/* More */
if(!isset($params['before_more'])) $params['before_more'] = '<span class="summary_more_link">';
if(!isset($params['after_more'])) $params['after_more'] = '</span>';

if(!isset($params ['more'])) $params ['more'] = T_( ' more...' );

// Before text:
if(!isset($params['before_text'])) $params['before_text'] = '<p>';
if(!isset($params['after_text'])) $params['after_text'] = "</p>";


// Blog to use.  Default is the current blog being displayed.
if(!isset($params[ 'available_blogs' ])) $params[ 'available_blogs' ] = $Blog->ID;	
if(!isset($params['blog_post_view'])) $params['blog_post_view'] = 3;

// The date format:
if(!isset($params['date_format'])) $params['date_format'] = locale_datefmt();


// --------------------------- BLOG LIST -----------------------------

	load_class( 'items/model/_itemlist.class.php', 'ItemList' );

		$BlogCache = & get_BlogCache();
		$blog_array  = $params[ 'available_blogs' ]; 
		$blog_array  = str_replace(' ', '', $blog_array );
		$blog_array  = explode( ',', $blog_array );

echo $params['block_start'];		

		if (empty($params['spes_title']))
							{
		if (!empty($params['title']))
		{

echo $params['block_title_start'] .'<span title="' . $params['title'] .'">' . $params['title'] .'</span>' . $params['block_title_end'];

								}
								}
		
else {		
			foreach( $blog_array as $blog )
	{	
			$l_Blog = & $BlogCache->get_by_ID( $blog );	
			$BlogBList = new ItemList2( $l_Blog, NULL, 'now');
			$BlogBList->set_filters( array(
					'order' => 'DESC',
					'unit' => 'posts',
				) );
			$BlogBList->query();
			$Item = & $BlogBList->get_item();	
}
		
if (empty($Item)){ 
			
echo $params['block_title_start'].'<span title="' . $params['title'] .'">' . $params['title'] .'</span>'. $params['block_title_end'];
					}
else {
		$n_Blog = & $BlogCache->get_by_ID( $params['spes_title'] );		
			
			echo $params['block_title_start']; 
			echo $params['span_title_start']; 		
			echo '<a href="'.$n_Blog->gen_blogurl().'" title="'. $params['title'] .'">'. $params['title'] .'</a>';
            echo $params['span_title_end'];
			echo $params['block_title_end'];
		}
			
			} /*END else empty($params['spes_title'] */

	foreach( $blog_array as $blog )
	{	// Loop through all public blogs:
		# by uncommenting the following lines you can hide some blogs
		// if( $blog == 2 ) continue; // Hide blog 2...

    /**
	 * @var Blog
	 */
					$l_Blog = & $BlogCache->get_by_ID( $blog );

echo $params ['clearfloat'];


if ($params['spes_blog_title'] !=0) { 
echo $params['specified_title_start'];

echo '<a href="'.$l_Blog->gen_blogurl().'" title="'.$l_Blog->disp( 'name', 'htmlattr' ).'">'.$l_Blog->disp( 'name', 'htmlattr' ).'</a>';

echo $params['specified_title_end'];
}
echo $params ['clearfloat']; 
echo $params['widget_start'];

// Get the 3 last posts for each blog:
			$BlogBList = new ItemList2( $l_Blog, NULL, 'now');
			$BlogBList->set_filters( array(
					'order' => 'DESC',
					'unit' => 'posts',
				) );
			$BlogBList->query();
			$Item = & $BlogBList->get_item();			

if (empty($Item)){
echo $params['line_start'];
echo $params['start_span'].''.$params ['empty_blog_msg'].''.$params['end_span'];
echo $params['line_end'];
				  }		  
else {	
			$BlogBList = new ItemList2( $l_Blog, NULL, 'now', $params['blog_post_view'] );
			$BlogBList->set_filters( array(
					'order' => 'DESC',
					'unit' => 'posts',
				) );

			// Run the query:
		  	$BlogBList->query();
			while( $Item = & $BlogBList->get_item() )
			{
				echo $params['line_start'];
				echo $params['start_span'];
				$Item->title( array('link_type' => 'permalink',) );
							
				if( $Item->is_featured() )	{
echo $params['f_font_start'].''.$params['featured_post_hint'].''.$params['f_font_end'];
											 }
				if( !$Item->is_featured() )	{
echo $params['r_font_start'].''.$params['regular_post_hint'].''.$params['r_font_end'];
											 }	
?>
<br />
<?php
			$Item->issue_date( array(
							'before'      => '<span class="date_entry" title="Date">',
							'after'       => '</span><br /><br />',
							'date_format' => 'l jS F Y',
							) );

echo $params['end_span'];
echo $params['line_end'];
echo $params ['clearfloat'];
}	
echo $params['line_start'];
echo $params['start_span']; 
echo $params['before_more'];
echo '<a href="'.$l_Blog->gen_blogurl().'">'.$params ['more'].'</a>';
echo $params['after_more'];
echo $params['end_span'];
echo $params['line_end'];
}

echo $params['widget_end'];
echo $params ['clearfloat'];
}
echo $params['block_end'];
/* END OF BLOG LIST */ 
//		return true; /* Not required using echo */
}

/* DISPLAY START */
function SkinTag( $params )
	{	// Start display
		echo $this->sum_blog($params);

		return true;
	}
/* DISPLAY END */


/* css is specified in skin so we are not using the default css, so we won't nees head tags, other users have to use below */
/*

function SkinBeginHtmlHead( & $params )
		{  	global $Plugins, $plugins_url;

			$plug_url = $this->get_plugin_url();
			$comm_start = '<!-- Start blog sum plugin -->';
			$comm_end = '<!-- End blog sum  plugin -->';
			add_headline( $comm_start );
			require_css( $plug_url . 'css/style.css', true );		
			add_headline( $comm_end );									
							
			return true;
						}
*/

}

?>

move the css rules below to -> $plug_url . 'css/style.css
note, the widget display in a custom block at footer with css defining the layout.

may have to define block:inline


ul.blocks li.block{list-style-type:none;margin:0;padding:0;}
ul.blocks li.block{width:33%;float:left;margin:0;padding:0;position:relative;}
ul.blocks li.block .block-content{padding:0 .8em; white-space:normal}



ul.blocks.widgetcount-1 li.block{width:100%;}
ul.blocks.widgetcount-2 li.block{width:50%;}
ul.blocks.widgetcount-3 li.block{width:33%;}
ul.blocks.widgetcount-4 li.block{width:25%;}
ul.blocks.widgetcount-4 li.block .block-content{padding:0 .6em;}
ul.blocks.widgetcount-5 li.block{width:20%;}
ul.blocks.widgetcount-5 li.block .block-content{padding:0 .5em;}
ul.blocks.widgetcount-6 li.block{width:16.6%;}
ul.blocks.widgetcount-6 li.block .block-content{padding:0 .4em;}

The ideal was to get the selected blogs name to display in the Customize Widget Panel, like with the free_html widget, so to make it easier to see which widget refer to which item, if that makes sense.

http://www.midnightstudios.co.za/downloads/widget.png

I have several blogs with different content and this displays a list for each blog above the footer in a newly created content block "Assets".


Form is loading...