Ignore:
Timestamp:
01/22/07 15:06:18 (13 years ago)
Author:
gocher
Message:

Update InsertPicture? plugin

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/plugins/InsertPicture/InsertPicture.php

    r677 r686  
    11<?PHP 
    22  //this plugin only use the relativ webpath to the picturefolder 
    3   //default ~  /htmlarea/plugins/InsertPicture/demo_pictures/ 
     3  //default ~  /Xinha/plugins/InsertPicture/demo_pictures/ 
    44  strstr( PHP_OS, "WIN") ? $strPathSeparator = "\\" : $strPathSeparator = "/"; 
    55  if (isset($_REQUEST['picturepath'])) { 
    6     $getRequest = true; 
    7     $PicturePath = 'http://'.$_SERVER['HTTP_HOST'].$_REQUEST['picturepath']; 
    8     //$LocalPicturePath = $_REQUEST['localpicturepath']; 
    9  
    10     $AInsertPicturePath = explode ('/', 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/demo_pictures/'); 
    11     $ALocalInsertPicturePath = explode($strPathSeparator, dirname(__FILE__).$strPathSeparator.'demo_pictures'); 
    12     $APicturePath = explode('/', 'http://'.$_SERVER['HTTP_HOST'].$_REQUEST['picturepath']); 
    13  
    14     $AtheFilePath = array_values (array_diff ($APicturePath, $AInsertPicturePath)); 
    15     $theFilePath = implode($strPathSeparator, $AtheFilePath).$strPathSeparator; 
    16  
     6    $PicturePath = $_REQUEST['picturepath']; 
     7 
     8    $AInsertPicturePath = explode ('/', dirname($_SERVER['PHP_SELF'])); 
     9    $ALocalInsertPicturePath = explode($strPathSeparator, dirname(__FILE__)); 
    1710    $AtheRootPath = array_values (array_diff ($ALocalInsertPicturePath, $AInsertPicturePath)); 
    18     $theRootPath = implode($strPathSeparator, $AtheRootPath); 
    19  
    20     $LocalPicturePath = $theRootPath.$strPathSeparator.$theFilePath.$strPathSeparator; 
    21   } else { 
    22     $getRequest = false; 
    23     $PicturePath =  'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/demo_pictures/'; 
    24     $LocalPicturePath = dirname(__FILE__).$strPathSeparator.'demo_pictures'; 
     11    $RootPath = implode($strPathSeparator, $AtheRootPath); 
     12 
     13    $LocalPicturePath = str_replace('http://'.$_SERVER['HTTP_HOST'], "", $PicturePath); 
     14    $LocalPicturePath = str_replace('/', $strPathSeparator, $LocalPicturePath); 
     15    $LocalPicturePath = $RootPath.$LocalPicturePath; 
     16 
     17    $LocalPicturePath = dirname(__FILE__).$strPathSeparator.'demo_pictures'.$strPathSeparator; 
     18    //$LocalPicturePath = realpath('../../../../images/content/').$strPathSeparator; 
    2519  } 
    2620  $limitedext = array(".gif",".jpg",".png",".jpeg"); //Extensions you want files uploaded limited to. 
    2721  $limitedsize = "1000000"; //size limit in bytes 
    2822  $message = ""; 
    29   function formatSize($size)  
     23 
     24  function formatSize($size) 
    3025  { 
    31     if($size < 1024)  
    32       return $size.' bytes';     
    33     else if($size >= 1024 && $size < 1024*1024)  
    34       return sprintf('%01.2f',$size/1024.0).' Kb';       
     26    if($size < 1024) 
     27      return $size.' bytes'; 
     28    else if($size >= 1024 && $size < 1024*1024) 
     29      return sprintf('%01.2f',$size/1024.0).' Kb'; 
    3530    else 
    36       return sprintf('%01.2f',$size/(1024.0*1024)).' Mb';        
    37   } 
    38  
     31      return sprintf('%01.2f',$size/(1024.0*1024)).' Mb'; 
     32  } 
     33  $DestFileName = ""; 
    3934  if (isset($_FILES['file'])) { 
    4035    $file = $_FILES['file']; 
    4136    $ext = strrchr($file['name'],'.'); 
    42     if (!in_array($ext,$limitedext)) { 
     37    if (!in_array($ext,$limitedext)) 
    4338      $message = "The file you are uploading doesn't have the correct extension."; 
    44     } else if (file_exists($LocalPicturePath.'\\'.$file['name'])) { 
     39    else if (file_exists($LocalPicturePath.$file['name'])) 
    4540      $message = "The file you are uploading already exists."; 
    46     } else if ($file['size'] > $limitedsize) { 
     41    else if ($file['size'] > $limitedsize) 
    4742      $message = "The file you are uploading is to big. The max Filesize is</span><span> ".formatSize($limitedsize)."."; 
    48     } else { 
    49       copy($file['tmp_name'], $LocalPicturePath.$strPathSeparator.$file['name']); 
    50     } 
    51   } 
    52  
     43    else 
     44      copy($file['tmp_name'], $LocalPicturePath.$file['name']); 
     45    $DestFileName = $file['name']; 
     46  } 
    5347?> 
    5448<html> 
    55  
    5649<head> 
    5750  <title>Insert Image</title> 
    58          
    5951<link rel="stylesheet" type="text/css" href="../../popups/popup.css" /> 
    6052<script type="text/javascript" src="../../popups/popup.js"></script> 
     
    6254<script type="text/javascript"> 
    6355 
    64 var HTMLArea = window.opener.HTMLArea; 
     56var Xinha = window.opener.Xinha; 
    6557function i18n(str) { 
    66   return (HTMLArea._lc(str, 'HTMLArea')); 
     58  return (Xinha._lc(str, 'Xinha')); 
    6759} 
    6860 
     
    7264  window.resizeTo(500, 490); 
    7365  // Make sure the translated string appears in the drop down. (for gecko) 
    74   document.getElementById("f_align").selectedIndex = 1; 
    75   document.getElementById("f_align").selectedIndex = 5; 
     66  document.getElementById("f_align").selectedIndex = 0; 
     67  document.getElementById("f_align").selectedIndex = document.getElementById("f_align").selectedIndex; 
    7668  var param = window.dialogArguments; 
    7769  if (param) { 
     
    8072      document.getElementById("f_border").value = param["f_border"]; 
    8173      document.getElementById("f_align").value = param["f_align"]; 
    82       document.getElementById("f_vert").value = param["f_vert"]; 
    83       document.getElementById("f_horiz").value = param["f_horiz"]; 
     74      document.getElementById("f_vert").value = (param["f_vert"]!="-1") ? param["f_vert"] : ""; 
     75      document.getElementById("f_horiz").value = (param["f_horiz"]!="-1") ? param["f_horiz"] : ""; 
    8476      document.getElementById("f_height").value = param["f_height"]; 
    85       document.getElementById("f_width").value = param["f_width"];                       
     77      document.getElementById("f_width").value = param["f_width"]; 
    8678      window.ipreview.location.replace(param.f_url); 
    8779  } 
    8880  document.getElementById("f_url").focus(); 
     81  document.getElementById("filelist").selectedIndex = document.getElementById("filelist").selectedIndex; 
     82<?php If ($DestFileName<>"") 
     83  echo "CopyToURL(\"".$PicturePath.$DestFileName."\");" 
     84?> 
    8985} 
    9086 
     
    10298  } 
    10399  // pass data back to the calling window 
    104   var fields = ["f_url", "f_alt", "f_align", "f_border", 
    105                 "f_horiz", "f_vert"]; 
     100  var fields = ["f_url", "f_alt", "f_align", "f_border", "f_horiz", "f_vert", "f_width", "f_height"]; 
    106101  var param = new Object(); 
    107102  for (var i in fields) { 
     
    126121    } 
    127122  } 
    128   submit(); 
    129   return false; 
     123  return true; 
    130124} 
    131125 
     
    174168} 
    175169</script> 
    176  
    177170</head> 
    178  
    179171<body class="dialog" onload="Init()"> 
    180  
    181172<div class="title">Insert Image</div> 
    182173<table border="0" width="100%" style="padding: 0px; margin: 0px"> 
    183174  <tbody> 
    184175  <tr> 
    185     <td>Images on the Server:<br> 
    186     <select value="" style="width:200" size="10" onClick="CopyToURL(this[this.selectedIndex].value);"> 
     176    <td>Images on the Server:<?php /*echo $LocalPicturePath*/ ?><br> 
     177    <select id="filelist" name="filelist" style="width:200" size="10" onClick="CopyToURL(this[this.selectedIndex].value);"> 
    187178<?php 
    188179  $d = @dir($LocalPicturePath); 
    189   while (false !== ($entry = $d->read())) { //not a dot file or directory 
    190     if(substr($entry,0,1) != '.') {  
    191       echo '<OPTION value="' . $PicturePath.$entry. '">' . $entry . '(' . formatSize(filesize($LocalPicturePath.'\\'.$entry)) .')</OPTION>'; 
     180  while (false !== ($entry = $d->read())) { 
     181    if(substr($entry,0,1) != '.') {  //not a dot file or directory 
     182      if ($entry == $DestFileName) 
     183        echo '<OPTION value="' . $PicturePath.$entry. '" selected="selected">' . $entry . '(' . formatSize(filesize($LocalPicturePath.'\\'.$entry)) .')</OPTION>'; 
     184      else 
     185        echo '<OPTION value="' . $PicturePath.$entry. '">' . $entry . '(' . formatSize(filesize($LocalPicturePath.'\\'.$entry)) .')</OPTION>'; 
    192186    } 
    193187  } 
     
    195189?> 
    196190    </select> 
    197 <?php 
    198   if ($getRequest == true) { 
    199     echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'?picturepath='.$_REQUEST['picturepath'].'" enctype="multipart/form-data">'; 
    200   } else { 
    201     echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'" enctype="multipart/form-data">'; 
    202   } 
    203 ?> 
     191 
     192      <form method="post" action="" enctype="multipart/form-data"> 
     193        <input type="hidden" name="localpicturepath" value="<?php echo $LocalPicturePath ?>"> 
     194        <input type="hidden" name="picturepath" value="<?php echo $PicturePath ?>"> 
    204195        <input type="file" name="file" id="file" size="30"><br> 
    205         <button type="submit" name="ok" onclick="return onUpload();">Upload file</button><br> 
     196        <button type="submit" name="ok" onclick="onUpload();">Upload file</button><br> 
    206197        <span><?php echo $message ?></span> 
    207198      </form> 
     
    218209 
    219210<form action="" method="get"> 
     211  <input type="hidden" name="localpicturepath" value="<?php echo $LocalPicturePath ?>"> 
     212  <input type="hidden" name="picturepath" value="<?php echo $PicturePath ?>"> 
    220213<table border="0" width="100%" style="padding: 0px; margin: 0px"> 
    221214  <tbody> 
     
    224217    <td style="width: 7em; text-align: right">Image URL:</td> 
    225218    <td><input type="text" name="url" id="f_url" style="width:75%" 
    226       title="Enter the image URL here" /> 
     219      title="Enter the image URL here"  value="<?php echo $PicturePath.$DestFileName ?>"/> 
    227220      <button name="preview" onclick="return onPreview();" 
    228221      title="Preview the image in a new window">Preview</button> 
     
    253246  <option value="texttop"                      >Texttop</option> 
    254247  <option value="absmiddle"                    >Absmiddle</option> 
    255   <option value="baseline" selected="1"        >Baseline</option> 
     248  <option value="baseline"                     >Baseline</option> 
    256249  <option value="absbottom"                    >Absbottom</option> 
    257250  <option value="bottom"                       >Bottom</option> 
     
    263256 
    264257<div class="fl" style="width: 6em;">Border thickness:</div> 
    265 <input type="text" name="border" id="f_border" size="5" 
    266 title="Leave empty for no border" /> 
    267  
     258<input type="text" name="border" id="f_border" size="5" title="Leave empty for no border" /> 
    268259<div class="space"></div> 
    269260 
     
    291282 
    292283<div class="fr" style="width: 5em;">Horizontal:</div> 
    293 <input type="text" name="horiz" id="f_horiz" size="5" 
    294 title="Horizontal padding" /> 
    295  
     284<input type="text" name="horiz" id="f_horiz" size="5" title="Horizontal padding" /> 
    296285<p /> 
    297286 
    298287<div class="fr" style="width: 5em;">Vertical:</div> 
    299 <input type="text" name="vert" id="f_vert" size="5" 
    300 title="Vertical padding" /> 
     288<input type="text" name="vert" id="f_vert" size="5" title="Vertical padding" /> 
    301289 
    302290<div class="space"></div> 
Note: See TracChangeset for help on using the changeset viewer.