Exemple #1
0
function migrate_old_content()
{
    $content = array();
    $tmp = array();
    $files = array();
    $draft = array();
    $dtmp = array();
    $dfiles = array();
    $tmp = glob('content/*/blog/*.md', GLOB_NOSORT);
    if (is_array($tmp)) {
        foreach ($tmp as $file) {
            $content[] = $file;
        }
    }
    if (!empty($content)) {
        foreach ($content as $c => $v) {
            $arr = explode('/', $v);
            $string = file_get_contents($v);
            $image = get_content_tag('image', $string);
            $video = get_youtube_id(get_content_tag('video', $string));
            $audio = get_content_tag('audio', $string);
            $link = get_content_tag('link', $string);
            $quote = get_content_tag('quote', $string);
            if (!empty($image)) {
                $files[] = array($v, 'content/' . $arr[1] . '/blog/uncategorized/image/' . $arr[3]);
                $dir = 'content/' . $arr[1] . '/blog/uncategorized/image/';
                if (!is_dir($dir)) {
                    mkdir($dir, 0775, true);
                }
            }
            if (!empty($video)) {
                $files[] = array($v, 'content/' . $arr[1] . '/blog/uncategorized/video/' . $arr[3]);
                $dir = 'content/' . $arr[1] . '/blog/uncategorized/video/';
                if (!is_dir($dir)) {
                    mkdir($dir, 0775, true);
                }
            }
            if (!empty($audio)) {
                $files[] = array($v, 'content/' . $arr[1] . '/blog/uncategorized/audio/' . $arr[3]);
                $dir = 'content/' . $arr[1] . '/blog/uncategorized/audio/';
                if (!is_dir($dir)) {
                    mkdir($dir, 0775, true);
                }
            }
            if (!empty($link)) {
                $files[] = array($v, 'content/' . $arr[1] . '/blog/uncategorized/link/' . $arr[3]);
                $dir = 'content/' . $arr[1] . '/blog/uncategorized/link/';
                if (!is_dir($dir)) {
                    mkdir($dir, 0775, true);
                }
            }
            if (!empty($quote)) {
                $files[] = array($v, 'content/' . $arr[1] . '/blog/uncategorized/quote/' . $arr[3]);
                $dir = 'content/' . $arr[1] . '/blog/uncategorized/quote/';
                if (!is_dir($dir)) {
                    mkdir($dir, 0775, true);
                }
            }
            if (empty($image) && empty($video) && empty($audio) && empty($link) && empty($quote)) {
                $files[] = array($v, 'content/' . $arr[1] . '/blog/uncategorized/post/' . $arr[3]);
                $dir = 'content/' . $arr[1] . '/blog/uncategorized/post/';
                if (!is_dir($dir)) {
                    mkdir($dir, 0775, true);
                }
            }
        }
        foreach ($files as $f) {
            rename($f[0], $f[1]);
        }
    }
    $dir = 'content/data/';
    if (!is_dir($dir)) {
        mkdir($dir, 0775, true);
    }
    if (file_exists('content/tags.lang')) {
        rename('content/tags.lang', 'content/data/tags.lang');
        unlink('content/views.json');
    }
    $dtmp = glob('content/*/draft/*.md', GLOB_NOSORT);
    $old = array();
    if (is_array($dtmp)) {
        foreach ($dtmp as $dfile) {
            $draft[] = $dfile;
        }
    }
    if (!empty($draft)) {
        foreach ($draft as $d => $val) {
            $arr = explode('/', $val);
            $old[] = 'content/' . $arr[1] . '/draft/';
            $dir = 'content/' . $arr[1] . '/blog/uncategorized/draft/';
            $new = 'content/' . $arr[1] . '/blog/uncategorized/draft/' . $arr[3];
            if (!is_dir($dir)) {
                mkdir($dir, 0775, true);
            }
            $dfiles[] = array($val, $new);
        }
        foreach ($dfiles as $fd) {
            rename($fd[0], $fd[1]);
        }
        $tt = array();
        $tt = array_unique($old, SORT_REGULAR);
        foreach ($tt as $t) {
            rmdir($t);
        }
    }
    rebuilt_cache('all');
}
Exemple #2
0
function delete_page($file, $destination)
{
    if (!login()) {
        return null;
    }
    $deleted_content = $file;
    if (!empty($menu)) {
        foreach (glob('cache/page/*.cache', GLOB_NOSORT) as $file) {
            unlink($file);
        }
    } else {
        $replaced = substr($file, 0, strrpos($file, '/')) . '/';
        $url = str_replace($replaced, '', $file);
        clear_page_cache($url);
    }
    if (!empty($deleted_content)) {
        unlink($deleted_content);
        rebuilt_cache('all');
        if ($destination == 'post') {
            $redirect = site_url();
            header("Location: {$redirect}");
        } else {
            $redirect = site_url() . $destination;
            header("Location: {$redirect}");
        }
    }
}
Exemple #3
0
function edit_profile($title, $content, $user)
{
    $user_title = safe_html($title);
    $user_content = '<!--t ' . $user_title . ' t-->' . "\n\n" . $content;
    if (!empty($user_title) && !empty($user_content)) {
        if (get_magic_quotes_gpc()) {
            $user_content = stripslashes($user_content);
        }
        $dir = 'content/' . $user . '/';
        $filename = 'content/' . $user . '/author.md';
        if (is_dir($dir)) {
            file_put_contents($filename, print_r($user_content, true));
        } else {
            mkdir($dir, 0775, true);
            file_put_contents($filename, print_r($user_content, true));
        }
        rebuilt_cache('all');
        $redirect = site_url() . 'author/' . $user;
        header("Location: {$redirect}");
    }
}
<?php

