Пример #1
0
function cpgUserLastComment($uid)
{
    global $CONFIG, $FORBIDDEN_SET;
    $result = cpg_db_query("SELECT COUNT(*), MAX(msg_id) FROM {$CONFIG['TABLE_COMMENTS']} AS c INNER JOIN {$CONFIG['TABLE_PICTURES']} AS p ON p.pid = c.pid WHERE approval = 'YES' AND author_id = '{$uid}' {$FORBIDDEN_SET}");
    list($comment_count, $lastcom_id) = mysql_fetch_row($result);
    mysql_free_result($result);
    $lastComArray = array('count' => 0);
    if ($comment_count) {
        $sql = "SELECT filepath, filename, url_prefix, pwidth, pheight, msg_author, UNIX_TIMESTAMP(msg_date) as msg_date, msg_body FROM {$CONFIG['TABLE_COMMENTS']} AS c INNER JOIN {$CONFIG['TABLE_PICTURES']} AS p ON p.pid = c.pid WHERE msg_id = {$lastcom_id}";
        $result = cpg_db_query($sql);
        if (mysql_num_rows($result)) {
            $row = mysql_fetch_assoc($result);
            $pic_url = get_pic_url($row, 'thumb');
            if (!is_image($row['filename'])) {
                $image_info = cpg_getimagesize(urldecode($pic_url));
                $row['pwidth'] = $image_info[0];
                $row['pheight'] = $image_info[1];
            }
            $image_size = compute_img_size($row['pwidth'], $row['pheight'], $CONFIG['thumb_width']);
            $lastcom = '<img src="' . $pic_url . '" class="image"' . $image_size['geom'] . ' border="0" alt="" />';
            $lastComArray = array('thumb' => $lastcom, 'comment' => $row['msg_body'], 'msg_date' => $row['msg_date'], 'count' => $comment_count);
        }
        mysql_free_result($result);
    }
    return $lastComArray;
}
function exif_parse_file($filename, $pid)
{
    global $CONFIG, $lang_picinfo;
    if (!is_readable($filename)) {
        return false;
    }
    $size = cpg_getimagesize($filename);
    if ($size[2] != 2) {
        return false;
        // Not a JPEG file
    }
    //String containing all the available exif tags.
    $exif_info = "AFFocusPosition|Adapter|ColorMode|ColorSpace|ComponentsConfiguration|CompressedBitsPerPixel|Contrast|CustomerRender|DateTimeOriginal|DateTimedigitized|DigitalZoom|DigitalZoomRatio|ExifImageHeight|ExifImageWidth|ExifInteroperabilityOffset|ExifOffset|ExifVersion|ExposureBiasValue|ExposureMode|ExposureProgram|ExposureTime|FNumber|FileSource|Flash|FlashPixVersion|FlashSetting|FocalLength|FocusMode|GainControl|IFD1Offset|ISOSelection|ISOSetting|ISOSpeedRatings|ImageAdjustment|ImageDescription|ImageSharpening|LightSource|Make|ManualFocusDistance|MaxApertureValue|MeteringMode|Model|NoiseReduction|Orientation|Quality|ResolutionUnit|Saturation|SceneCaptureMode|SceneType|Sharpness|Software|WhiteBalance|YCbCrPositioning|xResolution|yResolution";
    $exif_names = explode("|", $exif_info);
    //Check if we have the data of the said file in the table
    $result = cpg_db_query("SELECT exifData FROM {$CONFIG['TABLE_EXIF']} WHERE pid = {$pid}");
    if (mysql_num_rows($result) > 0) {
        $row = mysql_fetch_assoc($result);
        mysql_free_result($result);
        $exif = unserialize($row['exifData']);
        // Convert old EXIF data style to new one
        if (array_key_exists('Errors', $exif)) {
            $exif = cpg_exif_strip_data($exif, $exif_names);
            cpg_db_query("UPDATE {$CONFIG['TABLE_EXIF']} SET exifData = '" . addslashes(serialize($exif)) . "' WHERE pid = '{$pid}'");
        }
    } else {
        // No data in the table - read it from the image file
        $exifRawData = read_exif_data_raw($filename, 0);
        $exif = cpg_exif_strip_data($exifRawData, $exif_names);
        // Insert it into table for future reference
        cpg_db_query("INSERT INTO {$CONFIG['TABLE_EXIF']} (pid, exifData) VALUES ({$pid}, '" . addslashes(serialize($exif)) . "')");
    }
    $exifParsed = array();
    $exifCurrentData = array_keys(array_filter(explode("|", $CONFIG['show_which_exif'])));
    foreach ($exifCurrentData as $i) {
        $name = $exif_names[$i];
        if (isset($exif[$name])) {
            $exifParsed[$lang_picinfo[$name]] = $exif[$name];
        }
    }
    ksort($exifParsed);
    return $exifParsed;
}
 function imageObject($directory, $filename, $previous = null)
 {
     $this->directory = $directory;
     $this->filename = $filename;
     $this->previous = $previous;
     $this->truecolor = true;
     if (file_exists($directory . $filename)) {
         $this->filesize = round(filesize($directory . $filename) / 1000);
         if ($this->filesize > 0) {
             $size = cpg_getimagesize($directory . $filename);
             // For IM we don't need an Image Resource (work directly on file :)
             if ($size && !$this->imgRes) {
                 $this->imgRes = true;
             }
             $this->width = $size[0];
             $this->height = $size[1];
             $this->string = $size[3];
         }
     }
 }
 function imageObject($directory, $filename, $previous = null)
 {
     $this->directory = $directory;
     $this->filename = $filename;
     $this->previous = $previous;
     $this->imgRes = $previous->imgRes;
     if (file_exists($directory . $filename)) {
         $this->filesize = round(filesize($directory . $filename) / 1000);
         if ($this->filesize > 0) {
             $size = cpg_getimagesize($directory . $filename);
             if ($size && !$this->imgRes) {
                 $this->imgRes = $this->getimgRes($directory . $filename, $size[2]);
             }
             if (function_exists('imagecreatetruecolor')) {
                 $this->truecolor = true;
             }
             $this->width = $size[0];
             $this->height = $size[1];
             $this->string = $size[3];
         }
     }
 }
Пример #5
0
function theme_html_picture()
{
    global $CONFIG, $CURRENT_PIC_DATA, $CURRENT_ALBUM_DATA, $USER, $LINEBREAK;
    global $album, $lang_date, $template_display_media;
    global $lang_display_image_php, $lang_picinfo, $lang_common, $lang_errors;
    $superCage = Inspekt::makeSuperCage();
    $pid = $CURRENT_PIC_DATA['pid'];
    $pic_title = '';
    if (!isset($USER['liv']) || !is_array($USER['liv'])) {
        $USER['liv'] = array();
    }
    // Add 1 to hit counter
    if ((!USER_IS_ADMIN && $CONFIG['count_admin_hits'] == 0 || $CONFIG['count_admin_hits'] == 1) && !in_array($pid, $USER['liv']) && $superCage->cookie->keyExists($CONFIG['cookie_name'] . '_data')) {
        add_hit($pid);
        if (count($USER['liv']) > 4) {
            array_shift($USER['liv']);
        }
        array_push($USER['liv'], $pid);
    }
    if ($CURRENT_PIC_DATA['title'] != '') {
        $pic_title .= $CURRENT_PIC_DATA['title'] . $LINEBREAK;
    }
    if ($CURRENT_PIC_DATA['caption'] != '') {
        $pic_title .= $CURRENT_PIC_DATA['caption'] . $LINEBREAK;
    }
    if ($CURRENT_PIC_DATA['keywords'] != '') {
        $pic_title .= $lang_common['keywords'] . ": " . $CURRENT_PIC_DATA['keywords'];
    }
    if (!$CURRENT_PIC_DATA['title'] && !$CURRENT_PIC_DATA['caption']) {
        template_extract_block($template_display_media, 'img_desc');
    } else {
        if (!$CURRENT_PIC_DATA['title']) {
            template_extract_block($template_display_media, 'title');
        }
        if (!$CURRENT_PIC_DATA['caption']) {
            template_extract_block($template_display_media, 'caption');
        }
    }
    $CURRENT_PIC_DATA['menu'] = html_picture_menu();
    //((USER_ADMIN_MODE && $CURRENT_ALBUM_DATA['category'] == FIRST_USER_CAT + USER_ID) || ($CONFIG['users_can_edit_pics'] && $CURRENT_PIC_DATA['owner_id'] == USER_ID && USER_ID != 0) || GALLERY_ADMIN_MODE) ? html_picture_menu($pid) : '';
    $image_size = array();
    if ($CONFIG['make_intermediate'] && cpg_picture_dimension_exceeds_intermediate_limit($CURRENT_PIC_DATA['pwidth'], $CURRENT_PIC_DATA['pheight'])) {
        $picture_url = get_pic_url($CURRENT_PIC_DATA, 'normal');
    } else {
        $picture_url = get_pic_url($CURRENT_PIC_DATA, 'fullsize');
    }
    $pic_title = '';
    $mime_content = cpg_get_type($CURRENT_PIC_DATA['filename']);
    if ($mime_content['content'] == 'movie' || $mime_content['content'] == 'audio') {
        if ($CURRENT_PIC_DATA['pwidth'] == 0 || $CURRENT_PIC_DATA['pheight'] == 0) {
            $resize_method = $CONFIG['picture_use'] == "thumb" ? $CONFIG['thumb_use'] == "ex" ? "any" : $CONFIG['thumb_use'] : $CONFIG['picture_use'];
            if ($resize_method == 'ht') {
                $pwidth = $CONFIG['picture_width'] * 4 / 3;
                $pheight = $CONFIG['picture_width'];
            } else {
                $pwidth = $CONFIG['picture_width'];
                $pheight = $CONFIG['picture_width'] * 3 / 4;
            }
            $CURRENT_PIC_DATA['pwidth'] = $pwidth;
            // Default width
            // Set default height; if file is a movie
            if ($mime_content['content'] == 'movie') {
                $CURRENT_PIC_DATA['pheight'] = $pheight;
                // Default height
            }
        }
        $ctrl_offset['mov'] = 15;
        $ctrl_offset['wmv'] = 45;
        $ctrl_offset['swf'] = 0;
        $ctrl_offset['rm'] = 0;
        $ctrl_offset_default = 45;
        $ctrl_height = isset($ctrl_offset[$mime_content['extension']]) ? $ctrl_offset[$mime_content['extension']] : $ctrl_offset_default;
        $image_size['whole'] = 'width="' . $CURRENT_PIC_DATA['pwidth'] . '" height="' . ($CURRENT_PIC_DATA['pheight'] + $ctrl_height) . '"';
    }
    if ($mime_content['content'] == 'image') {
        list($image_size['width'], $image_size['height'], , $image_size['geom']) = cpg_getimagesize(urldecode($picture_url));
        if ($CURRENT_PIC_DATA['mode'] != 'fullsize') {
            $winsizeX = $CURRENT_PIC_DATA['pwidth'] + $CONFIG['fullsize_padding_x'];
            //the +'s are the mysterious FF and IE paddings
            $winsizeY = $CURRENT_PIC_DATA['pheight'] + $CONFIG['fullsize_padding_y'];
            //the +'s are the mysterious FF and IE paddings
            if ($CONFIG['transparent_overlay'] == 1) {
                $pic_html = "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td background=\"" . $picture_url . "\" width=\"{$image_size['width']}\" height=\"{$image_size['height']}\" class=\"image\">";
                $pic_html_href_close = '</a>' . $LINEBREAK;
                if (!USER_ID && $CONFIG['allow_unlogged_access'] <= 2) {
                    if ($CONFIG['allow_user_registration'] == 0) {
                        $pic_html_href_close = '';
                    } else {
                        $pic_html .= '<a href="javascript:;" onclick="alert(\'' . sprintf($lang_errors['login_needed'], '', '', '', '') . '\');">';
                    }
                } elseif (USER_ID && USER_ACCESS_LEVEL <= 2) {
                    $pic_html .= '<a href="javascript:;" onclick="alert(\'' . sprintf($lang_errors['access_intermediate_only'], '', '', '', '') . '\');">';
                } else {
                    $pic_html .= "<a href=\"javascript:;\" onclick=\"MM_openBrWindow('displayimage.php?pid={$pid}&amp;fullsize=1','" . uniqid(rand()) . "','scrollbars=yes,toolbar=no,status=no,resizable=yes,width={$winsizeX},height={$winsizeY}')\">";
                }
                $pic_title = $lang_display_image_php['view_fs'] . $LINEBREAK . '==============' . $LINEBREAK . $pic_title;
                $pic_html .= "<img src=\"images/image.gif?id=" . floor(rand() * 1000 + rand()) . "\" width=\"{$image_size['width']}\" height=\"{$image_size['height']}\"  border=\"0\" alt=\"{$lang_display_image_php['view_fs']}\" /><br />";
                $pic_html .= $pic_html_href_close . '</td></tr></table>';
                //PLUGIN FILTER
                $pic_html = CPGPluginAPI::filter('html_image_reduced_overlay', $pic_html);
            } else {
                $pic_html_href_close = '</a>' . $LINEBREAK;
                if (!USER_ID && $CONFIG['allow_unlogged_access'] <= 2) {
                    if ($CONFIG['allow_user_registration'] == 0) {
                        $pic_html = $pic_html_href_close = '';
                    } else {
                        $pic_html = '<a href="javascript:;" onclick="alert(\'' . sprintf($lang_errors['login_needed'], '', '', '', '') . '\');">';
                    }
                } elseif (USER_ID && USER_ACCESS_LEVEL <= 2) {
                    $pic_html = '<a href="javascript:;" onclick="alert(\'' . sprintf($lang_errors['access_intermediate_only'], '', '', '', '') . '\');">';
                } else {
                    $pic_html = "<a href=\"javascript:;\" onclick=\"MM_openBrWindow('displayimage.php?pid={$pid}&amp;fullsize=1','" . uniqid(rand()) . "','scrollbars=yes,toolbar=no,status=no,resizable=yes,width={$winsizeX},height={$winsizeY}')\">";
                }
                $pic_title = $lang_display_image_php['view_fs'] . $LINEBREAK . '==============' . $LINEBREAK . $pic_title;
                $pic_html .= "<img src=\"" . $picture_url . "\" {$image_size['geom']} class=\"image\" border=\"0\" alt=\"{$lang_display_image_php['view_fs']}\" /><br />";
                $pic_html .= $pic_html_href_close;
                //PLUGIN FILTER
                $pic_html = CPGPluginAPI::filter('html_image_reduced', $pic_html);
            }
        } else {
            if ($CONFIG['transparent_overlay'] == 1) {
                $pic_html = "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td background=\"" . $picture_url . "\" width=\"{$CURRENT_PIC_DATA['pwidth']}\" height=\"{$CURRENT_PIC_DATA['pheight']}\" class=\"image\">";
                $pic_html .= "<img src=\"images/image.gif?id=" . floor(rand() * 1000 + rand()) . "\" width={$CURRENT_PIC_DATA['pwidth']} height={$CURRENT_PIC_DATA['pheight']} border=\"0\" alt=\"\" /><br />" . $LINEBREAK;
                $pic_html .= "</td></tr></table>";
                //PLUGIN FILTER
                $pic_html = CPGPluginAPI::filter('html_image_overlay', $pic_html);
            } else {
                $pic_html = "<img src=\"" . $picture_url . "\" {$image_size['geom']} class=\"image\" border=\"0\" alt=\"\" /><br />" . $LINEBREAK;
                //PLUGIN FILTER
                $pic_html = CPGPluginAPI::filter('html_image', $pic_html);
            }
        }
    } elseif ($mime_content['content'] == 'document') {
        $pic_thumb_url = get_pic_url($CURRENT_PIC_DATA, 'thumb');
        $pic_html = "<a href=\"{$picture_url}\" target=\"_blank\" class=\"document_link\"><img src=\"" . $pic_thumb_url . "\" border=\"0\" class=\"image\" /></a><br />" . $LINEBREAK;
        //PLUGIN FILTER
        $pic_html = CPGPluginAPI::filter('html_document', $pic_html);
    } else {
        $autostart = $CONFIG['media_autostart'] ? 'true' : 'false';
        if ($mime_content['player'] == 'HTMLA') {
            $pic_html = '<audio controls="true" src="' . $picture_url . '" autostart="' . $autostart . '"></audio>';
        } elseif ($mime_content['player'] == 'HTMLV') {
            $pic_html = '<video controls="true" src="' . $picture_url . '" autostart="' . $autostart . '"' . $image_size['whole'] . '></video>';
        } else {
            $players['WMP'] = array('id' => 'MediaPlayer', 'clsid' => '', 'codebase' => 'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" ', 'mime' => 'type="application/x-mplayer2" ');
            $players['DIVX'] = array('id' => 'DivX', 'clsid' => 'classid="clsid:67DABFBF-D0AB-41fa-9C46-CC0F21721616"', 'codebase' => 'codebase="http://go.divx.com/plugin/DivXBrowserPlugin.cab"', 'mime' => 'type="video/divx"');
            $players['RMP'] = array('id' => 'RealPlayer', 'clsid' => 'classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" ', 'codebase' => '', 'mime' => 'type="audio/x-pn-realaudio-plugin" ');
            $players['QT'] = array('id' => 'QuickTime', 'clsid' => 'classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" ', 'codebase' => 'codebase="http://www.apple.com/qtactivex/qtplugin.cab" ', 'mime' => 'type="video/x-quicktime" ');
            $players['SWF'] = array('id' => 'SWFlash', 'clsid' => '', 'codebase' => '', 'mime' => 'type="application/x-shockwave-flash" ', 'data' => 'data="' . $picture_url . '" ');
            $players['UNK'] = array('id' => 'DefaultPlayer', 'clsid' => '', 'codebase' => '', 'mime' => '');
            $player = $players[$mime_content['player']];
            if (!$player) {
                $player = 'UNK';
            }
            $pic_html = '<object id="' . $player['id'] . '" ' . $player['data'] . $player['clsid'] . $player['codebase'] . $player['mime'] . $image_size['whole'] . '>';
            $pic_html .= "<param name=\"autostart\" value=\"{$autostart}\" /><param name=\"src\" value=\"" . $picture_url . "\" />";
            $pic_html .= '</object><br />' . $LINEBREAK;
        }
        //PLUGIN FILTER
        $pic_html = CPGPluginAPI::filter('html_other_media', $pic_html);
    }
    $CURRENT_PIC_DATA['html'] = $pic_html;
    $CURRENT_PIC_DATA['header'] = '';
    $CURRENT_PIC_DATA['footer'] = '';
    $CURRENT_PIC_DATA = CPGPluginAPI::filter('file_data', $CURRENT_PIC_DATA);
    $params = array('{CELL_HEIGHT}' => '100', '{IMAGE}' => $CURRENT_PIC_DATA['header'] . $CURRENT_PIC_DATA['html'] . $CURRENT_PIC_DATA['footer'], '{ADMIN_MENU}' => $CURRENT_PIC_DATA['menu'], '{TITLE}' => bb_decode($CURRENT_PIC_DATA['title']), '{CAPTION}' => bb_decode($CURRENT_PIC_DATA['caption']));
    return template_eval($template_display_media, $params);
}
Пример #6
0
/**
 * picrow()
 *
 * return the HTML code for a row to be displayed for an image
 * the row contains a checkbox, the image name, a thumbnail
 *
 * @param  $picfile the full path of the file that contains the picture
 * @param  $picid the name of the check box
 * @return the HTML code
 */
