示例#1
0
 function develop()
 {
     $this->autoRender = false;
     $this->layout = false;
     $val = $this->params['named']['a'];
     //        $this->log($this->params, LOG_DEBUG);
     if (strpos($val, 'http://') !== false || substr($val, 0, 1) == '/') {
         header('Location: ' . $val);
         exit;
     } else {
         $val = str_replace(' ', '.2B', $val);
     }
     if (!defined('UPLOAD_DIR')) {
         define('UPLOAD_DIR', 'uploads');
     }
     App::import('Component', 'Salt');
     $salt = new SaltComponent();
     $val = str_replace(' ', '.2B', $val);
     $crypt = $salt->convert($val, false);
     $a = explode(',', $crypt);
     //    $this->log($a, LOG_DEBUG);
     $file = $fn = basename($a[0]);
     // Make sure supplied filename contains only approved chars
     if (preg_match("/[^A-Za-z0-9._-]/", $file)) {
         header('HTTP/1.1 403 Forbidden');
         exit;
     }
     $id = $a[1];
     $w = $this->n($a[2]);
     $h = $this->n($a[3]);
     $q = $this->n($a[4], 100);
     $sq = $this->n($a[5]);
     $sh = $this->n($a[6], 0);
     $x = $this->n($a[7], 50);
     $y = $this->n($a[8], 50);
     $force = $this->n($a[9], 0);
     if ($sq != 1) {
         list($w, $h) = computeSize(PRODUCTIMAGES . DS . $id . DS . $fn, $w, $h, $sq);
         $w = $this->n($w);
         $h = $this->n($h);
     }
     $ext = $this->returnExt($file);
     if (strpos($id, 'avatar') !== false) {
         $bits = explode('-', $id);
         $id = $bits[1];
         define('PATH', PRODUCTIMAGES . DS . 'avatars' . DS . $id);
         $original = PATH . DS . $file;
         $base_dir = PATH;
     } else {
         define('PATH', PRODUCTIMAGES . DS . $id);
         $original = PATH . DS . $file;
         $base_dir = PATH . DS . 'cache';
     }
     if ($sq == 2) {
         $base_dir = PATH;
         $path_to_cache = $original;
     } else {
         $fn .= "_{$w}_{$h}_{$sq}_{$q}_{$sh}_{$x}_{$y}";
         $fn .= ".{$ext}";
         $base_dir = PATH . DS . 'cache';
         $path_to_cache = PATH . DS . 'cache' . DS . $fn;
     }
     // Make sure dirname of the cached copy is sane
     if (dirname($path_to_cache) !== $base_dir) {
         header('HTTP/1.1 403 Forbidden');
         exit;
     }
     $noob = false;
     if (!file_exists($path_to_cache)) {
         $noob = true;
         if ($sq == 2) {
             copy($original, $path_to_cache);
         } else {
             if (!defined('MAGICK_PATH')) {
                 define('MAGICK_PATH_FINAL', 'convert');
             } else {
                 if (strpos(strtolower(MAGICK_PATH), 'c:\\') !== false) {
                     define('MAGICK_PATH_FINAL', '"' . MAGICK_PATH . '"');
                 } else {
                     define('MAGICK_PATH_FINAL', MAGICK_PATH);
                 }
             }
             if (!defined('FORCE_GD')) {
                 define('FORCE_GD', 0);
             }
             if (!is_dir(dirname($path_to_cache))) {
                 $parent_perms = substr(sprintf('%o', fileperms(dirname(dirname($path_to_cache)))), -4);
                 $old = umask(0);
                 mkdir(dirname($path_to_cache), octdec($parent_perms));
                 umask($old);
             }
             App::import('Component', 'Darkroom');
             $d = new DarkroomComponent();
             $d->develop($original, $path_to_cache, $w, $h, $q, $sh, $sq, $x, $y, $force);
         }
     }
     $specs = getimagesize($path_to_cache);
     $mtime = filemtime($path_to_cache);
     $etag = md5($path_to_cache . $mtime);
     if (!$noob) {
         if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag) {
             header("HTTP/1.1 304 Not Modified");
             exit;
         }
         if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= filemtime($path_to_cache)) {
             header("HTTP/1.1 304 Not Modified");
             exit;
         }
     }
     $disabled_functions = explode(',', ini_get('disable_functions'));
     header('Content-type: ' . $specs['mime']);
     header('Content-length: ' . filesize($path_to_cache));
     header('Cache-Control: public');
     header('Expires: ' . gmdate('D, d M Y H:i:s', strtotime('+1 year')));
     header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($path_to_cache)));
     header('ETag: ' . $etag);
     if (is_callable('readfile') && !in_array('readfile', $disabled_functions)) {
         readfile($path_to_cache);
     } else {
         die(file_get_contents($path_to_cache));
     }
 }
