/**
  * Tests to make sure short codes get translated to full paths.
  *
  */
 public function testRedirectingMapping()
 {
     DocumentationPermalinks::add(array('foo' => 'en/framework/subfolder/foo', 'bar' => 'en/cms/bar'));
     $this->autoFollowRedirection = false;
     $v = new DocumentationViewer();
     $response = $v->handleRequest(new SS_HTTPRequest('GET', 'foo'), DataModel::inst());
     $this->assertEquals('301', $response->getStatusCode());
     $this->assertContains('en/framework/subfolder/foo', $response->getHeader('Location'));
 }
 /**
  * Tests to make sure short codes get translated to full paths
  */
 function testRedirectingMapping()
 {
     // testing the viewer class but clearer here
     DocumentationPermalinks::add(array('foo' => 'current/en/sapphire/subfolder/foo', 'bar' => 'current/en/cms/bar'));
     $this->autoFollowRedirection = false;
     $v = new DocumentationViewer();
     $response = $v->handleRequest(new SS_HTTPRequest('GET', 'foo'));
     $this->assertEquals('301', $response->getStatusCode());
     $this->assertContains('current/en/sapphire/subfolder/foo', $response->getHeader('Location'));
 }
 public function description()
 {
     $viewer = new DocumentationViewer();
     if (!$viewer->canView()) {
         return Security::permissionFailure($this);
     }
     if (!Config::inst()->get('DocumentationSearch', 'enabled')) {
         return $this->httpError('404');
     }
     $data = DocumentationSearch::get_meta_data();
     $link = Director::absoluteBaseUrl() . ($data['SearchPageLink'] = Controller::join_links($viewer->Link(), 'results/?Search={searchTerms}&start={startIndex}&length={count}&action_results=1'));
     $data['SearchPageAtom'] = $data['SearchPageLink'] . '&format=atom';
     return $this->customise(new ArrayData($data))->renderWith(array('OpenSearchDescription'));
 }
<?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);
 function getRelativeLink($version = false, $lang = false)
 {
     if (!$lang) {
         $lang = 'en';
     }
     if ($version == $this->getStableVersion()) {
         $version = false;
     }
     return Controller::join_links(DocumentationViewer::get_link_base(), $this->getFolder(), $lang, $version);
 }
 function testVersionWarning()
 {
     $v = new DocumentationViewer();
     // the current version is set to 2.4, no notice should be shown on that page
     $response = $v->handleRequest(new SS_HTTPRequest('GET', 'DocumentationViewerTests/en/2.4'));
     $this->assertFalse($v->VersionWarning());
     // 2.3 is an older release, hitting that should return us an outdated flag
     $response = $v->handleRequest(new SS_HTTPRequest('GET', 'DocumentationViewerTests/en/2.3'));
     $warn = $v->VersionWarning();
     $this->assertTrue($warn->OutdatedRelease);
     $this->assertNull($warn->FutureRelease);
     // 3.0 is a future release
     $response = $v->handleRequest(new SS_HTTPRequest('GET', 'DocumentationViewerTests/en/3.0'));
     $warn = $v->VersionWarning();
     $this->assertNull($warn->OutdatedRelease);
     $this->assertTrue($warn->FutureRelease);
 }
 function testGetModulePages()
 {
     $v = new DocumentationViewer();
     $response = $v->handleRequest(new SS_HTTPRequest('GET', '2.4/en/DocumentationViewerTests/subfolder/'));
     $pages = $v->getModulePages();
     $this->assertEquals(array('index', 'subfolder', 'test'), $pages->column('Filename'));
     $this->assertEquals(array('link', 'current', 'link'), $pages->column('LinkingMode'));
     $links = $pages->column('Link');
     $this->assertStringEndsWith('2.4/en/DocumentationViewerTests/', $links[0]);
     $this->assertStringEndsWith('2.4/en/DocumentationViewerTests/subfolder/', $links[1]);
     $this->assertStringEndsWith('2.4/en/DocumentationViewerTests/test/', $links[2]);
     // Children
     $pagesArr = $pages->toArray();
     $child1 = $pagesArr[0];
     $this->assertFalse($child1->Children);
     $child2 = $pagesArr[1];
     $this->assertType('DataObjectSet', $child2->Children);
     $this->assertEquals(array('subpage', 'subsubfolder'), $child2->Children->column('Filename'));
     $child2Links = $child2->Children->column('Link');
     $this->assertStringEndsWith('2.4/en/DocumentationViewerTests/subfolder/subpage/', $child2Links[0]);
     $this->assertStringEndsWith('2.4/en/DocumentationViewerTests/subfolder/subsubfolder/', $child2Links[1]);
 }
