conn = new mysqli(DB_SERVER,DB_USER,DB_PASSWORD,DB_NAME)or die('Hubo un problema al conectar a la base de Datos'); $this->tables = $this->tables(); $this->fields = $this->fields(); $this->myACL = new ACL(); } // MISCELLANEOUS Functions protected function tables(){ $resultado = $this->conn->query('SHOW TABLES'); $datos = Array(); $i=0; while($row = $resultado->fetch_assoc()){ $datos[$i] = $row['Tables_in_'.DB_NAME]; $i++; } return $datos; } protected function fields(){ $datos = Array(); $i=0; foreach($this->tables as $table){ $resultado = $this->conn->query('SHOW FIELDS FROM '.$table); while($row = $resultado->fetch_assoc()){ $datos[$i] = $row['Field']; $i++; } } return $datos; } protected function fields_table($table){ $datos = Array(); $i=0; $resultado = $this->conn->query('SHOW FIELDS FROM '.$table); while($row = $resultado->fetch_assoc()){ $datos[$i] = $row['Field']; $i++; } return $datos; } protected function get_object_result($stmt){ $result = array(); $metadata = $stmt->result_metadata(); $fields = $metadata->fetch_fields(); for (;;){ $pointers = array(); $row = new stdClass(); $pointers[] = $stmt; foreach ($fields as $field){ $fieldname = $field->name; $pointers[] = &$row->$fieldname; } call_user_func_array(mysqli_stmt_bind_result, $pointers); if (!$stmt->fetch()) break; $result[] = $row; } $metadata->free(); return $result; } protected function get_result($stmt){ $meta = $stmt->result_metadata(); while ($field = $meta->fetch_field()){ $params[] = &$row[$field->name]; } call_user_func_array(array($stmt, 'bind_result'), $params); while ($stmt->fetch()){ foreach($row as $key => $val){ $c[$key] = $val; } $result[] = $c; } $meta->free(); return $result; } function sanitize_uri($uri) { $uri = replace_accents($uri); $uri = strtolower($uri); $uri = strtolower($uri); $uri = preg_replace('/&.+?;/', '', $uri); // kill entities $uri = preg_replace('/[^a-z0-9 -]/', '', $uri); $uri = preg_replace('/\s+/', ' ', $uri); $uri = trim($uri); $uri = str_replace(' ', '-', $uri); $uri = preg_replace('|-+|', '-', $uri); return $uri; } function crear_uri($table,$field,$id,$uri){ if($n_uri = $this->n_diff_uri($table, $field, $id, $uri)){ for($i=1;$n_uri>0;$i++){ $nuevo_uri = $uri.'-'.$i; $n_uri = $this->n_diff_uri($table, $field, $id, $nuevo_uri); } return $nuevo_uri; }else{ return $uri; } } function n_diff_uri($table,$field,$id,$uri){ if(in_array($table, $this->tables) && in_array($field, $this->fields)){ $query = "SELECT uri FROM $table WHERE uri = ? AND $field != ?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('si',$uri,$id); $stmt->execute(); $stmt->store_result(); $stmt->fetch(); $num = $stmt->num_rows; $stmt->close(); return $num; }else{ return false; } }else{ return false; } } function check_Email_Is_Available($email,$user_id){ $query = "SELECT COUNT(*) AS total FROM user WHERE email = ? AND user_id !=?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('si',$email,$user_id); $stmt->execute(); $stmt->bind_result($count); $stmt->fetch(); if($count>0){ return false; }else{ return true; } }else{ return false; } } function check_personal_id_Is_Available($personal_id,$user_id=0){ $personal_id = preg_replace("/[^0-9\s]/", "", $personal_id); $query = "SELECT COUNT(*) AS total FROM user_extra WHERE personal_id = ? AND user_id !=?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('si',$personal_id,$user_id); $stmt->execute(); $stmt->bind_result($count); $stmt->fetch(); if($count>0){ return false; }else{ return true; } }else{ return false; } } function check_cellphone_Is_Available($cellphone,$user_id=0){ $cellphone = preg_replace("/[^0-9\s]/", "", $cellphone); $query = "SELECT COUNT(*) AS total FROM user_extra WHERE cellphone = ? AND user_id !=?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('si',$cellphone,$user_id); $stmt->execute(); $stmt->bind_result($count); $stmt->fetch(); if($count>0){ return false; }else{ return true; } }else{ return false; } } function validEmail($email){ $isValid = true; $atIndex = strrpos($email, "@"); if (is_bool($atIndex) && !$atIndex){ $isValid = false; }else{ $domain = substr($email, $atIndex+1); $local = substr($email, 0, $atIndex); $localLen = strlen($local); $domainLen = strlen($domain); if ($localLen < 1 || $localLen > 64){ // local part length exceeded $isValid = false; }else if ($domainLen < 1 || $domainLen > 255){ // domain part length exceeded $isValid = false; }else if ($local[0] == '.' || $local[$localLen-1] == '.'){ // local part starts or ends with '.' $isValid = false; }else if (preg_match('/\\.\\./', $local)){ // local part has two consecutive dots $isValid = false; }else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)){ // character not valid in domain part $isValid = false; }else if (preg_match('/\\.\\./', $domain)){ // domain part has two consecutive dots $isValid = false; }else if(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/',str_replace("\\\\","",$local))){ // character not valid in local part unless // local part is quoted if (!preg_match('/^"(\\\\"|[^"])+"$/',str_replace("\\\\","",$local))){ $isValid = false; } } if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))){ // domain not found in DNS $isValid = false; } } return $isValid; } function check_Nick($nick,$user_id){ $query = "SELECT COUNT(*) AS total FROM user WHERE nick = ? AND user_id != ?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('si',$nick,$user_id); $stmt->execute(); $stmt->bind_result($count); $stmt->fetch(); if($count>0){ return false; }else{ return true; } }else{ return false; } } // SITEDATA Functions function sitedata(){ $query = "SELECT data_key,data_value FROM sitedata"; if($resultado = $this->conn->query($query)){ $datos = new stdClass(); while($row = $resultado->fetch_assoc()){ $datos->$row[data_key] = $row[data_value]; } if(count($datos)>0){ return $datos; }else{ return false; } }else{ return false; } } function get_sitedata($sitedata_id){ if(!$this->myACL->hasPermission('sitedata_list')) die_icms(NO_PERMISSION,'red'); $query = "SELECT * FROM sitedata WHERE sitedata_id = ? LIMIT 1"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$sitedata_id); $stmt->execute(); if($result = $this->get_object_result($stmt)){ $stmt->close(); return $result[0]; }else{ $stmt->close(); return false; } }else{ return false; } } function insert_sitedata($data_key,$data_value,$status){ if(!$this->myACL->hasPermission('sitedata_edit')) die_icms(NO_PERMISSION,'red'); $query = "INSERT INTO sitedata (data_key,data_value,status) VALUES (?,?,?)"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('ssi',$data_key,$data_value,$status); $stmt->execute(); $insert_id = $stmt->insert_id; $stmt->close(); return $insert_id; }else{ return false; } } function update_sitedata($data_key,$data_value,$status,$sitedata_id){ if(!$this->myACL->hasPermission('sitedata_edit')) die_icms(NO_PERMISSION,'red'); $query = "UPDATE sitedata SET data_key = ?, data_value = ?, status = ? WHERE sitedata_id = ?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('ssii',$data_key,$data_value,$status,$sitedata_id); if($stmt->execute()){ $stmt->close(); return true; }else{ echo $stmt->error; $stmt->close(); return false; } } } function delete_sitedata($sitedata_id){ if(!$this->myACL->hasPermission('sitedata_delete')) die_icms(NO_PERMISSION,'red'); $query = "DELETE FROM sitedata WHERE sitedata_id = ?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$sitedata_id); if($stmt->execute()){ if($stmt->affected_rows==0){ $stmt->close(); return false; } $stmt->close(); return true; }else{ echo $stmt->error; $stmt->close(); return false; } }else{ return false; } } // PERM Functions function get_perm($perm_id){ $query = "SELECT * FROM perm WHERE perm_id = ?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$perm_id); $stmt->execute(); if($result = $this->get_object_result($stmt)){ $stmt->close(); return $result[0]; }else{ $stmt->close(); return false; } }else{ return false; } } function insert_perm($permKey,$permName){ if(!$this->myACL->hasPermission('perm_edit')) die_icms(NO_PERMISSION,'red'); $query = "INSERT INTO perm (permKey,permName) VALUES (?,?)"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('ss',$permKey,$permName); $stmt->execute(); $insert_id = $stmt->insert_id; $stmt->close(); return $insert_id; }else{ return false; } } function update_perm($permKey,$permName,$perm_id){ if(!$this->myACL->hasPermission('perm_edit')) die_icms(NO_PERMISSION,'red'); $query = "UPDATE perm SET permKey = ?, permName = ? WHERE perm_id = ?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('ssi',$permKey,$permName,$perm_id); if($stmt->execute()){ $stmt->close(); return true; }else{ echo $stmt->error; $stmt->close(); return false; } } } function delete_perm($perm_id){ if(!$this->myACL->hasPermission('perm_delete')) die_icms(NO_PERMISSION,'red'); $query = "DELETE FROM perm WHERE perm_id = ? LIMIT 1"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$perm_id); if($stmt->execute()){ if($stmt->affected_rows==0){ $stmt->close(); return false; } $stmt->close(); return true; }else{ echo $stmt->error; $stmt->close(); return false; } }else{ return false; } } // ROLE_PERM Functions function insert_role_perm($role_id,$perm_id){ if(!$this->myACL->hasPermission('role_edit')) die_icms(NO_PERMISSION,'red'); $date = date("Y-m-d h:i:s",mktime()); $query = "INSERT INTO role_perm (role_id,perm_id,value,date) VALUES (?,?,'1','$date')"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('ii',$role_id,$perm_id); $stmt->execute(); $insert_id = $stmt->insert_id; $stmt->close(); return $insert_id; }else{ return false; } } function delete_role_perm($role_id){ if(!$this->myACL->hasPermission('role_delete')) die_icms(NO_PERMISSION,'red'); $query = "DELETE FROM role_perm WHERE role_id = ?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$role_id); if($stmt->execute()){ if($stmt->affected_rows==0){ $stmt->close(); return false; } $stmt->close(); return true; }else{ echo $stmt->error; $stmt->close(); return false; } }else{ return false; } } function get_role_permissions($role_id){ $query = "SELECT perm_id FROM role_perm WHERE role_id = ?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$role_id); $stmt->execute(); $stmt->bind_result($id); $z=0; $rows = array(); while($row = $stmt->fetch()){ $rows[$z] = $id; $z++; } $stmt->close(); return $rows; }else{ return false; } } // USER_PERM Functions function insert_user_perm($user_id,$perm_id){ if(!$this->myACL->hasPermission('user_perm_edit')) die_icms(NO_PERMISSION,'red'); $date = date("Y-m-d h:i:s",mktime()); $query = "INSERT INTO user_perm (user_id,perm_id,value,date) VALUES (?,?,'1','$date')"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('ii',$user_id,$perm_id); $stmt->execute(); $insert_id = $stmt->insert_id; $stmt->close(); return $insert_id; }else{ return false; } } function delete_user_perm($user_id){ if(!$this->myACL->hasPermission('user_perm_edit')) die_icms(NO_PERMISSION,'red'); $query = "DELETE FROM user_perm WHERE user_id = ?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$user_id); if($stmt->execute()){ if($stmt->affected_rows==0){ $stmt->close(); return false; } $stmt->close(); return true; }else{ echo $stmt->error; $stmt->close(); return false; } }else{ return false; } } // USER_ROLE Functions function insert_user_role($user_id,$role_id){ if(!$this->myACL->hasPermission('user_role_edit')) die_icms(NO_PERMISSION,'red'); $query = "INSERT INTO user_roles (user_id,role_id) VALUES (?,?)"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('ii',$user_id,$role_id); $stmt->execute(); $insert_id = $stmt->insert_id; $stmt->close(); return $insert_id; }else{ return false; } } function delete_user_role($user_id){ if(!$this->myACL->hasPermission('user_role_edit')) die_icms(NO_PERMISSION,'red'); $query = "DELETE FROM user_roles WHERE user_id = ?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$user_id); $stmt->execute(); $stmt->close(); }else{ return false; } } // ROLE Functions function get_role($role_id){ $query = "SELECT * FROM role WHERE role_id = ?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$role_id); $stmt->execute(); if($result = $this->get_object_result($stmt)){ $stmt->close(); return $result[0]; }else{ $stmt->close(); return false; } }else{ return false; } } function insert_role($name){ if(!$this->myACL->hasPermission('role_edit')) die_icms(NO_PERMISSION,'red'); $query = "INSERT INTO role (name) VALUES (?)"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('s',$name); $stmt->execute(); $insert_id = $stmt->insert_id; $stmt->close(); return $insert_id; }else{ return false; } } function update_role($name,$role_id){ if(!$this->myACL->hasPermission('role_edit')) die_icms(NO_PERMISSION,'red'); $query = "UPDATE role SET name = ? WHERE role_id = ?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('si',$name,$role_id); if($stmt->execute()){ $stmt->close(); return true; }else{ echo $stmt->error; $stmt->close(); return false; } } } function delete_role($role_id){ if(!$this->myACL->hasPermission('role_delete')) die_icms(NO_PERMISSION,'red'); $query = "DELETE FROM role WHERE role_id = ?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$role_id); if($stmt->execute()){ if($stmt->affected_rows==0){ $stmt->close(); return false; } $stmt->close(); return true; }else{ echo $stmt->error; $stmt->close(); return false; } }else{ return false; } } // USER Functions function verify_Email_and_Passw($email, $passw){ $query = "SELECT user_id FROM user WHERE email = ? AND passw = ? AND status='1'"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('ss',$email,$passw); $stmt->execute(); $stmt->store_result(); $num_rows = $stmt->num_rows; if($stmt->fetch() && $stmt->num_rows==1){ $stmt->close(); return true; }else{ return false;} }else{ return false;} } function verify_Passw_Recovery_String($email, $string){ $query = "SELECT user_id FROM user WHERE email = ? AND passw_recovery_string = ?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('ss',$email,$string); $stmt->execute(); $stmt->store_result(); $num_rows = $stmt->num_rows; if($stmt->fetch() && $stmt->num_rows==1){ $stmt->close(); return true; }else{ return false;} }else{ return false;} } function insert_user($email,$passw,$name,$lastname,$sex,$nick,$uri=null,$fb_uid=0,$status=0){ if(!$this->myACL->hasPermission('user_edit')) die_icms(NO_PERMISSION,'red'); $passw = md5($passw); if(!is_null($uri)){ $uri = $this->sanitize_uri($uri); }else{ $uri = $this->sanitize_uri($name.' '.$lastname); } $uri = $this->crear_uri('user','user_id',0, $uri); $query = "INSERT INTO user (email,passw,name,lastname,sex,nick,uri,fb_uid,status) VALUES(?,?,?,?,?,?,'$uri',?,?)"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('ssssssii',$email,$passw,$name,$lastname,$sex,$nick,$fb_uid,$status); $stmt->execute(); $insert_id = $stmt->insert_id; $stmt->close(); return $insert_id; }else{ return false; } } function insert_user_public($email,$passw,$name,$lastname,$sex,$nick,$uri=null,$fb_uid=0,$status=0){ $passw = md5($passw); if(!is_null($uri)){ $uri = $this->sanitize_uri($uri); }else{ $uri = $this->sanitize_uri($name.' '.$lastname); } $uri = $this->crear_uri('user','user_id',0, $uri); $query = "INSERT INTO user (email,passw,name,lastname,sex,nick,uri,fb_uid,status) VALUES(?,?,?,?,?,?,'$uri',?,?)"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('ssssssii',$email,$passw,$name,$lastname,$sex,$nick,$fb_uid,$status); $stmt->execute(); $insert_id = $stmt->insert_id; $stmt->close(); return $insert_id; }else{ return false; } } function update_user($email,$name,$lastname,$sex,$nick,$uri=null,$fb_uid=0,$status=0,$user_id){ if(!$this->myACL->hasPermission('user_edit') && $user_id!=$_SESSION[user_id]) die_icms(NO_PERMISSION,'red'); if(!is_null($uri)){ $uri = $this->sanitize_uri($uri); }else{ $uri = $this->sanitize_uri($name.' '.$lastname); } $uri = $this->crear_uri('user','user_id',0, $uri); $query = "UPDATE user SET email = ?, name = ?, lastname = ?, sex = ?, nick = ?, uri = '$uri', fb_uid = ?, status = ? WHERE user_id = ? LIMIT 1"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('ssssssii',$email,$name,$lastname,$sex,$nick,$fb_uid,$status,$user_id); $stmt->execute(); $stmt->close(); return true; }else{ return false; } } function activate_user($email,$string){ if($this->verify_Passw_Recovery_String($email,$string)){ $query = "UPDATE user SET status = 1 WHERE email = ? LIMIT 1"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('s',$email); $stmt->execute(); $stmt->close(); return true; }else{ return false; } } } function update_user_passw($passw, $user_id){ if(!$this->myACL->hasPermission('user_edit') && $user_id!=$_SESSION[user_id]) die_icms(NO_PERMISSION,'red'); $passw = md5($passw); $query = "UPDATE user SET passw=? WHERE user_id=? LIMIT 1"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('si',$passw, $user_id); $stmt->execute(); $stmt->close(); return true; }else{ return false; } } function update_user_passw_recovery($passw, $user_id){ $passw = md5($passw); $query = "UPDATE user SET passw=? WHERE user_id=? LIMIT 1"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('si',$passw, $user_id); $stmt->execute(); $stmt->close(); return true; }else{ return false; } } function update_user_passw_recovery_string($user_id,$string){ $query = "UPDATE user SET passw_recovery_string = ? WHERE user_id = ? LIMIT 1"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('si',$string, $user_id); $stmt->execute(); $stmt->close(); return true; }else{ return false; } } function insert_user_fb($email,$name,$lastname,$sex,$fb_uid,$status=1){ $query = "INSERT INTO user (email,name,lastname,sex,fb_uid,status) VALUES (?,?,?,?,?,?)"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('sssssi',$email,$name,$lastname,$sex,$fb_uid,$status); $stmt->execute(); $insert_id = $stmt->insert_id; $stmt->close(); return $insert_id; }else{ return false; } } function get_user($id){ $query = "SELECT user_id,email,passw,name,lastname,nick,uri,sex,fb_uid,status FROM user WHERE user_id = ?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$id); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($user_id,$email,$passw,$name,$lastname,$nick,$uri,$sex,$fb_uid,$status); if($stmt->fetch() && $stmt->num_rows==1){ $stmt->close(); $resultado = new stdClass(); $resultado->user_id = $user_id; $resultado->email = strip_tags($email); $resultado->passw = $passw; $resultado->name = strip_tags($name); $resultado->lastname = strip_tags($lastname); $resultado->nick = strip_tags($nick); $resultado->uri = $uri; $resultado->sex = strip_tags($sex); $resultado->fb_uid = $fb_uid; $resultado->status = $status; return $resultado; }else{ return false; } }else{ return false; } } function get_user_by_email($email){ $query = "SELECT user_id FROM user WHERE email = ? LIMIT 1"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('s',$email); $stmt->execute(); if($result = $this->get_object_result($stmt)){ $stmt->close(); return $result[0]; }else{ $stmt->close(); return false; } } } function get_user_by_fb_uid($fb_uid){ $query = "SELECT user_id FROM user WHERE fb_uid = ? LIMIT 1"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('s',$fb_uid); $stmt->execute(); if($result = $this->get_object_result($stmt)){ $stmt->close(); return $result[0]; }else{ $stmt->close(); return false; } } } function delete_user($user_id){ if(!$this->myACL->hasPermission('user_delete')) die_icms(NO_PERMISSION,'red'); $query = "DELETE FROM user WHERE user_id = ? LIMIT 1"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$user_id); if($stmt->execute()){ if($stmt->affected_rows==0){ $stmt->close(); return false; } $stmt->close(); return true; }else{ echo $stmt->error; $stmt->close(); return false; } }else{ return false; } } function user_update_fb_uid($user_id,$fb_uid){ $query = 'UPDATE user SET fb_uid = ? WHERE user_id = ? LIMIT 1'; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('si',$fb_uid,$user_id); if($stmt->execute()){ $stmt->close(); return true; }else{ echo $stmt->error; $stmt->close(); return false; } } } function user_change_status($user_id,$status=0){ $query = 'UPDATE user SET status = ? WHERE user_id = ? LIMIT 1'; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('ii',$status,$user_id); if($stmt->execute()){ $stmt->close(); return true; }else{ echo $stmt->error; $stmt->close(); return false; } } } // POST Functions function get_post($id,$status=1){ $query = ' SELECT post_id,title,category_id,post_type_id,uri,intro,content,user_id,status,date_cre,date_mod,date_pub,tags,sticky,language_id,original_post_id FROM post WHERE post_id = ?'; if($status!='any'){ $query .= ' AND status = "'.intval($status).'"'; } $query .= ' LIMIT 1'; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$id); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($post_id,$title,$category_id,$post_type_id,$uri,$intro,$content,$user_id,$status,$date_cre,$date_mod,$date_pub,$tags,$sticky,$language_id,$original_post_id); if($stmt->fetch() && $stmt->num_rows==1){ $stmt->close(); $resultado = new stdClass(); $resultado->post_id = $post_id; $resultado->title = stripslashes($title); $resultado->category_id = $category_id; $resultado->post_type_id = $post_type_id; $resultado->uri = $uri; $resultado->intro = stripslashes($intro); $resultado->content = stripslashes($content); $resultado->user_id = $user_id; $resultado->status = $status; $resultado->date_cre = $date_cre; $resultado->date_mod = $date_mod; $resultado->date_pub = $date_pub; $resultado->tags = $tags; $resultado->sticky = $sticky; $resultado->language_id = $language_id; $resultado->original_post_id = $original_post_id; return $resultado; }else{ return false; } }else{ return false; } } function get_post_id_by_uri($uri){ $query = "SELECT post_id FROM post WHERE uri = ?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('s',$uri); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($id); if($stmt->fetch() && $stmt->num_rows==1){ $stmt->close(); return $id; }else{ return false; } }else{ return false; } } function select_post($from,$to,$condition=null,$fields=null,$terms=null,$operator="OR",$exact_word=false){ if(!is_null($fields)){ $columns = array('post_id'); $query = $this->build_Search_SQL($columns, 'post', $fields, $terms, $operator, $condition,$exact_word); }else{ $query = "SELECT post_id FROM post"; if(!is_null($condition)){ $query .= " WHERE $condition"; } } $query .= ' LIMIT '.$from.','.$to; if($resultado = $this->conn->query($query)){ $obj = new stdClass(); $i=0; while($row = $resultado->fetch_assoc()){ $obj->{$i}=$row[post_id]; $i++; } return $obj; } } function insert_post($title,$post_type_id,$category_id,$intro,$content,$tags,$status,$date_pub,$sticky,$language_id,$original_post_id=0,$uri=null){ if(!$this->myACL->hasPermission('post_edit')) die_icms(NO_PERMISSION,'red'); $date_cre = time(); $date_mod = time(); if(!is_null($uri)){ $uri = $this->sanitize_uri($uri); }else{ $uri = $this->sanitize_uri($title); } $uri = $this->crear_uri('post','post_id',0, $uri); $query = "INSERT INTO post (title,post_type_id,category_id,uri,intro,content,tags,status,user_id,date_cre,date_mod,date_pub,sticky,language_id,original_post_id) VALUES (?,?,?,'$uri',?,?,?,?,'$user_id','$date_cre','$date_mod',?,?,?,?)"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('siisssiiiii',$title,$post_type_id,$category_id,$intro,$content,$tags,$status,$date_pub,$sticky,$language_id,$original_post_id); $stmt->execute(); $insert_id = $stmt->insert_id; $stmt->close(); return $insert_id; }else{ return false; } } function update_post($title,$post_type_id,$category_id,$intro,$content,$tags,$status,$date_pub,$sticky,$language_id,$post_id,$original_post_id=0,$uri=null){ if(!$this->myACL->hasPermission('post_edit')) die_icms(NO_PERMISSION,'red'); $date_mod = time(); if(!is_null($uri)){ $uri = $this->sanitize_uri($uri); }else{ $uri = $this->sanitize_uri($title); } $uri = $this->crear_uri('post','post_id',$post_id, $uri); $query = "UPDATE post SET title = ?, post_type_id = ?, category_id = ?, uri = '$uri', intro = ?, content = ?, tags = ?, status = ?, date_pub = ?, date_mod = '$date_mod', sticky = ?, language_id = ?, original_post_id = ? WHERE post_id = ?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('siisssiiiiii',$title,$post_type_id,$category_id,$intro,$content,$tags,$status,$date_pub,$sticky,$language_id,$original_post_id,$post_id); if($stmt->execute()){ $stmt->close(); return true; }else{ echo $stmt->error; $stmt->close(); return false; } } } function delete_post($post_id){ if(!$this->myACL->hasPermission('post_delete')) die_icms(NO_PERMISSION,'red'); $query = "DELETE FROM post WHERE post_id = ?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$post_id); if($stmt->execute()){ if($stmt->affected_rows==0){ $stmt->close(); return false; } $stmt->close(); return true; }else{ echo $stmt->error; $stmt->close(); return false; } }else{ echo "stmt prepare failed"; return false; } } // TAGS Functions function insert_tag($name,$uri=null,$post_count=0,$status=1){ if($name!=""){ if(!is_null($uri)){ $uri = $this->sanitize_uri($uri); }else{ $uri = $this->sanitize_uri($name); } $uri = $this->crear_uri('tag','tag_id',0, $uri); $query = 'INSERT INTO tag (name,uri,post_count,status) VALUES (?,?,?,?)'; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('ssii',$name,$uri,$post_count,$status); $stmt->execute(); $insert_id = $stmt->insert_id; $stmt->close(); return $insert_id; }else{ return false; } } } function get_tag($tag_id=0,$uri){ if($tag_id==0){ $query = 'SELECT * FROM tag WHERE uri = ? LIMIT 1'; }else{ $query = 'SELECT * FROM tag WHERE tag_id = ? LIMIT 1'; } if($stmt = $this->conn->prepare($query)){ if($tag_id==0){ $stmt->bind_param('s',$uri); }else{ $stmt->bind_param('i',$tag_id); } $stmt->execute(); if($result = $this->get_object_result($stmt)){ $stmt->close(); return $result[0]; }else{ $stmt->close(); return false; } }else{ return false; } } function update_tag($name,$tag_id){ $query = 'UPDATE tag SET name = ? WHERE tag_id = ? LIMIT 1'; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('si',$name,$tag_id); if($stmt->execute()){ $stmt->close(); return true; }else{ echo $stmt->error; $stmt->close(); return false; } } } function delete_tag($tag_id=0,$name){ if($tag_id==0){ $query = 'DELETE FROM tag WHERE name = ? LIMIT 1'; }else{ $query = 'DELETE FROM tag WHERE tag_id = ? LIMIT 1'; } if($stmt = $this->conn->prepare($query)){ if($tag_id==0){ $stmt->bind_param('s',$name); }else{ $stmt->bind_param('i',$tag_id); } if($stmt->execute()){ if($stmt->affected_rows==0){ $stmt->close(); return false; } $stmt->close(); return true; }else{ echo $stmt->error; $stmt->close(); return false; } }else{ echo "stmt prepare failed"; return false; } } function delete_post_tag_by_tag_id($tag_id){ $query = 'DELETE FROM post_tag WHERE tag_id = ?'; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$tag_id); if($stmt->execute()){ $stmt->close(); return true; }else{ echo $stmt->error; $stmt->close(); return false; } }else{ echo "stmt prepare failed"; return false; } } function delete_post_tag($post_id,$tag_id){ $query = 'DELETE FROM post_tag WHERE post_id = ? AND tag_id = ?'; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('ii',$post_id,$tag_id); if($stmt->execute()){ if($stmt->affected_rows==0){ $stmt->close(); return false; } $stmt->close(); return true; }else{ echo $stmt->error; $stmt->close(); return false; } } } function insert_post_tag($post_id,$tag_id,$status=1){ $query = 'INSERT INTO post_tag (post_id,tag_id,status) VALUES (?,?,?)'; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('iii',$post_id,$tag_id,$status); $stmt->execute(); $insert_id = $stmt->insert_id; $stmt->close(); return $insert_id; }else{ return false; } } function check_tag_exists($name){ $query = "SELECT tag_id FROM tag WHERE name = ? LIMIT 1"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('s',$name); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($id); if($stmt->fetch() && $stmt->num_rows==1){ $stmt->close(); return $id; }else{ return false; } }else{ return false; } } function tag_count($tag_id){ $query = "SELECT COUNT(*) AS total FROM post_tag WHERE tag_id = ?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$tag_id); $stmt->execute(); $stmt->bind_result($count); $stmt->fetch(); return $count; }else{ return false; } } function tag_post_count_update($tag_id,$action='increase',$amount=1){ $action = strtolower($action); $actions = array('increase','decrease'); if(in_array($action, $actions)){ switch($action){ case "increase": $action = '+'; break; case "decrease": $action = '-'; break; } $query = 'UPDATE tag SET post_count = post_count '.$action.' '.$amount.' WHERE tag_id = ?'; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$tag_id); if($stmt->execute()){ $stmt->close(); return true; }else{ echo $stmt->error; $stmt->close(); return false; } }else{ return false; } }else{ return false; } } function get_post_tags($post_id){ $query = 'SELECT tag.name FROM tag,post_tag WHERE post_tag.post_id = ? AND tag.tag_id = post_tag.tag_id'; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$post_id); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($name); $result = array(); while($stmt->fetch()){ array_push($result,$name); } $stmt->close(); return $result; }else{ return false; } } function get_post_by_tag($tag_id){ $query = 'SELECT post_id FROM post_tag WHERE tag_id = ?'; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$tag_id); $stmt->execute(); if($result = $this->get_object_result($stmt)){ $stmt->close(); return $result; }else{ $stmt->close(); return false; } }else{ return false; } } // CATEGORY Functions function get_category($id){ $query = " SELECT * FROM category WHERE category_id = ? LIMIT 1"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$id); $stmt->execute(); if($result = $this->get_object_result($stmt)){ $stmt->close(); return $result[0]; }else{ $stmt->close(); return false; } }else{ return false; } } function get_category_id_by_uri($uri){ $query = "SELECT category_id FROM category WHERE uri = ?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('s',$uri); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($id); if($stmt->fetch() && $stmt->num_rows==1){ $stmt->close(); return $id; }else{ return false; } }else{ return false; } } function insert_category($name,$uri=null,$parent_category_id,$status,$language_id){ if(!$this->myACL->hasPermission('category_edit')) die_icms(NO_PERMISSION,'red'); if(!is_null($uri)){ $uri = $this->sanitize_uri($uri); }else{ $uri = $this->sanitize_uri($name); } $uri = $this->crear_uri('category','category_id',0, $uri); $query = "INSERT INTO category (name,uri,parent_id,status,language_id) VALUES (?,'$uri',?,?,?)"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('siii',$name,$parent_category_id,$status,$language_id); $stmt->execute(); $insert_id = $stmt->insert_id; $stmt->close(); return $insert_id; }else{ return false; } } function update_category($name,$uri=null,$parent_category_id,$status,$language_id,$category_id){ if(!$this->myACL->hasPermission('category_edit')) die_icms(NO_PERMISSION,'red'); if(!is_null($uri)){ $uri = $this->sanitize_uri($uri); }else{ $uri = $this->sanitize_uri($name); } $uri = $this->crear_uri('category','category_id',$category_id, $uri); $query = "UPDATE category SET name = ?, uri = '$uri', parent_id = ?, status = ?, language_id = ? WHERE category_id = ?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('siiii',$name,$parent_category_id,$status,$language_id,$category_id); if($stmt->execute()){ $stmt->close(); return true; }else{ echo $stmt->error; $stmt->close(); return false; } } } function delete_category($category_id){ if(!$this->myACL->hasPermission('category_delete')) die_icms(NO_PERMISSION,'red'); $query = "DELETE FROM category WHERE category_id = ? LIMIT 1"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$category_id); if($stmt->execute()){ if($stmt->affected_rows==0){ $stmt->close(); return false; } $stmt->close(); return true; }else{ echo $stmt->error; $stmt->close(); return false; } }else{ echo "stmt prepare failed"; return false; } } function render_category_select($select_id,$class,$selected_id,$independent=false){ $categories = $this->search_anything($columns=array('category_id'), 'category'); $output = ''; return $output; } // LANGUAGE Functions function get_language($id){ $query = " SELECT * FROM language WHERE language_id = ? LIMIT 1"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$id); $stmt->execute(); if($result = $this->get_object_result($stmt)){ $stmt->close(); return $result[0]; }else{ $stmt->close(); return false; } }else{ return false; } } function render_language_select($select_id="language_id",$class=null,$selected_id=0,$name="language_id"){ $languages = $this->search_anything(array('language_id'), 'language', 'status = "1"'); $output = ''; return $output; } function render_original_menu_select($this_id,$selected_id=0,$select_id="original_menu_id",$class=null,$name="original_menu_id"){ $menus = $this->search_anything(array('menu_id'),'menu',' (original_menu_id IS NULL OR original_menu_id = "0") AND status="1"'); $output = ''; return $output; } // SQL SEARCH Functions function search_split_terms($terms){ $terms = preg_replace("/\"(.*?)\"/e", "search_transform_term('\$1')", $terms); $terms = preg_split("/\s+|,/", $terms); $out = array(); foreach($terms as $term){ $term = preg_replace("/\{WHITESPACE-([0-9]+)\}/e", "chr(\$1)", $term); $term = preg_replace("/\{COMMA\}/", ",", $term); $out[] = $term; } return $out; } function search_transform_term($term){ $term = preg_replace("/(\s)/e", "'{WHITESPACE-'.ord('\$1').'}'", $term); $term = preg_replace("/,/", "{COMMA}", $term); return $term; } function search_escape_rlike($string){ return preg_replace("/([.\[\]*^\$])/", '\\\$1', $string); } function search_db_escape_terms($terms){ $out = array(); foreach($terms as $term){ $out[] = AddSlashes($this->search_escape_rlike($term)); } return $out; } function search_db_escape_terms_exact_word($terms){ $out = array(); foreach($terms as $term){ $out[] = '[[:<:]]'.AddSlashes($this->search_escape_rlike($term)).'[[:>:]]'; } return $out; } function build_Search_SQL($columns,$table,$fields,$terms,$operator="OR",$condition=null,$exact_word=false){ $terms = $this->search_split_terms($terms); if($exact_word){ $terms_db = $this->search_db_escape_terms_exact_word($terms); }else{ $terms_db = $this->search_db_escape_terms($terms); } $parts = array(); foreach($terms_db as $term_db){ foreach($fields as $field){ $parts[] = "$field RLIKE '$term_db'"; } } $parts = implode(' '.$operator.' ', $parts); $columnslist = ""; $columnscount = count($columns); $i=1; foreach($columns as $column){ $columnslist .= "$column"; if($i<$columnscount){ $columnslist .=","; } $i++; } $query = "SELECT $columnslist FROM $table WHERE $parts"; if(!is_null($condition)){ $query .= " AND $condition"; } return $query; } function search_anything($columns,$table,$condition=null,$from=null,$to=null,$fields=null,$terms=null,$sidx=null,$sord=null,$operator="OR",$exact_word=false){ if(!is_null($fields)){ $query = $this->build_Search_SQL($columns,$table,$fields, $terms, $operator, $condition,$exact_word); }else{ $columnslist = ""; $columnscount = count($columns); $i=1; foreach($columns as $column){ $columnslist .= "$column"; if($i<$columnscount){ $columnslist .=","; } $i++; } $query = "SELECT $columnslist FROM $table"; if(!is_null($condition)){ $query .= " WHERE $condition"; } } if(!is_null($sidx) && !is_null($sord)){ $query .= ' ORDER BY '.$sidx.' '.$sord; } if(!is_null($from) && !is_null($to)){ $query .= ' LIMIT '.$from.','.$to; } if($resultado = $this->conn->query($query)){ $obj = new stdClass(); $i=0; while($row = $resultado->fetch_assoc()){ foreach($columns as $column){ $column = explode('.', $column); if(!empty($column[1])){ $column = $column[1]; }else{ $column = $column[0]; } $obj->{$i}->$column=$row[$column]; } $i++; } return $obj; } } // FILES Functions function insert_file($name,$size,$file_type_id,$title,$description,$tags,$user_id,$status,$seed=null,$assigned=null){ if(is_null($seed))$seed=0; if(is_null($assigned))$assigned=0; $query = "INSERT INTO file (name, size, file_type_id, title, description, tags, user_id, status, seed, assigned) VALUES ( ?,?,?,?,?,?,?,?,?,? )"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('siisssiiii',$name,$size,$file_type_id,$title,$description,$tags,$user_id,$status,$seed,$assigned); $stmt->execute(); $insert_id = $stmt->insert_id; $stmt->close(); return $insert_id; }else{ return false; } } function update_file($title,$description,$tags,$status,$file_id){ $query = "UPDATE file SET title = ?, description = ?, tags = ?, status = ? WHERE file_id = ? LIMIT 1"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('sssii',$title,$description,$tags,$status,$file_id); if($stmt->execute()){ $stmt->close(); return true; }else{ echo $stmt->error; $stmt->close(); return false; } }else{ return false; } } function delete_file($file_id){ $query = "DELETE FROM file WHERE file_id = ?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$file_id); $file = $this->get_file($file_id); switch($file->file_type_id){ case 1: $command = "rm ../media/img/$file_id--*"; exec($command); $command = "rm ../media/img/O/$file_id--*"; exec($command); break; case 2: $command = "rm ../media/aud/$file_id--*"; exec($command); break; case 3: $command = "rm ../media/vid/$file_id--*"; exec($command); $command = "rm ../media/vid/cap/$file_id--*"; exec($command); break; case 4: $command = "rm ../media/otr/$file_id--*"; exec($command); break; } $stmt->execute(); $stmt->close(); return true; }else{ return false; } } function get_file_uri($file_id,$size=null,$crop=false,$crop_ratio=''){ $query = "SELECT file_id, name, file_type_id FROM file WHERE file_id = ?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$file_id); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($file_id,$name,$file_type_id); if($stmt->fetch() && $stmt->num_rows==1){ $stmt->close(); $resultado = new stdClass(); switch($file_type_id){ case 1: $file_type_uri = "img"; if(is_null($size)){ $uri = 'media/'.$file_type_uri.'/O/'.$file_id.'--O-'.$name; }else{ if($crop){ $uri = 'media/'.$file_type_uri.'/'.$file_id.'--'.$size.'-crop-'.$crop_ratio.'-'.$name; }else{ $uri = 'media/'.$file_type_uri.'/'.$file_id.'--'.$size.'-'.$name; } } break; case 2: $file_type_uri = "aud"; if(is_null($size)){ $uri = 'media/'.$file_type_uri.'/'.$file_id.'--'.$name; }else{ $uri = 'icms/img/icons/50x-document_mp3.png'; } break; case 3: $file_type_uri = "vid"; if(is_null($size)){ $uri = 'media/'.$file_type_uri.'/'.$file_id.'--'.$name.'.flv'; }elseif($size=="O"){ $uri = 'media/'.$file_type_uri.'/cap/O/'.$file_id.'--O-'.$name.'.jpg'; }else{ $uri = 'media/'.$file_type_uri.'/cap/'.$file_id.'--'.$size.'-'.$name.'.jpg'; } break; case 4: $file_type_uri = "otr"; if(is_null($size)){ $uri = 'media/'.$file_type_uri.'/'.$file_id.'--'.$name; }else{ $extension = getFileExtension($name); switch($extension){ case ".pdf": $uri = 'icms/img/icons/50x-document_pdf.png'; break; case ".doc": case ".odt": case ".ott": $uri = 'icms/img/icons/50x-document_write.png'; break; case ".xls": case ".ods": $uri = 'icms/img/icons/50x-document_xls.png'; break; case ".zip": $uri = 'icms/img/icons/50x-document_zip.png'; break; case ".ppt": $uri = 'icms/img/icons/50x-document_zip.png'; break; default: $uri = 'icms/img/icons/50x-document_tag.png'; break; } } break; } return $uri; } } } function get_file($file_id,$thumb_size=50,$crop=false,$crop_ratio=''){ $query = "SELECT * FROM file WHERE file_id = ? LIMIT 1"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$file_id); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($file_id,$name,$size,$file_type_id,$title,$description,$tags,$user_id,$status,$seed,$assigned,$date_cre,$date_mod); if($stmt->fetch() && $stmt->num_rows==1){ $stmt->close(); $resultado = new stdClass(); $resultado->file_id = $file_id; $resultado->name = $name; $resultado->size = $size; $resultado->file_type_id = $file_type_id; $resultado->title = strip_tags($title); $resultado->description = strip_tags($description); $resultado->tags = $tags; $resultado->user_id = $user_id; $resultado->uri = $this->get_file_uri($file_id); $resultado->uri_thumb = $this->get_file_uri($file_id,$thumb_size,$crop,$crop_ratio); $resultado->status = $status; $resultado->seed = $seed; $resultado->assigned = $assigned; $resultado->date_cre = $date_cre; $resultado->date_mod = $date_mod; return $resultado; }else{ return false; } }else{ return false; } }// End get_file function function insert_menu($name,$status,$original_menu_id=null,$language_id=1){ $query = "INSERT INTO menu (name,status,original_menu_id,language_id) VALUES (?,?,?,?)"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('siii',$name,$status,$original_menu_id,$language_id); if($stmt->execute()){ $insert_id = $stmt->insert_id; $stmt->close(); return $insert_id; }else{ echo $stmt->error; return false; } }else{ return false; } }// End insert_menu function function update_menu($name,$status,$original_menu_id=null,$language_id=1,$menu_id){ $query = "UPDATE menu SET name = ?, status = ?, original_menu_id = ?, language_id = ? WHERE menu_id = ?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('siiii',$name,$status,$original_menu_id,$language_id,$menu_id); if($stmt->execute()){ $stmt->close(); return true; }else{ echo $stmt->error; $stmt->close(); return false; } } }// End update_menu function function delete_menu($menu_id){ $query = "DELETE FROM menu WHERE menu_id = ?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$menu_id); $stmt->execute(); $stmt->close(); return true; }else{ return false; } }// End delete_menu function function get_menu($id){ $query = " SELECT * FROM menu WHERE menu_id = ? LIMIT 1"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$id); $stmt->execute(); if($result = $this->get_object_result($stmt)){ $stmt->close(); return $result[0]; }else{ $stmt->close(); return false; } }else{ return false; } } // End get_menu function function insert_menu_item($text,$href,$parent_id,$item_order,$menu_id){ $query = "INSERT INTO menu_item (text,href,parent_id,item_order,menu_id) VALUES (?,?,?,?,?)"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('ssiii',$text,$href,$parent_id,$item_order,$menu_id); if($stmt->execute()){ $insert_id = $stmt->insert_id; $stmt->close(); return $insert_id; }else{ echo $stmt->error; return false; } }else{ return false; } } function delete_menu_item($menu_id){ $query = "DELETE FROM menu_item WHERE menu_id = ?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$menu_id); $stmt->execute(); $stmt->close(); return true; }else{ return false; } }// End delete_menu_item function function get_menu_item($id){ $query = " SELECT * FROM menu_item WHERE menu_item_id = ? LIMIT 1"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$id); $stmt->execute(); if($result = $this->get_object_result($stmt)){ $stmt->close(); return $result[0]; }else{ $stmt->close(); return false; } }else{ return false; } } // End get_menu_item function function get_menu_items($menu_id,$parent_id=0){ $query = "SELECT * FROM menu_item WHERE menu_id = ? AND parent_id = ? ORDER BY item_order ASC"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('ii',$menu_id,$parent_id); $stmt->execute(); if($result = $this->get_object_result($stmt)){ $stmt->close(); return $result; }else{ $stmt->close(); return false; } }else{ return false; } } function render_menu($menu_id,$selected_id=null,$link=true,$container_element="ul",$items_element="li"){ $menu_items = $this->get_menu_items($menu_id); if(!empty($menu_items)){ $output = '<'.$container_element.'>'; foreach($menu_items as $menu_item){ $menu_item = $this->get_menu_item($menu_item->menu_item_id); $output .= '<'.$items_element.'>'; if($link){ $output .= 'text; if($link){ $output .=''; } $sub_menu_items = $this->get_menu_items($menu_item->menu_id,$menu_item->menu_item_id); if(!empty($sub_menu_items)){ $output .= '<'.$container_element.'>'; foreach($sub_menu_items as $sub_menu_item){ $output .= '<'.$items_element.'>'; if($link){ $output .= 'text; if($link){ $output .=''; } $output .= ''; } $output .= ''; } $output .= ''; } $output .= ''; } echo $output; } function insert_gallery($name,$description,$status){ $query = "INSERT INTO gallery (name,description,status) VALUES (?,?,?)"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('ssi',$name,$description,$status); if($stmt->execute()){ $insert_id = $stmt->insert_id; $stmt->close(); return $insert_id; }else{ echo $stmt->error; return false; } }else{ return false; } } // End insert_gallery function function update_gallery($name,$description,$status,$gallery_id){ $query = "UPDATE gallery SET name = ?, description = ?, status = ? WHERE gallery_id = ?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('ssii',$name,$description,$status,$gallery_id); if($stmt->execute()){ $stmt->close(); return true; }else{ echo $stmt->error; $stmt->close(); return false; } } } // End update_gallery function function delete_gallery($gallery_id){ $query = "DELETE FROM gallery WHERE gallery_id = ?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$gallery_id); $stmt->execute(); $stmt->close(); return true; }else{ return false; } } // End delete_gallery function function get_gallery($gallery_id){ $query = "SELECT * FROM gallery WHERE gallery_id = ?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$gallery_id); $stmt->execute(); if($result = $this->get_object_result($stmt)){ $stmt->close(); return $result[0]; }else{ $stmt->close(); return false; } }else{ return false; } } // End get_gallery function function insert_gallery_file($gallery_id,$file_id,$file_order){ $query = "INSERT INTO gallery_file (gallery_id,file_id,file_order) VALUES (?,?,?)"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('iii',$gallery_id,$file_id,$file_order); if($stmt->execute()){ $insert_id = $stmt->insert_id; $stmt->close(); return $insert_id; }else{ echo $stmt->error; return false; } }else{ return false; } } // End insert_gallery_file function function delete_gallery_file($gallery_id){ $query = "DELETE FROM gallery_file WHERE gallery_id = ?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$gallery_id); $stmt->execute(); $stmt->close(); return true; }else{ return false; } } // End delete_gallery_file function function select_gallery_file($gallery_id){ $query = "SELECT file_id FROM gallery_file WHERE gallery_id = ? ORDER BY file_order ASC"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$gallery_id); $stmt->execute(); if($result = $this->get_object_result($stmt)){ $stmt->close(); return $result; }else{ $stmt->close(); return false; } } } function insert_gallery_post($gallery_id,$post_id){ $query = "INSERT INTO gallery_post (gallery_id,post_id) VALUES (?,?)"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('ii',$gallery_id,$post_id); if($stmt->execute()){ $insert_id = $stmt->insert_id; $stmt->close(); return $insert_id; }else{ echo $stmt->error; return false; } }else{ return false; } } // End insert_gallery_post function function delete_gallery_post($post_id){ $query = "DELETE FROM gallery_post WHERE post_id = ?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$post_id); $stmt->bind_param('i',$gallery_id); $stmt->execute(); $stmt->close(); return true; }else{ return false; } } // End delete_gallery_post function function select_gallery_post($post_id){ $query = "SELECT gallery_id FROM gallery_post WHERE post_id = ?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$post_id); $stmt->execute(); if($result = $this->get_object_result($stmt)){ $stmt->close(); return $result[0]; }else{ $stmt->close(); return false; } } } function insert_related_post($post1,$post2,$post_order,$status=1){ $query = "INSERT INTO post_post (post1,post2,post_order,status) VALUES (?,?,?,?)"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('iiii',$post1,$post2,$post_order,$status); if($stmt->execute()){ $insert_id = $stmt->insert_id; $stmt->close(); return $insert_id; }else{ echo $stmt->error; return false; } }else{ return false; } } function reset_related_post($post1){ $query = "DELETE FROM post_post WHERE post1 = ?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$post1); if($stmt->execute()){ if($stmt->affected_rows==0){ $stmt->close(); return false; } $stmt->close(); return true; }else{ echo $stmt->error; $stmt->close(); return false; } }else{ return false; } } function insert_subscriber($subscription_id,$email,$status,$name=false,$lastname=false,$phone){ $query = "INSERT INTO subscriber (subscription_id,email,status,name,lastname,phone) VALUES (?,?,?,?,?,?)"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('isisss',$subscription_id,$email,$status,$name,$lastname,$phone); if($stmt->execute()){ $insert_id = $stmt->insert_id; $stmt->close(); return $insert_id; }else{ echo $stmt->error; return false; } }else{ return false; } } function get_subscriber($subscriber_id){ $query = "SELECT * FROM subscriber WHERE subscriber_id = ? LIMIT 1"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('i',$subscriber_id); $stmt->execute(); if($result = $this->get_object_result($stmt)){ $stmt->close(); return $result[0]; }else{ $stmt->close(); return false; } } } function get_subscriber_by_email($email){ $query = "SELECT subscriber_id FROM subscriber WHERE email = ? LIMIT 1"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('s',$email); $stmt->execute(); if($result = $this->get_object_result($stmt)){ $stmt->close(); return $result[0]; }else{ $stmt->close(); return false; } } } function get_subscriber_by_subscription($subscription_id,$status=1){ $query = "SELECT subscriber_id FROM subscriber WHERE subscription_id = ? AND status = ?"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('ii',$subscription_id,$status); $stmt->execute(); if($result = $this->get_object_result($stmt)){ $stmt->close(); return $result; }else{ $stmt->close(); return false; } }else{ echo 'stmt failed'; } } function update_subscriber_status($subscriber_id,$status){ $query = "UPDATE subscriber SET status = ? WHERE subscriber_id = ? LIMIT 1"; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('ii',$status,$subscriber_id); if($stmt->execute()){ $stmt->close(); return true; }else{ echo $stmt->error; $stmt->close(); return false; } } } function insert_contact($name,$lastname,$email,$phone,$cellphone,$organization,$comment,$status=1){ $query = 'INSERT INTO contact (name,lastname,email,phone,cellphone,organization,comment,status) VALUES (?,?,?,?,?,?,?,?)'; if($stmt = $this->conn->prepare($query)){ $stmt->bind_param('sssssssi',$name,$lastname,$email,$phone,$cellphone,$organization,$comment,$status); if($stmt->execute()){ $insert_id = $stmt->insert_id; $stmt->close(); return $insert_id; }else{ echo $stmt->error; return false; } }else{ return false; } } function fecha ($timestamp){ if(!$timestamp){ $timestamp=time(); } $vect=getdate($timestamp); $vect_dia_corto=array("Dom","Lun","Mar","Mié","Jue","Vie","Sáb"); $vect_dia_largo=array("Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado"); $vect_mes_corto=array("empty","Ene","Feb","Mar","Abr","May","Jun","Jul","Ago","Sep","Oct","Nov","Dic"); $vect_mes_largo=array("empty","Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"); $result = array( 'horas' => $vect['hours'], 'minutos' => $vect['minutes'], 'segundos' => $vect['seconds'], 'dia' => $vect['mday'], 'mes' => $vect['mon'], 'año' => $vect['year'], 'dia_corto' => $vect_dia_corto[$vect['wday']], 'dia_largo' => $vect_dia_largo[$vect['wday']], 'mes_corto' => $vect_mes_corto[$vect['mon']], 'mes_largo' => $vect_mes_largo[$vect['mon']], 'fecha' => $vect_dia_largo[$vect['wday']].", ".$vect['mday']." de ".$vect_mes_largo[$vect['mon']]." de ".$vect['year']); return $result; } }// End of iCMS Class
Fatal error: Class 'iCMS' not found in /var/www/clients/client1/web1/web/current/public/icms-load.php on line 57