getSslPage($apiUrl)); // $items = $apiResult->items; // foreach ($items as $item) { // $snippet = $item->snippet; // $published = $snippet->publishedAt; // $author = $snippet->channelTitle; // $author_url = "https://youtube.com/channel/" . $snippet->channelId; // $title = $snippet->title; // if (isset($snippet->thumbnails->maxres->url)) $thumbnail = $snippet->thumbnails->maxres->url; // else $thumbnail = $snippet->thumbnails->standard->url; // $url = "http://youtu.be/" . $snippet->resourceId->videoId; // // $this->db->query('INSERT INTO social_posts (origin, post_content, post_url, post_author, post_author_url, date, post_img_source) VALUES (?, ?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE post_content = ?, post_img_source = ?;', ["YouTube", $title, $url, $author, $author_url, strtotime($published), $thumbnail, $title, $thumbnail]); // } // } // // public function getTwitterPosts() // { // $consumer_key = 'TsUzd4stukv9Ix7TGG7RdYq4k'; // $consumer_key_secret = 'sTRq4WcELJZuciTrkNUttGgWhEiGaUkuqNhISgaG4uHRFgzm0B'; // $access_token = '1880071790-Nij2RaBDVRGVWoWW2PSJUwAvuLAOaQFAAr5tAtC'; // $access_token_secret = 'ldhLg0SP3ycrrdIqhNcddj0042pdGY9vmZMKQJRClmDkD'; // // $oauth_hash = 'count=20&oauth_consumer_key=' . $consumer_key . '&oauth_nonce=' . time() . '&oauth_signature_method=HMAC-SHA1&oauth_timestamp=' . time() . '&oauth_token=' . $access_token . '&oauth_version=1.0'; // $base = 'GET&' . urlencode('https://api.twitter.com/1.1/statuses/user_timeline.json') . '&' . rawurlencode($oauth_hash); // $key = rawurlencode($consumer_key_secret) . '&' . rawurlencode($access_token_secret); // $signature = base64_encode(hash_hmac('sha1', $base, $key, true)); // $signature = rawurlencode($signature); // // $oauth_header = 'oauth_consumer_key="' . $consumer_key . '", oauth_nonce="' . time() . '", oauth_signature="' . $signature . '", oauth_signature_method="HMAC-SHA1", oauth_timestamp="' . time() . '", oauth_token="' . $access_token . '", oauth_version="1.0", '; // $curl_header = array("Authorization: Oauth {$oauth_header}", 'Expect:'); // // $curl_request = curl_init(); // curl_setopt($curl_request, CURLOPT_HTTPHEADER, $curl_header); // curl_setopt($curl_request, CURLOPT_HEADER, false); // curl_setopt($curl_request, CURLOPT_URL, 'https://api.twitter.com/1.1/statuses/user_timeline.json?count=20'); // curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, true); // curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false); // $json = curl_exec($curl_request); // curl_close($curl_request); // // $posts = json_decode($json); // // // foreach ($posts as $post) { // $content = str_replace("\n", "
", $post->text); // $author = $post->user->screen_name; // $author_url = 'https://twitter.com/' . $author; // $url = $author_url . '/status/' . $post->id_str; // $published = strtotime($post->created_at); // $original_id = $post->id_str; // if (isset($post->extended_entities->media[0]->media_url)) { // $image = $post->extended_entities->media[0]->media_url; // } else { // $image = ''; // } // $this->db->query('INSERT INTO social_posts (origin, post_content, post_url, post_author, post_author_url, date, post_img_source, post_original_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE post_content = ?, post_author_url = ?, post_original_id = ?;', ["Twitter", $content, $url, $author, $author_url, $published, $image, $original_id, $content, $author_url, $original_id]); // } // } public function newestVids($vidCount) { $data = $this->db->query('SELECT * FROM social_posts WHERE origin = "YouTube" ORDER BY date DESC LIMIT ?', [$vidCount])->result_array(); if (!empty($data)) { return $data; } else { return null; } } public function getAllPosts() { $this->getTwitterPosts(); $items = $this->db->query('SELECT * FROM social_posts ORDER BY date DESC')->result_array(); return $items; } public function getPosts($amount, $offset) { if ($offset == 0) { $items = $this->db->query('SELECT * FROM social_posts ORDER BY date DESC LIMIT ?', [$amount])->result_array(); } else { $items = $this->db->query('SELECT * FROM social_posts ORDER BY date DESC LIMIT ? OFFSET ?', [$amount, $offset])->result_array(); } return $items; } public function getPostsOfCategory($amount, $offset, $category) { if ($offset == 0) { $items = $this->db->query('SELECT * FROM social_posts WHERE origin LIKE ? ORDER BY date DESC LIMIT ?', [$category, $amount])->result_array(); } else { $items = $this->db->query('SELECT * FROM social_posts WHERE origin LIKE ? ORDER BY date DESC LIMIT ? OFFSET ?', [$category, $amount, $offset])->result_array(); } return $items; } }