Esempio n. 1
0
function gen_blogposts_cache()
{
    global $dbtable_prefix;
    $dirname = dirname(__FILE__);
    $temp = array();
    if ($dirname[0] == '/') {
        // unixes here
        $temp = explode('/', $dirname);
    } else {
        // windows here
        $temp = explode('\\', $dirname);
    }
    $interval = (int) $temp[count($temp) - 1];
    // that's how often we're executed ;)
    $short_blog_chars = 400;
    $config = get_site_option(array('bbcode_blogs', 'use_smilies'), 'core_blog');
    require_once _BASEPATH_ . '/includes/classes/fileop.class.php';
    $fileop = new fileop();
    $post_ids = array();
    $query = "SELECT a.`post_id`,UNIX_TIMESTAMP(a.`date_posted`) as `date_posted`,a.`fk_user_id`,a.`_user` as `user`,a.`fk_blog_id`,a.`title`,a.`post_content`,b.`_photo` as `photo`,c.`blog_name` FROM `{$dbtable_prefix}blog_posts` a,`{$dbtable_prefix}user_profiles` b,`{$dbtable_prefix}user_blogs` c WHERE a.`fk_user_id`=b.`fk_user_id` AND a.`fk_blog_id`=c.`blog_id` AND a.`status`=" . STAT_APPROVED . " AND a.`last_changed`>=DATE_SUB('" . gmdate('YmdHis') . "',INTERVAL " . ($interval + 2) . " MINUTE)";
    if (!($res = @mysql_query($query))) {
        trigger_error(mysql_error(), E_USER_ERROR);
    }
    while ($blog = mysql_fetch_assoc($res)) {
        $post_ids[] = $blog['post_id'];
        $blog['title'] = remove_banned_words(sanitize_and_format($blog['title'], TYPE_STRING, $GLOBALS['__field2format'][TEXT_DB2EDIT]));
        $blog['post_content'] = remove_banned_words($blog['post_content']);
        $post_content_short = substr($blog['post_content'], 0, strrpos(substr($blog['post_content'], 0, $short_blog_chars), ' '));
        $post_content_short = sanitize_and_format($post_content_short, TYPE_STRING, $GLOBALS['__field2format'][TEXT_DB2DISPLAY]);
        $blog['post_content'] = sanitize_and_format($blog['post_content'], TYPE_STRING, $GLOBALS['__field2format'][TEXT_DB2DISPLAY]);
        if (!empty($config['bbcode_blogs'])) {
            $blog['post_content'] = bbcode2html($blog['post_content']);
            $post_content_short = bbcode2html($post_content_short);
        }
        if (!empty($config['use_smilies'])) {
            $blog['post_content'] = text2smilies($blog['post_content']);
            $post_content_short = text2smilies($post_content_short);
        }
        if (empty($blog['photo']) || !is_file(_PHOTOPATH_ . '/t1/' . $blog['photo'])) {
            $blog['photo'] = 'no_photo.gif';
        } else {
            $blog['has_photo'] = true;
        }
        if (empty($blog['fk_user_id'])) {
            unset($blog['fk_user_id']);
        }
        $towrite = '<?php $post=' . var_export($blog, true) . ';';
        $fileop->file_put_contents(_CACHEPATH_ . '/blogs/posts/' . $blog['post_id'][0] . '/' . $blog['post_id'] . '.inc.php', $towrite);
        $blog['post_content'] = $post_content_short;
        $towrite = '<?php $post=' . var_export($blog, true) . ';';
        $fileop->file_put_contents(_CACHEPATH_ . '/blogs/posts/' . $blog['post_id'][0] . '/' . $blog['post_id'] . '_short.inc.php', $towrite);
    }
    return true;
}
Esempio n. 2
0
 function download()
 {
     $this->error = false;
     define('HTTP_EOL', "\r\n");
     if (!empty($this->remote_file)) {
         $this->file_name = '';
         $info = parse_url($this->remote_file);
         $fileop = new fileop();
         $header = 'GET ' . $info['path'];
         if (isset($info['query'])) {
             $header .= '?' . $info['query'];
         }
         $header .= ' HTTP/1.0' . HTTP_EOL;
         $header .= 'Host: ' . $info['host'] . HTTP_EOL;
         $header .= 'Connection: close' . HTTP_EOL . HTTP_EOL;
         $socket = fsockopen($info['host'], 80, $errno, $errstr, 30);
         if ($socket) {
             fputs($socket, $header);
         }
         $reply = '';
         $headerdone = false;
         while (!feof($socket)) {
             $line = fgets($socket);
             if (strcmp($line, HTTP_EOL) == 0) {
                 // read the header
                 $headerdone = true;
             } elseif (!$headerdone) {
                 if (empty($this->file_name)) {
                     if (preg_match('/Content\\-Disposition: attachment; filename="(.+)"/', $line, $m)) {
                         $this->file_name = $m[1];
                     } elseif (preg_match('/Content\\-Type: application\\/octet\\-stream; name="(.+)"/', $line, $m)) {
                         $this->file_name = $m[1];
                     } elseif (preg_match('/Content\\-Type: application\\/octetstream; name="(.+)"/', $line, $m)) {
                         $this->file_name = $m[1];
                     }
                 }
             } elseif ($headerdone) {
                 // header has been read. now read the contents
                 $reply .= $line;
             }
         }
         fclose($socket);
         if (!empty($reply) && !empty($this->file_name)) {
             $fileop->file_put_contents(_BASEPATH_ . '/tmp/' . $this->file_name, $reply);
             if ($this->verify()) {
                 $fileop->rename(_BASEPATH_ . '/tmp/' . $this->file_name, _BASEPATH_ . '/tmp/packages/' . $this->file_name);
             }
         } else {
             $this->error = true;
             $this->error_text = 'Unable to download package.';
         }
     } else {
         $this->error = true;
         $this->error_text = 'Invalid package selected for download.';
     }
     return !$this->error;
 }
