コード例 #1
0
 function tearDownOnce()
 {
     parent::tearDownOnce();
     DocumentationService::unregister("DocumentationViewerTests");
     DocumentationService::set_automatic_registration($this->origEnabled);
     DocumentationViewer::set_link_base($this->origLinkBase);
 }
コード例 #2
0
 function testGetLink()
 {
     $entity = new DocumentationEntity('testmodule', null, BASE_PATH . '/sapphiredocs/tests/docs/');
     $page = new DocumentationPage();
     $page->setRelativePath('test.md');
     $page->setEntity($entity);
     // single layer
     $this->assertStringEndsWith('testmodule/en/test', $page->Link(), 'The page link should have no extension and have a language');
     $folder = new DocumentationPage();
     $folder->setRelativePath('sort');
     $folder->setEntity($entity);
     // folder, should have a trailing slash
     $this->assertStringEndsWith('testmodule/en/sort/', $folder->Link());
     // second
     $nested = new DocumentationPage();
     $nested->setRelativePath('subfolder/subpage.md');
     $nested->setEntity($entity);
     $this->assertStringEndsWith('testmodule/en/subfolder/subpage', $nested->Link());
     // test with version.
     $entity = DocumentationService::register("versionlinks", BASE_PATH . "/sapphiredocs/tests/docs-v2.4/", '1');
     $entity->addVersion('2', BASE_PATH . "/sapphiredocs/tests/docs-v3.0/");
     $entity->setStableVersion('2');
     $page = new DocumentationPage();
     $page->setRelativePath('test.md');
     $page->setEntity($entity);
     $page->setVersion('1');
     $this->assertStringEndsWith('versionlinks/en/1/test', $page->Link());
 }
コード例 #3
0
 function testGetAllPages()
 {
     if (!DocumentationSearch::enabled()) {
         return;
     }
     DocumentationService::set_automatic_registration(false);
     DocumentationService::register('docs-search', BASE_PATH . '/sapphiredocs/tests/docs-search/');
     $search = DocumentationSearch::get_all_documentation_pages();
     $this->assertEquals(7, $search->Count(), '5 pages. 5 pages in entire folder');
 }
 function tearDownOnce()
 {
     parent::tearDownOnce();
     DocumentationService::unregister("DocumentationViewerTests");
     DocumentationService::set_automatic_registration($this->origEnabled);
     DocumentationViewer::set_link_base($this->origLinkBase);
     // $this->origModules = Documentation::get_registered_modules();
     // foreach($this->origModules as $name => $module) {
     // 	DocumentationService::register($name);
     // }
 }
コード例 #5
0
 function testIsValidExtension()
 {
     $this->assertTrue(DocumentationService::is_valid_extension('md'));
     $this->assertTrue(DocumentationService::is_valid_extension('markdown'));
     $this->assertTrue(DocumentationService::is_valid_extension('MD'));
     $this->assertTrue(DocumentationService::is_valid_extension('MARKDOWN'));
     $this->assertFalse(DocumentationService::is_valid_extension('.markd'));
     $this->assertFalse(DocumentationService::is_valid_extension('.exe'));
     // require an extension as internally we check for extension, not using
     // one could cause issues.
     $this->assertFalse(DocumentationService::is_valid_extension(''));
 }
コード例 #6
0
 /**
  * Return the raw markdown for a given documentation page. Will throw
  * an error if the path isn't a file.
  *
  * Will return empty if the type is not readable
  *
  * @return string
  */
 function getMarkdown()
 {
     try {
         $path = $this->getPath(true);
         if ($path) {
             $ext = $this->getExtension();
             if (DocumentationService::is_valid_extension($ext)) {
                 return file_get_contents($path);
             }
         }
     } catch (InvalidArgumentException $e) {
     }
     return false;
 }
コード例 #7
0
<?php

global $project;
$project = 'mysite';
global $database;
$database = 'SS_ssnewdocstest';
require_once 'conf/ConfigureFromEnv.php';
MySQLDatabase::set_connection_charset('utf8');
// This line set's the current theme. More themes can be
// downloaded from http://www.silverstripe.org/themes/
SSViewer::set_theme('docs');
// enable nested URLs for this site (e.g. page/sub-page/)
SiteTree::enable_nested_urls();
// render the user documentation first
Director::addRules(20, array('Security//$Action/$ID/$OtherID' => 'Security'));
DocumentationViewer::set_link_base('');
DocumentationViewer::$check_permission = false;
Director::addRules(10, array('$Action' => 'DocumentationViewer', '' => '->current/en/cms'));
DocumentationService::set_automatic_registration(false);
DocumentationService::register("cms", realpath("../../master/cms/docs/"), '2.4');
// We want this to be reviewed by the whole community
BasicAuth::protect_entire_site(false);
コード例 #8
0
 /**
  * Add another version to this entity
  *
  * @param Float $version Version number
  * @param String $path path to folder
  */
 public function addVersion($version = '', $path)
 {
     $langs = scandir($path);
     $available = array();
     if ($langs) {
         foreach ($langs as $key => $lang) {
             if (!is_dir($path . $lang) || strlen($lang) > 2 || in_array($lang, DocumentationService::get_ignored_files(), true)) {
                 $lang = 'en';
             }
             if (!in_array($lang, $available)) {
                 $available[] = $lang;
             }
         }
     }
     $this->addLanguage($available);
     $this->versions[$version] = $path;
 }
