Example #1
0
/**
 * create or edit a page
 *
 * @return array status of the edit
 */
function Core_adminPageEdit()
{
    /**
     * function for recursively updating a page (and its children) template
     *
     * @param int    $id       the page id
     * @param string $template the template name
     *
     * @return null
     */
    function recursivelyUpdatePageTemplates($id, $template)
    {
        $pages = Pages::getInstancesByParent($id, false);
        $ids = array();
        foreach ($pages->pages as $page) {
            $ids[] = $page->id;
            recursivelyUpdatePageTemplates($page->id, $template);
        }
        if (!count($ids)) {
            return;
        }
        dbQuery('update pages set template="' . addslashes($template) . '" where id in (' . join(',', $ids) . ')');
    }
    $id = (int) @$_REQUEST['id'];
    $pid = $id ? dbOne('select parent from pages where id=' . $id, 'parent') : (int) $_REQUEST['parent'];
    $special = 0;
    if (isset($_REQUEST['special'])) {
        $specials = $_REQUEST['special'];
        if (is_array($specials)) {
            foreach ($specials as $a => $b) {
                $special += pow(2, $a);
            }
        }
        $homes = dbOne("select count(id) as ids from pages where (special&1)" . ($id ? " AND id!={$id}" : ""), 'ids');
        if ($special & 1) {
            // there can be only one homepage
            if ($homes != 0) {
                dbQuery("update pages set special=special-1 where special&1");
            }
        } else {
            if ($homes == 0) {
                $special += 1;
            }
        }
    }
    $keywords = @$_REQUEST['keywords'];
    $title = @$_REQUEST['title'];
    $description = @$_REQUEST['description'];
    $date_publish = isset($_REQUEST['date_publish']) ? $_REQUEST['date_publish'] : '0000-00-00 00:00:00';
    $date_unpublish = isset($_REQUEST['date_unpublish']) ? $_REQUEST['date_unpublish'] : '0000-00-00 00:00:00';
    $importance = (double) @$_REQUEST['importance'];
    if (!isset($_REQUEST['body'])) {
        $_REQUEST['body'] = '';
    }
    if ($importance < 0.1) {
        $importance = 0.5;
    }
    if ($importance > 1) {
        $importance = 1;
    }
    // { name, alias
    $name = trim($_REQUEST['name']);
    if (!$name) {
        $name = __('No page name provided');
    } else {
        // check to see if name is already in use
        $sql = 'select id from pages where name="' . addslashes($name) . '" and parent=' . $pid . ' and id!=' . $id;
        if (dbOne($sql, 'id')) {
            $i = 2;
            while (dbOne('select id from pages where name="' . addslashes($name . $i) . '" and parent=' . $pid . ' and id!="' . $id . '"', 'id')) {
                $i++;
            }
            $msgs .= '<em>' . __('A page named "%1" already exists. Page name amended to "%2"', $name, $name . $i) . '</em>';
            $name .= $i;
        }
    }
    $alias = transcribe(__FromJson($name, true));
    // }
    // { body
    if (@$_REQUEST['page_vars']['_body']) {
        $_REQUEST['body'] = $_REQUEST['page_vars']['_body'];
        unset($_REQUEST['page_vars']['_body']);
    }
    if (!$id) {
        $original_body = '<h1>' . htmlspecialchars($name) . '</h1><p>&nbsp;</p>';
    } else {
        $lim = (int) @$GLOBALS['DBVARS']['site_page_length_limit'];
        if (is_array($_REQUEST['body'])) {
            if ($lim) {
                foreach ($_REQUEST['body'] as $k => $v) {
                    if (strlen($v) > $lim) {
                        $_REQUEST['body'][$k] = preg_replace('/<[^>]*$/', '', substr($v, 0, $lim));
                    }
                }
            }
            $original_body = json_encode($_REQUEST['body']);
        } else {
            $original_body = $_REQUEST['body'];
            if ($lim && strlen($original_body) > $lim) {
                $original_body = preg_replace('/<[^>]*$/', '', substr($original_body, 0, $lim));
            }
        }
    }
    foreach ($GLOBALS['PLUGINS'] as $plugin) {
        if (isset($plugin['admin']['body_override'])) {
            $original_body = $plugin['admin']['body_override'](false);
        }
    }
    $body = $original_body;
    $body = Core_sanitiseHtml($body);
    // }
    // { template
    $template = @$_REQUEST['template'];
    if ($template == '' && $pid) {
        $template = dbOne('select template from pages where id=' . $pid, 'template');
    }
    if (isset($_REQUEST['recursively_update_page_templates'])) {
        recursivelyUpdatePageTemplates($id, $template);
    }
    // }
    if ($id != 0) {
        //if we don't create a page
        //i.e. we edit it
        $page = Page::getInstance($id);
        $page->initValues();
        if (isset($page->plugin)) {
            //if this page it's a plugin
            $type = $page->plugin;
            //we find the plugin's name(plugin type)
        }
        if (@$GLOBALS['PLUGINS'][$type]['do-not-delete']) {
            // don't modify type
            $type = dbOne('select type from pages where id=' . $id, 'type');
            if ($type != $_REQUEST['type']) {
                echo '<script>alert("' . addslashes(__("The type of the page couldn't be changed")) . '")</script>';
            }
        } else {
            //We can change the type
            $type = $_REQUEST['type'];
        }
    } else {
        //if we create the page
        $type = $_REQUEST['type'];
    }
    $destType = preg_replace('/\\|.*/', '', $_REQUEST['type']);
    if (@$GLOBALS['PLUGINS'][$destType]['only-one-page-instance'] == true) {
        //we count how many pages of this type
        //we have
        $howMany = dbOne('select COUNT(type) FROM pages WHERE type="' . $_REQUEST['type'] . '"' . ' and id!=' . $id, 'COUNT(type)');
        if ($howMany >= 1) {
            //If we already have a page
            echo "<script>alert('" . addslashes(__('You already have one page of that type')) . "');</script>";
            return array('error' => __('You can have only one page of this type'));
        }
    }
    $associated_date = isset($_REQUEST['associated_date']) ? $_REQUEST['associated_date'] : date('Y-m-d H:i:s');
    $q = 'pages set importance=' . $importance . ',template="' . addslashes($template) . '",edate=now()' . ',type="' . addslashes($type) . '"' . ',date_unpublish="' . addslashes($date_unpublish) . '"' . ',date_publish="' . addslashes($date_publish) . '"' . ',associated_date="' . addslashes($associated_date) . '"' . ',keywords="' . addslashes($keywords) . '"' . ',description="' . addslashes($description) . '"' . ',name="' . addslashes($name) . '"' . ',title="' . addslashes($title) . '"' . ',original_body="' . addslashes(Core_sanitiseHtmlEssential($original_body)) . '"' . ',link="' . addslashes(__FromJson($name, true)) . '"' . ',body="' . addslashes($body) . '"' . ',alias="' . $alias . '",parent=' . $pid . ',special=' . $special;
    if (!$id) {
        // ord
        $ord = dbOne('select ord from pages where parent=' . $pid . ' order by ord desc limit 1', 'ord') + 1;
        $q .= ',ord=' . $ord . ',cdate=now()';
    }
    // { insert the page
    if ($id) {
        $q = 'update ' . $q . ' where id=' . $id;
    } else {
        $onlyOnePageInstance = false;
        $pluginType = preg_replace('/\\|.*/', '', $_REQUEST['type']);
        if (isset($GLOBALS['PLUGINS'][$pluginType]['only-one-page-instance'])) {
            $onlyOnePageInstance = $GLOBALS['PLUGINS'][$pluginType]['only-one-page-instance'];
        }
        $alreadyAtInstancesLimit = $onlyOnePageInstance ? dbOne('select COUNT(type) FROM pages WHERE type="' . $_REQUEST['type'] . '"', 'COUNT(type)') : 0;
        $q = 'INSERT into ' . $q . ',category=""';
        if ($onlyOnePageInstance == true) {
            if ($howMany >= 1) {
                return array('error' => __('You can have only one page of this type'));
            }
        }
    }
    dbQuery($q);
    if (!$id) {
        $id = dbOne('select last_insert_id() as id', 'id');
    }
    // }
    // { page_vars
    dbQuery('delete from page_vars where page_id="' . $id . '"');
    $pagevars = isset($_REQUEST['page_vars']) ? $_REQUEST['page_vars'] : array();
    if (@$_REQUEST['short_url']) {
        dbQuery('insert into short_urls set cdate=now(),page_id=' . $id . ',short_url="' . addslashes($_REQUEST['short_url']) . '"');
        $pagevars['_short_url'] = 1;
    } else {
        dbQuery('delete from short_urls where page_id=' . $id);
        unset($pagevars['_short_url']);
    }
    if (is_array($pagevars)) {
        if (isset($pagevars['google-site-verification'])) {
            $pagevars['google-site-verification'] = preg_replace('#.*content="([^"]*)".*#', '\\1', $pagevars['google-site-verification']);
        }
        foreach ($pagevars as $k => $v) {
            if (is_array($v)) {
                $v = json_encode($v);
            }
            dbQuery('insert into page_vars (name,value,page_id) values("' . addslashes($k) . '","' . addslashes($v) . '",' . $id . ')');
        }
    }
    // }
    if ($_POST['type'] == 4) {
        $page_summary_parent = isset($_POST['page_summary_parent']) ? $_POST['page_summary_parent'] : $id;
        $r2 = dbRow('select * from page_summaries where page_id="' . $id . '"');
        $do = 1;
        if ($r2) {
            if (isset($_POST['page_summary_parent']) && $r2['parent_id'] != $page_summary_parent) {
                dbQuery('delete from page_summaries where page_id="' . $id . '"');
            } else {
                $do = 0;
            }
        }
        if ($do) {
            dbQuery('insert into page_summaries set page_id="' . $id . '",parent_id="' . $page_summary_parent . '",rss=""');
        }
        require_once SCRIPTBASE . '/ww.incs/page.summaries.php';
        PageSummaries_getHtml($id);
    }
    // { clean up and return
    dbQuery('update page_summaries set rss=""');
    if (@$GLOBALS['DBVARS']['cron-next']) {
        unset($GLOBALS['DBVARS']['cron-next']);
    }
    Core_cacheClear();
    Core_configRewrite();
    return array('id' => $id, 'pid' => $pid, 'alias' => $alias, 'sql' => $q);
    // }
}
Example #2
0
/**
 * display page summaries
 *
 * PHP version 5.2
 *
 * @category None
 * @package  None
 * @author   Kae Verens <*****@*****.**>
 * @license  GPL 2.0
 * @link     http://webworks.ie/
 */
