/**
 * Updates a category
 *
 */
function updateCategory(&$reports)
{
    $date = date('Y-m-d_H-i-s');
    $id = sanitize_numeric($_POST['id']);
    $permalink = getcheckboxState('permalink');
    $title = process_language_string_save("title", 2);
    $desc = process_language_string_save("desc", 0);
    $custom = process_language_string_save("custom_data", 1);
    $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 link to change
            $link = seoFriendly(get_language_string($title));
            if (!empty($link)) {
                $titlelink = $link;
            }
        }
    }
    $titleok = true;
    if ($titlelink != $oldtitlelink) {
        // title link change must be reflected in DB before any other updates
        $titleok = query('UPDATE ' . prefix('news_categories') . ' SET `titlelink`=' . db_quote($titlelink) . ' WHERE `id`=' . $id, false);
        if (!$titleok) {
            $titlelink = $oldtitlelink;
            // force old link so data gets saved
        }
    } else {
        $titlelink = $oldtitlelink;
    }
    //update category
    $show = getcheckboxState('show');
    $cat = new ZenpageCategory($titlelink);
    $notice = processPasswordSave($cat);
    $cat->setPermalink(getcheckboxState('permalink'));
    $cat->set('title', $title);
    $cat->setDesc($desc);
    $cat->setCustomData(zp_apply_filter('save_category_custom_data', $custom, $cat));
    $cat->setShow($show);
    if (getcheckboxState('resethitcounter')) {
        $cat->set('hitcounter', 0);
    }
    $msg = zp_apply_filter('update_category', '', $cat, $oldtitlelink);
    $cat->save();
    if ($titleok) {
        if (empty($titlelink) or empty($title)) {
            $reports[] = "<p class='errorbox fade-message'>" . gettext("You forgot to give your category a <strong>title or titlelink</strong>!") . "</p>";
        } else {
            if ($notice == 'user') {
                $reports[] = "<p class='errorbox fade-message'>" . gettext('You must supply a password for the Protected Category user') . '</p>';
            } else {
                if ($notice == 'pass') {
                    $reports[] = "<p class='errorbox fade-message'>" . gettext('Your passwords were empty or did not match') . '</p>';
                } else {
                    $reports[] = "<p class='messagebox fade-message'>" . gettext("Category updated!") . "</p>";
                }
            }
        }
    } else {
        $reports[] = "<p class='errorbox fade-message'>" . sprintf(gettext("A category with the title/titlelink <em>%s</em> already exists!"), html_encode($cat->getTitle())) . "</p>";
    }
    if ($msg) {
        $reports[] = $msg;
    }
    return $cat;
}
Exemplo n.º 2
0
                    }
                    if ($commentexists_count != 0) {
                        $postinfo .= '<li class="import-exists">' . sprintf(ngettext('%1$u comment already exists.', '%1$u comments already exist.', $commentexists_count), $commentexists_count) . '</li>';
                    }
                    if ($commentcount != 0) {
                        $postinfo .= '<li class="import-success">' . sprintf(ngettext('%1$u comment imported.', '%1$u comments imported.', $commentcount), $commentcount) . '</li>';
                    }
                } else {
                    $postinfo .= '<ul><li class="import-nothing">' . gettext('No comments to import') . '</li>';
                }
                debugLogVar('Wordpress import - Comments for "' . $post['title'] . '" (' . $post['type'] . ')', $comments);
                $postinfo .= '</ul></li>';
                $postcount++;
            }
            // posts foreach
            $metaURL = 'wordpress_import.php?refresh=' . $postcount . '&amp;dbname=' . $wp_dbname . '&amp;dbuser='******'&amp;dbpass='******'&amp;dbhost=' . $wp_dbhost . '&amp;tableprefix=' . $wp_prefix . '&amp;convertlinefeeds=' . getcheckboxState('convertlinefeeds') . '&amp;XSRFToken=' . getXSRFToken('wordpress');
        } else {
            // if posts are available at all
            $metaURL = '';
            // to be sure...
            $postinfo .= "<li class='import-nothing'>" . gettext("No posts or pages to import.") . "</li>";
        }
    }
    // if db data set
    $zenphoto_tabs['overview']['subtabs'] = array(gettext('Wordpress') => '');
    printAdminHeader('overview', 'wordpress');
    if (!empty($metaURL) && $postcount < $posttotalcount) {
        ?>
		<meta http-equiv="refresh" content="1; url=<?php 
        echo $metaURL;
        ?>
/**
 * Updates or adds a category
 *
 * @param array $reports the results display
 * @param bool $newcategory true if a new article
 *
 */
function updateCategory(&$reports, $newcategory = false)
{
    $date = date('Y-m-d_H-i-s');
    $id = sanitize_numeric($_POST['id']);
    $permalink = getcheckboxState('permalink');
    $title = process_language_string_save("title", 2);
    $desc = process_language_string_save("desc", EDITOR_SANITIZE_LEVEL);
    $custom = process_language_string_save("custom_data", 1);
    if ($newcategory) {
        $titlelink = seoFriendly(get_language_string($title));
        if (empty($titlelink)) {
            $titlelink = seoFriendly($date);
        }
        $sql = 'SELECT `id` FROM ' . prefix('news_categories') . ' 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 category title') . '</p>';
        }
        $oldtitlelink = $titlelink;
    } else {
        $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 link to change
                $link = seoFriendly(get_language_string($title));
                if (!empty($link)) {
                    $titlelink = $link;
                }
            }
        }
    }
    $titleok = true;
    if ($titlelink != $oldtitlelink) {
        // title link change must be reflected in DB before any other updates
        $titleok = query('UPDATE ' . prefix('news_categories') . ' SET `titlelink`=' . db_quote($titlelink) . ' WHERE `id`=' . $id, false);
        if (!$titleok) {
            $titlelink = $oldtitlelink;
            // force old link so data gets saved
        } else {
            SearchEngine::clearSearchCache();
        }
    }
    //update category
    $show = getcheckboxState('show');
    $cat = new ZenpageCategory($titlelink, true);
    $notice = processCredentials($cat);
    $cat->setPermalink(getcheckboxState('permalink'));
    $cat->set('title', $title);
    $cat->setDesc($desc);
    $cat->setCustomData(zp_apply_filter('save_category_custom_data', $custom, $cat));
    $cat->setShow($show);
    if (getcheckboxState('resethitcounter')) {
        $cat->set('hitcounter', 0);
    }
    if (getcheckboxState('reset_rating')) {
        $cat->set('total_value', 0);
        $cat->set('total_votes', 0);
        $cat->set('used_ips', 0);
    }
    if ($newcategory) {
        $msg = zp_apply_filter('new_category', '', $cat);
        if (empty($title)) {
            $reports[] = "<p class='errorbox fade-message'>" . sprintf(gettext("Category <em>%s</em> added but you need to give it a <strong>title</strong> before publishing!"), $titlelink) . '</p>';
        } else {
            if ($notice == '?mismatch=user') {
                $reports[] = "<p class='errorbox fade-message'>" . gettext('You must supply a password for the Protected Category user') . '</p>';
            } else {
                if ($notice) {
                    $reports[] = "<p class='errorbox fade-message'>" . gettext('Your passwords were empty or did not match') . '</p>';
                } else {
                    $reports[] = "<p class='messagebox fade-message'>" . sprintf(gettext("Category <em>%s</em> added"), $titlelink) . '</p>';
                }
            }
        }
    } else {
        $msg = zp_apply_filter('update_category', '', $cat, $oldtitlelink);
        if ($titleok) {
            if (empty($titlelink) or empty($title)) {
                $reports[] = "<p class='errorbox fade-message'>" . gettext("You forgot to give your category a <strong>title or titlelink</strong>!") . "</p>";
            } else {
                if ($notice == '?mismatch=user') {
                    $reports[] = "<p class='errorbox fade-message'>" . gettext('You must supply a password for the Protected Category user') . '</p>';
                } else {
                    if ($notice) {
                        $reports[] = "<p class='errorbox fade-message'>" . gettext('Your passwords were empty or did not match') . '</p>';
                    } else {
                        $reports[] = "<p class='messagebox fade-message'>" . gettext("Category updated!") . "</p>";
                    }
                }
            }
        } else {
            $reports[] = "<p class='errorbox fade-message'>" . sprintf(gettext("A category with the title/titlelink <em>%s</em> already exists!"), html_encode($cat->getTitle())) . "</p>";
        }
    }
    $cat->save();
    if ($msg) {
        $reports[] = $msg;
    }
    return $cat;
}