Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2006-09-09 13:35:41

aswihart
Member
From: Pittsburgh, PA
Registered: 2006-07-22
Posts: 345
Website

Re: Hack: custom fields for files

This is such a useful mod, can someone please figure out how to get something like this to work for the current version of textpattern? I think extra fields should be available for all the txp:> elements, by default in a normal textpattern install, don’t you? It would be great to be able to assign a thumbnail image to each file, or as the original creator of this old hack suggests, an author field. I don’t know squat about php, so please someone help out here, I’m amazed this isn’t a more popular concept, or maybe nobody is using the txp:> elements that much, or maybe nobody is using textpattern at all. Thanks a lot,
Andrew

Last edited by aswihart (2006-09-09 13:36:43)

Offline

#14 2007-02-12 15:36:50

mattgilbert
Member
Registered: 2006-03-23
Posts: 70

Re: Hack: custom fields for files

I would just like to weigh in and say that I would also find this useful.

matt

Offline

#15 2007-02-13 03:23:55

mattgilbert
Member
Registered: 2006-03-23
Posts: 70

Re: Hack: custom fields for files

Well, I kind of went ahead and did it. I’ve made a plugin that still requires adding tables in phpMyAdmin and is specific to my needs in a few ways, but it could be generalized. Let me know if anyone is interested in helping me with it. (It shouldn’t take much for someone with experience developing plugins.)

Offline

#16 2007-02-13 10:32:44

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Hack: custom fields for files

@ mattgilbert

Could you post this in the Plugins forum please? Because this is an expired thread not many people will notice it.

Offline

#17 2009-01-12 22:36:26

azw
Member
Registered: 2007-01-29
Posts: 279

Re: Hack: custom fields for files

mattgilbert wrote:

Well, I kind of went ahead and did it. I’ve made a plugin that still requires adding tables in phpMyAdmin and is specific to my needs in a few ways, but it could be generalized. Let me know if anyone is interested in helping me with it. (It shouldn’t take much for someone with experience developing plugins.)

Matt, I realize that it’s been eons since you posted here. Are you still working with this idea? I’d be interested in possibly using what you’ve got.

Last edited by azw (2009-01-12 22:37:08)

Offline

#18 2009-01-12 23:46:58

keith
Member
From: Blyth, Northumberland, England
Registered: 2004-12-08
Posts: 199
Website

Re: Hack: custom fields for files

Matt’s last post here was on 28 November 2007…


Keith
Blyth, Northumberland, England
Capture The Moment

Offline

#19 2009-01-13 01:19:04

azw
Member
Registered: 2007-01-29
Posts: 279

Re: Hack: custom fields for files

Yeah, I’m guessing that I’ll be disappointed, but if I’m wrong, his help sure could save me a lot of effort and time!

Offline

#20 2009-01-13 14:36:22

thebombsite
Archived Plugin Author
From: Exmouth, England
Registered: 2004-08-24
Posts: 3,251
Website

Re: Hack: custom fields for files

Not sure if this is the same guy but that is a TXP site so maybe drop him a line?


Stuart

In a Time of Universal Deceit
Telling the Truth is Revolutionary.

Offline

#21 2009-01-13 20:22:21

azw
Member
Registered: 2007-01-29
Posts: 279

Re: Hack: custom fields for files

Great idea! Thanks, Stuart. I’ll post back if I learn anything useful.

Offline

#22 2009-01-14 10:00:49

azw
Member
Registered: 2007-01-29
Posts: 279

Re: Hack: custom fields for files

Matt has sent me the file and allowed me to post it. He hasn’t checked to see if it works with the current version of TXP.

I’m not sure this will work….

<?php
if (@txpinterface == 'admin'){
  add_privs('glb_custom_fields_for_files', '1,2,3,4,5');
  register_callback('glb_custom_fields_for_files', 'glb_custom_fields_for_files');

  add_privs('glb_show_file_custom_fields', '1,2,3,4,5');
  register_callback("glb_show_file_custom_fields", "file");
}

