Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixed gallery, added like system for it
  • Loading branch information
killme committed Feb 23, 2012
1 parent b5a3a03 commit a829acf
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 25 deletions.
6 changes: 3 additions & 3 deletions application/config/config.php
Expand Up @@ -293,9 +293,9 @@
| 'csrf_cookie_name' = The cookie name
| 'csrf_expire' = The number in seconds the token should expire.
*/
$config['csrf_protection'] = FALSE;
$config['csrf_token_name'] = 'csrf_test_name';
$config['csrf_cookie_name'] = 'csrf_cookie_name';
$config['csrf_protection'] = true;
$config['csrf_token_name'] = 'antihack_csrf';
$config['csrf_cookie_name'] = 'antihack_csrf_yum_cookie';
$config['csrf_expire'] = 7200;

/*
Expand Down
95 changes: 87 additions & 8 deletions plugins/gallery/controllers/gallery.php
Expand Up @@ -11,6 +11,7 @@ function __construct()
#$this->load->model('site_settings');
$this->load->helper('url');
$this->load->model('gallery_m');
$this->load->helper('quick_escape');

}

Expand All @@ -25,8 +26,8 @@ function index()
case 'html':
$this->template
->set_title('Galery overvieuw')
->add_head('<link href="'.base_url('static/css/caption.css').'" rel="stylesheet" type="text/css" />')
->build('gallery_view', array('images' => $this->gallery_m->get_db_images()));
#->add_head('<link href="'.base_url('static/css/caption.css').'" rel="stylesheet" type="text/css" />')
->build('gallery_view', array('images' => quick_html_escape($this->gallery_m->get_db_images())));
break;

case 'json':
Expand All @@ -45,17 +46,21 @@ function img($id = -1, $format = 'full', $action = '')
{
try
{
$img = $this->gallery_m->get_db_image($id);
switch($action)
{
default:
case 'vieuw':
$this->template
->set_title('image TITLE')
->build('single_img', array('img' => array(
'url' => site_url('gallery/img/'.(int)$id.'/thumb/raw'),
'full_img' => site_url('gallery/img/'.(int)$id.'/full/raw'),
'title' => 'the IMG!',
'description' => 'my description'
->build('single_img', array('img' => array(
'id' => (int)$img->id,
'url' => site_url('gallery/img/'.(int)$img->id.'/thumb/raw'),
'full_img' => site_url('gallery/img/'.(int)$img->id.'/full/raw'),
'title' => htmlentities($img->name),
'description' => auto_link(htmlentities($img->description)),
'date_added' => htmlentities($img->date_added),
'rating' => (int)$img->rating
)));
break;

Expand All @@ -72,7 +77,81 @@ function img($id = -1, $format = 'full', $action = '')
{
print_r($e);
}
}

function img_info($id)
{
try
{
$info = $this->gallery_m->get_db_image($id);
$info = (object)quick_html_escape($info);
switch($this->router->content_type)
{
case 'json':
$this->output->set_output(json_encode($info));
break;

case 'xml':
$xml_img = new SimpleXMLElement('<images><image /></images>');

$xml_img->image->id = $info->id;
$xml_img->image->name = $info->name;
$xml_img->image->description = $info->description;
$xml_img->image->rating = $info->rating;
$xml_img->image->date_added = $info->date_added;

$this->output->set_output($xml_img->asXML());
break;
}
}
catch(Exception $e)
{
print_r($e);
}

}

function rate($id, $way)
{
try
{

if($way == 'up')
$way_ = '+ 1';
elseif($way == 'down')
$way_ = '- 1';
else
throw new exception('unvalid way');

$this->load->library('form');

$this->form
->open('gallery/rate/'.(int)$id.'/'.rawurlencode($way))
->label('are you shure you want to change '.(int)$id.' '.htmlentities($way));

# exit;
if(1 == (int)$this->site_settings->get_setting('rate_use_captcha', '0'))
$this->form->recaptcha('Please enter the captcha code');

$this->form
->model('gallery_m', 'submit_rate', array('id' => (int)$id, 'way' => $way_))
->onsuccess('redirect', 'gallery/img/'.(int)$id)
->submit();


$data['form'] = $this->form->get(); // this returns the validated form as a string
$data['errors'] = $this->form->errors; // this returns validation errors as a string

$this->template
->set_title('confirm')
->add_head('<link href="'.base_url('static/form.css').'" rel="stylesheet" type="text/css" />')
->build('contact/contact_view', $data);
#$this->gallery_m->update_rate($id, ($way == 'up') ? '+ 1' : ($way == 'down') ? '- 1' : throw new excpetion('unvalid way')); #example of bad coding


}
catch(Exception $e)
{
print_r($e);
}
}
}
51 changes: 49 additions & 2 deletions plugins/gallery/models/gallery_m.php
Expand Up @@ -47,7 +47,7 @@ function save_img_file($id, $img_path)

function get_db_images()
{
return $this->db->query('
$result = $this->db->query('
SELECT
id,
name,
Expand All @@ -58,6 +58,53 @@ function get_db_images()
FROM
web_gallery
WHERE
public = b\'1\';')->result_object();
public = b\'1\';');

if($result->num_rows() !== 1)
throw new exception('invalid id');
else
return $result->result_object();
}

function get_db_image($id)
{
$result = $this->db->query('
SELECT
id,
name,
description,
rating,
date_added,
public
FROM
web_gallery
WHERE
id = ?;', array($id));

if($result->num_rows() !== 1)
throw new exception('invalid id');
else
$result = $result->first_row();

if(ord($result->{'public'}) == 0)
throw new exception('trying to access non public page');
else
return $result;
}

function submit_rate(&$form, $data)
{
if($data['way'] !== '+ 1' && $data['way'] !== '- 1')
$form->adderror('way', 'Unvalid way');

$result = $this->db->query('
UPDATE
web_gallery
SET
rating = rating '.$data['way'].'
WHERE
id = ?', array($data['id']));

return $result;
}
}
18 changes: 11 additions & 7 deletions plugins/gallery/views/gallery_view.php
Expand Up @@ -6,16 +6,20 @@
$(".cover", this).stop().animate({top:"260px"},{queue:false,duration:160});
});
</script>
<?php foreach($images as $image): ?>
<?php foreach($images as $image):
$image = (object) $image;
?>
<div class="boxgrid captionfull">
<img src="<?php echo site_url('gallery/img/'.(int)$image->id.'/thumb/raw'); ?>" alt="<?php echo $image->name; ?>" title="<?php echo $image->name; ?>"/>
<div class="cover boxcaption">
<!-- <a href="<?php echo site_url('gallery/img/'.(int)$image->id.'/thumb/view'); ?>" >-->
<h3>Jarek Kubicki</h3>
<p>text</p>
<a href="<?php echo site_url('gallery/img/'.(int)$image->id.'/thumb/view'); ?>" >
<img src="<?php echo site_url('gallery/img/'.(int)$image->id.'/thumb/raw'); ?>" alt="<?php echo $image->name; ?>" title="<?php echo $image->name; ?>"/>
</a>
<!-- <div class="cover boxcaption">-->

<!-- <h3>Jarek Kubicki</h3> -->
<!-- <p>text</p> -->


</div>
<!-- </div> -->
</div>

<?php endforeach; ?>
22 changes: 17 additions & 5 deletions plugins/gallery/views/single_img.php
Expand Up @@ -44,12 +44,24 @@
<img src="{as:img:url}" alt="{as:img:title}" title="{as:img:title}"/>
</a>
<section>
<h1>{as:img:title}</h1>
<p>{as:img:description}</p>
<article>
<h1>{as:img:title}</h1>
<p>{as:img:description}</p>
</article>
<p>
<div class="rating" data-type="img" data-id="">
<a href="">like</a>
<a href="">DIE</a>
<details>
<ul>
<li>id: #{as:img:id}</li>
<li>name: {as:img:title}</li>
<li>url small : <a href="{as:img:url}" >{as:img:url}</a></li>
<li>url large: <a href="{as:img:full_img}">{as:img:full_img}</a></li>
<li>date added: {as:img:date_added}</li>
</ul>
</details>
<div data-rating="{as:img:rating}" class="rating" data-type="img" data-id="">
Current rating: <span>{as:img:rating}</span>
<a href="{as:helpers:url:site url='gallery/rate/{as:img:id /}/up' /}">like</a>
<a href="{as:helpers:url:site url='gallery/rate/{as:img:id /}/down' /}">DIE</a>
</div>
</p>
</section>
Expand Down

0 comments on commit a829acf

Please sign in to comment.