示例#1
0
/**
 * Parse a string and replace any Textpattern tags with their actual value
 *
 * @param string $thing The raw string
 * @return string The parsed string
 */
function parse($thing)
{
    $f = '@(</?txp:\\w+(?:\\s+\\w+\\s*=\\s*(?:"(?:[^"]|"")*"|\'(?:[^\']|\'\')*\'|[^\\s\'"/>]+))*\\s*/?' . chr(62) . ')@s';
    $t = '@:(\\w+)(.*?)/?.$@s';
    $parsed = preg_split($f, $thing, -1, PREG_SPLIT_DELIM_CAPTURE);
    $level = 0;
    $out = '';
    $inside = '';
    $istag = FALSE;
    foreach ($parsed as $chunk) {
        if ($istag) {
            if ($level === 0) {
                preg_match($t, $chunk, $tag);
                if (substr($chunk, -2, 1) === '/') {
                    # self closing
                    $out .= processTags($tag[1], $tag[2]);
                } else {
                    # opening
                    $level++;
                }
            } else {
                if (substr($chunk, 1, 1) === '/') {
                    # closing
                    if (--$level === 0) {
                        $out .= processTags($tag[1], $tag[2], $inside);
                        $inside = '';
                    } else {
                        $inside .= $chunk;
                    }
                } elseif (substr($chunk, -2, 1) !== '/') {
                    # opening inside open
                    ++$level;
                    $inside .= $chunk;
                } else {
                    $inside .= $chunk;
                }
            }
        } else {
            if ($level) {
                $inside .= $chunk;
            } else {
                $out .= $chunk;
            }
        }
        $istag = !$istag;
    }
    return $out;
}
/**
 * Updates a news article and returns the object of that article
 *
 * @return object
 */
