public function edit($id) { if (!($banner = Banner::findById($id))) { Flash::set('error', __('Banner not found!')); redirect(get_url('banner')); } // check if trying to save if (get_request_method() == 'POST') { return $this->_edit($id); } $this->display('banner/view', array('banner' => $banner)); }
function banner_count_display($args) { // check for banner click if (preg_match('#^/banner-show/(\d+)$#i',$args,$matches)) { // update the click count of the banner $id = (int)$matches[1]; $banner = Banner::findById($id); $banner->ccount++; $banner->save(); // get image uri $imguri = Plugin::getSetting('imguri','banner'); // redirect to the requested url header ('HTTP/1.1 301 Moved Permanently', true); header ("Location: /{$imguri}/{$banner->image}"); exit; } // no click so keep going return $args; }
/** * Processes an update to the banner and redirects back to the edit page * * @param int $id */ public function banner_update($id=null) { if (is_null($id)){ Flash::set('error','Banners - '.__('No ID specified!')); redirect(get_url('plugin/banner/banner_list')); } // retrieve the current banner settings from the database if (!$current = Banner::findById($id)) { Flash::set('error','Banners - '.__('Could not find banner!')); redirect(get_url('plugin/banner/banner_list')); } // retrieve the new banner settings from $_POST $_POST['id'] = $id; $input = $this->__validate($_POST); // rename the current image with the new settings $newname = $this->__imgname($input,'.'.pathinfo($current->image,PATHINFO_EXTENSION)); $oldname = $current->image; if ($newname !== $oldname) { if (!$this->__rename($oldname,$newname)) { Flash::set('error','Banners - '.__('Could not rename image!')); redirect(get_url('plugin/banner/banner_edit/'.$id)); } $current->image = $newname; if (!$current->save()) { $this->__rename($newname,$oldname); Flash::set('error','Banners - '.__('Could not save new image name in database!')); redirect(get_url('plugin/banner/banner_edit/'.$id)); } } // attempt to upload a new banner image if ($newname = $this->__upload('banner',$input,$current->image)) $current->image = $newname; // update banner in database $current = Banner::findById($id); $current->updated = date('Y-m-d H:i:s'); foreach ($input as $key => $value) { $current->$key = $value; } if (!$current->save()) { Flash::set('error','Banners - '.__('Could not update the banner in the database.')); redirect(get_url('plugin/banner/banner_edit/'.$id)); } Flash::set('success','Banners - '.__('banner saved!')); redirect(get_url('plugin/banner/banner_edit/'.$id)); }//*/