scripting / Scripting-News

I'm starting to use GitHub for work on my blog. Why not? It's got good communication and collaboration tools. Why not hook it up to a blog?
121 stars 10 forks source link

Storage in WordPress, comments welcome #273

Open scripting opened 1 year ago

scripting commented 1 year ago

I wrote a piece yesterday about Storage in WordPress, and a follow-up today.

This thread is a place where people can add more info or perspectives.

yudel commented 1 year ago

Am I understanding correctly that you would like to be able to store (and later edit) OPML as a post, and then have WP render the OPML the way Scripting News does, with the [[insertions]]?

scripting commented 1 year ago

When you publish from the outline, it would generate HTML the same way we generate HTML now, but it would also store the OPML source with the post.

I'm not 100% sure the tag manager stuff would be possible because there has to be some JS running to interpret it, but all the other stuff would work.

yudel commented 1 year ago

Seems like creating a plugin to do this is very feasible. Getting Automatic to include the plugin on the WordPress.com site, however....

I've done a little WP programming for my business site, and ChatGPT as a helper may inspire me to so a bit more. I'm not at all familiar with the remote API – https://developer.wordpress.org/rest-api/ – which would of course be key to this.

My first inclination in creating such a plug-in would be to look into creating a new Post type, which could then be caught on the editing and rendering side. The OPML would be stored in the meta database.

A couple newer developments in the WP ecosystem, which I haven't fully studied, would come in to play:

The new Gutenberg Block front end seems to render based on javascript. That might mean that you could create a block that simply rendered raw OMPL using your present js code.

There is also a new datastore being implemented, but perhaps that is only for WooCommerce.

The main WP programming paradigm is a bit wonky at first – it involves registering and unregistering hooks of various priorities – but once past that, it's pretty simple.

mterenzio commented 1 year ago

Doubt it is useful, but here is a WP plugin I wrote in 2006 or so to integrate remotely hosted OPML into Wordpress. Unfortunately I haven't worked with Wordpress in over a decade so I don't know the current state of their plugin API

<?php
/*
Plugin Name: Remote OPML Enabler (ROPE)
Plugin URI: http://everybuddy.org/software/remote-opml-wordpress-plugin/
Description: Allows remotely editing and synchronizing Blogrolls and other remote OPML used in Wordpress
Author: Matthew Terenzio
Version: 0.2
Author URI: http://everybuddy.org/contact/

Copyright (C) 2006  Matthew Terenzio

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

// opmlCommunityServer.saveFile ...syncs remote opml
function opmlrpc_opmlSaveFile($args) {
    global $wpdb, $current_user;
    //$this->escape($args); //not sure about this yet??

    $blog_ID    = $args[0]; /* though we don't use it yet  per WP people*/
    $user_login = $args[1];
    $user_pass  = $args[2];
    $path       = $args[3];
    $opml       = $args[4];

    // Verify user
    if (!user_pass_ok($user_login, $user_pass)) {
        return new IXR_Error(403, 'Bad login/pass combination.');
    }
    $user = new WP_User(0, $user_login);
    $is_admin = $user->has_cap('level_8');
    if ($is_admin != true) {
        return new IXR_Error(403, 'Sorry you need to have administrative rights.');
    }

    $user_data = get_userdatabylogin($user_login);

        // Good login, return the requested info...
        //if ($path == 'wp-links-opml.php') {
        $opmltype = 'blogroll';
        //}
        switch ($opmltype) {
            case 'blogroll':
            $theparse = parse_blogroll_and_save($opml);
            break;
        }
        if ($theparse == true) {
            return true;
        } else {
            return new IXR_Error(403, 'We had trouble working with that OPML file.');
        }

}

// parses BLOGROLL and saves it 
function parse_blogroll_and_save($opmldata) {
    global $wpdb, $current_user;

    $parser = xml_parser_create("ISO-8859-1");
    $thestruct = xml_parse_into_struct( $parser, $opmldata, $values );
    if ($thestruct == 0) {
        return false;
    }
    //clear current blogroll
    $thewipe = $wpdb->query("DELETE FROM $wpdb->links WHERE link_category = 1");
    if ($thewipe == false) {
        return false;
    }

    for($x=0;$x<count($values);$x++){
        $type = $wpdb->escape($values[$x][type]);
        $tag = $wpdb->escape($values[$x][tag]);
        $value = $wpdb->escape($values[$x][value]);
        $url = $values[$x]["attributes"]["URL"];
        //$xmlurl = $values[$x]["attributes"]["XMLURL"];
        //$htmlurl = $wpdb->escape($values[$x]["attributes"]["HTMLURL"]);
        $text = $wpdb->escape($values[$x]["attributes"]["TEXT"]);
        if ($url != "") {
            $queryresult = $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_image, link_target, link_category, link_description, link_visible, link_owner, link_rating, link_rel, link_notes, link_rss) VALUES('$url', '$text', '', '', '1', '', 'Y', '$user_data->ID', '0', '$link_rel', '', '')");
        }
    }

    if ($queryresult != false) {
        return true;
    } else {
        return false;
    }
}

function attach_new_xmlrpc($methods) {
    $methods['opmlCommunityServer.saveFile'] = 'opmlrpc_opmlSaveFile';
    return $methods;
}

add_action('xmlrpc_methods', 'attach_new_xmlrpc');

?>
jedlin commented 1 year ago

If you want to experiment with Wordpress I recommend you check out Local (https://localwp.com/) which will do 1-click installs of WP sites on your local Mac where you can experiment to your heart’s content.