function updateArticle(&$reports)
{
    $date = date('Y-m-d_H-i-s');
    $title = process_language_string_save("title", 2);
    $author = sanitize($_POST['author']);
    $content = process_language_string_save("content", 0);
    // TinyMCE already clears unallowed code
    $extracontent = process_language_string_save("extracontent", 0);
    // TinyMCE already clears unallowed code
    $custom = process_language_string_save("custom_data", 1);
    $show = getcheckboxState('show');
    $date = sanitize($_POST['date']);
    $expiredate = getExpiryDatePost();
    $permalink = getcheckboxState('permalink');
    $lastchange = sanitize($_POST['lastchange']);
    $lastchangeauthor = sanitize($_POST['lastchangeauthor']);
    $commentson = getcheckboxState('commentson');
    $codeblock1 = sanitize($_POST['codeblock1'], 0);
    $codeblock2 = sanitize($_POST['codeblock2'], 0);
    $codeblock3 = sanitize($_POST['codeblock3'], 0);
    $codeblock = serialize(array("1" => $codeblock1, "2" => $codeblock2, "3" => $codeblock3));
    $locked = getcheckboxState('locked');
    $titlelink = $oldtitlelink = sanitize($_POST['titlelink-old'], 3);
    if (getcheckboxState('edittitlelink')) {
        $titlelink = sanitize($_POST['titlelink'], 3);
        if (empty($titlelink)) {
            $titlelink = seoFriendly(get_language_string($title));
            if (empty($titlelink)) {
                $titlelink = seoFriendly($date);
            }
        }
    } else {
        if (!$permalink) {
            //	allow the title link to change.
            $link = seoFriendly(get_language_string($title));
            if (!empty($link)) {
                $titlelink = $link;
            }
        }
    }
    $id = sanitize($_POST['id']);
    $rslt = true;
    if ($titlelink != $oldtitlelink) {
        // title link change must be reflected in DB before any other updates
        $rslt = query('UPDATE ' . prefix('news') . ' SET `titlelink`=' . db_quote($titlelink) . ' WHERE `id`=' . $id, false);
        if (!$rslt) {
            $titlelink = $oldtitlelink;
            // force old link so data gets saved
        }
    }
    // update article
    $article = new ZenpageNews($titlelink, true);
    $article->setTitle($title);
    $article->setContent($content);
    $article->setExtracontent($extracontent);
    $article->setCustomData(zp_apply_filter('save_article_custom_data', $custom, $article));
    $article->setShow($show);
    $article->setDateTime($date);
    $article->setCommentsAllowed($commentson);
    $article->setCodeblock($codeblock);
    $article->setAuthor($author);
    $article->setLastchange($lastchange);
    $article->setLastchangeauthor($lastchangeauthor);
    $article->setPermalink($permalink);
    $article->setLocked($locked);
    $article->setExpiredate($expiredate);
    $article->setSticky(sanitize_numeric($_POST['sticky']));
    if (getcheckboxState('resethitcounter')) {
        $article->set('hitcounter', 0);
    }
    processTags($article);
    $categories = array();
    $result2 = query_full_array("SELECT * FROM " . prefix('news_categories') . " ORDER BY titlelink");
    foreach ($result2 as $cat) {
        if (isset($_POST["cat" . $cat['id']])) {
            $categories[] = $cat['titlelink'];
        }
    }
    $article->setCategories($categories);
    $msg = zp_apply_filter('update_article', '', $article, $oldtitlelink);
    $article->save();
    if (!$rslt) {
        $reports[] = "<p class='errorbox fade-message'>" . sprintf(gettext("An article with the title/titlelink <em>%s</em> already exists!"), $titlelink) . '</p>';
    } else {
        if (empty($title)) {
            $reports[] = "<p class='errorbox fade-message'>" . sprintf(gettext("Article <em>%s</em> updated but you need to give it a <strong>title</strong> before publishing!"), get_language_string($titlelink)) . '</p>';
        } else {
            $reports[] = "<p class='messagebox fade-message'>" . sprintf(gettext("Article <em>%s</em> updated"), $titlelink) . '</p>';
        }
    }
    if ($msg) {
        $reports[] = $msg;
    }
    return $article;
}
示例#3
0
function parse($thing)
{
    $f = '@(</?txp:\\S+\\b.*(?:/)?(?<!\\\\)>)@sU';
    $parsed = preg_split($f, $thing, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
    $tagpat = '@^<(/?)txp:(\\w+)\\b(.*?)(/?)(?<!\\\\)>$@';
    $out = '';
    $stack = array();
    $inside = '';
    $tag = array();
    foreach ($parsed as $chunk) {
        if (preg_match($tagpat, $chunk, $m)) {
            if ($m[1] == '' and $m[4] == '') {
                // opening tag
                if (empty($stack)) {
                    $tag = $m;
                } else {
                    $inside .= $chunk;
                }
                array_push($stack, $m);
            } elseif ($m[1] == '/' and $m[4] == '') {
                // closing tag
                $pop = @array_pop($stack);
                if (!$pop or $pop[2] != $m[2]) {
                    trigger_error(gTxt('parse_tag_mismatch', array('code', $chunk)));
                }
                if (empty($stack)) {
                    $out .= processTags(array($m[0], $tag[2], $tag[3], '', $inside));
                    $inside = '';
                } else {
                    $inside .= $chunk;
                }
            } elseif ($m[1] == '' and $m[4] == '/') {
                // self closing
                if (empty($stack)) {
                    $out .= processTags(array($m[0], $m[2], $m[3]));
                } else {
                    $inside .= $chunk;
                }
            } else {
                trigger_error(gTxt('parse_error' . ':' . $chunk, array('code', $chunk)));
            }
        } else {
            if (empty($stack)) {
                $out .= $chunk;
            } else {
                $inside .= $chunk;
            }
        }
    }
    if ($inside) {
        $out .= $inside;
    }
    foreach ($stack as $t) {
        trigger_error(gTxt('parse_tag_unclosed', array('tag', $t[2])));
    }
    return $out;
}
/**
 * Updates or adds a news article and returns the object of that article
 *
 * @param array $reports display
 * @param bool $newarticle true if a new article
 *
 * @return object
 */
function updateArticle(&$reports, $newarticle = false)
{
    $date = date('Y-m-d_H-i-s');
    $title = process_language_string_save("title", 2);
    $author = sanitize($_POST['author']);
    $content = zpFunctions::updateImageProcessorLink(process_language_string_save("content", EDITOR_SANITIZE_LEVEL));
    $extracontent = zpFunctions::updateImageProcessorLink(process_language_string_save("extracontent", EDITOR_SANITIZE_LEVEL));
    $custom = process_language_string_save("custom_data", 1);
    $show = getcheckboxState('show');
    $date = sanitize($_POST['date']);
    $expiredate = getExpiryDatePost();
    $permalink = getcheckboxState('permalink');
    $lastchange = sanitize($_POST['lastchange']);
    $lastchangeauthor = sanitize($_POST['lastchangeauthor']);
    $commentson = getcheckboxState('commentson');
    if (zp_loggedin(CODEBLOCK_RIGHTS)) {
        $codeblock = processCodeblockSave(0);
    }
    $locked = getcheckboxState('locked');
    if ($newarticle) {
        $titlelink = seoFriendly(get_language_string($title));
        if (empty($titlelink)) {
            $titlelink = seoFriendly($date);
        }
        $sql = 'SELECT `id` FROM ' . prefix('news') . ' WHERE `titlelink`=' . db_quote($titlelink);
        $rslt = query_single_row($sql, false);
        if ($rslt) {
            //already exists
            $time = explode(' ', microtime());
            $titlelink = $titlelink . '_' . ($time[1] + $time[0]);
            $reports[] = "<p class='warningbox fade-message'>" . gettext('Duplicate article title') . '</p>';
        }
        $oldtitlelink = $titlelink;
        $id = 0;
    } else {
        $titlelink = $oldtitlelink = sanitize($_POST['titlelink-old'], 3);
        $id = sanitize($_POST['id']);
    }
    if (getcheckboxState('edittitlelink')) {
        $titlelink = sanitize($_POST['titlelink'], 3);
        if (empty($titlelink)) {
            $titlelink = seoFriendly(get_language_string($title));
            if (empty($titlelink)) {
                $titlelink = seoFriendly($date);
            }
        }
    } else {
        if (!$permalink) {
            //	allow the title link to change.
            $link = seoFriendly(get_language_string($title));
            if (!empty($link)) {
                $titlelink = $link;
            }
        }
    }
    $rslt = true;
    if ($titlelink != $oldtitlelink) {
        // title link change must be reflected in DB before any other updates
        $rslt = query('UPDATE ' . prefix('news') . ' SET `titlelink`=' . db_quote($titlelink) . ' WHERE `id`=' . $id, false);
        if (!$rslt) {
            $titlelink = $oldtitlelink;
            // force old link so data gets saved
        } else {
            SearchEngine::clearSearchCache();
        }
    }
    // update article
    $article = new ZenpageNews($titlelink, true);
    $article->setTitle($title);
    $article->setContent($content);
    $article->setExtracontent($extracontent);
    $article->setCustomData(zp_apply_filter('save_article_custom_data', $custom, $article));
    $article->setShow($show);
    $article->setDateTime($date);
    $article->setCommentsAllowed($commentson);
    if (zp_loggedin(CODEBLOCK_RIGHTS)) {
        $article->setCodeblock($codeblock);
    }
    $article->setAuthor($author);
    $article->setLastchange($lastchange);
    $article->setLastchangeauthor($lastchangeauthor);
    $article->setPermalink($permalink);
    $article->setLocked($locked);
    $article->setExpiredate($expiredate);
    $article->setSticky(sanitize_numeric($_POST['sticky']));
    if (getcheckboxState('resethitcounter')) {
        $article->set('hitcounter', 0);
    }
    if (getcheckboxState('reset_rating')) {
        $article->set('total_value', 0);
        $article->set('total_votes', 0);
        $article->set('used_ips', 0);
    }
    $article->setTruncation(getcheckboxState('truncation'));
    processTags($article);
    $categories = array();
    $result2 = query_full_array("SELECT * FROM " . prefix('news_categories') . " ORDER BY titlelink");
    foreach ($result2 as $cat) {
        if (isset($_POST["cat" . $cat['id']])) {
            $categories[] = $cat['titlelink'];
        }
    }
    $article->setCategories($categories);
    if ($newarticle) {
        $msg = zp_apply_filter('new_article', '', $article);
        if (empty($title)) {
            $reports[] = "<p class='errorbox fade-message'>" . sprintf(gettext("Article <em>%s</em> added but you need to give it a <strong>title</strong> before publishing!"), get_language_string($titlelink)) . '</p>';
        } else {
            $reports[] = "<p class='messagebox fade-message'>" . sprintf(gettext("Article <em>%s</em> added"), $titlelink) . '</p>';
        }
    } else {
        $msg = zp_apply_filter('update_article', '', $article, $oldtitlelink);
        if (!$rslt) {
            $reports[] = "<p class='errorbox fade-message'>" . sprintf(gettext("An article with the title/titlelink <em>%s</em> already exists!"), $titlelink) . '</p>';
        } else {
            if (empty($title)) {
                $reports[] = "<p class='errorbox fade-message'>" . sprintf(gettext("Article <em>%s</em> updated but you need to give it a <strong>title</strong> before publishing!"), get_language_string($titlelink)) . '</p>';
            } else {
                $reports[] = "<p class='messagebox fade-message'>" . sprintf(gettext("Article <em>%s</em> updated"), $titlelink) . '</p>';
            }
        }
    }
    $article->save();
    if ($msg) {
        $reports[] = $msg;
    }
    return $article;
}
示例#5
0
/**
 * Updates or adds a news article and returns the object of that article
 *
 * @param array $reports display
 * @param bool $newarticle true if a new article
 *
 * @return object
 */
function updateArticle(&$reports, $newarticle = false)
{
    global $_zp_current_admin_obj;
    $date = date('Y-m-d_H-i-s');
    $title = process_language_string_save("title", 2);
    $author = sanitize($_POST['author']);
    $content = zpFunctions::updateImageProcessorLink(process_language_string_save("content", EDITOR_SANITIZE_LEVEL));
    $show = getcheckboxState('show');
    $date = sanitize($_POST['date']);
    $pubdate = sanitize($_POST['pubdate']);
    $expiredate = getExpiryDatePost();
    $permalink = getcheckboxState('permalink');
    $lastchange = sanitize($_POST['lastchange']);
    $lastchangeauthor = sanitize($_POST['lastchangeauthor']);
    $commentson = getcheckboxState('commentson');
    $locked = getcheckboxState('locked');
    $show = getcheckboxState('show');
    if ($newarticle) {
        $titlelink = seoFriendly(get_language_string($title));
        if (empty($titlelink)) {
            $titlelink = seoFriendly($date);
        }
        $sql = 'SELECT `id` FROM ' . prefix('news') . ' WHERE `titlelink`=' . db_quote($titlelink);
        $rslt = query_single_row($sql, false);
        if ($rslt) {
            //already exists
            $time = explode(' ', microtime());
            $titlelink = $titlelink . '_' . ($time[1] + $time[0]);
            $reports[] = "<p class='warningbox fade-message'>" . gettext('Duplicate article title') . '</p>';
        }
        $oldtitlelink = $titlelink;
        $id = 0;
    } else {
        $titlelink = $oldtitlelink = sanitize($_POST['titlelink-old'], 3);
        $id = sanitize($_POST['id']);
    }
    if (getcheckboxState('edittitlelink')) {
        $titlelink = sanitize($_POST['titlelink'], 3);
        if (empty($titlelink)) {
            $titlelink = seoFriendly(get_language_string($title));
            if (empty($titlelink)) {
                $titlelink = seoFriendly($date);
            }
        }
    } else {
        if (!$permalink) {
            //	allow the title link to change.
            $link = seoFriendly(get_language_string($title));
            if (!empty($link)) {
                $titlelink = $link;
            }
        }
    }
    $rslt = true;
    if ($titlelink != $oldtitlelink) {
        // title link change must be reflected in DB before any other updates
        $rslt = query('UPDATE ' . prefix('news') . ' SET `titlelink`=' . db_quote($titlelink) . ' WHERE `id`=' . $id, false);
        if (!$rslt) {
            $titlelink = $oldtitlelink;
            // force old link so data gets saved
        }
    }
    // update article
    $article = newArticle($titlelink, true);
    $article->setTitle($title);
    $article->setContent($content);
    $article->setDateTime($date);
    $article->setCommentsAllowed($commentson);
    $article->setAuthor($author);
    $article->setLastchange($lastchange);
    $article->setLastchangeauthor($lastchangeauthor);
    $article->setPermalink($permalink);
    $article->setLocked($locked);
    $article->setExpiredate($expiredate);
    $article->setPublishDate($pubdate);
    $article->setSticky(sanitize_numeric($_POST['sticky']));
    if (getcheckboxState('resethitcounter')) {
        $article->set('hitcounter', 0);
    }
    if (getcheckboxState('reset_rating')) {
        $article->set('total_value', 0);
        $article->set('total_votes', 0);
        $article->set('used_ips', 0);
    }
    $article->setTruncation(getcheckboxState('truncation'));
    processTags($article);
    $categories = array();
    $myCategories = array_flip($_zp_current_admin_obj->getObjects('news'));
    if (isset($_POST['addcategories'])) {
        $cats = sanitize($_POST['addcategories']);
        $result2 = query_full_array("SELECT * FROM " . prefix('news_categories') . " ORDER BY titlelink", true, 'id');
        if ($result2) {
            foreach ($cats as $cat) {
                if (isset($result2[$cat])) {
                    $categories[] = $result2[$cat]['titlelink'];
                }
            }
        }
        if (!zp_loggedin(MANAGE_ALL_NEWS_RIGHTS)) {
            foreach ($categories as $key => $cat) {
                if (!isset($myCategories[$cat])) {
                    unset($categories[$key]);
                }
            }
        }
    }
    $article->setCategories($categories);
    $article->setShow($show);
    if (!zp_loggedin(MANAGE_ALL_NEWS_RIGHTS) && empty($categories)) {
        //	check if he is allowed to make un-categorized articles
        if (!isset($myCategories['`'])) {
            $reports[] = "<p class='errorbox fade-message'>" . sprintf(gettext("Article <em>%s</em> may not be un-categorized."), $titlelink) . '</p>';
            unset($myCategories['`']);
            $cagegories[] = array_shift($myCategories);
        }
    }
    if ($newarticle) {
        $msg = zp_apply_filter('new_article', '', $article);
        if (empty($title)) {
            $reports['success'] = "<p class='errorbox fade-message'>" . sprintf(gettext("Article <em>%s</em> added but you need to give it a <strong>title</strong> before publishing!"), get_language_string($titlelink)) . '</p>';
        } else {
            $reports['success'] = "<p class='messagebox fade-message'>" . sprintf(gettext("Article <em>%s</em> added"), $titlelink) . '</p>';
        }
    } else {
        $msg = zp_apply_filter('update_article', '', $article, $oldtitlelink);
        if (!$rslt) {
            $reports[] = "<p class='errorbox fade-message'>" . sprintf(gettext("An article with the title/titlelink <em>%s</em> already exists!"), $titlelink) . '</p>';
        } else {
            if (empty($title)) {
                $reports['success'] = "<p class='errorbox fade-message'>" . sprintf(gettext("Article <em>%s</em> updated but you need to give it a <strong>title</strong> before publishing!"), get_language_string($titlelink)) . '</p>';
            } else {
                $reports['success'] = "<p class='messagebox fade-message'>" . sprintf(gettext("Article <em>%s</em> updated"), $titlelink) . '</p>';
            }
        }
    }
    zp_apply_filter('save_article_custom_data', NULL, $article);
    $article->save();
    $msg = zp_apply_filter('edit_error', $msg);
    if ($msg) {
        $reports[] = $msg;
    }
    return $article;
}