示例#2
0
 function user($id, $users, $size = array())
 {
     if (is_null($id)) {
         $id = $users['king'];
     }
     $data = array();
     if (is_array($id)) {
         $user_id = $id['id'];
         $u = $users[$user_id];
         if (isset($id['count'])) {
             $count = $id['count'];
         } else {
             $count = $u['image_count'];
         }
     } else {
         if ($id == 0) {
             return '';
         } else {
             $user_id = $id;
             $u = $users[$user_id];
             $count = $u['image_count'];
         }
     }
     $externals = unserialize($u['externals']);
     $ex_str = '';
     if (!empty($externals)) {
         $data['externals'] = array();
         foreach ($externals as $a) {
             $data['externals'][] = array('name' => $a['name'], 'url' => $a['url']);
         }
     }
     $originals = glob(AVATARS . DS . $user_id . DS . 'original.*');
     $size_str = '';
     if (!empty($size) && count($originals) != 0) {
         $data['photos'] = array();
         foreach ($size as $s) {
             $s = explode(',', $s);
             $data['photos'][$s[0]] = array();
             $arr = unserialize($u['anchor']);
             if (empty($arr)) {
                 $x = $y = 50;
             } else {
                 $x = $arr['x'];
                 $y = $arr['y'];
             }
             list($w, $h) = computeSize($originals[0], $s[1], $s[2], $s[3]);
             $data['photos'][$s[0]]['url'] = __p(array('src' => basename($originals[0]), 'album_id' => "avatar-{$user_id}", 'width' => $s[1], 'height' => $s[2], 'square' => $s[3], 'quality' => $s[4], 'sharpening' => $s[5], 'anchor_x' => $x, 'anchor_y' => $y));
             $data['photos'][$s[0]]['width'] = $w;
             $data['photos'][$s[0]]['height'] = $h;
         }
     }
     $data['id'] = $user_id;
     $data['username'] = $u['usr'];
     $data['first'] = $u['first_name'];
     $data['last'] = $u['last_name'];
     $data['display_name'] = $u['display_name'];
     $data['profile'] = $u['profile'];
     $data['content_count'] = $count;
     return $data;
 }
