Beispiel #1
0
/**
 * 获取或生成采集地址
 */
function cacherobotlist($type, $url, $robotid, $sarray = array(), $varname = 'newurlarr')
{
    global $alang;
    $cachefile = S_ROOT . './data/robot/' . $robotid . '_' . md5($url) . '.php';
    if ($type == 'get') {
        if (file_exists($cachefile)) {
            include_once $cachefile;
            showprogress($alang['robot_robot_cache_read'] . ' (' . srealpath($cachefile) . ')', 1);
            //srealpath是格式化URL地址
            return ${$varname};
        } else {
            return false;
        }
    } else {
        $wtext = arrayeval($sarray);
        if (!@($fp = fopen($cachefile, 'w'))) {
            showprogress($alang['robot_robot_cache_write_failed'] . ' (' . srealpath($cachefile) . ')', 1);
            //缓存无法写入
        } else {
            $text = "<?php\n\n";
            $text .= '$' . $varname . '=';
            $text .= $wtext;
            $text .= "\n\n?>";
            flock($fp, 2);
            fwrite($fp, $text);
            fclose($fp);
            showprogress($alang['robot_robot_cache_write_success'] . ' (' . srealpath($cachefile) . ')', 1);
        }
    }
}
                errorlog('Cron', srealpath($attachfilepath) . ' have no permission to be removed.', 0);
            }
        } else {
            errorlog('Cron', srealpath($attachfilepath) . ' not found.', 0);
        }
    }
    $deletethumbflag = true;
    if (!empty($attach['thumbpath'])) {
        $attachthumbpath = A_DIR . '/' . $attach['thumbpath'];
        if (file_exists($attachthumbpath)) {
            if (!@unlink($attachthumbpath)) {
                $deletethumbflag = false;
                errorlog('Cron', srealpath($attachthumbpath) . ' have no permission to be removed.', 0);
            }
        } else {
            errorlog('Cron', srealpath($attachthumbpath) . ' not found.', 0);
        }
    }
    if ($deletefileflag && $deletethumbflag) {
        $uid = $attach['uid'];
        $delaidarr[] = $attach['aid'];
        if (empty($delsizearr[$uid])) {
            $delsizearr[$uid] = $attach['size'];
        } else {
            $delsizearr[$uid] = $delsizearr[$uid] + $attach['size'];
        }
    }
}
if (!empty($delaidarr)) {
    $_SGLOBAL['db']->query('DELETE FROM ' . tname('attachments') . ' WHERE aid IN (' . simplode($delaidarr) . ')');
}
Beispiel #3
0
<?php

/*
	[SupeSite] (C) 2007-2009 Comsenz Inc.
	$Id: tagcontent.php 10898 2008-12-31 02:58:50Z zhaofei $
*/
if (!defined('IN_SUPESITE')) {
    exit('Access Denied');
}
$cachefile = S_ROOT . './data/system/tag.cache.php';
$tagnamearr = array();
$query = $_SGLOBAL['db']->query('SELECT tagname FROM ' . tname('tags') . ' ORDER BY spacenewsnum DESC LIMIT 0,100');
while ($tag = $_SGLOBAL['db']->fetch_array($query)) {
    if (strlen($tag['tagname']) > 2) {
        $tagnamearr[] = $tag['tagname'];
    }
}
if (empty($tagnamearr)) {
    $text = '';
} else {
    $text = '$_SGLOBAL[\'tagcontent\']=\'' . implode('|', $tagnamearr) . '\';';
}
if (!writefile($cachefile, $text, 'php', 'w', 0)) {
    errorlog('Cron', srealpath($cachefile) . ' Not found or have no access!', 0);
}
Beispiel #4
0
function writefile($filename, $writetext, $filemod = 'text', $openmod = 'w', $eixt = 1)
{
    if (!@($fp = fopen($filename, $openmod))) {
        if ($eixt) {
            exit('File :<br>' . srealpath($filename) . '<br>Have no access to write!');
        } else {
            return false;
        }
    } else {
        $text = '';
        if ($filemod == 'php') {
            $text = "<?php\r\n\r\nif(!defined('IN_SUPESITE')) exit('Access Denied');\r\n\r\n";
        }
        $text .= $writetext;
        if ($filemod == 'php') {
            $text .= "\r\n\r\n?>";
        }
        flock($fp, 2);
        fwrite($fp, $text);
        fclose($fp);
        return true;
    }
}
Beispiel #5
0
/**
 * ¶ÁÄ£°åÒ³½øÐÐÌæ»»ºóдÈëµ½cacheÒ³Àï
 *
 * @param string $tplfile £ºÄ£°åÎļþÃû
 * @param string $objfile £ºcacheÎļþÃû
 * @return 
 */
