function get_data($codeid) { if (!preg_match('/^[a-z]+$/', $codeid)) { return; } $data = cache_fetch($codeid, 'code'); if ($data) { return $data; } $db = getdb(); if (!$db) { return false; } $res = $db->query('select editid, title, bbcode from ' . DB_TABLE . " where codeid = '{$codeid}'"); $assoc = $res->num_rows > 0 ? $res->fetch_assoc() : false; $res->free(); cache_put($codeid, 'code', $assoc); cache_purge(); // since we've accessed the db, why not purge the cache? return $assoc; }
* * Crows is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Crows. If not, see <http://www.gnu.org/licenses/>. * */ include_once('../config.php'); include('../common.php'); send_cache_headers($youtube_ttl); if($result = cache_fetch("youtube-data")) { print $result; exit; } $curl = curl_init(); $youtube_api_url=$youtube_api_url.'&alt=json&orderby='.$youtube_orderby; curl_setopt ($curl, CURLOPT_URL,$youtube_api_url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec ($curl); curl_close ($curl); cache_store("youtube-data",$result,$youtube_ttl); print($result);
function fetch_library($userid) { $stored = cache_fetch($userid, 'user'); if ($stored !== false) { return $stored; } global $message; $codes = array(); $db = getdb(); if (!$db) { return $codes; } $sql = 'select now() as now, m.*, u.editable from ' . DB_TABLE . ' m, ' . DB_TABLE . '_users u where u.codeid = m.codeid and u.userid = \'' . $db->escape_string($userid) . '\' order by m.updated desc limit 100'; $res = $db->query($sql); if ($res) { require_once 'mapbbcode.php'; while ($row = $res->fetch_assoc()) { $item = array(); $item['codeid'] = $row['codeid']; $item['editid'] = $row['editable'] ? $row['editid'] : ''; $item['created'] = human_date($row['created'], $row['now']); $item['updated'] = human_date($row['updated'], $row['now']); $item['title'] = $row['title']; $item['stats'] = mapbbcode_stats($row['bbcode']); $codes[] = $item; } $res->free(); cache_put($userid, 'user', $codes); } else { $message = 'Failed to retrieve user library: ' . $db->error; } return $codes; }
* * You should have received a copy of the GNU General Public License * along with Crows. If not, see <http://www.gnu.org/licenses/>. * */ include_once('../config.php'); include_once('../common.php'); $page=!empty($_POST['page']) ? $_POST['page'] : 1; send_cache_headers($flickr_ttl); $flickr_request_url = $flickr_api_url.'&format=json&page='.$page; if($result = cache_fetch($flickr_request_url)) { print $result; exit; } $curl = curl_init(); curl_setopt ($curl, CURLOPT_URL,$flickr_request_url); curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec ($curl); curl_close ($curl); cache_store($flickr_request_url, $result, $flickr_ttl); print $result;
include_once('../config.php'); include('../common.php'); send_cache_headers($twitter_ttl); header("Content-type: text/json"); $searchterm=$_POST['searchterm']; $page=$_POST['page']; $twitterquery='http://search.twitter.com/search.json?q='.urlencode($searchterm).'&rpp=100&page='.$page; if($result = cache_fetch($twitterquery)) { print $result; exit; } //call twitter $curl = curl_init(); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.7')); curl_setopt ($curl, CURLOPT_URL,$twitterquery); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec ($curl); curl_close ($curl); cache_store($twitterquery, $result, $twitter_ttl); print($result);
* * Crows is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Crows. If not, see <http://www.gnu.org/licenses/>. * */ include('../config.php'); include('../common.php'); send_cache_headers($podcast_ttl); if($result = cache_fetch("podcast-proxy")) { print $result; exit; } header("Content-type: text/xml"); $curl = curl_init(); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.7')); curl_setopt ($curl, CURLOPT_URL,$podcast_feed_url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec ($curl); curl_close ($curl); $result=str_replace('media:','',$result); cache_store("podcast-proxy", $result, $podcast_ttl);