示例#3
0
function checkForThreeCycle($AdjMatrix, $Neighbors, $n)
{
    /* first check for three cycle */
    $ThreeCycleVertices = array();
    //this keeps track of vertices that together with all its neighbors forms three cycles
    $FourCycleVertices = array();
    /* take one vertex and its neighboring vertices in pairs,
    	if these three vertices share an edge between each other, then there is a three cycle */
    for ($vertex = 0; $vertex < $n; $vertex++) {
        /* i has the first vertex */
        /* check if all neigbors form a complete graph */
        $edgeList = array();
        $numNeighbors = count($Neighbors[$vertex]);
        // print("Start ---\n Showing neighbors first\n");
        // print_r($Neighbors[$vertex]);
        // print("vertex $vertex no. of neighbors: $numNeighbors\n");
        $edgeListSize = computeSize($numNeighbors);
        // print("edge list size: $edgeListSize\n");
        $TotalNumOfEdges = $numNeighbors * ($numNeighbors - 1) / 2;
        // print("total num edges: $TotalNumOfEdges\n");
        if ($TotalNumOfEdges == 1) {
            $n1 = $Neighbors[$vertex][0];
            $n2 = $Neighbors[$vertex][1];
            // print("one edge neighbors: $nbr1 $nbr2\n");
            if ($AdjMatrix[$n1][$n2] == 1) {
                if (!in_array($vertex, $ThreeCycleVertices)) {
                    array_push($ThreeCycleVertices, $vertex);
                }
            } else {
                /* do these neighbors belong to a four cycle? */
                $nbr1ON = array();
                $nbr2ON = array();
                $commonNeigbors = array();
                $nbr1ON = $Neighbors[$n1];
                $nbr2ON = $Neighbors[$n2];
                /* check if any of nbr1's  neighbor is also nbr2's neighbor, apart from vertex */
                for ($j = 0; $j < count($nbr1ON); $j++) {
                    $nbr = $nbr1ON[$j];
                    if (in_array($nbr, $nbr2ON) && $nbr != $vertex) {
                        array_push($commonNeigbors, $nbr);
                    }
                }
                if (count($commonNeigbors) > 0) {
                    /* the neighbors belong to a four cycle */
                    array_push($FourCycleVertices, $vertex);
                }
            }
            //end if-else 3-4 cycle
        } else {
            for ($i = 0; $i < $edgeListSize; $i++) {
                $edgeList[$i] = array();
            }
            $edgeList = getAllTwoCombinationOfOpenNeighbors($edgeListSize);
            // print("edge list\n");
            // print_r($edgeList);
            /* now for each of these two combinations, check if the vertices share an edge */
            for ($i = 0; $i < $edgeListSize; $i++) {
                $nbr1 = $edgeList[$i][0];
                $nbr2 = $edgeList[$i][1];
                $n1 = $Neighbors[$vertex][$nbr1];
                $n2 = $Neighbors[$vertex][$nbr2];
                // print("neighbors: $nbr1 $nbr2\n");
                if ($AdjMatrix[$n1][$n2] == 1) {
                    if (!in_array($vertex, $ThreeCycleVertices)) {
                        array_push($ThreeCycleVertices, $vertex);
                    }
                } else {
                    /* do these neighbors belong to a four cycle? */
                    $nbr1ON = array();
                    $nbr2ON = array();
                    $commonFourNeigbors = array();
                    $nbr1ON = $Neighbors[$n1];
                    $nbr2ON = $Neighbors[$n2];
                    /* check if any of nbr1's  neighbor is also nbr2's neighbor, apart from vertex */
                    for ($j = 0; $j < count($nbr1ON); $j++) {
                        $nbr = $nbr1ON[$j];
                        if (in_array($nbr, $nbr2ON) && $nbr != $vertex) {
                            array_push($commonFourNeigbors, $nbr);
                        }
                    }
                    if (count($commonFourNeigbors) > 0) {
                        /* the neighbors belong to a four cycle */
                        if (!in_array($vertex, $FourCycleVertices)) {
                            array_push($FourCycleVertices, $vertex);
                        }
                    }
                }
                //end if-else 3-4 cycle
            }
            //end for i<edgeListSize
        }
        //end if-else TotalNumOfEdges == 1
    }
    //end for vertex<n
    print "all three cycle vertices\n";
    print_r($ThreeCycleVertices);
    print "all four cycle vertices\n";
    print_r($FourCycleVertices);
    /* combine both the three cycles and fourcycles, remove duplicates, and check if all vertices are present.  If yes, then graph is self-repairing else not self-repairing. */
    $cycleVertices = array();
    $cycleVertices = array_unique(array_merge($ThreeCycleVertices, $FourCycleVertices));
    $checkSum = ($n - 1) * ($n / 2);
    $aSum = array_sum($cycleVertices);
    if ($checkSum == $aSum) {
        return true;
    } else {
        return false;
    }
}