Esempio n. 1
0
 function delete($record_id = null)
 {
     global $wpdb;
     if (!empty($record_id) && ($record = $this->find(array('id' => $record_id)))) {
         $query = "DELETE FROM `" . $this->table . "` WHERE `id` = '" . $record_id . "' LIMIT 1";
         if ($wpdb->query($query)) {
             switch ($this->model) {
                 case 'Gallery':
                     $query = "DELETE FROM `" . $wpdb->prefix . strtolower($this->pre) . "_galleriesslides` WHERE `gallery_id` = '" . $record_id . "'";
                     $wpdb->query($query);
                     break;
                 case 'Slide':
                     $imagepath = GalleryHtmlHelper::uploads_path() . DS . $this->plugin_name . DS . $record->image;
                     @unlink($imagepath);
                     $query = "DELETE FROM `" . $wpdb->prefix . strtolower($this->pre) . "_galleriesslides` WHERE `slide_id` = '" . $record_id . "'";
                     $wpdb->query($query);
                     break;
             }
             return true;
         }
     }
     return false;
 }
Esempio n. 2
0
if (!empty($this->Slide->data->type) && $this->Slide->data->type == "file") {
    if (!empty($this->Slide->data->image)) {
        ?>
                                    
                                    <input type="hidden" name="Slide[image_oldfile]" value="<?php 
        echo esc_attr(stripslashes($this->Slide->data->image));
        ?>
" />
                                    <p><small><?php 
        _e('Current image. Leave the field above blank to keep this image.', $this->plugin_name);
        ?>
</small></p>
									<?php 
        $imagespath = $this->get_option('imagespath');
        if (empty($imagespath)) {
            $image = GalleryHtmlHelper::uploads_path() . DS . $this->plugin_name . DS . $this->Slide->data->image;
        } else {
            $image = rtrim($imagespath, DS) . DS . $this->Slide->data->image;
        }
        ?>
                                    <p><a title="<?php 
        echo esc_attr($this->Slide->data->title);
        ?>
" class="colorbox" href="<?php 
        echo $this->Slide->data->image_path;
        ?>
"><img src="<?php 
        echo $this->Html->bfithumb_image_src($image, 100, 100, 100);
        ?>
" alt="" class="slideshow" /></a></p>
                                    
 function validate($data = null)
 {
     $this->errors = array();
     if (!empty($data)) {
         $data = empty($data[$this->model]) ? $data : $data[$this->model];
         $data = stripslashes_deep($data);
         extract($data, EXTR_SKIP);
         if (empty($title)) {
             $this->errors['title'] = __('Please fill in a title', $this->plugin_name);
         }
         if (empty($showinfo)) {
             $this->data->showinfo = "both";
         }
         if (empty($type)) {
             $this->errors['type'] = __('Please select an image type', $this->plugin_name);
         } elseif ($type == "media") {
             if (!empty($media_file) && !empty($attachment_id)) {
                 $imagename = basename($media_file);
                 $this->data->image = $imagename;
                 $this->data->image_path = $media_file;
                 $this->data->image_url = $media_file;
             } else {
                 $this->errors['media_file'] = __('Choose an image', $this->plugin_name);
             }
         } elseif ($type == "file") {
             if (!empty($image_oldfile) && empty($_FILES['image_file']['name'])) {
                 $imagename = $image_oldfile;
                 $imagepath = GalleryHtmlHelper::uploads_path() . DS . $this->plugin_name . DS;
                 $imagefull = $imagepath . $imagename;
                 $this->data->image = $imagename;
                 GalleryHtmlHelper::image_path($this->data);
             } else {
                 if ($_FILES['image_file']['error'] <= 0) {
                     $imagename = $_FILES['image_file']['name'];
                     $image_name = GalleryHtmlHelper::strip_ext($imagename, "name");
                     $image_ext = GalleryHtmlHelper::strip_ext($imagename, "ext");
                     $imagename = GalleryHtmlHelper::sanitize($image_name) . '.' . $image_ext;
                     $imagepath = GalleryHtmlHelper::uploads_path() . DS . $this->plugin_name . DS;
                     $imagefull = $imagepath . $imagename;
                     $issafe = false;
                     $mimes = get_allowed_mime_types();
                     foreach ($mimes as $type => $mime) {
                         if (strpos($type, $image_ext) !== false) {
                             $issafe = true;
                         }
                     }
                     if (empty($issafe) || $issafe == false) {
                         $this->errors['image_file'] = __('This file type is not allowed for security reasons', $this->plugin_name);
                     } else {
                         if (!is_uploaded_file($_FILES['image_file']['tmp_name'])) {
                             $this->errors['image_file'] = __('The image did not upload, please try again', $this->plugin_name);
                         } elseif (!move_uploaded_file($_FILES['image_file']['tmp_name'], $imagefull)) {
                             $this->errors['image_file'] = __('Image could not be moved from TMP to "wp-content/uploads/", please check permissions', $this->plugin_name);
                         } else {
                             @chmod($imagefull, 0644);
                             $this->data->image = $imagename;
                             GalleryHtmlHelper::image_path($this->data);
                         }
                     }
                 } else {
                     switch ($_FILES['image_file']['error']) {
                         case UPLOAD_ERR_INI_SIZE:
                         case UPLOAD_ERR_FORM_SIZE:
                             $this->errors['image_file'] = __('The image file is too large', $this->plugin_name);
                             break;
                         case UPLOAD_ERR_PARTIAL:
                             $this->errors['image_file'] = __('The image was partially uploaded, please try again', $this->plugin_name);
                             break;
                         case UPLOAD_ERR_NO_FILE:
                             $this->errors['image_file'] = __('No image was chosen for uploading, please choose an image', $this->plugin_name);
                             break;
                         case UPLOAD_ERR_NO_TMP_DIR:
                             $this->errors['image_file'] = __('No TMP directory has been specified for PHP to use, please ask your hosting provider', $this->plugin_name);
                             break;
                         case UPLOAD_ERR_CANT_WRITE:
                             $this->errors['image_file'] = __('Image cannot be written to disc, please ask your hosting provider', $this->plugin_name);
                             break;
                     }
                 }
             }
         } elseif ($type == "url") {
             if (empty($image_url)) {
                 $this->errors['image_url'] = __('Please specify an image', $this->plugin_name);
             } else {
                 if ($image = wp_remote_fopen(str_replace(" ", "%20", $image_url))) {
                     $filename = basename($image_url);
                     $file_name = GalleryHtmlHelper::strip_ext($filename, "name");
                     $file_ext = GalleryHtmlHelper::strip_ext($filename, "ext");
                     $filename = GalleryHtmlHelper::sanitize($file_name) . '.' . $file_ext;
                     $filepath = GalleryHtmlHelper::uploads_path() . DS . $this->plugin_name . DS;
                     $filefull = $filepath . $filename;
                     if (!file_exists($filefull)) {
                         $fh = @fopen($filefull, "w");
                         @fwrite($fh, $image);
                         @fclose($fh);
                     }
                 }
             }
         }
     } else {
         $this->errors[] = __('No data was posted', $this->plugin_name);
     }
     return $this->errors;
 }
Esempio n. 4
0
if (!empty($this->Slide->data->type) && $this->Slide->data->type == "file") {
    if (!empty($this->Slide->data->image)) {
        ?>
                                    
                                    <input type="hidden" name="Slide[image_oldfile]" value="<?php 
        echo esc_attr(stripslashes($this->Slide->data->image));
        ?>
" />
                                    <p><small><?php 
        _e('Current image. Leave the field above blank to keep this image.', $this->plugin_name);
        ?>
</small></p>
									<?php 
        $imagespath = $this->get_option('imagespath');
        if (empty($imagespath)) {
            $image = GalleryHtmlHelper::uploads_path() . DS . 'slideshow-gallery' . DS . $this->Slide->data->image;
        } else {
            $image = rtrim($imagespath, DS) . DS . $this->Slide->data->image;
        }
        ?>
                                    <p><a title="<?php 
        echo esc_attr($this->Slide->data->title);
        ?>
" class="colorbox" href="<?php 
        echo $this->Html->image_url($this->Slide->data->image);
        ?>
"><img src="<?php 
        echo $this->Html->bfithumb_image_src($image, 100, 100, 100);
        ?>
" alt="" class="slideshow" /></a></p>