Exemple #8
0
css/docs.css">
		<?php 
    }
    public function title()
    {
        echo 'Documentation';
    }
    public function desc()
    {
        $this->title();
    }
    public function author()
    {
        echo 'Ryan Barry';
    }
    public function main()
    {
        foreach (glob("*.md") as $filename) {
            $markdown = file_get_contents($filename);
            ?>
			<div class="docblock">
				<?php 
            echo Markdown($markdown);
            ?>
			</div>
			<?php 
        }
    }
}
$doc = new DocumentationViewer('../');
$doc->render();
 /**
  * @param String
  */
 static function set_link_base($base)
 {
     self::$link_base = $base;
 }
if (isset($_ENV['CLEARDB_DATABASE_URL'])) {
    global $databaseConfig;
    $parts = parse_url($_ENV['CLEARDB_DATABASE_URL']);
    $databaseConfig['type'] = 'MySQLDatabase';
    $databaseConfig['server'] = $parts['host'];
    $databaseConfig['username'] = $parts['user'];
    $databaseConfig['password'] = $parts['pass'];
    $databaseConfig['database'] = trim($parts['path'], '/');
} else {
    require_once 'conf/ConfigureFromEnv.php';
}
MySQLDatabase::set_connection_charset('utf8');
SSViewer::set_theme('docs');
Config::inst()->update('DocumentationManifest', 'automatic_registration', false);
Config::inst()->update('DocumentationViewer', 'link_base', '');
Config::inst()->update('DocumentationViewer', 'check_permission', false);
DocumentationViewer::set_edit_link('framework', 'https://github.com/silverstripe/silverstripe-framework/edit/%version%/docs/%lang%/%path%', array('rewritetrunktomaster' => true));
if (Director::isLive()) {
    ControllerExtension::$google_analytics_code = 'UA-84547-8';
}
DocumentationSearch::set_meta_data(array('ShortName' => 'SilverStripe Documentation', 'Description' => 'Documentation for SilverStripe CMS / Framework', 'Tags' => 'silverstripe sapphire php framework cms content management system'));
// Changelogs have heaps of phrases, but are rarely relevant for content searches
Config::inst()->update('DocumentationSearch', 'boost_by_path', array('/^changelog/' => 0.05));
// Set shared index (avoid issues with different temp paths between CLI and web users)
if (file_exists(BASE_PATH . '/.lucene-index')) {
    Config::inst()->update('DocumentationSearch', 'index_location', BASE_PATH . '/.lucene-index');
}
// Fix invalid character in iconv
// see http://stackoverflow.com/questions/4723135/invalid-characters-for-lucene-text-search
Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8');
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive());
 public function testGetLanguage()
 {
     $v = new DocumentationViewer();
     $response = $v->handleRequest(new SS_HTTPRequest('GET', 'en/doc_test/2.3/'), DataModel::inst());
     $this->assertEquals('en', $v->getLanguage());
     $response = $v->handleRequest(new SS_HTTPRequest('GET', 'en/doc_test/2.3/subfolder/subsubfolder/subsubpage/'), DataModel::inst());
     $this->assertEquals('en', $v->getLanguage());
 }