コード例 #9
0
 /**
  * Set automatic registration of entities and documentation folders
  *
  * @see DocumentationService::$automatic_registration
  * @param bool
  */
 public static function set_automatic_registration($bool = true)
 {
     self::$automatic_registration = $bool;
     if (!$bool) {
         // remove current registed entities when disabling automatic registration
         // needed to avoid caching issues when running all the tests
         self::$registered_entities = array();
     }
 }
コード例 #10
0
 /**
  * Set automatic registration of modules and documentation folders
  *
  * @see DocumentationService::$automatic_registration
  * @param bool
  */
 public static function set_automatic_registration($bool = true)
 {
     self::$automatic_registration = $bool;
 }
コード例 #11
0
 /**
  * Build the language dropdown.
  *
  * @todo do this on a page by page rather than global
  *
  * @return Form
  */
 function LanguageForm()
 {
     if ($module = $this->getModule()) {
         $langs = DocumentationService::get_registered_languages($module->getModuleFolder());
     } else {
         $langs = DocumentationService::get_registered_languages();
     }
     $fields = new FieldSet($dropdown = new DropdownField('LangCode', _t('DocumentationViewer.LANGUAGE', 'Language'), $langs, $this->Lang));
     $actions = new FieldSet(new FormAction('doLanguageForm', _t('DocumentationViewer.CHANGE', 'Change')));
     $dropdown->setDisabled(true);
     return new Form($this, 'LanguageForm', $fields, $actions);
 }
コード例 #12
0
 /**
  * Return the children from a given module. Used for building the tree of the page
  *
  * @param String module name
  *
  * @return DataObjectSet
  */
 public static function get_pages_from_folder($folder)
 {
     $handle = opendir($folder);
     $output = new DataObjectSet();
     if ($handle) {
         $extensions = DocumentationService::get_valid_extensions();
         $ignore = DocumentationService::get_ignored_files();
         while (false !== ($file = readdir($handle))) {
             if (!in_array($file, $ignore)) {
                 $file = strtolower($file);
                 $clean = ($pos = strrpos($file, '.')) ? substr($file, 0, $pos) : $file;
                 $output->push(new ArrayData(array('Title' => self::clean_page_name($file), 'Filename' => $clean, 'Path' => $folder . $file . '/')));
             }
         }
     }
     return $output;
 }
コード例 #13
0
 /**
  * Generate an array of every single documentation page installed on the system. 
  *
  * @return DataObjectSet
  */
 public static function get_all_documentation_pages()
 {
     DocumentationService::load_automatic_registration();
     $modules = DocumentationService::get_registered_entities();
     $output = new DataObjectSet();
     if ($modules) {
         foreach ($modules as $module) {
             foreach ($module->getVersions() as $version) {
                 try {
                     $pages = DocumentationService::get_pages_from_folder($module, false, true, $version);
                     if ($pages) {
                         foreach ($pages as $page) {
                             $output->push($page);
                         }
                     }
                 } catch (Exception $e) {
                     user_error($e, E_USER_WARNING);
                 }
             }
         }
     }
     return $output;
 }
コード例 #14
0
error_reporting(E_ALL);
// This line set's the current theme. More themes can be
// downloaded from http://www.silverstripe.org/themes/
SSViewer::set_theme('userhelp');
if (@$_GET['db'] == "sqlite3") {
    global $databaseConfig;
    $databaseConfig['type'] = 'SQLite3Database';
}
DocumentationService::set_automatic_registration(false);
DocumentationService::enable_meta_comments();
DocumentationViewer::set_link_base('');
DocumentationViewer::$check_permission = false;
try {
    DocumentationService::register("framework", BASE_PATH . "/src/framework_master/docs/", 'trunk');
    DocumentationService::register("framework", BASE_PATH . "/src/framework_3.1/docs/", '3.1', false, true);
    DocumentationService::register("framework", BASE_PATH . "/src/framework_3.0/docs/", '3.0');
} catch (InvalidArgumentException $e) {
}
// Silence if path is not found (for CI environment)
DocumentationViewer::set_edit_link('framework', 'https://github.com/silverstripe/silverstripe-userhelp-content/edit/%version%/docs/%lang%/%path%', array('rewritetrunktomaster' => true));
Object::add_extension('Controller', 'ControllerExtension');
if (Director::isLive()) {
    ControllerExtension::$google_analytics_code = 'UA-84547-10';
}
// Validator::set_javascript_validation_handler('none');
DocumentationSearch::enable();
DocumentationSearch::set_meta_data(array('ShortName' => 'SilverStripe Userhelp', 'Description' => 'Userhelp for SilverStripe CMS / Framework', 'Tags' => 'silverstripe sapphire php framework cms content management system'));
// Set shared index (avoid issues with different temp paths between CLI and web users)
if (file_exists(BASE_PATH . '/.lucene-index')) {
    DocumentationSearch::set_index(BASE_PATH . '/.lucene-index');
}