function cache_get_new_data($back_url, $entries) { $rdf = parse_url($back_url); $fp = fsockopen($rdf['host'], 80, $errno, $errstr, 15); if (!$fp) { rssfail("Can't connect to host."); } else { // print("<p>fsockopen ".$rdf['host']."\n"); fputs($fp, "GET " . $rdf['path'] . "?" . $rdf['query'] . " HTTP/1.0\r\n"); fputs($fp, "HOST: " . $rdf['host'] . "\r\n\r\n"); $string = ""; while (!feof($fp)) { $pagetext = fgets($fp, 228); $string .= chop($pagetext); } fputs($fp, "Connection: close\r\n\r\n"); fclose($fp); // print("<p>fsockclose ".$rdf['host']."\n"); $items = explode("</item>", $string); $content = "<span class=\"small\">"; for ($i = 0; $i < $entries; $i++) { $link = ereg_replace(".*<link>", "", $items[$i]); $link = ereg_replace("</link>.*", "", $link); $title2 = ereg_replace(".*<title>", "", $items[$i]); $title2 = ereg_replace("</title>.*", "", $title2); if (strcmp($link, $title2)) { $content .= "<li><a href=\"{$link}\" target=\"_blank\">{$title2}</a></li>\n"; } } $content .= "</span>"; } $content = FixQuotes($content); return $content; }
function BlocksEditSave($bid, $bkey, $title, $content, $url, $oldposition, $bposition, $active, $refresh, $weight, $blanguage, $blockfile, $view, $expire, $action, $subscription, $moretime) { global $prefix, $db, $admin_file; if (!empty($moretime)) { $moretime = $moretime * 86400; $expire = $moretime + $expire; } if (!empty($url)) { $bkey = ""; $btime = time(); if (!ereg("http://", $url)) { $url = "http://{$url}"; } $rdf = parse_url($url); $fp = fsockopen($rdf['host'], 80, $errno, $errstr, 15); if (!$fp) { rssfail(); exit; } if ($fp) { fputs($fp, "GET " . $rdf['path'] . "?" . $rdf['query'] . " HTTP/1.0\r\n"); fputs($fp, "HOST: " . $rdf['host'] . "\r\n\r\n"); $string = ""; while (!feof($fp)) { $pagetext = fgets($fp, 300); $string .= chop($pagetext); } fputs($fp, "Connection: close\r\n\r\n"); fclose($fp); $items = explode("</item>", $string); $content = "<font class=\"content\">"; for ($i = 0; $i < 10; $i++) { $link = ereg_replace(".*<link>", "", $items[$i]); $link = ereg_replace("</link>.*", "", $link); $title2 = ereg_replace(".*<title>", "", $items[$i]); $title2 = ereg_replace("</title>.*", "", $title2); if ($items[$i] == "" and $cont != 1) { $content = ""; } else { if (strcmp($link, $title2) and $items[$i] != "") { $cont = 1; $content .= "<strong><big>·</big></strong> <a href=\"{$link}\" target=\"new\">{$title2}</a><br>\n"; } } } } if ($oldposition != $bposition) { $result = $db->sql_query("select bid from " . $prefix . "_blocks where weight>='{$weight}' AND bposition='{$bposition}'"); $fweight = $weight; $oweight = $weight; while ($row = $db->sql_fetchrow($result)) { $nbid = intval($row['bid']); $weight++; $db->sql_query("update " . $prefix . "_blocks set weight='{$weight}' where bid='{$nbid}'"); } $result2 = $db->sql_query("select bid from " . $prefix . "_blocks where weight>'{$oweight}' AND bposition='{$oldposition}'"); while ($row2 = $db->sql_fetchrow($result2)) { $obid = intval($row2['bid']); $db->sql_query("update " . $prefix . "_blocks set weight='{$oweight}' where bid='{$obid}'"); $oweight++; } $row3 = $db->sql_fetchrow($db->sql_query("select weight from " . $prefix . "_blocks where bposition='{$bposition}' order by weight DESC limit 0,1")); $lastw = $row3['weight']; if ($lastw <= $fweight) { $lastw++; $db->sql_query("update " . $prefix . "_blocks set title='{$title}', content='{$content}', bposition='{$bposition}', weight='{$lastw}', active='{$active}', refresh='{$refresh}', blanguage='{$blanguage}', blockfile='{$blockfile}', view='{$view}', subscription='{$subscription}' where bid='{$bid}'"); } else { $db->sql_query("update " . $prefix . "_blocks set title='{$title}', content='{$content}', bposition='{$bposition}', weight='{$fweight}', active='{$active}', refresh='{$refresh}', blanguage='{$blanguage}', blockfile='{$blockfile}', view='{$view}', subscription='{$subscription}' where bid='{$bid}'"); } } else { $db->sql_query("update " . $prefix . "_blocks set bkey='{$bkey}', title='{$title}', content='{$content}', url='{$url}', bposition='{$bposition}', weight='{$weight}', active='{$active}', refresh='{$refresh}', blanguage='{$blanguage}', blockfile='{$blockfile}', view='{$view}', subscription='{$subscription}' where bid='{$bid}'"); } Header("Location: " . $admin_file . ".php?op=BlocksAdmin"); } else { $title = filter($title, "nohtml", 1); $content = filter($content, "", 1); if ($oldposition != $bposition) { $result5 = $db->sql_query("select bid from " . $prefix . "_blocks where weight>='{$weight}' AND bposition='{$bposition}'"); $fweight = $weight; $oweight = $weight; while ($row5 = $db->sql_fetchrow($result5)) { $nbid = intval($row5['bid']); $weight++; $db->sql_query("update " . $prefix . "_blocks set weight='{$weight}' where bid='{$nbid}'"); } $result6 = $db->sql_query("select bid from " . $prefix . "_blocks where weight>'{$oweight}' AND bposition='{$oldposition}'"); while ($row6 = $db->sql_fetchrow($result6)) { $obid = intval($row6['bid']); $db->sql_query("update " . $prefix . "_blocks set weight='{$oweight}' where bid='{$obid}'"); $oweight++; } $row7 = $db->sql_fetchrow($db->sql_query("select weight from " . $prefix . "_blocks where bposition='{$bposition}' order by weight DESC limit 0,1")); $lastw = $row7['weight']; if ($lastw <= $fweight) { $lastw++; $db->sql_query("update " . $prefix . "_blocks set title='{$title}', content='{$content}', bposition='{$bposition}', weight='{$lastw}', active='{$active}', refresh='{$refresh}', blanguage='{$blanguage}', blockfile='{$blockfile}', view='{$view}', subscription='{$subscription}' where bid='{$bid}'"); } else { $db->sql_query("update " . $prefix . "_blocks set title='{$title}', content='{$content}', bposition='{$bposition}', weight='{$fweight}', active='{$active}', refresh='{$refresh}', blanguage='{$blanguage}', blockfile='{$blockfile}', view='{$view}', subscription='{$subscription}' where bid='{$bid}'"); } } else { if (empty($expire)) { $expire = 0; } if ($expire != 0 and $expire <= 999) { $expire = time() + $expire * 86400; } $result8 = $db->sql_query("update " . $prefix . "_blocks set bkey='{$bkey}', title='{$title}', content='{$content}', url='{$url}', bposition='{$bposition}', weight='{$weight}', active='{$active}', refresh='{$refresh}', blanguage='{$blanguage}', blockfile='{$blockfile}', view='{$view}', expire='{$expire}', action='{$action}', subscription='{$subscription}' where bid='{$bid}'"); } Header("Location: " . $admin_file . ".php?op=BlocksAdmin"); } }
if (filesize($cache_file) <= 1 || time() - filectime($cache_file) > $time) { if (!file_exists($cache_file)) { @touch($cache_file); } if ($rfh = @fopen($cache_file, 'r')) { // obtain a blocking write lock, else wait 1 second and try again if (flock($rfh, 2)) { // open file for writing. if this does not work, something is broken. if (!($wfh = @fopen($cache_file, 'w'))) { rssfail("Can't write cache file."); } else { // have successful locks and opens now $rdf = parse_url($back_url); $fp = fsockopen($rdf['host'], 80, $errno, $errstr, 15); if (!$fp) { rssfail("Can't connect to host."); } else { fputs($fp, "GET " . $rdf['path'] . "?" . $rdf['query'] . " HTTP/1.0\r\n"); fputs($fp, "HOST: " . $rdf['host'] . "\r\n\r\n"); $string = ""; while (!feof($fp)) { $pagetext = fgets($fp, 228); $string .= chop($pagetext); } fputs($fp, "Connection: close\r\n\r\n"); fclose($fp); $items = explode("</item>", $string); $content = "<span class=\"small\">"; for ($i = 0; $i < 35; $i++) { $link = ereg_replace(".*<link>", "", $items[$i]); $link = ereg_replace("</link>.*", "", $link);
function BlocksEditSave($bid) { global $prefix, $db; if (!Security::check_post()) { cpg_error(_SEC_ERROR); } $update['title'] = $_POST['title']; $update['content'] = $_POST['content']; $update['url'] = empty($_POST['url']) ? '' : $_POST['url']; $oldposition = $_POST['oldposition']; $update['bposition'] = $_POST['bposition']; $update['active'] = $_POST['active']; $update['refresh'] = isset($_POST['refresh']) ? intval($_POST['refresh']) : 0; $update['blanguage'] = $_POST['blanguage']; $update['blockfile'] = empty($_POST['blockfile']) ? '' : $_POST['blockfile']; $update['view'] = intval($_POST['view']); $update['weight'] = intval($_POST['weight']); $update['in_module'] = ''; if ($update['url'] != '') { $update['time'] = time(); if (0 !== stripos($update['url'], 'http://')) { $update['url'] = 'http://' . $update['url']; } require_once CORE_PATH . 'classes/rss.php'; if (!($update['content'] = CPG_RSS::format(CPG_RSS::read($update['url'])))) { rssfail(); return; } } # can be removed if ($oldposition != $update['bposition']) { $db->sql_query('UPDATE ' . $prefix . '_blocks SET weight=weight+1 WHERE weight>=' . $update['weight'] . " AND bposition='{$update['bposition']}'"); $db->sql_query('UPDATE ' . $prefix . '_blocks SET weight=weight-1 WHERE weight>' . $update['weight'] . " AND bposition='{$oldposition}'"); } $db->sql_update($prefix . '_blocks', $update, 'bid=' . $bid); $count = empty($_POST['in_module']) ? 0 : count($_POST['in_module']); for ($i = 0; $i < $count; $i++) { if (!intval($_POST['in_module'][$i])) { continue; } else { $new_in_modules[intval($_POST['in_module'][$i])] = intval($_POST['in_module'][$i]); } } $table_data = array(); # select all data $result = $db->sql_query('SELECT a.mid, a.bid, MAX(b.weight) FROM ' . $prefix . '_blocks_custom a, ' . $prefix . '_blocks_custom b GROUP BY a.mid, a.bid'); if ($db->sql_numrows($result)) { while ($row = $db->sql_fetchrow($result, SQL_NUM)) { # block is there but module id has not been posted so delete from it if ($row[1] == $bid && !isset($new_in_modules[$row[0]])) { $db->sql_uquery('DELETE FROM ' . $prefix . "_blocks_custom WHERE bid={$bid} AND mid=" . $row[0]); $db->sql_uquery('UPDATE ' . $prefix . "_blocks_custom SET weight=weight-1 WHERE weight>{$row[2]} AND mid=" . $row[0]); } else { if ($row[1] == $bid && isset($new_in_modules[$row[0]])) { # module id has been posted and it exists within the table: clearing posteded data $new_in_modules[$row[0]] = ''; } } if (!isset($table_data[$row[0]])) { # save what we need for later use $table_data[$row[0]] = $row[2]; } } $db->sql_freeresult($result); } $values = array(); # insert anything left from the posted data if (!empty($new_in_modules)) { foreach ($new_in_modules as $mid) { if (!empty($mid)) { $values[] = "('{$bid}', '{$mid}', '{$update['bposition']}', '" . ($table_data[$mid] + 1) . "')"; } } } if (!empty($values)) { $db->sql_uquery('INSERT INTO ' . $prefix . '_blocks_custom (bid, mid, side, weight) VALUES ' . implode(',', $values)); } Cache::array_delete('blocks_list'); URL::redirect(URL::admin('blocks')); }