示例#1
0
<?php

//encoding=UTF-8
function createArticle($aFileName)
{
    $articleDoc = new DOMDocument("1.0", "UTF-8");
    $articleDoc->appendChild($articleDoc->createProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"../component/article/view-article.xsl\""));
    $articleDoc->appendChild($articleDoc->createProcessingInstruction("setter", "href=\"../component/article/setter-article.php\""));
    $articleE = $articleDoc->appendChild($articleDoc->createElementNS("http://formax.cz/ns/article", "article"));
    $articleE->setAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "xsi:schemaLocation", "http://formax.cz/ns/article ../component/article/model-article.xsd");
    $articleE->appendChild($articleDoc->createElementNS("http://formax.cz/ns/article", "h", "nový článek"));
    $articleE->appendChild($articleDoc->createElementNS("http://formax.cz/ns/article", "p", "nový článek"));
    $articleDoc->save($aFileName);
}
if (isset($_REQUEST["fileName"])) {
    $fileName = $_REQUEST["fileName"];
    createArticle("../../data/{$fileName}");
}
示例#2
0
fclose($fp);
if (!isset($pageProperties->onentry) and $pageProperties->operation == 'change') {
    exit;
}
$xslt = new XSLTProcessor();
$xslDoc->load("../page/setter-pageController.xsl");
$xslt->importStylesheet($xslDoc);
$xslt->setParameter("", "onentry", json_encode($pageProperties->onentry));
$xslt->setParameter("", "newStateId", $pageProperties->uri);
$xmlDoc->load($baseDir . "data/controller-page.scxml");
if (strpos($pageProperties->operation, "insert") === 0) {
    $xpath = new DOMXpath($xmlDoc);
    $elements = $xpath->query("//*[@id='{$stateId}']");
    if (!is_null($elements->item(0))) {
        foreach ($pageProperties->onentry as $fields) {
            foreach ($fields as $field) {
                foreach ($field as $data) {
                    if (!is_file($baseDir . $data)) {
                        createArticle($baseDir . $data);
                    }
                }
            }
        }
        $xslt->setParameter("", "stateId", $elements->item(0)->parentNode->getAttribute("id"));
        $xslt->setParameter("", "operation", "append");
    }
} else {
    $xslt->setParameter("", "operation", $pageProperties->operation);
    $xslt->setParameter("", "stateId", $stateId);
}
$result = $xslt->transformToURI($xmlDoc, $baseDir . "data/controller-page.scxml");
function sportal_add_article()
{
    global $smcFunc, $context, $scripturl, $sourcedir, $txt;
    if (!allowedTo(array('sp_add_article', 'sp_manage_articles', 'sp_admin'))) {
        fatal_lang_error('error_sp_cannot_add_article');
    }
    require_once $sourcedir . '/Subs-PortalAdmin.php';
    loadLanguage('SPortalAdmin', sp_languageSelect('SPortalAdmin'));
    loadTemplate('PortalArticles');
    if (!empty($_POST['add_article'])) {
        $article_options = array('id_category' => !empty($_POST['category']) ? (int) $_POST['category'] : 0, 'id_message' => !empty($_POST['message']) ? (int) $_POST['message'] : 0, 'approved' => allowedTo(array('sp_admin', 'sp_manage_articles', 'sp_auto_article_approval')) ? 1 : 0);
        createArticle($article_options);
        redirectexit('topic=' . $_POST['return']);
    }
    $context['message'] = !empty($_REQUEST['message']) ? (int) $_REQUEST['message'] : 0;
    $context['return'] = !empty($_REQUEST['return']) ? $_REQUEST['return'] : '';
    if (empty($context['message'])) {
        fatal_lang_error('error_sp_no_message_id');
    }
    $request = $smcFunc['db_query']('', '
		SELECT id_message
		FROM {db_prefix}sp_articles
		WHERE id_message = {int:message}', array('message' => $context['message']));
    list($exists) = $smcFunc['db_fetch_row']($request);
    $smcFunc['db_free_result']($request);
    if ($exists) {
        fatal_lang_error('error_sp_article_exists');
    }
    $context['list_categories'] = getCategoryInfo(null, true);
    if (empty($context['list_categories'])) {
        fatal_error(allowedTo(array('sp_admin', 'sp_manage_articles')) ? $txt['error_sp_no_category'] . '<br />' . sprintf($txt['error_sp_no_category_sp_moderator'], $scripturl . '?action=admin;area=portalarticles;sa=addcategory') : $txt['error_sp_no_category_normaluser'], false);
    }
    $context['sub_template'] = 'add_article';
}
示例#4
0
文件: article.php 项目: VecHK/pache
function createArticleProcess($POST)
{
    if (createArticle($POST)) {
        $topArticle = getArticleTop();
        if (isset($POST['tag']) && gettype($POST['tag']) == 'array') {
            if (!insertTagsById($topArticle->id, $POST['tag'])) {
                return echoInfoJson(101, 'ok, but tag fail');
            }
        }
        echo json_encode(new backTop($topArticle));
    } else {
        return echoInfoJson(2, 'fail');
    }
}
function sportal_admin_article_add()
{
    global $txt, $context, $scripturl, $smcFunc, $modSettings;
    // Are we ready?
    if (empty($_POST['createArticle']) || empty($_POST['articles'])) {
        // List all the categories.
        $context['list_categories'] = getCategoryInfo();
        // Do we have any category to add?
        if (empty($context['list_categories'])) {
            fatal_error($txt['error_sp_no_category'] . '<br />' . sprintf($txt['error_sp_no_category_sp_moderator'], $scripturl . '?action=admin;area=portalarticles;sa=addcategory'), false);
        }
        // Which board to show?
        if (isset($_REQUEST['targetboard'])) {
            $_REQUEST['targetboard'] = (int) $_REQUEST['targetboard'];
        } else {
            // Find one yourself.
            $request = $smcFunc['db_query']('', '
				SELECT b.id_board
				FROM {db_prefix}boards AS b
				WHERE b.redirect = \'\'
					AND {query_see_board}
				ORDER BY b.id_board DESC
				LIMIT 1');
            list($_REQUEST['targetboard']) = $smcFunc['db_fetch_row']($request);
            $smcFunc['db_free_result']($request);
        }
        $context['target_board'] = $_REQUEST['targetboard'];
        // Get the total topic count.
        $request = $smcFunc['db_query']('', '
			SELECT COUNT(*)
			FROM {db_prefix}topics as t
				INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
				LEFT JOIN {db_prefix}sp_articles as a ON (a.id_message = t.id_first_msg)
			WHERE t.id_board = {int:targetboard}
				AND IFNULL(a.id_article, 0) = 0
				AND {query_see_board}', array('targetboard' => $_REQUEST['targetboard']));
        list($topiccount) = $smcFunc['db_fetch_row']($request);
        $smcFunc['db_free_result']($request);
        // Create the page index.
        $context['page_index'] = constructPageIndex($scripturl . '?action=admin;area=portalarticles;sa=addarticle;targetboard=' . $_REQUEST['targetboard'] . ';board=' . $_REQUEST['targetboard'] . '.%d', $_REQUEST['start'], $topiccount, $modSettings['defaultMaxTopics'], true);
        // Get some info about the boards and categories.
        $request = $smcFunc['db_query']('', '
			SELECT b.id_board, b.name AS bName, c.name AS cName
			FROM {db_prefix}boards AS b
				LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
			WHERE b.redirect = \'\'
				AND {query_see_board}');
        $context['boards'] = array();
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            $context['boards'][] = array('id' => $row['id_board'], 'name' => $row['bName'], 'category' => $row['cName']);
        }
        $smcFunc['db_free_result']($request);
        // Time to get the topic data.
        $request = $smcFunc['db_query']('', '
			SELECT t.id_topic, m.subject, m.id_member, IFNULL(mem.real_name, m.poster_name) AS poster_name, m.id_msg
			FROM {db_prefix}topics AS t
				INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
				INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
				LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
				LEFT JOIN {db_prefix}sp_articles as a ON (a.id_message = t.id_first_msg)
			WHERE IFNULL(a.id_article, 0) = {int:article}
				AND t.id_board = {int:targetboard}
				AND {query_see_board}
			ORDER BY ' . (!empty($modSettings['enableStickyTopics']) ? 't.is_sticky DESC, ' : '') . 't.id_last_msg DESC
			LIMIT {int:start}, {int:max}', array('article' => 0, 'targetboard' => $_REQUEST['targetboard'], 'start' => $_REQUEST['start'], 'max' => $modSettings['defaultMaxTopics']));
        $context['topics'] = array();
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            censorText($row['subject']);
            $context['topics'][] = array('id' => $row['id_topic'], 'msg_id' => $row['id_msg'], 'poster' => array('id' => $row['id_member'], 'name' => $row['poster_name'], 'href' => empty($row['id_member']) ? '' : $scripturl . '?action=profile;u=' . $row['id_member'], 'link' => empty($row['id_member']) ? $row['poster_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" target="_blank">' . $row['poster_name'] . '</a>'), 'subject' => $row['subject'], 'js_subject' => addcslashes(addslashes($row['subject']), '/'));
        }
        $smcFunc['db_free_result']($request);
        // Set the page title and sub-template.
        $context['page_title'] = $txt['sp-articlesAdd'];
        $context['sub_template'] = 'article_add';
    } else {
        // But can you?
        checkSession();
        // Are they integer?
        foreach ($_POST['articles'] as $index => $article_id) {
            $_POST['articles'][(int) $index] = (int) $article_id;
        }
        // Add all of them.
        foreach ($_POST['articles'] as $article) {
            // Set them. They have their own IDs.
            $articleOptions = array('id_category' => !empty($_POST['category']) ? (int) $_POST['category'] : 0, 'id_message' => $article, 'approved' => 1);
            // A tricky function.
            createArticle($articleOptions);
        }
        // Time to go back.
        redirectexit('action=admin;area=portalarticles;sa=articles');
    }
}