function parse_template($tplfile, $objfile, $template = '')
{
    global $_SCONFIG;
    //read
    if (empty($template)) {
        if (!@($fp = fopen($tplfile, 'r'))) {
            exit('Template file :<br>' . srealpath($tplfile) . '<br>Not found or have no access!');
        }
        $template = fread($fp, filesize($tplfile));
        fclose($fp);
        $template = str_replace('<?exit?>', '', $template);
    }
    //parse
    $var_regexp = "((\\\$[a-zA-Z_-ÿ][a-zA-Z0-9_-ÿ]*)(\\[[a-zA-Z0-9_\\-\\.\"\\'\\[\\]\$-ÿ]+\\])*)";
    $const_regexp = "([a-zA-Z_-ÿ][a-zA-Z0-9_-ÿ]*)";
    $template = preg_replace("/([\n\r]+)\t+/s", "\\1", $template);
    $template = preg_replace("/\\<\\!\\-\\-\\{(.+?)\\}\\-\\-\\>/s", "{\\1}", $template);
    $template = preg_replace("/\\{lang\\s+(.+?)\\}/ies", "languagevar('\\1')", $template);
    $template = str_replace("{LF}", "<?=\"\\n\"?>", $template);
    $template = preg_replace("/(\\\$[a-zA-Z0-9_\\[\\]\\'\"\$-ÿ]+)\\.([a-zA-Z_-ÿ][a-zA-Z0-9_-ÿ]*)/s", "\\1['\\2']", $template);
    $template = preg_replace("/\\{(\\\$[a-zA-Z0-9_\\[\\]\\'\"\$\\.-ÿ]+)\\}/s", "<?=\\1?>", $template);
    $template = preg_replace("/\\{(\\\$[a-zA-Z0-9_\\[\\]\\'\"\$\\.-ÿ]+)\\}/s", "<?=\\1?>", $template);
    $template = preg_replace("/{$var_regexp}/es", "addquote('<?=\\1?>')", $template);
    $template = preg_replace("/\\<\\?\\=\\<\\?\\={$var_regexp}\\?\\>\\?\\>/es", "addquote('<?=\\1?>')", $template);
    $template = preg_replace("/[\n\r\t]*\\{block\\s+name=\"(.+?)\"\\s+parameter=\"(.+?)\"\\}[\n\r\t]*/ies", "blocktags('\\1', '\\2')", $template);
    $template = preg_replace("/[\n\r\t]*\\#date\\((.+?)\\)\\#[\n\r\t]*/ies", "striptagquotes('<?php sdate(\\1); ?>')", $template);
    $template = preg_replace("/[\n\r\t]*\\#getad\\((.+?)\\)\\#[\n\r\t]*/ies", "striptagquotes('<?php echo getad(\\1); ?>')", $template);
    $template = preg_replace("/[\n\r\t]*\\#(uid|action)(.+?)\\#[\n\r\t]*/ies", "striptagquotes('<?php echo geturl(\"\\1\\2\"); ?>')", $template);
    $template = ltrim($template);
    $template = "<?php if(!defined('IN_SUPESITE')) exit('Access Denied'); ?>{$template}";
    $template = preg_replace("/[\n\r\t]*\\{template\\s+([a-z0-9_]+)\\}[\n\r\t]*/is", "\n<?php include template('\\1'); ?>\n", $template);
    $template = preg_replace("/[\n\r\t]*\\{template\\s+(.+?)\\}[\n\r\t]*/is", "\n<?php include template(\\1); ?>\n", $template);
    $template = preg_replace("/[\n\r\t]*\\{eval\\s+(.+?)\\}[\n\r\t]*/ies", "stripvtags('<?php \\1; ?>','')", $template);
    $template = preg_replace("/[\n\r\t]*\\{echo\\s+(.+?)\\}[\n\r\t]*/ies", "stripvtags('\n<?php echo \\1; ?>\n','')", $template);
    $template = preg_replace("/[\n\r\t]*\\{elseif\\s+(.+?)\\}[\n\r\t]*/ies", "stripvtags('\n<?php } elseif(\\1) { ?>\n','')", $template);
    $template = preg_replace("/[\n\r\t]*\\{else\\}[\n\r\t]*/is", "\n<?php } else { ?>\n", $template);
    for ($i = 0; $i < 5; $i++) {
        $template = preg_replace("/[\n\r\t]*\\{loop\\s+(\\S+)\\s+(\\S+)\\}[\n\r]*(.+?)[\n\r]*\\{\\/loop\\}[\n\r\t]*/ies", "stripvtags('\n<?php if(is_array(\\1)) { foreach(\\1 as \\2) { ?>','\n\\3\n<?php } } ?>\n')", $template);
        $template = preg_replace("/[\n\r\t]*\\{loop\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\}[\n\r\t]*(.+?)[\n\r\t]*\\{\\/loop\\}[\n\r\t]*/ies", "stripvtags('\n<?php if(is_array(\\1)) { foreach(\\1 as \\2 => \\3) { ?>','\n\\4\n<?php } } ?>\n')", $template);
        $template = preg_replace("/[\n\r\t]*\\{if\\s+(.+?)\\}[\n\r]*(.+?)[\n\r]*\\{\\/if\\}[\n\r\t]*/ies", "stripvtags('\n<?php if(\\1) { ?>','\n\\2\n<?php } ?>\n')", $template);
    }
    $template = preg_replace("/\\{{$const_regexp}\\}/s", "<?=\\1?>", $template);
    $template = preg_replace("/ \\?\\>[\n\r]*\\<\\? /s", " ", $template);
    //write
    $template = trim($template);
    if (!empty($template)) {
        $needwrite = false;
        if (@unlink($objfile)) {
            writefile($objfile . '.tmp', $template, 'text', 'w', 0);
            if (@rename($objfile . '.tmp', $objfile)) {
                $needwrite = false;
            } else {
                $needwrite = true;
            }
        } else {
            $needwrite = true;
        }
        //ÔÙ´ÎдÈë
        if ($needwrite) {
            writefile($objfile, $template, 'text', 'w', 0);
        }
    }
}