onethink보다 더 좋은 플러그인 메커니즘
<?php
// +----------------------------------------------------------------------
// | Thinkphp [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2015 http://www.inuoer.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: better <[email protected]>
// +----------------------------------------------------------------------
namespace Common\Controller;
use Think\Controller;
/**
*
* @author better <[email protected]>
*/
abstract class Addon extends Controller
{
/**
*
* @var view
* @access protected
*/
protected $view = null;
public $addon_path = '';
public $config_file = '';
public $view_path = '';
public function __construct()
{
$this->view = \Think\Think::instance('Think\View');
$this->addon_path = ADDON_PATH . '/' . $this->getName() . '/';
//
C('DEFAULT_THEME', '');
C('VIEW_PATH', '');
if (is_file($this->addon_path . 'Conf/config.php')) {
$this->config_file = $this->addon_path . 'Conf/config.php';
$config = require $this->config_file;
C($config);
}
$this->view_path = __ROOT__ . '/' . ADDON_PATH . '/' . $this->getName() . '/';
C("TMPL_PARSE_STRING", array(
'__IMG__' => $this->view_path . 'View' . C("DEFAULT_THEME") . '/Public/image',
'__CSS__' => $this->view_path . 'View' . C("DEFAULT_THEME") . '/Public/css',
'__JS__' => $this->view_path . 'View' . C("DEFAULT_THEME") . '/Public/js',
'__ADDON_PUBLIC__' => $this->view_path . 'View' . C("DEFAULT_THEME") . '/Public',
));
}
/**
*
* @access protected
* @param string $theme
* @return Action
*/
final protected function theme($theme)
{
$this->view->theme($theme);
return $this;
}
//
final protected function display($template = '')
{
if ($template == '')
$template = CONTROLLER_NAME;
$action = ACTION_NAME;
echo($this->fetch($template, $action));
}
/**
*
* @access protected
* @param mixed $name
* @param mixed $value
* @return Action
*/
final protected function assign($name, $value = '')
{
$this->view->assign($name, $value);
return $this;
}
//
final protected function fetch($templateFile = CONTROLLER_NAME, $action = ACTION_NAME)
{
if (!is_file($templateFile)) {
if (C('VIEW_PATH')) {
$templateFile = C('VIEW_PATH') . C('DEFAULT_THEME') . '/' . $templateFile . '/' . $action . C('TMPL_TEMPLATE_SUFFIX');
} else {
$templateFile = $this->addon_path . 'View/' . C('DEFAULT_THEME') . '/' . $templateFile . '/' . $action . C('TMPL_TEMPLATE_SUFFIX');
}
if (!is_file($templateFile)) {
throw new \Exception(" :$templateFile");
}
}
return $this->view->fetch($templateFile);
}
final public function getName()
{
$class = get_class($this);
$str = explode('\\', $class);
return $str[1];
}
//
abstract public function install();
//
abstract public function uninstall();
}
/**
* SQL
*/
function execute_sql_file($sql_path)
{
// SQL
$sql = wp_file_get_contents($sql_path);
$sql = str_replace("\r", "
", $sql);
$sql = explode(";
", $sql);
//
$orginal = 'wp_';
$prefix = C('DB_PREFIX');
$sql = str_replace("{$orginal}", "{$prefix}", $sql);
//
foreach ($sql as $value) {
$value = trim($value);
if (empty ($value))
continue;
$res = M()->execute($value);
// dump($res);
// dump(M()->getLastSql());
}
}
// file_get_contents
function wp_file_get_contents($url)
{
$context = stream_context_create(array(
'http' => array(
'timeout' => 30
)
)); // ,
return file_get_contents($url, 0, $context);
}
/**
* url
* @param string $url url
* @param array $param
* @author better
* @useage u_addons('apply://App/Index/addorder',array('id'=>'1'))
*/
function u_addons($url, $param = array()){
$url = explode('://', $url);
$addon = $url[0];
$url = $url[1];
$url = U($url, $param, false);
return $url . '/addon/' . $addon;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
bitnami redmine4.*환경에 플러그인을 설치합니다.bitnami redmine4.*시스템 환경에 이전 플러그인(redmine bootstrap kit)을 설치합니다. windwos 버전만 검증하고 다른 환경은 확인되지 않았지만 다른 사람의 참고가 될 수 있어 공개합...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.