function text($name = '', $args = array()) { $defaults = array('id' => empty($args['id']) ? $name : $args['id'], 'width' => '100%', 'class' => "widefat", 'error' => true, 'value' => empty($args['value']) ? GalleryHtmlHelper::field_value($name) : $args['value'], 'autocomplete' => "on"); $r = wp_parse_args($args, $defaults); extract($r, EXTR_SKIP); echo $this->Html->field_value($name); ob_start(); ?> <input class="<?php echo $class; ?> " type="text" autocomplete="<?php echo $autocomplete; ?> " style="width:<?php echo $width; ?> " name="<?php echo $this->Html->field_name($name); ?> " value="<?php echo $value; ?> " id="<?php echo $id; ?> " /><?php if ($error == true) { echo $this->Html->field_error($name); } $text = ob_get_clean(); return $text; }
function validate($data = null) { $this->errors = array(); if (!empty($data)) { $data = empty($data[$this->model]) ? $data : $data[$this->model]; foreach ($data as $dkey => $dval) { $this->data->{$dkey} = stripslashes($dval); } extract($data, EXTR_SKIP); if (empty($title)) { $this->errors['title'] = __('Please fill in a title', $this->plugin_name); } if (empty($description)) { $this->errors['description'] = __('Please fill in a description', $this->plugin_name); } if (empty($image_url)) { $this->errors['image_url'] = __('Please specify an image', $this->plugin_name); } else { if ($image = wp_remote_fopen($image_url)) { $filename = basename($image_url); $filepath = ABSPATH . 'wp-content' . DS . 'uploads' . DS . $this->plugin_name . DS; $filefull = $filepath . $filename; if (!file_exists($filefull)) { $fh = @fopen($filefull, "w"); @fwrite($fh, $image); @fclose($fh); $name = GalleryHtmlHelper::strip_ext($filename, 'filename'); $ext = GalleryHtmlHelper::strip_ext($filename, 'ext'); $thumbfull = $filepath . $name . '-thumb.' . $ext; $smallfull = $filepath . $name . '-small.' . $ext; image_resize($filefull, $width = null, $height = 75, $crop = false, $append = 'thumb', $dest = null, $quality = 100); image_resize($filefull, $width = 50, $height = 50, $crop = true, $append = 'small', $dest = null, $quality = 100); @chmod($filefull, 0777); @chmod($thumbfull, 0777); @chmod($smallfull, 0777); } } } } else { $this->errors[] = __('No data was posted', $this->plugin_name); } return $this->errors; }
function defaults() { $defaults = array('created' => GalleryHtmlHelper::gen_date(), 'modified' => GalleryHtmlHelper::gen_date()); return $defaults; }
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; }
/** * WHERE conditions * This should be an array * */ var $where = ''; /** * ORDER condition * */ var $order = array('modified', "DESC"); var $plugin_url = ''; var $sub = ''; var $parent = ''; var $allcount = 0; var $allRecords = array(); var $pagination = ''; function GalleryPaginate($table = '', $fields = '', $sub = '', $parent = '') { $this->sub = $sub; $this->parentd = $parent; if (!empty($table)) { $this->table = $table; } if (!empty($fields)) { $this->fields = $fields; } } function start_paging($page = '') { global $wpdb; $page = empty($page) ? 1 : $page; if (!empty($page)) { $this->page = $page; } if (!empty($this->fields)) { if (is_array($this->fields)) { $this->fields = implode(", ", $this->fields); } } $query = "SELECT " . $this->fields . " FROM `" . $this->table . "`"; $countquery = "SELECT COUNT(*) FROM `" . $this->table . "`"; //check if some conditions where passed. if (!empty($this->where)) { //append the "WHERE" command to the query $query .= " WHERE"; $countquery .= " WHERE"; $c = 1; foreach ($this->where as $key => $val) { if (!empty($val) && is_array($val)) { $k = 1; foreach ($val as $vkey => $vval) { if (eregi("LIKE", $val)) { $query .= " `" . $key . "` " . $vval . ""; $countquery .= " `" . $key . "` " . $vval . ""; } elseif (preg_match("/SE (.*)/si", $vval, $vmatches)) { if (!empty($vmatches[1])) { $query .= " `" . $key . "` <= " . $vmatches[1] . ""; $countquery .= " `" . $key . "` <= " . $vmatches[1] . ""; } } elseif (preg_match("/LE (.*)/si", $vval, $vmatches)) { if (!empty($vmatches[1])) { $query .= " `" . $key . "` >= " . $vmatches[1] . ""; $countquery .= " `" . $key . "` >= " . $vmatches[1] . ""; } } else { $query .= " `" . $key . "` = '" . $vval . "'"; $countquery .= " `" . $key . "` = '" . $vval . "'"; } if ($k < count($val)) { $query .= " AND"; $countquery .= " AND"; } $k++; $vmatches = false; } } else { if (eregi("LIKE", $val)) { $query .= " `" . $key . "` " . $val . ""; $countquery .= " `" . $key . "` " . $val . ""; } elseif (preg_match("/SE (.*)/si", $val, $vmatches)) { if (!empty($vmatches[1])) { $query .= " `" . $key . "` <= " . $vmatches[1] . ""; $countquery .= " `" . $key . "` <= " . $vmatches[1] . ""; } } elseif (preg_match("/LE (.*)/si", $val, $vmatches)) { if (!empty($vmatches[1])) { $query .= " `" . $key . "` >= " . $vmatches[1] . ""; $countquery .= " `" . $key . "` >= " . $vmatches[1] . ""; } } else { $query .= " `" . $key . "` = '" . $val . "'"; $countquery .= " `" . $key . "` = '" . $val . "'"; } if ($c < count($this->where)) { $query .= " AND"; $countquery .= " AND"; } $c++; $vmatches = false; }
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; }
</a> </th> <th><?php _e('Slides', $this->plugin_name); ?> </th> <th><?php _e('Shortcode', $this->plugin_name); ?> </th> <th class="column-modified <?php echo $orderby == "modified" ? 'sorted ' . $order : 'sortable desc'; ?> "> <a href="<?php echo GalleryHtmlHelper::retainquery('orderby=modified&order=' . ($orderby == "modified" ? $otherorder : "asc")); ?> "> <span><?php _e('Date', $this->plugin_name); ?> </span> <span class="sorting-indicator"></span> </a> </th> </tr> </tfoot> <tbody> <?php foreach ($galleries as $gallery) { ?>
public static function retainquery($add = null, $old_url = null, $endslash = true) { $url = empty($old_url) ? $_SERVER['REQUEST_URI'] : rtrim($old_url, '&'); $urls = @explode("?", $url); $add = ltrim($add, '&'); $url_parts = @parse_url($url); parse_str($url_parts['query'], $path_parts); $add = str_replace("&", "&", $add); parse_str($add, $add_parts); if (empty($path_parts) || !is_array($path_parts)) { $path_parts = array(); } if (!empty($add_parts) && is_array($add_parts)) { foreach ($add_parts as $addkey => $addvalue) { $path_parts[$addkey] = $addvalue; } } $querystring = GalleryHtmlHelper::queryString($path_parts); $urls[1] = preg_replace("/[\\&|\\?]Gallerymessage\\=([0-9a-z-_+]*)/i", "", $urls[1]); $urls[1] = preg_replace("/[\\&|\\?]page\\=/si", "", $urls[1]); $url = $urls[0]; $url .= '?'; if (!empty($querystring)) { $url .= '&' . $querystring; } return preg_replace("/\\?(\\&)?/si", "?", $url); }
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>
echo GalleryHtmlHelper::retainquery('orderby=modified&order=' . ($orderby == "modified" ? $otherorder : "asc")); ?> "> <span><?php _e('Date', $this->plugin_name); ?> </span> <span class="sorting-indicator"></span> </a> </th> <th class="column-order <?php echo $orderby == "order" ? 'sorted ' . $order : 'sortable desc'; ?> "> <a href="<?php echo GalleryHtmlHelper::retainquery('orderby=order&order=' . ($orderby == "order" ? $otherorder : "asc")); ?> "> <span><?php _e('Order', $this->plugin_name); ?> </span> <span class="sorting-indicator"></span> </a> </th> </tr> </tfoot> <tbody> <?php foreach ($slides as $slide) { ?>
function validate($data = null) { $this->errors = array(); if (!empty($data)) { $data = empty($data[$this->model]) ? $data : $data[$this->model]; foreach ($data as $dkey => $dval) { $this->data->{$dkey} = stripslashes($dval); } extract($data, EXTR_SKIP); if (empty($title)) { $this->errors['title'] = __('Please fill in a title', $this->plugin_name); } if (empty($description)) { $this->errors['description'] = __('Please fill in a description', $this->plugin_name); } if (empty($type)) { $this->errors['type'] = __('Please select an image type', $this->plugin_name); } elseif ($type == "file") { if (!empty($image_oldfile) && empty($_FILES['image_file']['name'])) { $imagename = $image_oldfile; $imagepath = ABSPATH . "wp-content" . DS . "uploads" . DS . $this->plugin_name . DS; $imagefull = $imagepath . $imagename; $this->data->image = $imagename; } else { if ($_FILES['image_file']['error'] <= 0) { $imagename = $_FILES['image_file']['name']; $imagepath = ABSPATH . 'wp-content' . DS . 'uploads' . DS . $this->plugin_name . DS; $imagefull = $imagepath . $imagename; 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 { $this->data->image = $imagename; $name = GalleryHtmlHelper::strip_ext($imagename, 'filename'); $ext = GalleryHtmlHelper::strip_ext($imagename, 'ext'); $thumbfull = $imagepath . $name . '-thumb.' . strtolower($ext); $smallfull = $imagepath . $name . '-small.' . strtolower($ext); image_resize($imagefull, $width = null, $height = 75, $crop = false, $append = 'thumb', $dest = null, $quality = 100); image_resize($imagefull, $width = 50, $height = 50, $crop = true, $append = 'small', $dest = null, $quality = 100); @chmod($imagefull, 0777); @chmod($thumbfull, 0777); @chmod($smallfull, 0777); } } 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($image_url)) { $filename = basename($image_url); $filepath = ABSPATH . 'wp-content' . DS . 'uploads' . DS . $this->plugin_name . DS; $filefull = $filepath . $filename; if (!file_exists($filefull)) { $fh = @fopen($filefull, "w"); @fwrite($fh, $image); @fclose($fh); $name = GalleryHtmlHelper::strip_ext($filename, 'filename'); $ext = GalleryHtmlHelper::strip_ext($filename, 'ext'); $thumbfull = $filepath . $name . '-thumb.' . strtolower($ext); $smallfull = $filepath . $name . '-small.' . strtolower($ext); image_resize($filefull, $width = null, $height = 75, $crop = false, $append = 'thumb', $dest = null, $quality = 100); image_resize($filefull, $width = 50, $height = 50, $crop = true, $append = 'small', $dest = null, $quality = 100); @chmod($filefull, 0777); @chmod($thumbfull, 0777); @chmod($smallfull, 0777); } } } } } else { $this->errors[] = __('No data was posted', $this->plugin_name); } return $this->errors; }
?> </h3> <p><?php echo __('Ensure that the original image exists by clicking the button below to open the image.', $this->plugin_name); ?> <br/> <?php echo sprintf(__('If the image does not open, go to Slideshow > Manage Slides and reupload the image to the slide for slide ID %s'), $slide->id); ?> <br/> <?php echo __('If it does open, you can continue to step 2 below.', $this->plugin_name); ?> </p> <p><a class="button" href="<?php echo GalleryHtmlHelper::image_url($slide->image); ?> " target="_blank"><?php echo sprintf(__('Open Original Image: %s', $this->plugin_name), __($slide->title)); ?> </a></p> </li> <li> <h3><?php _e('Test Resized/Cropped Image', $this->plugin_name); ?> </h3> <p><?php _e('Below is a button to open the resized image in a new tab and then an actual 100 by 100 pixels sample of the image.', $this->plugin_name); ?> <br/>
function save($data = null, $validate = true) { global $wpdb; $defaults = method_exists($this, 'defaults') ? $this->defaults() : false; $data = empty($data[$this->model]) ? $data : $data[$this->model]; $r = wp_parse_args($data, $defaults); $this->data = GalleryHtmlHelper::array_to_object($r); if ($validate == true) { if (method_exists($this, 'validate')) { $this->validate($r); } } if (empty($this->errors)) { switch ($this->model) { case 'Slide': if ($this->data->type == "file") { //$this -> data -> image = $_FILES['image_file']['name']; } else { $this->data->image = basename($this->data->image_url); } if (empty($this->data->uselink) || $this->data->uselink == "N") { $this->data->link = ""; } if (empty($this->data->section)) { $this->data->section = "1"; } break; } //the MySQL query $query = empty($this->data->id) ? $this->insert_query($this->model) : $this->update_query($this->model); //echo $query; //return false; if ($wpdb->query($query)) { $this->insertid = $insertid = empty($this->data->id) ? $wpdb->insert_id : $this->data->id; return true; } } return false; }
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>