'DBFM Attachment', 'callback' => 'dbfm_mapper_feeds_set_target', 'description' => t('The URL for the CCK @name field of the node.', array('@name' => $name)), ); } /** * Implementation of hook_feeds_set_target(). * * @param $node * The target node. * @param $field_name * The name of field on the target node to map to. * @param $value * The value to be mapped. Should contain a URL or an array of URLs; a * FeedsEnclosure or an array of FeedsEnclosures. * * @todo: should we support $object->url again? */ function dbfm_mapper_feeds_set_target($node, $target, $value) { // Normalize $value, create an array of FeedsEnclosures of it. $enclosures = array(); if (!is_array($value)) { $value = array($value); } foreach ($value as $k => $v) { /* * Esto nos deja solo los valores que esten entre '@@@' y '###' */ $v = substr($v, strpos($v, '@@@')+3); $v = substr($v, 0, strpos($v, '###')); if ($v instanceof FeedsEnclosure) { $enclosures[] = $v; } elseif (valid_url($v)) { $enclosures[$k] = new FeedsEnclosure($v, 'application/octet-stream'); } } // Map enclosures. foreach ($enclosures as $key -> $enclosure) { if ($fpath = $enclosure->getFile()) { if ($fid = dbfm_upload_file($fpath, basename($enclosure->getValue()), $node->uid)) { dbfm_dbinsert_attach($node->nid, $node->vid, $fid, $key); } } } } fname; $fpath .= '/'; $fpath .= $fname; $fsize = filesize($ftmp_path); $pfid = $parent_rec->fid; $currentdate = date("Y-m-d H:i:s"); $metadata = array(); $metadata['fpath'] = $fpath; $metadata['fname'] = $fname; $metadata['fparent'] = $pfid; $metadata['flastmod'] = $currentdate; $metadata['ftitle'] = $fname; $metadata['fcreatedate'] = $currentdate; $metadata['flang'] = 0; $metadata['fstatus'] = NULL; $metadata['fclass'] = NULL; //if we don't put the connection parameter then there will be errors $metadata['fdesc'] = NULL; $metadata['fkeywords'] = NULL; $metadata['fdistribution'] = 0; $metadata['fnewver'] = NULL; //now, the new file will inherit its parents file permissions - lets have a look first at the access permissions in dbfm_file $metadata['fwaccess'] = $parent_rec->fwaccess; $metadata['fraccess'] = $parent_rec->fraccess; if($pos = strrpos($fname, '.')) { //save in lower case only $ext = strtolower(substr($fname, $pos+1)); } else { $ext = ''; } $metadata['fmime'] = file_get_mimetype($fname); $metadata['fext'] = $ext; if ($i = @getimagesize($ftmp_path)) { $metadata['fimagesize'] = $i[0] . 'x' . $i[1]; // the text string (couldn't use i[3], it was too verbose $metadata['fimagew'] = (int) $i[0]; $metadata['fimageh'] = (int) $i[1]; } if (dbfm_compress($ext)) { $fblob = gzcompress($filecontent); $metadata['fmd5'] = md5($fblob); } else { $metadata['fmd5'] = md5($filecontent); $fblob = $filecontent; } //make up a data record $data_rec = new stdClass(); $data_rec->fid = $fid; //at this point we only know the fid if it's an update $data_rec->fblob = $fblob; $data_rec->fblobmod = $currentdate; $data_rec->fmd5 = $metadata['fmd5']; //moved from the dbinsert program $metadata['uid'] = $account->uid; $metadata['fsize'] = $fsize; $newfid = dbfm_dbinsert_file($parent_rec, $err, $metadata); if ($newfid == 0) { return FALSE; } $data_rec->fid = $newfid; if (!drupal_write_record('dbfm_data',$data_rec)) { watchdog("dbfm", "Failed to write the dbfm_data record for fid: %newfid", array('%newfid' => $newfid),WATCHDOG_ERROR); db_query("DELETE FROM {dbfm_file} WHERE fid = " . $newfid); } return TRUE; }