Recent Topics

1 Jan 31, 2008 16:25    

Hi, this is my old litle hack to b2.

Users can choose layout and full edit in control panel. I connect this function to autoblog plugin V.1.8.2.

Instalation:

open: autoblog_plugin.php

change:


$new_blog_skin = $this->Settings->get('blog_skin');


on:


$new_blog_skin = '_skinuser/_user_'. $new_blog_shortname;

after:


$new_blog_force_skin = $this->Settings->get('blog_force_skin');
$new_blog_allowblogcss = $this->Settings->get('blog_allowblogcss');
$new_blog_in_bloglist = $this->Settings->get('blog_in_bloglist');
$new_blog_show_bloglist = $this->Settings->get('show_bloglist');


add:


		// HACK DJHORS ******************************************************
		$skinurl = get_path('skins');

		include($basepath."inc/_misc/_dirtool.class.php");

		$dir = new dirtool($skinurl.'custom');
		//$dir->debug(TRUE);
		$dir->copy($skinurl.'_skinuser/_user_'.$new_blog_shortname, 0777, $skinurl.'custom');
		//$dir->debug(TRUE);

		//*******************************************************************


open: b2template.php (/inc/CONTROL/skins)

change all :


$edit_folder = $skins_path.'custom/';

on


$edit_folder = $skins_path.'_skinuser/_user_'.$current_User->dget('login').'/';

open: _blogs_skin.form.php (/inc/collections/)

change all on:


<?php
/**
 * This file implements the UI view for the Advanced blog properties.
 *
 * This file is part of the b2evolution/evocms project - {@link http://b2evolution.net/}.
 * See also {@link http://sourceforge.net/projects/evocms/}.
 *
 * @copyright (c)2003-2007 by Francois PLANQUE - {@link http://fplanque.net/}.
 *
 * @license http://b2evolution.net/about/license.html GNU General Public License (GPL)
 *
 * @package admin
 */
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );

/**
 * @var Blog
 */
global $edited_Blog;

//HACK DJHORS *****************
$useron = $current_User->login;
//*****************************
$Form = & new Form( NULL, 'blogadvanced_checkchanges' );

$Form->begin_form( 'fform', T_('Choose a skin') );

	$Form->hidden_ctrl();
	$Form->hidden( 'action', 'update' );
	$Form->hidden( 'tab', 'skin' );
	$Form->hidden( 'blog',$edited_Blog->ID );

	$Form->begin_fieldset( T_('Available skins') );
	
	for( skin_list_start(); skin_list_next(); ) 
	{ 
		$skin_name = skin_list_iteminfo( 'name', false );
		$skin_path = skin_list_iteminfo( 'path', false );
		$skin_url = skin_list_iteminfo( 'url', false );
		$preview_url = url_add_param($edited_Blog->get('blogurl'),'tempskin='.rawurlencode($skin_name));
		echo '<div class="skinshot">';
		if( file_exists( $skin_path.'/skinshot.jpg' ) )
		{
			echo '<a href="'.$preview_url.'" target="_blank" title="'.T_('Preview blog with this skin in a new window').'">';
			echo '<img src="'.$skin_url.'/skinshot.jpg" width="240" height="180" alt="'.$skin_name.'"';
			if( $skin_name == $edited_Blog->default_skin )
			{
				echo ' class="current"';
			}
			echo '/></a>';
		}
		echo '<div class="legend">';
		echo '<div class="actions">';
		if( $skin_name == $edited_Blog->default_skin)
		{
			echo T_('Selected');
		}
		else
		{
		// ORYGINAL ********************************************************************
		/*
		echo '<a href="?ctrl=collections&tab=skin&blog='.$edited_Blog->ID.'&amp;action=update&amp;blog_default_skin='.rawurlencode($skin_name).'">'.T_('Select').'</a>';
		}
		echo '</div>';
		echo '<strong>'.$skin_name.'</strong></div>';
		*/
		//********************************************** HACK DJHORS *******************
		if ($skin_name == 'skinners_guide')
			{
			$skin_name = '_skinuser/_user_'.$useron;
			}
			echo '<a href="?ctrl=collections&tab=skin&blog='.$edited_Blog->ID.'&amp;action=update&amp;blog_default_skin='.rawurlencode($skin_name).'">'.T_('Select').'</a>';
		}
		echo '</div>';
		if ($skin_name == '_skinuser/_user_'.$useron)
			{
			echo '<strong>'.T_('Your personal skin').'</strong></div>';
			}
		else
			{
			echo '<strong>'.$skin_name.'</strong></div>';
			}
		//********************************************************************************
		echo '</div>';
	} 

	echo '<div class="clear"></div>';

	$Form->end_fieldset( );
	
$Form->end_form();
?>

create '_skinuser' folder in /skins folder b2 and chmod to 777

I created that fast and they can some error but on my b2 its work. I test this in only: v1.10.3

