Beispiel #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);
    }
}
Beispiel #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;
            }
        }
    }
    while ($row = $db->fetchArray($result)) {
        $img = new RMImage();
        $img->assignVars($row);
        $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['name'] . '.' . $fd['extension'];
        if (!file_exists(XOOPS_UPLOAD_PATH . '/' . $thumb)) {
            $thumb = date('Y', $img->getVar('date')) . '/' . date('m', $img->getVar('date')) . '/' . $fd['filename'] . '.' . $fd['extension'];
        }
        $images[] = array('id' => $img->id(), 'title' => $img->getVar('title'), 'thumb' => XOOPS_UPLOAD_URL . '/' . $thumb);
    }
    include RMTemplate::get()->get_template('rmc-images-list-editor.php', 'module', 'rmcommon');
} elseif ($action == 'image-details') {
    function images_send_json($data)
    {
        header('Cache-Control: no-cache, must-revalidate');
        header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
        header('Content-type: application/json');
        echo json_encode($data);
 $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', ''));
 }
 include RMTemplate::get()->get_template('images_list_editor.php', 'module', 'rmcommon');
Beispiel #4
0
 /**
  * Get an image from image manager
  * @param $id int Image id
  * @param string Size name from category
  */
 function get_image($id, $size = '')
 {
     if ($id <= 0) {
         return false;
     }
     $img = new RMImage($id);
     if ($img->isNew()) {
         return false;
     }
     $cat = new RMImageCategory($img->getVar('cat'));
     $sizes = $cat->getVar('sizes');
     foreach ($sizes as $s) {
         if ($s['name'] == $size) {
             break;
         }
     }
     $date = explode('-', date('d-m-Y', $img->getVar('date')));
     $file = XOOPS_UPLOAD_URL . '/' . $date[2] . '/' . $date[1] . '/';
     if ($size == '') {
         $file .= $img->getVar('file');
         return $file;
     }
     $file .= 'sizes/' . substr($img->getVar('file'), 0, -4) . '_' . $s['width'] . 'x' . $s['height'] . substr($img->getVar('file'), -4);
     if (!is_file(str_replace(XOOPS_URL, XOOPS_ROOT_PATH, $file))) {
         return $img->getOriginal();
     }
     return $file;
 }