$files = array();
$draft = array();
$files = glob('content/*/blog/*.md', GLOB_NOSORT);
$draft = glob('content/*/draft/*.md', GLOB_NOSORT);
if (!empty($files) || !empty($draft)) {
    migrate_old_content();
}
rebuilt_cache('all');
foreach (glob('cache/page/*.cache', GLOB_NOSORT) as $file) {
    unlink($file);
}
echo 'All cache has been deleted!';
Exemple #5
0
function rebuilt_cache($type)
{
    $dir = 'cache/index';
    $posts_cache_sorted = array();
    $posts_cache_unsorted = array();
    $page_cache = array();
    $author_cache = array();
    if (is_dir($dir) === false) {
        mkdir($dir, 0775, true);
    }
    if ($type === 'posts') {
        $posts_cache_unsorted = glob('content/*/blog/*.md', GLOB_NOSORT);
        $string = serialize($posts_cache_unsorted);
        file_put_contents('cache/index/index-unsorted.txt', print_r($string, true));
        $tmp = array();
        $tmp = glob('content/*/blog/*.md', GLOB_NOSORT);
        if (is_array($tmp)) {
            foreach ($tmp as $file) {
                $posts_cache_sorted[] = pathinfo($file);
            }
        }
        usort($posts_cache_sorted, "sortfile");
        $string = serialize($posts_cache_sorted);
        file_put_contents('cache/index/index-sorted.txt', print_r($string, true));
    } elseif ($type === 'page') {
        $page_cache = glob('content/static/*.md', GLOB_NOSORT);
        $string = serialize($page_cache);
        file_put_contents('cache/index/index-page.txt', print_r($string, true));
    } elseif ($type === 'subpage') {
        $page_cache = glob('content/static/*/*.md', GLOB_NOSORT);
        $string = serialize($page_cache);
        file_put_contents('cache/index/index-sub-page.txt', print_r($string, true));
    } elseif ($type === 'author') {
        $author_cache = glob('content/*/author.md', GLOB_NOSORT);
        $string = serialize($author_cache);
        file_put_contents('cache/index/index-author.txt', print_r($string, true));
    } elseif ($type === 'all') {
        rebuilt_cache('posts');
        rebuilt_cache('page');
        rebuilt_cache('subpage');
        rebuilt_cache('author');
    }
}