victor-stm/confluence

Confluence API ADF helper

Maintainers

Package info

gitlab.com/victor-stm/confluence-api-tools

Issues

pkg:composer/victor-stm/confluence

Statistics

Installs: 1 975

Dependents: 0

Suggesters: 0

Stars: 0

2.1.1 2021-06-21 14:35 UTC

This package is not auto-updated.

Last update: 2026-04-07 11:10:40 UTC


README

Helps construct and publish documents into the Confluence using PHP.

Example

Set your secrets in the config part of ./example/demo-page.php and run script:

php example/demo-page.php

Usage

// config
$apiURL     = 'domain.without.schema';  // Correct: 'x.atlassian.net', WRONG: 'https://x.atlassian.net'
$apiToken   = 'user:api_token';
$pageID     = '12378764';
$pageTitle  = ''; // use page's title
$pageSpace  = 'MY';

$confAPI    = new Confluence ($apiURL, $apiToken);


//---------------------------------------------------------------------
// Content build
//---------------------------------------------------------------------

$content = new Content ();


//---------------------------------------------------------------------
// Headers
//---------------------------------------------------------------------

$h1 = new Header ('Header H1');
$h1->level = 1;

$h2 = new Header ('Header H2', 2);

$content->add ($h1)
    ->add ($h2)
    ->add (new Header ('Header H3, etc.', 3));


//---------------------------------------------------------------------
// Paragraph
//---------------------------------------------------------------------

$p = new Paragraph ('Hello, ');
$p->add (new Text('world!'))
    ->add (new Text(' And here is a link example: '))
    ->add (new TextWithLink('Google.com', 'https://google.com/'));

$content->add ($p);


//---------------------------------------------------------------------
// Table Node
//---------------------------------------------------------------------

$table = new Table ();
$table->attributes->layout = TableAttributes::LAYOUT_FULL_WIDTH;


//---------------------------------------------------------------------
// First row with header nodes
//---------------------------------------------------------------------

$headerRow = new TableRow ();
$table->add ($headerRow);

$headTime = new TableHeader ('Time');
$headTime->attributes->colwidth = [150];

$headProject = new TableHeader ('Project');
$headProject->attributes->colwidth = [220];

$headerRow->add ($headTime)
    ->add ($headProject)
    ->add (new TableHeader ('Message'));


//---------------------------------------------------------------------
// Rows
//---------------------------------------------------------------------

$table->add ((new TableRow())
                 ->add (new TableCell ('00:00:00'))
                 ->add (new TableCell ('Row 1 Project'))
                 ->add (new TableCell ('Row 1 Message'))
);

// OR

$row = new TableRow();
$row->add (new TableCell ('00:00:00'));
$row->add (new TableCell ('Row 2 Project'));
$row->add (new TableCell ('Row 2 Message'));
$table->add ($row);


//---------------------------------------------------------------------
// Add table to content & update existing page
//---------------------------------------------------------------------

$content->add ($table);

$confAPI->updatePage ($pageID, $content, $pageTitle, $pageSpace);

Expected result: Expected result

License

Licensed under the MIT license.