function picrow($picfile, $picid, $albid)
{
    global $CONFIG, $expic_array, $picrowCounter;
    $encoded_picfile = urlencode(base64_encode($picfile));
    $picname = $CONFIG['fullpath'] . $picfile;
    $pic_url = urlencode($picfile);
    $pic_fname = basename($picfile);
    $pic_dirname = dirname($picname);
    $thumb_file = dirname($picname) . '/' . $CONFIG['thumb_pfx'] . $pic_fname;
    if ($CONFIG['display_thumbs_batch_add'] == 1) {
        if (file_exists($thumb_file)) {
            $thumb_info = cpg_getimagesize($picname);
            $thumb_size = compute_img_size($thumb_info[0], $thumb_info[1], 48);
            $img = '<img src="' . path2url($thumb_file) . '" ' . $thumb_size['geom'] . ' class="thumbnail" border="0" alt="" />';
        } elseif (is_image($picname)) {
            $img = '<img src="showthumb.php?picfile=' . $pic_url . '&amp;size=48" class="thumbnail" border="0" alt="" />';
        } else {
            $file['filepath'] = $pic_dirname . '/';
            $file['filename'] = $pic_fname;
            $filepathname = get_pic_url($file, 'thumb');
            $img = '<img src="' . $filepathname . '" class="thumbnail" width="48" border="0" alt="" />';
        }
    } else {
        $img = '';
    }
    if (filesize($picname) && is_readable($picname)) {
        // for video support, maybe check: http://www.getid3.org/
        // for now, hack in something that works (don't check !$fullimagesize)
        $fullimagesize = cpg_getimagesize($picname);
        $winsizeX = $fullimagesize[0] + 16;
        $winsizeY = $fullimagesize[1] + 16;
        // $checked = isset($expic_array[$picfile]) || !$fullimagesize ? '' : 'checked';
        $picfile_replaced_forbidden = dirname($picfile) . '/' . replace_forbidden(basename($picfile));
        if ($CONFIG['batch_add_hide_existing_files'] && isset($expic_array[$picfile_replaced_forbidden])) {
            return;
        }
        if ($picrowCounter++ % 2) {
            $rowStyle = 'tableb';
        } else {
            $rowStyle = 'tableb tableb_alternate';
        }
        $checked = isset($expic_array[$picfile_replaced_forbidden]) || !is_known_filetype($pic_fname) ? '' : 'checked="checked"';
        $return = <<<EOT
        <tr>
                <td class="{$rowStyle}" valign="middle" width="30">
                        <input name="pics[]" id="checkbox_p_{$picid}" type="checkbox" value="{$picid}" {$checked} />
                        <input name="album_lb_id_{$picid}" type="hidden" value="{$albid}" />
                        <input name="picfile_{$picid}" type="hidden" value="{$encoded_picfile}" />
                </td>
EOT;
        // if $fullimagesize is not null, then assume it's an image
        if ($fullimagesize) {
            $return .= <<<EOT
                <td class="{$rowStyle}" valign="middle">
                        <a href="javascript:;" onclick= "MM_openBrWindow('displayimage.php?fullsize=1&amp;picfile={$pic_url}', 'ImageViewer', 'toolbar=yes, status=yes, resizable=yes, width={$winsizeX}, height={$winsizeY}')">{$pic_fname}</a>
                </td>
                <td class="{$rowStyle}" valign="middle" align="center">
                        <a href="javascript:;" onclick= "MM_openBrWindow('displayimage.php?fullsize=1&amp;picfile={$pic_url}', 'ImageViewer', 'toolbar=yes, status=yes, resizable=yes, width={$winsizeX}, height={$winsizeY}')">
EOT;
        } else {
            // assume it's not an image so hope that browser can display/play it with a helper app
            $nonpic_url = rawurldecode($pic_url);
            $return .= <<<EOT
                <td class="{$rowStyle}" valign="middle">
                        <a href="javascript:;" onclick= "MM_openBrWindow('{$CONFIG['fullpath']}{$nonpic_url}', 'ImageViewer', 'toolbar=yes, status=yes, resizable=yes, width={$winsizeX}, height={$winsizeY}')">{$pic_fname}</a>
                </td>
                <td class="{$rowStyle}" valign="middle" align="center">
                        <a href="javascript:;" onclick= "MM_openBrWindow('{$CONFIG['fullpath']}{$nonpic_url}', 'ImageViewer', 'toolbar=yes, status=yes, resizable=yes, width={$winsizeX}, height={$winsizeY}')">
EOT;
        }
        if ($CONFIG['display_thumbs_batch_add'] == 1) {
            $return .= <<<EOT
                        <img src="images/spacer.gif" width="1" height="48" border="0" alt="" />
EOT;
        }
        $return .= <<<EOT
                        {$img}</a><br />
                </td>

                <td class="{$rowStyle}" valign="middle" width="100" height="40">
                    <p id="p_{$picid}" name="addpic.php?pic_file={$encoded_picfile}"></p>
                </td>
        </tr>
EOT;
        return $return;
    } else {
        $winsizeX = 300;
        $winsizeY = 300;
        $return = <<<EOT
        <tr>
                <td class="{$rowStyle}" valign="middle">
                        &nbsp;
                </td>
                <td class="{$rowStyle}" valign="middle">
                        <i>{$pic_fname}</i>
                </td>
                <td class="{$rowStyle}" valign="middle" align="center">
                        <a href="javascript:;" onclick= "MM_openBrWindow('displayimage.php?fullsize=1&amp;picfile={$pic_url}', 'ImageViewer', 'toolbar=yes, status=yes, resizable=yes, width={$winsizeX}, height={$winsizeY}')">
EOT;
        if ($CONFIG['display_thumbs_batch_add'] == 1) {
            $return .= <<<EOT
                        <img src="showthumb.php?picfile={$pic_url}&amp;size=48" class="thumbnail" border="0" alt="" />
EOT;
        }
        $return .= <<<EOT
                        </a>
                </td>
        </tr>
EOT;
        return $return;
    }
}
Пример #7
0
function refresh_db()
{
    global $CONFIG, $lang_util_php, $lang_common;
    $superCage = Inspekt::makeSuperCage();
    if ($superCage->post->keyExists('albumid')) {
        $albumid = $superCage->post->getInt('albumid');
    } else {
        $albumid = 0;
    }
    $albstr = $albumid ? "WHERE aid = {$albumid}" : '';
    $numpics = $superCage->post->getInt('refresh_numpics');
    if ($superCage->post->keyExists('refresh_startpic')) {
        $startpic = $superCage->post->getInt('refresh_startpic');
    } else {
        $startpic = 0;
    }
    starttable('100%', $lang_util_php['update_result'], 3);
    echo "<tr><th class=\"tableh2\">{$lang_util_php['file']}</th><th class=\"tableh2\">{$lang_util_php['problem']}</th><th class=\"tableh2\">{$lang_util_php['status']}</th></tr>";
    $outcome = 'none';
    $result = cpg_db_query("SELECT * FROM {$CONFIG['TABLE_PICTURES']} {$albstr} ORDER BY pid ASC LIMIT {$startpic}, {$numpics}");
    $count = mysql_num_rows($result);
    $found = 0;
    while ($row = mysql_fetch_assoc($result)) {
        extract($row, EXTR_PREFIX_ALL, "db");
        unset($prob);
        $full_pic_url = $CONFIG['fullpath'] . $db_filepath . $db_filename;
        $thumb_url = $CONFIG['fullpath'] . $db_filepath . $CONFIG['thumb_pfx'] . $db_filename;
        $normal_url = $CONFIG['fullpath'] . $db_filepath . $CONFIG['normal_pfx'] . $db_filename;
        $url = '<a href="' . $CONFIG["ecards_more_pic_target"] . (substr($CONFIG["ecards_more_pic_target"], -1) == '/' ? '' : '/') . "displayimage.php?pos=-{$db_pid}" . '" target="_blank">' . "{$db_title} ({$db_pid})" . '</a>';
        if (file_exists($full_pic_url)) {
            $filesize = filesize($full_pic_url);
            $dimensions = cpg_getimagesize($full_pic_url);
            if ($filesize) {
                $thumb_filesize = filesize($thumb_url);
                $normal_filesize = filesize($normal_url);
                $total_filesize = $filesize + $thumb_filesize + $normal_filesize;
                if ($total_filesize != $db_total_filesize) {
                    $prob .= "{$lang_util_php['incorrect_filesize']}<br />{$lang_util_php['database']}{$db_total_filesize}{$lang_util_php['bytes']}<br />{$lang_util_php['actual']}{$total_filesize}{$lang_util_php['bytes']}<br />";
                    cpg_db_query("UPDATE {$CONFIG['TABLE_PICTURES']} SET total_filesize = '{$total_filesize}' WHERE pid = '{$db_pid}' LIMIT 1");
                    $outcome = $lang_util_php['updated'];
                }
                if ($filesize != $db_filesize) {
                    $prob .= "{$lang_util_php['incorrect_filesize']}<br />{$lang_util_php['database']}{$db_filesize}{$lang_util_php['bytes']}<br />{$lang_util_php['actual']}{$filesize}{$lang_util_php['bytes']}<br />";
                    cpg_db_query("UPDATE {$CONFIG['TABLE_PICTURES']} SET filesize = '{$filesize}' WHERE pid = '{$db_pid}' LIMIT 1");
                    $outcome = $lang_util_php['updated'];
                }
            } else {
                $prob .= $lang_util_php['filesize_error'] . '<br />';
                $outcome = $lang_util_php['skipped'];
            }
            if ($dimensions) {
                if ($dimensions[0] != $db_pwidth || $dimensions[1] != $db_pheight) {
                    $prob .= "{$lang_util_php['incorect_dimension']}<br />{$lang_util_php['database']}{$db_pwidth}x{$db_pheight}<br />{$lang_util_php['actual']}{$dimensions[0]}x{$dimensions[1]}<br />";
                    cpg_db_query("UPDATE {$CONFIG['TABLE_PICTURES']} SET pwidth = '{$dimensions[0]}', pheight = '{$dimensions[1]}' WHERE pid = '{$db_pid}' LIMIT 1");
                    $outcome = $lang_util_php['updated'];
                }
            } else {
                $prob .= $lang_util_php['dimension_error'] . '<br />';
                $outcome = $lang_util_php['skipped'];
            }
        } else {
            $prob .= sprintf($lang_util_php['fullpic_error'], $full_pic_url) . '<br />';
            $outcome = $lang_util_php['cannot_fix'];
        }
        if ($prob) {
            echo "<tr><td class=\"tableb\">{$url}</td><td class=\"tableb\">{$prob}</td><td class=\"tableb\">{$outcome}</td></tr>";
        } else {
            echo "<tr><td class=\"tableb\">{$url}</td><td class=\"tableb\">{$lang_util_php['no_prob_detect']}</td><td class=\"tableb\">{$lang_common['ok']}</td></tr>";
        }
    }
    endtable();
    if ($outcome == 'none') {
        echo $lang_util_php['no_prob_found'];
    }
    if ($count == $numpics) {
        $startpic += $numpics;
        list($timestamp, $form_token) = getFormToken();
        echo <<<EOT
                    <form name="cpgform4" id="cpgform4" action="util.php" method="post">
                            <input type="hidden" name="action" value="refresh_db" />
                            <input type="hidden" name="refresh_numpics" value="{$numpics}" />
                            <input type="hidden" name="refresh_startpic" value="{$startpic}" />
                            <input type="hidden" name="albumid" value="{$albumid}" />
                            <button type="submit" class="button" name="submit" id="submit" value="{$lang_util_php['continue']}">{$lang_util_php['continue']} {$icon_array['continue']}</button>
                            <input type="hidden" name="form_token" value="{$form_token}" />
                            <input type="hidden" name="timestamp" value="{$timestamp}" />
                    </form>
EOT;
    }
    mysql_free_result($result);
}
Пример #8
0
function cpgUserLastComment($uid)
{
    global $CONFIG;
    $result = cpg_db_query("SELECT count(*), MAX(msg_id) FROM {$CONFIG['TABLE_COMMENTS']} as c, {$CONFIG['TABLE_PICTURES']} as p WHERE c.pid = p.pid AND approval='YES' AND author_id = '{$uid}' {$FORBIDDEN_SET}");
    $nbEnr = mysql_fetch_array($result);
    $comment_count = $nbEnr[0];
    $lastcom_id = $nbEnr[1];
    mysql_free_result($result);
    $lastcom = '';
    if ($comment_count) {
        $sql = "SELECT filepath, filename, url_prefix, pwidth, pheight, msg_author, UNIX_TIMESTAMP(msg_date) as msg_date, msg_body, approval " . "FROM {$CONFIG['TABLE_COMMENTS']} AS c, {$CONFIG['TABLE_PICTURES']} AS p " . "WHERE msg_id='" . $lastcom_id . "' AND approval = 'YES' AND c.pid = p.pid";
        $result = cpg_db_query($sql);
        if (mysql_num_rows($result)) {
            $row = mysql_fetch_array($result);
            mysql_free_result($result);
            $pic_url = get_pic_url($row, 'thumb');
            if (!is_image($row['filename'])) {
                $image_info = cpg_getimagesize(urldecode($pic_url));
                $row['pwidth'] = $image_info[0];
                $row['pheight'] = $image_info[1];
            }
            $image_size = compute_img_size($row['pwidth'], $row['pheight'], $CONFIG['thumb_width']);
            $mime_content = cpg_get_type($row['filename']);
            $lastcom = '<img src="' . $pic_url . '" class="image"' . $image_size['geom'] . ' border="0" alt="" />';
        }
    }
    $lastComArray = array();
    $lastComArray['thumb'] = $lastcom;
    $lastComArray['comment'] = $row['msg_body'];
    $lastComArray['msg_date'] = $row['msg_date'];
    $lastComArray['count'] = $comment_count;
    return $lastComArray;
}
Пример #9
0
EOT;
$i = 100;
$lb = '';
$j = 1;
if (count($rowset) > 0) {
    foreach ($rowset as $picture) {
        $get_photo_name = $picture['title'];
        $picname = $CONFIG['fullpath'] . $picture['filepath'] . $picture['filename'];
        $pic_url = urlencode($picture['filename']);
        $pic_fname = basename($picture['filename']);
        $pic_dirname = dirname($picname);
        $thumb_file = dirname($picname) . '/' . $CONFIG['thumb_pfx'] . $pic_fname;
        $img = '';
        if (file_exists($thumb_file)) {
            $thumb_info = cpg_getimagesize($picname);
            $thumb_size = compute_img_size($thumb_info[0], $thumb_info[1], 48);
            $img = '<img src="' . path2url($thumb_file) . '" ' . $thumb_size['geom'] . ' class="thumbnail" border="0" alt="" title="' . $get_photo_name . '" />';
        } elseif (is_image($picname)) {
            $img = '<img src="showthumb.php?picfile=' . $pic_url . '&amp;size=48" class="thumbnail" border="0" alt="" title="' . $get_photo_name . '" />';
        } else {
            $file['filepath'] = $pic_dirname . '/';
            $file['filename'] = $pic_fname;
            $filepathname = get_pic_url($file, 'thumb');
            $img = '<img src="' . $filepathname . '" class="thumbnail" width="48" border="0" alt="" title="' . $get_photo_name . '" />';
        }
        $unique_id = uniqid(rand());
        $pic_title = $picture['title'] ? "<strong>{$picture['title']}</strong><br />\n" : '';
        $lb .= <<<EOT
            <tr id="sort-{$picture['pid']}">
                <td class="dragHandle"></td>
Пример #10
0
 $uploaded_pic = $dest_dir . $picture_name;
 CPGPluginAPI::action('upload_html_pre_move', $superCage->files->getRaw("/userpicture/tmp_name"));
 // Move the picture into its final location
 // getRaw is safe here since this filename is generated by the server
 if (!move_uploaded_file($superCage->files->getRaw("/userpicture/tmp_name"), $uploaded_pic)) {
     cpg_die(CRITICAL_ERROR, sprintf($lang_db_input_php['err_move'], $picture_name, $dest_dir), __FILE__, __LINE__, true);
 }
 // Change file permission
 chmod($uploaded_pic, octdec($CONFIG['default_file_mode']));
 // Get picture information
 // Check that picture file size is lower than the maximum allowed
 if (filesize($uploaded_pic) > $CONFIG['max_upl_size'] * 1024) {
     @unlink($uploaded_pic);
     cpg_die(ERROR, sprintf($lang_db_input_php['err_imgsize_too_large'], $CONFIG['max_upl_size']), __FILE__, __LINE__);
 } elseif (is_image($picture_name)) {
     $imginfo = cpg_getimagesize($uploaded_pic);
     if ($imginfo == null) {
         // getimagesize does not recognize the file as a picture
         @unlink($uploaded_pic);
         cpg_die(ERROR, $lang_db_input_php['err_invalid_img'], __FILE__, __LINE__, true);
     } elseif ($imginfo[2] != GIS_JPG && $imginfo[2] != GIS_PNG && $CONFIG['GIF_support'] == 0) {
         // JPEG and PNG only are allowed with GD
         @unlink($uploaded_pic);
         cpg_die(ERROR, $lang_errors['gd_file_type_err'], __FILE__, __LINE__, true);
         // Check that picture size (in pixels) is lower than the maximum allowed
     }
     // Image is ok
 }
 // Upload is ok
 // Create thumbnail and internediate image and add the image into the DB
 $result = add_picture($album, $filepath, $picture_name, 0, $title, $caption, $keywords, $user1, $user2, $user3, $user4, $category, $raw_ip, $hdr_ip, $superCage->post->getInt('width'), $superCage->post->getInt('height'));
Пример #11
0
/**
* resize_image()
*
* Create a file containing a resized image
*
* @param  $src_file the source file
* @param  $dest_file the destination file
* @param  $new_size the size of the square within which the new image must fit
* @param  $method the method used for image resizing
* @return 'true' in case of success
*/
function resize_image($src_file, $dest_file, $new_size, $method, $thumb_use)
{
    global $CONFIG, $ERROR;
    global $lang_errors;
    $imginfo = cpg_getimagesize($src_file);
    if ($imginfo == null) {
        return false;
    }
    // GD can only handle JPG & PNG images
    //if ($imginfo[2] != GIS_JPG && $imginfo[2] != GIS_PNG && ($method == 'gd1' || $method == 'gd2')) {
    if ($imginfo[2] != GIS_JPG && $imageinfo[2] != GIS_PNG && $CONFIG['GIF_support'] == 0) {
        $ERROR = $lang_errors['gd_file_type_err'];
        return false;
    }
    // height/width
    $srcWidth = $imginfo[0];
    $srcHeight = $imginfo[1];
    if ($thumb_use == 'ht') {
        $ratio = $srcHeight / $new_size;
    } elseif ($thumb_use == 'wd') {
        $ratio = $srcWidth / $new_size;
    } else {
        $ratio = max($srcWidth, $srcHeight) / $new_size;
    }
    $ratio = max($ratio, 1.0);
    $destWidth = (int) ($srcWidth / $ratio);
    $destHeight = (int) ($srcHeight / $ratio);
    // Method for thumbnails creation
    switch ($method) {
        case "im":
            if (preg_match("#[A-Z]:|\\\\#Ai", __FILE__)) {
                // get the basedir, remove '/include'
                $cur_dir = substr(dirname(__FILE__), 0, -8);
                $src_file = '"' . $cur_dir . '\\' . strtr($src_file, '/', '\\') . '"';
                $im_dest_file = str_replace('%', '%%', '"' . $cur_dir . '\\' . strtr($dest_file, '/', '\\') . '"');
            } else {
                $src_file = escapeshellarg($src_file);
                $im_dest_file = str_replace('%', '%%', escapeshellarg($dest_file));
            }
            $output = array();
            /*
             * Hack for working with ImageMagick on WIndows even if IM is installed in C:\Program Files.
             * By Aditya Mooley <*****@*****.**>
             */
            if (eregi("win", $_ENV['OS'])) {
                $cmd = "\"" . str_replace("\\", "/", $CONFIG['impath']) . "convert\" -quality {$CONFIG['jpeg_qual']} {$CONFIG['im_options']} -geometry {$destWidth}x{$destHeight} " . str_replace("\\", "/", $src_file) . " " . str_replace("\\", "/", $im_dest_file);
                exec("\"{$cmd}\"", $output, $retval);
            } else {
                $cmd = "{$CONFIG['impath']}convert -quality {$CONFIG['jpeg_qual']} {$CONFIG['im_options']} -geometry {$destWidth}x{$destHeight} {$src_file} {$im_dest_file}";
                exec($cmd, $output, $retval);
            }
            if ($retval) {
                $ERROR = "Error executing ImageMagick - Return value: {$retval}";
                if ($CONFIG['debug_mode']) {
                    // Re-execute the command with the backtit operator in order to get all outputs
                    // will not work is safe mode is enabled
                    $output = `{$cmd} 2>&1`;
                    $ERROR .= "<br /><br /><div align=\"left\">Cmd line : <br /><font size=\"2\">" . nl2br(htmlspecialchars($cmd)) . "</font></div>";
                    $ERROR .= "<br /><br /><div align=\"left\">The convert program said:<br /><font size=\"2\">";
                    $ERROR .= nl2br(htmlspecialchars($output));
                    $ERROR .= "</font></div>";
                }
                @unlink($dest_file);
                return false;
            }
            break;
        case "gd1":
            if (!function_exists('imagecreatefromjpeg')) {
                cpg_die(CRITICAL_ERROR, 'PHP running on your server does not support the GD image library, check with your webhost if ImageMagick is installed', __FILE__, __LINE__);
            }
            if ($imginfo[2] == GIS_JPG) {
                $src_img = imagecreatefromjpeg($src_file);
            } else {
                $src_img = imagecreatefrompng($src_file);
            }
            if (!$src_img) {
                $ERROR = $lang_errors['invalid_image'];
                return false;
            }
            $dst_img = imagecreate($destWidth, $destHeight);
            imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, $destWidth, (int) $destHeight, $srcWidth, $srcHeight);
            imagejpeg($dst_img, $dest_file, $CONFIG['jpeg_qual']);
            imagedestroy($src_img);
            imagedestroy($dst_img);
            break;
        case "gd2":
            if (!function_exists('imagecreatefromjpeg')) {
                cpg_die(CRITICAL_ERROR, 'PHP running on your server does not support the GD image library, check with your webhost if ImageMagick is installed', __FILE__, __LINE__);
            }
            if (!function_exists('imagecreatetruecolor')) {
                cpg_die(CRITICAL_ERROR, 'PHP running on your server does not support GD version 2.x, please switch to GD version 1.x on the admin page', __FILE__, __LINE__);
            }
            if ($imginfo[2] == GIS_GIF && $CONFIG['GIF_support'] == 1) {
                $src_img = imagecreatefromgif($src_file);
            } elseif ($imginfo[2] == GIS_JPG) {
                $src_img = imagecreatefromjpeg($src_file);
            } else {
                $src_img = imagecreatefrompng($src_file);
            }
            if (!$src_img) {
                $ERROR = $lang_errors['invalid_image'];
                return false;
            }
            if ($imginfo[2] == GIS_GIF) {
                $dst_img = imagecreate($destWidth, $destHeight);
            } else {
                $dst_img = imagecreatetruecolor($destWidth, $destHeight);
            }
            imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $destWidth, (int) $destHeight, $srcWidth, $srcHeight);
            imagejpeg($dst_img, $dest_file, $CONFIG['jpeg_qual']);
            imagedestroy($src_img);
            imagedestroy($dst_img);
            break;
    }
    // Set mode of uploaded picture
    @chmod($dest_file, octdec($CONFIG['default_file_mode']));
    //silence the output in case chmod is disabled
    // We check that the image is valid
    $imginfo = cpg_getimagesize($dest_file);
    if ($imginfo == null) {
        $ERROR = $lang_errors['resize_failed'];
        @unlink($dest_file);
        return false;
    } else {
        return true;
    }
}
Пример #12
0
/**
* list_cat_albums()
*
* This has been added to list the albums in a category, used for showing first level albums, largely a repetition of code elsewhere
* Redone for a cleaner approach
* @param integer $cat Category id for which albums are needed
*/
function list_cat_albums($cat, $catdata)
{
    global $CONFIG, $lang_date, $FORBIDDEN_SET_DATA;
    global $lang_list_albums;
    $PAGE = 1;
    if ($cat == 0) {
        return '';
    }
    $cat_owner_id = $cat > 10000 ? 10000 - $cat : 10001;
    $cpg_nopic_data = cpg_get_system_thumb('nopic.jpg', $cat_owner_id);
    $cpg_privatepic_data = cpg_get_system_thumb('private.jpg', $cat_owner_id);
    $alb_per_page = $CONFIG['albums_per_page'];
    //unused code {SaWey}
    /*$maxTab = $CONFIG['max_tabs'];
    
        $album_filter = '';
        $pic_filter = '';
    
        if (!empty($FORBIDDEN_SET) && !$cpg_show_private_album) {
            $album_filter = ' and ' . str_replace('p.', 'a.', $FORBIDDEN_SET);
            $pic_filter = ' and ' . $FORBIDDEN_SET;
        }*/
    $nbAlb = $catdata['details']['alb_count'];
    if ($nbAlb == 0) {
        return;
    }
    $totalPages = ceil($nbAlb / $alb_per_page);
    $alb_list = array();
    $approved = ' AND approved=\'YES\'';
    $forbidden_set_string = count($FORBIDDEN_SET_DATA) > 0 ? ' AND aid NOT IN (' . implode(', ', $FORBIDDEN_SET_DATA) . ')' : '';
    $last_pids = array();
    $last_pid_data = array();
    foreach ($catdata['subalbums'] as $aid => $album) {
        if ($CONFIG['link_pic_count'] == 1 || $album['pic_count'] == 0) {
            if (!empty($album['keyword'])) {
                $keyword = $album['keyword'] ? "AND (keywords like '%" . addslashes($album['keyword']) . "%' {$forbidden_set_string})" : '';
                $query = "SELECT count(pid) AS link_pic_count, max(pid) AS link_last_pid, max(ctime) AS link_last_upload " . " FROM {$CONFIG['TABLE_PICTURES']} " . " WHERE ((aid != '{$aid}' {$forbidden_set_string}) {$keyword}) {$approved}";
                $result = cpg_db_query($query);
                $link_stat = $result->fetchAssoc(true);
                $catdata['subalbums'][$aid]['link_pic_count'] = $link_stat['link_pic_count'];
                $catdata['subalbums'][$aid]['last_pid'] = !empty($album['last_pid']) && $album['last_pid'] > $link_stat['link_last_pid'] ? $album['last_pid'] : $link_stat['link_last_pid'];
                if ($CONFIG['link_last_upload'] && $link_stat['link_pic_count'] > 0) {
                    $catdata['subalbums'][$aid]['last_upload'] = $album['last_upload'] > $link_stat['link_last_upload'] ? $album['last_upload'] : $link_stat['link_last_upload'];
                }
            }
        }
        if ($catdata['subalbums'][$aid]['last_pid']) {
            $last_pids[] = $catdata['subalbums'][$aid]['last_pid'];
        }
        if ($album['thumb'] > 0) {
            $last_pids[] = $album['thumb'];
        }
    }
    if (count($last_pids)) {
        $result = cpg_db_query("SELECT pid, filepath, filename, url_prefix, pwidth, pheight FROM {$CONFIG['TABLE_PICTURES']} WHERE pid IN (" . implode(',', $last_pids) . ")");
        while ($row = $result->fetchAssoc()) {
            $last_pid_data[$row['pid']] = $row;
            unset($last_pid_data[$row['pid']]['pid']);
        }
        $result->free();
    }
    unset($last_pids);
    foreach ($catdata['subalbums'] as $aid => $album) {
        // Inserts a thumbnail if the album contains 1 or more images
        //unused code {SaWey}
        //$visibility = $album['visibility'];
        $keyword = $album['keyword'] ? "OR (keywords like '%" . addslashes($album['keyword']) . "%' {$forbidden_set_string})" : '';
        if (!in_array($aid, $FORBIDDEN_SET_DATA) || $CONFIG['allow_private_albums'] == 0) {
            //test for visibility
            if ($album['pic_count'] > 0 || !empty($album['link_pic_count'])) {
                if (!empty($last_pid_data[$album['thumb']]['filename'])) {
                    $picture = $last_pid_data[$album['thumb']];
                } elseif ($album['thumb'] < 0) {
                    $sql = "SELECT filepath, filename, url_prefix, pwidth, pheight " . "FROM {$CONFIG['TABLE_PICTURES']} WHERE ((aid = '{$aid}' {$forbidden_set_string}) {$keyword}) {$approved} " . "ORDER BY RAND() LIMIT 0,1";
                    $result = cpg_db_query($sql);
                    $picture = $result->fetchAssoc(true);
                } else {
                    $picture = $last_pid_data[$album['last_pid']];
                }
                $pic_url = get_pic_url($picture, 'thumb');
                if (!is_image($picture['filename'])) {
                    $image_info = cpg_getimagesize(urldecode($pic_url));
                    $picture['pwidth'] = $image_info[0];
                    $picture['pheight'] = $image_info[1];
                }
                //thumb cropping
                if (array_key_exists('system_icon', $picture) && $picture['system_icon'] == true) {
                    $image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size'], true, 'cat_thumb');
                } else {
                    $image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size'], false, 'cat_thumb');
                }
                $alb_list[$aid]['thumb_pic'] = "<img src=\"" . $pic_url . "\" class=\"image thumbnail\" {$image_size['geom']} border=\"0\" alt=\"{$picture['filename']}\" />";
            } else {
                // Inserts an empty thumbnail if the album contains 0 images
                // $image_size = compute_img_size(100, 75, $CONFIG['alb_list_thumb_size']);
                $alb_list[$aid]['thumb_pic'] = '<img src="' . $cpg_nopic_data['thumb'] . '" ' . $cpg_nopic_data['whole'] . ' class="image thumbnail" border="0" alt="" />';
            }
        } elseif ($CONFIG['show_private']) {
            // $image_size = compute_img_size(100, 75, $CONFIG['alb_list_thumb_size']);
            $alb_list[$aid]['thumb_pic'] = '<img src="' . $cpg_privatepic_data['thumb'] . '" ' . $cpg_privatepic_data['whole'] . ' class="image thumbnail" border="0" alt="" />';
        }
        // Prepare everything
        if (!in_array($aid, $FORBIDDEN_SET_DATA) || $CONFIG['allow_private_albums'] == 0) {
            $link_pic_count = !empty($album['link_pic_count']) ? $album['link_pic_count'] : 0;
            $last_upload_date = $album['pic_count'] || $CONFIG['link_pic_count'] && $link_pic_count > 0 ? localised_date($album['last_upload'], $lang_date['lastup']) : '';
            $alb_list[$aid]['aid'] = $aid;
            $alb_list[$aid]['album_title'] = $album['title'];
            $alb_list[$aid]['album_desc'] = bb_decode($album['description']);
            $alb_list[$aid]['pic_count'] = $album['pic_count'];
            $alb_list[$aid]['last_upl'] = $last_upload_date;
            $alb_list[$aid]['alb_hits'] = sprintf($lang_list_albums['alb_hits'], $album['alb_hits']);
            $alb_list[$aid]['album_info'] = theme_album_info($album['pic_count'], $link_pic_count, $last_upload_date);
            $alb_list[$aid]['album_adm_menu'] = album_adm_menu($aid, $cat, $album['owner']);
        } elseif ($CONFIG['show_private']) {
            // show private album description
            $link_pic_count = !empty($album['link_pic_count']) ? $album['link_pic_count'] : 0;
            $last_upload_date = $album['pic_count'] || $CONFIG['link_pic_count'] && $link_pic_count > 0 ? localised_date($album['last_upload'], $lang_date['lastup']) : '';
            $alb_list[$aid]['aid'] = $aid;
            $alb_list[$aid]['album_title'] = $album['title'];
            $alb_list[$aid]['album_desc'] = bb_decode($album['description']);
            $alb_list[$aid]['pic_count'] = $album['pic_count'];
            $alb_list[$aid]['last_upl'] = $last_upload_date;
            $alb_list[$aid]['alb_hits'] = sprintf($lang_list_albums['alb_hits'], $album['alb_hits']);
            $alb_list[$aid]['album_info'] = theme_album_info($album['pic_count'], $link_pic_count, $last_upload_date);
            $alb_list[$aid]['album_adm_menu'] = album_adm_menu($aid, $cat, $album['owner']);
        }
    }
    ob_start();
    theme_display_album_list_cat($alb_list, $nbAlb, $cat, $PAGE, $totalPages);
    $cat_albums = ob_get_contents();
    ob_end_clean();
    return $cat_albums;
}
Пример #13
0
function makethumbnail($src_file, $newSize, $method)
{
    global $CONFIG;
    $content_type = array(GIS_GIF => 'gif', GIS_JPG => 'jpeg', GIS_PNG => 'png');
    // Checks that file exists and is readable
    if (!filesize($src_file) || !is_readable($src_file)) {
        header("Content-type: image/png");
        fpassthru(fopen(READ_ERROR_ICON, 'rb'));
        exit;
    }
    // find the image size, no size => unknow type
    $imginfo = cpg_getimagesize($src_file);
    if ($imginfo == null) {
        header("Content-type: image/png");
        fpassthru(fopen(UNKNOW_ICON, 'rb'));
        exit;
    }
    // GD can't handle gif images
    //if ($imginfo[2] == GIS_GIF && ($method == 'gd1' || $method == 'gd2')) {
    if ($imginfo[2] == GIS_GIF && $CONFIG['GIF_support'] == 0) {
        header("Content-type: image/png");
        fpassthru(fopen(GIF_ICON, 'rb'));
        exit;
    }
    // height/width
    $srcWidth = $imginfo[0];
    $srcHeight = $imginfo[1];
    $ratio = max($srcWidth, $srcHeight) / $newSize;
    $ratio = max($ratio, 1.0);
    $destWidth = (int) ($srcWidth / $ratio);
    $destHeight = (int) ($srcHeight / $ratio);
    // Choose method for thumb creation
    switch ($method) {
        case "im":
            if (preg_match("#[A-Z]:|\\\\#Ai", __FILE__)) {
                $cur_dir = dirname(__FILE__);
                $src_file = '"' . $cur_dir . '\\' . strtr($src_file, '/', '\\') . '"';
            } else {
                $src_file = escapeshellarg($src_file);
            }
            header("Content-type: image/" . $content_type[$imginfo[2]]);
            passthru("{$CONFIG['impath']}convert -quality {$CONFIG['jpeg_qual']} -antialias -geometry {$destWidth}x{$destHeight} {$src_file} -");
            break;
        case "gd2":
            if ($imginfo[2] == GIS_GIF && $CONFIG['GIF_support'] == 1) {
                $src_img = imagecreatefromgif($src_file);
            } elseif ($imginfo[2] == GIS_JPG) {
                $src_img = imagecreatefromjpeg($src_file);
            } else {
                $src_img = imagecreatefrompng($src_file);
            }
            if ($imginfo[2] == GIS_GIF) {
                $dst_img = imagecreate($destWidth, $destHeight);
            } else {
                $dst_img = imagecreatetruecolor($destWidth, $destHeight);
            }
            imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $destWidth, (int) $destHeight, $srcWidth, $srcHeight);
            header("Content-type: image/jpeg");
            imagejpeg($dst_img);
            imagedestroy($src_img);
            imagedestroy($dst_img);
            break;
    }
}
/**
 * function cpg_getimagesize()
 *
 * Try to get the size of an image, this is custom built as some webhosts disable this function or do weird things with it
 *
 * @param string $image
 * @param boolean $force_cpg_function
 * @return array $size
 */
