url.class.php
2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
class Url{
 var $db = null;
 var $tpl = null;
 var $error = null;
//var $id = false;
 function Url(&$db,&$tpl,&$error){
  $this->db = &$db;
  $this->tpl = &$tpl;
  $this->error = &$error;
 }
 
 
 function viewAllAdvices($param = array()){
  $search = array();
  $sql = "select * from url_tags where 1=1 ";
  if(count($search))$sql .= "AND " . implode(" AND ",$search)." ";
  $sql .= "order by id desc";
  $pagerOptions = Array(
    'mode' => 'Sliding',
    'delta' => 6,
    'perPage' => 1110,
    'spacesBeforeSeparator' => 1,
    'spacesAfterSeparator' => 1
  );
  $this->tpl->assign('advicesAllData', Pager_Wrapper_DB($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array()));
 }
 function viewOneAdvices($id,&$row,$lang = "rus"){
  $sql = "select * from url_tags where id=? limit 1";
  $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
  $this->tpl->assign('advices',$row);
 }
 
 function getUrl(){
	//print_r($_SERVER);
	$url = $_SERVER['REQUEST_URI'];
	$sql = "select * from url_tags where url=?";
	return $this->db->getRow($sql,array($url),DB_FETCHMODE_ASSOC);
 }
 
 function admin_infoEditAdvicesOne($id){
  $sql = "select * from url_tags where id=? limit 1";
  $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
  $this->tpl->assign('advices',$row);
 }
 function trim(&$data){
  foreach($data as $key=>$value){
   if(!is_array($data[$key]))$data[$key] = trim($value);
  }
 }
 function valid($data,$upload = null){
  if(isset($data['rss_rubric'])){
   if( !preg_match("/^([0-9]+)$/",$data['rss_rubric']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Ðóáðèêà.";
  }
  
  if(isset($data['title'])){
   if( !preg_match("/.{1,150}/i",$data['title']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Çàãëàâèå, îò 1-150 ñèìâîëîâ.";
  }
  if(isset($upload['pic']['name']) && $upload['pic']['name']!=null){
   $type = substr(strrchr($upload['pic']['name'],"."),1);
   if( !preg_match("/^(jpeg|jpg|gif|png)$/i",$type) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Èçîáðàæåíèÿ, òîëüêî jpg,png,gif.";
  }
 return ( count($this->error) ) ? true : false;
 }
 function SaveAdvices($data,$upload = null){
  $table_name = "url_tags";
  if($data['update_id']>0){$DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;$id = $data['update_id'];$where = "id=$id";}else{$DB_AUTOQUERY = DB_AUTOQUERY_INSERT;$where = null;}
  $fields_values = array("url"=>$data['url'],"h1"=>$data['h1'],"text"=>$data['text'],"meta_title"=>$data['meta_title'],"meta_description"=>$data['meta_description'],"meta_keywords"=>$data['meta_keywords'],"meta_about"=>$data['meta_about']);
 $this->db->autoExecute($table_name, $fields_values, $DB_AUTOQUERY,$where);
  return $id;
 }
 function admin_deleteAdvicesOne($id){
  $sql = "delete from url_tags where id=?";
  $this->db->query($sql,array($id));
 }
 
 function displayAdvicesSave(){
  $this->tpl->assign("tpl","url_tags_save.tpl");
 }
 
 function displayAdvices(){
  $this->tpl->assign("tpl","url_tags.tpl");
 }
 function displayAdvicesOne(){
  $this->tpl->assign("tpl","advices_one.tpl");
 }
}
?>