Dotclear

source: plugins/meuh/class.meuh.php @ 2223

Revision 2223, 2.9 KB checked in by bruno, 14 years ago (diff)

New plugin : meuh 0.2

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ----------------------------------
3#
4# This file is part of Meuh,
5# a plugin for DotClear2.
6#
7# Copyright (c) 2010 Bruno Hondelatte and contributors
8#
9# Licensed under the GPL version 2.0 license.
10# See LICENSE file or
11# http://www.gnu.org/licenses/gpl-2.0.txt
12#
13# -- END LICENSE BLOCK ------------------------------------
14
15class dcMeuh
16{
17     protected $core;
18     protected $aliases;
19     
20     public function __construct(&$core)
21     {
22          $this->core =& $core;
23     }
24     
25     public function getAliases($post_url=null)
26     {
27          $sql =    'SELECT post_type, post_url, meuh_url, meuh_count, meuh_lastread '.
28                    'FROM '.$this->core->prefix.'meuh '.
29                    "WHERE blog_id = '".$this->core->con->escape($this->core->blog->id)."' ";
30          if ($post_url != null)
31               $sql .= "AND post_url='".$this->core->con->escape($post_url)."' ";
32          $rs = $this->core->con->select($sql);
33          return $rs;
34     }
35     
36     
37     public function addAlias($post_type,$post_url,$alias)
38     {
39          if (!$post_url) {
40               throw new Exception(__('Alias URL is empty.'));
41          }
42         
43          if (!$alias) {
44               throw new Exception(__('Alias destination is empty.'));
45          }
46         
47          $cur = $this->core->con->openCursor($this->core->prefix.'meuh');
48          $cur->blog_id = (string) $this->core->blog->id;
49          $cur->post_type = (string) $post_type;
50          $cur->post_url = (string) $post_url;
51          $cur->meuh_url = (string) $alias;
52          $cur->insert();
53     }
54     
55     public function renamePostUrl($post_type,$old_url,$new_url)
56     {
57          $this->core->con->execute(
58               'UPDATE '.$this->core->prefix.'meuh '.
59               "SET post_url = '".$this->core->con->escape($new_url)."' ".
60               "WHERE blog_id = '".$this->core->con->escape($this->core->blog->id)."' ".
61               "AND post_url='".$this->core->con->escape($old_url)."' "
62          );
63     }   
64     
65     public function updateAlias($post_type,$meuh_url) {
66          $this->core->con->execute(
67               'UPDATE '.$this->core->prefix.'meuh '.
68               "SET meuh_count = meuh_count+1, meuh_lastread=now() ".
69               "WHERE blog_id = '".$this->core->con->escape($this->core->blog->id)."' ".
70               "AND post_type='".$this->core->con->escape($post_type)."' ".
71               "AND meuh_url='".$this->core->con->escape($meuh_url)."' "
72          );
73     }
74     public function getPostUrl($post_type,$meuh_url) {
75          $sql =    'SELECT post_url '.
76                    'FROM '.$this->core->prefix.'meuh '.
77                    "WHERE blog_id = '".$this->core->con->escape($this->core->blog->id)."' ".
78                    "AND post_type='".$this->core->con->escape($post_type)."' ".
79                    "AND meuh_url='".$this->core->con->escape($meuh_url)."' ";
80          $rs = $this->core->con->select($sql);
81          if (!$rs->fetch()) {
82               return null;
83          }
84          return $rs->post_url;
85     }
86     
87     public function deleteAlias($post_type,$meuh_url,$post_url=null)
88     {
89          $req =
90               'DELETE FROM '.$this->core->prefix.'meuh '.
91               "WHERE blog_id = '".$this->core->con->escape($this->core->blog->id)."' ".
92               " AND post_type='".$this->core->con->escape($post_type)."' ".
93               " AND meuh_url='".$this->core->con->escape($meuh_url)."' ";
94          if ($post_url != null) 
95               $req .= " AND post_url='".$this->core->con->escape($post_url)."' ";
96
97          $this->core->con->execute($req);
98     }
99
100}
Note: See TracBrowser for help on using the repository browser.

Sites map