Example #1
0
                }
                unset($page);
            }
        }
    }
    //Move the file.
    rename(PAGE_DIR . '/' . get_page_filename($var1), 'data/trash/pages/' . $newfile . '.php');
    //Then move the sub-pages, if any.
    if (isset($sub_pages)) {
        foreach ($sub_pages as $sub_page) {
            rename(PAGE_DIR . '/' . $sub_page, 'data/trash/pages/' . str_replace(get_sub_page_dir(get_page_seoname($sub_page)) . '/', '', get_page_seoname($sub_page)) . '.php');
        }
        //Delete the dir where the sub-pages were in.
        rmdir(PAGE_DIR . '/' . $var1);
    }
    //If it's a sub-page, we have to do a few things.
    if (strpos($var1, '/') !== false) {
        //Delete the dir, if there are no other pages.
        if (read_dir_contents(PAGE_DIR . '/' . get_sub_page_dir($var1), 'files') == false) {
            rmdir(PAGE_DIR . '/' . get_sub_page_dir($var1));
        } else {
            reorder_pages(PAGE_DIR . '/' . get_sub_page_dir($var1));
        }
    } else {
        reorder_pages(PAGE_DIR);
    }
    //Show message.
    show_error($lang['trashcan']['moving_item'], 3);
}
//Redirect user.
redirect('?action=page', 0);
Example #2
0
/**
 * Save a page with a lot of options.
 *
 * @since 4.7
 * @package admin
 * @param mixed $title if string - The title, if array title => The title, seo_name => The seo_name.
 * @param string $content The content.
 * @param string $hidden Should it be hidden ('yes' or 'no')?
 * @param string $subpage Specifies the parent page, if the saved page should be a sub page. Default to null.
 * @param string $description Description of the page. Defaults to null.
 * @param string $keywords Keywords of the page. Defaults to null.
 * @param array $module_additional_data Additional data variable, can be edited by modules through hooks (admin_save_page_module_additional_data). Defaults to null.
 * @param string $current_seoname Current seoname of the page, if we are editing a page. Defaults to null.
 * @return string Seoname of the saved page.
 */
function save_page($title, $content, $hidden, $subpage = null, $description = null, $keywords = null, $module_additional_data = null, $current_seoname = null)
{
    //Run a few hooks.
    run_hook('admin_save_page', array(&$title, &$content));
    run_hook('admin_save_page_meta', array(&$description, &$keywords));
    run_hook('admin_save_page_module_additional_data', array(&$module_additional_data));
    //Configure title and seo_name
    if (is_array($title)) {
        if (!empty($title['seo_name'])) {
            $seo_title = $title['seo_name'];
            $title = $title['title'];
        } else {
            $seo_title = seo_url($title['title']);
            $title = $title['title'];
        }
    } else {
        $seo_title = seo_url($title);
    }
    //Check if the seo url  is empty.
    if (empty($seo_title)) {
        return false;
    }
    //Check if a page already exists with the name.
    if ((!isset($current_seoname) || $current_seoname != $subpage . $seo_title) && get_page_filename($subpage . $seo_title) != false) {
        return false;
    }
    //Do we want to create a new page?
    if (!isset($current_seoname)) {
        //Check if we want a sub-page.
        if (!empty($subpage)) {
            //We need to make sure that the dir exists, and if not, create it.
            if (!file_exists(PAGE_DIR . '/' . rtrim($subpage, '/'))) {
                mkdir(PAGE_DIR . '/' . rtrim($subpage, '/'));
                chmod(PAGE_DIR . '/' . rtrim($subpage, '/'), 0777);
            }
            $pages = read_dir_contents(PAGE_DIR . '/' . rtrim($subpage, '/'), 'files');
        } else {
            $pages = read_dir_contents(PAGE_DIR, 'files');
        }
        //Are there any pages?
        if ($pages == false) {
            $number = 1;
        } else {
            $number = count($pages) + 1;
        }
        $newfile = $subpage . $number . '.' . $seo_title;
    } else {
        $filename = get_page_filename($current_seoname);
        //the old file name
        //Is it a sub-page, or do we want to make it one?
        if (strpos($current_seoname, '/') !== false || !empty($subpage)) {
            $page_name = explode('/', $subpage);
            $count = count($page_name);
            unset($page_name[$count]);
            $dir = get_sub_page_dir($current_seoname);
            $filename_array = str_replace($dir . '/', '', $filename);
            $filename_array = explode('.', $filename_array);
            $newfilename = implode('/', $page_name) . '/' . $filename_array[0] . '.' . $seo_title;
            $newdir = get_sub_page_dir($newfilename);
            //We need to make sure that the dir exists, and if not, create it.
            if (!file_exists(PAGE_DIR . '/' . $newdir)) {
                mkdir(PAGE_DIR . '/' . $newdir);
                chmod(PAGE_DIR . '/' . $newdir, 0777);
            }
            //If the name isn't the same as before, we have to find the correct number.
            if ($newfilename . '.php' != $filename) {
                //If the sub-folder is the same, use the same number as before.
                if ($dir . '/' == $newdir) {
                    $number = $filename_array[0];
                } else {
                    $pages = read_dir_contents(PAGE_DIR . '/' . $newdir, 'files');
                    if ($pages) {
                        $count = count($pages);
                        $number = $count + 1;
                    } else {
                        $number = 1;
                    }
                }
                $newfile = implode('/', $page_name) . $number . '.' . $seo_title;
            }
        } else {
            $filename_array = explode('.', $filename);
            $newfile = $filename_array[0] . '.' . $seo_title;
        }
    }
    //Save the title, content and hidden status.
    $data = '<?php' . "\n" . '$title = \'' . sanitize($title) . '\';' . "\n" . '$seoname = \'' . sanitize($seo_title) . '\';' . "\n" . '$content = \'' . sanitize($content, false) . '\';' . "\n" . '$hidden = \'' . $hidden . '\';';
    //Save the description and keywords, if any.
    if ($description != null) {
        $data .= "\n" . '$description = \'' . sanitize($description) . '\';';
    }
    if ($keywords != null) {
        $data .= "\n" . '$keywords = \'' . sanitize($keywords) . '\';';
    }
    //If modules have supplied additional data, save it.
    if ($module_additional_data != null && is_array($module_additional_data)) {
        foreach ($module_additional_data as $var => $value) {
            $data .= "\n" . '$' . $var . ' = \'' . $value . '\';';
        }
    }
    $data .= "\n" . '?>';
    //Save the file.
    save_file(PAGE_DIR . '/' . $newfile . '.php', $data);
    //Do a little cleanup if we are editing a page.
    if (isset($current_seoname)) {
        //Check if the title is different from what we started with.
        if ($newfile . '.php' != $filename) {
            //If there are sub-pages, rename the folder.
            if (file_exists(PAGE_DIR . '/' . get_page_seoname($filename))) {
                rename(PAGE_DIR . '/' . get_page_seoname($filename), PAGE_DIR . '/' . get_page_seoname($newfile . '.php'));
            }
            //Remove the old file.
            unlink(PAGE_DIR . '/' . $filename);
            //If there are no files in the old dir, delete it.
            if (isset($dir) && read_dir_contents(PAGE_DIR . '/' . $dir, 'files') == false) {
                rmdir(PAGE_DIR . '/' . $dir);
            } elseif (isset($dir)) {
                reorder_pages(PAGE_DIR . '/' . $dir);
            } else {
                reorder_pages(PAGE_DIR);
            }
        }
    }
    //Return the seoname.
    return get_page_seoname($newfile . '.php');
}