美文网首页
给蝉知换一个markdwon的编辑器

给蝉知换一个markdwon的编辑器

作者: hainuo | 来源:发表于2015-08-10 01:27 被阅读720次

    蝉知
    蝉知企业门户系统是由业内资深开发团队开发的一款专向企业营销使用的企业门户系统,企业使用蝉知系统可以非常方便地搭建一个专业的企业营销网站,进行宣传,开展业务,服务客户。蝉知系统内置了文章、产品、论坛、评论、会员、博客、帮助等功能,同时还可以和微信进行集成绑定。功能丰富实用,后台操作简洁方便。蝉知系统还内置了搜索引擎优化必备的功能,比如关键词,摘要,站点地图,友好路径等,使用蝉知系统可以非常方便的搭建对搜索引擎友好的网站。
    展示效果可以到我的个人博客海娜博客公告板查看

    准备

    下载thinker-md文件 传送门:海诺修改版thinker-md

    下载方式 1: git clone http://git.oschina.net/hainuo/thinker-md

    下载方式2:点击 zip 下载元文件,有用的就是那个dist文件夹

    ps:下载方式1下载的用户可以进行编译成自己适用的版本。这是多余的话。

    #开始修改

    • 将dist更名为thinker-md移动到www目录下

    • 修改文件

    
    js::import($jsRoot . "thinker-md/javascripts/thinker-md.vendor.js");
    
     js::import($jsRoot . "thinker-md/javascripts/tohtml.js"); 
    
     css::import($jsRoot . "thinker-md/stylesheets/thinker-md.user.css");
    
     css::import($jsRoot . "thinker-md/stylesheets/thinker-md.vendor.css");
    
     css::import($jsRoot . "thinker-md/emoji/nature.css");
    
      css::import($jsRoot . "thinker-md/emoji/object.css");
    
      css::import($jsRoot . "thinker-md/emoji/people.css");
    
      css::import($jsRoot . "thinker-md/emoji/place.css");
    
      css::import($jsRoot . "thinker-md/emoji/Sysmbols.css");
    
      css::import($jsRoot . "thinker-md/emoji/twemoji.css");
    
    
    • 文件4:www/template/default/view/common/ext/header.lite.html.php 新增 内容为

    http://git.oschina.net/hainuo/chanzhi/raw/master/www/template/default/view/common/ext/header.lite.html.php

    • 文件5:system/module/file/control.php 第84行 在上个函数结束后增加 以下代码
    
    /**
    
    * AJAX: the api to recive the file posted through ajax.
    
    *
    
    * @param  string $uid
    
    * @access public
    
    * @return array
    
    */
    
    public function ajaxUploadImage($uid)
    
    {
    
    if(RUN_MODE == 'front' and !commonModel::isAvailable('forum')) exit;
    
    if(!$this->loadModel('file')->canUpload())  $this->send(array('error' => 1, 'message' => $this->lang->file->uploadForbidden));
    
    $file = $this->file->getUpload('img');
    
    $file = $file[0];
    
    if($file)
    
    {
    
    if(!$this->file->checkSavePath()) $this->send(array('error' => 1, 'message' => $this->lang->file->errorUnwritable));
    
    if(!in_array(strtolower($file['extension']), $this->config->file->editorExtensions)) $this->send(array('error' => 1, 'message' => $this->lang->fail));
    
    move_uploaded_file($file['tmpname'], $this->file->savePath . $file['pathname']);
    
    if(in_array(strtolower($file['extension']), $this->config->file->imageExtensions) !== false)
    
    {
    
    $this->file->compressImage($this->file->savePath . $file['pathname']);
    
    $imageSize = $this->file->getImageSize($this->file->savePath . $file['pathname']);
    
    $file['width']  = $imageSize['width'];
    
    $file['height'] = $imageSize['height'];
    
    }
    
    $url =  $this->file->webPath . $file['pathname'];
    
    $file['addedBy']  = $this->app->user->account;
    
    $file['addedDate'] = helper::now();
    
    $file['editor']    = 1;
    
    $file['lang']      = 'all';
    
    unset($file['tmpname']);
    
    $this->dao->insert(TABLE_FILE)->data($file)->exec();
    
    $_SESSION['album'][$uid][] = $this->dao->lastInsertID();
    
    $this->loadModel('setting')->setItems('system.common.site', array('lastUpload' => time()));
    
    die( $_SERVER['REQUEST_SCHEME']."://".$_SERVER['HTTP_HOST'] .$url);
    
    }
    
    }
    
    /**
    
    * Paste image in kindeditor at firefox and chrome.
    
    *
    
    * @param  string uid
    
    * @access public
    
    * @return void
    
    */
    
    public function ajaxPasteImageBase64($uid)
    
    {
    
    if($_POST)
    
    {
    
    echo $this->file->pasteImageBase64($_POST['base64Date'], $uid);
    
    }
    
    }
    
    
    • 文件6:system/module/file/model.php在640行 上个函数结束后增加
    
    /**
    
    * Paste image in kindeditor at firefox and chrome.
    
    *
    
    * @param  string $data
    
    * @param  string $uid
    
    * @access public
    
    * @return string
    
    */
    
    public function pasteImageBase64($data, $uid)
    
    {
    
    if (!$this->checkSavePath()) return false;
    
    ini_set('pcre.backtrack_limit', strlen($data));
    
    preg_match('/data:image\/(\S+);base64,(\S+)/', $data, $out);
    
    if($out && !empty($out[2])) {
    
    $imageData = base64_decode($out[2]);
    
    $file['extension'] = $out[1];
    
    $file['pathname'] = $this->setPathName($key, $file['extension']);
    
    $file['size'] = strlen($imageData);
    
    $file['addedBy'] = $this->app->user->account;
    
    $file['addedDate'] = helper::today();
    
    $file['title'] = basename($file['pathname']);
    
    $file['editor'] = 1;
    
    file_put_contents($this->savePath . $file['pathname'], $imageData);
    
    $this->compressImage($this->savePath . $file['pathname']);
    
    $imageSize = $this->getImageSize($this->savePath . $file['pathname']);
    
    $file['width'] = $imageSize['width'];
    
    $file['height'] = $imageSize['height'];
    
    $file['lang'] = 'all';
    
    $this->dao->insert(TABLE_FILE)->data($file)->exec();
    
    $_SESSION['album'][$uid][] = $this->dao->lastInsertID();
    
    $data = $this->webPath . $file['pathname'];
    
    return $_SERVER['REQUEST_SCHEME']."://".$_SERVER['HTTP_HOST'].$data;
    
    }else{
    
    return ' ';
    
    }
    
    }
    
    

    总结

    经过以上操作就可以将原来的编辑器更换为thinker-md编辑器。

    QQ20150810-7.png QQ20150810-8.png

    bug

    每篇文章的第一行请保留为空,这样提交后会避免在前台展示时出现首行code样式的bug

    相关文章

      网友评论

          本文标题:给蝉知换一个markdwon的编辑器

          本文链接:https://www.haomeiwen.com/subject/pskiqttx.html