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;
 }
Exemple #2
0
<?php

// get a user's authorised projects
require_once $_SERVER['DOCUMENT_ROOT'] . '/include/main_func.php';
auth();
$user = $_SESSION['user_id'];
$q = new myQuery("SELECT id, project.user_id, name, notes, perm FROM project\n                        LEFT JOIN project_user ON project.id=project_id \n                        WHERE project_user.user_id='{$user}'");
$return['projects'] = $q->get_assoc();
$_SESSION['projects'] = $q->get_one_col('id');
foreach ($return['projects'] as $i => $proj) {
    $q = new myQuery("SELECT user.id, firstname, lastname, email, project_user.perm\n                    FROM project_user \n                    LEFT JOIN user ON user.id=user_id \n                    LEFT JOIN project ON project.id=project_id\n                    WHERE project_id={$proj['id']}\n                    ORDER BY project.user_id!=user.id, lastname, firstname");
    $return['projects'][$i]['owners'] = $q->get_assoc();
}
$q = new myQuery("SELECT id, firstname, lastname, email FROM user");
$return['users'] = $q->get_by_id('id');
function countFilesOO($dir)
{
    if (!is_dir($dir)) {
        return false;
    }
    /*
    $Directory=new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS);
    $Iterator = new RecursiveIteratorIterator($Directory);
    $TrashRegex = new RegexIterator($Iterator, '/\/\.trash\//', RecursiveRegexIterator::GET_MATCH);
    $trash = iterator_count($TrashRegex);
    $TmpRegex = new RegexIterator($Iterator, '/\/\.tmp\//', RecursiveRegexIterator::GET_MATCH);
    $tmp = iterator_count($TmpRegex);
    $files = iterator_count($Iterator);
    //foreach ($Iterator as $filename=>$cur) {
    //    $size += $cur->getSize();
    //}
Exemple #3
0
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();
}
Exemple #4
0
<?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 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;
 }
Exemple #6
0
// get default values for a tem in the database
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),
Exemple #7
0
    $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
$added_to_db = array();
Exemple #8
0
 function set_options($opts, $start = null, $end = null)
 {
     $cquery = new myQuery('SELECT id, country FROM countries ORDER BY IF(country="none", "ZZZZZ", country)');
     $countries = $cquery->get_assoc(false, 'id', 'country');
     if (empty($opts)) {
         $this->options = $countries;
     } else {
         $this->options = array($opts, $countries);
     }
 }
Exemple #9
0
function imgEdit($edit, $data, $img)
{
    global $default_rgb;
    switch ($edit) {
        case 'align':
            if (!$img->getTem()) {
                return false;
            } else {
                if (preg_match('/^(\\d{1,3}),(\\d{1,3}),(\\d{1,4}(?:\\.\\d+)?),(\\d{1,4}(?:\\.\\d+)?),(\\d{1,4}(?:\\.\\d+)?),(\\d{1,4}(?:\\.\\d+)?),(\\d{1,5}),(\\d{1,5})(?:,rgb\\((\\d{1,3},\\d{1,3},\\d{1,3})\\))?$/i', $data, $align)) {
                    $align_pt1 = intval($align[1]);
                    $align_pt2 = intval($align[2]);
                    $aligned_x1 = $align[3];
                    $aligned_y1 = $align[4];
                    $aligned_x2 = $align[5];
                    $aligned_y2 = $align[6];
                    $align_width = $align[7];
                    $align_height = $align[8];
                    if (count($align) == 10) {
                        $rgb = explode(",", $align[9]);
                    } else {
                        $rgb = $default_rgb;
                    }
                } else {
                    if (preg_match('/^default$/i', $data)) {
                        $q = new myQuery("SELECT pref, prefval FROM pref WHERE user_id='{$_SESSION['user_id']}'");
                        $myprefs = $q->get_assoc(false, 'pref', 'prefval');
                        $align_pt1 = $myprefs['align_pt1'];
                        $align_pt2 = $myprefs['align_pt2'];
                        $aligned_x1 = $myprefs['align_x1'];
                        $aligned_y1 = $myprefs['align_y1'];
                        $aligned_x2 = $myprefs['align_x2'];
                        $aligned_y2 = $myprefs['align_y2'];
                        $align_width = $myprefs['align_w'];
                        $align_height = $myprefs['align_h'];
                        $rgb = $default_rgb;
                    } else {
                        if (preg_match('/^frl$/i', $data)) {
                            $align_pt1 = 0;
                            $align_pt2 = 1;
                            $aligned_x1 = 496.98;
                            $aligned_y1 = 825.688;
                            $aligned_x2 = 853.02;
                            $aligned_y2 = 825.688;
                            $align_width = 1350;
                            $align_height = 1800;
                            $rgb = $default_rgb;
                        } else {
                            return false;
                        }
                    }
                }
            }
            $img->alignEyes($align_width, $align_height, array($aligned_x1, $aligned_y1), array($aligned_x2, $aligned_y2), $align_pt1, $align_pt2, $rgb);
            return true;
        case 'resize':
            $resize = explode(',', $data);
            // if only 1 value, must be a %
            if (count($resize) == 1 && preg_match('/^(\\d+(?:\\.\\d+)?)\\%$/', $resize[0], $resize1)) {
                $scale = $resize1[1] / 100;
                $img->resize($scale, $scale);
                return $scale . '%';
            } else {
                if (count($resize) == 2) {
                    // if 1st value is null, second must be % or px (keep aspect ratio)
                    if ($resize[0] == 'null') {
                        if (preg_match('/^(\\d+(?:\\.\\d+)?)(\\%|px)$/i', $resize[1], $resize2)) {
                            if ($resize2[2] == '%') {
                                $scale = $resize2[1] / 100;
                                $img->resize($scale, $scale);
                                return $scale . '%';
                            } else {
                                if ($resize2[2] == 'px') {
                                    $h = $img->getHeight();
                                    $scale = $resize2[1] / $h;
                                    $img->resize($scale, $scale);
                                    return $scale . '%';
                                }
                            }
                        }
                        // if 2nd value is null, second must be % or px (keep aspect ratio)
                    } else {
                        if ($resize[1] == 'null') {
                            if (preg_match('/^(\\d+(?:\\.\\d+)?)(\\%|px)$/i', $resize[0], $resize1)) {
                                if ($resize1[2] == '%') {
                                    $scale = $resize1[1] / 100;
                                    $img->resize($scale, $scale);
                                    return $scale . '%';
                                } else {
                                    if ($resize1[2] == 'px') {
                                        $w = $img->getWidth();
                                        $scale = $resize1[1] / $w;
                                        $img->resize($scale, $scale);
                                        return $scale . '%';
                                    }
                                }
                            }
                            // if neither value is null, must be same vale type (% or px)
                        } else {
                            if (preg_match('/^(\\d+(?:\\.\\d+)?)(\\%|px)$/i', $resize[0], $resize1) && preg_match('/^(\\d+(?:\\.\\d+)?)(\\%|px)$/i', $resize[1], $resize2) && $resize1[2] == $resize2[2]) {
                                if ($resize1[2] == '%') {
                                    $xResize = $resize1[1] / 100;
                                    $yResize = $resize2[1] / 100;
                                    $img->resize($xResize, $yResize);
                                    return $xResize . '%, ' . $yResize . '%';
                                } else {
                                    if ($resize1[2] == 'px') {
                                        $w = $img->getWidth();
                                        $h = $img->getHeight();
                                        $xResize = $resize1[1] / $w;
                                        $yResize = $resize2[1] / $h;
                                        $img->resize($xResize, $yResize);
                                        return $xResize . 'px, ' . $yResize . 'px';
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return false;
        case 'rotate':
            if (preg_match('/^(-?\\d{1,3}(?:\\.\\d+)?)(?:,rgb\\((\\d{1,3},\\d{1,3},\\d{1,3})\\))?$/i', $data, $rotate)) {
                if (count($rotate) == 3) {
                    $rgb = explode(",", $rotate[2]);
                } else {
                    $rgb = $default_rgb;
                }
                $img->rotate($rotate[1], $rgb);
                return true;
            }
            return false;
        case 'crop':
            if (preg_match('/^(-?\\d+),(-?\\d+),(-?\\d+),(-?\\d+)(?:,rgb\\((\\d{1,3},\\d{1,3},\\d{1,3})\\))?$/i', $data, $crop)) {
                if (count($crop) == 6) {
                    $rgb = explode(",", $crop[5]);
                } else {
                    $rgb = $default_rgb;
                }
                $orig_w = $img->getImg()->getWidth();
                $orig_h = $img->getImg()->getHeight();
                $w = $orig_w + $crop[4] + $crop[2];
                $h = $orig_h + $crop[1] + $crop[3];
                $x = -1 * $crop[4];
                $y = -1 * $crop[1];
                $img->crop($x, $y, $w, $h, $rgb);
                return $crop;
            }
            return false;
        case 'mask':
            if (preg_match('/^\\(([^\\(\\)]+)\\),(\\d{1,2})(?:,(?:(transparent)|rgb\\((\\d{1,3},\\d{1,3},\\d{1,3})\\)))?$/i', $data, $mask)) {
                if (count($mask) == 5) {
                    $rgba = explode(",", $mask[4]);
                    array_push($rgba, 1);
                } else {
                    if (count($mask) == 4) {
                        $rgba = array(1, 244, 1, 0);
                    } else {
                        $rgba = $default_rgb;
                        array_push($rgba, 1);
                    }
                }
                $blur = $mask[2];
                $custom = null;
                if (preg_match('/^(?:[a-z_]+,)*[a-z_]+$/i', $mask[1])) {
                    $masks = explode(',', $mask[1]);
                    $possible_masks = array("oval", "face", "neck", "ears", "eyes", "brows", "left_ear", "right_ear", "left_eye", "right_eye", "left_brow", "right_brow", "mouth", "teeth", "nose");
                    foreach ($masks as $i => $m) {
                        if (!in_array($m, $possible_masks)) {
                            return false;
                        } else {
                            if ($m == 'ears') {
                                $masks[$i] = 'left_ear';
                                $masks[] = 'right_ear';
                            } else {
                                if ($m == 'eyes') {
                                    $masks[$i] = 'left_eye';
                                    $masks[] = 'right_eye';
                                } else {
                                    if ($m == 'brows') {
                                        $masks[$i] = 'left_brow';
                                        $masks[] = 'right_brow';
                                    }
                                }
                            }
                        }
                    }
                } else {
                    if (preg_match('/^(((\\d+,)*\\d+;)*(\\d+,)*\\d+:)*((\\d+,)*\\d+;)*(\\d+,)*\\d+$/', $mask[1])) {
                        $custom = explode(':', $mask[1]);
                        $masks = array('custom');
                        foreach ($custom as $j => $m) {
                            $custom[$j] = explode(';', $m);
                            foreach ($custom[$j] as $i => $m2) {
                                $custom[$j][$i] = explode(',', $m2);
                            }
                        }
                    } else {
                        return false;
                    }
                }
                ini_set('max_execution_time', 30 * ($blur + 1));
                $img->mask($masks, $rgba, $blur, $custom);
                return true;
            }
            return false;
        case 'sym':
            if ($img->getTem() && preg_match('/^(shape|color|colour)(?:,(shape|color|colour))?$/i', $data)) {
                $symtypes = explode(',', $data);
                $shape = in_array('shape', $symtypes) ? 0.5 : 0;
                $colortex = in_array('color', $symtypes) || in_array('colour', $symtypes) ? 0.5 : 0;
                $img->sym($shape, $colortex);
                return true;
            }
            return false;
        case 'mirror':
            if (preg_match('/^(true|t|1)$/i', $data)) {
                $img->mirror();
                return true;
            }
            return false;
    }
}
Exemple #10
0
echo '<tr><td>Query</td><td>' . $q->get_query() . '</td><td>SELECT id, firstname FROM user LIMIT 3</td></tr>';
echo '<tr><td>N Rows</td><td>' . $q->get_num_rows() . '</td><td>3</td></tr>';
echo '<tr><td>get_row()</td><td>';
print_r($q->get_row());
echo '</td><td>Array ( [id] => 1 [firstname] => Lisa )</td></tr>';
echo '<tr><td>get_row(2)</td><td>';
print_r($q->get_row(2));
echo '</td><td>Array ( [id] => 3 [firstname] => Amanda )</td></tr>';
echo '<tr><td>get_col("id")</td><td>';
print_r($q->get_col('id'));
echo '</td><td>Array ( [0] => 1 [1] => 2 [2] => 3 )</td></tr>';
echo '<tr><td>get_one()</td><td>' . $q->get_one() . '</td><td>1</td></tr>';
echo '<tr><td>get_one(2, "firstname")</td><td>' . $q->get_one(2, 'firstname') . '</td><td>Amanda</td></tr>';
echo '<tr><td>get_one(2, "error")</td><td>' . $q->get_one(2, 'error') . '</td><td>Column <code>error</code> does not exist in row <code>2</code></td></tr>';
echo '<tr><td>get_assoc()</td><td>';
print_r($q->get_assoc());
echo '</td><td>Array ( [0] => Array ( [id] => 1 [firstname] => Lisa ) [1] => Array ( [id] => 2 [firstname] => Ben ) [2] => Array ( [id] => 3 [firstname] => Amanda ) )</td></tr>';
echo '<tr><td>get_result_as_table()</td><td>' . $q->get_result_as_table() . '</td><td>
<table class="query">
<thead><tr>	<th>id</th><th>firstname</th></tr></thead><tbody>
<tr><td>1</td> <td>Lisa</td></tr>
<tr><td>2</td><td>Ben</td></tr>
<tr><td>3</td><td>Amanda</td></tr>
</tbody></table></td></tr>';
echo '<tr><td>prepare()</td><td>';
$query = "SELECT id, email FROM user WHERE firstname!=? AND lastname!=?";
$params = array("ss", "Lisa", "DeBruine");
$return = array("id", "email");
$data = $q->prepare($query, $params, $return);
echo "{$data['id']}: {$data['email']}";
echo '</td><td>1: lisa.debruine@glasgow.ac.uk</td></tr>';
Exemple #11
0
<?php

// get a list of users
require_once $_SERVER['DOCUMENT_ROOT'] . '/include/main_func.php';
auth();
$return = array('error' => false, 'errorText' => '');
if ($_SESSION['user_id'] == '1') {
    $q = new myQuery("SELECT id, CONCAT(lastname, ', ', firstname, ' (', email, ')') as name FROM user ORDER BY name");
    $return['users'] = $q->get_assoc();
} else {
    $return['error'] = true;
    $return['errorText'] = "You don't have permission to list users.";
}
scriptReturn($return);
exit;