function cpg_getimagesize($image, $force_cpg_function = false)
{
    if (!function_exists('getimagesize') || $force_cpg_function) {
        // custom function borrowed from http://www.wischik.com/lu/programmer/get-image-size.html
        $f = @fopen($image, 'rb');
        if ($f === false) {
            return false;
        }
        fseek($f, 0, SEEK_END);
        $len = ftell($f);
        if ($len < 24) {
            fclose($f);
            return false;
        }
        fseek($f, 0);
        $buf = fread($f, 24);
        if ($buf === false) {
            fclose($f);
            return false;
        }
        if (ord($buf[0]) == 255 && ord($buf[1]) == 216 && ord($buf[2]) == 255 && ord($buf[3]) == 224 && $buf[6] == 'J' && $buf[7] == 'F' && $buf[8] == 'I' && $buf[9] == 'F') {
            $pos = 2;
            while (ord($buf[2]) == 255) {
                if (ord($buf[3]) == 192 || ord($buf[3]) == 193 || ord($buf[3]) == 194 || ord($buf[3]) == 195 || ord($buf[3]) == 201 || ord($buf[3]) == 202 || ord($buf[3]) == 203) {
                    break;
                    // we've found the image frame
                }
                $pos += 2 + (ord($buf[4]) << 8) + ord($buf[5]);
                if ($pos + 12 > $len) {
                    break;
                    // too far
                }
                fseek($f, $pos);
                $buf = $buf[0] . $buf[1] . fread($f, 12);
            }
        }
        fclose($f);
        // GIF:
        if ($buf[0] == 'G' && $buf[1] == 'I' && $buf[2] == 'F') {
            $x = ord($buf[6]) + (ord($buf[7]) << 8);
            $y = ord($buf[8]) + (ord($buf[9]) << 8);
            $type = 1;
        }
        // JPEG:
        if (ord($buf[0]) == 255 && ord($buf[1]) == 216 && ord($buf[2]) == 255) {
            $y = (ord($buf[7]) << 8) + ord($buf[8]);
            $x = (ord($buf[9]) << 8) + ord($buf[10]);
            $type = 2;
        }
        // PNG:
        if (ord($buf[0]) == 0x89 && $buf[1] == 'P' && $buf[2] == 'N' && $buf[3] == 'G' && ord($buf[4]) == 0xd && ord($buf[5]) == 0xa && ord($buf[6]) == 0x1a && ord($buf[7]) == 0xa && $buf[12] == 'I' && $buf[13] == 'H' && $buf[14] == 'D' && $buf[15] == 'R') {
            $x = (ord($buf[16]) << 24) + (ord($buf[17]) << 16) + (ord($buf[18]) << 8) + (ord($buf[19]) << 0);
            $y = (ord($buf[20]) << 24) + (ord($buf[21]) << 16) + (ord($buf[22]) << 8) + (ord($buf[23]) << 0);
            $type = 3;
        }
        // added ! from source line since it doesn't work otherwise
        if (!isset($x, $y, $type)) {
            return false;
        }
        return array($x, $y, $type, 'height="' . $x . '" width="' . $y . '"');
    } else {
        $size = getimagesize($image);
        if (!$size) {
            //false was returned
            return cpg_getimagesize($image, true);
        } elseif (!isset($size[0]) || !isset($size[1])) {
            //webhost possibly changed getimagesize functionality
            return cpg_getimagesize($image, true);
        } else {
            //function worked as expected, return the results
            return $size;
        }
    }
}
Пример #15
0
}
$path_to_image = $dest_dir . $uniqueName;
//Now we upload the file.
if (!move_uploaded_file($_FILES['file']['tmp_name'], $path_to_image)) {
    // The file upload has failed.
    cpg_die(12);
}
// Change file permission
@chmod($path_to_image, octdec($CONFIG['default_file_mode']));
//silence the output in case chmod is disabled
// Create a testing alias.
$picture_alias = $matches[1] . "." . $matches[2];
// Check to see if the filename is consistent with that of a picture.
if (is_image($picture_alias)) {
    // If it is, get the picture information
    $imginfo = cpg_getimagesize($path_to_image);
    // If cpg_getimagesize does not recognize the file as a picture, delete the picture.
    if ($imginfo === 'FALSE') {
        @unlink($path_to_image);
        // The file upload has failed -- the image is not an image or it is corrupt.
        cpg_die(13);
        // JPEG and PNG only are allowed with GD. If the image is not allowed for GD,delete it.
        //} elseif ($imginfo[2] != GIS_JPG && $imginfo[2] != GIS_PNG && ($CONFIG['thumb_method'] == 'gd1' || $CONFIG['thumb_method'] == 'gd2')) {
    } elseif ($imginfo[2] != GIS_JPG && $imginfo[2] != GIS_PNG && $CONFIG['GIF_support'] == 0 && $CONFIG['thumb_method'] != 'im' && $CONFIG['thumb_method'] != 'gd2') {
        @unlink($path_to_image);
        // The file upload has failed -- the image is not allowed with GD.
        cpg_die(14);
        // Check that picture size (in pixels) is lower than the maximum allowed. If not, delete it.
    } elseif (max($imginfo[0], $imginfo[1]) > $CONFIG['max_upl_width_height']) {
        // Yet to implement in API
        if (USER_IS_ADMIN && $CONFIG['auto_resize'] == 1 || !USER_IS_ADMIN && $CONFIG['auto_resize'] > 0) {
Пример #16
0
 $imginfo = cpg_getimagesize($image);
 if ($imginfo == null) {
     @unlink($CONFIG['fullpath'] . $row['filepath'] . $row['filename']);
     // Go back to the renamed copy
     rename($CONFIG['fullpath'] . $row['filepath'] . 'renamed_' . $row['filename'], $CONFIG['fullpath'] . $row['filepath'] . $row['filename']);
     cpgRedirectPage('displayimage.php?album=' . $aid . '&pid=' . $pid, $lang_common['error'], $lang_plugin_external_edit['error_broken'], 0, 'warning');
 }
 // The new file appears to be OK, so let's delete the backup
 @unlink($CONFIG['fullpath'] . $row['filepath'] . 'renamed_' . $row['filename']);
 $output .= '<li>' . $external_edit_icon_array['ok'] . sprintf($lang_plugin_external_edit['file_integrity'], $lang_common['ok']) . '</li>';
 if ($row['pwidth'] != $imginfo[0] || $row['pheight'] != $imginfo[1]) {
     // The dimensions have changed - let's write back those changes into the db
     cpg_db_query("UPDATE {$CONFIG['TABLE_PICTURES']} SET pwidth = '{$imginfo[0]}', pheight = '{$imginfo[1]}' WHERE pid = {$pid}");
 }
 $work_image = $image;
 $imagesize = cpg_getimagesize($work_image);
 if (resize_image($work_image, $thumb, $CONFIG['thumb_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use'], "false", 1)) {
     $output .= '<li>' . $external_edit_icon_array['ok'] . sprintf($lang_plugin_external_edit['thumbnail'], $lang_plugin_external_edit['created']) . '</li>';
 } else {
     $output .= '<li>' . $external_edit_icon_array['cancel'] . sprintf($lang_plugin_external_edit['thumbnail'], $lang_plugin_external_edit['failure']) . '</li>';
 }
 $CONFIG['enable_watermark'] == '1' && $CONFIG['which_files_to_watermark'] == 'both' || $CONFIG['which_files_to_watermark'] == 'resized' ? $watermark = "true" : ($watermark = "false");
 if (max($imagesize[0], $imagesize[1]) > $CONFIG['picture_width'] && $CONFIG['make_intermediate']) {
     if (resize_image($work_image, $normal, $CONFIG['picture_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use'], $watermark)) {
         $output .= '<li>' . $external_edit_icon_array['ok'] . sprintf($lang_plugin_external_edit['intermediate'], $lang_plugin_external_edit['created']) . '</li>';
     } else {
         $output .= '<li>' . $external_edit_icon_array['cancel'] . sprintf($lang_plugin_external_edit['intermediate'], $lang_plugin_external_edit['failure']) . '</li>';
     }
 } else {
     $output .= '<li>' . $external_edit_icon_array['ignore'] . sprintf($lang_plugin_external_edit['intermediate'], $lang_plugin_external_edit['skipped']) . '</li>';
 }
Пример #17
0
/**
 * display_thumbnails()
 *
 * Generates data to display thumbnails of pictures in an album
 *
 * @param mixed $album Either the album ID or the meta album name
 * @param integer $cat Either the category ID or album ID if negative
 * @param integer $page Page number to display
 * @param integer $thumbcols
 * @param integer $thumbrows
 * @param boolean $display_tabs
 **/
function fetchcontent_display_thumbnails($album, $cat, $page, $thumbcols, $thumbrows, $display_tabs)
{
    global $CONFIG, $USER, $LINEBREAK;
    global $lang_date, $lang_display_thumbnails, $lang_byte_units, $lang_common;
    $superCage = Inspekt::makeSuperCage();
    $thumb_per_page = $thumbcols * $thumbrows;
    $lower_limit = ($page - 1) * $thumb_per_page;
    $pic_data = get_pic_data($album, $thumb_count, $album_name, $lower_limit, $thumb_per_page);
    $total_pages = ceil($thumb_count / $thumb_per_page);
    $i = 0;
    if (count($pic_data) > 0) {
        foreach ($pic_data as $key => $row) {
            $i++;
            $pic_title = $lang_common['filename'] . '=' . $row['filename'] . $LINEBREAK . $lang_common['filesize'] . '=' . ($row['filesize'] >> 10) . $lang_byte_units[1] . $LINEBREAK . $lang_display_thumbnails['dimensions'] . $row['pwidth'] . "x" . $row['pheight'] . $LINEBREAK . $lang_display_thumbnails['date_added'] . localised_date($row['ctime'], $lang_date['album']);
            $pic_url = get_pic_url($row, 'thumb');
            if (!is_image($row['filename'])) {
                $image_info = cpg_getimagesize(urldecode($pic_url));
                $row['pwidth'] = $image_info[0];
                $row['pheight'] = $image_info[1];
            }
            // thumb cropping - if we display a system thumb we calculate the dimension by any and not ex
            if (array_key_exists('system_icon', $row) && $row['system_icon'] == true) {
                $image_size = compute_img_size($row['pwidth'], $row['pheight'], $CONFIG['thumb_width'], true);
            } else {
                $image_size = compute_img_size($row['pwidth'], $row['pheight'], $CONFIG['thumb_width']);
            }
            $thumb_list[$i]['pos'] = $key < 0 ? $key : $i - 1 + $lower_limit;
            $thumb_list[$i]['pid'] = $row['pid'];
            // $thumb_list[$i]['image']        = '<img src="' . $pic_url . '" class="image" ' . $image_size['geom'] . ' border="0" alt="' . $row['filename'] . '" title="' . $pic_title . '" />'; // commented out for fetchcontent
            $thumb_list[$i]['thumbpath'] = $pic_url;
            // Added for fetchcontent
            $thumb_list[$i]['thumbsize'] = $image_size['geom'];
            // Added for fetchcontent
            $thumb_list[$i]['caption'] = bb_decode($row['caption_text']);
            $thumb_list[$i]['admin_menu'] = '';
            $thumb_list[$i]['aid'] = $row['aid'];
            $thumb_list[$i]['pwidth'] = $row['pwidth'];
            $thumb_list[$i]['pheight'] = $row['pheight'];
            // cpg1.5: new thumb fields below
            $thumb_list[$i]['title'] = $row['title'];
            $thumb_list[$i]['description'] = $row['caption'];
            $thumb_list[$i]['filepath'] = $row['filepath'];
            $thumb_list[$i]['filename'] = $row['filename'];
            $thumb_list[$i]['filesize'] = $row['filesize'];
            $thumb_list[$i]['msg_id'] = isset($row['msg_id']) ? $row['msg_id'] : '';
            // needed for get_pic_pos()
        }
        // Add a hit to album counter if it is a numeric album
        if (is_numeric($album)) {
            // Create an array to hold the album id for hits (if not created)
            if (!isset($USER['liv_a']) || !is_array($USER['liv_a'])) {
                $USER['liv_a'] = array();
            }
            // Add 1 to album hit counter
            if ((!USER_IS_ADMIN && $CONFIG['count_admin_hits'] == 0 || $CONFIG['count_admin_hits'] == 1) && !in_array($album, $USER['liv_a']) && $superCage->cookie->keyExists($CONFIG['cookie_name'] . '_data')) {
                add_album_hit($album);
                if (count($USER['liv_a']) > 4) {
                    array_shift($USER['liv_a']);
                }
                array_push($USER['liv_a'], $album);
                user_save_profile();
            }
        }
        //Using getRaw(). The date is sanitized in the called function.
        $date = $superCage->get->keyExists('date') ? cpgValidateDate($superCage->get->getRaw('date')) : null;
        // This is the difference to the original function taken from Coppermine's core: we don't process the data further, but put it into an array and return it
        $return = array('thumb_list' => $thumb_list, 'thumb_count' => $thumb_count, 'album_name' => $album_name, 'aid' => $album, 'cat' => $cat, 'page' => $page, 'total_pages' => $total_pages, 'sort_options' => is_numeric($album), 'display_tabs' => $display_tabs, 'mode' => 'thumb', 'date' => $date);
    } elseif (is_numeric($album)) {
        $return = array('album_name' => $album_name);
    }
    return $return;
}
Пример #18
0
function image_preview($path_to_primary_image, $maximum_width)
{
    //Globalize appropriate variables.
    global $CONFIG, $lang_image_processor_php, $preview_image_directory;
    //Determine thumbnail method.
    $method = $CONFIG['thumb_method'];
    if ($method == 'gd2' and !function_exists('imageistruecolor')) {
        //Set ignore imageistruecolor to false.
        $ignore = 0;
    } else {
        //Set $ignore image is true color to true.
        $ignore = 1;
    }
    // Get image info.
    $source_image_size_and_type = cpg_getimagesize($path_to_primary_image) or die($lang_image_processor_php['file_corrupt']);
    $source_image_width = $source_image_size_and_type[0];
    $source_image_height = $source_image_size_and_type[1];
    $source_image_type = $source_image_size_and_type[2];
    //We need specify the path for the transitory file.
    // Create a prefix for easier human recognition.
    $prefix = "pre_";
    //Set the correct file extension.
    if ($source_image_type == '1') {
        $suffix = '.gif';
    } elseif ($source_image_type == '2') {
        $suffix = '.jpg';
    } elseif ($source_image_type == '3') {
        $suffix = '.png';
    }
    // Generate the unique name.
    do {
        $seed = substr(md5(uniqid('')), 0, 8);
        $path_to_preview_image = $preview_image_directory . $prefix . $seed . $suffix;
    } while (file_exists($path_to_preview_image));
    //Now we can upload the file.
    // Calculate dimensions.
    if ($source_image_width > $maximum_width) {
        $new_width = (int) $maximum_width;
        $new_height = (int) ($source_image_height * ($maximum_width / $source_image_width));
    } else {
        $new_width = $source_image_width;
        $new_height = $source_image_height;
    }
    //Begin processing if GD is used.
    if ($method == "gd2" or $method == "gd1") {
        // Get image handle
        $image_handle = get_handle($path_to_primary_image);
        // Create the destination image handle.
        if ($method == "gd2") {
            if ($ignore) {
                if (ImageIsTrueColor($image_handle)) {
                    $destination_image_handle = ImageCreateTrueColor($new_width, $new_height);
                } else {
                    $destination_image_handle = ImageCreate($new_width, $new_height);
                }
            } else {
                $destination_image_handle = ImageCreate($new_width, $new_height);
            }
        } elseif ($method == "gd1") {
            $destination_image_handle = ImageCreate($new_width, $new_height);
        }
        // Resize the image
        if ($method == "gd2") {
            //Use the higher quality function imagecopyresampled.
            imagecopyresampled($destination_image_handle, $image_handle, 0, 0, 0, 0, $new_width, $new_height, $source_image_width, $source_image_height);
        } elseif ($method == "gd1") {
            //Use the lower quality imagecopyresized.
            imagecopyresized($destination_image_handle, $image_handle, 0, 0, 0, 0, $new_width, $new_height, $source_image_width, $source_image_height);
        }
        //Destroy $image_handle
        imagedestroy($image_handle);
        // Write the image to disk.
        write_to_disk($source_image_type, $destination_image_handle, $path_to_preview_image);
        /*        if ($source_image_type == "2") {
        
        				imagejpeg($destination_image_handle, $path_to_preview_image) or die($lang_image_processor_php['no_write']);
        
        		} elseif ($source_image_type == "3") {
        
        				imagepng($destination_image_handle, $path_to_preview_image) or die($lang_image_processor_php['no_write']);
        
        		} elseif ($source_image_type == "1" && $CONFIG['GIF_support'] == 1) {
        				imagegif($destination_image_handle, $path_to_preview_image) or die($lang_image_processor_php['no_write']);
        		}
        
        // Destroy $destination_image_handle.
        imagedestroy($destination_image_handle); */
    } elseif ($method == "im") {
        // Set IM path.
        $im_path = $CONFIG['impath'];
        //Check the IM path for the final slash.
        if (eregi('/$', $im_path) or empty($im_path)) {
            $trailing_slash = "";
        } else {
            $trailing_slash = "/";
        }
        //Determine real paths to files.
        $real_path_to_primary_image = realpath($path_to_primary_image);
        $real_path_to_preview_image = realpath($path_to_preview_image);
        // Prevent the user from creating a process zombie by aborting while IM does its work.
        ignore_user_abort(true);
        // Issue the command for resizing to IM.  Have ImageMagick write the image to disk.
        $output = array();
        $cmd = "{$CONFIG['impath']}" . $trailing_slash . "convert -geometry {$new_width}x{$new_height} \"{$real_path_to_primary_image}\" \"{$real_path_to_preview_image}\"";
        exec($cmd, $output, $retval);
        // Restore the user abort setting.
        ignore_user_abort(false);
        if ($retval) {
            $ERROR = $lang_image_processor_php['IM_Error'] . $retval;
            if ($CONFIG['debug_mode']) {
                // Re-execute the command with the backtick operator in order to get all outputs
                // will not work is safe mode is enabled
                $output = `{$cmd} 2>&1`;
                $ERROR .= "<br /><br /><div align=\"left\">{$lang_image_processor_php['cmd_line']}<br /><span style=\"font-size:120%\">" . nl2br(htmlspecialchars($cmd)) . "</span></div>";
                $ERROR .= "<br /><br /><div align=\"left\">{$lang_image_processor_php['mog_said']}<br /><span style=\"font-size:120%\">";
                $ERROR .= nl2br(htmlspecialchars($output));
                $ERROR .= "</span></div>";
            }
            die($ERROR);
        }
    }
    return $path_to_preview_image;
}
Пример #19
0
/**
 * picrow()
 *
 * return the HTML code for a row to be displayed for an image
 * the row contains a checkbox, the image name, a thumbnail
 *
 * @param  $picfile the full path of the file that contains the picture
 * @param  $picid the name of the check box
 * @return the HTML code
 */
function picrow($picfile, $picid, $albid)
{
    global $CONFIG, $expic_array, $rowCounter;
    $rowCounter++;
    if ($rowCounter / 2 == floor($rowCounter / 2)) {
        $rowStyle = 'tableb';
    } else {
        $rowStyle = 'tableb tableb_alternate';
    }
    $encoded_picfile = base64_encode($picfile);
    $picname = $CONFIG['fullpath'] . $picfile;
    $pic_url = urlencode($picfile);
    $pic_fname = basename($picfile);
    $pic_dirname = dirname($picname);
    $thumb_file = dirname($picname) . '/' . $CONFIG['thumb_pfx'] . $pic_fname;
    if (file_exists($thumb_file)) {
        $thumb_info = cpg_getimagesize($picname);
        $thumb_size = compute_img_size($thumb_info[0], $thumb_info[1], 48);
        if ($CONFIG['display_thumbs_batch_add'] == 1) {
            $img = '<img src="' . path2url($thumb_file) . '" ' . $thumb_size['geom'] . ' class="thumbnail" border="0" alt="" />';
        }
    } elseif (is_image($picname)) {
        if ($CONFIG['display_thumbs_batch_add'] == 1) {
            $img = '<img src="showthumb.php?picfile=' . $pic_url . '&amp;size=48" class="thumbnail" border="0" alt="" />';
        }
    } else {
        $file['filepath'] = $pic_dirname . '/';
        //substr($picname,0,strrpos($picname,'/'))
        $file['filename'] = $pic_fname;
        $filepathname = get_pic_url($file, 'thumb');
        //$mime_content = cpg_get_type($picname);
        //$extension = file_exists("images/thumb_{$mime_content['extension']}.jpg") ? $mime_content['extension']:$mime_content['content'];
        //$img = '<img src="images/thumb_'.$extension.'.jpg" class="thumbnail" width="48" border="0" alt="" />';
        if ($CONFIG['display_thumbs_batch_add'] == 1) {
            $img = '<img src="' . $filepathname . '" class="thumbnail" width="48" border="0" alt="" />';
        }
    }
    if (filesize($picname) && is_readable($picname)) {
        //$fullimagesize = cpg_getimagesize($picname); COMMENTED OUT FOR VIDEO SUPPORT
        $winsizeX = $fullimagesize[0] + 16;
        $winsizeY = $fullimagesize[1] + 16;
        //$checked = isset($expic_array[$picfile]) || !$fullimagesize ? '' : 'checked';
        $checked = isset($expic_array[$picfile]) ? '' : 'checked';
        $return = <<<EOT
        <tr>
                <td class="{$rowStyle}" valign="middle" width="30">
                        <input name="pics[]" id="picselector" type="checkbox" value="{$picid}" {$checked} />
                        <input name="album_lb_id_{$picid}" type="hidden" value="{$albid}" />
                        <input name="picfile_{$picid}" type="hidden" value="{$encoded_picfile}" />
                </td>
                <td class="{$rowStyle}" valign="middle">
                        <a href="javascript:;" onclick= "MM_openBrWindow('displayimage.php?fullsize=1&amp;picfile={$pic_url}', 'ImageViewer', 'toolbar=yes, status=yes, resizable=yes, width={$winsizeX}, height={$winsizeY}')">{$pic_fname}</a>
                </td>
                <td class="{$rowStyle}" valign="middle" align="center">
                        <a href="javascript:;" onclick= "MM_openBrWindow('displayimage.php?fullsize=1&amp;picfile={$pic_url}', 'ImageViewer', 'toolbar=yes, status=yes, resizable=yes, width={$winsizeX}, height={$winsizeY}')">
EOT;
        if ($CONFIG['display_thumbs_batch_add'] == 1) {
            $return .= <<<EOT
                        <img src="images/spacer.gif" width="1" height="48" border="0" alt="" />
EOT;
        }
        $return .= <<<EOT
                        {$img}</a><br />
                </td>
        </tr>
EOT;
        return $return;
    } else {
        $winsizeX = 300;
        $winsizeY = 300;
        $return = <<<EOT
        <tr>
                <td class="{$rowStyle}" valign="middle">
                        &nbsp;
                </td>
                <td class="{$rowStyle}" valign="middle">
                        <i>{$pic_fname}</i>
                </td>
                <td class="{$rowStyle}" valign="middle" align="center">
                        <a href="javascript:;" onclick= "MM_openBrWindow('displayimage.php?fullsize=1&amp;picfile={$pic_url}', 'ImageViewer', 'toolbar=yes, status=yes, resizable=yes, width={$winsizeX}, height={$winsizeY}')">
EOT;
        if ($CONFIG['display_thumbs_batch_add'] == 1) {
            $return .= <<<EOT
                        <img src="showthumb.php?picfile={$pic_url}&amp;size=48" class="thumbnail" border="0" alt="" />
EOT;
        }
        $return .= <<<EOT
                        </a>
                </td>
        </tr>
EOT;
        return $return;
    }
}
Пример #20
0
/**
* list_cat_albums()
*
* This has been added to list the albums in a category, used for showing first level albumslargely a repetition of code elsewhere
* Redone for a cleaner approach
* @param integer $cat Category id for which albums are needed
*/
function list_cat_albums($cat = 0)
{
    global $CONFIG, $USER, $lastup_date_fmt, $USER_DATA, $FORBIDDEN_SET, $FORBIDDEN_SET_DATA, $cpg_show_private_album;
    global $lang_list_albums, $lang_errors;
    $PAGE = 1;
    if ($cat == 0) {
        return '';
    }
    $cat_owner_id = $cat > 10000 ? 10000 - $cat : 10001;
    $cpg_nopic_data = cpg_get_system_thumb('nopic.jpg', $cat_owner_id);
    $cpg_privatepic_data = cpg_get_system_thumb('private.jpg', $cat_owner_id);
    $alb_per_page = $CONFIG['albums_per_page'];
    $maxTab = $CONFIG['max_tabs'];
    $album_filter = '';
    $pic_filter = '';
    if (!empty($FORBIDDEN_SET) && !$cpg_show_private_album) {
        $album_filter = ' and ' . str_replace('p.', 'a.', $FORBIDDEN_SET);
        $pic_filter = ' and ' . $FORBIDDEN_SET;
    }
    $sql = "SELECT count(aid) FROM {$CONFIG['TABLE_ALBUMS']} as a WHERE category = '{$cat}'" . $album_filter;
    $result = cpg_db_query($sql);
    $nbEnr = mysql_fetch_array($result);
    $nbAlb = $nbEnr[0];
    mysql_free_result($result);
    if ($nbAlb == 0) {
        return;
    }
    $totalPages = ceil($nbAlb / $alb_per_page);
    if ($PAGE > $totalPages) {
        $PAGE = 1;
    }
    $lower_limit = ($PAGE - 1) * $alb_per_page;
    $upper_limit = min($nbAlb, $PAGE * $alb_per_page);
    $limit = "LIMIT " . $lower_limit . "," . ($upper_limit - $lower_limit);
    $sql = 'SELECT a.aid, a.title, a.description, a.thumb, visibility, filepath, ' . 'filename, url_prefix, pwidth, pheight ' . 'FROM ' . $CONFIG['TABLE_ALBUMS'] . ' as a ' . 'LEFT JOIN ' . $CONFIG['TABLE_PICTURES'] . ' as p ' . 'ON a.thumb=p.pid ' . 'WHERE category=' . $cat . $album_filter . ' ORDER BY a.pos ' . $limit;
    $alb_thumbs_q = cpg_db_query($sql);
    $alb_thumbs = cpg_db_fetch_rowset($alb_thumbs_q);
    mysql_free_result($alb_thumbs_q);
    $disp_album_count = count($alb_thumbs);
    $album_set = '';
    foreach ($alb_thumbs as $value) {
        $album_set .= $value['aid'] . ', ';
    }
    $album_set = '(' . substr($album_set, 0, -2) . ')';
    /*$sql = "SELECT aid, count(pid) as pic_count, max(pid) as last_pid, max(ctime) as last_upload " . "FROM {$CONFIG['TABLE_PICTURES']} " . "WHERE aid IN $album_set AND approved = 'YES' " . "GROUP BY aid";
      $alb_stats_q = cpg_db_query($sql);
      $alb_stats = cpg_db_fetch_rowset($alb_stats_q);
      mysql_free_result($alb_stats_q);*/
    //This query will fetch album stats and keyword for the albums
    $sql = "SELECT a.aid, count( p.pid )  AS pic_count, max( p.pid )  AS last_pid, max( p.ctime )  AS last_upload, a.keyword, a.alb_hits" . " FROM {$CONFIG['TABLE_ALBUMS']} AS a " . " LEFT JOIN {$CONFIG['TABLE_PICTURES']} AS p ON a.aid = p.aid AND p.approved =  'YES' " . "WHERE a.aid IN {$album_set}" . "GROUP BY a.aid";
    $alb_stats_q = cpg_db_query($sql);
    $alb_stats = cpg_db_fetch_rowset($alb_stats_q);
    mysql_free_result($alb_stats_q);
    foreach ($alb_stats as $key => $value) {
        $cross_ref[$value['aid']] =& $alb_stats[$key];
        if ($CONFIG['link_pic_count'] == 1) {
            if (!empty($value['keyword'])) {
                $query = "SELECT count(pid) AS link_pic_count\n                      FROM {$CONFIG['TABLE_PICTURES']}\n                        WHERE aid != {$value['aid']} AND\n                        keywords LIKE '%{$value['keyword']}%' AND\n                        approved = 'YES'";
                $result = cpg_db_query($query);
                $link_stat = mysql_fetch_array($result);
                mysql_free_result($result);
                $alb_stats[$key]['link_pic_count'] = $link_stat['link_pic_count'];
            }
        }
    }
    for ($alb_idx = 0; $alb_idx < $disp_album_count; $alb_idx++) {
        $alb_thumb =& $alb_thumbs[$alb_idx];
        $aid = $alb_thumb['aid'];
        if (isset($cross_ref[$aid])) {
            $alb_stat = $cross_ref[$aid];
            $count = $alb_stat['pic_count'];
            $alb_hits = $alb_stat['alb_hits'];
        } else {
            $alb_stat = array();
            $count = 0;
            $alb_hits = 0;
        }
        // Inserts a thumbnail if the album contains 1 or more images
        $visibility = $alb_thumb['visibility'];
        if (!in_array($aid, $FORBIDDEN_SET_DATA) || $CONFIG['allow_private_albums'] == 0) {
            //test for visibility
            if ($count > 0) {
                // Inserts a thumbnail if the album contains 1 or more images
                if ($alb_thumb['filename']) {
                    $picture =& $alb_thumb;
                } elseif ($alb_thumb['thumb'] < 0) {
                    $sql = "SELECT filepath, filename, url_prefix, pwidth, pheight " . "FROM {$CONFIG['TABLE_PICTURES']} WHERE aid = '{$alb_thumb['aid']}' ORDER BY RAND() LIMIT 0,1";
                    $result = cpg_db_query($sql);
                    $picture = mysql_fetch_array($result);
                    mysql_free_result($result);
                } else {
                    $sql = "SELECT filepath, filename, url_prefix, pwidth, pheight " . "FROM {$CONFIG['TABLE_PICTURES']} " . "WHERE pid='{$alb_stat['last_pid']}'";
                    $result = cpg_db_query($sql);
                    $picture = mysql_fetch_array($result);
                    mysql_free_result($result);
                }
                $pic_url = get_pic_url($picture, 'thumb');
                if (!is_image($picture['filename'])) {
                    $image_info = cpg_getimagesize(urldecode($pic_url));
                    $picture['pwidth'] = $image_info[0];
                    $picture['pheight'] = $image_info[1];
                }
                //thumb cropping
                if ($picture['system_icon'] == 'true') {
                    $image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size'], true, 'cat_thumb');
                } else {
                    $image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size'], false, 'cat_thumb');
                }
                $alb_list[$alb_idx]['thumb_pic'] = "<img src=\"" . $pic_url . "\" class=\"image\" {$image_size['geom']} border=\"0\" alt=\"{$picture['filename']}\" />";
            } else {
                // Inserts an empty thumbnail if the album contains 0 images
                // $image_size = compute_img_size(100, 75, $CONFIG['alb_list_thumb_size']);
                $alb_list[$alb_idx]['thumb_pic'] = '<img src="' . $cpg_nopic_data['thumb'] . '" ' . $cpg_nopic_data['whole'] . ' class="image" border="0" alt="" />';
            }
        } elseif ($CONFIG['show_private']) {
            // $image_size = compute_img_size(100, 75, $CONFIG['alb_list_thumb_size']);
            $alb_list[$alb_idx]['thumb_pic'] = '<img src="' . $cpg_privatepic_data['thumb'] . '" ' . $cpg_privatepic_data['whole'] . ' class="image" border="0" alt="" />';
        }
        // Prepare everything
        if (!in_array($aid, $FORBIDDEN_SET_DATA) || $CONFIG['allow_private_albums'] == 0) {
            $last_upload_date = $count ? localised_date($alb_stat['last_upload'], $lastup_date_fmt) : '';
            $link_pic_count = !empty($alb_stat['link_pic_count']) ? $alb_stat['link_pic_count'] : 0;
            $alb_list[$alb_idx]['aid'] = $alb_thumb['aid'];
            $alb_list[$alb_idx]['album_title'] = $alb_thumb['title'];
            $alb_list[$alb_idx]['album_desc'] = bb_decode($alb_thumb['description']);
            $alb_list[$alb_idx]['pic_count'] = $count;
            $alb_list[$alb_idx]['last_upl'] = $last_upload_date;
            $alb_list[$alb_idx]['alb_hits'] = sprintf($lang_list_albums['alb_hits'], $alb_hits);
            $alb_list[$alb_idx]['album_info'] = sprintf($lang_list_albums['n_pictures'], $count) . ($count ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "") . ($CONFIG['link_pic_count'] && $link_pic_count > 0 ? sprintf(", {$lang_list_albums['n_link_pictures']}, {$lang_list_albums['total_pictures']}", $link_pic_count, $count + $link_pic_count) : "");
            $alb_list[$alb_idx]['album_adm_menu'] = album_adm_menu($alb_thumb['aid'], $cat);
        } elseif ($CONFIG['show_private']) {
            // uncomment this else block to show private album description
            $last_upload_date = $count ? localised_date($alb_stat['last_upload'], $lastup_date_fmt) : '';
            $link_pic_count = !empty($alb_stat['link_pic_count']) ? $alb_stat['link_pic_count'] : 0;
            $alb_list[$alb_idx]['aid'] = $alb_thumb['aid'];
            $alb_list[$alb_idx]['album_title'] = $alb_thumb['title'];
            $alb_list[$alb_idx]['album_desc'] = bb_decode($alb_thumb['description']);
            $alb_list[$alb_idx]['pic_count'] = $count;
            $alb_list[$alb_idx]['last_upl'] = $last_upload_date;
            $alb_list[$alb_idx]['alb_hits'] = sprintf($lang_list_albums['alb_hits'], $alb_hits);
            $alb_list[$alb_idx]['album_info'] = sprintf($lang_list_albums['n_pictures'], $count) . ($count ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "") . ($CONFIG['link_pic_count'] && $link_pic_count > 0 ? sprintf(", {$lang_list_albums['n_link_pictures']}, {$lang_list_albums['total_pictures']}", $link_pic_count, $count + $link_pic_count) : "");
            $alb_list[$alb_idx]['album_adm_menu'] = album_adm_menu($alb_thumb['aid'], $cat);
        }
    }
    ob_start();
    theme_display_album_list_cat($alb_list, $nbAlb, $cat, $PAGE, $totalPages);
    $cat_albums = ob_get_contents();
    ob_end_clean();
    return $cat_albums;
}
Пример #21
0
function file_replacer_page_start()
{
    global $CONFIG, $lang_errors;
    $superCage = Inspekt::makeSuperCage();
    if ($superCage->get->keyExists('replacer_id')) {
        $pid = $superCage->get->getInt('replacer_id');
        $result = cpg_db_query("SELECT * FROM {$CONFIG['TABLE_PICTURES']} AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = p.aid WHERE p.pid = '{$pid}' LIMIT 1");
        $row = mysql_fetch_assoc($result);
        if (!(USER_ADMIN_MODE && $row['category'] == FIRST_USER_CAT + USER_ID || $CONFIG['users_can_edit_pics'] && $row['owner_id'] == USER_ID && USER_ID != 0 || GALLERY_ADMIN_MODE)) {
            load_template();
            cpg_die(ERROR, $lang_errors['access_denied'], __FILE__, __LINE__);
        }
        require_once "./plugins/file_replacer/lang/english.php";
        if ($CONFIG['lang'] != 'english' && file_exists("./plugins/file_replacer/lang/{$CONFIG['lang']}.php")) {
            require_once "./plugins/file_replacer/lang/{$CONFIG['lang']}.php";
        }
        if ($superCage->files->keyExists('fileupload') && $row) {
            if (!checkFormToken()) {
                load_template();
                global $lang_errors;
                cpg_die(ERROR, $lang_errors['invalid_form_token'], __FILE__, __LINE__);
            }
            $fileupload = $superCage->files->_source['fileupload'];
            if ($fileupload['error']) {
                load_template();
                global $lang_errors;
                cpg_die(ERROR, $lang_errors['error'] . ' ' . $fileupload['error'], __FILE__, __LINE__);
            }
            $image = $CONFIG['fullpath'] . $row['filepath'] . $row['filename'];
            $normal = $CONFIG['fullpath'] . $row['filepath'] . $CONFIG['normal_pfx'] . $row['filename'];
            $thumb = $CONFIG['fullpath'] . $row['filepath'] . $CONFIG['thumb_pfx'] . $row['filename'];
            $orig = $CONFIG['fullpath'] . $row['filepath'] . $CONFIG['orig_pfx'] . $row['filename'];
            $work_image = $image;
            if (!move_uploaded_file($fileupload['tmp_name'], $image)) {
                load_template();
                cpg_die(ERROR, sprintf($lang_plugin_file_replacer['error_move_file'], $fileupload['tmp_name'], $image), __FILE__, __LINE__);
            }
            chmod($image, octdec($CONFIG['default_file_mode']));
            if (is_known_filetype($image)) {
                if (is_image($image)) {
                    require 'include/picmgmt.inc.php';
                    $imagesize = cpg_getimagesize($image);
                    if ($CONFIG['read_iptc_data']) {
                        // read IPTC data
                        $iptc = get_IPTC($image);
                        if ($superCage->post->keyExists('overwrite_metadata')) {
                            $title = isset($iptc['Headline']) ? $iptc['Headline'] : '';
                            $caption = isset($iptc['Caption']) ? $iptc['Caption'] : '';
                            $keywords = isset($iptc['Keywords']) ? implode($CONFIG['keyword_separator'], $iptc['Keywords']) : '';
                            $metadata_sql = ", title = '{$title}', caption = '{$caption}', keywords = '{$keywords}'";
                        }
                    }
                    // resize picture if it's bigger than the max width or height for uploaded pictures
                    if (max($imagesize[0], $imagesize[1]) > $CONFIG['max_upl_width_height']) {
                        if (USER_IS_ADMIN && $CONFIG['auto_resize'] == 1 || !USER_IS_ADMIN && $CONFIG['auto_resize'] > 0) {
                            resize_image($image, $image, $CONFIG['max_upl_width_height'], $CONFIG['thumb_method'], 'any', 'false');
                            // hard-coded 'any' according to configuration string 'Max width or height for uploaded pictures'
                            $imagesize = cpg_getimagesize($image);
                        } elseif (USER_IS_ADMIN) {
                            // skip resizing for admin
                            $picture_original_size = true;
                        } else {
                            @unlink($uploaded_pic);
                            $msg = sprintf($lang_db_input_php['err_fsize_too_large'], $CONFIG['max_upl_width_height'], $CONFIG['max_upl_width_height']);
                            return array('error' => $msg, 'halt_upload' => 1);
                        }
                    }
                    // create backup of full sized picture if watermark is enabled for full sized pictures
                    if (!file_exists($orig) && $CONFIG['enable_watermark'] == '1' && ($CONFIG['which_files_to_watermark'] == 'both' || $CONFIG['which_files_to_watermark'] == 'original')) {
                        if (!copy($image, $orig)) {
                            return false;
                        } else {
                            $work_image = $orig;
                        }
                    }
                    //if (!file_exists($thumb)) {
                    // create thumbnail
                    if (($result = resize_image($work_image, $thumb, $CONFIG['thumb_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use'], "false", 1)) !== true) {
                        return $result;
                    }
                    //}
                    if (max($imagesize[0], $imagesize[1]) > $CONFIG['picture_width'] && $CONFIG['make_intermediate']) {
                        // create intermediate sized picture
                        $resize_method = $CONFIG['picture_use'] == "thumb" ? $CONFIG['thumb_use'] == "ex" ? "any" : $CONFIG['thumb_use'] : $CONFIG['picture_use'];
                        $watermark = $CONFIG['enable_watermark'] == '1' && ($CONFIG['which_files_to_watermark'] == 'both' || $CONFIG['which_files_to_watermark'] == 'resized') ? 'true' : 'false';
                        if (($result = resize_image($work_image, $normal, $CONFIG['picture_width'], $CONFIG['thumb_method'], $resize_method, $watermark)) !== true) {
                            return $result;
                        }
                    }
                    // watermark full sized picture
                    if ($CONFIG['enable_watermark'] == '1' && ($CONFIG['which_files_to_watermark'] == 'both' || $CONFIG['which_files_to_watermark'] == 'original')) {
                        $wm_max_upl_width_height = $picture_original_size ? max($imagesize[0], $imagesize[1]) : $CONFIG['max_upl_width_height'];
                        // use max aspect of original image if it hasn't been resized earlier
                        if (($result = resize_image($work_image, $image, $wm_max_upl_width_height, $CONFIG['thumb_method'], 'any', 'true')) !== true) {
                            return $result;
                        }
                    }
                    list($width, $height) = getimagesize($image);
                } else {
                    $width = 0;
                    $height = 0;
                }
                $image_filesize = filesize($image);
                $total_filesize = is_image($row['filename']) ? $image_filesize + (file_exists($normal) ? filesize($normal) : 0) + filesize($thumb) : $image_filesize;
                cpg_db_query("UPDATE {$CONFIG['TABLE_PICTURES']} SET filesize = '{$image_filesize}', total_filesize = '{$total_filesize}', pwidth = '{$width}', pheight = '{$height}' {$metadata_sql} WHERE pid = '{$pid}' LIMIT 1");
                if ($superCage->post->keyExists('update_timestamp')) {
                    cpg_db_query("UPDATE {$CONFIG['TABLE_PICTURES']} SET ctime = '" . time() . "' WHERE pid = '{$pid}' LIMIT 1");
                }
                cpg_db_query("DELETE FROM {$CONFIG['TABLE_EXIF']} WHERE pid = '{$pid}' LIMIT 1");
                if ($CONFIG['read_exif_data']) {
                    include "include/exif_php.inc.php";
                    exif_parse_file($image, $pid);
                }
                $CONFIG['site_url'] = rtrim($CONFIG['site_url'], '/');
            } else {
                if (is_image($image)) {
                    @unlink($normal);
                    @unlink($thumb);
                }
                @unlink($image);
            }
            header("Location: {$CONFIG['site_url']}/displayimage.php?pid={$pid}");
            die;
        } else {
            load_template();
            pageheader($lang_plugin_file_replacer['file_replacer']);
            echo '<form method="post" enctype="multipart/form-data">';
            starttable('60%', $lang_plugin_file_replacer['upload_file'], 2);
            list($timestamp, $form_token) = getFormToken();
            echo <<<EOT
                <tr>
                    <td class="tableb" valign="top">
                        {$lang_plugin_file_replacer['browse']}
                    </td>
                    <td class="tableb" valign="top">
                        <input type="file" name="fileupload" size="40" class="listbox" />
                    </td>
                </tr>
                <tr>
                    <td class="tableb" valign="top">
                        {$lang_plugin_file_replacer['update_timestamp']}
                    </td>
                    <td class="tableb" valign="top">
                        <input type="checkbox" name="update_timestamp" />
                    </td>
                </tr>
                <tr>
                    <td class="tableb" valign="top">
                        {$lang_plugin_file_replacer['overwrite_metadata']}
                    </td>
                    <td class="tableb" valign="top">
                        <input type="checkbox" name="overwrite_metadata" />
                    </td>
                </tr>
                <tr>
                    <td align="center" colspan="2" class="tablef">
                        <input type="hidden" name="form_token" value="{$form_token}" />
                        <input type="hidden" name="timestamp" value="{$timestamp}" />
                        <input type="submit" name="commit" class="button" value="{$lang_plugin_file_replacer['upload']}"/>
                    </td>
                </tr>
EOT;
            endtable();
            echo '</form>';
            pagefooter();
            exit;
        }
    }
}
Пример #22
0
                         }
                     } elseif ($value == 'ip') {
                         list($row['ip_detail']) = CPGPluginAPI::filter('ip_information', array('', $row[$value]));
                         print '      ' . $row[$value] . $row['ip_detail'] . $LINEBREAK;
                     } else {
                         print '      ' . $row[$value] . $LINEBREAK;
                     }
                 }
                 print '    </td>' . $LINEBREAK;
             }
             if ($pid == '') {
                 print '    <td class="' . $row_style_class . '">' . $LINEBREAK;
                 if ($file == 1) {
                     $thumb_url = get_pic_url($row, 'thumb');
                     if (!is_image($row['filename'])) {
                         $image_info = cpg_getimagesize($thumb_url);
                         $row['pwidth'] = $image_info[0];
                         $row['pheight'] = $image_info[1];
                     }
                     $image_size = compute_img_size($row['pwidth'], $row['pheight'], $CONFIG['alb_list_thumb_size']);
                     print '      <a href="displayimage.php?pid=' . $row['pid'] . '"><img src="' . $thumb_url . '" ' . $image_size['geom'] . ' class="image" border="0" alt="" /></a>';
                 }
                 print '    </td>' . $LINEBREAK;
             }
             print '  </tr>' . $LINEBREAK;
         }
         // check internals end
     }
 }
 $result->free();
 // Display pagination
