/** * insert * * insert new object data * * @param array $valuemap * values to insert * @param string $type * inserted object type * * @return int * inserted object id */ function insert($valuemap, $type) { if (count($valuemap) == 0) { return; } $names = ''; $values = ''; $comma = ''; foreach ($valuemap as $key => $value) { if (is_null($value)) { continue; } $names .= $comma . '' . $key . ''; $values .= $comma . " '" . $value . "'"; $comma = ', '; } $obj = EasyContactFormsClassLoader::getObject($type); $dbtable = $obj->getTableName(); $dbtable = EasyContactFormsDB::wptn($dbtable); $query = 'INSERT INTO ' . $dbtable . '(' . $names . ') VALUES (' . $values . ')'; EasyContactFormsDB::query($query); global $wpdb; return $wpdb->insert_id; }
/** * webdirUpload * * takes a file from a temporary folder, registers it in the file * manager * places the file to a web directory for direct download and makes a * thumbnail * copy if it is necessary * * @param array $_uldmap * request data */ function webdirUpload($_uldmap) { $filerequestid = $_uldmap['t'] . '_' . $_uldmap['fld'] . '_' . $_uldmap['oid']; if ($_FILES[$filerequestid]['error'] != UPLOAD_ERR_OK) { return FALSE; } $oowner = $_uldmap['easycontactusr']->id; $filename = $_FILES[$filerequestid]['name']; $tmpname = $_FILES[$filerequestid]['tmp_name']; $filesize = $_FILES[$filerequestid]['size']; $filetype = mysql_real_escape_string($_FILES[$filerequestid]['type']); $id = intval($_uldmap['oid']); $Type = mysql_real_escape_string($_uldmap['t']); $fieldname = mysql_real_escape_string($_uldmap['fld']); $filename = mysql_real_escape_string($filename); $ds = DIRECTORY_SEPARATOR; $targdir = EASYCONTACTFORMS__fileUploadDir . $ds . $Type . $ds . $id . $ds . $fieldname; $query = "SELECT Name FROM #wp__easycontactforms_files WHERE Doctype='{$Type}' AND Docid='{$id}' AND Docfield='{$fieldname}'"; $name = EasyContactFormsDB::getValue($query); $filepath = $targdir . $ds . $name; if (is_file($filepath)) { unlink($filepath); } $filepath = $targdir . $ds . $filename; $query = "DELETE FROM #wp__easycontactforms_files WHERE Doctype='{$Type}' AND Docid='{$id}' AND Docfield='{$fieldname}'"; EasyContactFormsDB::query($query); $valuemap = array(); $valuemap['Count'] = '0'; $valuemap['Docfield'] = $fieldname; $valuemap['Doctype'] = $Type; $valuemap['Docid'] = $id; $valuemap['Name'] = $filename; $valuemap['Size'] = $filesize; $valuemap['Type'] = $filetype; $valuemap['Protected'] = 0; $valuemap['Webdir'] = 1; $valuemap['Storagename'] = $filename; $valuemap['ObjectOwner'] = $oowner; $isid = EasyContactFormsDB::insert($valuemap, 'Files'); if ($Type == 'Files') { $valuemap = array(); $valuemap['Docid'] = $isid; EasyContactFormsDB::update($valuemap, 'Files', $isid); } if (!is_dir($targdir)) { EasyContactFormsUtils::createFolder($targdir); } move_uploaded_file($tmpname, $filepath); if (isset($_uldmap['thumbnailx']) && intval($_uldmap['thumbnailx']) != 0) { $newfieldname = 'thumb' . $fieldname; $newfilename = 'thumb' . $filename; $newtargdir = EASYCONTACTFORMS__fileUploadDir . $ds . $Type . $ds . $id . $ds . $newfieldname; $query = "SELECT Name FROM #wp__easycontactforms_files WHERE Doctype='{$Type}' AND Docid='{$id}' AND Docfield='thumb{$fieldname}'"; $name = EasyContactFormsDB::getValue($query); if (is_file($newtargdir . $ds . $name)) { unlink($newtargdir . $ds . $name); } EasyContactFormsUtils::createFolder($newtargdir); EasyContactFormsFiles::imgResize($filepath, $newtargdir . $ds . $newfilename, $_uldmap['thumbnailx'], $_uldmap['thumbnaily'], 0xffffff, 80); $query = "DELETE FROM #wp__easycontactforms_files WHERE Doctype='{$Type}' AND Docid='{$id}' AND Docfield='{$newfieldname}'"; EasyContactFormsDB::query($query); $valuemap = array(); $valuemap['Count'] = '0'; $valuemap['Docfield'] = $newfieldname; $valuemap['Doctype'] = $Type; $valuemap['Docid'] = $id; $valuemap['Name'] = $newfilename; $valuemap['Size'] = filesize($newtargdir . $ds . $newfilename); $valuemap['Type'] = $filetype; $valuemap['Protected'] = 0; $valuemap['Webdir'] = 1; $valuemap['Storagename'] = $newfilename; $valuemap['ObjectOwner'] = $oowner; EasyContactFormsDB::insert($valuemap, 'Files'); } if (isset($_uldmap['resizex']) && intval($_uldmap['resizex']) != 0) { EasyContactFormsFiles::imgResize($filepath, $filepath, $_uldmap['resizex'], $_uldmap['resizey'], 0xffffff, 80); $valuemap = array(); $valuemap['Size'] = filesize($filepath); EasyContactFormsDB::update($valuemap, 'Files', $isid); } echo json_encode(array('success' => 'TRUE')); return TRUE; }
/** * getSid * * * @return * */ function getSid() { if (rand(1, 10) == 9) { $nDaysAgo = 3; $query = "DELETE FROM `#wp__easycontactforms_sessions` WHERE opentime < '" . date("Y-m-d H:i:s", time() - 24 * 60 * 60 * $nDaysAgo) . "'"; EasyContactFormsDB::query($query); } $pwd = EasyContactFormsSecurityManager::getServerPwd(); $maxid = EasyContactFormsDB::getValue('SELECT MAX(id) FROM #wp__easycontactforms_sessions'); $sid = md5($maxid + 10 . $pwd); $query = 'INSERT INTO #wp__easycontactforms_sessions(sid, value) VALUES (\'' . $sid . '\', \'<data />\')'; EasyContactFormsDB::query($query); return $sid; }
/** * delete * * deletes an object record and all subordinated object records from the * database * * @param int $objid * object id */ function delete($objid) { $queries = $this->getDeleteStatements($objid); foreach ($queries as $query) { EasyContactFormsDB::query($query); } }