Ejemplo n.º 1
0
function txGalleryApprove()
{
    global $DB, $json, $C;
    VerifyPrivileges(P_GALLERY_MODIFY, TRUE);
    $t = new Template();
    $t->assign_by_ref('config', $C);
    $result = GetWhichGalleries();
    $amount = 0;
    while ($gallery = $DB->NextRow($result)) {
        if ($gallery['status'] == 'pending' || $gallery['status'] == 'unconfirmed') {
            $gallery['status'] = 'approved';
            $gallery['date_approved'] = MYSQL_NOW;
            $gallery['administrator'] = $_SERVER['REMOTE_USER'];
            // Mark the gallery as approved
            if ($_REQUEST['framed']) {
                $gallery = array_merge($gallery, $_REQUEST);
                $gallery['categories'] = CategoryTagsFromIds($gallery['categories']);
                if (!preg_match(RE_DATETIME, $gallery['date_scheduled'])) {
                    $gallery['date_scheduled'] = '';
                }
                if (!preg_match(RE_DATETIME, $gallery['date_deletion'])) {
                    $gallery['date_deletion'] = '';
                }
                NullIfEmpty($gallery['date_scheduled']);
                NullIfEmpty($gallery['date_deletion']);
                $DB->Update('UPDATE `tx_galleries` SET ' . '`gallery_url`=?, ' . '`description`=?, ' . '`keywords`=?, ' . '`thumbnails`=?, ' . '`nickname`=?, ' . '`weight`=?, ' . '`sponsor_id`=?, ' . '`type`=?, ' . '`format`=?, ' . '`status`=?, ' . '`date_approved`=?, ' . '`date_scheduled`=?, ' . '`date_deletion`=?, ' . '`administrator`=?, ' . '`allow_scan`=?, ' . '`allow_preview`=?, ' . '`tags`=?, ' . '`categories`=? ' . 'WHERE `gallery_id`=?', array($gallery['gallery_url'], $gallery['description'], $gallery['keywords'], $gallery['thumbnails'], $gallery['nickname'], $gallery['weight'], $gallery['sponsor_id'], $gallery['type'], $gallery['format'], $gallery['status'], $gallery['date_approved'], $gallery['date_scheduled'], $gallery['date_deletion'], $gallery['administrator'], intval($gallery['allow_scan']), intval($gallery['allow_preview']), $gallery['tags'], $gallery['categories'], $gallery['gallery_id']));
                // Update user defined fields
                UserDefinedUpdate('tx_gallery_fields', 'tx_gallery_field_defs', 'gallery_id', $gallery['gallery_id'], $gallery);
                // Update icons
                $DB->Update('DELETE FROM `tx_gallery_icons` WHERE `gallery_id`=?', array($gallery['gallery_id']));
                if (is_array($_REQUEST['icons'])) {
                    foreach ($_REQUEST['icons'] as $icon) {
                        $DB->Update('INSERT INTO `tx_gallery_icons` VALUES (?,?)', array($gallery['gallery_id'], $icon));
                    }
                }
            } else {
                $DB->Update('UPDATE `tx_galleries` SET `status`=?,`date_approved`=?,`administrator`=? WHERE `gallery_id`=?', array($gallery['status'], $gallery['date_approved'], $gallery['administrator'], $gallery['gallery_id']));
            }
            // Send approval e-mail if option is enabled
            if ($C['email_on_approval'] && $gallery['email'] != $C['from_email']) {
                $t->assign_by_ref('gallery', $gallery);
                SendMail($gallery['email'], 'email-gallery-approved.tpl', $t);
            }
            $amount++;
        }
    }
    $DB->Free($result);
    // Update administrator count of galleries approved
    $DB->Update('UPDATE `tx_administrators` SET `approved`=`approved`+? WHERE `username`=?', array($amount, $_SERVER['REMOTE_USER']));
    echo $json->encode(array('status' => JSON_SUCCESS, 'message' => "{$amount} galler" . ($amount == 1 ? 'y has' : 'ies have') . " been approved"));
}
Ejemplo n.º 2
0
function txGalleryEdit()
{
    global $DB, $C;
    VerifyPrivileges(P_GALLERY_MODIFY);
    $v = new Validator();
    $v->Register($_REQUEST['email'], V_EMAIL, 'The E-mail Address is not properly formatted');
    $v->Register($_REQUEST['gallery_url'], V_URL, 'The Gallery URL is not properly formatted');
    $v->Register($_REQUEST['date_scheduled'], V_DATETIME, 'The Scheduled Date is not properly formatted');
    $v->Register($_REQUEST['date_deletion'], V_DATETIME, 'The Delete Date is not properly formatted');
    if ($_REQUEST['status'] == 'used' || $_REQUEST['status'] == 'holding') {
        $v->Register($_REQUEST['date_displayed'], V_EMPTY, 'The Displayed Date must be filled in');
        $v->Register($_REQUEST['date_displayed'], V_DATETIME, 'The Displayed Date is not properly formatted');
    }
    if (!IsEmptyString($_REQUEST['partner'])) {
        $partner = $DB->Row('SELECT * FROM `tx_partners` WHERE `username`=?', array($_REQUEST['partner']));
        if (!$partner) {
            $v->SetError('The Partner username you entered does not match an existing partner account');
        }
    }
    // Check tags for proper format
    if (!IsEmptyString($_REQUEST['tags'])) {
        $_REQUEST['tags'] = FormatSpaceSeparated($_REQUEST['tags']);
        foreach (explode(' ', $_REQUEST['tags']) as $tag) {
            if (strlen($tag) < 4 || !preg_match('~^[a-z0-9_]+$~i', $tag)) {
                $v->SetError('All tags must be at least 4 characters in length and contain only letters, numbers, and underscores');
                break;
            }
        }
    }
    if (!$v->Validate()) {
        return $v->ValidationError('txShGalleryEdit');
    }
    NullIfEmpty($_REQUEST['date_scheduled']);
    NullIfEmpty($_REQUEST['date_displayed']);
    NullIfEmpty($_REQUEST['date_deletion']);
    // Update gallery data
    $DB->Update('UPDATE `tx_galleries` SET ' . '`gallery_url`=?, ' . '`description`=?, ' . '`keywords`=?, ' . '`thumbnails`=?, ' . '`email`=?, ' . '`nickname`=?, ' . '`weight`=?, ' . '`clicks`=?, ' . '`submit_ip`=?, ' . '`sponsor_id`=?, ' . '`type`=?, ' . '`format`=?, ' . '`status`=?, ' . '`date_scheduled`=?, ' . '`date_displayed`=?, ' . '`date_deletion`=?, ' . '`partner`=?, ' . '`allow_scan`=?, ' . '`allow_preview`=?, ' . '`tags`=?, ' . '`categories`=? ' . 'WHERE `gallery_id`=?', array($_REQUEST['gallery_url'], $_REQUEST['description'], FormatSpaceSeparated($_REQUEST['keywords']), $_REQUEST['thumbnails'], $_REQUEST['email'], $_REQUEST['nickname'], $_REQUEST['weight'], $_REQUEST['clicks'], $_REQUEST['submit_ip'], $_REQUEST['sponsor_id'], $_REQUEST['type'], $_REQUEST['format'], $_REQUEST['status'], $_REQUEST['date_scheduled'], $_REQUEST['date_displayed'], $_REQUEST['date_deletion'], $_REQUEST['partner'], intval($_REQUEST['allow_scan']), intval($_REQUEST['allow_preview']), FormatSpaceSeparated($_REQUEST['tags']), CategoryTagsFromIds($_REQUEST['categories']), $_REQUEST['gallery_id']));
    // Update user defined fields
    UserDefinedUpdate('tx_gallery_fields', 'tx_gallery_field_defs', 'gallery_id', $_REQUEST['gallery_id'], $_REQUEST);
    // Update icons
    $DB->Update('DELETE FROM `tx_gallery_icons` WHERE `gallery_id`=?', array($_REQUEST['gallery_id']));
    if (is_array($_REQUEST['icons'])) {
        foreach ($_REQUEST['icons'] as $icon_id) {
            $DB->Update('INSERT INTO `tx_gallery_icons` VALUES (?,?)', array($_REQUEST['gallery_id'], $icon_id));
        }
    }
    $GLOBALS['message'] = 'Gallery successfully updated';
    $GLOBALS['added'] = true;
    txShGalleryEdit();
}