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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
| <?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Crud_model extends Model {
function Crud_model() {
parent::Model();
}
////user///////////////////////////////
function admin_login($username,$password) {
if($username=="" || $password=="")
return false;
$sql = "SELECT * FROM admin WHERE username = ? AND password = ?";
$query=$this->db->query($sql, array($username,$password));
if ($query->num_rows() > 0)
return true;
else
return false;
}
function retrieve_password()
{
$query=$this->db->get('user');
return $query->result();
}
function update_password($password_new)
{
$sql = "UPDATE user SET `password` = '$password_new' ";
$query=$this->db->query($sql);
}
////facebook user///////////////////////
function create_facebook_user($data)
{
$sql = $this->db->insert_string('facebook_user', $data);
$query=$this->db->query($sql);
}
function retrieve_facebook_user()
{
$query=$this->db->get('facebook_user');
return $query->result();
}
////category////////////////////////////
function create_category($name)
{
$sql = "INSERT INTO category(`name`) VALUES ('$name') ";
$query=$this->db->query($sql);
}
function retrieve_category_all()
{
$query = $this->db->get('category');
return $query->result();
}
function retrieve_category_name($category_id)
{
$this->db->where('category_id' , $category_id );
$query = $this->db->get('category');
$result = $query->result();
foreach($result as $row)
return $row->name;
}
function delete_category($name)
{
$sql = $this->db->delete('category', array('name' => $name));
//$query=$this->db->query($sql);
}
function update_category($data,$category_id)
{
$this->db->where('category_id' , $category_id);
$this->db->update('category',$data);
}
////site_info////////////////////////////
function retrieve_site_info()
{
$query=$this->db->get('site_info');
return $query->result();
}
function update_site_info($data)
{
$this->db->update('site_info',$data);
}
/////admin///////////////////////////
function retrieve_admin()
{
$query=$this->db->get('admin');
return $query->result();
}
function update_admin($data)
{
$this->db->update('admin',$data);
}
/////video//////////////////////////////
function create_video($data)
{
$sql = $this->db->insert_string('video', $data);
$query=$this->db->query($sql);
}
function retrieve_video($sort)
{
$this->db->order_by($sort, "desc");
$this->db->limit(12);
$this->db->where('valid', 1);
$query=$this->db->get('video');
return $query->result();
}
function retrieve_video_all($sort , $category_id, $featured, $limit = NULL, $offset = 0)
{
if($sort == 'recent')
{
$sort = 'id';
}
else if($sort == 'viewed')
{
$sort = 'viewed';
}
else $sort = 'id';
$this->db->order_by($sort, "desc");
if($category_id != 'all')
{
$this->db->where('category_id', $category_id);
}
if($featured == 'featured')
{
$this->db->where('featured', 1);
}
$query = $this->db->get('video',$limit, $offset);
return $query->result_array();
}
function retrieve_single_video($id)
{
$this->db->where('id', $id);
$query=$this->db->get('video');
$result = $query->result_array();
foreach($result as $video_data)return $video_data;
}
function retrieve_video_rss()
{
//$this->db->order_by('id', "desc");
$query=$this->db->get('video' , 20,0);
return $query->result();
}
function count_video_by_category($category_id)
{
$this->db->where('category_id', $category_id);
$query=$this->db->get('video');
return $query->num_rows();
}
function update_video_viewed($id)
{
//$this->db->where('id' , $id);
//$this->db->update('video',$data);
$sql = "UPDATE `video` SET `viewed` = `viewed`+1 WHERE `video`.`id` ='$id' LIMIT 1 ;";
$query=$this->db->query($sql);
}
function delete_video($id)
{
//$query=$this->db->query($sql);
$sql = $this->db->delete('video', array('id' => $id));
}
function youtube_gdata($mode = NULL , $limit = NULL , $offset = 1, $string = NULL )
{
$query = $this->db->get('site_info');
$key_res = $query->result_array();
foreach($key_res as $row)$key = $row['youtube_developer_key'];
if($mode == 'top_rated')
$url = 'https://gdata.youtube.com/feeds/api/standardfeeds/top_rated?alt=rss&key='.$key;
if($mode == 'most_popular')
$url = 'https://gdata.youtube.com/feeds/api/standardfeeds/most_popular?alt=rss&key='.$key;
if($mode == 'most_viewed')
$url = 'https://gdata.youtube.com/feeds/api/standardfeeds/most_viewed?alt=rss&key='.$key;
if($mode == 'most_shared')
$url = 'https://gdata.youtube.com/feeds/api/standardfeeds/most_shared?alt=rss&key='.$key;
if($mode == 'most_recent')
$url = 'https://gdata.youtube.com/feeds/api/standardfeeds/most_recent?alt=rss&key='.$key;
if($mode == 'recently_featured')
$url = 'https://gdata.youtube.com/feeds/api/standardfeeds/recently_featured?alt=rss&key='.$key;
if($mode == 'related')
$url = 'https://gdata.youtube.com/feeds/api/videos/'.$string.'/related?alt=rss&key='.$key;
if($mode == 'search')
$url = 'https://gdata.youtube.com/feeds/api/videos?q='.$string.'&orderby=rating&start-index='.$offset.'&max-results='.$limit.'&v=2&alt=rss&key='.$key;
//---------------------------------------------------------------------------------------------------------------------
$this->load->library('RSSParser', array('url' => $url));
$data = $this->rssparser->getFeed($limit);
return $data ;
//foreach ($data as $item) :
// $details = $this->crud_model->get_video_details($this->get_youtube_id($item['link']));
//endforeach;
}
function get_video_details($youtube_id = NULL)
{
$query = $this->db->get('site_info');
$key_res = $query->result_array();
foreach($key_res as $row)$key = $row['youtube_developer_key'];
// set video data feed URL
$feedURL = 'http://gdata.youtube.com/feeds/api/videos/'. $youtube_id.'?key='.$key;
// read feed into SimpleXML object
$entry = simplexml_load_file($feedURL);
// parse video entry
$video_info = $this->parseVideoEntry($entry);
$video['title'] = $video_info->title;
$video['type'] = 'youtube';
$video['video_id'] = $youtube_id;
$video['description'] = $video_info->description;
//$video['keywords'] = $video_info->keywords;
$video['thumbnail'] = $video_info->thumbnailURL;
$video['duration'] = $video_info->length;
$video['url_web'] = $video_info->watchURL;
$video['youtube_id'] = $youtube_id;
$video['url_embed'] = 'http://www.youtube.com/embed/'.$youtube_id;
$video['category'] = '';
//print_r($video);
return $video;
}
function parseVideoEntry($entry) {
$obj= new stdClass;
// get nodes in media: namespace for media information
$URL = "http://search.yahoo.com/mrss/";
$media = simplexml_load_file($URL);
$obj->title = $media->group->title;
$obj->description = $media->group->description;
// get video player URL
@$attrs = $media->group->player->attributes();
$obj->watchURL = $attrs['url'];
// get video thumbnail
$attrs = $media->group->thumbnail[0]->attributes();
$obj->thumbnailURL = $attrs['url'];
// get <yt:duration> node for video length
$yt = $media->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->duration->attributes();
$obj->length = $attrs['seconds'];
// get <yt:stats> node for viewer statistics
$yt = $entry->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->statistics->attributes();
$obj->viewCount = $attrs['viewCount'];
// get <gd:rating> node for video ratings
$gd = $entry->children('http://schemas.google.com/g/2005');
if ($gd->rating) {
$attrs = $gd->rating->attributes();
$obj->rating = $attrs['average'];
} else {
$obj->rating = 0;
}
// get <gd:comments> node for video comments
$gd = $entry->children('http://schemas.google.com/g/2005');
if ($gd->comments->feedLink) {
$attrs = $gd->comments->feedLink->attributes();
$obj->commentsURL = $attrs['href'];
$obj->commentsCount = $attrs['countHint'];
}
// get feed URL for video responses
$entry->registerXPathNamespace('feed', 'http://www.w3.org/2005/Atom');
$nodeset = $entry->xpath("feed:link[@rel='http://gdata.youtube.com/schemas/
2007#video.responses']");
if (count($nodeset) > 0) {
$obj->responsesURL = $nodeset[0]['href'];
}
// get feed URL for related videos
$entry->registerXPathNamespace('feed', 'http://www.w3.org/2005/Atom');
$nodeset = $entry->xpath("feed:link[@rel='http://gdata.youtube.com/schemas/
2007#video.related']");
if (count($nodeset) > 0) {
$obj->relatedURL = $nodeset[0]['href'];
}
// return object to caller
return $obj;
}
} |
Partager