and you must download class dirtoll or copy/ past from next post and name this file _dirtool.class.php / copy this file to /inc/_misc/

Remeber. You give acces to edit php layout for your users :)

sorry for my english :)

2 Jan 31, 2008 16:57

Hi djhors,

I reviewed your solution and I think it is a great idea. I would like somebody to write how to enable the users to edit their new skin.

I did remove the link to the file you presented for upload. It contained a function able to delete a complete directory structure. Since you don't use this function in your hack I believe it is better to only put the fragments that are able to copy a directory in one's server.
This is the edited file _dirtool.class.php you want to put in the inc/_misc/ folder:

<?php 

/* Do not remove or alter this section***************************

************************Class Description************************
dirtool  (c) Nov 2005  Uwe Stein

dirtool allows to copy, delete and move complete directory-trees 
*****************************************************************

************************ sorry and thx ***************************
Please excuse errors in this text. English isnt my native language,
and so  suggestions about the code and the spelling are welcome

*********************Contact and Bug report***********************
contact me using the "contact-button" at one of my packages at phpclasses.org

********************Licence****************************************
This software is covered by The GNU General Public License (GPL)
***************************************************************

**************End of do not remove or alter section*************************/

// get the value of slash according to the OS
function slash(){
    if(isset($_SERVER['OS'])) 
           return "\\";
    else 
          return "/";
}
class dirtool {
     var $path;
     var $from;
     var $to;
     var $aContent= array();
     var $debug = FALSE;
     
     function dirtool($path) {
       if (!is_dir($path))
           die("<br><strong>$path is NOT a directory</strong>");
        $this->path = realpath($path);
        $from = "";
        $to="";
        
        // read the directory
        $slash = slash();
        $verz=opendir ($path);
        while ($file = readdir ($verz)) {
            if ($file != "." && $file != "..") {
               $tmp = $this->path.$slash.$file;
                if (is_dir($tmp)) 
                   $this->aContent[] = new dirtool($tmp);
                else 
                    $this->aContent[] = $tmp;
             }  //if 
        } // while
         closedir($verz);
     }  //End of func directory


     function copy($path, $mode, $from = "") {
            $this->copy_tree($path, $mode, $from = "");
            $this->copy_files($path, $mode, $from = "");
     }  // End of func copy


     function copy_tree($path, $mode, $from = "") {
        if (!mkdir($path, $mode))
           die ("Error: directory $path could not be created"); 
           if ($this->debug == TRUE)
              echo "<br>Katalog stworzono!";
         chmod($path,$mode);
        // at the first loop of recursiv callings keep the "$from-path        
        //if ($from == "")
       $this->from = $this->path;
       $this->to = $path;

       // walk through the array aContent and create all  directories
       for ($i=0; $i < count($this->aContent); $i++) {
            if (is_object($this->aContent[$i])) {
               $pattern = "^".$this->from."^";
               $replace = $this->to;
               $dirToCreate = preg_replace($pattern,$replace, $this->aContent[$i]->path );
            // call copy recursively to create the new directory and process the next level
              $this->aContent[$i]->copy_tree($dirToCreate, $mode,$this->from);
            } // End if ... 

       }  // End for .... 
       clearstatcache();

    }  // End of func copy_tree

    function copy_files ($path, $mode, $from = "") {
       for ($i=0; $i < count($this->aContent); $i++) {
            // if it is a dir-objekt, call copy recursively
            if (is_object($this->aContent[$i])) {
               $pattern = "^".$this->from."^";
               $replace = $this->to;
               $newpath = preg_replace($pattern,$replace, $this->aContent[$i]->path );
             // call copy recursively to enter the sub-dir and process the next level
              $this->aContent[$i]->copy_files($newpath, $mode,$this->from);
            } // End if ... 
            // if it is a file, copy 
            else {
                 // save the fileperms 
                 $perms = fileperms($this->aContent[$i]);
                 $src = $this->aContent[$i];
                 $pattern = "^".$this->from."^";
                 $replace = $this->to;
                 $dest = preg_replace($pattern,$replace, $this->aContent[$i] );
                 copy($src,$dest);
                 if ($this->debug == TRUE) 
                    echo "<br>Plik skopiowano!</b>";
                 chmod($dest,$perms);
            }
        } // End for.....
        clearstatcache();
    
    }  // End of func copy files 

 
    function debug($bool=TRUE){
        $this->debug = $bool;
    }
    
    
} // End of class dirtool
?>


Any one interested in the original file can PM either me or djhors.

I would love to hear some feedback on the concept of a user able to edit their skin. Are there a lot of users in a Multiblog situation using this possibility?
In the 2.x series a blogger is able to edit the css file of a skin. I have not yet experimented with this feature.

Have fun

3 Jan 31, 2008 17:08

