src/AppBundle/Common/BlockToolkit.php
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
<?php
namespace AppBundle\Common;
use Symfony\Component\HttpFoundation\Request;
use Topxia\Service\Common\ServiceKernel;
class BlockToolkit
{
public static function init($jsonFile, $container = null, $blocksFolder = null)
{
if (file_exists($jsonFile)) {
$blockMeta = json_decode(file_get_contents($jsonFile), true);
if (empty($blockMeta)) {
throw new \RuntimeException(ServiceKernel::instance()->trans('插件元信息文件%blockMeta%格式不符合JSON规范,解析失败,请检查元信息文件格式',
array('%blockMeta%' => $blockMeta)));
}
$blockService = ServiceKernel::instance()->getBiz()->service('Content:BlockService');
foreach ($blockMeta as $key => $meta) {
$blockTemplate = $blockService->getBlockTemplateByCode($key);
$default = array();
foreach ($meta['items'] as $i => $item) {
$default[$i] = $item['default'];
}
$blockTemplateFields = array(
'code' => $key,
'mode' => 'template',
'category' => empty($meta['category']) ? 'system' : $meta['category'],
'meta' => $meta,
'data' => $default,
'templateName' => $meta['templateName'],
'title' => $meta['title'],
);
if (empty($blockTemplate)) {
$blockTemplate = $blockService->createBlockTemplate($blockTemplateFields);
} else {
//unset($blockTemplateFields['code']);
$blockTemplate = $blockService->updateBlockTemplate($blockTemplate['id'], $blockTemplateFields);
}
if (!empty($blocksFolder)) {
$filename = $blocksFolder.'block-'.md5($key).'.html';
if (file_exists($filename)) {
$content = file_get_contents($filename);
} else {
$content = '';
}
$blockTemplate = $blockService->updateTemplateContent($blockTemplate['id'], $content);
}
if (empty($blockTemplate['content']) && $container) {
$content = self::render($blockTemplate, $container);
$blockService->updateTemplateContent($blockTemplate['id'], $content);
}
}
}
}
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。