PHP code example of pickles2 / lib-px2-contents-editor
1. Go to this page and download the library: Download pickles2/lib-px2-contents-editor library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pickles2 / lib-px2-contents-editor example snippets
/**
* api.php
*/
ibs\contentsEditor\main();
$px2ce->init(array(
'target_mode' => 'page_content', // <- 編集対象のモード ('page_content' (default) or 'theme_layout')
'page_path' => '/path/to/page.html', // <- 編集対象ページのパス (target_mode=theme_layout のとき、 `/{theme_id}/{layout_id}.html` の形式)
'theme_id' => 'your_target_theme', // <- (target_mode=theme_layout のとき) 編集対象のテーマID
'layout_id' => 'your_target_layout', // <- (target_mode=theme_layout のとき) 編集対象のレイアウトID
'appMode' => 'web', // 'web' or 'desktop'. default to 'web'
'entryScript' => '/realpath/to/.px_execute.php', // Pickles 2 のエンドポイント
'customFields' => array(
// カスタムフィールドのサーバーサイドスクリプト。クラス名(ネームスペース含む)を指定します。
// この関数は、`broccoliHtmlEditor\fieldBase` を基底クラスとして継承します。
// customFields オブジェクトのキー(ここでは custom1)が、フィールドの名称になります。
'custom1' => 'test_php_field_custom1',
) ,
'log' => function($msg){
// ログ情報出力時にコールされます。
// $msg を受け取り、適切なファイルへ出力するように実装してください。
file_put_contents('/path/to/px2ce.log', $msg);
},
'commands' => array(
'php' => array(
// PHPコマンドのパスを表すオブジェクト
// または、 文字列で '/path/to/php' とすることも可 (この場合、 php.ini のパスは指定されない)
'bin' => '/path/to/php',
'ini' => '/path/to/php.ini',
),
),
'noimagePlaceholder' => '/path/to/noimage-placeholder.png',
));
if($_GET['client_resources'] ?? null){
$value = $px2ce->get_client_resources(__DIR__.'/caches/');
header('Content-type: text/json');
echo json_encode($value);
exit;
}
$value = $px2ce->gpi( json_decode( $_REQUEST['data'] ) );
header('Content-type: text/json');
echo json_encode($value);
exit;
<div id="canvas"></div>
<!--
エディタが利用する CSS や JavaScript などのリソースファイルがあります。
`$px2ce->get_client_resources()` からリソースの一覧を取得し、読み込んでください。
-->
}
foreach($resources->js as $js_file){
echo('<script src="'.htmlspecialchars($js_file).'"></script>');
}