čtvrtek 16. února 2012
List of keywords
Here's a small plugin that takes a search queue and displays a list of keywords from selected field. Ie, I needed to be able to display all the order names in 2011, so now I just have to do a search using the native RS search, and I got the list of keywords on top.
<?php
function HookListSearchBeforesearchresults()
{
global $archive, $search, $restypes,$order_by,$archive,$sort,$starsearch ;
?>
<!-- Javascript for displaying/hiding the div, and css styling begins here -->
<script language="javascript">
function toggle2(showHideDiv, switchTextDiv) {
var ele = document.getElementById(showHideDiv);
var text = document.getElementById(switchTextDiv);
if(ele.style.display == "block") {
ele.style.display = "none";
text.innerHTML = "+ Seznam zakazek";
}
else {
ele.style.display = "block";
text.innerHTML = "- Skryt";
}
}
</script>
<style type="text/css">
#headerDiv, #contentDiv {
width: 300px;
}
#titleText {
float: left;
font-size: 1.1em;
font-weight: bold;
margin: 5px;
}
#headerDiv {
background-color: #0037DB;
color: #9EB6FF;
}
#contentDiv {
background-color: black;
}
#myContent {
margin: 5px 10px;
}
#myContent a {
font-size: 16px;
margin: 0 0 10px 0!important;
}
#headerDiv a {
float: right;
}
#headerDiv a:hover {
color: #FFFFFF;
}
</style>
<!-- Javascript for displaying/hiding the div, and css styling ends here -->
<!-- content -->
<div id="headerDiv">
<div id="titleText"></div><a id="myHeader" href="javascript:toggle2('myContent','myHeader');" > + Seznam zakazek</a>
</div>
<div id="contentDiv">
<div id="myContent" style="display: none;">
<?php
// use the actual search
$result2=do_search($search,$restypes,$order_by,$archive,'10000000',$sort,false,$starsearch);
// get list of resource ref's
if (!empty($result2)) {
foreach ($result2 as $res) {
$ref1[] = $res['ref'];
}
// implode for use in mysql query
$list = implode(",",$ref1);
// the actual query, replace resource_type_field value with anything you need
$result = mysql_query("SELECT distinct r1.value as nazev FROM `resource_data` r1 where r1.`resource_type_field`=8 and r1.`resource` IN ($list) ");
// create array with the names
$names=array();
while($row = mysql_fetch_array($result)){
// this is here because ie. dynamic keyword list adds "," at the beginning of the keyword
$name=str_replace(",","",$row['nazev']);
array_push($names,$name);
}
// remove duplicates
$unique_names=array_unique($names);
// sort alphabetically
asort($unique_names);
// create the list
foreach ($unique_names as $name){
?> <a href="search.php?search=<?php echo $name;?>"><?php echo $name;?></a><br />
<?php
}}
?>
</div>
</div>
<?php }
?>
Any feedback welcome...
středa 15. února 2012
Resourcespace - resize original
We use ResourceSpace as a photo gallery, where people from our company post their photos. As we don't need the photos to be high resolution, and we are space limited, we started to look for a way to resize the images. RS doesn't offer this funcionality (it never touches the original files), so I created a plugin for resizing the resources either on upload, or later in the Team center.
Imagick is required for this to work. You need to add these lines to your include/config.php
For the resize on upload, open include/image_processing.php, and after these lines:
insert the code for resizing:
What the plugin does: it finds resources with one side longer than $resize_original_max, resizes them, and writes new dimensions back to db. One glitch here: the exif data is not touched, so you probably get mismatch between exif data and info in db.
Feel free to use this anyway you like, suggestions and patches are welcome.
Imagick is required for this to work. You need to add these lines to your include/config.php
# resize on upload
$resize_original_on_upload=false;
# resize plugin
$resize_original=true;
# extensions to be resized
$resize_original_allowed_ext=array("jpg","png","tiff","tif");
# longer side dimension
$resize_original_max="2000";
For the resize on upload, open include/image_processing.php, and after these lines:
$identoutput=run_command($identcommand);
preg_match('/^([0-9]+)x([0-9]+)$/ims',$identoutput,$smatches);
if ((@list(,$sw,$sh) = $smatches)===false) { return false; }
insert the code for resizing:
global $resize_original_on_upload, $resize_original_allowed_ext, $resize_original_max;If you prefer to resize later, download the plugin, put it into your plugins folder and activate it. When you go to Team center, an option "Resize original images" should appear. Click it, you get number of resources to be resized, "this cannot be undone" warning and link to resize images. Click, the resources should get resized.
//to be changed to $path=$file once debugged
$path=$file;
//check if resize_original
if ($resize_original_on_upload) {
if (file_exists($file)) {
//check extension
$path_info= pathinfo($file);
if (in_array($path_info['extension'],$resize_original_allowed_ext)) {
//get dimensions
$image=new Imagick($file);
//check if one of the dimensions is longer than resize_original_max
if (($resize_original_max < $sh) || ($resize_original_max < $sw) ) {
//find longer side and scale the image
if ($sw > $sh) {
$image -> scaleImage($resize_original_max,0);}
else {
$image -> scaleImage(0,$resize_original_max);}
//save the image
$image -> writeImage($path);
//get new dimensions
$e = $image->identifyImage($path);
$sh=$e['geometry']['height'];
$sw=$e['geometry']['width'];
}}}}
What the plugin does: it finds resources with one side longer than $resize_original_max, resizes them, and writes new dimensions back to db. One glitch here: the exif data is not touched, so you probably get mismatch between exif data and info in db.
Feel free to use this anyway you like, suggestions and patches are welcome.
Přihlásit se k odběru:
Příspěvky (Atom)