Esempio n. 3
0
function on_before_delete_blog_post()
{
    global $dbtable_prefix, $post_ids;
    require_once _BASEPATH_ . '/includes/classes/fileop.class.php';
    $fileop = new fileop();
    $query = "SELECT `post_id`,`fk_blog_id`,`fk_user_id`,UNIX_TIMESTAMP(`date_posted`) as `date_posted` FROM `{$dbtable_prefix}blog_posts` WHERE `post_id` IN ('" . join("','", $post_ids) . "')";
    if (!($res = @mysql_query($query))) {
        trigger_error(mysql_error(), E_USER_ERROR);
    }
    $blog_ids = array();
    $user_ids = array();
    $dates = array();
    while ($rsrow = mysql_fetch_assoc($res)) {
        if (isset($blog_ids[$rsrow['fk_blog_id']])) {
            --$blog_ids[$rsrow['fk_blog_id']];
        } else {
            $blog_ids[$rsrow['fk_blog_id']] = -1;
        }
        if (isset($user_ids[$rsrow['fk_user_id']])) {
            --$user_ids[$rsrow['fk_user_id']];
        } else {
            $user_ids[$rsrow['fk_user_id']] = -1;
        }
        $dates[$rsrow['fk_blog_id']][] = $rsrow['date_posted'];
    }
    foreach ($blog_ids as $bid => $num) {
        // blog stats
        $bid = (string) $bid;
        $query = "UPDATE `{$dbtable_prefix}user_blogs` SET `stat_posts`=`stat_posts`+{$num} WHERE `blog_id`={$bid}";
        if (!($res = @mysql_query($query))) {
            trigger_error(mysql_error(), E_USER_ERROR);
        }
        // blog_archive
        $blog_archive = array();
        if (is_file(_CACHEPATH_ . '/blogs/' . $bid[0] . '/' . $bid . '/blog_archive.inc.php')) {
            include _CACHEPATH_ . '/blogs/' . $bid[0] . '/' . $bid . '/blog_archive.inc.php';
        }
        for ($i = 0; isset($dates[$bid][$i]); ++$i) {
            $year = (int) date('Y', $dates[$bid][$i]);
            $month = (int) date('m', $dates[$bid][$i]);
            if (isset($blog_archive[$year][$month])) {
                --$blog_archive[$year][$month];
            }
            if (empty($blog_archive[$year][$month])) {
                unset($blog_archive[$year][$month]);
            }
        }
        krsort($blog_archive, SORT_NUMERIC);
        $towrite = '<?php $blog_archive=' . var_export($blog_archive, true) . ';';
        $fileop->file_put_contents(_CACHEPATH_ . '/blogs/' . $bid[0] . '/' . $bid . '/blog_archive.inc.php', $towrite);
    }
    foreach ($user_ids as $uid => $num) {
        update_stats($uid, 'blog_posts', $num);
        add_member_score($uid, 'del_blog', -$num);
        // -$num because $num is already negative.
    }
}
Esempio n. 4
0
function upd_latest_comm_widg()
{
    global $dbtable_prefix, $comment_ids, $comment_type;
    if ($comment_type == 'blog') {
        $max_title_length = 40;
        $config = get_site_option(array('items', 'enabled'), 'latest_blog_comments');
        if (!empty($config['enabled'])) {
            $query = "SELECT a.`comment_id`,a.`fk_user_id`,c.`alt_url` as `profile_url`,a.`_user`,b.`post_id`,b.`title`,b.`alt_url` as `post_url` FROM `{$dbtable_prefix}comments_blog` a LEFT JOIN `{$dbtable_prefix}user_profiles` c ON a.`fk_user_id`=c.`fk_user_id`,`{$dbtable_prefix}blog_posts` b WHERE a.`fk_parent_id`=b.`post_id` AND a.`status`=" . STAT_APPROVED . " AND b.`is_public`=1 AND b.`status`=" . STAT_APPROVED . " ORDER BY a.`date_posted` DESC LIMIT " . $config['items'];
            if (!($res = @mysql_query($query))) {
                trigger_error(mysql_error(), E_USER_ERROR);
            }
            $loop = array();
            $i = 0;
            while ($rsrow = mysql_fetch_assoc($res)) {
                if (empty($rsrow['profile_url'])) {
                    if (!empty($rsrow['fk_user_id'])) {
                        $loop[$i]['profile_url'] = _BASEURL_ . '/profile.php?uid=' . $rsrow['fk_user_id'];
                    }
                } else {
                    $loop[$i]['profile_url'] = $rsrow['profile_url'];
                }
                if (empty($rsrow['post_url'])) {
                    $loop[$i]['post_url'] = _BASEURL_ . '/blog_post_view.php?pid=' . $rsrow['post_id'] . '#comm' . $rsrow['comment_id'];
                } else {
                    $loop[$i]['post_url'] = $rsrow['post_url'] . '#comm' . $rsrow['comment_id'];
                }
                $loop[$i]['user'] = $rsrow['_user'];
                if (strlen($rsrow['title']) > $max_title_length) {
                    $rsrow['title'] = substr($rsrow['title'], 0, $max_title_length) . '...';
                }
                $loop[$i]['title'] = sanitize_and_format($rsrow['title'], TYPE_STRING, $GLOBALS['__field2format'][TEXT_DB2DISPLAY]);
                ++$i;
            }
            require_once _BASEPATH_ . '/includes/classes/fileop.class.php';
            $fileop = new fileop();
            $towrite = '<?php $latest_comments=' . var_export($loop, true) . ';';
            $fileop->file_put_contents(_CACHEPATH_ . '/widgets/latest_blog_comments/comments.inc.php', $towrite);
        }
    }
}
Esempio n. 5
0
function on_after_approve_blog_post()
{
    global $dbtable_prefix, $post_ids;
    require_once _BASEPATH_ . '/includes/classes/fileop.class.php';
    $fileop = new fileop();
    $query = "SELECT `post_id`,`fk_blog_id`,`fk_user_id` FROM `{$dbtable_prefix}blog_posts` WHERE `post_id` IN ('" . join("','", $post_ids) . "') AND `processed`=0";
    if (!($res = @mysql_query($query))) {
        trigger_error(mysql_error(), E_USER_ERROR);
    }
    $post_ids = array();
    // yup
    $blog_ids = array();
    $user_ids = array();
    while ($rsrow = mysql_fetch_assoc($res)) {
        $post_ids[] = $rsrow['post_id'];
        // get only the not processed ones
        if (!isset($blog_ids[$rsrow['fk_blog_id']])) {
            $blog_ids[$rsrow['fk_blog_id']] = 1;
        } else {
            ++$blog_ids[$rsrow['fk_blog_id']];
        }
        if (!isset($user_ids[$rsrow['fk_user_id']])) {
            $user_ids[$rsrow['fk_user_id']] = 1;
        } else {
            ++$user_ids[$rsrow['fk_user_id']];
        }
    }
    $year = (int) date('Y');
    $month = (int) date('m');
    foreach ($blog_ids as $bid => $num) {
        // blog stats
        $bid = (string) $bid;
        $query = "UPDATE `{$dbtable_prefix}user_blogs` SET `stat_posts`=`stat_posts`+{$num} WHERE `blog_id`={$bid}";
        if (!($res = @mysql_query($query))) {
            trigger_error(mysql_error(), E_USER_ERROR);
        }
        // blog_archive
        $blog_archive = array();
        if (is_file(_CACHEPATH_ . '/blogs/' . $bid[0] . '/' . $bid . '/blog_archive.inc.php')) {
            include _CACHEPATH_ . '/blogs/' . $bid[0] . '/' . $bid . '/blog_archive.inc.php';
        }
        if (isset($blog_archive[$year][$month])) {
            $blog_archive[$year][$month] += $num;
        } else {
            $blog_archive[$year][$month] = $num;
        }
        krsort($blog_archive, SORT_NUMERIC);
        $towrite = '<?php $blog_archive=' . var_export($blog_archive, true) . ';';
        $fileop->file_put_contents(_CACHEPATH_ . '/blogs/' . $bid[0] . '/' . $bid . '/blog_archive.inc.php', $towrite);
    }
    foreach ($user_ids as $uid => $num) {
        update_stats($uid, 'blog_posts', $num);
        add_member_score($uid, 'add_blog', $num);
    }
    if (!empty($post_ids)) {
        $query = "UPDATE `{$dbtable_prefix}blog_posts` SET `processed`=1 WHERE `post_id` IN ('" . join("','", $post_ids) . "')";
        if (!($res = @mysql_query($query))) {
            trigger_error(mysql_error(), E_USER_ERROR);
        }
    }
}
Esempio n. 6
0
function gen_comment_feeds()
{
    global $dbtable_prefix;
    require_once _BASEPATH_ . '/includes/access_levels.inc.php';
    $short_blog_chars = 400;
    if (allow_at_level('read_blogs')) {
        // if non-members are allowed to read blogs...
        require_once _BASEPATH_ . '/includes/classes/rss_writer.class.php';
        $rss_writer_object = new rss_writer_class();
        $rss_writer_object->specification = '1.0';
        $rss_writer_object->about = _BASEURL_ . '/rss/latest-comments.xml';
        //		$rss_writer_object->rssnamespaces['dc']='http://purl.org/dc/elements/1.1/';
        $properties = array();
        $properties['description'] = 'Latest blog comments on ' . _SITENAME_;
        $properties['link'] = _BASEURL_;
        $properties['title'] = 'Latest Blog Comments';
        //		$properties['dc:date']=mktime(gmdate('H'),gmdate('i'),gmdate('s'),gmdate('m'),gmdate('d'),gmdate('Y'));
        $rss_writer_object->addchannel($properties);
        $query = "SELECT a.`comment_id`,a.`fk_user_id`,c.`alt_url` as `profile_url`,a.`_user`,a.`comment`,b.`post_id`,b.`title`,b.`alt_url` as `post_url` FROM `{$dbtable_prefix}comments_blog` a LEFT JOIN `{$dbtable_prefix}user_profiles` c ON a.`fk_user_id`=c.`fk_user_id`,`{$dbtable_prefix}blog_posts` b WHERE a.`fk_parent_id`=b.`post_id` AND a.`status`=" . STAT_APPROVED . " AND b.`is_public`=1 AND b.`status`=" . STAT_APPROVED . " ORDER BY a.`date_posted` DESC LIMIT 10";
        if (!($res = @mysql_query($query))) {
            trigger_error(mysql_error(), E_USER_ERROR);
        }
        while ($rsrow = mysql_fetch_assoc($res)) {
            $properties = array();
            if (strlen($rsrow['comment']) < $short_blog_chars) {
                $properties['description'] = $rsrow['comment'];
            } else {
                $properties['description'] = substr($rsrow['comment'], 0, strrpos(substr($rsrow['comment'], 0, $short_blog_chars), ' '));
            }
            $properties['description'] = sanitize_and_format($properties['description'], TYPE_STRING, $GLOBALS['__field2format'][TEXT_DB2DISPLAY]);
            if (empty($rsrow['post_url'])) {
                $properties['link'] = _BASEURL_ . '/blog_post_view.php?pid=' . $rsrow['post_id'] . '#comm' . $rsrow['comment_id'];
            } else {
                $properties['link'] = $rsrow['post_url'] . '#comm' . $rsrow['comment_id'];
            }
            $rsrow['title'] = sanitize_and_format($rsrow['title'], TYPE_STRING, $GLOBALS['__field2format'][TEXT_DB2DISPLAY]);
            $properties['title'] = sprintf('%1$s on "%2$s"', $rsrow['_user'], $rsrow['title']);
            //			$properties['dc:date']=$rsrow['date_posted'];
            $rss_writer_object->additem($properties);
        }
        if ($rss_writer_object->writerss($towrite)) {
            require_once _BASEPATH_ . '/includes/classes/fileop.class.php';
            $fileop = new fileop();
            $fileop->file_put_contents(_BASEPATH_ . '/rss/latest-comments.xml', $towrite);
        } else {
            $error = true;
            $topass['message']['type'] = MESSAGE_ERROR;
            $topass['message']['text'] = $rss_writer_object->error;
        }
    }
    return true;
}
Esempio n. 7
0
        $query = "SELECT `news_title`,`news_body`,UNIX_TIMESTAMP(`date_posted`) as `date_posted` FROM `{$dbtable_prefix}site_news` ORDER BY `news_id` DESC";
        if (!($res = @mysql_query($query))) {
            trigger_error(mysql_error(), E_USER_ERROR);
        }
        while ($rsrow = mysql_fetch_assoc($res)) {
            $properties = array();
            $properties['description'] = $rsrow['news_body'];
            $properties['link'] = '';
            $properties['title'] = $rsrow['news_title'];
            $properties['dc:date'] = $rsrow['date_posted'];
            $rss_writer_object->additem($properties);
        }
        if ($rss_writer_object->writerss($towrite)) {
            require_once _BASEPATH_ . '/includes/classes/fileop.class.php';
            $fileop = new fileop();
            $fileop->file_put_contents(_BASEPATH_ . '/rss/site_news.xml', $towrite);
        } else {
            $error = true;
            $topass['message']['type'] = MESSAGE_ERROR;
            $topass['message']['text'] = $rss_writer_object->error;
        }
    } else {
        $nextpage = 'admin/site_news_addedit.php';
        // 		you must re-read all textareas from $_POST like this:
        //		$input['x']=addslashes_mq($_POST['x']);
        $input['news_body'] = addslashes_mq($_POST['news_body']);
        $input = sanitize_and_format($input, TYPE_STRING, FORMAT_HTML2TEXT_FULL | FORMAT_STRIPSLASH);
        $topass['input'] = $input;
    }
}
$nextpage = _BASEURL_ . '/' . $nextpage;
Esempio n. 8
0
             for ($i = 0; isset($_on_before_insert[$i]); ++$i) {
                 call_user_func($_on_before_insert[$i]);
             }
         }
         if (!($res = @mysql_query($query))) {
             trigger_error(mysql_error(), E_USER_ERROR);
         }
         $input['blog_id'] = mysql_insert_id();
         $towrite['blog_id'] = $input['blog_id'];
         $input['blog_id'] = (string) $input['blog_id'];
         // create the blog cache folder if it doesn't exist
         if (!is_dir(_CACHEPATH_ . '/blogs/' . $input['blog_id'][0] . '/' . $input['blog_id'])) {
             $fileop->mkdir(_CACHEPATH_ . '/blogs/' . $input['blog_id'][0] . '/' . $input['blog_id']);
         }
         $temp = '<?php $blog_archive=array();';
         $fileop->file_put_contents(_CACHEPATH_ . '/blogs/' . $input['blog_id'][0] . '/' . $input['blog_id'] . '/blog_archive.inc.php', $temp);
         $topass['message']['type'] = MESSAGE_INFO;
         $topass['message']['text'] = $GLOBALS['_lang'][15];
         if (isset($_on_after_insert)) {
             for ($i = 0; isset($_on_after_insert[$i]); ++$i) {
                 call_user_func($_on_after_insert[$i]);
             }
         }
     }
     $towrite['fk_user_id'] = $input['fk_user_id'];
     unset($towrite['return']);
     $towrite = '<?php $blog=' . var_export($towrite, true) . ';';
     $fileop->file_put_contents(_CACHEPATH_ . '/blogs/' . $input['blog_id'][0] . '/' . $input['blog_id'] . '/blog.inc.php', $towrite);
 } else {
     $nextpage = 'blog_addedit.php';
     // 		you must re-read all textareas from $_POST like this:
Esempio n. 9
0
    }
    if (!$error) {
        $input['fileop_mode'] = $_SESSION['install']['write'];
        $input['license_key'] = strtoupper(gen_pass(22));
        $input['license_key_md5'] = md5($input['license_key']);
        $tpl = new phemplate('../skin/', 'remove_nonjs');
        $tpl->set_file('content', 'defines.inc.php');
        $tpl->set_var('input', $input);
        $towrite = $tpl->process('content', 'content', TPL_FINISH);
        define('_BASEPATH_', $input['basepath']);
        define('_FILEOP_MODE_', $input['fileop_mode']);
        define('_FTPHOST_', $input['ftphost']);
        define('_FTPPATH_', $input['ftppath']);
        define('_FTPUSER_', $input['ftpuser']);
        define('_FTPPASS_', $input['ftppass']);
        require_once '../../includes/classes/fileop.class.php';
        $fileop = new fileop();
        $fileop->delete($input['basepath'] . '/includes/defines.inc.php');
        $fileop->file_put_contents($input['basepath'] . '/includes/defines.inc.php', $towrite);
        $_SESSION['install']['input'] = $input;
    } else {
        $nextpage = 'install/step2.php';
        // 		you must re-read all textareas from $_POST like this:
        //		$input['x']=addslashes_mq($_POST['x']);
        $input = sanitize_and_format($input, TYPE_STRING, FORMAT_HTML2TEXT_FULL | FORMAT_STRIPSLASH);
        $topass['input'] = $input;
    }
}
$my_url = str_replace('/install/processors/write_defines.php', '', $_SERVER['PHP_SELF']);
define('_BASEURL_', (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $my_url);
redirect2page($nextpage, $topass, $qs);
Esempio n. 10
0
 function _do_diff($diff_file, $force_revision = false, $test_only = false)
 {
     $files_to_change = array();
     // keeps the files that are/will be changed in the diff
     $fileop = new fileop();
     if (!function_exists('striprn')) {
         function striprn(&$v, $k)
         {
             $v = rtrim($v, "\r\n");
         }
     }
     $diff_array = file($diff_file);
     array_walk($diff_array, 'striprn');
     $cur_file = '';
     $cur_ext = '';
     $file_content = array();
     $src_size = -1;
     $src_start = 0;
     $dst_size = -1;
     $dest_start = 0;
     $new_revision = 0;
     $this->error = false;
     $first_chunk = true;
     $last_line_rn = false;
     for ($i = 0; isset($diff_array[$i]); ++$i) {
         if (substr($diff_array[$i], 0, 7) == 'Index: ') {
             // a new file
             if (!$first_chunk && !$test_only) {
                 if (empty($file_content)) {
                     $fileop->delete($cur_file);
                 } else {
                     if ($cur_ext == 'html') {
                         $LE = "\r\n";
                     } else {
                         $LE = "\n";
                     }
                     $file_content = join($LE, $file_content);
                     if ($last_line_rn) {
                         $file_content .= $LE;
                     }
                     if ($force_revision) {
                         $file_content = preg_replace('/' . chr(38) . 'Revision: \\d+ ' . chr(38) . '/', chr(38) . 'Revision: ' . $new_revision . ' ' . chr(38), $file_content);
                     }
                     $fileop->file_put_contents($cur_file, $file_content);
                 }
             }
             $cur_file = _BASEPATH_ . '/' . trim(substr($diff_array[$i], 7));
             $cur_ext = strtolower(substr(strrchr($cur_file, '.'), 1));
             if (is_file($cur_file)) {
                 $file_content = file($cur_file);
                 $temp = substr($file_content[count($file_content) - 1], -1);
                 if ($temp == "\n" || $temp == "\r") {
                     $last_line_rn = true;
                 } else {
                     $last_line_rn = false;
                 }
                 array_walk($file_content, 'striprn');
             } else {
                 $file_content = array();
             }
             $files_to_change[] = $cur_file;
             $last_change_on_line = -1;
         } elseif (substr($diff_array[$i], 0, 3) == '===') {
         } elseif (substr($diff_array[$i], 0, 3) == '---') {
         } elseif (substr($diff_array[$i], 0, 3) == '+++') {
             if (preg_match('/\\(revision (\\d+)\\)/', $diff_array[$i], $m)) {
                 $new_revision = $m[1];
             }
         } elseif (substr($diff_array[$i], 0, 2) == '@@') {
             $m = array();
             if (preg_match('/@@ -(\\d+)(,(\\d+))?\\s+\\+(\\d+)(,(\\d+))?\\s+@@/', $diff_array[$i], $m)) {
                 $src_start = (int) $m[1] - 1;
                 // -1 because our arrays are 0 based
                 $dest_start = (int) $m[4] - 1;
                 // -1 because our arrays are 0 based
                 if ($m[3] === '') {
                     $src_size = 1;
                 } else {
                     $src_size = (int) $m[3];
                 }
                 if ($m[6] === '') {
                     $dst_size = 1;
                 } else {
                     $dst_size = (int) $m[6];
                 }
             } else {
                 $this->error = true;
                 $this->error_text = sprintf('Invalid diff file: %s. Line %s in diff file', $diff_file, $i);
                 break;
             }
         } elseif ($diff_array[$i][0] == ' ' || $diff_array[$i][0] == '-' || $diff_array[$i][0] == '+' || $diff_array[$i][0] == '\\') {
             $source = array();
             $dest = array();
             while ($src_size > 0 || $dst_size > 0) {
                 if (isset($diff_array[$i])) {
                     // make sure we haven't reached the end of the diff array
                     $type = $diff_array[$i][0];
                     $diff_line = substr($diff_array[$i], 1);
                 } else {
                     $this->error = true;
                     $this->error_text = sprintf('Invalid diff file: %s. Unexpected end of file', $diff_file);
                     break 2;
                 }
                 if ($type == ' ') {
                     $source[] = $diff_line;
                     $dest[] = $diff_line;
                     --$src_size;
                     --$dst_size;
                 } elseif ($type == '-') {
                     $source[] = $diff_line;
                     --$src_size;
                 } elseif ($type == '+') {
                     $dest[] = $diff_line;
                     --$dst_size;
                 } else {
                     $this->error = true;
                     $this->error_text = sprintf('Invalid diff file: %s. Line %s in diff file. Unknown diff marker.', $diff_file, $i);
                     break 2;
                 }
                 ++$i;
             }
             --$i;
             // the outer for() would increment it again and we don't want this.
             if (!empty($src_size) || !empty($dst_size) || empty($source) && empty($dest)) {
                 $this->error = true;
                 $this->error_text = sprintf('Invalid diff file: %s. Unexpected end of block at line %s', $diff_file, $i);
                 break;
             }
             if (!empty($source)) {
                 // where could our block be? We don't want to rely on the $dest_start read from the diff file
                 $possible_locations = array_keys($file_content, $source[0]);
                 for ($k = 0, $plcount = count($possible_locations); $k < $plcount; ++$k) {
                     for ($j = 1, $scount = count($source); $j < $scount; ++$j) {
                         if (isset($source[$j]) && isset($possible_locations[$k])) {
                             if ($possible_locations[$k] < $last_change_on_line || !isset($file_content[$possible_locations[$k] + $j]) || $source[$j] != $file_content[$possible_locations[$k] + $j]) {
                                 unset($possible_locations[$k]);
                             }
                         }
                     }
                 }
                 if (empty($possible_locations)) {
                     $this->error = true;
                     $this->error_text = sprintf('Cannot apply patch because the source file (%s) is changed. Line %s in diff file.', $cur_file, $i);
                     break;
                 } elseif (count($possible_locations) > 1) {
                     if (!in_array($dest_start, $possible_locations)) {
                         $this->error = true;
                         $this->error_text = sprintf('Cannot apply patch because the source file (%s) is changed. More possible locations in diff file at line %s.', $cur_file, $i);
                         break;
                     }
                 } elseif (count($possible_locations) == 1) {
                     reset($possible_locations);
                     $dest_start = current($possible_locations);
                 }
             }
             // if we are here then there was no error and we can apply the diff!!!
             array_splice($file_content, $dest_start, count($source), $dest);
             $last_change_on_line = $dest_start + count($dest);
             $first_chunk = false;
         }
     }
     if (!$this->error && !$first_chunk && !$test_only) {
         if (empty($file_content)) {
             $fileop->delete($cur_file);
         } else {
             if ($cur_ext == 'html') {
                 $LE = "\r\n";
             } else {
                 $LE = "\n";
             }
             $file_content = join($LE, $file_content);
             if ($last_line_rn) {
                 $file_content .= $LE;
             }
             if ($force_revision) {
                 $file_content = preg_replace('/' . chr(38) . 'Revision: \\d+ ' . chr(38) . '/', chr(38) . 'Revision: ' . $new_revision . ' ' . chr(38), $file_content);
             }
             $fileop->file_put_contents($cur_file, $file_content);
         }
     }
     if (!$this->error) {
         return $files_to_change;
     } else {
         return false;
     }
 }
Esempio n. 11
0
function regenerate_langstrings_array($skin_module_code = '')
{
    require_once _BASEPATH_ . '/includes/classes/fileop.class.php';
    global $dbtable_prefix;
    $fileop = new fileop();
    if (empty($skin_module_code)) {
        $query = "SELECT a.`module_code`,b.`config_value` as `skin_dir` FROM `{$dbtable_prefix}modules` a,`{$dbtable_prefix}site_options3` b WHERE a.`module_type`=" . MODULE_SKIN . " AND a.`module_code`=b.`fk_module_code` AND b.`config_option`='skin_dir'";
    } else {
        $query = "SELECT `fk_module_code` as `module_code`,`config_value` as `skin_dir` FROM `{$dbtable_prefix}site_options3` WHERE `config_option`='skin_dir' AND `fk_module_code`='{$skin_module_code}'";
    }
    if (!($res = @mysql_query($query))) {
        trigger_error(mysql_error(), E_USER_ERROR);
    }
    $skins = array();
    while ($rsrow = mysql_fetch_assoc($res)) {
        $skins[] = $rsrow;
    }
    for ($i = 0; isset($skins[$i]); ++$i) {
        $towrite = array();
        $towrite[''][] = '<?php';
        $query = "SELECT b.`codes` FROM `{$dbtable_prefix}site_options3` a,`{$dbtable_prefix}locales` b WHERE a.`config_option`='fk_locale_id' AND a.`config_value`=b.`locale_id` AND a.`fk_module_code`='" . $skins[$i]['module_code'] . "'";
        if (!($res = @mysql_query($query))) {
            trigger_error(mysql_error(), E_USER_ERROR);
        }
        if (mysql_num_rows($res)) {
            $temp = mysql_result($res, 0, 0);
            $towrite[''][] = "setlocale(LC_TIME,array('" . str_replace(',', "','", $temp) . "'));";
        }
        $query = "SELECT a.`lk_id`,a.`alt_id_text`,b.`lang_value`,a.`lk_use`,a.`save_file` FROM `{$dbtable_prefix}lang_keys` a LEFT JOIN `{$dbtable_prefix}lang_strings` b ON (a.`lk_id`=b.`fk_lk_id` AND b.`skin`='" . $skins[$i]['module_code'] . "')";
        if (!($res = @mysql_query($query))) {
            trigger_error(mysql_error(), E_USER_ERROR);
        }
        while ($rsrow = mysql_fetch_assoc($res)) {
            if ($rsrow['lk_use'] != LK_FIELD) {
                $rsrow['lang_value'] = addcslashes($rsrow['lang_value'], "'\\");
            } else {
                // field related strings cannot contain html code
                $rsrow['lang_value'] = sanitize_and_format($rsrow['lang_value'], TYPE_STRING, $GLOBALS['__field2format'][TEXT_DB2EDIT]);
            }
            if (!empty($rsrow['alt_id_text'])) {
                $rsrow['lk_id'] = "'" . $rsrow['alt_id_text'] . "'";
            }
            if (!isset($towrite[$rsrow['save_file']])) {
                $towrite[$rsrow['save_file']][] = '<?php';
            }
            $towrite[$rsrow['save_file']][] = "\$GLOBALS['_lang'][" . $rsrow['lk_id'] . "]='" . $rsrow['lang_value'] . "';";
        }
        foreach ($towrite as $file => $arr) {
            if (empty($file)) {
                $file = 'global.inc.php';
            }
            $temp = join("\n", $arr);
            $fileop->file_put_contents(_BASEPATH_ . '/skins_site/' . $skins[$i]['skin_dir'] . '/lang/' . $file, $temp);
        }
    }
}
Esempio n. 12
0
        } else {
            // read the manifest from the zip file
            $zipfile->read_zip(_BASEPATH_ . '/tmp/packages/' . $entry);
            $found = false;
            $manifest_content = '';
            foreach ($zipfile->files as $zfile) {
                if ($zfile['name'] == 'manifest.xml' && $zfile['dir'] == '/') {
                    $found = true;
                    $filenames[$i] = $entry;
                    $manifest_content = $zfile['data'];
                    break;
                }
            }
            if ($found) {
                // now save it as a separate file to speed things up next time
                $fileop->file_put_contents(_BASEPATH_ . '/tmp/packages/' . $filename . '.info', $manifest_content);
                $packages[$i++] = _BASEPATH_ . '/tmp/packages/' . $filename . '.info';
            }
        }
    }
}
$not_installed = array();
$m = 0;
for ($i = 0; isset($packages[$i]); ++$i) {
    $p = new etano_package($packages[$i]);
    if (!isset($mcodes[$p->module_code]) || $mcodes[$p->module_code] < $p->version) {
        // not installed packages
        $install_req_satisfied = 0;
        $reasons = array();
        // holds the reasons why this is not satisfied (if it isn't)
        $relevant_install = true;
Esempio n. 13
0
     $post_content_short = bbcode2html($post_content_short);
 }
 if (!empty($config['use_smilies'])) {
     $blog['post_content'] = text2smilies($blog['post_content']);
     $post_content_short = text2smilies($post_content_short);
 }
 if (empty($blog['photo']) || !is_file(_PHOTOPATH_ . '/t1/' . $blog['photo'])) {
     $blog['photo'] = 'no_photo.gif';
 } else {
     $blog['has_photo'] = true;
 }
 if (empty($blog['fk_user_id'])) {
     unset($blog['fk_user_id']);
 }
 $towrite = '<?php $post=' . var_export($blog, true) . ';';
 $fileop->file_put_contents(_CACHEPATH_ . '/blogs/posts/' . $blog['post_id'][0] . '/' . $blog['post_id'] . '.inc.php', $towrite);
 $blog['post_content'] = $post_content_short;
 $towrite = '<?php $post=' . var_export($blog, true) . ';';
 $fileop->file_put_contents(_CACHEPATH_ . '/blogs/posts/' . $blog['post_id'][0] . '/' . $blog['post_id'] . '_short.inc.php', $towrite);
 if (!isset($blog_details[$blog['fk_blog_id']])) {
     $query = "SELECT `blog_id`,`blog_name`,`blog_diz`,`blog_skin`,`fk_user_id`,`alt_url` FROM `{$dbtable_prefix}user_blogs` WHERE `blog_id`=" . $blog['fk_blog_id'];
     if (!($res2 = @mysql_query($query))) {
         trigger_error(mysql_error(), E_USER_ERROR);
     }
     if (mysql_num_rows($res2)) {
         $blog_details = mysql_fetch_assoc($res2);
         $blog_details['blog_name'] = sanitize_and_format($blog_details['blog_name'], TYPE_STRING, $__field2format[TEXT_DB2DISPLAY]);
         $blog_details['blog_diz'] = sanitize_and_format($blog_details['blog_diz'], TYPE_STRING, $__field2format[TEXT_DB2DISPLAY]);
     }
 }
 if (!is_dir(_CACHEPATH_ . '/blogs/' . $blog_details['blog_id'][0] . '/' . $blog_details['blog_id'])) {
Esempio n. 14
0
function regenerate_ban_array()
{
    require_once _BASEPATH_ . '/includes/classes/fileop.class.php';
    global $dbtable_prefix;
    $query = "SELECT `ban_type`,`what` FROM `{$dbtable_prefix}site_bans` GROUP BY `what`";
    if (!($res = @mysql_query($query))) {
        trigger_error(mysql_error(), E_USER_ERROR);
    }
    $_bans = array();
    while ($rsrow = mysql_fetch_row($res)) {
        $_bans[$rsrow[0]][] = $rsrow[1];
    }
    $towrite = "<?php\n";
    if (!empty($_bans[_PUNISH_BANIP_])) {
        $towrite .= '$_bans[_PUNISH_BANIP_]=array(\'' . join("','", $_bans[_PUNISH_BANIP_]) . "');\n";
    }
    if (!empty($_bans[_PUNISH_BANUSER_])) {
        $towrite .= '$_bans[_PUNISH_BANUSER_]=array(\'' . join("','", $_bans[_PUNISH_BANUSER_]) . "');\n";
    }
    if (!empty($_bans[_PUNISH_BANEMAIL_])) {
        $towrite .= '$_bans[_PUNISH_BANEMAIL_]=array(\'' . join("','", $_bans[_PUNISH_BANEMAIL_]) . "');\n";
    }
    $fileop = new fileop();
    $fileop->file_put_contents(_BASEPATH_ . '/includes/site_bans.inc.php', $towrite);
}
Esempio n. 15
0
******************************************************************************/
require_once '../../includes/common.inc.php';
require_once '../../includes/admin_functions.inc.php';
allow_dept(DEPT_ADMIN);
$error = false;
$qs = '';
$qs_sep = '';
$topass = array();
$word_id = isset($_GET['word_id']) ? (int) $_GET['word_id'] : 0;
$query = "DELETE FROM `{$dbtable_prefix}banned_words` WHERE `word_id`={$word_id}";
if (!($res = @mysql_query($query))) {
    trigger_error(mysql_error(), E_USER_ERROR);
}
if (!$error) {
    // save in file
    require_once _BASEPATH_ . '/includes/classes/fileop.class.php';
    $query = "SELECT `word` FROM `{$dbtable_prefix}banned_words`";
    if (!($res = @mysql_query($query))) {
        trigger_error(mysql_error(), E_USER_ERROR);
    }
    $towrite = array();
    for ($i = 0; $i < mysql_num_rows($res); ++$i) {
        $towrite[] = mysql_result($res, $i, 0);
    }
    $towrite = '<?php $_banned_words=' . var_export($towrite, true) . ';';
    $fileop = new fileop();
    $fileop->file_put_contents(_BASEPATH_ . '/includes/banned_words.inc.php', $towrite);
}
$topass['message']['type'] = MESSAGE_INFO;
$topass['message']['text'] = 'Word deleted.';
redirect2page('admin/banned_words.php', $topass, $qs);
Esempio n. 16
0
            if (isset($_POST['levels'][$levels[$l]][$memberships[$m]])) {
                $new_levels[$levels[$l]] += $memberships[$m];
            }
        }
    }
    // save in db
    foreach ($new_levels as $k => $v) {
        $query = "UPDATE `{$dbtable_prefix}access_levels` SET `level`='{$v}' WHERE `level_id`={$k}";
        if (!($res = @mysql_query($query))) {
            trigger_error(mysql_error(), E_USER_ERROR);
        }
    }
    // save in file
    require_once _BASEPATH_ . '/includes/classes/fileop.class.php';
    require_once _BASEPATH_ . '/includes/access_levels.inc.php';
    $query = "SELECT `level_code`,`level` FROM `{$dbtable_prefix}access_levels`";
    if (!($res = @mysql_query($query))) {
        trigger_error(mysql_error(), E_USER_ERROR);
    }
    $towrite = "<?php\n\$GLOBALS['_access_level']=array('auth'=>65534,'all'=>65535";
    while ($rsrow = mysql_fetch_row($res)) {
        $towrite .= ",'" . $rsrow[0] . "'=>" . $rsrow[1];
    }
    $towrite .= ");\n";
    $towrite .= '$GLOBALS[\'_allow_na\']=' . var_export($GLOBALS['_allow_na'], true) . ";\n";
    $fileop = new fileop();
    $fileop->file_put_contents(_BASEPATH_ . '/includes/access_levels.inc.php', $towrite);
    $topass['message']['type'] = MESSAGE_INFO;
    $topass['message']['text'] = 'Access levels changed.';
}
redirect2page('admin/access_levels.php', $topass, $qs);
Esempio n. 17
0
$qs_sep = '';
$topass = array();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $input = array();
    $input['file'] = str_replace('..', '', preg_replace('~[^a-zA-Z0-9\\._/-]~', '', sanitize_and_format_gpc($_POST, 'file', TYPE_STRING, $__field2format[FIELD_TEXTFIELD], '')));
    $input['file_content'] = preg_replace('/\\r/m', '', sanitize_and_format_gpc($_POST, 'file_content', TYPE_STRING, FORMAT_STRIP_MQ));
    if (strtolower(substr(strrchr($input['file'], '.'), 1)) == 'html') {
        $input['file_content'] = preg_replace('/\\n/m', "\r\n", $input['file_content']);
    }
    if (!empty($input['file']) && $input['file'][0] == '/') {
        $input['file'] = substr($input['file'], 1);
    }
    if (empty($input['file'])) {
        $error = true;
        $topass['message']['type'] = MESSAGE_ERROR;
        $topass['message']['text'] = 'No file selected';
    }
    if (!$error) {
        require_once '../../includes/classes/fileop.class.php';
        $fileop = new fileop();
        $fileop->file_put_contents(_BASEPATH_ . '/' . $input['file'], $input['file_content']);
        $topass['message']['type'] = MESSAGE_INFO;
        $topass['message']['text'] = 'File saved successfully';
        $temp = str_replace(strrchr($input['file'], '/'), '', $input['file']);
        if ($temp != $input['file']) {
            $qs .= $qs_sep . 'path=' . urlencode($temp);
            $qs_sep = '&';
        }
    }
}
redirect2page('admin/file_browser.php', $topass, $qs);