function get_logpics($purpose, $userid = 0, $cacheid = 0)
{
    global $login;
    $fields = "`pics`.`uuid` AS `pic_uuid`, `pics`.`url` AS `pic_url`,\n\t\t\t            `pics`.`title`, `pics`.`date_created`,\n\t\t\t            `logs`.`user_id`, `logs`.`cache_id`,\n\t\t\t            `logs`.`date` AS `logdate`, `pics`.`date_created` < LEFT(NOW(),4) AS `oldyear`,\n\t\t\t\t\t\t\t\t\t`logs`.`id` AS `logid`, `logs`.`type` AS `logtype`";
    $join_logs = "INNER JOIN `cache_logs` `logs` ON `logs`.`id`=`pics`.`object_id`";
    $join_caches = "INNER JOIN `caches` ON `caches`.`cache_id`=`logs`.`cache_id`";
    $join_cachestatus = "INNER JOIN `cache_status` ON `caches`.`status`=`cache_status`.`id` AND `allow_user_view`=1";
    $join_user = "******";
    $rs = false;
    switch ($purpose) {
        case LOGPICS_FOR_STARTPAGE_GALLERY:
            // one pic per user and day,
            // one pic per cache and day
            // no spoilers, no bad data, no invisible or unpublished caches
            // The group-by via nested query make this whole thing sufficiently performant.
            // Direct group-bys combined with the wheres are awful slow, and no kind of
            // index seems to be good enough to speed it up.
            // Indexing the for the inner WHERE seems rather useless, as it filters out
            // only a few percent of caches. We must rely on fast data caching.
            $rs = sql_slave("SELECT {$fields}, `user`.`username`, `pics`.`date_created` AS `picdate`\n\t\t\t\t   FROM (SELECT * FROM\n\t\t\t\t            (SELECT `uuid`, `url`, `title`, `date_created`, `object_id` FROM `pictures`\n  \t\t               WHERE `local`=1 AND `display`=1 AND `spoiler`=0 AND `unknown_format`=0\n\t                \t       AND `object_type`=1\n\t                   ORDER BY `date_created` DESC\n\t\t                 LIMIT 240) `piics`\n\t\t\t\t  \t\t\t     /* 20 times reserve for filtering out user dups, cache dups and invisibles */\n                    GROUP BY `object_id`, LEFT(`date_created`,10)) `pics`   /* max. 1 pic per cache and day */\n           {$join_logs}\n           {$join_caches}\n           {$join_cachestatus}\n           {$join_user}\n           GROUP BY `user`.`user_id`, LEFT(`pics`.`date_created`,10)  /* max. 1 pic per user and day */\n\t         ORDER BY `pics`.`date_created` DESC\n\t\t\t\t\t LIMIT 6");
            break;
        case LOGPICS_FOR_NEWPICS_GALLERY:
            // like above, without the "one pic per cache and day" condition
            // This saves us one grouped subquery.
            $rs = sql_slave("SELECT {$fields}, `user`.`username`, `pics`.`date_created` AS `picdate`\n             FROM (SELECT `uuid`, `url`, `title`, `date_created`, `object_id` FROM `pictures`\n\t\t\t\t\t\t\t\t        WHERE `local`=1 AND `display`=1 AND `spoiler`=0 AND `unknown_format`=0\n\t\t\t                        AND `object_type`=1\n\t\t  \t             ORDER BY `date_created` DESC\n\t\t\t                  LIMIT 600) `pics`\n\t\t\t                  /* 10 times reserve for filtering out user dups and invisibles */\n    \t       {$join_logs}\n    \t       {$join_caches}\n    \t       {$join_cachestatus}\n    \t       {$join_user}\n\t\t\t       GROUP BY `user`.`user_id`, LEFT(`pics`.`date_created`,10)\n\t\t\t       ORDER BY `date_created` DESC\n\t\t\t\t\t\t\t    LIMIT &1", MAX_PICTURES_PER_GALLERY_PAGE);
            break;
        case LOGPICS_FOR_USER_STAT:
            // just count all the logpics of one user
            // It's faster, sensible and consistend with cache and log handling to count
            // also invisible data here. Actually, it is present, the pic was made and
            // uploaded with a log, and it is still visible for the logger himself
            // (and hopfully some time for all, independend of the invisible listing!).
            $result = sql_value_slave("SELECT COUNT(*)\n\t\t             FROM `pictures` `pics`\n\t\t\t           {$join_logs}\n\t\t\t\t\t      WHERE `pics`.`object_type`=1 AND `logs`.`user_id`='&1'", 0, $userid);
            break;
        case LOGPICS_FOR_USER_GALLERY:
            // all pics of one user, except spoilers and invisibles
            $rs = sql("SELECT {$fields}, `logs`.`date` AS `picdate`\n\t\t\t      \t       FROM `pictures` `pics`\n\t\t                 {$join_logs}\n\t\t                 {$join_caches}\n\t\t                 {$join_cachestatus}\n\t\t                WHERE `object_type`=1 AND `logs`.`user_id`='&1' AND NOT `spoiler`\n\t\t\t\t         ORDER BY `logs`.`date` DESC", $userid);
            break;
        case LOGPICS_FOR_MYHOME_GALLERY:
            // all picture of one user, with the only exception of zombie pix hanging
            // by an old log deletion (we should remove those ...)
            $rs = sql("SELECT {$fields}, `logs`.`date` AS `picdate`\n\t                   FROM `pictures` AS `pics`\n                     {$join_logs}\n                    WHERE `object_type`=1 AND `logs`.`user_id`='&1' \n                 ORDER BY `logs`.`date` DESC", $login->userid);
            break;
        case LOGPICS_FOR_CACHE_STAT:
            // all pictures for a cache except license-replacement pics
            // need not to exclude invisible caches, as this is only displayed in listing view
            $result = sql_value("SELECT COUNT(*)\n\t\t\t\t             FROM `pictures` AS `pics`\n\t\t\t\t             {$join_logs}\n\t\t\t\t             {$join_user}\n                    WHERE `object_type`=1 AND `logs`.`cache_id`='&1'\n\t\t\t\t\t\t\t\t\t\t  AND NOT (`data_license` IN ('&2','&3'))", 0, $cacheid, NEW_DATA_LICENSE_ACTIVELY_DECLINED, NEW_DATA_LICENSE_PASSIVELY_DECLINED);
            break;
        case LOGPICS_FOR_CACHE_GALLERY:
            // all picture for a cache except license-replacement pics
            // for all users except owner: also excluding invisble caches
            $rs = sql("SELECT {$fields}, `user`.`username`, `logs`.`date` AS `picdate`\n\t                   FROM `pictures` AS `pics`\n\t                   {$join_logs} " . ($userid == $login->userid ? "" : "{$join_caches} {$join_cachestatus}") . "\n\t                   {$join_user}\n                    WHERE `object_type`=1 AND `logs`.`cache_id`='&1'\n\t\t\t\t\t\t\t\t\t\t  AND NOT (`data_license` IN ('&2','&3'))\n                 ORDER BY `logs`.`date` DESC", $cacheid, NEW_DATA_LICENSE_ACTIVELY_DECLINED, NEW_DATA_LICENSE_PASSIVELY_DECLINED);
            break;
        default:
            global $tpl;
            $tpl->error(ERROR_INVALID_OPERATION);
            return null;
    }
    if ($rs !== false) {
        $result = sql_fetch_assoc_table($rs);
        foreach ($result as &$logpic) {
            $logpic['pic_url'] = use_current_protocol($logpic['pic_url']);
        }
    }
    return $result;
}
Exemple #2
0
                break;
            case 'bmp':
                imagebmp($thumbimage, $savedir . '/' . $filename);
                break;
        }
        sql("UPDATE `pictures` SET `thumb_last_generated`=NOW(), `thumb_url`='&1' WHERE `uuid`='&2'", $opt['logic']['pictures']['thumb_url'] . '/' . mb_substr($filename, 0, 1) . '/' . mb_substr($filename, 1, 1) . '/' . $filename, $r['uuid']);
        if ($debug == 1) {
            die($opt['logic']['pictures']['thumb_url'] . '/' . $filename);
        } else {
            $tpl->redirect(use_current_protocol($opt['logic']['pictures']['thumb_url'] . '/' . mb_substr($filename, 0, 1) . '/' . mb_substr($filename, 1, 1) . '/' . $filename));
        }
    } else {
        if ($debug == 1) {
            die($r['thumb_url']);
        } else {
            $tpl->redirect(use_current_protocol($r['thumb_url']));
        }
    }
} else {
    if ($debug == 1) {
        die('Debug: line ' . __LINE__);
    } else {
        $tpl->redirect(thumbpath('404', $default_object_type));
    }
}
function thumbpath($name, $object_type)
{
    global $opt, $default_object_type;
    if (!in_array($name, ['404', 'intern', 'extern', 'spoiler', 'unknown']) || $object_type != 1 && $object_type != 2) {
        if ($debug == 1) {
            die('Debug: line ' . __LINE__);
 *
 *  Unicode Reminder メモ
 ***************************************************************************/
require './lib2/web.inc.php';
$tpl->name = 'imagebrowser';
$tpl->popup = true;
$login->verify();
$cacheid = isset($_REQUEST['cacheid']) ? $_REQUEST['cacheid'] + 0 : 0;
$rs = sql("SELECT `caches`.`name`\n    FROM `caches`\n    INNER JOIN `cache_status` ON `caches`.`status`=`cache_status`.`id`\n    WHERE `caches`.`user_id`='&1'\n    AND `cache_id`='&2'", $login->userid, $cacheid);
$rCache = sql_fetch_assoc($rs);
sql_free_result($rs);
if ($rCache === false) {
    $tpl->error(ERROR_NO_ACCESS);
}
$tpl->assign('cachename', $rCache['name']);
$rsPictures = sql('SELECT `uuid`, `url`, `title`
    FROM `pictures` 
    WHERE `object_id`=&1
    AND `object_type`=2
    ORDER BY `seq`', $cacheid);
$pictures = array();
while ($rPicture = sql_fetch_assoc($rsPictures)) {
    // TinyMCE will create a relative link only of the protocol of the image URL matches.
    // This also avoides MSIE warnings in https mode.
    $rPicture['url'] = use_current_protocol($rPicture['url']);
    $pictures[] = $rPicture;
}
$tpl->assign('pictures', $pictures);
sql_free_result($rsPictures);
$tpl->assign('thumbwidth', $opt['logic']['pictures']['thumb_max_width']);
$tpl->display();