View source  
  <?php
require 'vendor/autoload.php';
use EdSDK\FlmngrServer\FlmngrServer;
function n1ed_menu() {
  $items = [];
  $items['admin/config/content/n1ed'] = [
    'title' => 'N1ED configuration',
    'description' => 'N1ED settings',
    'page callback' => 'drupal_get_form',
    'page arguments' => [
      'n1ed_admin_form',
    ],
    'access arguments' => [
      'administer users',
    ],
    'type' => MENU_NORMAL_ITEM,
  ];
  $items['admin/config/content/n1ed/setApiKey'] = [
    'title' => 'setApikey',
    'page callback' => 'n1ed_setApiKey',
    'access arguments' => [
      'administer users',
    ],
  ];
  $items['admin/config/content/n1ed/flmngr'] = [
    'title' => 'FM',
    'page callback' => 'n1ed_flmngr',
    'access arguments' => [
      'administer users',
    ],
  ];
  return $items;
}
function n1ed_flmngr() {
  $tmp = drupal_get_path('module', 'n1ed') . '/tmp/';
  $cache = drupal_get_path('module', 'n1ed') . '/cache/';
  if (!file_exists($tmp)) {
    mkdir($tmp, 0777, TRUE);
  }
  if (!file_exists($cache)) {
    mkdir($cache, 0777, TRUE);
  }
  if (!file_exists($cache)) {
    mkdir(drupal_realpath('public://') . '/flmngr', 0777, TRUE);
  }
  echo FlmngrServer::flmngrRequest([
    'dirFiles' => drupal_realpath('public://') . '/flmngr',
    'dirTmp' => $tmp,
    'dirCache' => $cache,
  ]);
}
function n1ed_setApiKey() {
  $key = $_POST['n1edApiKey'];
  $token = $_POST['n1edToken'];
  variable_set('n1edApiKey', $key);
  variable_set('n1edToken', $token);
  die('ok');
}
function n1ed_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == "article_node_form") {
    $form['body'][LANGUAGE_NONE][0]['summary']['#attributes']['data-disable-n1ed'] = 'true';
  }
}
function n1ed_ckeditor_settings_alter(array &$settings, &$conf) {
  $settings['removePlugins'] = 'iframe';
  $conf['removePlugins'] = 'iframe';
}
function n1ed_preprocess_page(&$page) {
  if ($page['page']['content']['system_main'] && @$page['page']['content']['system_main']['#node_edit_form']) {
    if (!variable_get('n1edApiKey')) {
      variable_set('n1edApiKey', 'N1D7DFLT');
    }
    $version = variable_get('n1ed_version') ?: '';
    if ($version === '') {
      $version = 'latest';
    }
    $urlCache = variable_get('urlCache') ?: '';
    if ($urlCache === '') {
      
      $path = '//' . (isset($_COOKIE["N1ED_PREFIX"]) ? $_COOKIE["N1ED_PREFIX"] . "." : "") . 'cloud.n1ed.com/cdn/' . variable_get('n1edApiKey') . '/' . $version . '/ckeditor/plugins/N1EDEco/plugin.js';
    }
    else {
      
      if (strpos($urlCache, "http:") === 0) {
        $urlCache = substr($urlCache, 5);
      }
      elseif (strpos($urlCache, "https:") === 0) {
        $urlCache = substr($urlCache, 6);
      }
      $path = $urlCache . variable_get('n1edApiKey') . '/' . $version . '/ckeditor/plugins/N1EDEco/plugin.js';
    }
    drupal_add_js([
      'N1ED' => [
        'urlPlugin' => $path,
        'urlFileManager' => '/admin/config/content/n1ed/flmngr',
        'urlFiles' => '/' . variable_get('file_public_path', conf_path() . '/files/'),
        'defaultUploadDir' => '/uploads/',
      ],
    ], 'setting');
  }
}
function n1ed_ckeditor_plugin() {
  return [
    'n1ed' => [
      'name' => 'N1ED',
      'desc' => t('N1ED - visual editor with Bootstrap support'),
      'path' => drupal_get_path('module', 'n1ed') . '/plugins/n1ed/',
    ],
  ];
}
function n1ed_admin_form($form, &$form_state) {
  $adminJS = '/' . drupal_get_path('module', 'n1ed') . '/js/admin.js';
  if (!variable_get('n1edApiKey')) {
    variable_set('n1edApiKey', 'N1D7DFLT');
  }
  drupal_add_js($adminJS, 'external');
  $form['#attributes'] = [
    'data-apikey' => variable_get('n1edApiKey'),
    'data-token' => variable_get('n1edToken'),
  ];
  $form['n1ed_config'] = [
    '#type' => 'hidden',
    '#required' => FALSE,
  ];
  return system_settings_form($form);
}