function glb_show_file_custom_fields($event, $step) {
  if(  (isset($_GET["step"]) && $_GET["step"] == 'file_edit')
|| isset($_POST["step"]) && $_POST["step"] == 'file_insert') {

    $width = "var file_width = ''; ";
    $height = "var file_height = ''; ";
    if(isset($_GET["step"]) && $_GET["step"] == 'file_edit'){
      $id = $_GET["id"];

      $query = "SELECT id, width, height FROM ".safe_pfx_j('txp_file')." WHERE id = ".$id;
      $result = safe_query($query);
      $row = mysql_fetch_assoc($result);
      $width = "var file_width = '".$row['width']."'; ";
      $height = "var file_height = '".$row['height']."'; ";
    }

    echo <<< EOF
<script language="JavaScript" type="text/javascript"><!--

$width
$height

function get_elem(doc,id) {
	if (doc.getElementById) {
		return doc.getElementById(id);
	} else if (doc.all) {
		return doc.all[id];
	} else if (doc.layers) {
		return doc.layers[id];
	}
	return null; // this is not happening
}

function add_customs_edit(){
  var lst_table = get_elem(document, 'list');
  var form = lst_table.tBodies[0].rows[1].cells[0].childNodes[1];

  var width_p = document.createElement('p');
  width_p.appendChild(document.createElement('label').appendChild(document.createTextNode('width')));
  width_p.appendChild(document.createElement('br'));
  var width_input;
  try {
    width_input = document.createElement("<input name='file_width' type='text' class='edit' value = '"+file_width+"' />");
  } catch (e) {
    width_input = document.createElement("input");
    width_input.setAttribute("name", "file_width");
    width_input.setAttribute("type", "text");
    width_input.setAttribute("class", "edit");
    width_input.setAttribute("value", file_width);
  }
  width_p.appendChild(width_input);
  form.insertBefore(width_p, form.childNodes[1]);

  var height_p = document.createElement('p');
  height_p.appendChild(document.createElement('label').appendChild(document.createTextNode('height')));
  height_p.appendChild(document.createElement('br'));
  var height_input;
  try {
    height_input = document.createElement("<input name='file_height' type='text' class='edit' value = '"+file_height+"' />");
  } catch (e) {
    height_input = document.createElement("input");
    height_input.setAttribute("name", "file_height");
    height_input.setAttribute("type", "text");
    height_input.setAttribute("class", "edit");
    height_input.setAttribute("value", file_height);
  }
  height_p.appendChild(height_input);
  form.insertBefore(height_p, form.childNodes[2]);
  form.removeChild(form.childNodes[0]);
}

addEvent(window,'load',function() {add_customs_edit();});
--></script>
EOF;
  }

  else if(isset($_POST["step"]) && $_POST["step"] == 'file_save') {
    $new_width = '';
    if(isset($_POST["file_width"])) $new_width = $_POST["file_width"];

    $new_height = '';
    if(isset($_POST["file_height"])) $new_height = $_POST["file_height"];

    $id = $_POST["id"];
    $query = "SELECT id, width, height FROM ".safe_pfx_j('txp_file')." WHERE id = ".$id;
    $result = safe_query($query);
    $row = mysql_fetch_assoc($result);
    $old_width = "var file_width = '".$row['width']."'; ";
    $old_height = "var file_height = '".$row['height']."'; ";

    if($new_width != $old_width){
      safe_update("txp_file", "width = '".$new_width."'", "id = '".$id."'");
    }
    if($new_height != $old_height){
      safe_update("txp_file", "height = '".$new_height."'", "id = '".$id."'");
    }
  }

  if( (isset($_POST["step"]) && $_POST["step"] == 'file_save' )
      || (!isset($_POST["step"]) && !isset($_GET["step"])) ) {
    $query = "SELECT id, width, height FROM ".safe_pfx_j('txp_file');
    $result = safe_query($query);
    $widths = "var widths = new Array(); ";
    $heights = "var heights = new Array(); ";
    if (mysql_num_rows($result) > 0){
      while ($row = mysql_fetch_array($result)){
        $widths .= "widths[".$row['id']."] = '".$row['width']."'; ";
        $heights .= "heights[".$row['id']."] = '".$row['height']."'; ";
      }
    }

echo <<< EOF
<script language="JavaScript" type="text/javascript"><!--

$widths
$heights

function get_elem(doc,id) {
	if (doc.getElementById) {
		return doc.getElementById(id);
	} else if (doc.all) {
		return doc.all[id];
	} else if (doc.layers) {
		return doc.layers[id];
	}
	return null; // this is not happening
}

function add_customs(){

  var lst_table = get_elem(document, 'list');
  var lst_rows = lst_table.tBodies[0].rows;

  var header_row = lst_rows[0];
  var custom1_cell = document.createElement('th');
  custom1_cell.appendChild(document.createTextNode('width'));
  header_row.insertBefore(custom1_cell, header_row.cells[4]);
  header_row.removeChild(header_row.cells[5]);

  var custom2_cell = document.createElement('th');
  custom2_cell.appendChild(document.createTextNode('height'));
  header_row.insertBefore(custom2_cell, header_row.cells[5]);
  header_row.removeChild(header_row.cells[6]);

  for(var i = 1; i < lst_rows.length; i++){ 
    var row = lst_rows[i];
    var row_id = row.cells[0].childNodes[0].nodeValue;

    var custom1_cell = document.createElement('td');
    custom1_cell.appendChild(document.createTextNode(widths[row_id]));
    row.insertBefore(custom1_cell, row.cells[4]);
    row.removeChild(row.cells[5]);

    var custom2_cell = document.createElement('td');
    custom2_cell.appendChild(document.createTextNode(heights[row_id]));
    row.insertBefore(custom2_cell, row.cells[5]);
    row.removeChild(row.cells[6]);
  }
}

addEvent(window,'load',function() {add_customs();});

--></script>
EOF;
  }
}

// front end plugins

function glb_if_file_download_width($atts, $thing){
  global $thisfile;
  $if_file_download_width = false;
  if (!empty($thisfile["width"])) {
    $if_file_download_width = true;
  }
  return ($if_file_download_width) ? parse(EvalElse($thing, true)) : parse(EvalElse($thing, false));
}

function glb_file_download_width($atts){
  global $thisfile;
  $file_download_width = '';
  if (!empty($thisfile["width"])) {
    $file_download_width = $thisfile["width"];
  }
  return $file_download_width;
}

function glb_if_file_download_height($atts, $thing){
  global $thisfile;
  $if_file_download_height = false;
  if (!empty($thisfile["height"])) {
    $if_file_download_height = true;
  }
  return ($if_file_download_height) ? parse(EvalElse($thing, true)) : parse(EvalElse($thing, false));
}

function glb_file_download_height($atts){
  global $thisfile;
  $file_download_height = '';
  if (!empty($thisfile["height"])) {
    $file_download_height = $thisfile["height"];
  }
  return $file_download_height;
}


/*
--- PLUGIN METADATA ---
Name: glb_custom_fields_for_files
Version: 0.1
Type: 1
Description: Plug-in adds custom fields for files
Author: Matt Gilbert
Link: http://www.mattgilbert.net
--- BEGIN PLUGIN HELP ---

--- END PLUGIN HELP & METADATA ---
*/
?>

Offline

Board footer

Powered by FluxBB