Recent Topics

1 May 20, 2008 22:28    

Hello,

today i started with my blog. Created a Entry with about 40 pictures. Then decidet to "clean up" the space (folders,...) ... The Links to the images used in the Blog entry are invalid now.

So i decided to start coding a plugin to "fix" this. But is there a "home made" or "still finished" possibility to activate php-code in the entry?

The Tags "<?php" and "?>" seems to be ignored...

If there is a complete solution about this case - you can post, too :lol:

I'm the only guy using that Blog, so activating php support will not be a risk.

I thought about sth like: "replacing the insertet div-code" through a function, that contains pictures id, and when the side gets parsed by the browser, the function reads the img url and text from the DB and inserts the div tags.

sth like:


<?php echo GetImageByID('3')?>

regards,
dognose[/code]

2 May 23, 2008 17:10

[image:folder-path:name][image:database-id]

There is not a way to use PHP when posting. The best bet is to make a rendering plugin that will give you something like or ... or even better <!-- image:whatever --> when you post that gets rendered into the actual image tag.

3 May 25, 2008 18:21

thanks for answer.

Well, i thought about that, too, so i starded to code my complete own blog ;-) Therefore i codet a plugin 4 image linking, which is still not finished right now (SQL implementations still missing), but seems to work fine.

If You - or anyone - is interested in that, here my "beta" source code:

<?php
/*
This is used in text to add an image.
usage:

  blog:
  [image]"var1"#"var2"#"var3"#"var4"#"var5"#"var6"[/image]

  code:
  InsertImage("var1","var2","var3","var4","var5","var6");
  
  Vars:
  
  [var1] = [$image_id] = Integer (reading from database)
  [var2] = [$image_url] = "http://www. ... .xy"
  [var3] = [$comment] = text    (Comment you want to add to picture. If NONE added, it will be selecting comment from DB / printing Url of linked img.)
  [var4] = [$scale] = integer 2, 4, 10, 20 , 30 , .... (percantage of scaling img up/down)
  [var5] = [$width] = integer, fixed width
  [var6] = [$height] = integer, fixed height.
  
  PLEASE NOTE:
  
  You can't use all vars at once - some only work alone.
  If using, [var1] = [$image_id] DONT use [var2] = [$image_url]   => will ignore $image_url
  If using, [var2] = [$image_url] DONT use [var1] = [$image_id]   => will not work
  If using, [var3] = [$comment] the comment read from DB will be ignored.
  if using [var3] = scale dont use var4,var5    =>   will ignore absolute vars
  
  using (Var1 OR Var2) AND (Var4 OR Var5) will cause the "Missing"-Value to be calculated,
  depending on picture ratio (4:3, 16:9, ...)
  
  Examples:
  [image]1###40##[/image]   =>Inserts Image with ID1 and scales it down on 40%, reading comment from DB
  [image]1####640#[/image]   =>Inserts Image with ID1, height="640" and calulates the according width., reading comment from db
  [image]#http://www. ... .xy/Bild.xz###100#100[/image]  =>Inserts Image form URL given,displays url, cause no comment set, and brings it on 100*100pixel. NOTE: NO propertional Resize!
  [image]1##That's me###[/image]   =>Inserts Image with ID1, and Picturedefined parametres. Adds Comment "That's me", ignoring database safed comment.
  
*/    

function CreateImage($image_id="", $image_url="",$image_comment, $scale="", $width="", $height=""){
  /*First lets check parameters given*/
  if ($image_id=="") {
  	/*no id given, so use url*/
  	$url_2_use = $image_url;
  	
  	if ($image_comment ==""){
  	  /*discription = referer*/
  	  $discription = $image_url;
  	  }
  	  ELSE
  	  {
      $discription = $image_comment;
      }
  }
  else
  {
    /*id given, so get url from database*/
    
    /* needs to be coded */
    /* first need structure and skript for uploading img.*/
  }
  /*Get img Info*/
  $size=getimagesize($url_2_use);
  $width_read=$size[0];
  $height_read=$size[1];
  
  /*scale, resize or "normal"?*/
  if ($scale!=""){
    /*scale given, so use it, scale down and finished!*/
    $width_write = ceil($width_read * ($scale/100));
    $height_write = ceil($height_read * ($scale/100));  
   }
   ELSE
   {
   /*no scale given, look for absolute vars*/
   if ($width != "" AND $height !=""){
     /*width given*/
     /*height given*/
     $width_write = $width;
     $height_write = $height;
     }
   elseif ($width != "" AND $height ==""){
     /*width given*/
     /*no hight given -> calculate*/
     $width_write = $width;
     $percentage = $width/$width_read;
     $height_write = ceil($percentage*$height_read);
     }
   elseif ($width == "" AND $height !=""){
     /*height given*/
     /*no width given -> calculate*/
     $height_write = $height;
     $percentage = $height/$height_read;
     $width_write = ceil($percentage*$width_read);
     }
     else
     {
     /*no height given*/
     /*no width given*/
     /*no scaling given*/
     /*=> Use pic parametres*/
     $height_write = $height_read;
     $width_write = $width_read;
     }
   }
   /*thats it. Make string, display, and end*/
    return "<div class='Image'><img src='$url_2_use' height='$height_write' width='$width_write'><div class='discription'>$discription</div></div>";
}

function look_4_img_tags($text){
/*search image tag*/
$hits =  preg_match_all("/\[image\](.*)\[\/image\]/i",$text,$imgstring);
$current = 0;
while ($current < $hits) {
  /*Split array*/
  $v = explode("#",$imgstring[1][$current]);
  
  /*make divs*/
  $s = CreateImage($v[0],$v[1],$v[2],$v[3],$v[4],$v[5]);
  
  /*replace in text*/
  $text = str_replace($imgstring[0][$current],$s,$text);
  
  $current = $current+1;
}
return $text;
}

maybe it will be better, to replace the tags by "Preg_replace_all" ... it's beta ;)

(smily and tag linking plugin works very fine with Preg_replace_all)

regards, dognose


Form is loading...