htmly icon indicating copy to clipboard operation
htmly copied to clipboard

What takes place when I make a post

Open AutomationMan808 opened this issue 4 years ago • 1 comments

I'm trying to figure out how to automate posts but I can't figure everywhere a post is listed

Rick

AutomationMan808 avatar Sep 11 '21 23:09 AutomationMan808

Hi AutomationMan808,

I am not sure if you want to automate posting or find places in code where a post is listed.

Here is for you and others how I post programmatically.

Basically you have to format your post content, write it inside the "content" folder and clear the cache.

My HTMLy code differs from the current code base but you can adapt (and comment) this function:

function add_my_content($title, $post_tag, $articleid, $content, $description = null, $category, $type) { $post_date = date('Y-m-d-H-i-s');

/* Deal with title */ $post_title = "\n";

/* Deal with short description */ $post_description = "\n";

/* Deal with tag */ $posttag = "\n";

/* Deal with desired URL */ $target_URL = preg_replace("/[^A-Za-z0-9]/", '-', $articleid);

/* Deal with content */ $post_content = $post_title . $post_description . $posttag . "\n\n" . $content; if (!empty($post_title) && !empty($post_tag) && !empty($articleid) && !empty($post_content)) { if (get_magic_quotes_gpc()) { $post_content = stripslashes($post_content); } $filename = $post_date . '' . $post_tag . '' . $target_URL . '.md';

$dir = __DIR__ . '/../../content/admin/blog/english/post/';

// We now search if a file with the same articleid had already been posted

$matches = glob($dir . '????-??-??-??-??-??_??????_' . $articleid . '.md') ;

// If $matches == false, then there is no such file in the content database
// If $matches != false, there is already a file with this articleid, so we do nothing
if ($matches == false) {
    if (is_dir($dir)) {
        $resfpc = file_put_contents($dir . $filename, print_r($post_content, true));
        if ($resfpc === false) {
            echo '<br>Failure 1 in writing content at: ' . $dir;
            die();
        }
    } else {
        mkdir($dir, 0775, true);
        $resfpc = file_put_contents($dir . $filename, print_r($post_content, true));
        if ($resfpc === false) {
            echo '<br>Failure 2 in writing content at: ' . $dir;
            die();
        }
    }
    // Clear cache
    $files = glob(__DIR__ . '/../../cache/index/*'); // get all file names
    foreach ($files as $file) { // iterate files
        if (is_file($file)) {
            unlink($file); // delete file
        }
    }
}

}

// https://example.com/2021/08/desiredurl return '/' . date('Y/m') . '/' . $target_URL;

Hjertesvikt avatar Sep 12 '21 08:09 Hjertesvikt

I will close this one. Scheduled post already available in latest version.

danpros avatar Dec 14 '23 14:12 danpros