rhildred / editable

dev-master 2015-01-11 14:58 UTC

This package is not auto-updated.

Last update: 2024-09-14 17:31:51 UTC


README

这是一个用于网页上可编辑Markdown的composer可安装模块。这里有一个部分演示。要在项目中使用,请在您的composer.json文件中添加"require": {"rhildred/editable": "dev-master"}

在您的仓库中名为www的文件夹中添加一个 .htaccess 文件

AddHandler application/x-httpd-php .phtml
RewriteEngine On

RewriteCond %{REQUEST_URI}::$1 ^(.*?/)(.*)::\2$
RewriteRule ^(.*)$ - [E=BASE:%1]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.%{TIME_YEAR}.html -f
# Rewrite /foo/bar to /foo/bar.html
RewriteRule ^(.*)$ %{REQUEST_URI}.%{TIME_YEAR}.html [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.html -f
# Rewrite /foo/bar to /foo/bar.html
RewriteRule ^(.*)$ %{REQUEST_URI}.html [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
# Rewrite /foo/bar to /foo/bar.php
RewriteRule ^(.*)$ %{REQUEST_URI}.php [L]

RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME}index.%{TIME_YEAR}.html -f
# Rewrite /foo/bar to have it compiled to a new php file
RewriteRule ^(.*)$ %{REQUEST_URI}index.%{TIME_YEAR}.html [L]

RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME}index.html -f
# Rewrite /foo/bar to have it compiled to a new php file
RewriteRule ^(.*)$ %{REQUEST_URI}index.html [L]

RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME}index.php -f
# Rewrite /foo/bar to have it compiled to a new php file
RewriteRule ^(.*)$ %{REQUEST_URI}index.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
# Rewrite /foo/bar to have it compiled to a new php file
RewriteRule ^(.*)$ %{ENV:BASE}indexTransform.php/$1 [L]

然后您还需要某种形式的路由。我已经将slim添加到我的composer.json文件中

"require":{
    "rhildred/editable":"*",
    "slim/slim": "*"
}

同样,在www文件夹中,我也添加了

<?php require_once(__DIR__ . '/../vendor/autoload.php');

$sScript = dirname(__FILE__) . $_SERVER['PATH_INFO'];
if(substr($sScript, -1) == "/") $sScript .= "index";
if (file_exists($sScript . ".phtml")){
    \RHildred\Editable\Phtml::render($sScript);
}else{


    session_start();

    $sUrl = "http";
    if(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443)
    {
        $sUrl .= "s";
    }
    $sUrl .= "://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . "/callback";


    $app = new \Slim\Slim();

    $app->get('/login', function () use ($app){
        global $sUrl;
        $oOauth2 = new \RHildred\Editable\Oauth2($sUrl);
        $app->redirect($oOauth2->redirect());
    });

    $app->get('/login/callback', function () use ($app) {
        global $sUrl;
        $oOauth2 = new \RHildred\Editable\Oauth2($sUrl);
        $rc= $oOauth2->handleCode($_GET["code"]);
        $_SESSION["currentuser"] = $rc;
        $app->redirect("../");
    });

    $app->get('/logout', function () {
        unset($_SESSION["currentuser"]);
        $rc = new stdClass();
        $rc->result = "success";
        echo json_encode($rc);

    });

    $app->get('/CurrentUser', function () {
        if(!isset($_SESSION["currentuser"])) throw new Exception('no user logged in');
        echo json_encode($_SESSION["currentuser"]);
    });

    $app->post('/ToMd/:sId', function($sId){
        $sReferer = !empty($_SERVER['HTTP_REFERER'])? basename($_SERVER['HTTP_REFERER']):"index";
        if($sReferer == "www" || $sReferer == "" || $sReferer == "salesucation.com") $sReferer = "index";

        echo \RHildred\Editable\Markdown::save($sId, $_POST["sValue"], $sReferer);
    });

    $app->run();

}

当所有这些设置完成时,您可以使用部分演示中的javascript来启用带有Markdown的网页编写和编辑。