require_once '../ww.incs/common.php';
header('Content-type: text/xml; charset=utf-8');
$pagename = preg_replace('#^/|.rss$#', '', urldecode($_SERVER['REQUEST_URI']));
$page = Page::getInstanceByName($pagename);
if ($page) {
    $r2 = dbRow('select rss from page_summaries where page_id=' . $page->id);
    if (count($r2)) {
        if ($r2['rss'] == '') {
            require_once SCRIPTBASE . '/ww.incs/page.summaries.php';
            PageSummaries_getHtml($page->id);
            $r2 = dbRow('select rss from page_summaries where page_id=' . $page->id);
        }
        $rss = str_replace('&rsquo;', '&apos;', $r2['rss']);
        $rss = str_replace('&sbquo;', '&apos;', $rss);
        echo $rss;
    }
} else {
    echo 'page "' . $pagename . '" not found';
}
Example #3
0
     $c .= $PAGEDATA->render();
     break;
     // }
 // }
 case '1':
     // { redirect
     if (isset($PAGEDATA->vars['redirect_to']) && $PAGEDATA->vars['redirect_to']) {
         redirect($PAGEDATA->vars['redirect_to'], 'this is a redirect page');
     }
     break;
     // }
 // }
 case '4':
     // { sub-page summaries
     require_once 'ww.incs/page.summaries.php';
     $c .= PageSummaries_getHtml($PAGEDATA->id);
     break;
     // }
 // }
 case '5':
     // { search results
     require_once 'ww.incs/search.php';
     $c .= $PAGEDATA->render() . Search_showResults();
     break;
     // }
 // }
 case '9':
     // { table of contents
     require 'ww.incs/tableofcontents.php';
     $c .= TableOfContents_getContent($PAGEDATA);
     break;
    }
}
// }
if (isset($_REQUEST['recursively_update_page_templates'])) {
    recursively_update_page_templates($id, $template);
}
if ($_POST['type'] == 4) {
    $r2 = dbRow('select * from page_summaries where page_id="' . $id . '"');
    $do = 1;
    if ($r2) {
        if (isset($_POST['page_summary_parent']) && $r2['parent_id'] != $_POST['page_summary_parent']) {
            dbQuery('delete from page_summaries where page_id="' . $id . '"');
        } else {
            $do = 0;
        }
    }
    if ($do) {
        dbQuery('insert into page_summaries set page_id="' . $id . '",parent_id="' . $_POST['page_summary_parent'] . '",rss=""');
    }
    include_once SCRIPTBASE . '/ww.incs/page.summaries.php';
    PageSummaries_getHtml($id);
}
$msgs .= '<em>The page has been updated.</em>';
dbQuery('update page_summaries set rss=""');
cache_clear('menus');
cache_clear('pages');
if (isset($_REQUEST['frontend-admin'])) {
    echo '<script type="text/javascript">parent.location=parent.location;</script>';
} else {
    echo '<script>window.parent.document.getElementById("page_' . $id . '")' . '.childNodes[1].innerHTML=\'<ins class="jstree-icon">&nbsp;</ins>' . htmlspecialchars($name) . '\';</script>';
}