示例#1
0
/**
* This function deletes all images in a category and the category
*/
function delete_category()
{
    global $xoopsSecurity;
    $id = rmc_server_var($_GET, 'id', 0);
    if (!$xoopsSecurity->check()) {
        redirectMsg('images.php?action=showcats', __('Operation not allowed!', 'rmcommon'), 1);
        die;
    }
    if ($id <= 0) {
        redirectMsg('images.php?action=showcats', __('Category ID not provided', 'rmcommon'), 1);
        die;
    }
    $cat = new RMImageCategory($id);
    if ($cat->isNew()) {
        redirectMsg('images.php?action=showcats', __('Category not found', 'rmcommon'), 1);
        die;
    }
    $sizes = array();
    foreach ($cat->getVar('sizes') as $size) {
        if ($size['width'] <= 0) {
            continue;
        }
        $sizes[] = '_' . $size['width'] . 'x' . $size['height'];
    }
    $db = Database::getInstance();
    $sql = "SELECT * FROM " . $db->prefix("rmc_images") . " WHERE cat='" . $cat->id() . "'";
    $result = $db->query($sql);
    while ($row = $db->fetchArray($result)) {
        $image = new RMImage();
        $image->assignVars($row);
        $updir = XOOPS_UPLOAD_PATH . '/' . date('Y', $image->getVar('date')) . '/' . date('m', time());
        $fd = pathinfo($image->getVar('file'));
        foreach ($sizes as $size) {
            $file = $updir . '/sizes/' . $fd['filename'] . $size . '.' . $fd['extension'];
            @unlink($file);
        }
        $file = $updir . '/' . $image->getVar('file');
        @unlink($file);
        $image->delete();
    }
    if ($cat->delete()) {
        redirectMsg('images.php?action=showcats', __('Category deleted successfully!', 'rmcommon'), 0);
    } else {
        redirectMsg('images.php?action=showcats', __('Errors ocurred while deleting the category', 'rmcommon') . '<br />' . $cat->errors(), 0);
    }
}
示例#2
0
 $category = $cat;
 $sizes = $category->getVar('sizes');
 $current_size = array();
 foreach ($sizes as $size) {
     if (empty($current_size)) {
         $current_size = $size;
     } else {
         if ($current_size['width'] >= $size['width'] && $size['width'] > 0) {
             $current_size = $size;
         }
     }
 }
 $mimes = (include XOOPS_ROOT_PATH . '/include/mimetypes.inc.php');
 while ($row = $db->fetchArray($result)) {
     $img = new RMImage();
     $img->assignVars($row);
     if (!isset($categories[$img->getVar('cat')])) {
         $categories[$img->getVar('cat')] = new RMImageCategory($img->getVar('cat'));
     }
     if (!isset($authors[$img->getVar('uid')])) {
         $authors[$img->getVar('uid')] = new XoopsUser($img->getVar('uid'));
     }
     $fd = pathinfo($img->getVar('file'));
     $filesurl = XOOPS_UPLOAD_URL . '/' . date('Y', $img->getVar('date')) . '/' . date('m', $img->getVar('date'));
     $thumb = date('Y', $img->getVar('date')) . '/' . date('m', $img->getVar('date')) . '/sizes/' . $fd['filename'] . '_' . $current_size['width'] . 'x' . $current_size['height'] . '.' . $fd['extension'];
     if (!file_exists(XOOPS_UPLOAD_PATH . '/' . $thumb)) {
         $thumb = date('Y', $img->getVar('date')) . '/' . date('m', $img->getVar('date')) . '/' . $fd['filename'] . '.' . $fd['extension'];
     }
     $ret = array('id' => $img->id(), 'title' => $img->getVar('title'), 'date' => formatTimestamp($img->getVar('date'), 'l'), 'desc' => $img->getVar('desc', 'n'), 'cat' => $categories[$img->getVar('cat')]->getVar('name'), 'author' => $authors[$img->getVar('uid')], 'thumb' => XOOPS_UPLOAD_URL . '/' . $thumb, 'url' => $filesurl, 'file' => $fd['filename'], 'extension' => $fd['extension'], 'mime' => isset($mimes[$fd['extension']]) ? $mimes[$fd['extension']] : 'application/octet-stream', 'links' => array('file' => array('caption' => __('File URL', 'rmcommon'), 'value' => XOOPS_UPLOAD_URL . '/' . date('Y', $img->getVar('date')) . '/' . date('m', $img->getVar('date')) . '/' . $img->getVar('file')), 'none' => array('caption' => __('None', 'rmcommon'), 'value' => '')));
     $images[] = RMEvents::get()->run_event('rmcommon.loading.single.editorimgs', $ret, rmc_server_var($_REQUEST, 'url', ''));
 }