function nextImg($name) { // get next imgname from uploads table $img_query = new myQuery(sprintf("INSERT INTO img (user_id, dt, name) \n VALUES ('%d', NOW(), '%s')\n ON DUPLICATE KEY UPDATE\n user_id='%d', dt=NOW()", $_SESSION['user_id'], str_replace(array('///', '//'), '/', $name), $_SESSION['user_id'])); $img_id = $img_query->get_insert_id(); return $img_id; }
/** * Очистить кэш * * @param string $pattern */ public static function clearCache($pattern) { if (is_null(self::$_cache)) { self::$_cache = new Doctrine_Cache_Memcache(array('servers' => array('host' => 'localhost', 'port' => 11211, 'persistent' => true), 'compression' => false)); } self::$_cache->delete($pattern); }
// remove trailing slash $basedir = preg_replace('@[^?;:{}/]+$@', '', $olddir); // remove last dir name $olddir = preg_replace('@^' . $basedir . '@', '', $olddir); if ($newdir == '') { $return['errorText'] .= 'You cannot change the directory name to “' . $_POST['newdir'] . '”'; } else { if (!is_dir(IMAGEBASEDIR . $basedir) || !chdir(IMAGEBASEDIR . $basedir)) { $return['errorText'] .= 'Could not change directory to ' . $basedir; } else { if (is_dir($newdir)) { $return['errorText'] .= $basedir . $newdir . ' already exists'; } else { if (!rename($olddir, $newdir)) { $return['errorText'] .= "Could not rename {$olddir} to {$newdir}"; } else { chmod($newdir, DIRPERMS); $return['error'] = false; $return['newdir'] = $basedir . $newdir; $old = '/' . $basedir . '/' . $olddir . '/'; $new = '/' . $basedir . '/' . $newdir . '/'; $old = str_replace('//', '/', $old); $new = str_replace('//', '/', $new); $q = new myQuery("UPDATE img SET name = REPLACE(name, '{$old}', '{$new}') WHERE LOCATE('{$old}', name) = 1"); $return['images_updated'] = $q->get_affected_rows(); } } } } scriptReturn($return); exit;
/** * Чистим кэш */ public function preDelete($event) { myQuery::clearCache('my_point_images_' . $this->getPointId()); }
} else { $ret['files']++; $ret['size'] += filesize($dir . '/' . $currentFile); } } } closedir($odir); return $ret; } $total_size = 0; foreach ($return['projects'] as $i => $proj) { $st = microtime(true); $res = countFilesOO(IMAGEBASEDIR . $proj['id']); if ($proj['user_id'] == $user) { $mysize += $res['size']; } if ($res) { $return['projects'][$i]['filemtime'] = filemtime(IMAGEBASEDIR . $proj['id']); $return['projects'][$i]['files'] = $res['files'] | 0; $return['projects'][$i]['trash'] = $res['trash'] | 0; $return['projects'][$i]['tmp'] = $res['tmp'] | 0; $return['projects'][$i]['size'] = formatBytes($res['size']); } $return['time']['proj' . $proj['id']] = microtime(true) - $st; } //$return['userAllocation'] = userAllocation($user); $q = new myQuery("SELECT allocation FROM user WHERE id='{$user}'"); $allocation = $q->get_one(0, 'allocation'); $return['userAllocation'] = array('allocation' => $allocation, 'size' => $mysize / 1024 / 1024); scriptReturn($return); exit;
public function mirror($sym, $w) { // create the mirror-reversed version of the file // use the sym file in argument1 if (empty($sym)) { $sym = $this->getID(); } if (is_int($sym)) { // $sym is a tem_id, get the sym file from the database $q = new myQuery("SELECT n, sym FROM point WHERE tem_id={$sym} AND sym IS NOT NULL"); $sym = $q->get_assoc(false, 'n', 'sym'); } if ($this->getPointNumber() != count($sym)) { return false; } $mirror_pts = array(); foreach ($this->_points as $i => $pts) { $mirror_pts[$i] = $this->getPoints($sym[$i]); } foreach ($mirror_pts as $i => $pts) { $pts[0] = $w - $pts[0]; // adjust for flipping $this->setPoints($i, $pts); } return $this; }
if (is_dir($dir . '/' . $currentFile)) { $ret2 = countFilesProc($dir . '/' . $currentFile); $ret['files'] += $ret2['files']; $ret['size'] += $ret2['size']; } else { $ret['files']++; $ret['size'] += filesize($dir . '/' . $currentFile); } } } closedir($odir); return $ret; } $user = $_SESSION['user_id']; $proj_id = $_POST['proj_id']; $q = new myQuery("SELECT project.user_id as owner \n FROM project \n LEFT JOIN project_user ON (project.id=project_id)\n WHERE project_user.user_id='{$user}' AND project_id='{$proj_id}'"); if ($q->get_num_rows() > 0) { $return['filemtime'] = filemtime(IMAGEBASEDIR . $proj_id); if ($return['filemtime'] != $_POST['filemtime']) { $res = countFilesProc(IMAGEBASEDIR . $proj_id); if ($res) { $return['mysize'] = $q->get_one() == $user ? $res['size'] : 0; $return['files'] = $res['files'] | 0; $return['trash'] = $res['trash'] | 0; $return['tmp'] = $res['tmp'] | 0; $return['size'] = formatBytes($res['size']); } } } scriptReturn($return); exit;
<?php // check if a user has access to something require_once $_SERVER['DOCUMENT_ROOT'] . '/include/main_func.php'; auth(); $return = array('error' => false, 'errorText' => ''); $user = $_SESSION['user_id']; $id = intval($_POST['id']); $table = $_POST['table']; if (in_array($table, array('tem', 'fm', 'img'))) { $q = new myQuery("SELECT COUNT(*) AS c FROM {$table} WHERE id={$id} AND user_id={$user}"); $c = $q->get_one(); if ($c == 0) { $return['error'] = true; $return['errorText'] = "Either the item does't exist or you do not own it."; } } else { $return['error'] = true; $return['errorText'] = "You cannot check for access in the {$table} table."; } scriptReturn($return); exit;
<?php // add a user's facialmetric equation to the database require_once $_SERVER['DOCUMENT_ROOT'] . '/include/main_func.php'; auth(); $return = array('error' => false, 'errorText' => ''); // clean the equation // Remove whitespaces $eq = preg_replace('/\\s+/', '', $_POST['eq']); $blank_eq = str_replace(array('abs(', 'min(', 'max(', 'atan(', 'asin(', 'acos(', 'tan(', 'sin(', 'cos(', 'sqrt(', 'pow(', 'rad2deg(', 'x[', 'y[', ']', '(', ')', '.', ',', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '-', '*', '/'), '', $eq); if (!empty($blank_eq)) { $return['error'] = true; $return['errorText'] .= 'The equation was not valid. These characters need to be removed: ' . $blank_eq; } else { $user = $_SESSION['user_id']; $name = my_clean($_POST['name']); $desc = my_clean($_POST['desc']); $q = new myQuery("REPLACE INTO fm (user_id, name, description, equation) \n VALUES ('{$user}', '{$name}', '{$desc}', '{$_POST['eq']}')"); if ($q->get_affected_rows() == 1) { $return['name'] = $name; $return['desc'] = $desc; $return['eq'] = $_POST['eq']; } else { $return['name'] = $q->get_affected_rows(); } } scriptReturn($return); exit; ?>
<?php // remove an owner from a project require_once $_SERVER['DOCUMENT_ROOT'] . '/include/main_func.php'; auth(); $return = array('error' => false, 'errorText' => ''); $user = $_SESSION['user_id']; $project = $_POST['project']; $deluser = $_POST['owner']; $q = new myQuery("SELECT 1 FROM project_user WHERE project_id='{$project}' AND user_id='{$user}'"); if ($q->get_affected_rows() > 0) { $q = new myQuery("SELECT COUNT(*) as c FROM project_user WHERE project_id='{$project}' GROUP BY project_id"); if ($q->get_one() < 2) { $return['error'] = true; $return['errorText'] = "This project only has one user. Please add more before deleting users to avoid abandoning projects."; } else { $q = new myQuery("DELETE FROM project_user WHERE project_id='{$project}' AND user_id='{$deluser}'"); if ($q->get_affected_rows() == 0) { $return['error'] = true; $return['errorText'] = "This user could not be deleted from this project"; } } } else { $return['error'] = true; $return['errorText'] = "You do not have permission to delete users from this project"; } scriptReturn($return); exit; ?>
<?php // check project permissions and set project_id SESSION variable require_once $_SERVER['DOCUMENT_ROOT'] . '/include/main_func.php'; auth(); $return = array('error' => false, 'errorText' => ''); $proj_id = validID($_POST['project']) ? $_POST['project'] : 0; $q = new myQuery("SELECT perm\n FROM project_user\n WHERE user_id='{$_SESSION['user_id']}'\n AND project_id='{$proj_id}'"); if ($q->get_num_rows() == 1) { $return['perm'] = $q->get_one(); $_SESSION['project_id'] = $proj_id; } else { $return['error'] = true; $return['errorText'] = 'You do not have permission to access this project.'; } scriptReturn($return); exit;
<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/include/main_func.php'; date_default_timezone_set('Europe/London'); include DOC_ROOT . '/include/classes/PHPMailer/PHPMailerAutoload.php'; $return = array('error' => false, 'errorText' => ''); $id = my_clean($_POST['id']); $auth = cleanData($_POST, 'auth', array("user", "disabled"), $default = 'disabled'); $q = new myQuery("UPDATE user SET status='{$auth}' WHERE id={$id}"); if ($auth == "user" && $q->get_affected_rows() == 1) { // create a new password $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ123456789123456789"; $password = substr(str_shuffle($chars), 0, 10); $salt = '$2y$10$' . substr(md5(microtime()), 0, 21) . '$'; $hash = crypt($password, $salt); $q = new myQuery(array("UPDATE user SET password='******' WHERE id='{$id}'", "SELECT email FROM user WHERE id='{$id}'")); $email = $q->get_one(); $return['email'] = $email; if (DEBUG) { $return['newpass'] = $password; } // only for debugging!!!! // email new password to the user $to = $email; $subject = 'WebMorph.org Account Authorized'; $headers = "From: lisa.debruine@glasgow.ac.uk\r\n"; $headers .= "Reply-To: lisa.debruine@glasgow.ac.uk\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; $message = "<html><body style='color: rgb(50,50,50); font-family:\"Lucida Grande\"';>" . "<p>Hi {$email},</p>\n" . "<p>Your requested <a href='http://webmorph.org'>WebMorph</a> account has been authorized.</p>\n" . "<p>Remember, WebMorph is in beta testing, so there are likely to be problems sometimes. \n WebMorph should work with Chrome and Safari, but I develop in FireFox, so errors are usually \n caught there first.</p>\n" . "<div style='border: 3px solid hsl(200,100%,20%); " . " box-shadow: 2px 2px 4px rgba(0,0,0,0.5);border-radius: 1em; padding: 1em; " . " text-align: center; width: 18em; margin: auto;'>\n" . " Your new password:\n" . " <div style='font-size: 200%; margin-top: 0.5em;'>{$password}</div>\n" . "</div>\n" . "<p>You can reset your password after logging in by going to the Preferences menu option.</p>\n" . "<p>Kind regards,</p>\n" . "<p>Lisa DeBruine</p>\n" . "</body></html>\n."; $text_message = "Hi {$email},\n" . "Your requested <a href='http://webmorph.org'>WebMorph</a> account has been authorized.\n\n" . "Remember, WebMorph is in beta testing, so there are likely to be problems sometimes. \n WebMorph should work with Chrome and Safari, but I develop in FireFox, so errors are usually \n caught there first. \n\n" . "Your new password: {$password} \n\n" . "You can reset your password after logging in by going to the Preferences menu option.</p>\n\n" . "Kind regards,\n" . "Lisa DeBruine\n.";
function duplicateTable($table, $type, $old_id, $new_id) { $q = new myQuery("SELECT * FROM {$table} WHERE {$type}_id={$old_id}"); $old_data = $q->get_assoc(); if (count($old_data) > 0) { unset($old_data[0]["{$type}_id"]); $fields = array_keys($old_data[0]); $query = sprintf("INSERT INTO {$table} ({$type}_id, %s) SELECT {$new_id}, %s FROM {$table} WHERE {$type}_id={$old_id}", implode(", ", $fields), implode(", ", $fields)); $q = new myQuery($query); } return $q->get_affected_rows(); }
require_once $_SERVER['DOCUMENT_ROOT'] . '/include/main_func.php'; auth(); $return = array('error' => false, 'errorText' => ''); $user = $_SESSION['user_id']; $tem_id = intval($_POST['tem_id']); $q = new myQuery("SELECT name FROM tem WHERE id=" . $tem_id); $return['name'] = $q->get_one(); $q = new myQuery("SELECT n as i, name, x, y FROM point WHERE tem_id=" . $tem_id . " ORDER BY n"); $return['defaultTem'] = $q->get_assoc(); $q = new myQuery("SELECT points FROM line WHERE tem_id=" . $tem_id . " ORDER BY n"); $return['defaultLines'] = array_map(function ($a) { return explode(',', $a['points']); }, $q->get_assoc()); $q = new myQuery("SELECT n, color FROM line WHERE tem_id=" . $tem_id . " ORDER BY n"); $return['lineColors'] = $q->get_assoc(false, false, 'color'); $q = new myQuery("SELECT 3ptdelin1, 3ptdelin2, 3ptdelin3 FROM tem WHERE id=" . $tem_id); $pts = $q->get_row(); $return['fitPoints'] = array($pts['3ptdelin1'], $pts['3ptdelin2'], $pts['3ptdelin3']); scriptReturn($return); exit; /* CREATE TABLE tem ( id INT(11) NOT NULL AUTO_INCREMENT, user_id INT(4) NOT NULL, name VARCHAR(255) NOT NULL, notes TEXT, public BOOL DEFAULT 0, 3ptdelin1 INT(4), 3ptdelin2 INT(4), 3ptdelin3 INT(4), PRIMARY KEY (id)
<?php // delete a default template from the database require_once $_SERVER['DOCUMENT_ROOT'] . '/include/main_func.php'; auth(); $return = array('error' => false, 'errorText' => ''); $user = $_SESSION['user_id']; // check if user has permission to delete this template $tem_id = intval($_POST['id']); $q = new myQuery("SELECT COUNT(*) as c FROM tem WHERE user_id={$user} AND id={$tem_id} AND id>1"); if ($q->get_one() == 0) { $return['error'] = true; $return['errorText'] = 'You do not have permission to delete this template.'; header('Content-Type: application/json'); echo json_encode($return); exit; } $q = new myQuery("DELETE FROM tem WHERE id={$tem_id};"); $return['tem_deleted'] = $q->get_affected_rows(); if ($return['tem_deleted'] == 0) { $return['error'] = true; $return['errorText'] = "Template {$tem_id} was not deleted."; } else { $q->set_query("DELETE FROM point WHERE tem_id={$tem_id};"); $return['points_deleted'] = $q->get_affected_rows(); $q->set_query("DELETE FROM line WHERE tem_id={$tem_id};"); $return['lines_deleted'] = $q->get_affected_rows(); } scriptReturn($return); exit;
<?php // delete a user's facialmetric equation from the database require_once $_SERVER['DOCUMENT_ROOT'] . '/include/main_func.php'; auth(); $return = array('error' => false, 'errorText' => ''); $user = $_SESSION['user_id']; $name = my_clean($_POST['name']); $q = new myQuery("DELETE FROM fm WHERE user_id='{$user}' AND name='{$name}'"); if ($q->get_affected_rows() !== 1) { $return['error'] = true; $return['errorText'] = $q->get_affected_rows() . ' equations were deleted'; } scriptReturn($return); exit; ?>
public function calculateQueryCacheHash() { self::$lastQueryCacheHash = parent::calculateQueryCacheHash(); return self::$lastQueryCacheHash; }
<?php // get a user's preferences and personal data require_once $_SERVER['DOCUMENT_ROOT'] . '/include/main_func.php'; auth(); $return = array('error' => false, 'errorText' => '', 'prefs' => array('mask_color' => 'rgb(255,255,255)', 'cross_color' => 'rgb(0,255,0)', 'selcross_color' => 'rgb(255,0,0)', 'line_color' => 'rgb(0,0,255)', 'defaultLineWidth' => 1, 'texture' => 'true', 'sample_contours' => 'true', 'show_thumbs' => 'false', 'align_pt1' => 0, 'align_pt2' => 1, 'align_x1' => 496.98, 'align_y1' => 825.688, 'align_x2' => 853.02, 'align_y2' => 825.688, 'align_w' => 1350, 'align_h' => 1800, 'defaultTem' => 1, 'normalisation' => 'none', 'warp' => 'multiscale', 'default_imageformat' => 'jpg', 'batch_names' => 'folder', 'default_project' => NULL, 'theme' => 0), 'defaultTemplates' => array('id' => 1, 'name' => 'FRL-189'), 'fm' => array()); $user = $_SESSION['user_id']; $return['user'] = $user; if (empty($user)) { $return['error'] = true; } else { $q = new myQuery("SELECT pref, prefval FROM pref WHERE user_id='{$user}'"); $myprefs = $q->get_assoc(false, 'pref', 'prefval'); foreach ($myprefs as $pref => $val) { $return['prefs'][$pref] = $val; } $q = new myQuery("SELECT * FROM user WHERE id='{$user}'"); $userinfo = $q->get_one_array(); unset($userinfo['password']); $return['prefs'] = array_merge($return['prefs'], $userinfo); $q = new myQuery("SELECT id, tem.name, notes, \n COUNT(DISTINCT l.n) as `lines`, \n COUNT(DISTINCT p.n) AS points\n FROM tem\n LEFT JOIN point AS p ON (tem.id=p.tem_id)\n LEFT JOIN line AS l ON (tem.id=l.tem_id)\n WHERE user_id='{$user}' OR public=TRUE\n GROUP BY tem.id"); $return['defaultTemplates'] = $q->get_assoc(); $_SESSION['theme'] = $return['prefs']['theme']; $q = new myQuery("SELECT name, description, equation FROM fm WHERE user_id='{$user}'"); $return['fm'] = $q->get_assoc(); } scriptReturn($return); exit;
/** * Чистим кэш */ public function postSave($event) { myQuery::clearCache('my_point_images_' . $this->getId()); }
require_once REL(__FILE__, "LookupOptsQuery.php"); getOpts(); #**************************************************************************** #* Additional initialization activity #**************************************************************************** ## get default collection name class myQuery extends Query { function getDefault() { $sql = "SELECT * FROM `collection_dm` " . " WHERE `default_flg`='Y' "; //echo "sql=$sql <br />"; return $this->select01($sql); } } $Q = new myQuery(); $Q->connect(); $s = $Q->getDefault(); $Q->close(); //print_r($s); $postVars['defaultCollect'] = $s['description']; ## set protocol flag if ($postVars[protocol] == 'YAZ') { //echo " want to use YAZ protocol <br />"; $useYAZ = true; $useSRU = false; } else { if ($postVars[protocol] == 'SRU') { //echo " want to use SRU protocol <br />"; $useSRU = true; $useYAZ = false;
<?php // get or set a user's read messages require_once $_SERVER['DOCUMENT_ROOT'] . '/include/main_func.php'; auth(); $return = array('error' => false, 'errorText' => '', 'read_msg_ids' => array()); $user = $_SESSION['user_id']; if (empty($user)) { $return['error'] = true; $return['errorText'] = "No user is logged in"; } else { if (array_key_exists('msg_id', $_POST)) { // mark a message as read $msg_id = my_clean($_POST['msg_id']); $q = new myQuery("INSERT INTO msg (id, user_id, dt) VALUES ('{$msg_id}', '{$user}', NOW())"); } // get all read messages for this user $q = new myQuery("SELECT id FROM msg WHERE user_id='{$user}'"); $return['read_msg_ids'] = $q->get_col('id'); } scriptReturn($return); exit; /* CREATE TABLE msg ( id VARCHAR(32), user_id INT(8) UNSIGNED, dt DATETIME, INDEX (user_id) ); */
<?php // old function for switching users for Lisa require_once $_SERVER['DOCUMENT_ROOT'] . '/include/main_func.php'; auth(); $return = array('error' => false, 'errorText' => ''); if ($_SESSION['user_id'] == '1' || $_SESSION['user_id'] == '3') { $id = intval($_POST['id']); if ($id > 0) { // switch user $q = new myQuery("SELECT * FROM user WHERE id={$id}"); $user = $q->get_one_array(); $return['name'] = $user['firstname'] . ' ' . $user['lastname']; $return['email'] = $user['email']; $_SESSION['user_id'] = $id; $return['user_id'] = $id; setcookie('user_id', $id, false, '/', $_SERVER['SERVER_NAME']); setcookie('id_hash', md5($id), false, '/', $_SERVER['SERVER_NAME']); } } else { $return['error'] = true; $return['errorText'] = "You don't have permission to switch users. ({$_SESSION['user_id']})"; } scriptReturn($return); exit;
function set_vars_from_query($q, $vn1 = null, $vn2 = null, $g = null, $g1 = null, $g2 = null) { // get independent data from query // $vn1 is the name of the variable to test // $vn2 is a placeholder // $g is the name of the grouping variable // $g1 and $g2 are the names of the first and second groups $query = new myQuery($q, true); $data = $query->get_array(); if (count($data) == 0) { return false; } // check that named vars do exists, // if not, use first and second columns $var = array_key_exists($vn1, $data[0]) ? $vn1 : 0; $group = array_key_exists($g, $data[0]) ? $g : 1; // delete existing vars and add new data $this->var1 = array(); $this->var2 = array(); foreach ($data as $d) { if ($d[$g] == $g1 && !is_null($d[$vn1])) { $this->var1[] = $d[$vn1]; } else { if ($d[$g] == $g2 && !is_null($d[$vn1])) { $this->var2[] = $d[$vn1]; } } } $this->calculate(); }
// get all authorised projects $q = new myQuery("SELECT project_id FROM project_user WHERE user_id='{$user}'"); $projects = $q->get_col("project_id"); } $dircontents = array(); foreach ($projects as $project_id) { $dir = IMAGEBASEDIR . $project_id; if (!is_dir($dir)) { $return['error'] = true; $return['errorText'] = 'Your user directory does not exist.'; } else { $dircontents = array_merge($dircontents, imageFiles($dir)); } } $proj_list = implode(",", $projects); $q = new myQuery("SELECT id, CONCAT(project_id, name) as path FROM img WHERE project_id IN ({$proj_list})"); $imglist = $q->get_assoc(false, 'id', 'path'); // delete missing images from the DB $deleted_from_db = array(); foreach ($imglist as $id => $name) { $path = IMAGEBASEDIR . $name; if (!is_file($path)) { $q = new myQuery("DELETE FROM img WHERE id='{$id}'"); //$q = new myQuery("DELETE FROM tag WHERE id='$id'"); $deleted_from_db[] = $name; } else { unset($dircontents[$path]); } } $return['deleted'] = $deleted_from_db; // add new images to DB
private function _nextImg() { $exp_path = explode("/", $this->getUserPath()); $project_id = $exp_path[0]; unset($exp_path[0]); $name = "/" . implode("/", $exp_path); // get next id from uploads table $img_query = new myQuery(sprintf("INSERT INTO img (user_id, dt, name, project_id) \n VALUES ('%d', NOW(), '%s', '%s')\n ON DUPLICATE KEY UPDATE\n user_id='%d', dt=NOW()", $_SESSION['user_id'], $name, $project_id, $_SESSION['user_id'])); $this->_id = $img_query->get_insert_id(); return $this->_id; }
public function sym($shape, $colortex, $sym = null) { // $shape and $colortex are transform proportions, usually 0 or 0.5 if (preg_match('/^(\\d{1,11})(\\/.+)(.jpg|.gif|.png)$/', $this->getURL(), $url)) { $project_id = $url[1]; $ext = $url[3]; } else { return false; } // make a mirrored image $clone = clone $this; $mirror = clone $this; $mirror->mirror($sym); $mirrorName = IMAGEBASEDIR . $project_id . '/.tmp/mirror_' . time() . $ext; $cloneName = IMAGEBASEDIR . $project_id . '/.tmp/clone_' . time() . $ext; if ($mirror->save($mirrorName) && $clone->save($cloneName)) { $mirrorURL = str_replace(IMAGEBASEDIR . $project_id, '', $mirrorName); $cloneURL = str_replace(IMAGEBASEDIR . $project_id, '', $cloneName); unset($mirror); unset($clone); } else { return false; } $url = 'http://' . $_SERVER["SERVER_NAME"] . '/tomcat/psychomorph/trans?'; // get this user's default prefs from database $q = new myQuery("SELECT pref, prefval FROM pref WHERE user_id='{$_SESSION['user_id']}'"); $myprefs = $q->get_assoc(false, 'pref', 'prefval'); $theData = array('subfolder' => $project_id, 'savefolder' => '/.tmp/', 'count' => 1, 'shape0' => $shape, 'color0' => $colortex, 'texture0' => $colortex, 'sampleContours0' => $myprefs['sample_contours'], 'transimage0' => $cloneURL, 'fromimage0' => $cloneURL, 'toimage0' => $mirrorURL, 'norm0' => 'none', 'warp0' => $myprefs['warp'], 'normPoint0_0' => 0, 'normPoint1_0' => 1, 'format' => $myprefs['default_imageformat']); $paramsJoined = array(); foreach ($theData as $param => $value) { $paramsJoined[] = "{$param}={$value}"; } $query = implode('&', $paramsJoined); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url . $query); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60); $data = curl_exec($ch); curl_close($ch); // delete the tmp files unlink($cloneName); unlink(preg_replace('@\\.(jpg|png|gif)$@', '.tem', $cloneName)); unlink($mirrorName); unlink(preg_replace('@\\.(jpg|png|gif)$@', '.tem', $mirrorName)); $transdata = json_decode($data, true); $symimg = $project_id . '/.tmp/' . $transdata[0]['img']; $symtem = $project_id . '/.tmp/' . $transdata[0]['tem']; $desc = $this->getImg()->_description; $this->_img = new PsychoMorph_Image($symimg); $this->_tem = new PsychoMorph_Tem($symtem); // describe image $symtype = $shape == 0 ? $colortex == 0 ? 'Un-' : 'Color-only ' : ($colortex == 0 ? 'Shape-only ' : 'Shape & color '); array_push($desc, array('sym' => $symtype)); $this->setDescription($desc); return $this; }
if ($func == 'copy') { $q = new myQuery("INSERT INTO img (user_id, dt, name) VALUES ('{$_SESSION['user_id']}', NOW(), '{$newname}')"); } else { if ($func == 'rename') { $q = new myQuery("UPDATE img SET name='{$newname}' WHERE name='{$oldname}' AND user_id='{$_SESSION['user_id']}'"); } } } else { if ($is_dir) { $olddir = str_replace(IMAGEBASEDIR, '', $source); $newdir = str_replace(IMAGEBASEDIR, '', $destination); if ($func == 'copy') { $q = new myQuery("INSERT INTO img (user_id, dt, name) SELECT '{$_SESSION['user_id']}', NOW(), REPLACE(name, '{$olddir}', '{$newdir}/') FROM img WHERE user_id='{$_SESSION['user_id']}' AND name REGEXP '^{$olddir}[^/]+\$'"); } else { if ($func == 'rename') { $q = new myQuery("UPDATE img SET name = REPLACE(name, '{$olddir}', '{$newdir}/') WHERE user_id='{$_SESSION['user_id']}' AND name REGEXP '^{$olddir}[^/]+\$'"); } } $return['query'] = $q->get_query(); } } } } } } } $return['errorText'] .= '</ol>'; } } scriptReturn($return); exit;
if (trim($vars[0]) == 'averaged') { $return['Description']['type'] = 'average'; $return['Description'] = array_merge($return['Description'], explode(' ', trim($vars[1]))); } else { $return['Description'][trim($vars[0])] = trim($vars[1]); } } else { $return['Description'][] = $d; } } } else { $return['Description'] = str_replace("\n", "<br>", trim($origdesc)); } } if (is_numeric($img['id'])) { $q = new myQuery("SELECT GROUP_CONCAT(tag SEPARATOR '; ') as tags FROM tag WHERE id={$img['id']} GROUP BY id"); if ($q->get_num_rows() > 0) { $return = array_merge(array('Tags' => $q->get_one()), $return); } } // add embedded tem info $tem = str_replace('ASCII', '', $exif['UserComment']); if (!empty($tem)) { $return['Embedded Tem'] = "<pre>" . $tem . "</pre>"; } } elseif (exif_imagetype($filename) == IMAGETYPE_PNG) { $png = new PNG_Reader($filename); $rawTextData = $png->get_chunks('tEXt'); $metadata = array(); foreach ($rawTextData as $data) { $sections = explode("", $data);
$return['error'] = true; $return['errorText'][$db_name] = 'does not exist'; } else { if (!underPath($file)) { $return['error'] = true; $return['errorText'][$db_name] = 'is not in your image path'; } else { if (!rename($file, $destination)) { $return['error'] = true; $return['errorText'][$db_name] = 'could not be deleted'; } else { if ($ext == 'jpg') { // delete database entry if it is an image //$q = new myQuery("SELECT id FROM img WHERE name='{$db_name}'"); //$id = $q->get_one(); $q = new myQuery("DELETE FROM img WHERE name='{$db_name}'"); if ($q->get_affected_rows() != 1) { //$return['error'] = true; $return['errorText'][$db_name] = 'deleted (not from db)'; } else { $return['errorText'][$db_name] = 'deleted'; } //$q = new myQuery("DELETE FROM tag WHERE id='{$id}'"); } } } } } } } }
<?php // set up data to delineate an image require_once $_SERVER['DOCUMENT_ROOT'] . '/include/main_func.php'; auth(); ini_set('max_execution_time', 10); if (array_key_exists('img', $_POST)) { if (is_numeric($_POST['img'])) { // get saved image by id number $q = new myQuery('SELECT name FROM img WHERE id=' . intval($_POST['img'])); $name = '/images' . $q->get_one(); echo $name; exit; } else { $name = my_clean($_POST['img']); } $imgname = str_replace("//", "/", $name); if (substr($imgname, -4) == '.tem') { // find the actual image associated with this tem if only a tem was passed $imgname = preg_replace('@\\.(jpg|png|gif|tem)$@', '.jpg', $imgname); if (!file_exists(IMAGEBASEDIR . $imgname)) { $imgname = preg_replace('@\\.(jpg|png|gif|tem)$@', '.png', $imgname); } else { if (!file_exists(IMAGEBASEDIR . $imgname)) { $imgname = preg_replace('@\\.(jpg|png|gif|tem)$@', '.gif', $imgname); } else { if (!file_exists(IMAGEBASEDIR . $imgname)) { $imgname = preg_replace('@\\.(jpg|png|gif|tem)$@', '.tem', $imgname); } } }