exacly this is hack ho i use 2 years ago but i don't have time to publish yet. I have only one think, becouse give acces for users posibilty edit php skript this is not good idea :) but i work now on changes some b2template.php to translated skript to special words how: {blog} {links} {calendar}.

This is simple one page layout from polish blogs:


<HTML><HEAD><TITLE>M�j blog</TITLE>

<META http-equiv=Content-Type content="text/html; charset=iso-8859-2">
<STYLE>

TD.FRAME {  background-color: #4E5872; }
TD.TOP {  background-color: #8899B0; }
TD.LEFT  {  background-color: #8796B2;
		 	text-align: center;
			vertical-align: top; }
TD.RIGHT  {  background-color: #BAD0DD;
		 	 text-align: center;
			 vertical-align: top; }
P { font-family: arial,helvetica,tahoma,verdana,sans-serif; }
			 
P.BLOG  { margin : 0pt;
		  padding: 20pt;
		  font-weight: normal;
		  color: #333333;
		  font-size: 9pt;
		  text-align: justify; }			 

A { font-family: arial,helvetica,tahoma,verdana,sans-serif; }		  

P.LEWY { margin: 0pt;
	   	 padding: 3pt 5pt 3pt 5pt;
		 text-align: center;
		 color: #000000;
		 font-size: 9pt;
		 font-weight: bold;
		 line-height: 15pt; }
		  
A:LINK,A:VISITED,A:ACTIVE { font-size: 9pt;
													   color: #333333;
				  									   text-decoration: none;
				  									   font-weight: bold; }
A:HOVER { text-decoration: underline; }													    

P.KSYWKA { margin: 0pt;
		   padding-right: 20pt;
		   text-align: right;
		   vertical-align: middle;
		   color: #ffffff;
		   font-size: 9pt;
		   font-weight: bold;}

BODY {
	SCROLLBAR-FACE-COLOR: D2E1EA; SCROLLBAR-HIGHLIGHT-COLOR: D2E1EA; SCROLLBAR-SHADOW-COLOR: 999999; SCROLLBAR-3DLIGHT-COLOR: 999999; SCROLLBAR-ARROW-COLOR: 999999; SCROLLBAR-TRACK-COLOR: D2E1EA; SCROLLBAR-DARKSHADOW-COLOR: D2E1EA
}
</STYLE>
</HEAD>
<BODY bgcolor="#D2E1EA">
<center>
<img SRC="http://szablonownia.atcsites.com/szabl/blogi/011/header.jpg" width="600" height="158"> <br>

<table width="600" border="0" bordercolor="#000000" cellspacing="0" cellpadding="0">
<tr>
	<td colspan="4" width="600" height="2" class="frame"><img SRC="http://szablonownia.atcsites.com/szabl/blogi/011/pixel.gif" width="600" height="2"></TD>
</TR>


<tr>
	<td width="2" class="FRAME"><img SRC="http://szablonownia.atcsites.com/szabl/blogi/011/pixel.gif" width="2" height="2"></TD>
	
	<td width="596" height="25" class="TOP" colspan="2">
	
	<P class="KSYWKA">bloguje : <i>tu_wpisz_swoj�_ksywk�</i></P>
	
	</TD>
	<td width="2" class="FRAME"><img SRC="http://szablonownia.atcsites.com/szabl/blogi/011/pixel.gif" width="2" height="2"></TD>
</TR>

<tr>
	<td width="2" class="FRAME"><img SRC="http://szablonownia.atcsites.com/szabl/blogi/011/pixel.gif" width="2" height="2"></TD>
	
	<td width="150" class="LEFT" >
	<br>
	<P class="LEWY">Linki:</P>
	
	<P class="LEWY">
	{linki}
	</P>
	
	<br> &nbsp <br>
	
	<P class="LEWY">
	{archiwum}
	</P>
	
	<br> &nbsp <br> 
	
	<P class="LEWY">
	<a HREF="/xiega/index.php">Ksi�ga go�ci</A>
	</P>
		
	<br> &nbsp <br> 
	
	<P class="LEWY">
	projekt:
	<a HREF="http://szablonownia.atcsites.com">Szablonownia</A>
	</P>
				
	</TD>
	
	<td width="446" class="RIGHT" >
	
	<P class="BLOG">
	{blog}
	</P>
	</TD>
	
	<td width="2" class="FRAME"><img SRC="http://szablonownia.atcsites.com/szabl/blogi/011/pixel.gif" width="2" height="2"></TD>
</TR>

<tr>
	<td colspan="4" width="600" height="2" class="frame"><img SRC="http://szablonownia.atcsites.com/szabl/blogi/011/pixel.gif" width="600" height="2"></TD>
</TR>


</TABLE>

</CENTER>


</body></html>

and try copy this code to main.php (before delete all code). And what we se - exacly preety layout and special words. I have idea to include something this to b2evolution.


Form is loading...