Пример #23
0
 cpg_db_connect();
 $query = "SELECT * FROM {$CONFIG['TABLE_PICTURES']} where pid=" . $img_id;
 $image = cpg_db_fetch_rowset(cpg_db_query($query));
 $image = $image[0];
 // REPLACE OPTION --- OVERWRITE FILE
 if ($img_savetype == 1) {
     // copy the image to the require location
     copy('./albums/snapshot.jpg', './albums/' . $image[2] . $image[3]);
     // update the thumbnail
     make_thumbnail($image[2], $image[3]);
     print "200";
 } else {
     if ($img_savetype == 2) {
         //save it with a new name in the album Directory with currentdate prefix
         //require('include/functions.inc.php');
         $siz_e = cpg_getimagesize('./albums/snapshot.jpg', true);
         $file_name = date("Ymdgi") . $image[3];
         //copy temporary file to the final destination
         rename('./albums/snapshot.jpg', './albums/' . $image[2] . $file_name);
         //copy entires into the database
         // All fields are duplicated except the id field, which
         // is auto-incremented to the next available value.
         //cpg_db_connect();
         $sql = "SELECT * FROM {$CONFIG['TABLE_PICTURES']} where pid=" . $img_id;
         $result = cpg_db_query($sql);
         //print "\n fetched results ".echoArray($result);
         if ($result) {
             $sql = "INSERT INTO {$CONFIG['TABLE_PICTURES']} SET ";
             $row = mysql_fetch_array($result);
             $RowKeys = array_keys($row);
             $RowValues = array_values($row);
/**
* resize_image()
*
* Create a file containing a resized image
*
* @param  $src_file the source file
* @param  $dest_file the destination file
* @param  $new_size the size of the square within which the new image must fit
* @param  $method the method used for image resizing
* @return 'true' in case of success
*/
function resize_image($src_file, $dest_file, $new_size, $method, $thumb_use, $watermark = "false", $sharpen = 0, $media_type = "false")
{
    global $CONFIG, $ERROR;
    global $lang_errors;
    list($sharpen) = CPGPluginAPI::filter('image_sharpen', array($sharpen, $new_size));
    //Make Cage
    $superCage = Inspekt::makeSuperCage();
    $imginfo = cpg_getimagesize($src_file);
    if ($imginfo == null) {
        return false;
    }
    // GD can only handle JPG & PNG images
    if ($imginfo[2] != GIS_JPG && $imginfo[2] != GIS_PNG && $CONFIG['GIF_support'] == 0) {
        $ERROR = $lang_errors['gd_file_type_err'];
        //return false;
        return array('error' => $ERROR);
    }
    // height/width
    $srcWidth = $imginfo[0];
    $srcHeight = $imginfo[1];
    $crop = 0;
    // initialize
    // if cropping is enabled calculate cropping parameters
    if ($thumb_use == 'ex') {
        $thb_width = $CONFIG['thumb_width'];
        $thb_height = $CONFIG['thumb_height'];
        if ($new_size == $thb_width) {
            $crop = 1;
            switch ($CONFIG['thumb_method']) {
                //cropping parameters for ImageMagick
                case "im":
                    $resize_commands = "";
                    if ($srcWidth / $srcHeight > $thb_width / $thb_height) {
                        $resize_commands .= "-resize x" . $thb_height;
                        $resized_w = $thb_height / $srcHeight * $srcWidth;
                        $resize_commands .= " -crop " . $thb_width . "x" . $thb_height . "+" . round(($resized_w - $thb_width) / 2) . "+0";
                    } else {
                        $resize_commands .= "-resize " . $thb_width;
                        $resized_h = $thb_width / $srcWidth * $srcHeight;
                        $resize_commands .= " -crop " . $thb_width . "x" . $thb_height . "+0+" . round(($resized_h - $thb_height) / 2);
                    }
                    break;
                    // cropping parameters for GD2
                // cropping parameters for GD2
                default:
                    if ($srcHeight < $srcWidth) {
                        $ratio = (double) ($srcHeight / $thb_height);
                        $cpyWidth = round($thb_width * $ratio);
                        if ($cpyWidth > $srcWidth) {
                            $ratio = (double) ($srcWidth / $thb_width);
                            $cpyWidth = $srcWidth;
                            $cpyHeight = round($thb_height * $ratio);
                            $xOffset = 0;
                            $yOffset = round(($srcHeight - $cpyHeight) / 2);
                        } else {
                            $cpyHeight = $srcHeight;
                            $xOffset = round(($srcWidth - $cpyWidth) / 2);
                            $yOffset = 0;
                        }
                    } else {
                        $ratio = (double) ($srcWidth / $thb_width);
                        $cpyHeight = round($thb_height * $ratio);
                        if ($cpyHeight > $srcHeight) {
                            $ratio = (double) ($srcHeight / $thb_height);
                            $cpyHeight = $srcHeight;
                            $cpyWidth = round($thb_width * $ratio);
                            $xOffset = round(($srcWidth - $cpyWidth) / 2);
                            $yOffset = 0;
                        } else {
                            $cpyWidth = $srcWidth;
                            $xOffset = 0;
                            $yOffset = round(($srcHeight - $cpyHeight) / 2);
                        }
                    }
                    $destWidth = $thb_width;
                    $destHeight = $thb_height;
                    $srcWidth = $cpyWidth;
                    $srcHeight = $cpyHeight;
                    break;
            }
        } else {
            $ratio = max($srcWidth, $srcHeight) / $new_size;
        }
    } elseif ($thumb_use == 'wd') {
        // resize method width
        $ratio = $srcWidth / $new_size;
    } elseif ($thumb_use == 'ht') {
        // resize method height
        $ratio = $srcHeight / $new_size;
    } else {
        // resize method any
        $ratio = max($srcWidth, $srcHeight) / $new_size;
    }
    $ratio = max($ratio, 1.0);
    if ($thumb_use == 'orig') {
        $ratio = 1.0;
    }
    if ($crop != 1) {
        $destWidth = (int) ($srcWidth / $ratio);
        $destHeight = (int) ($srcHeight / $ratio);
        $resize_commands = "-geometry " . $destWidth . "x" . $destHeight;
        $xOffset = 0;
        $yOffset = 0;
    }
    // Method for thumbnails creation
    switch ($method) {
        case "im":
            if (preg_match("#[A-Z]:|\\\\#Ai", __FILE__)) {
                // get the basedir, remove '/include'
                $cur_dir = substr(dirname(__FILE__), 0, -8);
                $src_file = '"' . $cur_dir . '\\' . strtr($src_file, '/', '\\') . '"';
                $im_dest_file = str_replace('%', '%%', '"' . $cur_dir . '\\' . strtr($dest_file, '/', '\\') . '"');
            } else {
                $src_file = escapeshellarg($src_file);
                $im_dest_file = str_replace('%', '%%', escapeshellarg($dest_file));
            }
            $output = array();
            /*
             * Hack for working with ImageMagick on Windows even if IM is installed in C:\Program Files.
             * By Aditya Mooley <*****@*****.**>
             */
            if ($sharpen == 1 && $CONFIG['enable_unsharp'] == 1) {
                $unsharp_mask = " -unsharp " . $CONFIG['unsharp_radius'] . "x" . sqrt($CONFIG['unsharp_radius']) . "+" . $CONFIG['unsharp_amount'] / 100 . "+" . $CONFIG['unsharp_threshold'] / 100 . " ";
            } else {
                $unsharp_mask = "";
            }
            if ($superCage->env->getMatched('OS', '/win/i')) {
                $cmd = "\"" . str_replace("\\", "/", $CONFIG['impath']) . "convert\" -quality {$CONFIG['jpeg_qual']} {$CONFIG['im_options']} " . $resize_commands . " " . $unsharp_mask . " " . str_replace("\\", "/", $src_file) . " " . str_replace("\\", "/", $im_dest_file);
                exec("\"{$cmd}\"", $output, $retval);
            } else {
                $cmd = "{$CONFIG['impath']}convert -quality {$CONFIG['jpeg_qual']} {$CONFIG['im_options']} " . $resize_commands . " " . $unsharp_mask . " {$src_file} {$im_dest_file}";
                exec($cmd, $output, $retval);
            }
            if ($media_type != "false") {
                //if a manual thumb gets generated we watermark the thumb with the media type
                //we now need to get the absolute path to the thumb watermark files
                $path_parts = pathinfo($CONFIG['watermark_file']);
                $CONFIG['watermark_file'] = $path_parts["dirname"] . "/wm_" . $media_type . ".png";
            }
            if ($watermark == "true" || $media_type != "false") {
                //do we need to resize the watermark to fit onto the intermediate?
                $wm_normal = (int) $CONFIG['reduce_watermark'];
                if ($wm_normal > $destWidth) {
                    $wm_resize = (int) ($destWidth / $wm_normal * 100);
                    //we have to create a temporary, downsized watermark file in the edit folder
                    //temp path for small wm
                    $path_to_tmp_wm = './' . $CONFIG['fullpath'] . 'edit/temp_wm.png';
                    if ($superCage->env->getMatched('OS', '/win/i')) {
                        $cmd = "\"" . str_replace("\\", "/", $CONFIG['impath']) . "convert\" -resize " . $wm_resize . "% " . str_replace("\\", "/", $CONFIG['watermark_file']) . " " . str_replace("\\", "/", $path_to_tmp_wm);
                        exec("\"{$cmd}\"", $output, $retval);
                    } else {
                        $cmd = "{$CONFIG['impath']}convert -resize {$wm_resize}% {$CONFIG['watermark_file']} {$path_to_tmp_wm}";
                        exec($cmd, $output, $retval);
                    }
                    $wm_file = $path_to_tmp_wm;
                    //set the path to the wm file to the temp one
                } else {
                    $wm_file = $CONFIG['watermark_file'];
                    //if no downsize... we take the orig watermark
                }
                // now we apply the watermark
                if ($superCage->env->getMatched('OS', '/win/i')) {
                    $cmd = "\"" . str_replace("\\", "/", $CONFIG['impath']) . "composite\" -dissolve {$CONFIG['watermark_transparency']} -gravity {$CONFIG['where_put_watermark']} \"{$wm_file}\" " . str_replace("\\", "/", $im_dest_file) . " " . str_replace("\\", "/", $im_dest_file);
                    exec("\"{$cmd}\"", $output, $retval);
                } else {
                    $cmd = "{$CONFIG['impath']}composite -dissolve {$CONFIG['watermark_transparency']} -gravity {$CONFIG['where_put_watermark']} {$wm_file} {$im_dest_file} {$im_dest_file}";
                    exec($cmd, $output, $retval);
                }
            }
            if ($retval) {
                $ERROR = "Error executing ImageMagick - Return value: {$retval}";
                if ($CONFIG['debug_mode']) {
                    // Re-execute the command with the backtick operator in order to get all outputs
                    // will not work is safe mode is enabled
                    $output = `{$cmd} 2>&1`;
                    $ERROR .= "<br /><br /><div align=\"left\">Cmd line : <br /><span style=\"font-size:120%\">" . nl2br(htmlspecialchars($cmd)) . "</span></div>";
                    $ERROR .= "<br /><br /><div align=\"left\">The convert program said:<br /><span style=\"font-size:120%\">";
                    $ERROR .= nl2br(htmlspecialchars($output));
                    $ERROR .= "</span></div>";
                }
                @unlink($dest_file);
                return array('error' => $ERROR);
            }
            break;
        case "gd1":
            if (!function_exists('imagecreatefromjpeg')) {
                return array('error' => 'PHP running on your server does not support the GD image library, check with your webhost if ImageMagick is installed', 'halt_upload' => 1);
            }
            if ($imginfo[2] == GIS_JPG) {
                $src_img = imagecreatefromjpeg($src_file);
            } else {
                $src_img = imagecreatefrompng($src_file);
            }
            if (!$src_img) {
                $ERROR = $lang_errors['invalid_image'];
                return array('error' => $ERROR);
            }
            $dst_img = imagecreate($destWidth, $destHeight);
            imagecopyresized($dst_img, $src_img, 0, 0, $xOffset, $yOffset, (int) $destWidth, (int) $destHeight, $srcWidth, $srcHeight);
            touch($dest_file);
            $fh = fopen($dest_file, 'w');
            fclose($fh);
            imagejpeg($dst_img, $dest_file, $CONFIG['jpeg_qual']);
            imagedestroy($src_img);
            imagedestroy($dst_img);
            break;
        case "gd2":
            if (!function_exists('imagecreatefromjpeg')) {
                return array('error' => 'PHP running on your server does not support the GD image library, check with your webhost if ImageMagick is installed', 'halt_upload' => 1);
            }
            if (!function_exists('imagecreatetruecolor')) {
                return array('error' => 'PHP running on your server does not support GD version 2.x, please switch to GD version 1.x on the admin page', 'halt_upload' => 1);
            }
            if ($imginfo[2] == GIS_GIF && $CONFIG['GIF_support'] == 1) {
                $src_img = imagecreatefromgif($src_file);
            } elseif ($imginfo[2] == GIS_JPG) {
                $src_img = imagecreatefromjpeg($src_file);
            } else {
                $src_img = imagecreatefrompng($src_file);
            }
            if (!$src_img) {
                $ERROR = $lang_errors['invalid_image'];
                //return false;
                return array('error' => $ERROR);
            }
            if ($imginfo[2] == GIS_GIF) {
                $dst_img = imagecreate($destWidth, $destHeight);
            } else {
                $dst_img = imagecreatetruecolor($destWidth, $destHeight);
                if ($imginfo[2] == GIS_PNG) {
                    imagealphablending($dst_img, false);
                }
            }
            imagecopyresampled($dst_img, $src_img, 0, 0, $xOffset, $yOffset, (int) $destWidth, (int) $destHeight, $srcWidth, $srcHeight);
            touch($dest_file);
            $fh = fopen($dest_file, 'w');
            fclose($fh);
            //sharpen the thumb
            if ($sharpen == 1 && $CONFIG['enable_unsharp'] == 1) {
                UnsharpMask($dst_img, $CONFIG['unsharp_amount'], $CONFIG['unsharp_radius'], $CONFIG['unsharp_threshold']);
            }
            if ($media_type != "false") {
                //if a manual thumb gets generated we watermark the thumb with the media type
                //we now need to get the absolute path to the thumb watermark files
                $path_parts = pathinfo($CONFIG['watermark_file']);
                $CONFIG['watermark_file'] = $path_parts["dirname"] . "/wm_" . $media_type . ".png";
            }
            if ($watermark == "true" || $media_type != "false") {
                //shrink watermark on intermediate images -> If I had known that this is that �%&# with the transparency preserve... grrr
                $wm_normal = (int) $CONFIG['reduce_watermark'];
                if ($wm_normal > $destWidth) {
                    $wm_resize = $destWidth / $wm_normal;
                    //load the original, huge sized logo (the one we want to size down)
                    $temp_logoImage = ImageCreateFromPNG($CONFIG['watermark_file']);
                    //get it's size
                    $temp_logoW = ImageSX($temp_logoImage);
                    $temp_logoH = ImageSY($temp_logoImage);
                    //calculate new size
                    $logoW = (int) ($temp_logoW * $wm_resize);
                    $logoH = (int) ($temp_logoH * $wm_resize);
                    //we create a new, resized logo
                    $logoImage = imagecreatetruecolor($logoW, $logoH);
                    //just to be sure that transparency gets preserved
                    imagealphablending($logoImage, FALSE);
                    imagealphablending($temp_logoImage, TRUE);
                    //now copy and resize the big one into the temp resized img
                    imagecopyresampled($logoImage, $temp_logoImage, 0, 0, 0, 0, (int) $logoW, (int) $logoH, $temp_logoW, $temp_logoH);
                    //we do not need the temp (huge) watermark anymore
                    imagedestroy($temp_logoImage);
                } else {
                    // shrink not enabled or no intermediate...
                    $logoImage = ImageCreateFromPNG($CONFIG['watermark_file']);
                    $logoW = ImageSX($logoImage);
                    $logoH = ImageSY($logoImage);
                }
                //where is the watermark displayed...
                $pos = $CONFIG['where_put_watermark'];
                if ($pos == "northwest") {
                    $src_x = 5;
                    $src_y = 5;
                } else {
                    if ($pos == "northeast") {
                        $src_x = $destWidth - ($logoW + 5);
                        $src_y = 5;
                    } else {
                        if ($pos == "southwest") {
                            $src_x = 5;
                            $src_y = $destHeight - ($logoH + 5);
                        } else {
                            if ($pos == "southeast") {
                                $src_x = $destWidth - ($logoW + 5);
                                $src_y = $destHeight - ($logoH + 5);
                            } else {
                                if ($pos == "center") {
                                    $src_x = $destWidth / 2 - $logoW / 2;
                                    $src_y = $destHeight / 2 - $logoH / 2;
                                }
                            }
                        }
                    }
                }
                imagealphablending($dst_img, TRUE);
                imagecolortransparent($logoImage, imagecolorat($logoImage, $CONFIG['watermark_transparency_featherx'], $CONFIG['watermark_transparency_feathery']));
                ImageCopy($dst_img, $logoImage, $src_x, $src_y, 0, 0, $logoW, $logoH);
            }
            if ($imginfo[2] == GIS_PNG) {
                imagesavealpha($dst_img, true);
                imagepng($dst_img, $dest_file, round((100 - $CONFIG['jpeg_qual']) / 10));
            } else {
                imagejpeg($dst_img, $dest_file, $CONFIG['jpeg_qual']);
            }
            imagedestroy($src_img);
            imagedestroy($dst_img);
            break;
    }
    // Set mode of uploaded picture
    @chmod($dest_file, octdec($CONFIG['default_file_mode']));
    //silence the output in case chmod is disabled
    // We check that the image is valid
    $imginfo = cpg_getimagesize($dest_file);
    if ($imginfo == null) {
        $ERROR = $lang_errors['resize_failed'];
        @unlink($dest_file);
        //return false;
        return array('error' => $ERROR);
    } else {
        return true;
    }
}
Пример #25
0
function exif_parse_file($filename)
{
    global $CONFIG, $lang_picinfo;
    //String containing all the available exif tags.
    $exif_info = "AFFocusPosition|Adapter|ColorMode|ColorSpace|ComponentsConfiguration|CompressedBitsPerPixel|Contrast|CustomerRender|DateTimeOriginal|DateTimedigitized|DigitalZoom|DigitalZoomRatio|ExifImageHeight|ExifImageWidth|ExifInteroperabilityOffset|ExifOffset|ExifVersion|ExposureBiasValue|ExposureMode|ExposureProgram|ExposureTime|FNumber|FileSource|Flash|FlashPixVersion|FlashSetting|FocalLength|FocusMode|GainControl|IFD1Offset|ISOSelection|ISOSetting|ISOSpeedRatings|ImageAdjustment|ImageDescription|ImageSharpening|LightSource|Make|ManualFocusDistance|MaxApertureValue|MeteringMode|Model|NoiseReduction|Orientation|Quality|ResolutionUnit|Saturation|SceneCaptureMode|SceneType|Sharpness|Software|WhiteBalance|YCbCrPositioning|xResolution|yResolution";
    if (!is_readable($filename)) {
        return false;
    }
    $size = cpg_getimagesize($filename);
    if ($size[2] != 2) {
        return false;
    }
    // Not a JPEG file
    $exifRawData = explode("|", $exif_info);
    $exifCurrentData = explode("|", $CONFIG['show_which_exif']);
    //Let's build the string of current exif values to be shown
    $showExifStr = "";
    foreach ($exifRawData as $key => $val) {
        if ($exifCurrentData[$key] == 1) {
            $showExifStr .= "|" . $val;
        }
    }
    //Check if we have the data of the said file in the table
    $sql = "SELECT * FROM {$CONFIG['TABLE_EXIF']} " . "WHERE filename = '" . addslashes($filename) . "'";
    $result = cpg_db_query($sql);
    if (mysql_num_rows($result) > 0) {
        $row = mysql_fetch_array($result);
        mysql_free_result($result);
        $exifRawData = unserialize($row["exifData"]);
    } else {
        // No data in the table - read it from the image file
        // Get the file name
        $file = basename($filename);
        // Get the path
        $path = dirname($filename);
        // Path to original file (without watermark)
        $orig_file = $path . '/' . $CONFIG['orig_pfx'] . $file;
        // Check whether original file exists
        if (file_exists($orig_file)) {
            // If original file is there then read exif data from it.
            $exifRawData = read_exif_data_raw($orig_file, 0);
        } else {
            $exifRawData = read_exif_data_raw($filename, 0);
        }
        // Insert it into table for future reference
        $sql = "INSERT INTO {$CONFIG['TABLE_EXIF']} " . "VALUES ('" . addslashes($filename) . "', '" . addslashes(serialize($exifRawData)) . "')";
        $result = cpg_db_query($sql);
    }
    $exif = array();
    if (is_array($exifRawData['IFD0'])) {
        $exif = array_merge($exif, $exifRawData['IFD0']);
    }
    if (is_array($exifRawData['SubIFD'])) {
        $exif = array_merge($exif, $exifRawData['SubIFD']);
    }
    if (is_array($exifRawData['SubIFD']['MakerNote'])) {
        $exif = array_merge($exif, $exifRawData['SubIFD']['MakerNote']);
    }
    $exif['IFD1OffSet'] = $exifRawData['IFD1OffSet'];
    $exifParsed = array();
    foreach ($exif as $key => $val) {
        if (strpos($showExifStr, "|" . $key) && isset($val)) {
            $exifParsed[$lang_picinfo[$key]] = $val;
            //$exifParsed[$key] = $val;
        }
    }
    ksort($exifParsed);
    return $exifParsed;
}